@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/config/schema.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const FIXED_PARTS = [
|
|
|
24
24
|
|
|
25
25
|
export const PURPOSES = ["plan", "build", "fix", "review"] as const;
|
|
26
26
|
export const SIZES = ["small", "medium", "large"] as const;
|
|
27
|
-
|
|
27
|
+
const TIERS = ["light", "standard", "top"] as const;
|
|
28
28
|
export const EFFORTS = ["low", "medium", "high"] as const;
|
|
29
29
|
|
|
30
30
|
/** A machine state tagged with either of these waits on something outside the run. */
|
|
@@ -49,7 +49,7 @@ const branchPrefix = z
|
|
|
49
49
|
.refine(isBranchPrefix, "a branch prefix followed by an item id must make a valid git branch name");
|
|
50
50
|
|
|
51
51
|
/** Where hum runs: a service on the owner's Mac, and a scheduled and event-woken CI workflow. */
|
|
52
|
-
|
|
52
|
+
const RUN_PLACES = ["mac", "ci"] as const;
|
|
53
53
|
|
|
54
54
|
export type RunPlace = (typeof RUN_PLACES)[number];
|
|
55
55
|
|
|
@@ -61,10 +61,10 @@ export type MergeMethod = (typeof MERGE_METHODS)[number];
|
|
|
61
61
|
export const REVIEWS = ["none", "agent", "owner"] as const;
|
|
62
62
|
|
|
63
63
|
/** When a merged change ships: at once, or once the proof its path names arrives. */
|
|
64
|
-
|
|
64
|
+
const RELEASES = ["at-once", "after-proof"] as const;
|
|
65
65
|
|
|
66
66
|
/** What a break after merge becomes: follow-up work, or a block on the path. */
|
|
67
|
-
|
|
67
|
+
const BREAKS = ["follow-up", "block"] as const;
|
|
68
68
|
|
|
69
69
|
/** Each place a model's judgment decides, measured on its own labelled set. */
|
|
70
70
|
export const BOUNDARIES = ["kind", "alignment", "plan-outcome", "review-verdict", "reply-option", "repeat-pair", "taste"] as const;
|
|
@@ -87,10 +87,10 @@ const pattern = z.string().min(1).refine(isRegExp, "a pattern is a valid regular
|
|
|
87
87
|
const date = z.iso.date();
|
|
88
88
|
|
|
89
89
|
/** When a refresh step runs: after every return, or only when a lockfile changed since the slot was last installed. */
|
|
90
|
-
|
|
90
|
+
const REFRESH_WHEN = ["always", "lockfile-changed"] as const;
|
|
91
91
|
|
|
92
92
|
/** Whether a slot gets its own services, or every slot shares one set and gets its own database. */
|
|
93
|
-
|
|
93
|
+
const SLOT_SERVICES = ["per-slot", "shared"] as const;
|
|
94
94
|
|
|
95
95
|
const RefreshStep = z.strictObject({ run: name, when: z.enum(REFRESH_WHEN) });
|
|
96
96
|
|
|
@@ -253,7 +253,7 @@ const withShippedDefaults = (settings: Settings): { [Key in keyof Settings]: z.Z
|
|
|
253
253
|
// SAFETY: `Object.fromEntries` loses the per-key types; each entry is its setting with its own shipped default.
|
|
254
254
|
Object.fromEntries(Object.entries<z.ZodType>(settings).map(([key, setting]) => [key, setting.default(SHIPPED_DEFAULTS[key as keyof Settings])])) as never;
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
const Role = z.strictObject({
|
|
257
257
|
file: name,
|
|
258
258
|
purpose: z.enum(PURPOSES),
|
|
259
259
|
skills: z.array(name),
|
package/src/config/settings.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import type { z } from "zod";
|
|
3
3
|
import { orMissing, readJson } from "../state/fs.ts";
|
|
4
|
+
import { migrateConfig } from "./migrate.ts";
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The settings `schema` names, read from the repo's `.hum/hum.json` after it is migrated to the schema version this
|
|
8
|
+
* engine runs. A repo with no `hum.json` gets the schema's own defaults. Throws when the file is unreadable, its
|
|
9
|
+
* schema version is one this engine does not read, or a value is refused.
|
|
10
|
+
*/
|
|
11
|
+
export const readSettings = <S extends z.ZodType>(repo: string, schema: S): z.output<S> => {
|
|
12
|
+
const raw = orMissing(() => readJson(join(repo, ".hum", "hum.json")), undefined);
|
|
13
|
+
|
|
14
|
+
if (raw === undefined) return schema.parse({});
|
|
15
|
+
|
|
16
|
+
const migrated = migrateConfig(raw);
|
|
17
|
+
|
|
18
|
+
if (!migrated.ok) throw new Error(migrated.refusal.message);
|
|
19
|
+
|
|
20
|
+
return schema.parse(migrated.value);
|
|
21
|
+
};
|
package/src/config/state-map.ts
CHANGED
|
@@ -5,9 +5,11 @@ import type { Config } from "./load.ts";
|
|
|
5
5
|
import { kindMachine } from "./machine.ts";
|
|
6
6
|
import type { Kind } from "./schema.ts";
|
|
7
7
|
|
|
8
|
-
/** A work item saved in a state of a kind. */
|
|
8
|
+
/** A work item saved in a state of a kind. `kind` is the kind's `machine.id`, as a saved snapshot records it, which need not be its file name. */
|
|
9
9
|
export type SavedItem = { readonly kind: string; readonly state: string };
|
|
10
10
|
|
|
11
|
+
const kindWithId = (config: Config, id: string): Kind | undefined => Object.values(config.kinds).find((kind) => kind.machine.id === id);
|
|
12
|
+
|
|
11
13
|
/** Where a saved state goes under the new kind: itself, its mapped name, or nowhere. */
|
|
12
14
|
const mappedState = (previous: Kind, next: Kind, state: string): string | undefined => {
|
|
13
15
|
if (state in next.machine.states) return state;
|
|
@@ -19,8 +21,8 @@ const mappedState = (previous: Kind, next: Kind, state: string): string | undefi
|
|
|
19
21
|
/** The saved items whose state the new config neither keeps nor maps. */
|
|
20
22
|
export const unmappedItems = (current: Config, next: Config, saved: readonly SavedItem[]): SavedItem[] =>
|
|
21
23
|
saved.filter(({ kind, state }) => {
|
|
22
|
-
const previous = current
|
|
23
|
-
const target = next
|
|
24
|
+
const previous = kindWithId(current, kind);
|
|
25
|
+
const target = kindWithId(next, kind);
|
|
24
26
|
|
|
25
27
|
return previous !== undefined && (target === undefined || mappedState(previous, target, state) === undefined);
|
|
26
28
|
});
|
package/src/decide/alignment.ts
CHANGED
|
@@ -15,12 +15,12 @@ export const AlignmentAnswer = z.strictObject({ alignment: Grade, verification:
|
|
|
15
15
|
export type AlignmentAnswer = z.infer<typeof AlignmentAnswer>;
|
|
16
16
|
|
|
17
17
|
/** Whether the alignment call may raise a level: the decision model's measured rate at this boundary meets the bar. */
|
|
18
|
-
export const
|
|
18
|
+
export const doesGateAlignment = (config: Pick<HumConfig, "decisionModel" | "measuredModels" | "minJudgeRate">): boolean => isTrusted([config.decisionModel], "alignment", config);
|
|
19
19
|
|
|
20
20
|
/** The cheap model call that grades a change against the item it answers. Below the bar its grades go in a report and decide nothing. */
|
|
21
21
|
export const alignmentQuestion = (item: Pick<Item, "title" | "body">, diff: string, config: Pick<HumConfig, "diffLimit" | "decisionModel" | "measuredModels" | "minJudgeRate">) => ({
|
|
22
22
|
boundary: "alignment" as const,
|
|
23
|
-
reportOnly: !
|
|
23
|
+
reportOnly: !doesGateAlignment(config) || undefined,
|
|
24
24
|
prompt: [
|
|
25
25
|
"Grade this change against the item it answers. alignment: does the diff do what the item asked, no more and no less? verification: do the tests or proof in the diff show it works? Grade each sound, partial or concern.",
|
|
26
26
|
DATA_RULE,
|
|
@@ -61,7 +61,7 @@ const gradeOfRank = (rank: number, levels: number): number => (levels < 2 ? GRAD
|
|
|
61
61
|
* Whether the alignment call's grades raise the level one step: they put the merge-risk score in a higher band than
|
|
62
62
|
* sound grades would at the same level. The call never lowers a level.
|
|
63
63
|
*/
|
|
64
|
-
export const
|
|
64
|
+
export const doesRaiseLevel = ({ rank, levels, answer, config: { mergeRisk } }: { readonly rank: number; readonly levels: number; readonly answer: AlignmentAnswer; readonly config: Pick<HumConfig, "mergeRisk"> }): boolean => {
|
|
65
65
|
const fromLevel = gradeOfRank(rank, levels);
|
|
66
66
|
|
|
67
67
|
const scored = (alignment: number, verification: number): number =>
|
|
@@ -75,5 +75,5 @@ export const alignedPlacement = (placement: Placement, answer: AlignmentAnswer,
|
|
|
75
75
|
const rank = config.levels.findIndex(({ name }) => name === placement.level.name);
|
|
76
76
|
const above = config.levels[Math.min(rank + 1, config.levels.length - 1)];
|
|
77
77
|
|
|
78
|
-
return above &&
|
|
78
|
+
return above && doesRaiseLevel({ rank, levels: config.levels.length, answer, config }) ? { ...placement, level: above, steps: [...placement.steps, { step: "alignment" }] } : placement;
|
|
79
79
|
};
|
package/src/decide/answer.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import type { ThreadEntry } from "../adapter-api.ts";
|
|
3
3
|
import { OWNER_APPROVAL } from "./merge.ts";
|
|
4
4
|
import { DATA_RULE, fenced } from "./prose.ts";
|
|
5
|
+
import { bareWord } from "./question.ts";
|
|
5
6
|
|
|
6
7
|
/** What the model call answers when none of the question's options fits the reply. */
|
|
7
8
|
export const NONE_OF_THESE = "none of these";
|
|
@@ -15,10 +16,17 @@ export type Resolution =
|
|
|
15
16
|
| { readonly source: "none-of-these" }
|
|
16
17
|
| { readonly source: "abstained"; readonly why: string };
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
/** Each way an answer comes to pick its option, by the name its settled answer is saved under. */
|
|
20
|
+
export const RESOLUTION_SOURCES = {
|
|
21
|
+
marker: "marker",
|
|
22
|
+
free: "free",
|
|
23
|
+
"first-word": "first-word",
|
|
24
|
+
model: "model",
|
|
25
|
+
"none-of-these": "none-of-these",
|
|
26
|
+
abstained: "abstained",
|
|
27
|
+
} as const satisfies { readonly [S in Resolution["source"]]: S };
|
|
19
28
|
|
|
20
|
-
const firstWordOf = (text: string): string =>
|
|
21
|
-
(text.trim().split(/\s+/)[0] ?? "").replaceAll(WORD_EDGES, "").toLowerCase();
|
|
29
|
+
const firstWordOf = (text: string): string => bareWord(text.trim().split(/\s+/)[0] ?? "").toLowerCase();
|
|
22
30
|
|
|
23
31
|
/** The option an answer picks by its hidden marker, else by its first word matching an option exactly. */
|
|
24
32
|
export const matchOption = (
|
|
@@ -39,9 +47,7 @@ export const matchOption = (
|
|
|
39
47
|
|
|
40
48
|
/** The cheap model call that picks one of a question's options for a reply no marker or exact word settles. */
|
|
41
49
|
export const replyQuestion = (
|
|
42
|
-
question: string,
|
|
43
|
-
options: readonly string[],
|
|
44
|
-
reply: string,
|
|
50
|
+
{ question, options, reply }: { readonly question: string; readonly options: readonly string[]; readonly reply: string },
|
|
45
51
|
) => ({
|
|
46
52
|
boundary: "reply-option" as const,
|
|
47
53
|
prompt: [
|
|
@@ -65,12 +71,14 @@ export type Stage =
|
|
|
65
71
|
/** It has merged, or otherwise ended. */
|
|
66
72
|
| "ended";
|
|
67
73
|
|
|
74
|
+
export const DISPOSITIONS = ["applied", "held", "dropped"] as const;
|
|
75
|
+
|
|
68
76
|
export type Disposition = {
|
|
69
|
-
readonly disposition:
|
|
77
|
+
readonly disposition: (typeof DISPOSITIONS)[number];
|
|
70
78
|
readonly why: string;
|
|
71
79
|
};
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
type DisposeFacts = {
|
|
74
82
|
readonly resolution: Resolution;
|
|
75
83
|
/** An earlier answer to the same question was applied. */
|
|
76
84
|
readonly answeredBefore: boolean;
|
|
@@ -79,6 +87,11 @@ export type DisposeFacts = {
|
|
|
79
87
|
|
|
80
88
|
const dropped = (why: string): Disposition => ({ disposition: "dropped", why });
|
|
81
89
|
|
|
90
|
+
const isUnmatched = ({ source }: Resolution): boolean => source === "none-of-these" || source === "abstained";
|
|
91
|
+
|
|
92
|
+
/** Whether a model call, not the owner's own word, picked the approval. */
|
|
93
|
+
const isModelApproval = (resolution: Resolution): boolean => resolution.source === "model" && resolution.option === OWNER_APPROVAL;
|
|
94
|
+
|
|
82
95
|
/** D4: every answer is applied, held for the next state, or dropped with its reason. A model's pick never approves a change that waits for the owner's approval. */
|
|
83
96
|
export const dispose = ({
|
|
84
97
|
resolution,
|
|
@@ -87,20 +100,9 @@ export const dispose = ({
|
|
|
87
100
|
}: DisposeFacts): Disposition => {
|
|
88
101
|
if (answeredBefore) return dropped("The question already has an answer.");
|
|
89
102
|
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
return dropped("No option matched the reply.");
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
resolution.source === "model" &&
|
|
98
|
-
resolution.option === OWNER_APPROVAL &&
|
|
99
|
-
stage === "approval"
|
|
100
|
-
)
|
|
101
|
-
return dropped(
|
|
102
|
-
`a model cannot approve it; reply with the word ${OWNER_APPROVAL}`,
|
|
103
|
-
);
|
|
103
|
+
if (isUnmatched(resolution)) return dropped("No option matched the reply.");
|
|
104
|
+
|
|
105
|
+
if (isModelApproval(resolution) && stage === "approval") return dropped(`a model cannot approve it; reply with the word ${OWNER_APPROVAL}`);
|
|
104
106
|
|
|
105
107
|
if (stage === "ended") return dropped("The item has ended.");
|
|
106
108
|
|
package/src/decide/kind.ts
CHANGED
|
@@ -9,11 +9,6 @@ const TEMPLATE_FIELD = /^(?:kind:[ \t]*(\S+)|#{1,6}[ \t]*kind[ \t]*\n+[ \t]*(\S+
|
|
|
9
9
|
/** The answer a model call gives when no kind fits. */
|
|
10
10
|
export const UNSURE = "unsure";
|
|
11
11
|
|
|
12
|
-
/** Where an item's kind came from. A fallback is an abstention: the item is unclear and runs on the fallback kind. */
|
|
13
|
-
export type KindOf =
|
|
14
|
-
| { readonly kind: string; readonly from: "source" | "model" }
|
|
15
|
-
| { readonly kind: string; readonly from: "fallback"; readonly why: string };
|
|
16
|
-
|
|
17
12
|
/** The kind an item names itself: a label the owner mapped to a kind or that is a kind's name, else its template field. */
|
|
18
13
|
export const declaredKind = (item: Pick<Item, "body" | "labels">, kinds: readonly string[], kindLabels: HumConfig["kindLabels"]): string | undefined => {
|
|
19
14
|
const field = TEMPLATE_FIELD.exec(item.body);
|
|
@@ -35,5 +30,5 @@ export const kindQuestion = (item: Pick<Item, "title" | "body">, { kinds, kindMe
|
|
|
35
30
|
});
|
|
36
31
|
|
|
37
32
|
/** A change of the docs-only kind that touches a path outside its globs is not docs. */
|
|
38
|
-
export const
|
|
33
|
+
export const doesLeaveDocs = (paths: readonly string[], { docsOnly }: Pick<HumConfig, "docsOnly">): boolean =>
|
|
39
34
|
paths.some((path) => !docsOnly.paths.some((glob) => new Bun.Glob(glob).match(path)));
|
package/src/decide/labels.ts
CHANGED
|
@@ -22,15 +22,15 @@ const SHA_IN_TEXT = /\b[0-9a-f]{7,40}\b/g;
|
|
|
22
22
|
const shasIn = (text: string): readonly string[] =>
|
|
23
23
|
text.match(SHA_IN_TEXT) ?? [];
|
|
24
24
|
|
|
25
|
-
const
|
|
25
|
+
const doesName = (later: PastChange, earlier: PastChange): boolean =>
|
|
26
26
|
shasIn(`${later.subject}\n${later.body}`).some((sha) =>
|
|
27
27
|
earlier.sha.startsWith(sha),
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const doShareAFile = (a: PastChange, b: PastChange): boolean =>
|
|
31
31
|
a.files.some((file) => b.files.includes(file));
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const doesRevertByTrailer = (
|
|
34
34
|
later: PastChange,
|
|
35
35
|
earlier: PastChange,
|
|
36
36
|
{ revertTrailer }: LabelRules,
|
|
@@ -39,14 +39,14 @@ const revertsByTrailer = (
|
|
|
39
39
|
([, sha]) => sha !== undefined && earlier.sha.startsWith(sha),
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const doesRevertByTitle = (
|
|
43
43
|
later: PastChange,
|
|
44
44
|
earlier: PastChange,
|
|
45
45
|
{ revertSubject }: LabelRules,
|
|
46
46
|
): boolean =>
|
|
47
47
|
new RegExp(revertSubject).test(later.subject) &&
|
|
48
48
|
(later.subject.includes(`"${earlier.subject}"`) ||
|
|
49
|
-
|
|
49
|
+
doesName(later, earlier) ||
|
|
50
50
|
later.blamed.includes(earlier.sha));
|
|
51
51
|
|
|
52
52
|
const isRevertOf = (
|
|
@@ -54,8 +54,8 @@ const isRevertOf = (
|
|
|
54
54
|
earlier: PastChange,
|
|
55
55
|
rules: LabelRules,
|
|
56
56
|
): boolean =>
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
doesRevertByTrailer(later, earlier, rules) ||
|
|
58
|
+
doesRevertByTitle(later, earlier, rules);
|
|
59
59
|
|
|
60
60
|
const isFixOf = (
|
|
61
61
|
later: PastChange,
|
|
@@ -63,7 +63,7 @@ const isFixOf = (
|
|
|
63
63
|
{ fixSubject }: LabelRules,
|
|
64
64
|
): boolean =>
|
|
65
65
|
new RegExp(fixSubject).test(later.subject) &&
|
|
66
|
-
(
|
|
66
|
+
(doesName(later, earlier) || later.blamed.includes(earlier.sha));
|
|
67
67
|
|
|
68
68
|
/** The later change that breaks `changes[at]`, and how: a revert of it, else a fix among the next `fixWindow` changes on its files. */
|
|
69
69
|
export const breakOf = (
|
|
@@ -81,7 +81,7 @@ export const breakOf = (
|
|
|
81
81
|
if (reverting) return { by: reverting, label: "reverted" };
|
|
82
82
|
|
|
83
83
|
const fixing = later
|
|
84
|
-
.filter((next) =>
|
|
84
|
+
.filter((next) => doShareAFile(next, change))
|
|
85
85
|
.slice(0, rules.fixWindow)
|
|
86
86
|
.find((next) => isFixOf(next, change, rules));
|
|
87
87
|
|
package/src/decide/merge.ts
CHANGED
|
@@ -30,11 +30,11 @@ const STRICTEST_PROOF = "the owner's word that the change is proven";
|
|
|
30
30
|
export type Approvals = { readonly review: boolean; readonly owner: boolean };
|
|
31
31
|
|
|
32
32
|
/** What clears a clear change without the owner, by its level's review. The owner's approval clears any change. */
|
|
33
|
-
const CLEARED_BY
|
|
33
|
+
const CLEARED_BY = {
|
|
34
34
|
none: () => true,
|
|
35
35
|
agent: (approvals) => approvals.review,
|
|
36
36
|
owner: () => false,
|
|
37
|
-
}
|
|
37
|
+
} as const satisfies Record<(typeof REVIEWS)[number], (approvals: Approvals) => boolean>;
|
|
38
38
|
|
|
39
39
|
const NO_APPROVALS: Approvals = { review: false, owner: false };
|
|
40
40
|
|
|
@@ -60,7 +60,7 @@ export const routeOf = (
|
|
|
60
60
|
return {
|
|
61
61
|
level,
|
|
62
62
|
unclear,
|
|
63
|
-
mergesAlone:
|
|
63
|
+
mergesAlone: isCleared({ level, unclear }, NO_APPROVALS),
|
|
64
64
|
proof:
|
|
65
65
|
level.release === "after-proof"
|
|
66
66
|
? proofs.join("; ") || STRICTEST_PROOF
|
|
@@ -69,16 +69,15 @@ export const routeOf = (
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
/** A route merges once nothing waits: on its own, once a fresh review approved a clear change at an agent-reviewed level, or once the owner approved it. */
|
|
72
|
-
export const isCleared = (route: Route, approvals: Approvals): boolean =>
|
|
72
|
+
export const isCleared = (route: Pick<Route, "level" | "unclear">, approvals: Approvals): boolean =>
|
|
73
73
|
approvals.owner || (route.unclear.length === 0 && CLEARED_BY[route.level.review](approvals));
|
|
74
74
|
|
|
75
75
|
/** Every level that asks for a review gets a fresh review run first; the owner's review comes after it. */
|
|
76
|
-
export const
|
|
76
|
+
export const doesNeedReviewRun = (route: Route): boolean => route.level.review !== "none";
|
|
77
77
|
|
|
78
78
|
/** Where the target branch requires a pull request, every change lands through one, merging itself only when cleared; elsewhere a cleared change is pushed. */
|
|
79
79
|
export const landingOf = (
|
|
80
|
-
requiresPullRequest: boolean,
|
|
81
|
-
cleared: boolean,
|
|
80
|
+
{ requiresPullRequest, cleared }: { readonly requiresPullRequest: boolean; readonly cleared: boolean },
|
|
82
81
|
): Landing => {
|
|
83
82
|
if (requiresPullRequest) return { via: "pull-request", autoMerge: cleared };
|
|
84
83
|
|
package/src/decide/prose.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { stripVTControlCharacters } from "node:util";
|
|
3
3
|
import parseDiff from "parse-diff";
|
|
4
|
-
import stringify from "safe-stable-stringify";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
import type { Finished } from "../adapters/claude-p.ts";
|
|
6
|
+
import { hashJson } from "../config/hash.ts";
|
|
7
7
|
import type { Boundary, HumConfig } from "../config/schema.ts";
|
|
8
8
|
|
|
9
9
|
const TAG_HASH = 12;
|
|
@@ -41,7 +41,7 @@ export const PlanFile = z.strictObject({
|
|
|
41
41
|
export type PlanFile = z.infer<typeof PlanFile>;
|
|
42
42
|
|
|
43
43
|
/** A plan's identity: a later run reads the plan with this hash, and any other text is not the approved plan. */
|
|
44
|
-
export const planHash = (plan: PlanFile): string =>
|
|
44
|
+
export const planHash = (plan: PlanFile): string => hashJson(plan);
|
|
45
45
|
|
|
46
46
|
/** The two states whose outcome is prose: the events each may pick, and the safer pick an unsure run takes. */
|
|
47
47
|
export const PROSE_STATES = {
|
|
@@ -75,7 +75,7 @@ export const pickSchema = (events: readonly string[]): JsonSchema => jsonSchemaO
|
|
|
75
75
|
const isInHunk = (line: number, { newStart, newLines }: { newStart: number; newLines: number }): boolean => line >= newStart && line < newStart + Math.max(newLines, 1);
|
|
76
76
|
|
|
77
77
|
/** At least one cite, and each names a file the diff changes and a line inside one of its hunks. */
|
|
78
|
-
export const
|
|
78
|
+
export const doesCiteDiff = (cites: readonly Cite[], diff: string): boolean => {
|
|
79
79
|
const files = parseDiff(diff);
|
|
80
80
|
const isChanged = ({ file, line }: Cite): boolean => files.some((changed) => changed.to === file && changed.chunks.some((hunk) => isInHunk(line, hunk)));
|
|
81
81
|
|
|
@@ -84,7 +84,7 @@ export const citesDiff = (cites: readonly Cite[], diff: string): boolean => {
|
|
|
84
84
|
|
|
85
85
|
/** Code's check on the artifact behind a pick: why it fails, or undefined when it holds. */
|
|
86
86
|
const FENCES = new Map<string, (pick: EventPick, diff: string) => string | undefined>([
|
|
87
|
-
["request-changes", (pick, diff) => (
|
|
87
|
+
["request-changes", (pick, diff) => (doesCiteDiff(pick.cites, diff) ? undefined : "request-changes must cite a file and a line the diff changes")],
|
|
88
88
|
["plan-ready", (pick) => (pick.plan ? undefined : "plan-ready must hold a plan: a summary, at least one step and the paths it touches")],
|
|
89
89
|
]);
|
|
90
90
|
|
package/src/decide/question.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { HumConfig } from "../config/schema.ts";
|
|
|
4
4
|
import { DAY_MS } from "../time.ts";
|
|
5
5
|
|
|
6
6
|
/** The reasons a run gives for needing the owner, each with the facts code checks it against. */
|
|
7
|
-
|
|
7
|
+
const ASK_REASONS = ["missing-secret", "past-undoing", "spends-money", "publishes", "choice", "unsure"] as const;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
type AskReason = (typeof ASK_REASONS)[number];
|
|
10
10
|
|
|
11
11
|
const ChoiceOption = z.strictObject({ word: z.string().min(1), paths: z.array(z.string().min(1)) });
|
|
12
12
|
|
|
@@ -33,29 +33,29 @@ export type AskFacts = {
|
|
|
33
33
|
readonly undoableLevels: readonly string[];
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
type AskDecision =
|
|
37
37
|
/** `confirmed`: the facts bear the reason out, so its own question is asked; otherwise the owner gets the plain one. */
|
|
38
38
|
| { readonly action: "ask"; readonly reason: AskReason; readonly confirmed: boolean }
|
|
39
39
|
| { readonly action: "decide"; readonly choice: string; readonly over: readonly string[] };
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
/** The run's own pick, when the choice is cheap to undo: every option touches only the change's own files, on a level where that is safe. */
|
|
42
|
+
const cheapPick = ({ options = [], default: chosen }: RunReason, { changedPaths, level, undoableLevels }: AskFacts): string | undefined =>
|
|
43
|
+
undoableLevels.includes(level) && options.every(({ paths }) => paths.every((path) => changedPaths.includes(path))) ? options.find(({ word }) => word === chosen)?.word : undefined;
|
|
44
44
|
|
|
45
|
-
const CONFIRMS
|
|
45
|
+
const CONFIRMS = {
|
|
46
46
|
"missing-secret": ({ variable }, { runnerVariables }) => variable !== undefined && !runnerVariables.has(variable),
|
|
47
47
|
"past-undoing": ({ command }) => command !== undefined,
|
|
48
48
|
"spends-money": () => true,
|
|
49
49
|
publishes: () => true,
|
|
50
50
|
choice: () => false,
|
|
51
51
|
unsure: () => true,
|
|
52
|
-
}
|
|
52
|
+
} as const satisfies Record<AskReason, (reason: RunReason, facts: AskFacts) => boolean>;
|
|
53
53
|
|
|
54
54
|
/** Whether the owner is asked: a reason the facts cannot confirm still asks, and a cheap choice is made without them. */
|
|
55
55
|
export const askDecision = (reason: RunReason, facts: AskFacts): AskDecision => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
56
|
+
const choice = reason.kind === "choice" ? cheapPick(reason, facts) : undefined;
|
|
57
|
+
|
|
58
|
+
if (choice !== undefined) return { action: "decide", choice, over: (reason.options ?? []).map(({ word }) => word) };
|
|
59
59
|
|
|
60
60
|
return { action: "ask", reason: reason.kind, confirmed: CONFIRMS[reason.kind](reason, facts) };
|
|
61
61
|
};
|
|
@@ -86,10 +86,10 @@ const ASKED = {
|
|
|
86
86
|
unsure: () => PLAIN_QUESTIONS.unsure,
|
|
87
87
|
} as const satisfies Record<AskReason, (reason: RunReason) => string>;
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
type AskedQuestion = { readonly question: Question; readonly plain: PlainQuestion };
|
|
90
90
|
|
|
91
91
|
/** The question a run's need becomes. A reason the facts bear out asks its own question with the run's words folded; any other asks in the run's words. */
|
|
92
|
-
export const askedQuestion = (reason: RunReason
|
|
92
|
+
export const askedQuestion = ({ reason, confirmed, runsWords }: { readonly reason: RunReason; readonly confirmed: boolean; readonly runsWords: string | undefined }): AskedQuestion => {
|
|
93
93
|
const kind = confirmed ? reason.kind : "unsure";
|
|
94
94
|
const options = reason.options?.map(({ word }) => word);
|
|
95
95
|
|
|
@@ -105,7 +105,7 @@ const SIDE_QUESTIONS: readonly string[] = [PLAIN_QUESTIONS.kind, PLAIN_QUESTIONS
|
|
|
105
105
|
export const isWaitQuestion = (text: string): boolean => !SIDE_QUESTIONS.includes(text);
|
|
106
106
|
|
|
107
107
|
/** Why a question text is refused. */
|
|
108
|
-
|
|
108
|
+
type QuestionIssue = "too-wide" | "no-question-mark" | "names-item" | "long-word";
|
|
109
109
|
|
|
110
110
|
const QUESTION_MARK = "?";
|
|
111
111
|
|
|
@@ -113,11 +113,14 @@ const words = (text: string): string[] => text.split(/\s+/).filter(Boolean);
|
|
|
113
113
|
|
|
114
114
|
const cellsOf = (text: string): number => Bun.stringWidth(text);
|
|
115
115
|
|
|
116
|
-
const WORD_EDGES =
|
|
116
|
+
const WORD_EDGES = /^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu;
|
|
117
|
+
|
|
118
|
+
/** A word without the punctuation around it. */
|
|
119
|
+
export const bareWord = (word: string): string => word.replaceAll(WORD_EDGES, "");
|
|
117
120
|
|
|
118
121
|
/** The question text rules: at most `cells` wide, ends in "?", names no item id, and no word over `wordCells`. */
|
|
119
|
-
export const questionIssues = (text
|
|
120
|
-
const mentionsItem = words(text).some((word) => word
|
|
122
|
+
export const questionIssues = ({ text, item, limits: { cells, wordCells } }: { readonly text: string; readonly item: string; readonly limits: HumConfig["questionLimits"] }): QuestionIssue[] => {
|
|
123
|
+
const mentionsItem = words(text).some((word) => bareWord(word) === item);
|
|
121
124
|
|
|
122
125
|
return [
|
|
123
126
|
...(cellsOf(text) > cells ? (["too-wide"] as const) : []),
|
|
@@ -129,7 +132,7 @@ export const questionIssues = (text: string, item: string, { cells, wordCells }:
|
|
|
129
132
|
|
|
130
133
|
/** A question to put on the thread: the run's own text when it passes the rules, else the plain one with the run's text folded. */
|
|
131
134
|
export const composeQuestion = (draft: Question, plain: PlainQuestion, item: string, limits: HumConfig["questionLimits"]): Question => {
|
|
132
|
-
if (questionIssues(draft.text, item, limits).length === 0) return draft;
|
|
135
|
+
if (questionIssues({ text: draft.text, item, limits }).length === 0) return draft;
|
|
133
136
|
|
|
134
137
|
return { ...draft, text: PLAIN_QUESTIONS[plain], detail: [draft.text, draft.detail].filter(Boolean).join("\n\n") };
|
|
135
138
|
};
|
|
@@ -148,12 +151,12 @@ export type Waiting = {
|
|
|
148
151
|
export const questionOrder = (a: Waiting, b: Waiting): number => a.priority - b.priority || b.behind - a.behind || a.since - b.since;
|
|
149
152
|
|
|
150
153
|
/** The priority of an item: the index of its first label in the owner's list, or past the end when it has none. */
|
|
151
|
-
export const priorityOf = (labels: readonly string[]
|
|
154
|
+
export const priorityOf = ({ labels, priorityLabels }: { readonly labels: readonly string[]; readonly priorityLabels: readonly string[] }): number => {
|
|
152
155
|
const found = priorityLabels.findIndex((label) => labels.includes(label));
|
|
153
156
|
|
|
154
157
|
return found < 0 ? priorityLabels.length : found;
|
|
155
158
|
};
|
|
156
159
|
|
|
157
160
|
/** How many more questions the owner can be asked now: the cap less those asked within the last day. No cap leaves no limit. */
|
|
158
|
-
export const roomToAsk = (askedAt: readonly number[]
|
|
161
|
+
export const roomToAsk = ({ askedAt, cap, now }: { readonly askedAt: readonly number[]; readonly cap: number | undefined; readonly now: number }): number =>
|
|
159
162
|
cap === undefined ? Number.POSITIVE_INFINITY : Math.max(0, cap - askedAt.filter((at) => now - at < DAY_MS).length);
|
package/src/decide/review.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Item } from "../adapter-api.ts";
|
|
2
1
|
import type { HumConfig } from "../config/schema.ts";
|
|
3
2
|
import { DATA_RULE, fenced } from "./prose.ts";
|
|
4
3
|
|
|
@@ -6,5 +5,8 @@ import { DATA_RULE, fenced } from "./prose.ts";
|
|
|
6
5
|
* What a fresh review run reads: the item as the owner asked it and the change's diff. It takes no thread, so the
|
|
7
6
|
* author's plan, questions and answers never reach the reviewer.
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
/** What a prompt quotes of an item: plain text, whatever its id's source. */
|
|
9
|
+
export type ItemText = { readonly id: string; readonly title: string; readonly body: string };
|
|
10
|
+
|
|
11
|
+
export const reviewInput = (item: ItemText, diff: string, { diffLimit }: Pick<HumConfig, "diffLimit">): string =>
|
|
10
12
|
[`# Item ${item.id}: ${item.title}`, DATA_RULE, fenced("item", item.body.trim()), `## The change`, fenced("diff", diff.slice(0, diffLimit))].join("\n\n");
|
package/src/decide/risk.ts
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { quantile } from "simple-statistics";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import type { HumConfig, Launch, Level, PathRule } from "../config/schema.ts";
|
|
3
4
|
|
|
4
5
|
/** What only the owner changes: hum's own config, the owner's adapters and the CI workflows. */
|
|
5
6
|
const OWN_PATHS = [".hum/**", "adapters/**", ".github/workflows/**"] as const;
|
|
6
7
|
|
|
7
8
|
/** What hum reads from a change's diff. */
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
export const Change = z
|
|
10
|
+
.object({
|
|
11
|
+
paths: z.array(z.string().min(1)).readonly(),
|
|
12
|
+
/** Lines added plus lines deleted. */
|
|
13
|
+
size: z.int().nonnegative(),
|
|
14
|
+
/** An added or removed line matches the project's loosened-check rule. */
|
|
15
|
+
loosened: z.boolean(),
|
|
16
|
+
/** A changed line in `package.json` or a lockfile names the engine package. */
|
|
17
|
+
pinChanged: z.boolean(),
|
|
18
|
+
})
|
|
19
|
+
.readonly();
|
|
20
|
+
|
|
21
|
+
export type Change = z.infer<typeof Change>;
|
|
17
22
|
|
|
18
23
|
export const LABELS = ["reverted", "fixed", "clean"] as const;
|
|
19
24
|
|
|
@@ -76,12 +81,12 @@ export type Placement = {
|
|
|
76
81
|
readonly steps: readonly Step[];
|
|
77
82
|
};
|
|
78
83
|
|
|
79
|
-
const
|
|
84
|
+
const doesMatch = (glob: string, path: string): boolean =>
|
|
80
85
|
new Bun.Glob(glob).match(path);
|
|
81
86
|
|
|
82
87
|
const isLaunchOn = (launch: Launch, { now, base }: Moment): boolean =>
|
|
83
88
|
"base" in launch
|
|
84
|
-
?
|
|
89
|
+
? doesMatch(launch.base, base)
|
|
85
90
|
: Date.parse(launch.from) <= now && now < Date.parse(launch.until);
|
|
86
91
|
|
|
87
92
|
/** Fixed or reverted changes among a path's last `of` merged changes. */
|
|
@@ -119,13 +124,16 @@ export const placeChange = (
|
|
|
119
124
|
names[Math.min(strictest, rank(name) + 1)] ?? name;
|
|
120
125
|
|
|
121
126
|
const rulesOn = (path: string): readonly PathRule[] =>
|
|
122
|
-
policy.paths.filter((rule) =>
|
|
127
|
+
policy.paths.filter((rule) => doesMatch(rule.glob, path));
|
|
123
128
|
|
|
124
129
|
const isStrict = (path: string): boolean =>
|
|
125
|
-
policy.strictPaths.some((glob) =>
|
|
130
|
+
policy.strictPaths.some((glob) => doesMatch(glob, path));
|
|
126
131
|
|
|
127
132
|
const isOwn = (path: string): boolean =>
|
|
128
|
-
[...OWN_PATHS, ...policy.hookPaths].some((glob) =>
|
|
133
|
+
[...OWN_PATHS, ...policy.hookPaths].some((glob) => doesMatch(glob, path));
|
|
134
|
+
|
|
135
|
+
/** A path no rule places, outside the strict paths and hum's own. */
|
|
136
|
+
const isUnclear = (path: string): boolean => rulesOn(path).length === 0 && !isStrict(path) && !isOwn(path);
|
|
129
137
|
|
|
130
138
|
const touched = [
|
|
131
139
|
...new Map(
|
|
@@ -162,7 +170,7 @@ export const placeChange = (
|
|
|
162
170
|
|
|
163
171
|
const launchSteps = policy.launches.flatMap((launch): SetsLevel[] =>
|
|
164
172
|
isLaunchOn(launch, moment) &&
|
|
165
|
-
change.paths.some((path) =>
|
|
173
|
+
change.paths.some((path) => doesMatch(launch.glob, path))
|
|
166
174
|
? [{ step: "launch", glob: launch.glob, level: launch.level }]
|
|
167
175
|
: [],
|
|
168
176
|
);
|
|
@@ -176,7 +184,7 @@ export const placeChange = (
|
|
|
176
184
|
),
|
|
177
185
|
...(change.pinChanged ? [{ step: "engine-pin" } as const] : []),
|
|
178
186
|
...change.paths.flatMap((path): Step[] =>
|
|
179
|
-
(moment.blocked ?? []).some((glob) =>
|
|
187
|
+
(moment.blocked ?? []).some((glob) => doesMatch(glob, path)) ? [{ step: "blocked-path", path }] : [],
|
|
180
188
|
),
|
|
181
189
|
];
|
|
182
190
|
|
|
@@ -208,9 +216,7 @@ export const placeChange = (
|
|
|
208
216
|
|
|
209
217
|
return {
|
|
210
218
|
level,
|
|
211
|
-
unclear: change.paths.filter(
|
|
212
|
-
(path) => rulesOn(path).length === 0 && !isStrict(path) && !isOwn(path),
|
|
213
|
-
),
|
|
219
|
+
unclear: change.paths.filter(isUnclear),
|
|
214
220
|
steps: [...ruleSteps, ...launchSteps, ...kindFloorSteps, ...floors, ...bumps],
|
|
215
221
|
};
|
|
216
222
|
};
|
package/src/decide/taste.ts
CHANGED
|
@@ -3,9 +3,9 @@ import type { HumConfig } from "../config/schema.ts";
|
|
|
3
3
|
import { DATA_RULE, fenced } from "./prose.ts";
|
|
4
4
|
|
|
5
5
|
/** Whether the diff keeps one taste rule, and the line of the diff that shows it. */
|
|
6
|
-
|
|
6
|
+
const TasteAnswer = z.strictObject({ keeps: z.boolean(), evidence: z.string() });
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type TasteAnswer = z.infer<typeof TasteAnswer>;
|
|
9
9
|
|
|
10
10
|
/** The cheap model call that checks a diff against one taste rule. Its pick is for a report and decides nothing. */
|
|
11
11
|
export const tasteQuestion = (rule: string, diff: string, { diffLimit }: Pick<HumConfig, "diffLimit">) => ({
|
|
@@ -24,7 +24,7 @@ export const tasteQuestion = (rule: string, diff: string, { diffLimit }: Pick<Hu
|
|
|
24
24
|
export type TasteResult = { readonly rule: string; readonly answer: TasteAnswer | { readonly abstained: string } };
|
|
25
25
|
|
|
26
26
|
/** The pull request comment. It only reports; `measured` says whether the model's rate at this boundary meets the bar. */
|
|
27
|
-
export const tasteComment = (results: readonly TasteResult[], measured: boolean): string => {
|
|
27
|
+
export const tasteComment = (results: readonly TasteResult[], { measured }: { readonly measured: boolean }): string => {
|
|
28
28
|
const lines = results.map(({ rule, answer }) => {
|
|
29
29
|
if ("abstained" in answer) return `- ? ${rule} (not checked: ${answer.abstained})`;
|
|
30
30
|
|