@moo.md/hum 0.0.0-stage → 0.1.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/defaults/hum.json +321 -0
- package/defaults/kinds/check.json +183 -0
- package/defaults/kinds/docs.json +151 -0
- package/defaults/kinds/feature.json +202 -0
- package/defaults/kinds/fix.json +183 -0
- package/defaults/kinds/hotfix.json +164 -0
- package/defaults/roles/build.md +3 -0
- package/defaults/roles/fix.md +1 -0
- package/defaults/roles/plan.md +3 -0
- package/defaults/roles/review.md +3 -0
- package/evals/alignment/RESULTS.md +8 -0
- package/evals/alignment/cases.jsonl +128 -0
- package/evals/alignment/sample.jsonl +20 -0
- package/evals/kind/RESULTS.md +5 -0
- package/evals/kind/cases.jsonl +24 -0
- package/evals/plan-outcome/RESULTS.md +4 -0
- package/evals/plan-outcome/cases.jsonl +12 -0
- package/evals/repeat-pair/RESULTS.md +4 -0
- package/evals/repeat-pair/cases.jsonl +51 -0
- package/evals/reply-option/RESULTS.md +3 -0
- package/evals/reply-option/cases.jsonl +45 -0
- package/evals/review-verdict/RESULTS.md +4 -0
- package/evals/review-verdict/cases.jsonl +12 -0
- package/package.json +88 -4
- package/schema/hum.schema.json +1355 -0
- package/scripts/eval.ts +244 -0
- package/src/adapter-api.ts +134 -0
- package/src/adapters/admit.ts +111 -0
- package/src/adapters/argument.ts +11 -0
- package/src/adapters/claim.ts +93 -0
- package/src/adapters/claude-bg.ts +392 -0
- package/src/adapters/claude-p.ts +599 -0
- package/src/adapters/contract.ts +231 -0
- package/src/adapters/fake.ts +157 -0
- package/src/adapters/git.ts +156 -0
- package/src/adapters/github.ts +479 -0
- package/src/adapters/guard.ts +152 -0
- package/src/adapters/history.ts +215 -0
- package/src/adapters/item-file.ts +102 -0
- package/src/adapters/limit.ts +67 -0
- package/src/adapters/markdown.ts +365 -0
- package/src/adapters/marked.ts +127 -0
- package/src/adapters/model-call.ts +75 -0
- package/src/adapters/once.ts +45 -0
- package/src/adapters/owner-commit.ts +60 -0
- package/src/adapters/pull-requests.ts +253 -0
- package/src/adapters/registry.ts +156 -0
- package/src/adapters/roundup.ts +293 -0
- package/src/adapters/serial.ts +22 -0
- package/src/adapters/transcript.ts +99 -0
- package/src/cli/commands.ts +46 -0
- package/src/cli/main.ts +8 -0
- package/src/cli/ops.ts +224 -0
- package/src/cli/service.ts +156 -0
- package/src/cli/setup.ts +141 -0
- package/src/cli/shared-watch.ts +127 -0
- package/src/config/change.ts +54 -0
- package/src/config/checks.ts +217 -0
- package/src/config/git-ref-name.d.ts +3 -0
- package/src/config/hash.ts +6 -0
- package/src/config/json.ts +6 -0
- package/src/config/load.ts +88 -0
- package/src/config/machine.ts +20 -0
- package/src/config/migrate.ts +61 -0
- package/src/config/refusal.ts +58 -0
- package/src/config/schema.ts +465 -0
- package/src/config/settings.ts +6 -0
- package/src/config/state-map.ts +76 -0
- package/src/decide/alignment.ts +79 -0
- package/src/decide/answer.ts +131 -0
- package/src/decide/kind.ts +39 -0
- package/src/decide/labels.ts +137 -0
- package/src/decide/merge.ts +102 -0
- package/src/decide/prose.ts +109 -0
- package/src/decide/question.ts +159 -0
- package/src/decide/review.ts +10 -0
- package/src/decide/risk.ts +216 -0
- package/src/decide/taste.ts +37 -0
- package/src/exec.ts +85 -0
- package/src/index.ts +200 -0
- package/src/loop/breaks.ts +8 -0
- package/src/loop/check-item.ts +76 -0
- package/src/loop/ci.ts +8 -0
- package/src/loop/github.ts +81 -0
- package/src/loop/groups.ts +108 -0
- package/src/loop/memory.ts +70 -0
- package/src/loop/notes.ts +76 -0
- package/src/loop/pair.ts +39 -0
- package/src/loop/pass.ts +99 -0
- package/src/loop/proof.ts +85 -0
- package/src/loop/prove-item.ts +33 -0
- package/src/loop/records.ts +75 -0
- package/src/loop/signals.ts +130 -0
- package/src/measure/inputs.ts +28 -0
- package/src/measure/measure.ts +68 -0
- package/src/service/cards.ts +24 -0
- package/src/service/ci-tick.ts +28 -0
- package/src/service/launchd.ts +16 -0
- package/src/service/supervise.ts +145 -0
- package/src/service/systemd.ts +44 -0
- package/src/service/token.ts +21 -0
- package/src/service/unit.ts +29 -0
- package/src/service/wake.ts +30 -0
- package/src/service/workflows.ts +97 -0
- package/src/setup/propose.ts +120 -0
- package/src/setup/prove.ts +216 -0
- package/src/setup/scan.ts +186 -0
- package/src/setup/scratch.ts +81 -0
- package/src/setup/shipped.ts +15 -0
- package/src/setup/tables.ts +101 -0
- package/src/setup/waits.ts +58 -0
- package/src/setup/write.ts +161 -0
- package/src/slots/env.ts +42 -0
- package/src/slots/pool.ts +329 -0
- package/src/slots/scan.ts +26 -0
- package/src/slots/worktree.ts +17 -0
- package/src/state/events.ts +52 -0
- package/src/state/faults.ts +73 -0
- package/src/state/format.ts +50 -0
- package/src/state/fs.ts +100 -0
- package/src/state/items.ts +195 -0
- package/src/state/open.ts +80 -0
- package/src/state/ops.ts +76 -0
- package/src/state/records.ts +35 -0
- package/src/state/runs.ts +99 -0
- package/src/state/saved.ts +119 -0
- package/src/status/file.ts +49 -0
- package/src/status/format.ts +132 -0
- package/src/status/sections.ts +14 -0
- package/src/status/version.ts +2 -0
- package/src/time.ts +7 -0
- package/src/worker/alignment-report.ts +18 -0
- package/src/worker/answers.ts +153 -0
- package/src/worker/base-check.ts +45 -0
- package/src/worker/checks.ts +40 -0
- package/src/worker/kind.ts +68 -0
- package/src/worker/land.ts +509 -0
- package/src/worker/lifecycle.ts +97 -0
- package/src/worker/merged.ts +29 -0
- package/src/worker/open.ts +100 -0
- package/src/worker/prose-run.ts +56 -0
- package/src/worker/questions.ts +89 -0
- package/src/worker/scheduler.ts +135 -0
- package/src/worker/signature.ts +41 -0
- package/src/worker/tally.ts +25 -0
- package/src/worker/taste.ts +38 -0
- package/src/worker/thin-path.ts +886 -0
- package/src/worker/worker.ts +750 -0
- package/surface.json +8787 -0
- package/README.md +0 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SCHEMA_VERSION } from "../config/schema.ts";
|
|
3
|
+
import { ADAPTER_API_VERSION } from "../adapter-api.ts";
|
|
4
|
+
import { STATUS_FORMAT } from "./version.ts";
|
|
5
|
+
|
|
6
|
+
export { STATUS_FORMAT };
|
|
7
|
+
|
|
8
|
+
const name = z.string().min(1);
|
|
9
|
+
|
|
10
|
+
const ACTION_LABEL_CELLS = 14;
|
|
11
|
+
const time = z.number().int().nonnegative();
|
|
12
|
+
|
|
13
|
+
/** A command the owner may run. A label is at most 14 cells, the width the view gives it. */
|
|
14
|
+
export const Action = z.strictObject({ label: name.max(ACTION_LABEL_CELLS), command: name });
|
|
15
|
+
|
|
16
|
+
/** A card's action: it fills the prompt with this answer to the card's item, and only the owner's Enter posts it. */
|
|
17
|
+
export const CardAction = z.strictObject({ label: name.max(ACTION_LABEL_CELLS), answer: name });
|
|
18
|
+
|
|
19
|
+
/** The most characters of a tool's own words a card quotes. */
|
|
20
|
+
export const CARD_EXCERPT = 200;
|
|
21
|
+
|
|
22
|
+
/** The cause, the fix in one sentence, then at most one action. */
|
|
23
|
+
export const Card = z.strictObject({
|
|
24
|
+
kind: z.enum(["waiting", "limited", "fault"]),
|
|
25
|
+
/** One card per key: a failure code plus the item it hit. */
|
|
26
|
+
key: name,
|
|
27
|
+
item: name.optional(),
|
|
28
|
+
code: name,
|
|
29
|
+
cause: name,
|
|
30
|
+
fix: name.refine((fix) => !fix.includes("\n"), "the fix is one sentence on one line"),
|
|
31
|
+
action: CardAction.optional(),
|
|
32
|
+
since: time,
|
|
33
|
+
}).refine(({ item, action }) => action === undefined || item !== undefined, "a card's action answers its item, so a card with an action names one");
|
|
34
|
+
|
|
35
|
+
export type Card = z.infer<typeof Card>;
|
|
36
|
+
|
|
37
|
+
const Row = z.strictObject({ item: name, title: name, level: name.optional(), state: name, since: time });
|
|
38
|
+
|
|
39
|
+
/** An unclear item carries the mark apart from its risk level. */
|
|
40
|
+
export const InFlight = Row.extend({ unclear: z.boolean() });
|
|
41
|
+
|
|
42
|
+
/** A question to the owner: its text and the option words an answer may pick, none for a free answer. */
|
|
43
|
+
export const Question = z.strictObject({ item: name, text: name, options: z.array(name), since: time });
|
|
44
|
+
|
|
45
|
+
export type Question = z.infer<typeof Question>;
|
|
46
|
+
|
|
47
|
+
export const Merged = z.strictObject({ item: name, title: name, level: name.optional(), mergedAt: time });
|
|
48
|
+
|
|
49
|
+
export const Choice = z.strictObject({ item: name, text: name, at: time });
|
|
50
|
+
|
|
51
|
+
/** A path rule the owner's answer added, with the command that takes it back. */
|
|
52
|
+
export type Choice = z.infer<typeof Choice>;
|
|
53
|
+
|
|
54
|
+
export const LearnedRule = z.strictObject({ glob: name, level: name, item: name, at: time, undo: Action });
|
|
55
|
+
|
|
56
|
+
const PerMerge = z.strictObject({
|
|
57
|
+
merges: z.int().nonnegative(),
|
|
58
|
+
/** Items that never merged in the window; their costs are in the numbers. */
|
|
59
|
+
abandoned: z.int().nonnegative(),
|
|
60
|
+
notes: z.number().nonnegative(),
|
|
61
|
+
questions: z.number().nonnegative(),
|
|
62
|
+
tokens: z.number().nonnegative(),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** Per merged change over the last `window` merged changes, and over each path's own last `window`. */
|
|
66
|
+
export const Measure = PerMerge.extend({
|
|
67
|
+
window: z.int().positive(),
|
|
68
|
+
byPath: z.array(PerMerge.extend({ glob: name })),
|
|
69
|
+
}).strict();
|
|
70
|
+
|
|
71
|
+
export type Measure = z.infer<typeof Measure>;
|
|
72
|
+
|
|
73
|
+
/** One file per repo; the view shows the sections in this order. */
|
|
74
|
+
export const Status = z.strictObject({
|
|
75
|
+
format: z.literal(STATUS_FORMAT),
|
|
76
|
+
/** Freshness is a pure function of these timestamps and the clock. */
|
|
77
|
+
writtenAt: time,
|
|
78
|
+
/** When each runner's worker last wrote; absent when it never has. */
|
|
79
|
+
workers: z.strictObject({ mac: time.optional(), ci: time.optional() }),
|
|
80
|
+
engine: z.strictObject({
|
|
81
|
+
version: name,
|
|
82
|
+
adapterApi: z.int().nonnegative(),
|
|
83
|
+
configSchema: z.int().positive(),
|
|
84
|
+
/** The newest published version, when the worker could read it. */
|
|
85
|
+
latest: name.optional(),
|
|
86
|
+
}),
|
|
87
|
+
questions: z.array(Question),
|
|
88
|
+
cards: z.array(Card),
|
|
89
|
+
inFlight: z.array(InFlight),
|
|
90
|
+
merged: z.array(Merged),
|
|
91
|
+
choices: z.array(Choice),
|
|
92
|
+
rules: z.array(LearnedRule),
|
|
93
|
+
/** Pairs of review notes only a model found alike, waiting for its precision to reach the owner's bar. */
|
|
94
|
+
possibleRepeats: z.array(z.strictObject({ a: name, b: name })),
|
|
95
|
+
/** memory.md rules no run applied in the last runs; the owner decides whether to keep them. */
|
|
96
|
+
unusedMemory: z.array(z.string()),
|
|
97
|
+
measure: Measure.nullable(),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export type Status = z.infer<typeof Status>;
|
|
101
|
+
|
|
102
|
+
/** A status with nothing in it, stamped with the engine that wrote it. */
|
|
103
|
+
export const emptyStatus = (engineVersion: string, writtenAt: number): Status => ({
|
|
104
|
+
format: STATUS_FORMAT,
|
|
105
|
+
writtenAt,
|
|
106
|
+
workers: {},
|
|
107
|
+
engine: { version: engineVersion, adapterApi: ADAPTER_API_VERSION, configSchema: SCHEMA_VERSION },
|
|
108
|
+
questions: [],
|
|
109
|
+
cards: [],
|
|
110
|
+
inFlight: [],
|
|
111
|
+
merged: [],
|
|
112
|
+
choices: [],
|
|
113
|
+
rules: [],
|
|
114
|
+
possibleRepeats: [],
|
|
115
|
+
unusedMemory: [],
|
|
116
|
+
measure: null,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/** What the worker writes each tick. The service unit shows a card when it is three ticks old. */
|
|
120
|
+
export const Heartbeat = z.strictObject({
|
|
121
|
+
time,
|
|
122
|
+
engineVersion: name,
|
|
123
|
+
configHash: name,
|
|
124
|
+
/** Items with a run going. */
|
|
125
|
+
inFlight: z.array(name),
|
|
126
|
+
/** The time between ticks, so a reader can tell three ticks old from fresh. */
|
|
127
|
+
intervalMs: z.int().positive(),
|
|
128
|
+
/** Set once the worker has seen an update and will exit when its runs end. */
|
|
129
|
+
restarting: name.optional(),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export type Heartbeat = z.infer<typeof Heartbeat>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Choice, Question } from "./format.ts";
|
|
2
|
+
import type { QueuedQuestion, SettledAnswer } from "../state/saved.ts";
|
|
3
|
+
|
|
4
|
+
const answersAfter = (answers: readonly SettledAnswer[], item: string, asked: number): boolean =>
|
|
5
|
+
answers.some((answer) => answer.item === item && answer.disposition === "applied" && answer.at >= asked);
|
|
6
|
+
|
|
7
|
+
/** A question stays open from the moment it is asked until an answer to its item is applied. */
|
|
8
|
+
export const openQuestions = (queued: readonly QueuedQuestion[], answers: readonly SettledAnswer[]): Question[] =>
|
|
9
|
+
queued
|
|
10
|
+
.flatMap(({ item, text, options = [], askedAt }) => (askedAt !== undefined && !answersAfter(answers, item, askedAt) ? [{ item, text, options, since: askedAt }] : []))
|
|
11
|
+
.sort((a, b) => a.since - b.since);
|
|
12
|
+
|
|
13
|
+
/** The newest `shown` choices, newest first. */
|
|
14
|
+
export const newestChoices = (choices: readonly Choice[], shown: number): Choice[] => [...choices].sort((a, b) => b.at - a.at).slice(0, shown);
|
package/src/time.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Pull, PullRequests } from "../adapters/pull-requests.ts";
|
|
2
|
+
import { alignmentComment, gatesAlignment } from "../decide/alignment.ts";
|
|
3
|
+
import type { LandContext } from "./land.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Comments on the pull request what the alignment call made of the change, once per head, while the call's rate is
|
|
7
|
+
* below the bar. Above the bar the call raises levels and needs no report.
|
|
8
|
+
*/
|
|
9
|
+
export const reportAlignment = async (ctx: LandContext, pulls: PullRequests, pull: Pull, head: string): Promise<void> => {
|
|
10
|
+
const alignment = ctx.state.landings.get(ctx.id)?.alignment;
|
|
11
|
+
|
|
12
|
+
if (!alignment || gatesAlignment(ctx.config.hum)) return;
|
|
13
|
+
|
|
14
|
+
await ctx.state.ops.once(
|
|
15
|
+
{ itemId: ctx.id, run: "merge", attempt: 0, op: `alignment:${head}` },
|
|
16
|
+
{ holds: async () => false, run: () => pulls.comment(pull, alignmentComment(alignment, ctx.config.hum)) },
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ADAPTER_API_VERSION, type Item, type ThreadEntry, type WorkSource } from "../adapter-api.ts";
|
|
2
|
+
import type { ModelCall } from "../adapters/model-call.ts";
|
|
3
|
+
import { optionsIn } from "../adapters/marked.ts";
|
|
4
|
+
import { onceCalls } from "../adapters/once.ts";
|
|
5
|
+
import { dispose, type Disposition, matchOption, NONE_OF_THESE, replyQuestion, replyStem, replyText, type Resolution, type Stage } from "../decide/answer.ts";
|
|
6
|
+
import { visibleText } from "../adapters/marked.ts";
|
|
7
|
+
import type { State } from "../state/open.ts";
|
|
8
|
+
import type { SettledAnswer } from "../state/saved.ts";
|
|
9
|
+
|
|
10
|
+
export type AnswerContext = {
|
|
11
|
+
readonly state: State;
|
|
12
|
+
readonly workSource: WorkSource;
|
|
13
|
+
readonly judge: ModelCall;
|
|
14
|
+
readonly now: () => number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** What the reader knows about the item that the thread does not say. */
|
|
18
|
+
export type AnswerScope = {
|
|
19
|
+
readonly stage: Stage;
|
|
20
|
+
/** The options a card offers when no question does, such as the parked item's actions. */
|
|
21
|
+
readonly options?: readonly string[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const isFromHum = (entry: ThreadEntry): boolean => entry.author !== "person";
|
|
25
|
+
|
|
26
|
+
const isQuestion = (entry: ThreadEntry): boolean => entry.kind === "question" && isFromHum(entry);
|
|
27
|
+
|
|
28
|
+
/** A marked answer, or a person's reply typed without a marker. */
|
|
29
|
+
const isReply = (entry: ThreadEntry): boolean => entry.kind === "answer" || (entry.kind === "comment" && !isFromHum(entry));
|
|
30
|
+
|
|
31
|
+
type Reply = { readonly entry: ThreadEntry; readonly ordinal: number; readonly index: number };
|
|
32
|
+
|
|
33
|
+
/** Every reply on the thread, numbered. Replies from people count only after a question; before one they are remarks. */
|
|
34
|
+
const repliesOn = (thread: readonly ThreadEntry[], afterQuestion: number): Reply[] => {
|
|
35
|
+
let ordinal = 0;
|
|
36
|
+
|
|
37
|
+
return thread.flatMap((entry, index) => {
|
|
38
|
+
if (!isReply(entry)) return [];
|
|
39
|
+
|
|
40
|
+
ordinal++;
|
|
41
|
+
|
|
42
|
+
return index > afterQuestion && (afterQuestion >= 0 || entry.kind === "answer") ? [{ entry, ordinal, index }] : [];
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const resolveReply = async (ctx: AnswerContext, itemId: string, question: string, options: readonly string[], { entry }: Reply): Promise<Resolution> => {
|
|
47
|
+
const matched = matchOption(entry, options);
|
|
48
|
+
|
|
49
|
+
if (matched) return matched;
|
|
50
|
+
|
|
51
|
+
const judged = await ctx.judge({ ...replyQuestion(question, options, entry.text), item: itemId });
|
|
52
|
+
|
|
53
|
+
if (judged.kind === "abstained") return { source: "abstained", why: judged.why };
|
|
54
|
+
|
|
55
|
+
return judged.value.option === NONE_OF_THESE ? { source: "none-of-these" } : { source: "model", option: judged.value.option };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const keyOf = (item: string, ordinal: number): string => `${item}#${ordinal}`;
|
|
59
|
+
|
|
60
|
+
const optionOf = (resolution: Resolution): { option?: string } => ("option" in resolution && resolution.option !== undefined ? { option: resolution.option } : {});
|
|
61
|
+
|
|
62
|
+
const recordOf = (item: string, { entry, ordinal }: Reply, resolution: Resolution, outcome: Disposition, at: number): SettledAnswer => ({
|
|
63
|
+
item,
|
|
64
|
+
ordinal,
|
|
65
|
+
text: entry.text,
|
|
66
|
+
...optionOf(resolution),
|
|
67
|
+
source: resolution.source,
|
|
68
|
+
disposition: outcome.disposition,
|
|
69
|
+
why: outcome.why,
|
|
70
|
+
at,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const resolutionOf = ({ source, option, why }: SettledAnswer): Resolution => {
|
|
74
|
+
if (source === "abstained") return { source, why };
|
|
75
|
+
|
|
76
|
+
if (source === "marker") return { source, option };
|
|
77
|
+
|
|
78
|
+
if (source === "free" || source === "none-of-these") return { source };
|
|
79
|
+
|
|
80
|
+
return { source, option: option ?? "" };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const isFinal = ({ disposition }: SettledAnswer): boolean => disposition !== "held";
|
|
84
|
+
|
|
85
|
+
const hasReplyOn = (thread: readonly ThreadEntry[], stem: string): boolean => thread.some((entry) => isFromHum(entry) && entry.kind === "comment" && entry.text.startsWith(stem));
|
|
86
|
+
|
|
87
|
+
/** The answer as the engine reads it from here on: the option it picked, or no longer an answer at all. */
|
|
88
|
+
const normalized = (entry: ThreadEntry, { disposition, option }: SettledAnswer): ThreadEntry =>
|
|
89
|
+
disposition === "applied" ? { ...entry, kind: "answer", option } : { ...entry, kind: "comment", option: undefined };
|
|
90
|
+
|
|
91
|
+
const SUPERSEDED: Disposition = { disposition: "dropped", why: "A newer question replaced the one this answered." };
|
|
92
|
+
|
|
93
|
+
type Settling = { readonly ctx: AnswerContext; readonly item: Item; readonly question: string; readonly options: readonly string[]; readonly stage: Stage };
|
|
94
|
+
|
|
95
|
+
/** One reply's record: kept once final, else decided again from where the item stands now. */
|
|
96
|
+
const settleOne = async ({ ctx, item, question, options, stage }: Settling, reply: Reply, answeredBefore: boolean): Promise<{ record: SettledAnswer; resolution: Resolution }> => {
|
|
97
|
+
const saved = ctx.state.answers.get(keyOf(item.id, reply.ordinal));
|
|
98
|
+
const resolution = saved ? resolutionOf(saved) : await resolveReply(ctx, item.id, question, options, reply);
|
|
99
|
+
|
|
100
|
+
if (saved && isFinal(saved)) return { record: saved, resolution };
|
|
101
|
+
|
|
102
|
+
const outcome = dispose({ resolution, answeredBefore, stage });
|
|
103
|
+
const record = saved?.disposition === outcome.disposition ? saved : recordOf(item.id, reply, resolution, outcome, ctx.now());
|
|
104
|
+
|
|
105
|
+
if (record !== saved) ctx.state.answers.put(keyOf(item.id, reply.ordinal), record);
|
|
106
|
+
|
|
107
|
+
return { record, resolution };
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** Answers held for a question that a newer one replaced can no longer take effect. */
|
|
111
|
+
const dropSuperseded = async ({ ctx, item }: Settling, current: ReadonlySet<number>): Promise<void> => {
|
|
112
|
+
for (const held of ctx.state.answers.list()) {
|
|
113
|
+
if (held.item !== item.id || held.disposition !== "held" || current.has(held.ordinal)) continue;
|
|
114
|
+
|
|
115
|
+
ctx.state.answers.put(keyOf(item.id, held.ordinal), { ...held, disposition: SUPERSEDED.disposition, why: SUPERSEDED.why });
|
|
116
|
+
await onceCalls({ apiVersion: ADAPTER_API_VERSION, workSource: ctx.workSource }, ctx.state.ops, { run: "answer-reply", attempt: 0 }).workSource?.comment(item.id, replyText(held.ordinal, SUPERSEDED, resolutionOf(held), [], held.text));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* D4: every answer on the item's thread is saved with what became of it, and gets one reply: applied, held, or
|
|
122
|
+
* dropped and why. An answer's option comes from its marker, else its first word, else the cheap model call.
|
|
123
|
+
* Returns the item with its thread as the engine reads it: an applied reply is an answer carrying its option, any
|
|
124
|
+
* other is a comment.
|
|
125
|
+
*/
|
|
126
|
+
export const settleAnswers = async (ctx: AnswerContext, item: Item, { stage, options: cardOptions }: AnswerScope): Promise<Item> => {
|
|
127
|
+
const asked = item.thread.findLastIndex(isQuestion);
|
|
128
|
+
const questionText = asked < 0 ? "" : (item.thread[asked]?.text ?? "");
|
|
129
|
+
const settling: Settling = { ctx, item, question: visibleText(questionText), options: cardOptions ?? optionsIn(questionText), stage };
|
|
130
|
+
const calls = onceCalls({ apiVersion: ADAPTER_API_VERSION, workSource: ctx.workSource }, ctx.state.ops, { run: "answer-reply", attempt: 0 });
|
|
131
|
+
const settled = new Map<number, SettledAnswer>();
|
|
132
|
+
const replies = repliesOn(item.thread, asked);
|
|
133
|
+
|
|
134
|
+
for (const reply of replies) {
|
|
135
|
+
const answeredBefore = [...settled.values()].some(({ disposition }) => disposition === "applied");
|
|
136
|
+
const { record, resolution } = await settleOne(settling, reply, answeredBefore);
|
|
137
|
+
const outcome = { disposition: record.disposition, why: record.why };
|
|
138
|
+
|
|
139
|
+
settled.set(reply.index, record);
|
|
140
|
+
|
|
141
|
+
if (!hasReplyOn(item.thread, replyStem(reply.ordinal, outcome))) await calls.workSource?.comment(item.id, replyText(reply.ordinal, outcome, resolution, settling.options, reply.entry.text));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
await dropSuperseded(settling, new Set(replies.map(({ ordinal }) => ordinal)));
|
|
145
|
+
|
|
146
|
+
const asEngineReads = (entry: ThreadEntry, index: number): ThreadEntry => {
|
|
147
|
+
const record = settled.get(index);
|
|
148
|
+
|
|
149
|
+
return record ? normalized(entry, record) : entry;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return { ...item, thread: item.thread.map(asEngineReads) };
|
|
153
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { WorkSource } from "../adapter-api.ts";
|
|
2
|
+
import { type Git } from "../adapters/git.ts";
|
|
3
|
+
import type { Config } from "../config/load.ts";
|
|
4
|
+
import { inWorktreeAt } from "../loop/proof.ts";
|
|
5
|
+
import type { State } from "../state/open.ts";
|
|
6
|
+
import { checksTimeoutMs, runChecks } from "./checks.ts";
|
|
7
|
+
import { placementOf } from "./land.ts";
|
|
8
|
+
|
|
9
|
+
export type BaseCheckOptions = {
|
|
10
|
+
readonly state: State;
|
|
11
|
+
readonly config: Config;
|
|
12
|
+
readonly workSource: Pick<WorkSource, "fileFollowUp">;
|
|
13
|
+
/** The owner's checkout; the merged commit is fetched into it. */
|
|
14
|
+
readonly git: Git;
|
|
15
|
+
readonly remote: string;
|
|
16
|
+
readonly base: string;
|
|
17
|
+
readonly checks: readonly string[];
|
|
18
|
+
readonly now: () => number;
|
|
19
|
+
readonly item: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const FAILURE_EXCERPT = 1500;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* After an item merged, the repo's checks run on the base at the merged commit. A failure there is a break: it is
|
|
26
|
+
* saved, a follow-up fix item is filed, and the owner's level for the change says whether its paths are blocked until
|
|
27
|
+
* that item merges. The fix limit counts the break beside the breaks git shows.
|
|
28
|
+
*/
|
|
29
|
+
export const checkBaseAfterMerge = async ({ state, config, workSource, git, remote, base, checks, now, item }: BaseCheckOptions): Promise<void> => {
|
|
30
|
+
const merge = state.merges.get(item);
|
|
31
|
+
|
|
32
|
+
if (!config.hum.breakCheck || checks.length === 0 || !merge) return;
|
|
33
|
+
|
|
34
|
+
await git.raw(["fetch", "-q", remote, base]);
|
|
35
|
+
|
|
36
|
+
const failure = await inWorktreeAt(git, merge.sha, (folder) => runChecks(checks, folder, { timeoutMs: checksTimeoutMs(config.hum) }));
|
|
37
|
+
|
|
38
|
+
if (failure === undefined) return;
|
|
39
|
+
|
|
40
|
+
const { placement } = await placementOf({ config, state, git, base, now }, { paths: merge.paths, size: 0, loosened: false, pinChanged: false });
|
|
41
|
+
const followUp = await workSource.fileFollowUp(item, { title: `Fix the checks that fail on ${base} after ${item} merged`, body: `Kind: fix\n\nThe repo's checks fail on ${base} at ${merge.sha}, the commit that merged ${item}.\n\n\`\`\`\n${failure.slice(0, FAILURE_EXCERPT)}\n\`\`\`` });
|
|
42
|
+
|
|
43
|
+
state.breaks.put(item, { item, sha: merge.sha, at: now(), paths: merge.paths, level: placement.level.name, failure: failure.slice(0, FAILURE_EXCERPT), onBreak: placement.level.onBreak, followUp: followUp.id });
|
|
44
|
+
};
|
|
45
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { HumConfig } from "../config/schema.ts";
|
|
2
|
+
import { CommandTimedOut, exec } from "../exec.ts";
|
|
3
|
+
import { SECOND_MS } from "../time.ts";
|
|
4
|
+
|
|
5
|
+
export type ShellOptions = {
|
|
6
|
+
/** Added to the worker's own environment. */
|
|
7
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
8
|
+
/** A command still running after this many ms is stopped, with every process it started, and counts as failed. */
|
|
9
|
+
readonly timeoutMs: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* One check's failure as its command, exit code and output, or as the limit it ran past; undefined when it passes.
|
|
14
|
+
* It runs with no stdin and the worker's own PATH, as in the owner's shell; the clone's `node_modules/.bin` is not added.
|
|
15
|
+
*/
|
|
16
|
+
const failureOf = async (command: string, cwd: string, { env, timeoutMs }: ShellOptions): Promise<string | undefined> => {
|
|
17
|
+
try {
|
|
18
|
+
const { exitCode, stdout, stderr } = await exec("sh", ["-c", command], { nodePath: false, timeoutMs, nodeOptions: { cwd, env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"] } });
|
|
19
|
+
|
|
20
|
+
return exitCode === 0 ? undefined : `${command} exited ${exitCode}:\n${stdout}${stderr}`;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof CommandTimedOut) return error.message;
|
|
23
|
+
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** How long the repo's checks may run: the owner's `proofTimeoutSeconds` in milliseconds. */
|
|
29
|
+
export const checksTimeoutMs = ({ proofTimeoutSeconds }: Pick<HumConfig, "proofTimeoutSeconds">): number => proofTimeoutSeconds * SECOND_MS;
|
|
30
|
+
|
|
31
|
+
/** The first failing check; undefined when all pass. */
|
|
32
|
+
export const runChecks = async (commands: readonly string[], cwd: string, options: ShellOptions): Promise<string | undefined> => {
|
|
33
|
+
for (const command of commands) {
|
|
34
|
+
const failure = await failureOf(command, cwd, options);
|
|
35
|
+
|
|
36
|
+
if (failure !== undefined) return failure;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return undefined;
|
|
40
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Item, Questions, WorkSource } from "../adapter-api.ts";
|
|
2
|
+
import type { ModelCall } from "../adapters/model-call.ts";
|
|
3
|
+
import type { Config } from "../config/load.ts";
|
|
4
|
+
import { declaredKind, kindQuestion, UNSURE } from "../decide/kind.ts";
|
|
5
|
+
import { PLAIN_QUESTIONS } from "../decide/question.ts";
|
|
6
|
+
import type { State } from "../state/open.ts";
|
|
7
|
+
import type { ItemKind } from "../state/saved.ts";
|
|
8
|
+
import { queueQuestion, releaseQuestions } from "./questions.ts";
|
|
9
|
+
|
|
10
|
+
export type KindContext = {
|
|
11
|
+
readonly state: State;
|
|
12
|
+
readonly config: Config;
|
|
13
|
+
readonly judge: ModelCall;
|
|
14
|
+
readonly workSource: WorkSource;
|
|
15
|
+
readonly questions: Questions;
|
|
16
|
+
readonly now: () => number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Why the model call gave no kind it may use. */
|
|
20
|
+
const noKind = async (o: KindContext, item: Item, kinds: readonly string[]): Promise<{ kind: string } | { why: string }> => {
|
|
21
|
+
const judged = await o.judge({ ...kindQuestion(item, { kinds, kindMeanings: o.config.hum.kindMeanings }), item: item.id });
|
|
22
|
+
|
|
23
|
+
if (judged.kind === "abstained") return { why: judged.why };
|
|
24
|
+
|
|
25
|
+
return judged.value.kind === UNSURE ? { why: "the model call could not tell" } : { kind: judged.value.kind };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An item's kind, decided once and saved: the name its source gives it, else the model call's pick from the kinds,
|
|
30
|
+
* else the fallback kind. A fallback is an abstention: the item is unclear, and one question asks the owner for its kind.
|
|
31
|
+
* `except` leaves one kind out, for an item whose change showed it is not that kind.
|
|
32
|
+
*/
|
|
33
|
+
export const decideKind = async (o: KindContext, item: Item, except?: string): Promise<ItemKind> => {
|
|
34
|
+
const kinds = o.config.hum.kinds.filter((kind) => kind !== except);
|
|
35
|
+
const declared = declaredKind(item, kinds, o.config.hum.kindLabels);
|
|
36
|
+
const picked = declared === undefined ? await noKind(o, item, kinds) : undefined;
|
|
37
|
+
|
|
38
|
+
const decided: ItemKind =
|
|
39
|
+
declared !== undefined
|
|
40
|
+
? { item: item.id, kind: declared, from: "source" }
|
|
41
|
+
: picked && "kind" in picked
|
|
42
|
+
? { item: item.id, kind: picked.kind, from: "model" }
|
|
43
|
+
: { item: item.id, kind: o.config.hum.fallbackKind, from: "fallback", why: picked?.why ?? "no kind named" };
|
|
44
|
+
|
|
45
|
+
o.state.itemKinds.put(item.id, decided);
|
|
46
|
+
|
|
47
|
+
if (decided.from === "fallback") {
|
|
48
|
+
queueQuestion(o, item, { text: PLAIN_QUESTIONS.kind, options: kinds, detail: `It runs as ${decided.kind} for now.` }, "kind");
|
|
49
|
+
await releaseQuestions(o);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return decided;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The kind the owner named in answer to the kind question, for an item still on its fallback kind. */
|
|
56
|
+
export const kindAnswered = (known: ItemKind, item: Item, kinds: readonly string[]): ItemKind | undefined => {
|
|
57
|
+
const answer = known.from === "fallback" ? item.thread.findLast((entry) => entry.kind === "answer" && entry.option !== undefined && kinds.includes(entry.option)) : undefined;
|
|
58
|
+
|
|
59
|
+
return answer?.option === undefined ? undefined : { item: item.id, kind: answer.option, from: "source" };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Drops what an item's run on its earlier kind left: its snapshot, its landing, its plan and its verdict. Its branch stays. */
|
|
63
|
+
export const forgetProgress = (state: State, id: string): void => {
|
|
64
|
+
state.items.remove(id);
|
|
65
|
+
state.landings.remove(id);
|
|
66
|
+
state.plans.remove(id);
|
|
67
|
+
state.verdicts.remove(id);
|
|
68
|
+
};
|