minga-swarm 0.1.0 → 0.1.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/AGENTS.md +38 -4
- package/README.md +15 -1
- package/dist/minga.mjs +519 -75
- package/package.json +1 -1
- package/src/cli/client.ts +9 -3
- package/src/cli/commands.ts +216 -24
- package/src/cli/dispatch.ts +85 -20
- package/src/cli/doctor.ts +53 -2
- package/src/cli/init.ts +3 -2
- package/src/cli/join-doc.ts +29 -14
- package/src/cli/main.ts +26 -5
- package/src/cli/mcp.ts +54 -13
- package/src/cli/runtime.ts +2 -2
- package/src/cli/store.ts +60 -3
- package/src/cli/sync.ts +149 -0
- package/src/core/protocol.ts +25 -2
- package/src/log/reducer.ts +6 -0
- package/src/sched/scheduler.ts +17 -5
- package/src/server/app.ts +64 -9
- package/src/server/git-http.ts +76 -0
- package/src/server/latency.ts +38 -0
- package/src/server/main.ts +3 -1
- package/src/ui/dev-server.ts +39 -21
- package/src/ui/index.html +266 -116
package/dist/minga.mjs
CHANGED
|
@@ -124,6 +124,9 @@ var COMMAND_OPTIONS = {
|
|
|
124
124
|
vote: {},
|
|
125
125
|
status: {},
|
|
126
126
|
board: {},
|
|
127
|
+
tasks: {
|
|
128
|
+
open: { type: "boolean" }
|
|
129
|
+
},
|
|
127
130
|
init: {
|
|
128
131
|
name: { type: "string" },
|
|
129
132
|
goal: { type: "string" },
|
|
@@ -136,6 +139,9 @@ var COMMAND_OPTIONS = {
|
|
|
136
139
|
doctor: {
|
|
137
140
|
repo: { type: "string" }
|
|
138
141
|
},
|
|
142
|
+
sync: {
|
|
143
|
+
discard: { type: "boolean" }
|
|
144
|
+
},
|
|
139
145
|
mcp: {}
|
|
140
146
|
};
|
|
141
147
|
var HEAD_OPTIONS = {
|
|
@@ -153,6 +159,9 @@ var HEAD_OPTIONS = {
|
|
|
153
159
|
ban: {
|
|
154
160
|
reason: { type: "string" }
|
|
155
161
|
},
|
|
162
|
+
note: {
|
|
163
|
+
kind: { type: "string" }
|
|
164
|
+
},
|
|
156
165
|
close: {
|
|
157
166
|
reason: { type: "string" }
|
|
158
167
|
}
|
|
@@ -329,18 +338,23 @@ async function joinCommand(client, input) {
|
|
|
329
338
|
`${response.rejoin ? "rejoined" : "joined"} ${response.project.name} as agent ${response.agent}`,
|
|
330
339
|
`goal: ${response.project.goal}`,
|
|
331
340
|
`scope: ${response.project.scope}`,
|
|
332
|
-
`rules: ${formatRules(response.project.rules)}
|
|
341
|
+
`rules: ${formatRules(response.project.rules)}`,
|
|
342
|
+
"",
|
|
343
|
+
`get the code: git clone ${input.url.replace(/\/+$/, "")}/repo.git work && cd work`,
|
|
344
|
+
"run minga from inside that checkout; submit reads files relative to cwd"
|
|
333
345
|
];
|
|
334
346
|
if (response.live.length > 0)
|
|
335
347
|
lines.push(`live attempts from before: ${response.live.join(", ")}`);
|
|
336
348
|
return { identity, result: { text: lines.join(`
|
|
337
349
|
`), data: response } };
|
|
338
350
|
}
|
|
339
|
-
function formatAssignment(a) {
|
|
351
|
+
function formatAssignment(a, headAgent) {
|
|
352
|
+
const headMark = (agent) => headAgent !== undefined && agent === headAgent ? "head: " : "";
|
|
340
353
|
const lines = [
|
|
341
354
|
`attempt ${a.attempt}`,
|
|
342
355
|
`role ${a.role}`,
|
|
343
356
|
`lease ${a.leaseUntil}`,
|
|
357
|
+
...a.head ? [`head ${a.head.slice(0, 7)} (minga sync if your checkout is older)`] : [],
|
|
344
358
|
`task ${a.task.id} ${a.task.title} (${a.task.points} points)`
|
|
345
359
|
];
|
|
346
360
|
if (a.path.length > 0) {
|
|
@@ -348,12 +362,13 @@ function formatAssignment(a) {
|
|
|
348
362
|
}
|
|
349
363
|
lines.push("body:", indent(a.task.body.length > 0 ? a.task.body : "(empty)"));
|
|
350
364
|
if (a.handoff) {
|
|
351
|
-
lines.push(`handoff ${a.handoff.id} (${a.handoff.kind}) ${a.handoff.text}`);
|
|
365
|
+
lines.push(`handoff ${a.handoff.id} ${headMark(a.handoff.agent)}(${a.handoff.kind}) ${a.handoff.text}`);
|
|
352
366
|
}
|
|
353
367
|
if (a.notes.length > 0) {
|
|
354
368
|
lines.push("notes:");
|
|
355
|
-
for (const note of a.notes)
|
|
356
|
-
lines.push(` ${note.id} ${note.agent} ${note.kind}: ${note.text}`);
|
|
369
|
+
for (const note of a.notes) {
|
|
370
|
+
lines.push(` ${note.id} ${headMark(note.agent)}${note.agent} ${note.kind}: ${note.text}`);
|
|
371
|
+
}
|
|
357
372
|
}
|
|
358
373
|
if (a.others.length > 0) {
|
|
359
374
|
lines.push("others on this task:");
|
|
@@ -380,10 +395,23 @@ async function nextCommand(client, input = {}) {
|
|
|
380
395
|
...input.approach !== undefined ? { approach: input.approach } : {},
|
|
381
396
|
...chunk > 0 ? { wait: chunk } : {}
|
|
382
397
|
});
|
|
383
|
-
if (response.
|
|
384
|
-
return { text:
|
|
398
|
+
if (response.done === true) {
|
|
399
|
+
return { text: "the project has no open tasks left. Stop here.", data: response };
|
|
400
|
+
}
|
|
401
|
+
if (response.assignment) {
|
|
402
|
+
let headAgent;
|
|
403
|
+
if (response.assignment.notes.length > 0 || response.assignment.handoff) {
|
|
404
|
+
try {
|
|
405
|
+
headAgent = (await client.project()).headAgent;
|
|
406
|
+
} catch {}
|
|
407
|
+
}
|
|
408
|
+
return { text: formatAssignment(response.assignment, headAgent), data: response };
|
|
409
|
+
}
|
|
385
410
|
last = response;
|
|
386
|
-
|
|
411
|
+
if (chunk > 0) {
|
|
412
|
+
const left = Math.max(0, Math.ceil(total - (Date.now() - started) / 1000));
|
|
413
|
+
input.onProgress?.(`no free task yet; waiting (${left}s left)`);
|
|
414
|
+
}
|
|
387
415
|
if (total === 0 || chunk <= 0)
|
|
388
416
|
break;
|
|
389
417
|
if (Date.now() - t0 < 50) {
|
|
@@ -395,10 +423,19 @@ async function nextCommand(client, input = {}) {
|
|
|
395
423
|
}
|
|
396
424
|
const wait = last?.retryAfterSeconds ?? 60;
|
|
397
425
|
return {
|
|
398
|
-
text: `nothing to do, retry in ${wait}s`,
|
|
426
|
+
text: total === 0 ? 'nothing to do right now; run "minga next --wait 600" to wait for a task' : `nothing to do, retry in ${wait}s`,
|
|
399
427
|
data: last ?? { assignment: null, retryAfterSeconds: wait }
|
|
400
428
|
};
|
|
401
429
|
}
|
|
430
|
+
var SUBMIT_MESSAGE_MAX = 200;
|
|
431
|
+
function fitSubmitMessage(message) {
|
|
432
|
+
if (message.length <= SUBMIT_MESSAGE_MAX)
|
|
433
|
+
return { message };
|
|
434
|
+
const first = message.split(`
|
|
435
|
+
`)[0] ?? "";
|
|
436
|
+
const fitted = first.length > SUBMIT_MESSAGE_MAX ? `${first.slice(0, SUBMIT_MESSAGE_MAX - 3)}...` : first;
|
|
437
|
+
return { message: fitted, notice: `submit message over ${SUBMIT_MESSAGE_MAX} chars; using "${fitted}"` };
|
|
438
|
+
}
|
|
402
439
|
function readSubmissionFiles(root, files) {
|
|
403
440
|
const resolvedRoot = resolve(root);
|
|
404
441
|
const out = {};
|
|
@@ -419,20 +456,30 @@ function isFinal(status) {
|
|
|
419
456
|
}
|
|
420
457
|
async function waitForSubmission(client, id, onProgress, initialStatus = "queued") {
|
|
421
458
|
let lastStatus = initialStatus;
|
|
459
|
+
let lastRuns = 0;
|
|
422
460
|
for (let i = 0;i < 1000; i++) {
|
|
423
461
|
const view = await client.submission(id, 30);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
462
|
+
const changed = view.status !== lastStatus || view.runs !== lastRuns;
|
|
463
|
+
lastStatus = view.status;
|
|
464
|
+
lastRuns = view.runs;
|
|
465
|
+
if (view.status === "checking" && changed) {
|
|
466
|
+
onProgress?.(`checking ${id} (run ${view.runs})`);
|
|
428
467
|
}
|
|
429
|
-
if (isFinal(view.status))
|
|
430
|
-
onProgress?.(`verdict ${view.status} ${id}`);
|
|
468
|
+
if (isFinal(view.status))
|
|
431
469
|
return view;
|
|
432
|
-
}
|
|
433
470
|
}
|
|
434
471
|
throw new Error(`submission ${id} has no verdict yet; check it with "minga result ${id}"`);
|
|
435
472
|
}
|
|
473
|
+
function staleReason(view) {
|
|
474
|
+
if (!("stale" in view) || view.stale !== true)
|
|
475
|
+
return;
|
|
476
|
+
const tail = view.outputTail ?? "";
|
|
477
|
+
if (/branch kept moving/i.test(tail))
|
|
478
|
+
return "the branch kept moving";
|
|
479
|
+
if (/\bclosed\b/i.test(tail))
|
|
480
|
+
return "the task closed first";
|
|
481
|
+
return "unknown reason";
|
|
482
|
+
}
|
|
436
483
|
function renderSubmission(view) {
|
|
437
484
|
const id = "submission" in view ? view.submission : view.id;
|
|
438
485
|
if (view.status === "queued") {
|
|
@@ -440,17 +487,33 @@ function renderSubmission(view) {
|
|
|
440
487
|
return `submission ${id}: queued${position}`;
|
|
441
488
|
}
|
|
442
489
|
const lines = [];
|
|
443
|
-
if (view.status === "checking")
|
|
490
|
+
if (view.status === "checking") {
|
|
444
491
|
lines.push(`submission ${id}: checking`);
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
492
|
+
return lines.join(`
|
|
493
|
+
`);
|
|
494
|
+
}
|
|
495
|
+
const attempt = "attempt" in view ? view.attempt : id;
|
|
496
|
+
const exitCode = view.exitCode ?? 0;
|
|
497
|
+
lines.push(`verdict: ${view.status}`, `submission ${id}`);
|
|
498
|
+
lines.push(`exit code: ${exitCode}${view.timedOut ? " (timed out)" : ""}`);
|
|
499
|
+
if (view.status === "rejected") {
|
|
500
|
+
const reason = staleReason(view);
|
|
501
|
+
if (reason !== undefined)
|
|
502
|
+
lines.push(`stale: ${reason}`);
|
|
503
|
+
}
|
|
448
504
|
if (view.outputTail && view.outputTail.length > 0) {
|
|
449
505
|
lines.push("output tail:", indent(view.outputTail));
|
|
506
|
+
} else if (view.status === "rejected") {
|
|
507
|
+
lines.push(`output: (the check printed nothing; exit code ${exitCode})`);
|
|
450
508
|
}
|
|
451
509
|
if (view.commit !== undefined)
|
|
452
510
|
lines.push(`commit: ${view.commit}`);
|
|
453
511
|
lines.push(`points: ${view.points}`);
|
|
512
|
+
if (view.status === "accepted") {
|
|
513
|
+
lines.push("next: minga sync && minga next --wait 600");
|
|
514
|
+
} else if (view.status === "rejected") {
|
|
515
|
+
lines.push(`next: fix and run "minga submit ${attempt} ..." again, or ` + `"minga release ${attempt} --handoff \\"...\\""`);
|
|
516
|
+
}
|
|
454
517
|
return lines.join(`
|
|
455
518
|
`);
|
|
456
519
|
}
|
|
@@ -468,10 +531,10 @@ async function submitCommand(client, input) {
|
|
|
468
531
|
files,
|
|
469
532
|
...input.model !== undefined ? { model: input.model } : {}
|
|
470
533
|
});
|
|
471
|
-
const progress = `queued ${queued.submission} #${queued.position}`;
|
|
534
|
+
const progress = `queued ${queued.submission} (#${queued.position} in line)`;
|
|
472
535
|
input.onProgress?.(progress);
|
|
473
536
|
if (input.wait === false)
|
|
474
|
-
return { text:
|
|
537
|
+
return { text: renderSubmission(queued), data: queued };
|
|
475
538
|
const final = await waitForSubmission(client, queued.submission, input.onProgress);
|
|
476
539
|
return { text: renderSubmission(final), data: final };
|
|
477
540
|
}
|
|
@@ -542,19 +605,41 @@ async function voteCommand(client, input) {
|
|
|
542
605
|
return { text: lines.join(`
|
|
543
606
|
`), data: response };
|
|
544
607
|
}
|
|
545
|
-
|
|
608
|
+
function leaseText(leaseUntil) {
|
|
609
|
+
const ms = Date.parse(leaseUntil) - Date.now();
|
|
610
|
+
if (!Number.isFinite(ms))
|
|
611
|
+
return leaseUntil;
|
|
612
|
+
return ms > 0 ? `${Math.ceil(ms / 60000)}m left` : "expired";
|
|
613
|
+
}
|
|
614
|
+
async function statusCommand(client, identity) {
|
|
546
615
|
const project = await client.project();
|
|
547
|
-
const
|
|
616
|
+
const data = { agent: identity.agent, project };
|
|
617
|
+
const lines = [
|
|
548
618
|
`project: ${project.name}`,
|
|
549
619
|
`goal: ${project.goal}`,
|
|
550
620
|
`scope: ${project.scope}`,
|
|
551
621
|
`check: ${project.check}`,
|
|
552
622
|
`paths: ${project.paths.join(", ")}`,
|
|
553
623
|
`rules: ${formatRules(project.rules)}`,
|
|
554
|
-
`your agent: ${agent}`
|
|
555
|
-
]
|
|
556
|
-
|
|
557
|
-
|
|
624
|
+
`your agent: ${identity.agent}`
|
|
625
|
+
];
|
|
626
|
+
const assignment = identity.lastAssignment;
|
|
627
|
+
if (assignment) {
|
|
628
|
+
lines.push(`attempt: ${assignment.attempt} (${assignment.role}) on ${assignment.task} — ` + `lease ${leaseText(assignment.leaseUntil)}`);
|
|
629
|
+
data.assignment = assignment;
|
|
630
|
+
}
|
|
631
|
+
if (identity.lastSubmission) {
|
|
632
|
+
try {
|
|
633
|
+
const view = await client.submission(identity.lastSubmission, 0);
|
|
634
|
+
const position = view.status === "queued" && view.position !== undefined ? ` #${view.position}` : "";
|
|
635
|
+
lines.push(`submission: ${view.id} ${view.status}${position}`);
|
|
636
|
+
data.submission = view;
|
|
637
|
+
} catch {
|
|
638
|
+
lines.push(`submission: ${identity.lastSubmission} (unavailable)`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return { text: lines.join(`
|
|
642
|
+
`), data };
|
|
558
643
|
}
|
|
559
644
|
async function boardCommand(client) {
|
|
560
645
|
const leaderboard = await client.leaderboard();
|
|
@@ -574,6 +659,49 @@ async function boardCommand(client) {
|
|
|
574
659
|
`);
|
|
575
660
|
return { text, data: leaderboard };
|
|
576
661
|
}
|
|
662
|
+
function tasksCommand(client, input = {}) {
|
|
663
|
+
return client.tasks().then((overview) => ({ text: renderTasks(overview, input), data: overview }));
|
|
664
|
+
}
|
|
665
|
+
function renderTaskLine(task, depth = 0, area = false) {
|
|
666
|
+
const status = task.status === "open" && task.live > 0 ? `open · ${task.live} live` : task.status;
|
|
667
|
+
const line = `${task.id} ${status.padEnd(10)} ${task.points} pts ${task.title}${area ? " [area]" : ""}`;
|
|
668
|
+
return `${" ".repeat(depth)}${line}`;
|
|
669
|
+
}
|
|
670
|
+
function renderTasks(overview, input = {}) {
|
|
671
|
+
const byId = new Map(overview.tasks.map((t) => [t.id, t]));
|
|
672
|
+
const children = new Map;
|
|
673
|
+
for (const t of overview.tasks) {
|
|
674
|
+
const parent = t.parent && byId.has(t.parent) ? t.parent : null;
|
|
675
|
+
const list = children.get(parent) ?? [];
|
|
676
|
+
list.push(t);
|
|
677
|
+
children.set(parent, list);
|
|
678
|
+
}
|
|
679
|
+
const lines = [];
|
|
680
|
+
const seen = new Set;
|
|
681
|
+
const visit = (parent, depth) => {
|
|
682
|
+
for (const t of children.get(parent) ?? []) {
|
|
683
|
+
if (seen.has(t.id))
|
|
684
|
+
continue;
|
|
685
|
+
seen.add(t.id);
|
|
686
|
+
if (!input.openOnly || t.status === "open") {
|
|
687
|
+
lines.push(renderTaskLine(t, depth, byId.get(t.id)?.leaf === false));
|
|
688
|
+
}
|
|
689
|
+
visit(t.id, depth + 1);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
visit(null, 0);
|
|
693
|
+
for (const t of overview.tasks) {
|
|
694
|
+
if (!seen.has(t.id)) {
|
|
695
|
+
seen.add(t.id);
|
|
696
|
+
if (!input.openOnly || t.status === "open") {
|
|
697
|
+
lines.push(renderTaskLine(t, 0, !t.leaf));
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
const footer = overview.done ? "project finished" : `open leaf tasks: ${overview.open}`;
|
|
702
|
+
return lines.length > 0 ? [...lines, "", footer].join(`
|
|
703
|
+
`) : footer;
|
|
704
|
+
}
|
|
577
705
|
function headKeygenCommand(existing, url) {
|
|
578
706
|
const keys = existing ? { publicKey: existing.publicKey, privateKey: existing.privateKey } : generateKeyPair();
|
|
579
707
|
const identity = {
|
|
@@ -625,6 +753,17 @@ async function headBanCommand(client, input) {
|
|
|
625
753
|
const response = await client.headBan({ agent: input.agent, reason: input.reason });
|
|
626
754
|
return { text: `banned ${input.agent}`, data: response };
|
|
627
755
|
}
|
|
756
|
+
async function headNoteCommand(client, input) {
|
|
757
|
+
const response = await client.headNote({
|
|
758
|
+
task: input.task,
|
|
759
|
+
text: input.text,
|
|
760
|
+
...input.kind !== undefined ? { kind: input.kind } : {}
|
|
761
|
+
});
|
|
762
|
+
return {
|
|
763
|
+
text: `note ${response.note.id} on ${input.task} (${response.note.kind})`,
|
|
764
|
+
data: response
|
|
765
|
+
};
|
|
766
|
+
}
|
|
628
767
|
async function headCloseCommand(client, input) {
|
|
629
768
|
const response = await client.headClose({
|
|
630
769
|
task: input.task,
|
|
@@ -678,6 +817,7 @@ function createClient(baseUrl, keys, fetchImpl = fetch) {
|
|
|
678
817
|
return send("GET", `/api/events?${query}`);
|
|
679
818
|
},
|
|
680
819
|
leaderboard: () => send("GET", "/api/leaderboard"),
|
|
820
|
+
tasks: () => send("GET", "/api/tasks"),
|
|
681
821
|
submission: (id, waitSeconds = 0) => {
|
|
682
822
|
const wait = Math.max(0, Math.min(30, Math.floor(waitSeconds)));
|
|
683
823
|
const query = wait > 0 ? `?wait=${wait}` : "";
|
|
@@ -695,6 +835,7 @@ function createClient(baseUrl, keys, fetchImpl = fetch) {
|
|
|
695
835
|
headDecide: (body) => send("POST", "/api/head/decide", body),
|
|
696
836
|
headRule: (body) => send("POST", "/api/head/rule", body),
|
|
697
837
|
headBan: (body) => send("POST", "/api/head/ban", body),
|
|
838
|
+
headNote: (body) => send("POST", "/api/head/note", body),
|
|
698
839
|
headClose: (body) => send("POST", "/api/head/close", body)
|
|
699
840
|
};
|
|
700
841
|
}
|
|
@@ -729,7 +870,7 @@ function findPackageRoot(fromUrl = import.meta.url) {
|
|
|
729
870
|
if (existsSync(file)) {
|
|
730
871
|
try {
|
|
731
872
|
const value = JSON.parse(readFileSync2(file, "utf8"));
|
|
732
|
-
if (value.name === "minga-swarm" || value.name === "minga")
|
|
873
|
+
if (value.name === "minga-swarm" || (value.name === "minga-swarm" || value.name === "minga"))
|
|
733
874
|
return dir;
|
|
734
875
|
} catch {}
|
|
735
876
|
}
|
|
@@ -747,7 +888,7 @@ function packageVersion(root = findPackageRoot()) {
|
|
|
747
888
|
return value.version;
|
|
748
889
|
} catch {}
|
|
749
890
|
}
|
|
750
|
-
return "0.1.
|
|
891
|
+
return "0.1.1";
|
|
751
892
|
}
|
|
752
893
|
function parseVersion(text) {
|
|
753
894
|
const match = /(\d+)\.(\d+)\.(\d+)/.exec(text);
|
|
@@ -859,6 +1000,29 @@ async function serveCommand(raw, deps = {}) {
|
|
|
859
1000
|
// src/cli/doctor.ts
|
|
860
1001
|
import { existsSync as existsSync2 } from "node:fs";
|
|
861
1002
|
import { join as join2, resolve as resolve2 } from "node:path";
|
|
1003
|
+
function dryRunError(raw) {
|
|
1004
|
+
try {
|
|
1005
|
+
const parsed = JSON.parse(raw);
|
|
1006
|
+
if (parsed && typeof parsed.error === "string" && parsed.error.length > 0) {
|
|
1007
|
+
return parsed.fix ? `${parsed.error} (fix: ${parsed.fix})` : parsed.error;
|
|
1008
|
+
}
|
|
1009
|
+
} catch {}
|
|
1010
|
+
return null;
|
|
1011
|
+
}
|
|
1012
|
+
function dryRunDetail(raw) {
|
|
1013
|
+
let parsed;
|
|
1014
|
+
try {
|
|
1015
|
+
parsed = JSON.parse(raw);
|
|
1016
|
+
} catch {
|
|
1017
|
+
return null;
|
|
1018
|
+
}
|
|
1019
|
+
const info = parsed?.project;
|
|
1020
|
+
if (!info || typeof info !== "object")
|
|
1021
|
+
return null;
|
|
1022
|
+
const sha = typeof info.head === "string" && info.head.length > 0 ? info.head.slice(0, 7) : "unknown";
|
|
1023
|
+
const slots = typeof parsed.checkConcurrency === "number" && parsed.checkConcurrency > 0 ? parsed.checkConcurrency : 1;
|
|
1024
|
+
return `${info.name ?? "project"}: check "${info.check ?? ""}", branch ${info.branch ?? "?"} @ ${sha}, ` + `${slots} check slot(s), recheck ${info.recheck ?? "?"}`;
|
|
1025
|
+
}
|
|
862
1026
|
function doctorCommand(input, deps = {}) {
|
|
863
1027
|
const runner = deps.syncRunner ?? defaultSyncRunner;
|
|
864
1028
|
const checks = [];
|
|
@@ -892,6 +1056,7 @@ function doctorCommand(input, deps = {}) {
|
|
|
892
1056
|
detail: `${tomlPath} is missing`,
|
|
893
1057
|
fix: `minga init ${repoDir} --name "<name>" --goal "<goal>" --scope "<scope>" --check "<check>" --paths "<glob>"`
|
|
894
1058
|
});
|
|
1059
|
+
let configDryRun;
|
|
895
1060
|
if (bun.ok) {
|
|
896
1061
|
const root = input.packageRoot === undefined ? deps.packageRoot === undefined ? findPackageRoot() : deps.packageRoot : input.packageRoot;
|
|
897
1062
|
if (root === null) {
|
|
@@ -904,7 +1069,16 @@ function doctorCommand(input, deps = {}) {
|
|
|
904
1069
|
} else {
|
|
905
1070
|
const worker = join2(root, "src", "server", "main.ts");
|
|
906
1071
|
const dry = runner(deps.bunPath ?? "bun", [worker, "--repo", repoDir, "--dry-run"]);
|
|
907
|
-
const
|
|
1072
|
+
const raw = dry.stdout.trim() || dry.stderr.trim() || `exit ${dry.status}`;
|
|
1073
|
+
const compact = dry.status === 0 ? dryRunDetail(raw) : null;
|
|
1074
|
+
if (compact !== null) {
|
|
1075
|
+
try {
|
|
1076
|
+
configDryRun = JSON.parse(raw);
|
|
1077
|
+
} catch {}
|
|
1078
|
+
}
|
|
1079
|
+
const firstLine = raw.split(`
|
|
1080
|
+
`)[0] ?? raw;
|
|
1081
|
+
const detail = compact ?? (dry.status === 0 ? firstLine : dryRunError(raw) ?? firstLine);
|
|
908
1082
|
add(dry.status === 0 ? { name: "config", ok: true, detail } : { name: "config", ok: false, detail, fix: "fix project.toml and re-run minga doctor" });
|
|
909
1083
|
}
|
|
910
1084
|
}
|
|
@@ -915,15 +1089,18 @@ function doctorCommand(input, deps = {}) {
|
|
|
915
1089
|
...check.fix !== undefined && !check.ok ? [`(fix: ${check.fix})`] : []
|
|
916
1090
|
].join(" ")).join(`
|
|
917
1091
|
`);
|
|
918
|
-
return {
|
|
1092
|
+
return {
|
|
1093
|
+
text,
|
|
1094
|
+
data: configDryRun === undefined ? { checks } : { checks, configDryRun }
|
|
1095
|
+
};
|
|
919
1096
|
}
|
|
920
1097
|
|
|
921
1098
|
// src/cli/init.ts
|
|
922
|
-
import { existsSync as
|
|
1099
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "node:fs";
|
|
923
1100
|
import { join as join4, resolve as resolve4 } from "node:path";
|
|
924
1101
|
|
|
925
1102
|
// src/cli/store.ts
|
|
926
|
-
import { chmodSync, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
1103
|
+
import { chmodSync, existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
927
1104
|
import { dirname as dirname2, join as join3, resolve as resolve3 } from "node:path";
|
|
928
1105
|
var MINGA_DIR = ".minga";
|
|
929
1106
|
function readText(path) {
|
|
@@ -979,8 +1156,20 @@ function agentPath(dir) {
|
|
|
979
1156
|
function headPath(dir) {
|
|
980
1157
|
return join3(dir, MINGA_DIR, "head.json");
|
|
981
1158
|
}
|
|
1159
|
+
function resolveAgentDir(dir) {
|
|
1160
|
+
const start = resolveDir(dir);
|
|
1161
|
+
let current = start;
|
|
1162
|
+
for (;; ) {
|
|
1163
|
+
if (existsSync3(agentPath(current)))
|
|
1164
|
+
return current;
|
|
1165
|
+
const parent = dirname2(current);
|
|
1166
|
+
if (parent === current)
|
|
1167
|
+
return start;
|
|
1168
|
+
current = parent;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
982
1171
|
function readAgent(dir) {
|
|
983
|
-
const path = agentPath(dir);
|
|
1172
|
+
const path = agentPath(resolveAgentDir(dir));
|
|
984
1173
|
const obj = readObject(path);
|
|
985
1174
|
if (!obj)
|
|
986
1175
|
return null;
|
|
@@ -995,6 +1184,29 @@ function readAgent(dir) {
|
|
|
995
1184
|
const owner = optionalString(obj, "owner");
|
|
996
1185
|
if (owner !== undefined)
|
|
997
1186
|
identity.owner = owner;
|
|
1187
|
+
const raw = obj.lastAssignment;
|
|
1188
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
1189
|
+
const a = raw;
|
|
1190
|
+
const attempt = optionalString(a, "attempt");
|
|
1191
|
+
const role = optionalString(a, "role");
|
|
1192
|
+
const leaseUntil = optionalString(a, "leaseUntil");
|
|
1193
|
+
const task = optionalString(a, "task");
|
|
1194
|
+
if (attempt && role && leaseUntil && task) {
|
|
1195
|
+
identity.lastAssignment = { attempt, role, leaseUntil, task };
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
const lastSubmission = optionalString(obj, "lastSubmission");
|
|
1199
|
+
if (lastSubmission !== undefined)
|
|
1200
|
+
identity.lastSubmission = lastSubmission;
|
|
1201
|
+
const accepted = obj.lastAccepted;
|
|
1202
|
+
if (accepted && typeof accepted === "object" && !Array.isArray(accepted)) {
|
|
1203
|
+
const entry = accepted;
|
|
1204
|
+
const submission = optionalString(entry, "submission");
|
|
1205
|
+
const files = entry.files;
|
|
1206
|
+
if (submission && Array.isArray(files) && files.every((f) => typeof f === "string")) {
|
|
1207
|
+
identity.lastAccepted = { submission, files };
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
998
1210
|
return identity;
|
|
999
1211
|
}
|
|
1000
1212
|
function writeAgent(dir, identity) {
|
|
@@ -1008,6 +1220,12 @@ function writeAgent(dir, identity) {
|
|
|
1008
1220
|
};
|
|
1009
1221
|
if (identity.owner !== undefined)
|
|
1010
1222
|
value.owner = identity.owner;
|
|
1223
|
+
if (identity.lastAssignment !== undefined)
|
|
1224
|
+
value.lastAssignment = identity.lastAssignment;
|
|
1225
|
+
if (identity.lastSubmission !== undefined)
|
|
1226
|
+
value.lastSubmission = identity.lastSubmission;
|
|
1227
|
+
if (identity.lastAccepted !== undefined)
|
|
1228
|
+
value.lastAccepted = identity.lastAccepted;
|
|
1011
1229
|
return writeObject(agentPath(dir), value);
|
|
1012
1230
|
}
|
|
1013
1231
|
function readHead(dir) {
|
|
@@ -1053,13 +1271,14 @@ function renderProjectToml(input) {
|
|
|
1053
1271
|
`head = ${tomlBasicString(input.head)}`,
|
|
1054
1272
|
`branch = ${tomlBasicString(input.branch ?? "main")}`,
|
|
1055
1273
|
"",
|
|
1056
|
-
"
|
|
1274
|
+
"[rules]",
|
|
1057
1275
|
"# width = 3",
|
|
1058
1276
|
"# lease_minutes = 45",
|
|
1059
1277
|
"# max_attempts_per_agent = 1",
|
|
1060
1278
|
"# default_points = 10",
|
|
1061
1279
|
'# accept = "head-or-votes:3"',
|
|
1062
|
-
"
|
|
1280
|
+
"",
|
|
1281
|
+
"[rules.roles]",
|
|
1063
1282
|
"# explore = 2",
|
|
1064
1283
|
"# build = 5",
|
|
1065
1284
|
"# attack = 2",
|
|
@@ -1076,11 +1295,11 @@ function renderProjectToml(input) {
|
|
|
1076
1295
|
}
|
|
1077
1296
|
function initCommand(input) {
|
|
1078
1297
|
const dir = resolve4(input.dir);
|
|
1079
|
-
if (!
|
|
1298
|
+
if (!existsSync4(join4(dir, ".git"))) {
|
|
1080
1299
|
throw new Error(`${dir} is not a git repository; run "git init ${dir}" first`);
|
|
1081
1300
|
}
|
|
1082
1301
|
const tomlPath = join4(dir, "project.toml");
|
|
1083
|
-
if (
|
|
1302
|
+
if (existsSync4(tomlPath) && input.force !== true) {
|
|
1084
1303
|
throw new Error(`${tomlPath} already exists; pass --force to overwrite it`);
|
|
1085
1304
|
}
|
|
1086
1305
|
const { identity, result } = headKeygenCommand(readHead(dir), input.url);
|
|
@@ -1088,7 +1307,7 @@ function initCommand(input) {
|
|
|
1088
1307
|
const projectToml = renderProjectToml({ ...input, head: result.data.head });
|
|
1089
1308
|
writeFileSync2(tomlPath, projectToml, "utf8");
|
|
1090
1309
|
const gitignore = join4(dir, ".gitignore");
|
|
1091
|
-
const current =
|
|
1310
|
+
const current = existsSync4(gitignore) ? readFileSync4(gitignore, "utf8") : "";
|
|
1092
1311
|
const hasIgnore = current.split(/\r?\n/).some((line) => {
|
|
1093
1312
|
const trimmed = line.trim();
|
|
1094
1313
|
return trimmed === ".minga" || trimmed === ".minga/";
|
|
@@ -1117,6 +1336,117 @@ wrote `)}`,
|
|
|
1117
1336
|
};
|
|
1118
1337
|
}
|
|
1119
1338
|
|
|
1339
|
+
// src/cli/sync.ts
|
|
1340
|
+
import { execFileSync } from "node:child_process";
|
|
1341
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
|
|
1342
|
+
import { resolve as resolve5 } from "node:path";
|
|
1343
|
+
function firstLine(err) {
|
|
1344
|
+
const text = err instanceof Error ? err.message : String(err);
|
|
1345
|
+
return text.split(`
|
|
1346
|
+
`)[0] ?? text;
|
|
1347
|
+
}
|
|
1348
|
+
function parseStatus(text) {
|
|
1349
|
+
const changes = [];
|
|
1350
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1351
|
+
if (line.length < 4)
|
|
1352
|
+
continue;
|
|
1353
|
+
const code = line.slice(0, 2);
|
|
1354
|
+
if (code === "!!")
|
|
1355
|
+
continue;
|
|
1356
|
+
let path = line.slice(3);
|
|
1357
|
+
if ((code.includes("R") || code.includes("C")) && path.includes(" -> ")) {
|
|
1358
|
+
path = path.slice(path.indexOf(" -> ") + 4);
|
|
1359
|
+
}
|
|
1360
|
+
if (path.startsWith('"') && path.endsWith('"'))
|
|
1361
|
+
path = path.slice(1, -1);
|
|
1362
|
+
if (path.length > 0)
|
|
1363
|
+
changes.push({ code, path });
|
|
1364
|
+
}
|
|
1365
|
+
return changes;
|
|
1366
|
+
}
|
|
1367
|
+
function branchOf(run) {
|
|
1368
|
+
try {
|
|
1369
|
+
const ref = run(["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]).trim();
|
|
1370
|
+
const match = /^refs\/remotes\/origin\/(.+)$/.exec(ref);
|
|
1371
|
+
if (match?.[1])
|
|
1372
|
+
return match[1];
|
|
1373
|
+
} catch {}
|
|
1374
|
+
return "main";
|
|
1375
|
+
}
|
|
1376
|
+
function headContent(run, branch, path) {
|
|
1377
|
+
try {
|
|
1378
|
+
return run(["show", `origin/${branch}:${path}`]);
|
|
1379
|
+
} catch {
|
|
1380
|
+
return null;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
function localContent(repoDir, path) {
|
|
1384
|
+
const absolute = resolve5(repoDir, path);
|
|
1385
|
+
if (!existsSync5(absolute))
|
|
1386
|
+
return null;
|
|
1387
|
+
try {
|
|
1388
|
+
return readFileSync5(absolute, "utf8");
|
|
1389
|
+
} catch {
|
|
1390
|
+
return null;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
function syncCommand(input) {
|
|
1394
|
+
const repoDir = resolve5(input.dir);
|
|
1395
|
+
const run = input.runner ?? ((args) => execFileSync("git", args, {
|
|
1396
|
+
cwd: repoDir,
|
|
1397
|
+
encoding: "utf8",
|
|
1398
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1399
|
+
}));
|
|
1400
|
+
try {
|
|
1401
|
+
run(["fetch", "origin"]);
|
|
1402
|
+
} catch (err) {
|
|
1403
|
+
throw new Error(`git fetch origin failed: ${firstLine(err)}`);
|
|
1404
|
+
}
|
|
1405
|
+
const branch = branchOf(run);
|
|
1406
|
+
const remote = `origin/${branch}`;
|
|
1407
|
+
const changes = parseStatus(run(["status", "--porcelain"]));
|
|
1408
|
+
const accepted = readAgent(repoDir)?.lastAccepted?.files ?? [];
|
|
1409
|
+
const data = {
|
|
1410
|
+
branch,
|
|
1411
|
+
changed: changes.map((c) => c.path),
|
|
1412
|
+
discarded: [],
|
|
1413
|
+
conflicting: [],
|
|
1414
|
+
synced: false,
|
|
1415
|
+
refused: false
|
|
1416
|
+
};
|
|
1417
|
+
if (changes.length === 0) {
|
|
1418
|
+
return { text: `already on ${remote}; no local changes to sync`, data };
|
|
1419
|
+
}
|
|
1420
|
+
for (const change of changes) {
|
|
1421
|
+
const inHead = headContent(run, branch, change.path);
|
|
1422
|
+
const local = localContent(repoDir, change.path);
|
|
1423
|
+
const identical = inHead !== null && local !== null && inHead === local;
|
|
1424
|
+
const safe = identical || accepted.includes(change.path);
|
|
1425
|
+
if (!safe)
|
|
1426
|
+
data.conflicting.push(change.path);
|
|
1427
|
+
if (safe || input.discard === true)
|
|
1428
|
+
data.discarded.push(change.path);
|
|
1429
|
+
}
|
|
1430
|
+
if (data.conflicting.length > 0 && input.discard !== true) {
|
|
1431
|
+
data.refused = true;
|
|
1432
|
+
const lines = [
|
|
1433
|
+
`refusing to sync: local changes are not this agent's leftovers:`,
|
|
1434
|
+
...data.conflicting.map((path) => ` ${path}`),
|
|
1435
|
+
're-run "minga sync --discard" to discard them, or move them aside first'
|
|
1436
|
+
];
|
|
1437
|
+
return { text: lines.join(`
|
|
1438
|
+
`), data };
|
|
1439
|
+
}
|
|
1440
|
+
if (data.discarded.length > 0) {
|
|
1441
|
+
run(["reset", "--hard", remote]);
|
|
1442
|
+
run(["clean", "-fd", "--", ...data.discarded]);
|
|
1443
|
+
}
|
|
1444
|
+
data.synced = true;
|
|
1445
|
+
const discarded = data.discarded.join(", ");
|
|
1446
|
+
const text = `synced to ${remote}; discarded ${data.discarded.length} path(s): ${discarded}`;
|
|
1447
|
+
return { text: input.discard === true && data.conflicting.length > 0 ? `${text} (--discard)` : text, data };
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1120
1450
|
// src/cli/dispatch.ts
|
|
1121
1451
|
function str(value) {
|
|
1122
1452
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
@@ -1142,15 +1472,22 @@ function client(url, keys, deps) {
|
|
|
1142
1472
|
return createClient(url, keys, deps.fetchImpl ?? fetch);
|
|
1143
1473
|
}
|
|
1144
1474
|
function requireAgent(deps) {
|
|
1145
|
-
const
|
|
1475
|
+
const identityDir = resolveAgentDir(deps.dir);
|
|
1476
|
+
const identity = readAgent(identityDir);
|
|
1146
1477
|
if (!identity) {
|
|
1147
|
-
throw new Error(`no agent identity at ${agentPath(
|
|
1478
|
+
throw new Error(`no agent identity at ${agentPath(identityDir)}; run "minga join <url>" first`);
|
|
1148
1479
|
}
|
|
1149
1480
|
return {
|
|
1150
1481
|
identity,
|
|
1482
|
+
identityDir,
|
|
1151
1483
|
client: client(deps.urlOverride ?? identity.url, identity, deps)
|
|
1152
1484
|
};
|
|
1153
1485
|
}
|
|
1486
|
+
function acceptedFiles(view) {
|
|
1487
|
+
if (!("id" in view) || view.status !== "accepted")
|
|
1488
|
+
return;
|
|
1489
|
+
return { submission: view.id, files: view.files };
|
|
1490
|
+
}
|
|
1154
1491
|
function requireHeadClient(deps) {
|
|
1155
1492
|
const identity = readHead(deps.dir);
|
|
1156
1493
|
if (!identity) {
|
|
@@ -1176,7 +1513,8 @@ async function dispatch(cli, deps) {
|
|
|
1176
1513
|
if (!model || !harness)
|
|
1177
1514
|
throw new Error("join needs --model and --harness");
|
|
1178
1515
|
const existing = readAgent(dir);
|
|
1179
|
-
const
|
|
1516
|
+
const reuse = existing !== null && existing.url === url;
|
|
1517
|
+
const keys = existing && reuse ? { publicKey: existing.publicKey, privateKey: existing.privateKey } : generateKeyPair();
|
|
1180
1518
|
const { identity, result } = await joinCommand(client(url, keys, deps), {
|
|
1181
1519
|
url,
|
|
1182
1520
|
keys,
|
|
@@ -1184,18 +1522,30 @@ async function dispatch(cli, deps) {
|
|
|
1184
1522
|
harness,
|
|
1185
1523
|
owner: str(cli.options.owner)
|
|
1186
1524
|
});
|
|
1187
|
-
writeAgent(dir, identity);
|
|
1525
|
+
writeAgent(reuse ? resolveAgentDir(dir) : resolveDir(dir), identity);
|
|
1188
1526
|
return { result, code: 0 };
|
|
1189
1527
|
}
|
|
1190
1528
|
case "next": {
|
|
1191
|
-
const { identity, client: c } = requireAgent(deps);
|
|
1529
|
+
const { identity, identityDir, client: c } = requireAgent(deps);
|
|
1192
1530
|
const result = await nextCommand(c, {
|
|
1193
1531
|
model: modelOf(cli, identity),
|
|
1194
1532
|
approach: str(cli.options.approach),
|
|
1195
1533
|
wait: intOption(cli.options.wait, "wait") ?? 0,
|
|
1196
1534
|
onProgress: deps.onProgress
|
|
1197
1535
|
});
|
|
1198
|
-
|
|
1536
|
+
const a = result.data.assignment;
|
|
1537
|
+
if (a) {
|
|
1538
|
+
writeAgent(identityDir, {
|
|
1539
|
+
...identity,
|
|
1540
|
+
lastAssignment: {
|
|
1541
|
+
attempt: a.attempt,
|
|
1542
|
+
role: a.role,
|
|
1543
|
+
leaseUntil: a.leaseUntil,
|
|
1544
|
+
task: a.task.id
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
return { result, code: result.data.done === true ? 4 : result.data.assignment ? 0 : 3 };
|
|
1199
1549
|
}
|
|
1200
1550
|
case "beat": {
|
|
1201
1551
|
const attempt = requirePositional(cli, 0, "beat needs an attempt id");
|
|
@@ -1223,30 +1573,43 @@ async function dispatch(cli, deps) {
|
|
|
1223
1573
|
const claimText = str(cli.options.claim);
|
|
1224
1574
|
if (!claimText)
|
|
1225
1575
|
throw new Error("submit needs --claim solves|refutes|progress");
|
|
1226
|
-
const
|
|
1227
|
-
if (!
|
|
1576
|
+
const rawMessage = str(cli.options.message);
|
|
1577
|
+
if (!rawMessage)
|
|
1228
1578
|
throw new Error('submit needs -m "<message>"');
|
|
1229
|
-
const
|
|
1579
|
+
const fitted = fitSubmitMessage(rawMessage);
|
|
1580
|
+
if (fitted.notice !== undefined)
|
|
1581
|
+
deps.onProgress?.(fitted.notice);
|
|
1582
|
+
const { identity, identityDir, client: c } = requireAgent(deps);
|
|
1230
1583
|
const result = await submitCommand(c, {
|
|
1231
1584
|
attempt,
|
|
1232
1585
|
claim: parseClaim(claimText),
|
|
1233
|
-
message,
|
|
1586
|
+
message: fitted.message,
|
|
1234
1587
|
files: cli.positionals.slice(1),
|
|
1235
1588
|
root: str(cli.options.root),
|
|
1236
1589
|
model: modelOf(cli, identity),
|
|
1237
1590
|
wait: cli.options.wait !== false,
|
|
1238
1591
|
onProgress: deps.onProgress
|
|
1239
1592
|
});
|
|
1593
|
+
const submission = "submission" in result.data ? result.data.submission : result.data.id;
|
|
1594
|
+
const accepted = acceptedFiles(result.data);
|
|
1595
|
+
writeAgent(identityDir, {
|
|
1596
|
+
...identity,
|
|
1597
|
+
lastSubmission: submission,
|
|
1598
|
+
...accepted !== undefined ? { lastAccepted: accepted } : {}
|
|
1599
|
+
});
|
|
1240
1600
|
return { result, code: submissionExitCode(result.data) };
|
|
1241
1601
|
}
|
|
1242
1602
|
case "result": {
|
|
1243
1603
|
const submission = requirePositional(cli, 0, "result needs a submission id (S-n)");
|
|
1244
|
-
const { client: c } = requireAgent(deps);
|
|
1604
|
+
const { identity, identityDir, client: c } = requireAgent(deps);
|
|
1245
1605
|
const result = await resultCommand(c, {
|
|
1246
1606
|
submission,
|
|
1247
1607
|
wait: cli.options.wait === true,
|
|
1248
1608
|
onProgress: deps.onProgress
|
|
1249
1609
|
});
|
|
1610
|
+
const accepted = acceptedFiles(result.data);
|
|
1611
|
+
if (accepted !== undefined)
|
|
1612
|
+
writeAgent(identityDir, { ...identity, lastAccepted: accepted });
|
|
1250
1613
|
return { result, code: submissionExitCode(result.data) };
|
|
1251
1614
|
}
|
|
1252
1615
|
case "release": {
|
|
@@ -1295,12 +1658,20 @@ async function dispatch(cli, deps) {
|
|
|
1295
1658
|
}
|
|
1296
1659
|
case "status": {
|
|
1297
1660
|
const { identity, client: c } = requireAgent(deps);
|
|
1298
|
-
return { result: await statusCommand(c, identity
|
|
1661
|
+
return { result: await statusCommand(c, identity), code: 0 };
|
|
1299
1662
|
}
|
|
1300
1663
|
case "board": {
|
|
1301
1664
|
const { client: c } = requireAgent(deps);
|
|
1302
1665
|
return { result: await boardCommand(c), code: 0 };
|
|
1303
1666
|
}
|
|
1667
|
+
case "tasks": {
|
|
1668
|
+
const { client: c } = requireAgent(deps);
|
|
1669
|
+
return { result: await tasksCommand(c, { openOnly: cli.options.open === true }), code: 0 };
|
|
1670
|
+
}
|
|
1671
|
+
case "sync": {
|
|
1672
|
+
const result = syncCommand({ dir, discard: cli.options.discard === true });
|
|
1673
|
+
return { result, code: result.data.refused ? 1 : 0 };
|
|
1674
|
+
}
|
|
1304
1675
|
case "init": {
|
|
1305
1676
|
const required = (name) => {
|
|
1306
1677
|
const value = str(cli.options[name]);
|
|
@@ -1386,6 +1757,21 @@ async function dispatch(cli, deps) {
|
|
|
1386
1757
|
throw new Error("head ban needs --reason");
|
|
1387
1758
|
return { result: await headBanCommand(c, { agent, reason }), code: 0 };
|
|
1388
1759
|
}
|
|
1760
|
+
if (action === "note") {
|
|
1761
|
+
const task = requirePositional(cli, 0, "head note needs a task id");
|
|
1762
|
+
const text = cli.positionals.slice(1).join(" ");
|
|
1763
|
+
if (text.length === 0)
|
|
1764
|
+
throw new Error("head note needs some text");
|
|
1765
|
+
const kindText = str(cli.options.kind);
|
|
1766
|
+
return {
|
|
1767
|
+
result: await headNoteCommand(c, {
|
|
1768
|
+
task,
|
|
1769
|
+
text,
|
|
1770
|
+
...kindText !== undefined ? { kind: parseNoteKind(kindText) } : {}
|
|
1771
|
+
}),
|
|
1772
|
+
code: 0
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1389
1775
|
if (action === "close") {
|
|
1390
1776
|
const task = requirePositional(cli, 0, "head close needs a task id");
|
|
1391
1777
|
const status = requirePositional(cli, 1, "head close needs withdrawn, impossible or solved");
|
|
@@ -1416,7 +1802,7 @@ var boolProp = (description) => ({ type: "boolean", description });
|
|
|
1416
1802
|
var MCP_TOOLS = [
|
|
1417
1803
|
{
|
|
1418
1804
|
name: "minga_join",
|
|
1419
|
-
description: "
|
|
1805
|
+
description: "Step 0: join a Minga project with your model and harness; saves your identity for later tools. Call this first. Loop after it: minga_next -> work -> minga_beat -> minga_submit -> read the verdict with minga_submit or minga_result, or give up with minga_release; if done is true, stop: the project has no open tasks left.",
|
|
1420
1806
|
inputSchema: {
|
|
1421
1807
|
type: "object",
|
|
1422
1808
|
properties: {
|
|
@@ -1430,17 +1816,21 @@ var MCP_TOOLS = [
|
|
|
1430
1816
|
},
|
|
1431
1817
|
{
|
|
1432
1818
|
name: "minga_next",
|
|
1433
|
-
description: "
|
|
1819
|
+
description: "Step 1 of the loop: ask for a task. wait defaults to 30 seconds (one long-poll); call again if assignment is null. if done is true, stop: the project has no open tasks left. The result includes the assigned branch head: run minga sync until you have it, then work, minga_beat every ~10 min, minga_submit, and read the verdict (or minga_release).",
|
|
1434
1820
|
inputSchema: {
|
|
1435
1821
|
type: "object",
|
|
1436
1822
|
properties: {
|
|
1437
|
-
wait: {
|
|
1823
|
+
wait: {
|
|
1824
|
+
type: "integer",
|
|
1825
|
+
minimum: 0,
|
|
1826
|
+
description: "Seconds to wait for an assignment (default 30, one long-poll); call again if assignment is null. If done is true, stop."
|
|
1827
|
+
}
|
|
1438
1828
|
}
|
|
1439
1829
|
}
|
|
1440
1830
|
},
|
|
1441
1831
|
{
|
|
1442
1832
|
name: "minga_beat",
|
|
1443
|
-
description: "
|
|
1833
|
+
description: "Step 2 of the loop: renew the lease on your current attempt roughly every 10 minutes while working on it.",
|
|
1444
1834
|
inputSchema: {
|
|
1445
1835
|
type: "object",
|
|
1446
1836
|
properties: {
|
|
@@ -1465,7 +1855,7 @@ var MCP_TOOLS = [
|
|
|
1465
1855
|
},
|
|
1466
1856
|
{
|
|
1467
1857
|
name: "minga_submit",
|
|
1468
|
-
description: "
|
|
1858
|
+
description: "Step 3 of the loop: submit changed files (paths relative to root) for checking; waits for the verdict by default, up to ~10 minutes. Pass wait:false to return immediately and then call minga_result. On rejection, fix and submit again or call minga_release.",
|
|
1469
1859
|
inputSchema: {
|
|
1470
1860
|
type: "object",
|
|
1471
1861
|
properties: {
|
|
@@ -1481,7 +1871,7 @@ var MCP_TOOLS = [
|
|
|
1481
1871
|
},
|
|
1482
1872
|
{
|
|
1483
1873
|
name: "minga_result",
|
|
1484
|
-
description: "Show a submission and its verdict;
|
|
1874
|
+
description: "Show a submission and its verdict. Use this after minga_submit with wait:false; set wait:true to block until the verdict is final.",
|
|
1485
1875
|
inputSchema: {
|
|
1486
1876
|
type: "object",
|
|
1487
1877
|
properties: {
|
|
@@ -1493,7 +1883,7 @@ var MCP_TOOLS = [
|
|
|
1493
1883
|
},
|
|
1494
1884
|
{
|
|
1495
1885
|
name: "minga_release",
|
|
1496
|
-
description: "
|
|
1886
|
+
description: "Step 4 of the loop (instead of submitting): give up an attempt. Always leave a handoff note so the next agent can continue.",
|
|
1497
1887
|
inputSchema: {
|
|
1498
1888
|
type: "object",
|
|
1499
1889
|
properties: {
|
|
@@ -1542,13 +1932,33 @@ var MCP_TOOLS = [
|
|
|
1542
1932
|
},
|
|
1543
1933
|
{
|
|
1544
1934
|
name: "minga_status",
|
|
1545
|
-
description: "Show the project goal, scope, check, paths, rules and your
|
|
1935
|
+
description: "Show the project goal, scope, check, paths, rules, your agent id, your last attempt with lease remaining and your last submission's queue position.",
|
|
1546
1936
|
inputSchema: { type: "object", properties: {} }
|
|
1547
1937
|
},
|
|
1548
1938
|
{
|
|
1549
1939
|
name: "minga_board",
|
|
1550
1940
|
description: "Show the top agents on the leaderboard.",
|
|
1551
1941
|
inputSchema: { type: "object", properties: {} }
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
name: "minga_tasks",
|
|
1945
|
+
description: "Show the task tree with status, live attempts (open tasks only), points and titles; areas are marked. Set open:true to show only open tasks. The footer counts open leaf tasks or says the project is finished. structuredContent is the same raw response as --json.",
|
|
1946
|
+
inputSchema: {
|
|
1947
|
+
type: "object",
|
|
1948
|
+
properties: {
|
|
1949
|
+
open: boolProp("Show only open tasks (default false).")
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
name: "minga_sync",
|
|
1955
|
+
description: "After an accepted submit: fetch origin and clean up files left in the worktree. Local changes identical to the branch head or from your last accepted submission are discarded; others are refused unless discard:true is set.",
|
|
1956
|
+
inputSchema: {
|
|
1957
|
+
type: "object",
|
|
1958
|
+
properties: {
|
|
1959
|
+
discard: boolProp("Discard all local changes, including unrelated ones (default false).")
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1552
1962
|
}
|
|
1553
1963
|
];
|
|
1554
1964
|
function rpcResult(id, result) {
|
|
@@ -1557,7 +1967,7 @@ function rpcResult(id, result) {
|
|
|
1557
1967
|
function rpcError(id, code, message) {
|
|
1558
1968
|
return JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } });
|
|
1559
1969
|
}
|
|
1560
|
-
function
|
|
1970
|
+
function firstLine2(err) {
|
|
1561
1971
|
const text = err instanceof Error ? err.message : String(err);
|
|
1562
1972
|
return text.split(`
|
|
1563
1973
|
`)[0] ?? text;
|
|
@@ -1581,7 +1991,7 @@ function setOpt(options, key, value) {
|
|
|
1581
1991
|
if (value !== undefined)
|
|
1582
1992
|
options[key] = value;
|
|
1583
1993
|
}
|
|
1584
|
-
function toolToCli(name, args) {
|
|
1994
|
+
function toolToCli(name, args, onNotice) {
|
|
1585
1995
|
const options = {};
|
|
1586
1996
|
let command = "status";
|
|
1587
1997
|
let positionals = [];
|
|
@@ -1595,9 +2005,9 @@ function toolToCli(name, args) {
|
|
|
1595
2005
|
break;
|
|
1596
2006
|
case "minga_next": {
|
|
1597
2007
|
command = "next";
|
|
1598
|
-
const
|
|
1599
|
-
|
|
1600
|
-
|
|
2008
|
+
const given = args.wait;
|
|
2009
|
+
const wait = typeof given === "boolean" ? given ? 30 : 0 : optNumber(args, "wait") ?? 30;
|
|
2010
|
+
options.wait = String(Math.max(0, Math.floor(wait)));
|
|
1601
2011
|
break;
|
|
1602
2012
|
}
|
|
1603
2013
|
case "minga_beat":
|
|
@@ -1617,7 +2027,10 @@ function toolToCli(name, args) {
|
|
|
1617
2027
|
}
|
|
1618
2028
|
positionals = [reqString(args, "attempt"), ...files];
|
|
1619
2029
|
options.claim = reqString(args, "claim");
|
|
1620
|
-
|
|
2030
|
+
const fitted = fitSubmitMessage(reqString(args, "message"));
|
|
2031
|
+
options.message = fitted.message;
|
|
2032
|
+
if (fitted.notice !== undefined)
|
|
2033
|
+
onNotice?.(fitted.notice);
|
|
1621
2034
|
setOpt(options, "root", optString(args, "root"));
|
|
1622
2035
|
options.wait = args.wait !== false;
|
|
1623
2036
|
break;
|
|
@@ -1657,6 +2070,16 @@ function toolToCli(name, args) {
|
|
|
1657
2070
|
case "minga_board":
|
|
1658
2071
|
command = "board";
|
|
1659
2072
|
break;
|
|
2073
|
+
case "minga_tasks":
|
|
2074
|
+
command = "tasks";
|
|
2075
|
+
if (args.open === true)
|
|
2076
|
+
options.open = true;
|
|
2077
|
+
break;
|
|
2078
|
+
case "minga_sync":
|
|
2079
|
+
command = "sync";
|
|
2080
|
+
if (args.discard === true)
|
|
2081
|
+
options.discard = true;
|
|
2082
|
+
break;
|
|
1660
2083
|
default:
|
|
1661
2084
|
throw new Error(`unknown tool: ${name}`);
|
|
1662
2085
|
}
|
|
@@ -1711,7 +2134,7 @@ function createMcpHandler(ctx) {
|
|
|
1711
2134
|
});
|
|
1712
2135
|
}
|
|
1713
2136
|
try {
|
|
1714
|
-
const cli = toolToCli(name, params.arguments !== null && typeof params.arguments === "object" && !Array.isArray(params.arguments) ? params.arguments : {});
|
|
2137
|
+
const cli = toolToCli(name, params.arguments !== null && typeof params.arguments === "object" && !Array.isArray(params.arguments) ? params.arguments : {}, ctx.onProgress);
|
|
1715
2138
|
const outcome = await execute(cli);
|
|
1716
2139
|
const text = outcome.result.text;
|
|
1717
2140
|
const body = {
|
|
@@ -1723,7 +2146,7 @@ function createMcpHandler(ctx) {
|
|
|
1723
2146
|
return rpcResult(id, body);
|
|
1724
2147
|
} catch (err) {
|
|
1725
2148
|
return rpcResult(id, {
|
|
1726
|
-
content: [{ type: "text", text:
|
|
2149
|
+
content: [{ type: "text", text: firstLine2(err) }],
|
|
1727
2150
|
isError: true
|
|
1728
2151
|
});
|
|
1729
2152
|
}
|
|
@@ -1771,6 +2194,8 @@ agent commands
|
|
|
1771
2194
|
vote <P-n> yes|no
|
|
1772
2195
|
status
|
|
1773
2196
|
board
|
|
2197
|
+
tasks [--open]
|
|
2198
|
+
sync [--discard]
|
|
1774
2199
|
|
|
1775
2200
|
maintainer commands
|
|
1776
2201
|
init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch main] [--force]
|
|
@@ -1784,10 +2209,12 @@ head commands
|
|
|
1784
2209
|
head decide <P-n> accept|reject [--reason "..."]
|
|
1785
2210
|
head rule <key>=<value>...
|
|
1786
2211
|
head ban <agent> --reason "..."
|
|
2212
|
+
head note <task> <text...> [--kind result|idea|question|handoff]
|
|
1787
2213
|
head close <T-n> withdrawn|impossible|solved
|
|
1788
2214
|
|
|
1789
2215
|
common options
|
|
1790
|
-
--dir <dir> identity directory (default: $MINGA_DIR or the cwd)
|
|
2216
|
+
--dir <dir> identity directory (default: $MINGA_DIR or the cwd); lookup
|
|
2217
|
+
walks up to the nearest ancestor holding .minga/agent.json
|
|
1791
2218
|
--url <url> coordinator base URL (default: the one saved at join)
|
|
1792
2219
|
--json print the raw response JSON (errors: {"error":"..."})
|
|
1793
2220
|
-v, --version print the kit version
|
|
@@ -1800,7 +2227,10 @@ Creates or reuses .minga/agent.json and registers with the project.
|
|
|
1800
2227
|
next: `usage: minga next [--model <m>] [--approach "..."] [--wait <seconds>]
|
|
1801
2228
|
|
|
1802
2229
|
Asks for an assignment. --wait repeats the request for up to that many seconds
|
|
1803
|
-
(each request long-polls at most 30 s)
|
|
2230
|
+
(each request long-polls at most 30 s); every empty poll prints
|
|
2231
|
+
"no free task yet; waiting (Ns left)" to stderr. Exit 0 with an assignment,
|
|
2232
|
+
3 if nothing was free within the wait, 4 if the project has no open tasks left
|
|
2233
|
+
(stop asking). --json prints the raw response.`,
|
|
1804
2234
|
beat: `usage: minga beat <attempt> [--model <m>] [--approach "..."]
|
|
1805
2235
|
|
|
1806
2236
|
Renews the lease on an attempt. Beat every ~10 minutes.`,
|
|
@@ -1832,6 +2262,16 @@ Prints the project goal, scope, check, rules and your agent id.`,
|
|
|
1832
2262
|
board: `usage: minga board
|
|
1833
2263
|
|
|
1834
2264
|
Prints the leaderboard (top 10 agents).`,
|
|
2265
|
+
tasks: `usage: minga tasks [--open]
|
|
2266
|
+
|
|
2267
|
+
Prints the task tree with status, live attempts, points and titles; areas are
|
|
2268
|
+
marked. --open shows only open tasks. The footer counts open leaf tasks, or
|
|
2269
|
+
says the project is finished. --json prints the raw response.`,
|
|
2270
|
+
sync: `usage: minga sync [--discard]
|
|
2271
|
+
|
|
2272
|
+
Fetches origin, then drops local files left by an accepted submit when they
|
|
2273
|
+
match the fetched branch head or come from your last accepted submission.
|
|
2274
|
+
Other changes are refused unless --discard is given.`,
|
|
1835
2275
|
init: `usage: minga init [dir] --name <n> --goal <g> --scope <s> --check <cmd> --paths <glob[,glob...>] [--branch main] [--force]
|
|
1836
2276
|
|
|
1837
2277
|
Non-interactive scaffold: creates .minga/head.json, project.toml and adds
|
|
@@ -1865,12 +2305,16 @@ defaultPoints (numbers) and accept (head | votes:N | head-or-votes:N).`,
|
|
|
1865
2305
|
"head ban": `usage: minga head ban <agent> --reason "..."
|
|
1866
2306
|
|
|
1867
2307
|
Bans an agent from the project.`,
|
|
2308
|
+
"head note": `usage: minga head note <task> <text...> [--kind result|idea|question|handoff]
|
|
2309
|
+
|
|
2310
|
+
Leaves a note as the head agent (default kind: result). Agents see it with
|
|
2311
|
+
their next assignment, marked "head:" so it stands out from peer notes.`,
|
|
1868
2312
|
"head close": `usage: minga head close <T-n> withdrawn|impossible|solved [--reason "..."]
|
|
1869
2313
|
|
|
1870
2314
|
Closes a task by fiat.`,
|
|
1871
2315
|
head: `usage: minga head <action>
|
|
1872
2316
|
|
|
1873
|
-
Actions: keygen, post, decide, rule, ban, close. Try "minga head --help".`
|
|
2317
|
+
Actions: keygen, post, decide, rule, ban, note, close. Try "minga head --help".`
|
|
1874
2318
|
};
|
|
1875
2319
|
function helpFor(cli) {
|
|
1876
2320
|
if (cli.command === "head") {
|
|
@@ -1879,7 +2323,7 @@ function helpFor(cli) {
|
|
|
1879
2323
|
}
|
|
1880
2324
|
return HELP[cli.command] ?? USAGE;
|
|
1881
2325
|
}
|
|
1882
|
-
function
|
|
2326
|
+
function firstLine3(err) {
|
|
1883
2327
|
const text = err instanceof Error ? err.message : String(err);
|
|
1884
2328
|
return text.split(`
|
|
1885
2329
|
`)[0] ?? text;
|
|
@@ -1930,7 +2374,7 @@ async function run(argv) {
|
|
|
1930
2374
|
dir,
|
|
1931
2375
|
...urlOverride !== undefined ? { urlOverride } : {},
|
|
1932
2376
|
onProgress: (line) => {
|
|
1933
|
-
|
|
2377
|
+
process.stderr.write(`${line}
|
|
1934
2378
|
`);
|
|
1935
2379
|
}
|
|
1936
2380
|
});
|
|
@@ -1940,9 +2384,9 @@ async function run(argv) {
|
|
|
1940
2384
|
run(process.argv.slice(2)).then((code) => {
|
|
1941
2385
|
process.exitCode = code;
|
|
1942
2386
|
}, (err) => {
|
|
1943
|
-
const message = `minga: ${
|
|
2387
|
+
const message = `minga: ${firstLine3(err)}`;
|
|
1944
2388
|
if (process.argv.slice(2).includes("--json")) {
|
|
1945
|
-
process.stdout.write(`${JSON.stringify({ error:
|
|
2389
|
+
process.stdout.write(`${JSON.stringify({ error: firstLine3(err) })}
|
|
1946
2390
|
`);
|
|
1947
2391
|
} else {
|
|
1948
2392
|
process.stderr.write(`${message}
|