@moo.md/hum 0.1.0 → 0.2.0
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/package.json +2 -2
- package/scripts/eval.ts +88 -50
- package/src/adapter-api.ts +46 -14
- package/src/adapters/admit.ts +2 -2
- package/src/adapters/argument.ts +1 -1
- package/src/adapters/claim.ts +18 -15
- package/src/adapters/claude-bg.ts +50 -27
- package/src/adapters/claude-p.ts +18 -23
- package/src/adapters/contract.ts +22 -10
- package/src/adapters/each-call.ts +9 -0
- package/src/adapters/fake.ts +6 -6
- package/src/adapters/git.ts +10 -18
- package/src/adapters/github-client.ts +102 -0
- package/src/adapters/github.ts +34 -142
- package/src/adapters/guard.ts +20 -9
- package/src/adapters/history.ts +12 -15
- package/src/adapters/item-file.ts +1 -1
- package/src/adapters/markdown.ts +49 -42
- package/src/adapters/marked.ts +6 -12
- package/src/adapters/model-call.ts +4 -4
- package/src/adapters/once.ts +5 -5
- package/src/adapters/owner-commit.ts +13 -11
- package/src/adapters/pull-requests.ts +11 -13
- package/src/adapters/registry.ts +7 -7
- package/src/adapters/roundup.ts +27 -35
- package/src/adapters/serial.ts +4 -5
- package/src/adapters/transcript.ts +13 -8
- package/src/cli/main.ts +1 -0
- package/src/cli/ops.ts +32 -14
- package/src/cli/service.ts +14 -8
- package/src/cli/setup.ts +8 -3
- package/src/cli/shared-watch.ts +3 -3
- package/src/config/checks.ts +14 -18
- package/src/config/machine.ts +5 -7
- package/src/config/refusal.ts +7 -0
- package/src/config/schema.ts +7 -7
- package/src/config/settings.ts +17 -2
- package/src/config/state-map.ts +5 -3
- package/src/decide/alignment.ts +4 -4
- package/src/decide/answer.ts +24 -22
- package/src/decide/kind.ts +1 -6
- package/src/decide/labels.ts +9 -9
- package/src/decide/merge.ts +6 -7
- package/src/decide/prose.ts +4 -4
- package/src/decide/question.ts +23 -20
- package/src/decide/review.ts +4 -2
- package/src/decide/risk.ts +25 -19
- package/src/decide/taste.ts +3 -3
- package/src/exec.ts +4 -3
- package/src/index.ts +14 -13
- package/src/loop/check-item.ts +3 -3
- package/src/loop/ci.ts +1 -1
- package/src/loop/github.ts +2 -2
- package/src/loop/groups.ts +13 -6
- package/src/loop/memory.ts +40 -28
- package/src/loop/notes.ts +5 -5
- package/src/loop/pair.ts +1 -1
- package/src/loop/pass.ts +18 -12
- package/src/loop/proof.ts +9 -7
- package/src/loop/prove-item.ts +1 -1
- package/src/loop/records.ts +12 -13
- package/src/loop/signals.ts +6 -6
- package/src/measure/inputs.ts +1 -1
- package/src/measure/measure.ts +4 -4
- package/src/measure/rate.ts +2 -0
- package/src/service/ci-tick.ts +2 -2
- package/src/service/supervise.ts +3 -2
- package/src/service/token.ts +3 -3
- package/src/service/wake.ts +2 -2
- package/src/service/workflows.ts +2 -2
- package/src/setup/propose.ts +4 -4
- package/src/setup/prove.ts +18 -12
- package/src/setup/scan.ts +31 -24
- package/src/setup/shipped.ts +8 -2
- package/src/setup/tables.ts +4 -3
- package/src/setup/waits.ts +9 -11
- package/src/setup/write.ts +17 -10
- package/src/slots/pool.ts +32 -24
- package/src/state/events.ts +1 -1
- package/src/state/faults.ts +13 -5
- package/src/state/format.ts +2 -2
- package/src/state/items.ts +9 -10
- package/src/state/open.ts +2 -2
- package/src/state/ops.ts +16 -10
- package/src/state/records.ts +5 -5
- package/src/state/runs.ts +33 -26
- package/src/state/saved.ts +44 -32
- package/src/status/file.ts +20 -1
- package/src/status/format.ts +47 -57
- package/src/status/sections.ts +2 -2
- package/src/worker/alignment-report.ts +4 -5
- package/src/worker/answers.ts +26 -24
- package/src/worker/base-check.ts +2 -2
- package/src/worker/kind.ts +23 -19
- package/src/worker/land.ts +114 -126
- package/src/worker/merged.ts +9 -7
- package/src/worker/open.ts +14 -12
- package/src/worker/prose-run.ts +3 -3
- package/src/worker/questions.ts +15 -12
- package/src/worker/scheduler.ts +4 -4
- package/src/worker/signature.ts +3 -3
- package/src/worker/tally.ts +0 -2
- package/src/worker/taste.ts +6 -15
- package/src/worker/thin-path.ts +148 -121
- package/src/worker/thread.ts +25 -0
- package/src/worker/worker.ts +77 -47
- package/surface.json +632 -2197
- package/src/slots/scan.ts +0 -26
package/src/worker/questions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ADAPTER_API_VERSION, type Item, type Question, type Questions, type ThreadEntry, type WorkSource } from "../adapter-api.ts";
|
|
1
|
+
import { ADAPTER_API_VERSION, type Item, ItemId, type Question, type Questions, type ThreadEntry, type WorkSource } from "../adapter-api.ts";
|
|
2
2
|
import { visibleText } from "../adapters/marked.ts";
|
|
3
3
|
import { onceCalls } from "../adapters/once.ts";
|
|
4
4
|
import type { Config } from "../config/load.ts";
|
|
@@ -6,7 +6,8 @@ import { composeQuestion, type PlainQuestion, priorityOf, questionOrder, roomToA
|
|
|
6
6
|
import type { State } from "../state/open.ts";
|
|
7
7
|
import type { QueuedQuestion } from "../state/saved.ts";
|
|
8
8
|
import { DAY_MS, HOUR_MS } from "../time.ts";
|
|
9
|
-
import { footprintOf,
|
|
9
|
+
import { footprintOf, doOverlap } from "./scheduler.ts";
|
|
10
|
+
import { openQuestion } from "./thread.ts";
|
|
10
11
|
|
|
11
12
|
export type QuestionContext = {
|
|
12
13
|
readonly state: State;
|
|
@@ -17,10 +18,9 @@ export type QuestionContext = {
|
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
const isOpenQuestion = (thread: readonly ThreadEntry[], text: string): boolean => {
|
|
20
|
-
const
|
|
21
|
-
const reply = thread.findIndex((entry, index) => index > last && (entry.kind === "answer" || (entry.kind === "comment" && entry.author === "person")));
|
|
21
|
+
const open = openQuestion(thread);
|
|
22
22
|
|
|
23
|
-
return
|
|
23
|
+
return open !== undefined && visibleText(open.text) === text;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const keyOf = ({ item, queuedAt }: Pick<QueuedQuestion, "item" | "queuedAt">): string => `${item}@${queuedAt}`;
|
|
@@ -28,10 +28,13 @@ const keyOf = ({ item, queuedAt }: Pick<QueuedQuestion, "item" | "queuedAt">): s
|
|
|
28
28
|
/** How long an asked question is kept: long enough to count the day, and to read late answers to it. */
|
|
29
29
|
const keptFor = ({ hum }: Config): number => Math.max(DAY_MS, hum.questionTimeoutHours * HOUR_MS);
|
|
30
30
|
|
|
31
|
+
/** Whether a question asked at `askedAt` is recent enough that an answer may still come for it. */
|
|
32
|
+
const isKept = (askedAt: number, config: Config, now: number): boolean => now - askedAt <= keptFor(config);
|
|
33
|
+
|
|
31
34
|
const isWaiting = ({ askedAt }: QueuedQuestion): boolean => askedAt === undefined;
|
|
32
35
|
|
|
33
36
|
/** A question to the owner, checked against the question rules and queued for room under the daily cap. One already open, or already queued, is not asked twice. */
|
|
34
|
-
export const queueQuestion = (ctx: QuestionContext, item: Item, draft: Question, plain: PlainQuestion): void => {
|
|
37
|
+
export const queueQuestion = (ctx: Pick<QuestionContext, "state" | "config" | "now">, item: Item, draft: Question, plain: PlainQuestion): void => {
|
|
35
38
|
const { state, config, now } = ctx;
|
|
36
39
|
const question = composeQuestion(draft, plain, item.id, config.hum.questionLimits);
|
|
37
40
|
const known = state.questions.list().some((queued) => queued.item === item.id && isWaiting(queued) && queued.text === question.text);
|
|
@@ -43,7 +46,7 @@ export const queueQuestion = (ctx: QuestionContext, item: Item, draft: Question,
|
|
|
43
46
|
text: question.text,
|
|
44
47
|
options: question.options && [...question.options],
|
|
45
48
|
detail: question.detail,
|
|
46
|
-
priority: priorityOf(item.labels ?? [], config.hum.priorityLabels),
|
|
49
|
+
priority: priorityOf({ labels: item.labels ?? [], priorityLabels: config.hum.priorityLabels }),
|
|
47
50
|
footprint: footprintOf(item) && [...(footprintOf(item) ?? [])],
|
|
48
51
|
queuedAt: now(),
|
|
49
52
|
};
|
|
@@ -55,7 +58,7 @@ const waitingOrder = (queue: readonly QueuedQuestion[]): QueuedQuestion[] => {
|
|
|
55
58
|
const ranked = queue.map((queued): Waiting & { queued: QueuedQuestion } => ({
|
|
56
59
|
item: queued.item,
|
|
57
60
|
priority: queued.priority,
|
|
58
|
-
behind: queue.filter((other) => other !== queued &&
|
|
61
|
+
behind: queue.filter((other) => other !== queued && doOverlap(queued.footprint, other.footprint)).length,
|
|
59
62
|
since: queued.queuedAt,
|
|
60
63
|
queued,
|
|
61
64
|
}));
|
|
@@ -68,15 +71,15 @@ export const releaseQuestions = async (ctx: QuestionContext): Promise<string[]>
|
|
|
68
71
|
const { state, config, workSource, questions, now } = ctx;
|
|
69
72
|
const all = state.questions.list();
|
|
70
73
|
|
|
71
|
-
for (const old of all) if (old.askedAt !== undefined &&
|
|
74
|
+
for (const old of all) if (old.askedAt !== undefined && !isKept(old.askedAt, config, now())) state.questions.remove(keyOf(old));
|
|
72
75
|
|
|
73
|
-
const room = roomToAsk(all.flatMap(({ askedAt }) => (askedAt === undefined ? [] : [askedAt])), config.hum.dailyQuestionCap, now());
|
|
76
|
+
const room = roomToAsk({ askedAt: all.flatMap(({ askedAt }) => (askedAt === undefined ? [] : [askedAt])), cap: config.hum.dailyQuestionCap, now: now() });
|
|
74
77
|
const released: string[] = [];
|
|
75
78
|
|
|
76
79
|
for (const queued of waitingOrder(all.filter(isWaiting)).slice(0, room)) {
|
|
77
80
|
const calls = onceCalls({ apiVersion: ADAPTER_API_VERSION, workSource, questions }, state.ops, { run: "ask", attempt: queued.queuedAt });
|
|
78
81
|
|
|
79
|
-
await calls.questions?.ask(queued.item, { text: queued.text, options: queued.options, detail: queued.detail });
|
|
82
|
+
await calls.questions?.ask(ItemId.parse(queued.item), { text: queued.text, options: queued.options, detail: queued.detail });
|
|
80
83
|
state.questions.put(keyOf(queued), { ...queued, askedAt: now() });
|
|
81
84
|
released.push(queued.item);
|
|
82
85
|
}
|
|
@@ -86,4 +89,4 @@ export const releaseQuestions = async (ctx: QuestionContext): Promise<string[]>
|
|
|
86
89
|
|
|
87
90
|
/** Items whose question was asked recently enough that an answer may still come for it. */
|
|
88
91
|
export const recentlyAsked = ({ state, config, now }: Pick<QuestionContext, "state" | "config" | "now">): string[] =>
|
|
89
|
-
state.questions.list().flatMap(({ item, askedAt }) => (askedAt !== undefined &&
|
|
92
|
+
state.questions.list().flatMap(({ item, askedAt }) => (askedAt !== undefined && isKept(askedAt, config, now()) ? [item] : []));
|
package/src/worker/scheduler.ts
CHANGED
|
@@ -26,10 +26,10 @@ const isRoot = (folder: string): boolean => folder === "";
|
|
|
26
26
|
const isWithin = (inner: string, outer: string): boolean => inner === outer || inner.startsWith(`${outer}/`);
|
|
27
27
|
|
|
28
28
|
/** Two folders are related when either holds the other; the repo root holds every folder. */
|
|
29
|
-
const
|
|
29
|
+
const areRelated = (a: string, b: string): boolean => isRoot(a) || isRoot(b) || isWithin(a, b) || isWithin(b, a);
|
|
30
30
|
|
|
31
31
|
/** Safe by default: two items clash when either footprint is unknown or any path of one lies in the other's. */
|
|
32
|
-
export const
|
|
32
|
+
export const doOverlap = (a: Footprint, b: Footprint): boolean => a === undefined || b === undefined || a.some((x) => b.some((y) => areRelated(folderOf(x), folderOf(y))));
|
|
33
33
|
|
|
34
34
|
export type Candidate = {
|
|
35
35
|
readonly id: string;
|
|
@@ -64,7 +64,7 @@ export const pick = ({ now, limitedUntil, runners, running, queue }: PickInput):
|
|
|
64
64
|
return ordered.reduce<Picked>(
|
|
65
65
|
(picked, candidate, index) => {
|
|
66
66
|
const ahead = [...running, ...ordered.slice(0, index)];
|
|
67
|
-
const clashes = ahead.some((other) =>
|
|
67
|
+
const clashes = ahead.some((other) => doOverlap(other.footprint, candidate.footprint));
|
|
68
68
|
const isFull = running.length + picked.start.length >= runners;
|
|
69
69
|
|
|
70
70
|
return clashes || isFull ? { ...picked, deferred: [...picked.deferred, candidate] } : { ...picked, start: [...picked.start, candidate] };
|
|
@@ -92,7 +92,7 @@ export class PrefixGate {
|
|
|
92
92
|
readonly #open = new Map<string, { readonly promise: Promise<void>; readonly resolve: () => void }>();
|
|
93
93
|
readonly #warm = new Map<string, number>();
|
|
94
94
|
|
|
95
|
-
constructor({ now
|
|
95
|
+
constructor({ now, ttlMs = CACHE_TTL_MS }: { now: () => number; ttlMs?: number }) {
|
|
96
96
|
this.#now = now;
|
|
97
97
|
this.#ttl = ttlMs;
|
|
98
98
|
}
|
package/src/worker/signature.ts
CHANGED
|
@@ -14,7 +14,7 @@ const LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "pnpm-lock.yaml
|
|
|
14
14
|
const isInside = (path: string, folder: string): boolean => path === folder || path.startsWith(`${folder}/`);
|
|
15
15
|
|
|
16
16
|
/** Every file under `folder` of `root`, hidden ones too, as paths from `root` in a stable order, without the items folder: every claim, answer and merge changes it, and it is no config. */
|
|
17
|
-
const filesUnder = (root: string
|
|
17
|
+
const filesUnder = ({ root, folder, itemsDir }: { readonly root: string; readonly folder: string; readonly itemsDir: string }): string[] =>
|
|
18
18
|
existsSync(join(root, folder))
|
|
19
19
|
? [...new Bun.Glob("**").scanSync({ cwd: join(root, folder), dot: true, onlyFiles: true })].flatMap((path) => (isInside(join(folder, path), itemsDir) ? [] : [join(folder, path)])).sort()
|
|
20
20
|
: [];
|
|
@@ -31,9 +31,9 @@ export const installedVersion = (repo: string, fallback: string): string => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/** The installed engine version and one hash of the lockfile, `.hum/` (without its items) and `adapters/`. */
|
|
34
|
-
export const signatureOf = (repo: string
|
|
34
|
+
export const signatureOf = ({ repo, fallbackVersion, itemsDir }: { readonly repo: string; readonly fallbackVersion: string; readonly itemsDir: string }): Signature => {
|
|
35
35
|
const hash = createHash("sha256");
|
|
36
|
-
const files = [...LOCKFILES.filter((name) => existsSync(join(repo, name))), ...filesUnder(repo, ".hum", itemsDir), ...filesUnder(repo, "adapters", itemsDir)];
|
|
36
|
+
const files = [...LOCKFILES.filter((name) => existsSync(join(repo, name))), ...filesUnder({ root: repo, folder: ".hum", itemsDir }), ...filesUnder({ root: repo, folder: "adapters", itemsDir })];
|
|
37
37
|
|
|
38
38
|
for (const file of files) hash.update(relative(repo, join(repo, file))).update("\0").update(readFileSync(join(repo, file))).update("\0");
|
|
39
39
|
|
package/src/worker/tally.ts
CHANGED
package/src/worker/taste.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { PATCH } from "../adapters/git.ts";
|
|
2
|
-
import type { Pull, PullRequests } from "../adapters/pull-requests.ts";
|
|
3
2
|
import { isTrusted } from "../decide/prose.ts";
|
|
4
3
|
import { type TasteResult, tasteComment, tasteQuestion } from "../decide/taste.ts";
|
|
5
|
-
import type { LandContext } from "./land.ts";
|
|
4
|
+
import type { LandContext, PullAtHead } from "./land.ts";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Comments on the pull request whether its diff keeps each of the owner's taste rules, once per head. The comment
|
|
9
8
|
* reports only: no result reaches the placement, the route or the merge.
|
|
10
9
|
*/
|
|
11
|
-
export const reportTaste = async (ctx: LandContext, pulls
|
|
10
|
+
export const reportTaste = async (ctx: LandContext, { pulls, pull, head }: PullAtHead): Promise<void> => {
|
|
12
11
|
const { rules, ...bar } = { rules: ctx.config.hum.tasteRules, measuredModels: ctx.config.hum.measuredModels, minJudgeRate: ctx.config.hum.minJudgeRate };
|
|
13
12
|
|
|
14
13
|
if (rules.length === 0) return;
|
|
@@ -19,19 +18,11 @@ export const reportTaste = async (ctx: LandContext, pulls: PullRequests, pull: P
|
|
|
19
18
|
holds: async () => false,
|
|
20
19
|
run: async () => {
|
|
21
20
|
const diff = await ctx.git.raw(["diff", ...PATCH, `origin/${ctx.base}...${head}`]);
|
|
22
|
-
const
|
|
21
|
+
const verdicts = await Promise.all(rules.map(async (rule) => ({ rule, judged: await ctx.judge({ ...tasteQuestion(rule, diff, ctx.config.hum), item: ctx.id }) })));
|
|
22
|
+
const results: TasteResult[] = verdicts.map(({ rule, judged }) => ({ rule, answer: judged.kind === "picked" ? judged.value : { abstained: judged.why } }));
|
|
23
|
+
const models = new Set(verdicts.flatMap(({ judged }) => (judged.kind === "picked" ? judged.models : [])));
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (const rule of rules) {
|
|
27
|
-
const judged = await ctx.judge({ ...tasteQuestion(rule, diff, ctx.config.hum), item: ctx.id });
|
|
28
|
-
|
|
29
|
-
if (judged.kind === "picked") judged.models.forEach((model) => models.add(model));
|
|
30
|
-
|
|
31
|
-
results.push({ rule, answer: judged.kind === "picked" ? judged.value : { abstained: judged.why } });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
await pulls.comment(pull, tasteComment(results, isTrusted([...models], "taste", bar)));
|
|
25
|
+
await pulls.comment(pull, tasteComment(results, { measured: isTrusted([...models], "taste", bar) }));
|
|
35
26
|
},
|
|
36
27
|
},
|
|
37
28
|
);
|