@moo.md/hum 0.0.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/schema/hum.schema.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 +72 -32
- package/src/adapters/claude-p.ts +26 -25
- 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 +12 -19
- package/src/adapters/github-client.ts +102 -0
- package/src/adapters/github.ts +50 -136
- 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 +15 -13
- 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 +31 -37
- 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 +9 -9
- 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 +10 -4
- 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 +3 -3
- 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 +20 -14
- 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 +20 -15
- 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 +4 -5
- package/src/worker/checks.ts +25 -11
- package/src/worker/kind.ts +23 -19
- package/src/worker/land.ts +115 -126
- package/src/worker/merged.ts +9 -7
- package/src/worker/open.ts +15 -13
- 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 +150 -123
- package/src/worker/thread.ts +25 -0
- package/src/worker/worker.ts +125 -73
- package/surface.json +633 -2198
- package/src/slots/scan.ts +0 -26
package/src/worker/worker.ts
CHANGED
|
@@ -5,9 +5,10 @@ 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 ItemRef, type Questions, type WorkSource } from "../adapter-api.ts";
|
|
8
|
+
import { ADAPTER_API_VERSION, type Answers, type Holder, 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
|
+
import { invokedSources } from "../config/machine.ts";
|
|
11
12
|
import { type Kind, SCHEMA_VERSION } from "../config/schema.ts";
|
|
12
13
|
import { checkTokenAge } from "../service/token.ts";
|
|
13
14
|
import { listFiles } from "../state/fs.ts";
|
|
@@ -21,13 +22,13 @@ import { readHistory } from "../adapters/history.ts";
|
|
|
21
22
|
import { gitIn, PATCH } from "../adapters/git.ts";
|
|
22
23
|
import { join } from "node:path";
|
|
23
24
|
import { configuredModelCall, modelCallOver } from "../adapters/model-call.ts";
|
|
24
|
-
import {
|
|
25
|
+
import { type MemoryEntry, readMemory, type RefusedLine, unusedEntries, useOf } from "../loop/memory.ts";
|
|
25
26
|
import { runLoopPass, type LoopPass } from "../loop/pass.ts";
|
|
26
|
-
import { modelProposer,
|
|
27
|
+
import { modelProposer, doesTrustRepeats } from "../loop/pair.ts";
|
|
27
28
|
import { measureOf } from "../measure/measure.ts";
|
|
28
29
|
import { measureInputsOf } from "../measure/inputs.ts";
|
|
29
|
-
import { readStatus, writeHeartbeat, writeStatus } from "../status/file.ts";
|
|
30
|
-
import {
|
|
30
|
+
import { emptyStatus, readStatus, writeHeartbeat, writeStatus } from "../status/file.ts";
|
|
31
|
+
import type { Status } from "../status/format.ts";
|
|
31
32
|
import { newestChoices, openQuestions } from "../status/sections.ts";
|
|
32
33
|
import { commandTimeoutMs } from "../exec.ts";
|
|
33
34
|
import { SECOND_MS } from "../time.ts";
|
|
@@ -39,7 +40,7 @@ import type { SlotPool } from "../slots/pool.ts";
|
|
|
39
40
|
import { type AnswerScope, settleAnswers } from "./answers.ts";
|
|
40
41
|
import { recentlyAsked, releaseQuestions } from "./questions.ts";
|
|
41
42
|
import { OWNER_APPROVAL } from "../decide/merge.ts";
|
|
42
|
-
import { answerTo, type Checkout, claimTtlMs, DEFAULT_BASE,
|
|
43
|
+
import { answerTo, type Checkout, ownerWaitStage, claimTtlMs, DEFAULT_BASE, hasEndedStuck, park, rememberKinds, RUN_AGAIN, runThinPath, type ThinResult, isWaitingOnOwner } from "./thin-path.ts";
|
|
43
44
|
|
|
44
45
|
export type { TickResult } from "./lifecycle.ts";
|
|
45
46
|
|
|
@@ -62,15 +63,19 @@ export type WorkerOptions = {
|
|
|
62
63
|
readonly remote: string;
|
|
63
64
|
readonly base?: string;
|
|
64
65
|
readonly checks: readonly string[];
|
|
65
|
-
readonly holder:
|
|
66
|
+
readonly holder: Holder;
|
|
66
67
|
readonly workDir?: string;
|
|
67
68
|
/** Gives each pass its working copy; by default a `git clone`. */
|
|
68
69
|
readonly checkout?: Checkout;
|
|
69
|
-
/** The run slots behind `checkout`, if any: each tick asks them to keep slots ready. */
|
|
70
|
-
readonly slots?: Pick<SlotPool, "keepReady">;
|
|
70
|
+
/** The run slots behind `checkout`, if any: each tick asks them to keep slots ready, and the worker is idle once their upkeep ends. */
|
|
71
|
+
readonly slots?: Pick<SlotPool, "keepReady" | "idle">;
|
|
71
72
|
readonly dir?: string;
|
|
72
73
|
readonly where?: "mac" | "ci";
|
|
73
|
-
readonly now
|
|
74
|
+
readonly now: () => number;
|
|
75
|
+
/** The names of the variables the runs have, for the missing-secret check. */
|
|
76
|
+
readonly runnerVariables: ReadonlySet<string>;
|
|
77
|
+
/** A fresh id for each run's session. */
|
|
78
|
+
readonly newSessionId: () => string;
|
|
74
79
|
/** The engine this process runs; the update check compares the one installed in `repo` with it. */
|
|
75
80
|
readonly engineVersion?: string;
|
|
76
81
|
/** The newest published version; a failed or slow read shows no version. */
|
|
@@ -104,6 +109,24 @@ type InFlight = {
|
|
|
104
109
|
|
|
105
110
|
const ERROR_EXCERPT = 300;
|
|
106
111
|
|
|
112
|
+
const UNREAD_CODE = "item-unread";
|
|
113
|
+
|
|
114
|
+
const linesText = (lines: readonly number[]): string => `${lines.length === 1 ? "line" : "lines"} ${lines.join(", ")}`;
|
|
115
|
+
|
|
116
|
+
/** The card for each reason memory.md lines are refused. */
|
|
117
|
+
const MEMORY_CARDS = {
|
|
118
|
+
"no-source": {
|
|
119
|
+
code: "memory-format",
|
|
120
|
+
cause: (lines: readonly number[]) => `Runs skip memory.md ${linesText(lines)}: no "(source: …)".`,
|
|
121
|
+
fix: "Give the line a source, as in - <rule> (source: <where you said it>).",
|
|
122
|
+
},
|
|
123
|
+
"past-cap": {
|
|
124
|
+
code: "memory-full",
|
|
125
|
+
cause: (lines: readonly number[], maxBytes: number) => `Runs skip memory.md ${linesText(lines)}: past memoryMaxBytes (${maxBytes}).`,
|
|
126
|
+
fix: "Remove entries you no longer need, or raise memoryMaxBytes in .hum/hum.json.",
|
|
127
|
+
},
|
|
128
|
+
} as const satisfies Record<RefusedLine["why"], { code: string; cause: (lines: readonly number[], maxBytes: number) => string; fix: string }>;
|
|
129
|
+
|
|
107
130
|
/** Reads `read` at most once per `everyMs`; a failed read, or one slower than `timeoutMs`, shows no value, and that too is kept for the period. */
|
|
108
131
|
const readEvery = <T>(read: (() => Promise<T | undefined>) | undefined, { everyMs, timeoutMs }: { everyMs: number; timeoutMs: number }): (() => Promise<T | undefined>) =>
|
|
109
132
|
read === undefined
|
|
@@ -111,8 +134,7 @@ const readEvery = <T>(read: (() => Promise<T | undefined>) | undefined, { everyM
|
|
|
111
134
|
: pMemoize(() => pTimeout(read(), { milliseconds: timeoutMs, fallback: () => undefined }).catch(() => undefined), { cache: new ExpiryMap(everyMs) });
|
|
112
135
|
|
|
113
136
|
/** Sources that never settle, so a restored item can be stepped by its timers without starting a run. */
|
|
114
|
-
const neverSources = (kind: Kind) =>
|
|
115
|
-
Object.fromEntries(Object.values(kind.machine.states).flatMap((node) => (node.invoke ? [[node.invoke.src, createAsyncLogic({ run: () => new Promise<never>(() => {}) })]] : [])));
|
|
137
|
+
const neverSources = (kind: Kind) => invokedSources(kind, createAsyncLogic({ run: () => new Promise<never>(() => {}) }));
|
|
116
138
|
|
|
117
139
|
/** The declared delays of the state an item was saved in, shortest first. */
|
|
118
140
|
const delaysOf = (kind: Kind, saved: SavedSnapshot): number[] =>
|
|
@@ -148,11 +170,12 @@ export class Worker {
|
|
|
148
170
|
readonly #answered = new Set<string>();
|
|
149
171
|
/** Saved changes that land again under this worker's config before anything else starts. */
|
|
150
172
|
readonly #relanding = new Set<string>();
|
|
173
|
+
/** Items whose thread a tick failed to read; the next tick reads them again whatever the watch says. */
|
|
174
|
+
readonly #unread = new Set<string>();
|
|
151
175
|
readonly #merged: Status["merged"] = [];
|
|
152
176
|
readonly #wakes = new EventTarget();
|
|
153
177
|
readonly #latest: () => Promise<string | undefined>;
|
|
154
178
|
readonly #ciTick: () => Promise<number | undefined>;
|
|
155
|
-
readonly #learn: (id: string) => Promise<Known>;
|
|
156
179
|
readonly #judge: ModelCall;
|
|
157
180
|
#watchToken: string | undefined;
|
|
158
181
|
/** Set while the worker has seen an update; no change lands until a worker on the new config takes it. */
|
|
@@ -164,22 +187,13 @@ export class Worker {
|
|
|
164
187
|
|
|
165
188
|
constructor(options: WorkerOptions) {
|
|
166
189
|
this.#o = options;
|
|
167
|
-
this.#now = options.now
|
|
190
|
+
this.#now = options.now;
|
|
168
191
|
this.#gate = options.gate ?? new PrefixGate({ now: this.#now });
|
|
169
192
|
const timeoutMs = options.config.hum.statusReadTimeoutSeconds * SECOND_MS;
|
|
170
193
|
|
|
171
194
|
this.#latest = readEvery(options.latestVersion, { everyMs: options.config.hum.latestVersionCacheSeconds * SECOND_MS, timeoutMs });
|
|
172
195
|
this.#ciTick = readEvery(options.ciTick, { everyMs: options.config.hum.ciTickCacheSeconds * SECOND_MS, timeoutMs });
|
|
173
|
-
this.#start = signatureOf(options.repo, options.engineVersion ?? ENGINE_VERSION, options.config.hum.itemsDir);
|
|
174
|
-
this.#learn = pMemoize(async (id: string): Promise<Known> => {
|
|
175
|
-
const item = await options.adapters.workSource.read(id);
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
footprint: footprintOf(item),
|
|
179
|
-
|
|
180
|
-
title: item.title,
|
|
181
|
-
};
|
|
182
|
-
});
|
|
196
|
+
this.#start = signatureOf({ repo: options.repo, fallbackVersion: options.engineVersion ?? ENGINE_VERSION, itemsDir: options.config.hum.itemsDir });
|
|
183
197
|
this.#judge = options.judge ?? configuredModelCall(options.runner, options.config.hum, (item, tokens) => tallyOf(options.state, item).spend(tokens));
|
|
184
198
|
rememberKinds(options.state, options.config);
|
|
185
199
|
this.#recheckLandings();
|
|
@@ -203,8 +217,10 @@ export class Worker {
|
|
|
203
217
|
return [...this.#inFlight.keys()];
|
|
204
218
|
}
|
|
205
219
|
|
|
206
|
-
|
|
207
|
-
|
|
220
|
+
/** Resolves when no pass runs and no slot upkeep a pass asked for is left: a returned slot is ready again. */
|
|
221
|
+
async idle(): Promise<void> {
|
|
222
|
+
await this.#pool.onIdle();
|
|
223
|
+
await this.#o.slots?.idle();
|
|
208
224
|
}
|
|
209
225
|
|
|
210
226
|
/** Asks a serving worker for a tick now: a run ended, or an answer arrived. */
|
|
@@ -222,7 +238,7 @@ export class Worker {
|
|
|
222
238
|
#isAsleep(saved: SavedSnapshot): boolean {
|
|
223
239
|
const kind = this.#kindNamed(saved.kind)?.kind;
|
|
224
240
|
|
|
225
|
-
return kind !== undefined &&
|
|
241
|
+
return kind !== undefined && isWaitingOnOwner(kind, saved.state);
|
|
226
242
|
}
|
|
227
243
|
|
|
228
244
|
#dueWaits(t: number): DueWait[] {
|
|
@@ -263,7 +279,7 @@ export class Worker {
|
|
|
263
279
|
if (value !== saved.state) {
|
|
264
280
|
state.items.save(saved.itemId, kind, persistedSnapshot(actor));
|
|
265
281
|
|
|
266
|
-
if (
|
|
282
|
+
if (hasEndedStuck(kind, value))
|
|
267
283
|
park(
|
|
268
284
|
{ state, now: this.#now },
|
|
269
285
|
{
|
|
@@ -303,7 +319,7 @@ export class Worker {
|
|
|
303
319
|
if (!parked) return;
|
|
304
320
|
|
|
305
321
|
state.parked.remove(id);
|
|
306
|
-
state.faults.clear(`item-${parked.why}
|
|
322
|
+
state.faults.clear({ code: `item-${parked.why}`, item: id });
|
|
307
323
|
|
|
308
324
|
const landsAgain = state.landings.get(id) !== undefined && option !== RUN_AGAIN;
|
|
309
325
|
|
|
@@ -328,7 +344,7 @@ export class Worker {
|
|
|
328
344
|
const asleep = sleeping.get(id);
|
|
329
345
|
const kind = asleep && this.#kindNamed(asleep.kind)?.kind;
|
|
330
346
|
|
|
331
|
-
if (asleep && kind) return { stage: kind
|
|
347
|
+
if (asleep && kind) return { stage: ownerWaitStage(kind, asleep.state) };
|
|
332
348
|
|
|
333
349
|
return { stage: ready ? "waiting" : "ended" };
|
|
334
350
|
}
|
|
@@ -352,12 +368,15 @@ export class Worker {
|
|
|
352
368
|
}
|
|
353
369
|
}
|
|
354
370
|
|
|
355
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* Reads the threads that can have changed, settles each new answer, and releases a parked item the owner answered.
|
|
373
|
+
* Each item is read on its own: one that fails raises a card naming it and is read again next tick, and the rest go on.
|
|
374
|
+
*/
|
|
356
375
|
async #readAnswers(sleeping: readonly SavedSnapshot[], changed: boolean): Promise<void> {
|
|
357
376
|
const { state, adapters, config } = this.#o;
|
|
358
377
|
const inbox = this.#inbox();
|
|
359
378
|
|
|
360
|
-
if (!changed && inbox.length === 0) return;
|
|
379
|
+
if (!changed && inbox.length === 0 && this.#unread.size === 0) return;
|
|
361
380
|
|
|
362
381
|
const waiting = new Set(sleeping.map((s) => s.itemId));
|
|
363
382
|
const asleep = new Map(sleeping.map((s) => [s.itemId, s]));
|
|
@@ -365,42 +384,58 @@ export class Worker {
|
|
|
365
384
|
const asked = recentlyAsked({ state, config, now: this.#now });
|
|
366
385
|
|
|
367
386
|
await Promise.all(
|
|
368
|
-
[...new Set([...waiting, ...parked.map((p) => p.item), ...inbox, ...asked])].map(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
387
|
+
[...new Set([...waiting, ...parked.map((p) => p.item), ...inbox, ...asked, ...this.#unread])].map((id) =>
|
|
388
|
+
this.#readThread(id, async () => {
|
|
389
|
+
const raw = await adapters.workSource.read(ItemId.parse(id));
|
|
390
|
+
const item = await settleAnswers({ state, workSource: adapters.workSource, judge: this.#judge, now: this.#now }, raw, this.#stageOf(id, raw.ready, asleep));
|
|
391
|
+
const held = parked.find((p) => p.item === id);
|
|
392
|
+
const lastAnswer = item.thread.findLast((e) => e.kind === "answer");
|
|
393
|
+
const lastAnswerAt = lastAnswer?.at;
|
|
394
|
+
|
|
395
|
+
if (held) {
|
|
396
|
+
if (isAnsweredSince(lastAnswerAt, held.since)) this.#unpark(id, lastAnswer?.option);
|
|
397
|
+
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const hasNewAnswer = waiting.has(id) && answerTo(item) !== undefined && lastAnswerAt !== undefined;
|
|
402
|
+
|
|
403
|
+
if (hasNewAnswer) {
|
|
404
|
+
state.events.add({
|
|
405
|
+
source: "thread",
|
|
406
|
+
sourceId: `answer:${lastAnswerAt}`,
|
|
407
|
+
itemId: id,
|
|
408
|
+
type: "answered",
|
|
409
|
+
payload: {},
|
|
410
|
+
});
|
|
411
|
+
this.#answered.add(id);
|
|
412
|
+
}
|
|
413
|
+
}),
|
|
414
|
+
),
|
|
394
415
|
);
|
|
395
416
|
}
|
|
396
417
|
|
|
418
|
+
/** Runs one item's read; a failure raises the card that names the item, and the item is read again next tick. */
|
|
419
|
+
async #readThread(id: string, read: () => Promise<void>): Promise<void> {
|
|
420
|
+
const { faults } = this.#o.state;
|
|
421
|
+
|
|
422
|
+
try {
|
|
423
|
+
await read();
|
|
424
|
+
this.#unread.delete(id);
|
|
425
|
+
faults.clear({ code: UNREAD_CODE, item: id });
|
|
426
|
+
} catch (error) {
|
|
427
|
+
this.#unread.add(id);
|
|
428
|
+
faults.raise({ code: UNREAD_CODE, item: id, cause: `The thread of ${id} could not be read: ${error instanceof Error ? error.message : String(error)}`.slice(0, ERROR_EXCERPT), fix: "hum reads it again each tick and goes on with the other items." });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
397
432
|
/** Every claim in flight is renewed; a run whose claim is gone stops. */
|
|
398
433
|
async #renew(): Promise<void> {
|
|
399
434
|
const { adapters, holder, config } = this.#o;
|
|
400
435
|
|
|
401
436
|
await Promise.all(
|
|
402
437
|
[...this.#inFlight].map(async ([id, run]) => {
|
|
403
|
-
const claim = await adapters.workSource.renew(id, holder, claimTtlMs(config)).catch(() => undefined);
|
|
438
|
+
const claim = await adapters.workSource.renew(ItemId.parse(id), holder, claimTtlMs(config)).catch(() => undefined);
|
|
404
439
|
|
|
405
440
|
if (claim?.won === false) run.abort.abort();
|
|
406
441
|
}),
|
|
@@ -427,10 +462,12 @@ export class Worker {
|
|
|
427
462
|
workDir: this.#o.workDir,
|
|
428
463
|
checkout: this.#o.checkout,
|
|
429
464
|
dir: this.#o.dir,
|
|
430
|
-
itemId: id,
|
|
465
|
+
itemId: ItemId.parse(id),
|
|
431
466
|
signal: abort.signal,
|
|
432
467
|
gate: this.#gate,
|
|
433
468
|
now: this.#now,
|
|
469
|
+
runnerVariables: this.#o.runnerVariables,
|
|
470
|
+
newSessionId: this.#o.newSessionId,
|
|
434
471
|
pulls: this.#o.pulls,
|
|
435
472
|
mayLand: () => this.#updating === undefined,
|
|
436
473
|
}).then(
|
|
@@ -466,19 +503,24 @@ export class Worker {
|
|
|
466
503
|
}
|
|
467
504
|
|
|
468
505
|
/** The memory.md rules the runs shown the file did not apply in the last `memoryUnusedRuns` of them. */
|
|
469
|
-
#unusedMemory(): string[] {
|
|
470
|
-
const { state, config
|
|
506
|
+
#unusedMemory(entries: readonly MemoryEntry[]): string[] {
|
|
507
|
+
const { state, config } = this.#o;
|
|
508
|
+
const { runsSoFar, lastUsed } = useOf(state.runs.all());
|
|
471
509
|
|
|
472
|
-
|
|
473
|
-
|
|
510
|
+
return unusedEntries({ entries, lastUsed, runsSoFar, limit: config.hum.memoryUnusedRuns }).map(({ rule }) => rule);
|
|
511
|
+
}
|
|
474
512
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
513
|
+
/** One card for each reason memory.md lines are refused, naming the lines as they stand; a reason no line has any more clears its card. */
|
|
514
|
+
#showRefusedMemory(refused: readonly RefusedLine[]): void {
|
|
515
|
+
const { faults } = this.#o.state;
|
|
516
|
+
|
|
517
|
+
for (const [why, { code, cause, fix }] of Object.entries(MEMORY_CARDS)) {
|
|
518
|
+
const lines = refused.flatMap((line) => (line.why === why ? [line.line] : []));
|
|
519
|
+
const now = lines.length === 0 ? undefined : cause(lines, this.#o.config.hum.memoryMaxBytes);
|
|
478
520
|
|
|
479
|
-
|
|
521
|
+
if (faults.list().some((card) => card.code === code && card.cause !== now)) faults.clear({ code });
|
|
480
522
|
|
|
481
|
-
|
|
523
|
+
if (now !== undefined) faults.raise({ code, cause: now, fix });
|
|
482
524
|
}
|
|
483
525
|
}
|
|
484
526
|
|
|
@@ -517,7 +559,7 @@ export class Worker {
|
|
|
517
559
|
history: () => readHistory(git, tip, config.hum),
|
|
518
560
|
hunkOf: async (sha, file) => (await git.run(["show", ...PATCH, "-U3", "--format=", sha, ...(file === undefined ? [] : ["--", file])])).stdout,
|
|
519
561
|
propose: modelProposer(call),
|
|
520
|
-
trusts: (models) =>
|
|
562
|
+
trusts: (models) => doesTrustRepeats(models, config.hum),
|
|
521
563
|
memoryPath: join(repo, ".hum", "memory.md"),
|
|
522
564
|
});
|
|
523
565
|
}
|
|
@@ -554,6 +596,9 @@ export class Worker {
|
|
|
554
596
|
|
|
555
597
|
const read = readStatus(state.statusPath);
|
|
556
598
|
const before = read.ok ? read.status : emptyStatus(signature.engineVersion, t);
|
|
599
|
+
const memory = readMemory(join(this.#o.repo, ".hum", "memory.md"), config.hum.memoryMaxBytes);
|
|
600
|
+
|
|
601
|
+
this.#showRefusedMemory(memory.refused);
|
|
557
602
|
const [latest, ci] = await Promise.all([this.#latest(), this.#ciTick()]);
|
|
558
603
|
const saved = new Map(state.items.saved().map((s) => [s.itemId, s.state]));
|
|
559
604
|
|
|
@@ -579,7 +624,7 @@ export class Worker {
|
|
|
579
624
|
})),
|
|
580
625
|
merged: [...this.#merged.splice(0), ...before.merged].slice(0, this.#o.config.hum.mergedShown),
|
|
581
626
|
possibleRepeats: state.possibleRepeats.list().map(({ a, b }) => ({ a, b })),
|
|
582
|
-
unusedMemory: this.#unusedMemory(),
|
|
627
|
+
unusedMemory: this.#unusedMemory(memory.entries),
|
|
583
628
|
measure: measureOf({ ...measureInputsOf(state), window: config.hum.measureWindow, globs: config.hum.paths.map(({ glob }) => glob) }) ?? null,
|
|
584
629
|
rules: state.learned.list().map(({ glob, level, item, at, commit }) => ({ glob, level, item, at, undo: { label: "Undo", command: `git revert ${commit}` } })),
|
|
585
630
|
});
|
|
@@ -607,6 +652,13 @@ export class Worker {
|
|
|
607
652
|
}
|
|
608
653
|
}
|
|
609
654
|
|
|
655
|
+
/** What the scheduler needs of an item, read fresh each tick so an owner's edit to its `touches:` counts. */
|
|
656
|
+
async #learn(id: string): Promise<Known> {
|
|
657
|
+
const item = await this.#o.adapters.workSource.read(ItemId.parse(id));
|
|
658
|
+
|
|
659
|
+
return { footprint: footprintOf(item), title: item.title };
|
|
660
|
+
}
|
|
661
|
+
|
|
610
662
|
/** Which waiting items start now, by the scheduler's rules, and starts them. */
|
|
611
663
|
async #startPicked(t: number, ready: readonly ItemRef[], sleeping: readonly SavedSnapshot[]): Promise<string[]> {
|
|
612
664
|
const { state, runner, config } = this.#o;
|
|
@@ -663,9 +715,9 @@ export class Worker {
|
|
|
663
715
|
|
|
664
716
|
await Promise.all(this.#dueWaits(t).map((due) => this.#fireDue(due, t)));
|
|
665
717
|
|
|
666
|
-
if (config.hum.ciToken) checkTokenAge(state.faults, config.hum.ciToken.setUp, t, config.hum.tokenWarnDays);
|
|
718
|
+
if (config.hum.ciToken) checkTokenAge(state.faults, { setUp: config.hum.ciToken.setUp, now: t, warnDays: config.hum.tokenWarnDays });
|
|
667
719
|
|
|
668
|
-
const signature = signatureOf(this.#o.repo, this.#o.engineVersion ?? ENGINE_VERSION, this.#o.config.hum.itemsDir);
|
|
720
|
+
const signature = signatureOf({ repo: this.#o.repo, fallbackVersion: this.#o.engineVersion ?? ENGINE_VERSION, itemsDir: this.#o.config.hum.itemsDir });
|
|
669
721
|
const update = this.#updateSeen(signature);
|
|
670
722
|
|
|
671
723
|
this.#updating = update;
|