@moo.md/hum 0.3.0 → 0.4.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/defaults/hum.json +5 -0
- package/defaults/roles/build.md +1 -1
- package/defaults/roles/fix.md +1 -1
- package/npm-shrinkwrap.json +3297 -0
- package/package.json +6 -2
- package/release.json +3 -0
- package/schema/hum.schema.json +47 -7
- package/scripts/eval.ts +21 -5
- package/src/adapter-api.ts +3 -1
- package/src/adapters/claude-bg.ts +2 -2
- package/src/adapters/claude-p.ts +44 -18
- package/src/adapters/contract.ts +12 -0
- package/src/adapters/fake.ts +5 -0
- package/src/adapters/git.ts +61 -9
- package/src/adapters/github-client.ts +15 -0
- package/src/adapters/github-commits.ts +84 -0
- package/src/adapters/github.ts +9 -0
- package/src/adapters/guard.ts +1 -0
- package/src/adapters/item-file.ts +1 -1
- package/src/adapters/markdown.ts +10 -1
- package/src/adapters/pull-requests.ts +8 -8
- package/src/adapters/registry.ts +3 -6
- package/src/adapters/roundup.ts +3 -0
- package/src/bytes.ts +1 -0
- package/src/cli/service.ts +176 -29
- package/src/cli/setup.ts +28 -33
- package/src/config/checks.ts +21 -50
- package/src/config/load.ts +2 -3
- package/src/config/machine.ts +29 -0
- package/src/config/refusal.ts +5 -6
- package/src/config/schema.ts +23 -7
- package/src/config/wake-job.ts +6 -2
- package/src/decide/risk.ts +2 -2
- package/src/exec.ts +10 -0
- package/src/index.ts +1 -1
- package/src/loop/records.ts +8 -1
- package/src/measure/rate.ts +22 -0
- package/src/publish/bundle.ts +128 -0
- package/src/publish/handoff.ts +107 -0
- package/src/publish/handover.ts +182 -0
- package/src/publish/intents.ts +61 -0
- package/src/publish/publisher.ts +259 -0
- package/src/publish/wake.ts +78 -0
- package/src/service/ci-state.ts +99 -0
- package/src/service/plugins.ts +137 -0
- package/src/service/wake.ts +3 -1
- package/src/service/workflows.ts +126 -30
- package/src/setup/propose.ts +17 -4
- package/src/setup/prove.ts +3 -3
- package/src/setup/write.ts +2 -2
- package/src/state/items.ts +17 -8
- package/src/state/open.ts +20 -6
- package/src/state/records.ts +7 -0
- package/src/state/runs.ts +5 -0
- package/src/state/saved.ts +17 -2
- package/src/worker/base-check.ts +41 -13
- package/src/worker/checks.ts +3 -2
- package/src/worker/evidence.ts +72 -0
- package/src/worker/kind.ts +4 -7
- package/src/worker/land.ts +173 -81
- package/src/worker/merged.ts +20 -8
- package/src/worker/open.ts +33 -17
- package/src/worker/questions.ts +16 -8
- package/src/worker/signed-push.ts +167 -0
- package/src/worker/thin-path.ts +245 -133
- package/src/worker/worker.ts +50 -9
- package/surface.json +185 -56
package/src/worker/worker.ts
CHANGED
|
@@ -5,7 +5,7 @@ import pMemoize from "p-memoize";
|
|
|
5
5
|
import PQueue from "p-queue";
|
|
6
6
|
import pTimeout from "p-timeout";
|
|
7
7
|
import { createAsyncLogic } from "xstate";
|
|
8
|
-
import { ADAPTER_API_VERSION, type Answers, type Holder, ItemId, type ItemRef, type Questions, type WorkSource } from "../adapter-api.ts";
|
|
8
|
+
import { ADAPTER_API_VERSION, type Answers, type Holder, type Item, ItemId, type ItemRef, type Questions, type WorkSource } from "../adapter-api.ts";
|
|
9
9
|
import type { Runner } from "../adapters/claude-p.ts";
|
|
10
10
|
import type { Config } from "../config/load.ts";
|
|
11
11
|
import { invokedSources } from "../config/machine.ts";
|
|
@@ -18,6 +18,7 @@ import type { State } from "../state/open.ts";
|
|
|
18
18
|
import { tallyOf } from "./tally.ts";
|
|
19
19
|
import { checkBaseAfterMerge } from "./base-check.ts";
|
|
20
20
|
import { settleMergedPulls } from "./merged.ts";
|
|
21
|
+
import type { GitHubCommits } from "../adapters/github-commits.ts";
|
|
21
22
|
import { readHistory } from "../adapters/history.ts";
|
|
22
23
|
import { gitIn, PATCH } from "../adapters/git.ts";
|
|
23
24
|
import { join } from "node:path";
|
|
@@ -40,7 +41,7 @@ import type { SlotPool } from "../slots/pool.ts";
|
|
|
40
41
|
import { type AnswerScope, settleAnswers } from "./answers.ts";
|
|
41
42
|
import { recentlyAsked, releaseQuestions } from "./questions.ts";
|
|
42
43
|
import { OWNER_APPROVAL } from "../decide/merge.ts";
|
|
43
|
-
import { answerTo, type Checkout, ownerWaitStage, claimTtlMs, DEFAULT_BASE, hasEndedStuck, park, rememberKinds, RUN_AGAIN, runThinPath, type ThinResult, isWaitingOnOwner } from "./thin-path.ts";
|
|
44
|
+
import { answerTo, type Checkout, ownerWaitStage, claimTtlMs, DEFAULT_BASE, gatherItem, hasEndedStuck, isGathered, park, rememberKinds, RUN_AGAIN, runThinPath, type ThinPathOptions, type ThinResult, isWaitingOnOwner } from "./thin-path.ts";
|
|
44
45
|
|
|
45
46
|
export type { TickResult } from "./lifecycle.ts";
|
|
46
47
|
|
|
@@ -86,10 +87,23 @@ export type WorkerOptions = {
|
|
|
86
87
|
readonly onResult?: (result: ThinResult) => void;
|
|
87
88
|
/** The remote's pull requests and branch rules, for a remote on GitHub. */
|
|
88
89
|
readonly pulls?: PullRequests;
|
|
90
|
+
/** The remote's branches through GitHub's API, which signs the commits it makes, for a remote on GitHub. */
|
|
91
|
+
readonly commits?: GitHubCommits;
|
|
89
92
|
/** What the review-note loop reads from the review surface and CI; without it the loop reads only git and the owner's answers. */
|
|
90
93
|
readonly loop?: Partial<Pick<LoopPass, "comments" | "ciLogs">>;
|
|
94
|
+
/** The CI job this worker is, where a wake splits into jobs; unset, a tick does all a wake does. */
|
|
95
|
+
readonly ciJob?: CiJob;
|
|
91
96
|
};
|
|
92
97
|
|
|
98
|
+
/**
|
|
99
|
+
* A wake's job that holds a token, `gather`, claims each item and settles its answers and kind, keeps it in `gathered`
|
|
100
|
+
* and runs nothing. The job that holds none, `work`, runs each pass and hands its outbox to `publish`; it asks,
|
|
101
|
+
* files and posts nothing itself. Either takes each item once.
|
|
102
|
+
*/
|
|
103
|
+
export type CiJob =
|
|
104
|
+
| { readonly kind: "gather"; readonly gathered: Map<string, Item> }
|
|
105
|
+
| { readonly kind: "work"; readonly publish: NonNullable<ThinPathOptions["publish"]> };
|
|
106
|
+
|
|
93
107
|
/** What the tick read of its sources: whether the watch saw a change, and the ready list. */
|
|
94
108
|
type Sources = {
|
|
95
109
|
readonly changed: boolean;
|
|
@@ -170,6 +184,8 @@ export class Worker {
|
|
|
170
184
|
readonly #answered = new Set<string>();
|
|
171
185
|
/** Saved changes that land again under this worker's config before anything else starts. */
|
|
172
186
|
readonly #relanding = new Set<string>();
|
|
187
|
+
/** The items a CI job's passes ended on: each job takes an item once, and the next wake takes it again. */
|
|
188
|
+
readonly #handled = new Set<string>();
|
|
173
189
|
/** Items whose thread a tick failed to read; the next tick reads them again whatever the watch says. */
|
|
174
190
|
readonly #unread = new Set<string>();
|
|
175
191
|
readonly #merged: Status["merged"] = [];
|
|
@@ -442,13 +458,28 @@ export class Worker {
|
|
|
442
458
|
);
|
|
443
459
|
}
|
|
444
460
|
|
|
461
|
+
/** A pass, or in a gather job its claim and settling alone, kept for the work job. */
|
|
462
|
+
async #pass(o: ThinPathOptions & { readonly itemId: ItemId }): Promise<ThinResult> {
|
|
463
|
+
const job = this.#o.ciJob;
|
|
464
|
+
|
|
465
|
+
if (job?.kind !== "gather") return runThinPath(o);
|
|
466
|
+
|
|
467
|
+
const gathered = await gatherItem(o, o.itemId);
|
|
468
|
+
|
|
469
|
+
if (!isGathered(gathered)) return gathered;
|
|
470
|
+
|
|
471
|
+
job.gathered.set(o.itemId, gathered.item);
|
|
472
|
+
|
|
473
|
+
return { outcome: "waiting", item: o.itemId };
|
|
474
|
+
}
|
|
475
|
+
|
|
445
476
|
#begin(id: string, known: Known, t: number): void {
|
|
446
477
|
const { state, config, adapters } = this.#o;
|
|
447
478
|
const abort = new AbortController();
|
|
448
479
|
|
|
449
480
|
this.#inFlight.set(id, { abort, since: t, known });
|
|
450
481
|
void this.#pool.add(() =>
|
|
451
|
-
|
|
482
|
+
this.#pass({
|
|
452
483
|
workSource: adapters.workSource,
|
|
453
484
|
questions: adapters.questions,
|
|
454
485
|
state,
|
|
@@ -469,7 +500,9 @@ export class Worker {
|
|
|
469
500
|
runnerVariables: this.#o.runnerVariables,
|
|
470
501
|
newSessionId: this.#o.newSessionId,
|
|
471
502
|
pulls: this.#o.pulls,
|
|
503
|
+
commits: this.#o.commits,
|
|
472
504
|
mayLand: () => this.#updating === undefined,
|
|
505
|
+
publish: this.#o.ciJob?.kind === "work" ? this.#o.ciJob.publish : undefined,
|
|
473
506
|
}).then(
|
|
474
507
|
(result) => this.#ended(id, known, result),
|
|
475
508
|
(error: Error) => this.#failed(id, error),
|
|
@@ -480,6 +513,8 @@ export class Worker {
|
|
|
480
513
|
#ended(id: string, known: Known, result: ThinResult): void {
|
|
481
514
|
this.#inFlight.delete(id);
|
|
482
515
|
|
|
516
|
+
if (this.#o.ciJob) this.#handled.add(id);
|
|
517
|
+
|
|
483
518
|
if (result.outcome === "merged")
|
|
484
519
|
this.#merged.unshift({
|
|
485
520
|
item: id,
|
|
@@ -489,6 +524,8 @@ export class Worker {
|
|
|
489
524
|
|
|
490
525
|
if (result.outcome === "merged") void this.#pool.add(() => this.#checkBase(id));
|
|
491
526
|
|
|
527
|
+
if (result.outcome === "held" && this.#o.state.landings.get(id) !== undefined) this.#relanding.add(id);
|
|
528
|
+
|
|
492
529
|
this.#o.onResult?.(result);
|
|
493
530
|
this.wake();
|
|
494
531
|
}
|
|
@@ -547,7 +584,7 @@ export class Worker {
|
|
|
547
584
|
|
|
548
585
|
const tip = (await git.raw(["rev-parse", LOOP_REF])).trim();
|
|
549
586
|
|
|
550
|
-
if (pulls) await settleMergedPulls(state, pulls, this.#now());
|
|
587
|
+
if (pulls) await settleMergedPulls(state, { pulls, workSource: adapters.workSource, git, remote }, this.#now());
|
|
551
588
|
|
|
552
589
|
await runLoopPass({
|
|
553
590
|
state,
|
|
@@ -566,6 +603,8 @@ export class Worker {
|
|
|
566
603
|
|
|
567
604
|
#failed(id: string, error: Error): void {
|
|
568
605
|
this.#inFlight.delete(id);
|
|
606
|
+
|
|
607
|
+
if (this.#o.ciJob) this.#handled.add(id);
|
|
569
608
|
this.#o.state.faults.raise({
|
|
570
609
|
code: "run-error",
|
|
571
610
|
item: id,
|
|
@@ -664,7 +703,7 @@ export class Worker {
|
|
|
664
703
|
const { state, runner, config } = this.#o;
|
|
665
704
|
const parked = new Set(state.parked.list().map((p) => p.item));
|
|
666
705
|
const asleep = new Set(sleeping.map((s) => s.itemId));
|
|
667
|
-
const isFresh = (id: string) => !this.#inFlight.has(id) && !parked.has(id) && !asleep.has(id);
|
|
706
|
+
const isFresh = (id: string) => !this.#inFlight.has(id) && !parked.has(id) && !asleep.has(id) && !this.#handled.has(id);
|
|
668
707
|
const isAnsweredAndIdle = (id: string) => this.#answered.has(id) && !this.#inFlight.has(id);
|
|
669
708
|
const learned = (id: string) => this.#learn(id).catch(() => undefined);
|
|
670
709
|
|
|
@@ -735,11 +774,13 @@ export class Worker {
|
|
|
735
774
|
|
|
736
775
|
const sources = await this.#readSources();
|
|
737
776
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
777
|
+
if (this.#o.ciJob?.kind !== "work") {
|
|
778
|
+
await releaseQuestions({ state, config, workSource: this.#o.adapters.workSource, questions: this.#o.adapters.questions, now: this.#now }).catch((error: Error) => {
|
|
779
|
+
state.faults.raise({ code: "question-release", cause: `Queued questions could not be asked: ${error.message}`.slice(0, ERROR_EXCERPT), fix: "hum asks them again on the next tick." });
|
|
780
|
+
});
|
|
741
781
|
|
|
742
|
-
|
|
782
|
+
this.#loopIfDue(t);
|
|
783
|
+
}
|
|
743
784
|
|
|
744
785
|
const ready = await this.#readReady(sources, sleeping);
|
|
745
786
|
const started = ready ? await this.#startPicked(t, ready, sleeping) : [];
|