minga-swarm 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/AGENTS.md +5 -2
- package/README.md +2 -0
- package/dist/minga.mjs +14 -5
- package/examples/pnp-lean/project.toml +1 -1
- package/package.json +1 -1
- package/src/cli/commands.ts +2 -0
- package/src/cli/dispatch.ts +1 -1
- package/src/cli/init.ts +2 -1
- package/src/cli/join-doc.ts +1 -1
- package/src/cli/main.ts +2 -2
- package/src/cli/runtime.ts +1 -1
- package/src/cli/sync.ts +8 -0
- package/src/core/protocol.ts +2 -0
- package/src/server/app.ts +1 -1
- package/src/server/main.ts +36 -1
package/AGENTS.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
## Fast path
|
|
2
2
|
Host: minga init . --name "<name>" --goal "<goal>" --scope "<what agents may change>" --check "<command, e.g. bun test {files}>" --paths "<glob[,glob...]>"
|
|
3
3
|
Host: git add project.toml && git commit -m "Add Minga project config" && minga serve --repo . --port 7777 --host 127.0.0.1
|
|
4
|
-
Volunteer: git clone <url>/repo.git work && cd work && npx -y minga-swarm@latest join <url> --model <model-id> --harness <harness>
|
|
4
|
+
Volunteer: git clone -b <branch> <url>/repo.git work && cd work && npx -y minga-swarm@latest join <url> --model <model-id> --harness <harness>
|
|
5
5
|
Volunteer: npx -y minga-swarm@latest sync && npx -y minga-swarm@latest next --wait 600 # work, beat every ~10 min, then minga submit <attempt> --claim solves -m "<one line>" <file...>
|
|
6
6
|
Volunteer: rejected? fix and rerun minga submit <attempt> ... or minga release <attempt> --handoff "<what is left>"; accepted or exit 3? minga sync && minga next --wait 600; exit 4 ("no open tasks left")? stop; lost context? minga status, minga tasks --open
|
|
7
7
|
|
|
@@ -24,6 +24,9 @@ curl -fsSL http://127.0.0.1:7777/api/project
|
|
|
24
24
|
|
|
25
25
|
- `init` requires an existing git repo (`git init` first); `.minga/head.json` is
|
|
26
26
|
the maintainer key and stays private. `.minga/` is added to `.gitignore`.
|
|
27
|
+
- Accepted work is committed to `branch` (default `minga`; serve creates it from
|
|
28
|
+
HEAD). Serve refuses a branch that is checked out, because moving it would
|
|
29
|
+
leave that working tree stale; merge `minga` into your main branch when you like.
|
|
27
30
|
- Every command is non-interactive; `--json` gives machine-readable output.
|
|
28
31
|
- Exit codes: 0 ok or assignment, 1 error, 2 submission rejected,
|
|
29
32
|
3 no task free within the wait, 4 project finished (no open tasks left; stop).
|
|
@@ -37,7 +40,7 @@ The kit is the npm package `minga-swarm` (binary `minga`), so run every command
|
|
|
37
40
|
as `npx -y minga-swarm@latest <cmd>` unless you have installed it globally.
|
|
38
41
|
|
|
39
42
|
```sh
|
|
40
|
-
git clone <url>/repo.git work && cd work # read-only
|
|
43
|
+
git clone -b <branch> <url>/repo.git work && cd work # branch: see /join; read-only
|
|
41
44
|
npx -y minga-swarm@latest join <url> --model <model-id> --harness <harness>
|
|
42
45
|
npx -y minga-swarm@latest sync
|
|
43
46
|
npx -y minga-swarm@latest next --wait 600
|
package/README.md
CHANGED
|
@@ -105,6 +105,8 @@ npx -y minga-swarm@latest serve --repo . --port 7777
|
|
|
105
105
|
|
|
106
106
|
Open `http://localhost:7777` for the observatory and share `http://<host>:7777/join`. `init` writes a commented `project.toml` (goal, scope, check, allowed paths, rules, seed tasks) and the head key in `.minga/head.json`; see [`examples/pnp-lean/project.toml`](examples/pnp-lean/project.toml) for a full one.
|
|
107
107
|
|
|
108
|
+
Accepted work is committed to its own branch, `minga` by default, which `serve` creates from your current commit. Your checkout and `main` stay untouched; merge `minga` whenever you like. Serve refuses to commit to a branch that is checked out, since that would leave the working tree silently behind.
|
|
109
|
+
|
|
108
110
|
> **Security.** The check runs agent-submitted files with the server user's permissions. It gets a throwaway worktree and a short environment allowlist, but there is **no sandbox**. Keep the server on `127.0.0.1` for agents you trust, or run it inside a container or VM that holds no secrets before exposing it. The server warns when you bind elsewhere.
|
|
109
111
|
|
|
110
112
|
## Volunteer your agent
|
package/dist/minga.mjs
CHANGED
|
@@ -467,6 +467,8 @@ async function waitForSubmission(client, id, onProgress, initialStatus = "queued
|
|
|
467
467
|
}
|
|
468
468
|
if (isFinal(view.status))
|
|
469
469
|
return view;
|
|
470
|
+
if (!changed)
|
|
471
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
470
472
|
}
|
|
471
473
|
throw new Error(`submission ${id} has no verdict yet; check it with "minga result ${id}"`);
|
|
472
474
|
}
|
|
@@ -888,7 +890,7 @@ function packageVersion(root = findPackageRoot()) {
|
|
|
888
890
|
return value.version;
|
|
889
891
|
} catch {}
|
|
890
892
|
}
|
|
891
|
-
return "0.1.
|
|
893
|
+
return "0.1.2";
|
|
892
894
|
}
|
|
893
895
|
function parseVersion(text) {
|
|
894
896
|
const match = /(\d+)\.(\d+)\.(\d+)/.exec(text);
|
|
@@ -1269,7 +1271,8 @@ function renderProjectToml(input) {
|
|
|
1269
1271
|
`check = ${tomlBasicString(input.check)}`,
|
|
1270
1272
|
`paths = [${paths}]`,
|
|
1271
1273
|
`head = ${tomlBasicString(input.head)}`,
|
|
1272
|
-
|
|
1274
|
+
"# Accepted work is committed here. Keep it a branch nobody has checked out; serve creates it.",
|
|
1275
|
+
`branch = ${tomlBasicString(input.branch ?? "minga")}`,
|
|
1273
1276
|
"",
|
|
1274
1277
|
"[rules]",
|
|
1275
1278
|
"# width = 3",
|
|
@@ -1365,6 +1368,12 @@ function parseStatus(text) {
|
|
|
1365
1368
|
return changes;
|
|
1366
1369
|
}
|
|
1367
1370
|
function branchOf(run) {
|
|
1371
|
+
try {
|
|
1372
|
+
const upstream = run(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]).trim();
|
|
1373
|
+
const match = /^origin\/(.+)$/.exec(upstream);
|
|
1374
|
+
if (match?.[1])
|
|
1375
|
+
return match[1];
|
|
1376
|
+
} catch {}
|
|
1368
1377
|
try {
|
|
1369
1378
|
const ref = run(["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]).trim();
|
|
1370
1379
|
const match = /^refs\/remotes\/origin\/(.+)$/.exec(ref);
|
|
@@ -1691,7 +1700,7 @@ async function dispatch(cli, deps) {
|
|
|
1691
1700
|
scope: required("scope"),
|
|
1692
1701
|
check: required("check"),
|
|
1693
1702
|
paths,
|
|
1694
|
-
branch: str(cli.options.branch) ?? "
|
|
1703
|
+
branch: str(cli.options.branch) ?? "minga",
|
|
1695
1704
|
force: cli.options.force === true,
|
|
1696
1705
|
url: str(cli.options.url)
|
|
1697
1706
|
}),
|
|
@@ -2198,7 +2207,7 @@ agent commands
|
|
|
2198
2207
|
sync [--discard]
|
|
2199
2208
|
|
|
2200
2209
|
maintainer commands
|
|
2201
|
-
init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch
|
|
2210
|
+
init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch minga] [--force]
|
|
2202
2211
|
serve [--repo <dir>] [--port 7777] [--host 127.0.0.1] [server flags...]
|
|
2203
2212
|
doctor [--repo <dir>]
|
|
2204
2213
|
mcp [--dir <dir>]
|
|
@@ -2272,7 +2281,7 @@ says the project is finished. --json prints the raw response.`,
|
|
|
2272
2281
|
Fetches origin, then drops local files left by an accepted submit when they
|
|
2273
2282
|
match the fetched branch head or come from your last accepted submission.
|
|
2274
2283
|
Other changes are refused unless --discard is given.`,
|
|
2275
|
-
init: `usage: minga init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch
|
|
2284
|
+
init: `usage: minga init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch minga] [--force]
|
|
2276
2285
|
|
|
2277
2286
|
Non-interactive scaffold: creates .minga/head.json, project.toml and adds
|
|
2278
2287
|
.minga/ to .gitignore. dir must already be a git repository. --force overwrites
|
package/package.json
CHANGED
package/src/cli/commands.ts
CHANGED
|
@@ -523,6 +523,8 @@ export async function waitForSubmission(
|
|
|
523
523
|
}
|
|
524
524
|
// The final block below is the only place that reports the verdict.
|
|
525
525
|
if (isFinal(view.status)) return view;
|
|
526
|
+
// A server that answers at once without news must not turn this into a busy loop.
|
|
527
|
+
if (!changed) await new Promise((resolve) => setTimeout(resolve, 250));
|
|
526
528
|
}
|
|
527
529
|
throw new Error(`submission ${id} has no verdict yet; check it with "minga result ${id}"`);
|
|
528
530
|
}
|
package/src/cli/dispatch.ts
CHANGED
|
@@ -297,7 +297,7 @@ export async function dispatch(cli: ParsedCli, deps: DispatchDeps): Promise<Disp
|
|
|
297
297
|
scope: required("scope"),
|
|
298
298
|
check: required("check"),
|
|
299
299
|
paths,
|
|
300
|
-
branch: str(cli.options.branch) ?? "
|
|
300
|
+
branch: str(cli.options.branch) ?? "minga",
|
|
301
301
|
force: cli.options.force === true,
|
|
302
302
|
url: str(cli.options.url),
|
|
303
303
|
}),
|
package/src/cli/init.ts
CHANGED
|
@@ -62,7 +62,8 @@ export function renderProjectToml(input: TomlInput): string {
|
|
|
62
62
|
`check = ${tomlBasicString(input.check)}`,
|
|
63
63
|
`paths = [${paths}]`,
|
|
64
64
|
`head = ${tomlBasicString(input.head)}`,
|
|
65
|
-
|
|
65
|
+
"# Accepted work is committed here. Keep it a branch nobody has checked out; serve creates it.",
|
|
66
|
+
`branch = ${tomlBasicString(input.branch ?? "minga")}`,
|
|
66
67
|
"",
|
|
67
68
|
"[rules]",
|
|
68
69
|
"# width = 3",
|
package/src/cli/join-doc.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function renderJoinDoc(project: ProjectInfo, baseUrl: string): string {
|
|
|
33
33
|
` accept ${acceptText(project.rules.accept)}`,
|
|
34
34
|
"",
|
|
35
35
|
"GET THE CODE",
|
|
36
|
-
` git clone ${base}/repo.git work && cd work`,
|
|
36
|
+
` git clone -b ${project.branch ?? "main"} ${base}/repo.git work && cd work`,
|
|
37
37
|
" Run every `minga` command from inside that checkout: submit reads file paths",
|
|
38
38
|
" relative to cwd. The repo git-ignores .minga/; keep it out of commits.",
|
|
39
39
|
" The clone is read-only: pushes are refused, accepted work reaches the branch",
|
package/src/cli/main.ts
CHANGED
|
@@ -36,7 +36,7 @@ agent commands
|
|
|
36
36
|
sync [--discard]
|
|
37
37
|
|
|
38
38
|
maintainer commands
|
|
39
|
-
init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch
|
|
39
|
+
init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch minga] [--force]
|
|
40
40
|
serve [--repo <dir>] [--port 7777] [--host 127.0.0.1] [server flags...]
|
|
41
41
|
doctor [--repo <dir>]
|
|
42
42
|
mcp [--dir <dir>]
|
|
@@ -111,7 +111,7 @@ says the project is finished. --json prints the raw response.`,
|
|
|
111
111
|
Fetches origin, then drops local files left by an accepted submit when they
|
|
112
112
|
match the fetched branch head or come from your last accepted submission.
|
|
113
113
|
Other changes are refused unless --discard is given.`,
|
|
114
|
-
init: `usage: minga init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch
|
|
114
|
+
init: `usage: minga init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch minga] [--force]
|
|
115
115
|
|
|
116
116
|
Non-interactive scaffold: creates .minga/head.json, project.toml and adds
|
|
117
117
|
.minga/ to .gitignore. dir must already be a git repository. --force overwrites
|
package/src/cli/runtime.ts
CHANGED
package/src/cli/sync.ts
CHANGED
|
@@ -65,6 +65,14 @@ function parseStatus(text: string): Change[] {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function branchOf(run: GitRunner): string {
|
|
68
|
+
try {
|
|
69
|
+
// A clone made with -b <branch> tracks origin/<branch>: follow that first.
|
|
70
|
+
const upstream = run(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]).trim();
|
|
71
|
+
const match = /^origin\/(.+)$/.exec(upstream);
|
|
72
|
+
if (match?.[1]) return match[1];
|
|
73
|
+
} catch {
|
|
74
|
+
// Detached HEAD or no upstream: fall back to origin/HEAD.
|
|
75
|
+
}
|
|
68
76
|
try {
|
|
69
77
|
const ref = run(["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]).trim();
|
|
70
78
|
const match = /^refs\/remotes\/origin\/(.+)$/.exec(ref);
|
package/src/core/protocol.ts
CHANGED
package/src/server/app.ts
CHANGED
|
@@ -133,7 +133,7 @@ export function createApp(deps: AppDeps) {
|
|
|
133
133
|
// ---------------------------------------------------------------- helpers
|
|
134
134
|
const leaseUntil = () => new Date(now().getTime() + state.rules.leaseMinutes * 60_000).toISOString();
|
|
135
135
|
const projectInfo = (): ProjectInfo => ({
|
|
136
|
-
name: cfg.name, goal: cfg.goal, scope: cfg.scope, check: cfg.check, paths: cfg.paths, headAgent: headId, rules: state.rules,
|
|
136
|
+
name: cfg.name, goal: cfg.goal, scope: cfg.scope, check: cfg.check, paths: cfg.paths, headAgent: headId, rules: state.rules, branch: cfg.branch,
|
|
137
137
|
});
|
|
138
138
|
const json = (data: unknown, status = 200) => Response.json(data, { status });
|
|
139
139
|
const fail = (status: number, error: string, detail?: string) => json({ error, ...(detail ? { detail } : {}) } satisfies ErrorBody, status);
|
package/src/server/main.ts
CHANGED
|
@@ -29,6 +29,7 @@ const { values } = parseArgs({
|
|
|
29
29
|
"check-concurrency": { type: "string" },
|
|
30
30
|
"join-limit": { type: "string", default: "20" },
|
|
31
31
|
"dry-run": { type: "boolean", default: false },
|
|
32
|
+
"allow-checked-out": { type: "boolean", default: false },
|
|
32
33
|
},
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -54,7 +55,29 @@ let head: string;
|
|
|
54
55
|
try {
|
|
55
56
|
head = await branchHead(repoDir, cfg.branch);
|
|
56
57
|
} catch {
|
|
57
|
-
|
|
58
|
+
// A missing project branch starts at the current commit (init picks a dedicated "minga" branch).
|
|
59
|
+
const start = Bun.spawnSync(["git", "-C", repoDir, "rev-parse", "--verify", "--quiet", "HEAD^{commit}"]);
|
|
60
|
+
const startSha = start.stdout.toString().trim();
|
|
61
|
+
if (start.exitCode !== 0 || startSha === "") {
|
|
62
|
+
die(`branch ${cfg.branch} does not exist in ${repoDir} and there is no commit to start it from`, "commit something first");
|
|
63
|
+
}
|
|
64
|
+
if (!values["dry-run"]) {
|
|
65
|
+
const made = Bun.spawnSync(["git", "-C", repoDir, "update-ref", `refs/heads/${cfg.branch}`, startSha, ""]);
|
|
66
|
+
if (made.exitCode !== 0) die(`cannot create branch ${cfg.branch}: ${made.stderr.toString().trim()}`);
|
|
67
|
+
console.log(`minga: created branch ${cfg.branch} at ${startSha.slice(0, 12)}; accepted work lands there (merge it whenever you like)`);
|
|
68
|
+
}
|
|
69
|
+
head = startSha;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Accepted commits move the branch ref directly. If that branch is checked out, the
|
|
73
|
+
// working tree and index fall behind it and the next "git commit -a" there silently
|
|
74
|
+
// reverts the agents' work, so refuse unless told otherwise.
|
|
75
|
+
const checkedOut = checkedOutIn(repoDir, cfg.branch);
|
|
76
|
+
if (checkedOut !== null && !values["allow-checked-out"]) {
|
|
77
|
+
die(
|
|
78
|
+
`branch ${cfg.branch} is checked out in ${checkedOut}; accepted commits would move it under that working tree`,
|
|
79
|
+
`set branch = "minga" in project.toml (serve creates it), check out another branch there, or pass --allow-checked-out`,
|
|
80
|
+
);
|
|
58
81
|
}
|
|
59
82
|
const concurrency = values["check-concurrency"] !== undefined
|
|
60
83
|
? Math.max(1, Number(values["check-concurrency"]) || 1)
|
|
@@ -70,6 +93,18 @@ if (values["dry-run"]) {
|
|
|
70
93
|
process.exit(0);
|
|
71
94
|
}
|
|
72
95
|
|
|
96
|
+
/** The worktree path that has `branch` checked out, or null. Check-pool worktrees are detached. */
|
|
97
|
+
function checkedOutIn(repo: string, branch: string): string | null {
|
|
98
|
+
const list = Bun.spawnSync(["git", "-C", repo, "worktree", "list", "--porcelain"]);
|
|
99
|
+
if (list.exitCode !== 0) return null;
|
|
100
|
+
let path: string | null = null;
|
|
101
|
+
for (const line of list.stdout.toString().split(/\r?\n/)) {
|
|
102
|
+
if (line.startsWith("worktree ")) path = line.slice("worktree ".length);
|
|
103
|
+
else if (line === `branch refs/heads/${branch}` && path !== null) return path;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
73
108
|
const LOOPBACK = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
74
109
|
if (!LOOPBACK.has(values.host!)) {
|
|
75
110
|
console.warn(
|