@moo.md/hum 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/release.json +1 -1
- package/src/cli/setup.ts +25 -29
- package/src/measure/rate.ts +12 -4
- package/src/service/workflows.ts +16 -14
- package/surface.json +2 -2
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moo.md/hum",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@moo.md/hum",
|
|
9
|
-
"version": "0.4.
|
|
9
|
+
"version": "0.4.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@actions/core": "3.0.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moo.md/hum",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The hum engine: work items become Claude Code agent runs, the repo's checks decide what they can, and only what nothing settles becomes a question to the owner.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
package/release.json
CHANGED
package/src/cli/setup.ts
CHANGED
|
@@ -30,22 +30,16 @@ const GhLabels = z.array(z.object({ name: z.string() }));
|
|
|
30
30
|
|
|
31
31
|
const EVAL_SCRIPT = join(import.meta.dir, "..", "..", "scripts", "eval.ts");
|
|
32
32
|
|
|
33
|
+
/** What the scan reads from GitHub. Each fact is read alone, and one whose read fails is unknown while the rest stand. */
|
|
33
34
|
type GithubFacts = {
|
|
34
|
-
readonly items: readonly Pick<Item, "body" | "labels">[];
|
|
35
|
-
readonly labels: readonly string[];
|
|
35
|
+
readonly items: readonly Pick<Item, "body" | "labels">[] | undefined;
|
|
36
|
+
readonly labels: readonly string[] | undefined;
|
|
36
37
|
/** Whether the repo lets a workflow open pull requests; off, a CI run cannot open one at all. */
|
|
37
|
-
readonly workflowsMayOpenPullRequests: boolean;
|
|
38
|
+
readonly workflowsMayOpenPullRequests: boolean | undefined;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
const Visibility = z.object({ visibility: z.string() });
|
|
41
42
|
|
|
42
|
-
/** Whether anyone may read and comment on the repo; undefined without `gh` or a GitHub remote. */
|
|
43
|
-
const isPublicRepo = async (repo: string): Promise<boolean | undefined> => {
|
|
44
|
-
const viewed = await gh(repo, ["repo", "view", "--json", "visibility"]);
|
|
45
|
-
|
|
46
|
-
return isRead(viewed) ? Visibility.parse(JSON.parse(viewed.stdout)).visibility === "PUBLIC" : undefined;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
43
|
const WorkflowPermissions = z.object({ can_approve_pull_request_reviews: z.boolean() });
|
|
50
44
|
|
|
51
45
|
/** Setup reads before any `hum.json` is written, so its commands run on the shipped time limit. */
|
|
@@ -62,25 +56,27 @@ const gh = async (repo: string, args: readonly string[]) => {
|
|
|
62
56
|
}
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
/**
|
|
60
|
+
* What one `gh` read prints, through `parse`; undefined where the read fails: without `gh` or a GitHub remote, or
|
|
61
|
+
* without the rights it needs, as a read that needs admin fails for anyone else.
|
|
62
|
+
*/
|
|
63
|
+
const ghRead = async <T>(repo: string, args: readonly string[], parse: (stdout: string) => T): Promise<T | undefined> => {
|
|
64
|
+
const output = await gh(repo, args);
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const issues = await gh(repo, ["issue", "list", "--state", "open", "--limit", GH_LIST_LIMIT, "--json", "body,labels"]);
|
|
72
|
-
const labels = await gh(repo, ["label", "list", "--limit", GH_LIST_LIMIT, "--json", "name"]);
|
|
73
|
-
|
|
74
|
-
const permissions = await gh(repo, ["api", "repos/{owner}/{repo}/actions/permissions/workflow"]);
|
|
66
|
+
return output?.exitCode === 0 ? parse(output.stdout) : undefined;
|
|
67
|
+
};
|
|
75
68
|
|
|
76
|
-
|
|
69
|
+
/** Whether anyone may read and comment on the repo; undefined where `gh` cannot read it. */
|
|
70
|
+
const isPublicRepo = (repo: string): Promise<boolean | undefined> => ghRead(repo, ["repo", "view", "--json", "visibility"], (stdout) => Visibility.parse(JSON.parse(stdout)).visibility === "PUBLIC");
|
|
77
71
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
72
|
+
/** The repo's open issues, its label names and its workflow permissions, from `gh`. Without the open issues and the labels both read, the scan prints no coverage, as the issues are counted against the labels. */
|
|
73
|
+
const githubFacts = async (repo: string): Promise<GithubFacts> => ({
|
|
74
|
+
items: await ghRead(repo, ["issue", "list", "--state", "open", "--limit", GH_LIST_LIMIT, "--json", "body,labels"], (stdout) =>
|
|
75
|
+
GhIssues.parse(JSON.parse(stdout)).map(({ body, labels }) => ({ body, labels: labels.map(({ name }) => name) })),
|
|
76
|
+
),
|
|
77
|
+
labels: await ghRead(repo, ["label", "list", "--limit", GH_LIST_LIMIT, "--json", "name"], (stdout) => GhLabels.parse(JSON.parse(stdout)).map(({ name }) => name)),
|
|
78
|
+
workflowsMayOpenPullRequests: await ghRead(repo, ["api", "repos/{owner}/{repo}/actions/permissions/workflow"], (stdout) => WorkflowPermissions.parse(JSON.parse(stdout)).can_approve_pull_request_reviews),
|
|
79
|
+
});
|
|
84
80
|
|
|
85
81
|
const printStep = ({ name, status, detail, ms }: Step): string => `${status.padEnd(7)} ${name} (${ms} ms): ${detail}`;
|
|
86
82
|
|
|
@@ -106,12 +102,12 @@ export const addSetupCommands = (root: Command, io: Io, done: (code: number) =>
|
|
|
106
102
|
const scan = await scanRepo(io.cwd, base);
|
|
107
103
|
const facts = await githubFacts(io.cwd);
|
|
108
104
|
const isPublic = await isPublicRepo(io.cwd);
|
|
109
|
-
const proposal = proposeSetup(scan, shipped.hum, { labels: facts
|
|
105
|
+
const proposal = proposeSetup(scan, shipped.hum, { labels: facts.labels, isPublic: isPublic ?? true, openIssues: facts.items?.length });
|
|
110
106
|
const { tracked, folders, ...shown } = scan;
|
|
111
|
-
const coverage = facts && kindCoverage(facts.items, shipped.hum.kinds, proposal.kindLabels);
|
|
107
|
+
const coverage = facts.items && facts.labels && kindCoverage(facts.items, shipped.hum.kinds, proposal.kindLabels);
|
|
112
108
|
const gitIdentity = await readGitIdentity(setupGit(io.cwd));
|
|
113
109
|
|
|
114
|
-
io.stdout(`${JSON.stringify({ scan: { ...shown, trackedFiles: tracked.length, folders: folders.map(({ folder, changes }) => ({ folder, changes })) }, proposal, waits: waitsOf(shipped.kinds), coverage: coverage ?? null, workflowsMayOpenPullRequests: facts
|
|
110
|
+
io.stdout(`${JSON.stringify({ scan: { ...shown, trackedFiles: tracked.length, folders: folders.map(({ folder, changes }) => ({ folder, changes })) }, proposal, waits: waitsOf(shipped.kinds), coverage: coverage ?? null, workflowsMayOpenPullRequests: facts.workflowsMayOpenPullRequests ?? null, isPublicRepo: isPublic ?? null, gitIdentity }, null, "\t")}\n`);
|
|
115
111
|
});
|
|
116
112
|
|
|
117
113
|
setup
|
package/src/measure/rate.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { BOUNDARIES, type Boundary, type HumConfig } from "../config/schema.ts";
|
|
2
2
|
|
|
3
3
|
/** The share of measured cases a model got right; none when nothing was measured, so no rate stands in for a measurement. */
|
|
4
4
|
export const rateOf = (right: number, measured: number): number | undefined => (measured === 0 ? undefined : right / measured);
|
|
5
5
|
|
|
6
6
|
const RATE_DIGITS = 2;
|
|
7
7
|
|
|
8
|
+
type MeasuredModels = HumConfig["measuredModels"];
|
|
9
|
+
|
|
10
|
+
/** Every boundary with no model measured on it: `hum.json` names each boundary, and an empty one trusts no model there. */
|
|
11
|
+
// SAFETY: `Object.fromEntries` loses the keys' type; the entries are every boundary.
|
|
12
|
+
const UNMEASURED = Object.fromEntries(BOUNDARIES.map((boundary) => [boundary, {}])) as MeasuredModels;
|
|
13
|
+
|
|
8
14
|
/**
|
|
9
15
|
* The owner's measured rates with one pooled rate set at `boundary`, under the model as the owner names it and under
|
|
10
|
-
* each model id that answered while it was measured
|
|
11
|
-
* such as `haiku` never is, and the pre-call checks read the
|
|
16
|
+
* each model id that answered while it was measured, and every boundary still unmeasured kept with no rate. Trust
|
|
17
|
+
* compares the ids a call's answer names, which an alias such as `haiku` never is, and the pre-call checks read the
|
|
18
|
+
* name in the owner's settings.
|
|
12
19
|
*/
|
|
13
|
-
export const withRate =
|
|
20
|
+
export const withRate = (measured: Partial<MeasuredModels>, { boundary, model, answered, rate }: { readonly boundary: Boundary; readonly model: string; readonly answered: readonly string[]; readonly rate: number }): MeasuredModels => ({
|
|
21
|
+
...UNMEASURED,
|
|
14
22
|
...measured,
|
|
15
23
|
[boundary]: { ...measured[boundary], ...Object.fromEntries([model, ...answered].map((id) => [id, Number(rate.toFixed(RATE_DIGITS))])) },
|
|
16
24
|
});
|
package/src/service/workflows.ts
CHANGED
|
@@ -84,6 +84,9 @@ echo "${JOB_TOOLS}/bin" >> "$GITHUB_PATH"
|
|
|
84
84
|
/** The YAML writer leaves out a key whose value is undefined, so a job that runs on the runner itself has no `container`. */
|
|
85
85
|
const NO_KEY = undefined;
|
|
86
86
|
|
|
87
|
+
/** An env, or no key where it holds nothing: actionlint refuses an empty `env`. */
|
|
88
|
+
const envOrNone = (env: Readonly<Record<string, string>>) => (Object.keys(env).length > 0 ? env : NO_KEY);
|
|
89
|
+
|
|
87
90
|
const OPTIONAL_SECRET = { required: false } as const;
|
|
88
91
|
|
|
89
92
|
/** The secrets the owner's settings name. A called workflow reads only the secrets it declares, so each is declared, and none is required. */
|
|
@@ -147,8 +150,7 @@ const gitSetup = ({ name, email }: HumConfig["commitIdentity"]) => ({
|
|
|
147
150
|
run: `git config --global user.name "$${ENV.gitName}"
|
|
148
151
|
git config --global user.email "$${ENV.gitEmail}"
|
|
149
152
|
git config --global credential.https://github.com.helper "$${ENV.gitCredentialHelper}"
|
|
150
|
-
|
|
151
|
-
`,
|
|
153
|
+
${SAFE_CHECKOUT.run}`,
|
|
152
154
|
env: {
|
|
153
155
|
[ENV.gitName]: name,
|
|
154
156
|
[ENV.gitEmail]: email,
|
|
@@ -211,12 +213,12 @@ const SAFE_CHECKOUT = { run: 'git config --global --add safe.directory "$GITHUB_
|
|
|
211
213
|
|
|
212
214
|
/**
|
|
213
215
|
* The wake, as three jobs. `gather` and `publish` hold GitHub's token and run hum as published, with none of the
|
|
214
|
-
* repo's code: no install of its packages, no hook and no check; each mints an App's token
|
|
215
|
-
* token's hour. `work` holds no GitHub token: its workflow token reads the repo alone and stays out of the
|
|
216
|
-
* and everything it needs from GitHub reaches it in gather
|
|
217
|
-
* they made goes to publish as the outbox, which publish checks before any write. The Claude
|
|
218
|
-
* value that reads a secret reach the steps that run hum alone. A runner GitHub does not
|
|
219
|
-
* so a process a run left could outlive the work job there: ephemeral runners close that.
|
|
216
|
+
* repo's code: no install of its packages, no hook and no check; each mints an App's token just before hum runs,
|
|
217
|
+
* inside the token's hour. `work` holds no GitHub token: its workflow token reads the repo alone and stays out of the
|
|
218
|
+
* checkout, and everything it needs from GitHub reaches it in the inbox gather uploads. Its runs and the repo's checks
|
|
219
|
+
* run there, and what they made goes to publish as the outbox, which publish checks before any write. The Claude
|
|
220
|
+
* sign-in and every `ciEnv` value that reads a secret reach the steps that run hum alone. A runner GitHub does not
|
|
221
|
+
* host keeps what a job leaves, so a process a run left could outlive the work job there: ephemeral runners close that.
|
|
220
222
|
*/
|
|
221
223
|
const wake = ({ commitIdentity, ciWakeTimeoutMinutes, ciOutboxMaxMegabytes, pullRequestToken, ciRunner, ciContainer, ciEnv, ciClaudeAuth }: WorkflowSettings) => {
|
|
222
224
|
const claude = CLAUDE_SIGN_IN[ciClaudeAuth];
|
|
@@ -226,13 +228,13 @@ const wake = ({ commitIdentity, ciWakeTimeoutMinutes, ciOutboxMaxMegabytes, pull
|
|
|
226
228
|
const humEnv = { ...env.humStep, ...claude.env, [ENV.githubToken]: github.token };
|
|
227
229
|
const checkout = (ref?: string) => ({ uses: ACTIONS.checkout.uses, with: { ...(ref && { ref }), "fetch-depth": 0, "persist-credentials": false } });
|
|
228
230
|
|
|
229
|
-
/** A job that holds GitHub's token: hum from npm, git that pushes as hum, and the token minted
|
|
230
|
-
const holdsToken = ({ before, ref, run, permissions = PERMISSIONS }: { readonly before: readonly object[]; readonly ref?: string; readonly run: object; readonly permissions?: typeof PERMISSIONS }) => ({
|
|
231
|
+
/** A job that holds GitHub's token: hum from npm, git that pushes as hum, and the token minted just before hum runs. It installs no plugin: it makes judgment calls alone, which load none. */
|
|
232
|
+
const holdsToken = ({ before, ref, run, after = [], permissions = PERMISSIONS }: { readonly before: readonly object[]; readonly ref?: string; readonly run: object; readonly after?: readonly object[]; readonly permissions?: typeof PERMISSIONS }) => ({
|
|
231
233
|
...where,
|
|
232
234
|
permissions,
|
|
233
235
|
"timeout-minutes": APP_TOKEN_MINUTES,
|
|
234
236
|
env: { ...env.everyStep, ...github.env, [ENV.event]: "${{ github.event_name }}" },
|
|
235
|
-
steps: [...github.check, checkout(ref), JOB_PATHS_STEP, installTools(` ${PUBLISHED_HUM}`), gitSetup(commitIdentity), ...before, ...github.steps, run],
|
|
237
|
+
steps: [...github.check, checkout(ref), JOB_PATHS_STEP, installTools(` ${PUBLISHED_HUM}`), gitSetup(commitIdentity), ...before, ...github.steps, run, ...after],
|
|
236
238
|
});
|
|
237
239
|
|
|
238
240
|
return {
|
|
@@ -241,7 +243,7 @@ const wake = ({ commitIdentity, ciWakeTimeoutMinutes, ciOutboxMaxMegabytes, pull
|
|
|
241
243
|
permissions: {},
|
|
242
244
|
jobs: {
|
|
243
245
|
gather: {
|
|
244
|
-
...holdsToken({ before: [], run: { id: "gather", run: `hum wake gather --inbox ${handoverFolder(HANDOVER.inbox)}`, env: humEnv } }),
|
|
246
|
+
...holdsToken({ before: [], run: { id: "gather", run: `hum wake gather --inbox ${handoverFolder(HANDOVER.inbox)}`, env: humEnv }, after: [upload(HANDOVER.inbox)] }),
|
|
245
247
|
outputs: { gathered: "${{ steps.gather.outputs.gathered }}" },
|
|
246
248
|
},
|
|
247
249
|
work: {
|
|
@@ -249,7 +251,7 @@ const wake = ({ commitIdentity, ciWakeTimeoutMinutes, ciOutboxMaxMegabytes, pull
|
|
|
249
251
|
...where,
|
|
250
252
|
permissions: { contents: "read" },
|
|
251
253
|
"timeout-minutes": ciWakeTimeoutMinutes,
|
|
252
|
-
env:
|
|
254
|
+
env: envOrNone(env.everyStep),
|
|
253
255
|
steps: [
|
|
254
256
|
checkout(GATHERED_BASE),
|
|
255
257
|
JOB_PATHS_STEP,
|
|
@@ -258,7 +260,7 @@ const wake = ({ commitIdentity, ciWakeTimeoutMinutes, ciOutboxMaxMegabytes, pull
|
|
|
258
260
|
{ run: "./node_modules/.bin/hum plugins" },
|
|
259
261
|
SAFE_CHECKOUT,
|
|
260
262
|
download(HANDOVER.inbox),
|
|
261
|
-
{ run: `./node_modules/.bin/hum wake work --inbox ${handoverFolder(HANDOVER.inbox)} --outbox ${handoverFolder(HANDOVER.outbox)}`, env: { ...env.humStep, ...claude.env } },
|
|
263
|
+
{ run: `./node_modules/.bin/hum wake work --inbox ${handoverFolder(HANDOVER.inbox)} --outbox ${handoverFolder(HANDOVER.outbox)}`, env: envOrNone({ ...env.humStep, ...claude.env }) },
|
|
262
264
|
upload(HANDOVER.outbox),
|
|
263
265
|
],
|
|
264
266
|
},
|
package/surface.json
CHANGED
|
@@ -2196,7 +2196,7 @@
|
|
|
2196
2196
|
"src/state/format.ts": {
|
|
2197
2197
|
"ENGINE_VERSION": {
|
|
2198
2198
|
"type": "string",
|
|
2199
|
-
"value": "0.4.
|
|
2199
|
+
"value": "0.4.1"
|
|
2200
2200
|
},
|
|
2201
2201
|
"Envelope": {
|
|
2202
2202
|
"type": "export type Envelope = z.infer<typeof Envelope>;\n= { format: 1; engineVersion: string; itemId: string; kind: string; machineVersion: string; savedAt: number; snapshot: JSONType; }\nZodObject<{ format: ZodLiteral<1>; engineVersion: ZodString; itemId: ZodString; kind: ZodString; machineVersion: ZodString; savedAt: ZodInt; snapshot: ZodJSONSchema; }, $strip>",
|
|
@@ -2994,7 +2994,7 @@
|
|
|
2994
2994
|
},
|
|
2995
2995
|
"ENGINE_VERSION": {
|
|
2996
2996
|
"type": "string",
|
|
2997
|
-
"value": "0.4.
|
|
2997
|
+
"value": "0.4.1"
|
|
2998
2998
|
},
|
|
2999
2999
|
"engineImporters": {
|
|
3000
3000
|
"type": "(files: readonly string[]) => { file: string; module: string; }[]"
|