@moo.md/hum 0.3.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/defaults/hum.json +5 -0
- package/defaults/roles/build.md +1 -1
- package/defaults/roles/fix.md +1 -1
- package/npm-shrinkwrap.json +3297 -0
- package/package.json +6 -2
- package/release.json +3 -0
- package/schema/hum.schema.json +47 -7
- package/scripts/eval.ts +21 -5
- package/src/adapter-api.ts +3 -1
- package/src/adapters/claude-bg.ts +2 -2
- package/src/adapters/claude-p.ts +44 -18
- package/src/adapters/contract.ts +12 -0
- package/src/adapters/fake.ts +5 -0
- package/src/adapters/git.ts +61 -9
- package/src/adapters/github-client.ts +15 -0
- package/src/adapters/github-commits.ts +84 -0
- package/src/adapters/github.ts +9 -0
- package/src/adapters/guard.ts +1 -0
- package/src/adapters/item-file.ts +1 -1
- package/src/adapters/markdown.ts +10 -1
- package/src/adapters/pull-requests.ts +8 -8
- package/src/adapters/registry.ts +3 -6
- package/src/adapters/roundup.ts +3 -0
- package/src/bytes.ts +1 -0
- package/src/cli/service.ts +176 -29
- package/src/cli/setup.ts +28 -33
- package/src/config/checks.ts +21 -50
- package/src/config/load.ts +2 -3
- package/src/config/machine.ts +29 -0
- package/src/config/refusal.ts +5 -6
- package/src/config/schema.ts +23 -7
- package/src/config/wake-job.ts +6 -2
- package/src/decide/risk.ts +2 -2
- package/src/exec.ts +10 -0
- package/src/index.ts +1 -1
- package/src/loop/records.ts +8 -1
- package/src/measure/rate.ts +22 -0
- package/src/publish/bundle.ts +128 -0
- package/src/publish/handoff.ts +107 -0
- package/src/publish/handover.ts +182 -0
- package/src/publish/intents.ts +61 -0
- package/src/publish/publisher.ts +259 -0
- package/src/publish/wake.ts +78 -0
- package/src/service/ci-state.ts +99 -0
- package/src/service/plugins.ts +137 -0
- package/src/service/wake.ts +3 -1
- package/src/service/workflows.ts +126 -30
- package/src/setup/propose.ts +17 -4
- package/src/setup/prove.ts +3 -3
- package/src/setup/write.ts +2 -2
- package/src/state/items.ts +17 -8
- package/src/state/open.ts +20 -6
- package/src/state/records.ts +7 -0
- package/src/state/runs.ts +5 -0
- package/src/state/saved.ts +17 -2
- package/src/worker/base-check.ts +41 -13
- package/src/worker/checks.ts +3 -2
- package/src/worker/evidence.ts +72 -0
- package/src/worker/kind.ts +4 -7
- package/src/worker/land.ts +173 -81
- package/src/worker/merged.ts +20 -8
- package/src/worker/open.ts +33 -17
- package/src/worker/questions.ts +16 -8
- package/src/worker/signed-push.ts +167 -0
- package/src/worker/thin-path.ts +245 -133
- package/src/worker/worker.ts +50 -9
- package/surface.json +185 -56
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { type GitIdentity, gitIn, push } from "../adapters/git.ts";
|
|
5
|
+
import { HEARTBEAT_FILE, INBOX_DIR, PUBLISH_DIR, SLOTS_DIR, STATUS_FILE, STOPS_DIR } from "../state/open.ts";
|
|
6
|
+
|
|
7
|
+
/** Where a CI wake keeps hum's state for the next one. A ref holds no file, so no branch or checkout changes. Anyone who can read the repo can read it. */
|
|
8
|
+
export const CI_STATE_REF = "refs/hum/state";
|
|
9
|
+
|
|
10
|
+
/** The state files a job keeps to itself: what the view and the service unit poll, what a Mac's hooks and slots leave, and publish's repo. */
|
|
11
|
+
const JOB_ONLY = [STATUS_FILE, HEARTBEAT_FILE, `${INBOX_DIR}/`, `${STOPS_DIR}/`, `${SLOTS_DIR}/`, `${PUBLISH_DIR}/`];
|
|
12
|
+
|
|
13
|
+
const isJobOnly = (path: string): boolean => JOB_ONLY.some((name) => (name.endsWith("/") ? path.startsWith(name) : path === name));
|
|
14
|
+
|
|
15
|
+
const NO_REF = /couldn't find remote ref/i;
|
|
16
|
+
|
|
17
|
+
type CiStateOptions = {
|
|
18
|
+
/** The checkout whose git holds the objects. */
|
|
19
|
+
readonly repo: string;
|
|
20
|
+
readonly remote: string;
|
|
21
|
+
/** The state folder. */
|
|
22
|
+
readonly dir: string;
|
|
23
|
+
readonly timeoutMs: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The state commit a wake read, which its save must replace; undefined where no wake saved before. */
|
|
27
|
+
export type CiStateRead = { readonly read: string | undefined };
|
|
28
|
+
|
|
29
|
+
/** A save lost the race: another wake saved after this one read, and hum never writes over that. */
|
|
30
|
+
export class CiStateRaced extends Error {
|
|
31
|
+
override name = "CiStateRaced";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Runs `use` with a scratch git index, removed after. */
|
|
35
|
+
const withScratchIndex = async <T>(use: (env: { readonly GIT_INDEX_FILE: string }) => Promise<T>): Promise<T> => {
|
|
36
|
+
const scratch = mkdtempSync(join(tmpdir(), "hum-state-index-"));
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
return await use({ GIT_INDEX_FILE: join(scratch, "index") });
|
|
40
|
+
} finally {
|
|
41
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Writes the state the last wake saved into `dir`, and returns the commit read; a remote that holds none leaves `dir` as it is. */
|
|
46
|
+
export const restoreCiState = async ({ repo, remote, dir, timeoutMs }: CiStateOptions): Promise<CiStateRead> => {
|
|
47
|
+
const git = gitIn(repo, { timeoutMs });
|
|
48
|
+
const fetched = await git.run(["fetch", "--quiet", "--no-tags", remote, `+${CI_STATE_REF}:${CI_STATE_REF}`]);
|
|
49
|
+
|
|
50
|
+
if (fetched.code !== 0 && NO_REF.test(fetched.stderr)) return { read: undefined };
|
|
51
|
+
|
|
52
|
+
if (fetched.code !== 0) throw new Error(`hum could not read its saved state from ${remote}: ${fetched.stderr.trim()}`);
|
|
53
|
+
|
|
54
|
+
const read = (await git.raw(["rev-parse", CI_STATE_REF])).trim();
|
|
55
|
+
|
|
56
|
+
mkdirSync(dir, { recursive: true });
|
|
57
|
+
await withScratchIndex(async (env) => {
|
|
58
|
+
const indexed = gitIn(repo, { timeoutMs, env });
|
|
59
|
+
|
|
60
|
+
await indexed.raw(["read-tree", read]);
|
|
61
|
+
await indexed.raw(["checkout-index", "--all", "--force", `--prefix=${join(dir, "/")}`]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return { read };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** The tree of every state file the next wake needs, built through a scratch index so no work tree is touched. */
|
|
68
|
+
const stateTree = async ({ repo, dir, timeoutMs }: Omit<CiStateOptions, "remote">): Promise<string> => {
|
|
69
|
+
const git = gitIn(repo, { timeoutMs });
|
|
70
|
+
const files = existsSync(dir) ? [...new Bun.Glob("**").scanSync({ cwd: dir, onlyFiles: true, dot: true })].filter((path) => !isJobOnly(path)).sort() : [];
|
|
71
|
+
|
|
72
|
+
if (files.length === 0) return (await git.raw(["hash-object", "-w", "-t", "tree", "/dev/null"])).trim();
|
|
73
|
+
|
|
74
|
+
const blobs = (await git.raw(["hash-object", "-w", "--stdin-paths"], `${files.map((path) => join(dir, path)).join("\n")}\n`)).trim().split("\n");
|
|
75
|
+
|
|
76
|
+
return withScratchIndex(async (env) => {
|
|
77
|
+
const indexed = gitIn(repo, { timeoutMs, env });
|
|
78
|
+
|
|
79
|
+
await indexed.raw(["update-index", "--add", "--index-info"], files.map((path, at) => `100644 ${blobs[at]}\t${path}\n`).join(""));
|
|
80
|
+
|
|
81
|
+
return (await indexed.raw(["write-tree"])).trim();
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Saves the state folder to the remote as one commit with no parent, so the ref never grows, in place of the commit
|
|
87
|
+
* this wake read: a compare-and-swap, which throws `CiStateRaced` when another wake saved first. Returns the new read.
|
|
88
|
+
*/
|
|
89
|
+
export const saveCiState = async ({ read, identity, at, ...options }: CiStateOptions & CiStateRead & { readonly identity: GitIdentity; readonly at: number }): Promise<CiStateRead> => {
|
|
90
|
+
const git = gitIn(options.repo, { identity, timeoutMs: options.timeoutMs });
|
|
91
|
+
const commit = (await git.raw(["commit-tree", await stateTree(options), "-m", `hum state ${new Date(at).toISOString()}`])).trim();
|
|
92
|
+
const pushed = await push(git, [`--force-with-lease=${CI_STATE_REF}:${read ?? ""}`, options.remote, `${commit}:${CI_STATE_REF}`]);
|
|
93
|
+
|
|
94
|
+
if (pushed.kind === "conflict") throw new CiStateRaced(`another wake saved hum's state to ${CI_STATE_REF} after this one read it, so this wake's state was not saved`);
|
|
95
|
+
|
|
96
|
+
if (pushed.kind === "refused") throw new Error(`${options.remote} refused hum's state at ${CI_STATE_REF}: ${pushed.said}`);
|
|
97
|
+
|
|
98
|
+
return { read: commit };
|
|
99
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { gitIn, whenGitFailed } from "../adapters/git.ts";
|
|
6
|
+
import { type Env, exec, SHIPPED_COMMAND_TIMEOUT_MS } from "../exec.ts";
|
|
7
|
+
|
|
8
|
+
/** The marketplace hope comes from, by the name its own manifest gives it. */
|
|
9
|
+
const MOO_MARKETPLACE = "moo.md";
|
|
10
|
+
|
|
11
|
+
const MOO_REPO = "https://github.com/saadshahd/moo.md";
|
|
12
|
+
|
|
13
|
+
const HOPE_PLUGIN = `hope@${MOO_MARKETPLACE}`;
|
|
14
|
+
|
|
15
|
+
/** The engine's folder: `hum-engine` in a moo.md checkout, `node_modules/@moo.md/hum` in an owner's repo. */
|
|
16
|
+
const ENGINE_ROOT = resolve(import.meta.dir, "..", "..");
|
|
17
|
+
|
|
18
|
+
/** The file the publish job writes beside the package: the moo.md commit it was published from. */
|
|
19
|
+
export const RELEASE_FILE = "release.json";
|
|
20
|
+
|
|
21
|
+
/** What `release.json` holds: the full sha of the moo.md commit the package was published from. */
|
|
22
|
+
export const Release = z.object({ commit: z.string().regex(/^[0-9a-f]{40}$/) });
|
|
23
|
+
|
|
24
|
+
/** A marketplace as a settings file declares it, in the forms `claude plugin marketplace add` takes. */
|
|
25
|
+
const Source = z.discriminatedUnion("source", [
|
|
26
|
+
z.looseObject({ source: z.literal("github"), repo: z.string().min(1), ref: z.string().min(1).optional(), path: z.never().optional() }),
|
|
27
|
+
z.looseObject({ source: z.literal("git"), url: z.string().min(1), ref: z.string().min(1).optional(), path: z.never().optional() }),
|
|
28
|
+
z.looseObject({ source: z.literal("url"), url: z.string().min(1) }),
|
|
29
|
+
z.looseObject({ source: z.literal("directory"), path: z.string().min(1) }),
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
/** What a repo's `.claude/settings.json` says about plugins; every other key is Claude Code's alone. */
|
|
33
|
+
export const RepoPlugins = z.looseObject({
|
|
34
|
+
extraKnownMarketplaces: z.record(z.string(), z.looseObject({ source: Source })).default({}),
|
|
35
|
+
enabledPlugins: z.record(z.string(), z.unknown()).default({}),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type RepoPlugins = z.infer<typeof RepoPlugins>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The moo.md commit this engine shipped with: the one its package was published from, or, where the engine runs from
|
|
42
|
+
* a moo.md checkout, that checkout's HEAD. Any other engine has none, and that throws: an unpinned hope could be one
|
|
43
|
+
* this engine was never released beside.
|
|
44
|
+
*/
|
|
45
|
+
export const shippedCommit = async (): Promise<string> => {
|
|
46
|
+
const file = join(ENGINE_ROOT, RELEASE_FILE);
|
|
47
|
+
|
|
48
|
+
if (existsSync(file)) return Release.parse(JSON.parse(readFileSync(file, "utf8"))).commit;
|
|
49
|
+
|
|
50
|
+
const git = gitIn(ENGINE_ROOT, { timeoutMs: SHIPPED_COMMAND_TIMEOUT_MS });
|
|
51
|
+
const top = (await git.raw(["rev-parse", "--show-toplevel"]).catch(whenGitFailed(""))).trim();
|
|
52
|
+
|
|
53
|
+
if (top === "" || resolve(top) !== resolve(ENGINE_ROOT, "..")) throw new Error(`this engine holds no ${RELEASE_FILE} and sits in no moo.md checkout, so it names no moo.md commit to install hope from`);
|
|
54
|
+
|
|
55
|
+
return (await git.raw(["rev-parse", "HEAD"])).trim();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const marketplaceArgument = (source: z.infer<typeof Source>, repo: string): string => {
|
|
59
|
+
switch (source.source) {
|
|
60
|
+
case "github":
|
|
61
|
+
return source.ref === undefined ? source.repo : `${source.repo}#${source.ref}`;
|
|
62
|
+
case "git":
|
|
63
|
+
return source.ref === undefined ? source.url : `${source.url}#${source.ref}`;
|
|
64
|
+
case "url":
|
|
65
|
+
return source.url;
|
|
66
|
+
case "directory":
|
|
67
|
+
return isAbsolute(source.path) ? source.path : join(repo, source.path);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const COMMIT_SHA = /^[0-9a-f]{40}$/;
|
|
72
|
+
|
|
73
|
+
/** A marketplace fetched from a repo by anything but a commit SHA installs whatever its branch or tag holds at the wake. */
|
|
74
|
+
const isUnpinned = (source: z.infer<typeof Source>): boolean => (source.source === "github" || source.source === "git") && !COMMIT_SHA.test(source.ref ?? "");
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The `claude` command lines that install hope and the repo's plugins: moo.md from `mooFolder`, its checkout at the
|
|
78
|
+
* shipped commit, which stands in for any moo.md the settings declare; each other marketplace they declare; then hope
|
|
79
|
+
* and every plugin they enable. A marketplace from a repo whose `ref` is no full commit SHA throws: its hooks would run
|
|
80
|
+
* in every run as whatever its branch or tag holds that day.
|
|
81
|
+
*/
|
|
82
|
+
export const pluginCommands = (settings: RepoPlugins, { repo, mooFolder }: { readonly repo: string; readonly mooFolder: string }): string[][] => {
|
|
83
|
+
const declared = Object.entries(settings.extraKnownMarketplaces).filter(([name]) => name !== MOO_MARKETPLACE);
|
|
84
|
+
const unpinned = declared.flatMap(([name, { source }]) => (isUnpinned(source) ? [name] : []));
|
|
85
|
+
|
|
86
|
+
if (unpinned.length > 0) throw new Error(`the marketplaces ${unpinned.join(", ")} in .claude/settings.json name no commit SHA as "ref", so a wake would install whatever their branch or tag holds, and their hooks run in every run. Give each a "ref" of a full 40-character commit SHA, which no push can move.`);
|
|
87
|
+
|
|
88
|
+
const marketplaces = declared.map(([, { source }]) => marketplaceArgument(source, repo));
|
|
89
|
+
const enabled = Object.entries(settings.enabledPlugins).flatMap(([id, on]) => (on === true ? [id] : []));
|
|
90
|
+
|
|
91
|
+
return [mooFolder, ...marketplaces].map((source) => ["plugin", "marketplace", "add", source]).concat([...new Set([HOPE_PLUGIN, ...enabled])].map((id) => ["plugin", "install", id]));
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** The plugin settings of the repo's `.claude/settings.json`; none where it has no such file. */
|
|
95
|
+
export const repoPlugins = (repo: string): RepoPlugins => {
|
|
96
|
+
const file = join(repo, ".claude", "settings.json");
|
|
97
|
+
|
|
98
|
+
return RepoPlugins.parse(existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** moo.md at `commit`, fetched alone into a new folder under `parent`. */
|
|
102
|
+
const checkOutMoo = async (commit: string, parent: string): Promise<string> => {
|
|
103
|
+
const folder = mkdtempSync(join(parent, "hum-moo-"));
|
|
104
|
+
const git = gitIn(folder, { timeoutMs: SHIPPED_COMMAND_TIMEOUT_MS });
|
|
105
|
+
|
|
106
|
+
await git.raw(["init", "-q"]);
|
|
107
|
+
await git.raw(["fetch", "-q", "--depth", "1", MOO_REPO, commit]);
|
|
108
|
+
await git.raw(["checkout", "-q", "FETCH_HEAD"]);
|
|
109
|
+
|
|
110
|
+
return folder;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type PluginInstall = {
|
|
114
|
+
readonly repo: string;
|
|
115
|
+
readonly env: Env;
|
|
116
|
+
/** Runs `claude` with these arguments; the CLI runs the real binary. */
|
|
117
|
+
readonly claude?: (args: readonly string[]) => Promise<{ readonly exitCode: number | undefined; readonly stdout: string; readonly stderr: string }>;
|
|
118
|
+
/** The moo.md folder to install from; by default a checkout of the shipped commit. */
|
|
119
|
+
readonly mooFolder?: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Installs hope and the repo's plugins for Claude Code in this job. A fresh checkout is a folder Claude Code does not
|
|
124
|
+
* trust, so it skips the marketplaces the repo's settings declare; this adds them as the user's own. The first command
|
|
125
|
+
* that fails throws, naming itself and what claude said.
|
|
126
|
+
*/
|
|
127
|
+
export const installPlugins = async ({ repo, env, claude = (args) => exec("claude", args, { throwOnError: false, timeoutMs: SHIPPED_COMMAND_TIMEOUT_MS, nodeOptions: { env } }), mooFolder }: PluginInstall): Promise<readonly string[][]> => {
|
|
128
|
+
const commands = pluginCommands(repoPlugins(repo), { repo, mooFolder: mooFolder ?? (await checkOutMoo(await shippedCommit(), env.RUNNER_TEMP ?? tmpdir())) });
|
|
129
|
+
|
|
130
|
+
for (const args of commands) {
|
|
131
|
+
const ran = await claude(args);
|
|
132
|
+
|
|
133
|
+
if (ran.exitCode !== 0) throw new Error(`claude ${args.join(" ")} exited ${ran.exitCode}: ${(ran.stderr || ran.stdout).trim()}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return commands;
|
|
137
|
+
};
|
package/src/service/wake.ts
CHANGED
|
@@ -5,12 +5,14 @@ import type { Worker } from "../worker/worker.ts";
|
|
|
5
5
|
/**
|
|
6
6
|
* CI wake: ticks, lets the runs it started end, and ticks again until a tick starts nothing. A CI job holds no
|
|
7
7
|
* session across a wait for the owner: a run that needs them has pushed its branch, asked on the item and ended.
|
|
8
|
+
* `afterTick` runs once each tick's runs have ended, so a job stopped at its time limit loses only the tick in flight.
|
|
8
9
|
*/
|
|
9
|
-
export const wakeUntilQuiet = async (worker: Worker): Promise<void> => {
|
|
10
|
+
export const wakeUntilQuiet = async (worker: Pick<Worker, "tick" | "idle">, afterTick: () => Promise<void> = async () => {}): Promise<void> => {
|
|
10
11
|
for (;;) {
|
|
11
12
|
const result = await worker.tick();
|
|
12
13
|
|
|
13
14
|
await worker.idle();
|
|
15
|
+
await afterTick();
|
|
14
16
|
|
|
15
17
|
if (result.kind !== "ran" || result.started.length === 0) return;
|
|
16
18
|
}
|
package/src/service/workflows.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Document, visit } from "yaml";
|
|
2
2
|
import { CLAUDE_FLOOR } from "../adapters/claude-p.ts";
|
|
3
3
|
import type { HumConfig, PullRequestToken } from "../config/schema.ts";
|
|
4
|
-
import { APP_TOKEN_ACTION, CLAUDE_TOKEN, readsSecrets, secretsNamed, TRUSTED_ASSOCIATIONS, WAKE_ENV as ENV, WORKFLOW_FILES } from "../config/wake-job.ts";
|
|
4
|
+
import { APP_TOKEN_ACTION, APP_TOKEN_MINUTES, CLAUDE_TOKEN, readsSecrets, secretsNamed, TRUSTED_ASSOCIATIONS, WAKE_ENV as ENV, WORKFLOW_FILES } from "../config/wake-job.ts";
|
|
5
|
+
import { ENGINE_VERSION } from "../state/format.ts";
|
|
6
|
+
import { MEGABYTE } from "../bytes.ts";
|
|
5
7
|
|
|
6
8
|
/** The settings the workflows are built from. */
|
|
7
9
|
export type WorkflowSettings = Pick<
|
|
8
10
|
HumConfig,
|
|
9
|
-
"runBranchPrefix" | "itemsDir" | "ciSchedule" | "commitIdentity" | "ciWakeTimeoutMinutes" | "pullRequestToken" | "ciRunner" | "ciContainer" | "ciEnv" | "ciClaudeAuth"
|
|
11
|
+
"runBranchPrefix" | "itemsDir" | "ciSchedule" | "commitIdentity" | "ciWakeTimeoutMinutes" | "ciOutboxMaxMegabytes" | "pullRequestToken" | "ciRunner" | "ciContainer" | "ciEnv" | "ciClaudeAuth"
|
|
10
12
|
>;
|
|
11
13
|
|
|
12
14
|
/** The type of the `repository_dispatch` event a tracker's webhook sends. */
|
|
@@ -14,8 +16,6 @@ const DISPATCH_EVENT = "hum-wake";
|
|
|
14
16
|
|
|
15
17
|
const WAKE_PATH = `./.github/workflows/${WORKFLOW_FILES.wake}`;
|
|
16
18
|
|
|
17
|
-
const HOPE_MARKETPLACE = "saadshahd/moo.md";
|
|
18
|
-
|
|
19
19
|
/** The Bun that builds the workflows is the one the owner's repo runs, so CI installs with the same lockfile reader. */
|
|
20
20
|
const BUN_VERSION = Bun.version;
|
|
21
21
|
|
|
@@ -26,12 +26,17 @@ const BUN_VERSION = Bun.version;
|
|
|
26
26
|
const ACTIONS = {
|
|
27
27
|
checkout: { uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1", release: "v7.0.1" },
|
|
28
28
|
appToken: { uses: `${APP_TOKEN_ACTION}@64ab729a6294000f5aa4a4bc0b73d1f32bc45510`, release: "v3.3.0" },
|
|
29
|
+
upload: { uses: "actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9", release: "v7.0.2" },
|
|
30
|
+
download: { uses: "actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333", release: "v8.0.2" },
|
|
29
31
|
} as const;
|
|
30
32
|
|
|
31
33
|
const RELEASE_OF: ReadonlyMap<string, string> = new Map(Object.values(ACTIONS).map(({ uses, release }) => [uses, release]));
|
|
32
34
|
|
|
33
35
|
const PERMISSIONS = { contents: "write", issues: "write", "pull-requests": "write" } as const;
|
|
34
36
|
|
|
37
|
+
/** The workflow token's permissions: the App's, and reading the run's artifacts, which the publish job sizes before it downloads one. */
|
|
38
|
+
const WORKFLOW_PERMISSIONS = { ...PERMISSIONS, actions: "read" } as const;
|
|
39
|
+
|
|
35
40
|
/** One wake at a time: a second event waits for the first run instead of racing it. */
|
|
36
41
|
const CONCURRENCY = { group: "hum-wake", "cancel-in-progress": false } as const;
|
|
37
42
|
|
|
@@ -52,7 +57,7 @@ type TriggerJob = { readonly if?: string };
|
|
|
52
57
|
const trigger = (name: string, on: TriggerEvents, job: TriggerJob = {}) => ({
|
|
53
58
|
name,
|
|
54
59
|
on,
|
|
55
|
-
permissions:
|
|
60
|
+
permissions: WORKFLOW_PERMISSIONS,
|
|
56
61
|
concurrency: CONCURRENCY,
|
|
57
62
|
jobs: { wake: { ...job, uses: WAKE_PATH, secrets: "inherit" } },
|
|
58
63
|
});
|
|
@@ -79,6 +84,9 @@ echo "${JOB_TOOLS}/bin" >> "$GITHUB_PATH"
|
|
|
79
84
|
/** The YAML writer leaves out a key whose value is undefined, so a job that runs on the runner itself has no `container`. */
|
|
80
85
|
const NO_KEY = undefined;
|
|
81
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
|
+
|
|
82
90
|
const OPTIONAL_SECRET = { required: false } as const;
|
|
83
91
|
|
|
84
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. */
|
|
@@ -99,18 +107,27 @@ const CLAUDE_SIGN_IN = {
|
|
|
99
107
|
|
|
100
108
|
/**
|
|
101
109
|
* The secrets a wake's GitHub token comes from, the env and steps that turn them into it, and the expression that
|
|
102
|
-
* holds it. An App's token is minted with the workflow token's permissions, so both hold the same rights.
|
|
110
|
+
* holds it. An App's token is minted with the workflow token's permissions, so both hold the same rights. A wake
|
|
111
|
+
* whose App secrets are unset stops at its first step and says which: with the workflow token in their place, the
|
|
112
|
+
* pull requests it opened would start no checks. A secret's token falls back to the workflow token while it is unset.
|
|
103
113
|
*/
|
|
104
114
|
const githubToken = (source: PullRequestToken) =>
|
|
105
115
|
source.from === "secret"
|
|
106
|
-
? { secrets: { [source.secret]: OPTIONAL_SECRET }, env: {}, steps: [], token: `\${{ secrets.${source.secret} || github.token }}` }
|
|
116
|
+
? { secrets: { [source.secret]: OPTIONAL_SECRET }, env: {}, check: [], steps: [], token: `\${{ secrets.${source.secret} || github.token }}` }
|
|
107
117
|
: {
|
|
108
118
|
secrets: { [source.clientIdSecret]: OPTIONAL_SECRET, [source.privateKeySecret]: OPTIONAL_SECRET },
|
|
109
|
-
env: { [ENV.hasApp]: `\${{ secrets.${source.clientIdSecret} != '' }}` },
|
|
119
|
+
env: { [ENV.hasApp]: `\${{ secrets.${source.clientIdSecret} != '' && secrets.${source.privateKeySecret} != '' }}` },
|
|
120
|
+
check: [
|
|
121
|
+
{
|
|
122
|
+
if: `env.${ENV.hasApp} != 'true'`,
|
|
123
|
+
run: `echo "::error title=hum::The GitHub App secrets ${source.clientIdSecret} and ${source.privateKeySecret} are not both set. A pull request opened with the workflow token starts no checks, so this wake stops. Set both secrets, or change pullRequestToken in .hum/hum.json."
|
|
124
|
+
exit 1
|
|
125
|
+
`,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
110
128
|
steps: [
|
|
111
129
|
{
|
|
112
130
|
id: APP_TOKEN_STEP,
|
|
113
|
-
if: `env.${ENV.hasApp} == 'true'`,
|
|
114
131
|
uses: ACTIONS.appToken.uses,
|
|
115
132
|
with: {
|
|
116
133
|
"client-id": secret(source.clientIdSecret),
|
|
@@ -119,7 +136,7 @@ const githubToken = (source: PullRequestToken) =>
|
|
|
119
136
|
},
|
|
120
137
|
},
|
|
121
138
|
],
|
|
122
|
-
token: `\${{ steps.${APP_TOKEN_STEP}.outputs.token
|
|
139
|
+
token: `\${{ steps.${APP_TOKEN_STEP}.outputs.token }}`,
|
|
123
140
|
};
|
|
124
141
|
|
|
125
142
|
/**
|
|
@@ -133,8 +150,7 @@ const gitSetup = ({ name, email }: HumConfig["commitIdentity"]) => ({
|
|
|
133
150
|
run: `git config --global user.name "$${ENV.gitName}"
|
|
134
151
|
git config --global user.email "$${ENV.gitEmail}"
|
|
135
152
|
git config --global credential.https://github.com.helper "$${ENV.gitCredentialHelper}"
|
|
136
|
-
|
|
137
|
-
`,
|
|
153
|
+
${SAFE_CHECKOUT.run}`,
|
|
138
154
|
env: {
|
|
139
155
|
[ENV.gitName]: name,
|
|
140
156
|
[ENV.gitEmail]: email,
|
|
@@ -142,43 +158,123 @@ git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
|
142
158
|
},
|
|
143
159
|
});
|
|
144
160
|
|
|
161
|
+
/** The inbox gather hands the work job, and the outbox the work job hands publish: one artifact each, kept a day. */
|
|
162
|
+
const HANDOVER = { inbox: "hum-inbox", outbox: "hum-outbox" } as const;
|
|
163
|
+
|
|
164
|
+
const RETENTION_DAYS = 1;
|
|
165
|
+
|
|
166
|
+
/** Where a handover sits on the runner: as an action's input reads it, and as a shell reads it. */
|
|
167
|
+
const handoverPath = (name: string): string => `\${{ runner.temp }}/${name}`;
|
|
168
|
+
|
|
169
|
+
const handoverFolder = (name: string): string => `"$RUNNER_TEMP/${name}"`;
|
|
170
|
+
|
|
171
|
+
const upload = (name: string) => ({ uses: ACTIONS.upload.uses, with: { name, path: handoverPath(name), "retention-days": RETENTION_DAYS, "if-no-files-found": "error" } });
|
|
172
|
+
|
|
173
|
+
const download = (name: string) => ({ uses: ACTIONS.download.uses, with: { name, path: handoverPath(name) } });
|
|
174
|
+
|
|
175
|
+
/** Stops the job before it downloads the artifact `name` when GitHub's artifacts API says it is larger than `maxBytes`, or the run holds no single one. */
|
|
176
|
+
const sizeCheck = (name: string, maxBytes: number) => ({
|
|
177
|
+
env: { [ENV.actionsToken]: "${{ github.token }}" },
|
|
178
|
+
run: `node --input-type=module -e '
|
|
179
|
+
const env = process.env;
|
|
180
|
+
const reply = await fetch(env.GITHUB_API_URL + "/repos/" + env.GITHUB_REPOSITORY + "/actions/runs/" + env.GITHUB_RUN_ID + "/artifacts?name=${name}", { headers: { authorization: "Bearer " + env.${ENV.actionsToken}, accept: "application/vnd.github+json" } });
|
|
181
|
+
if (!reply.ok) throw new Error("GitHub artifacts API answered " + reply.status);
|
|
182
|
+
const { artifacts } = await reply.json();
|
|
183
|
+
if (artifacts.length !== 1) throw new Error("the run holds " + artifacts.length + " artifacts named ${name}");
|
|
184
|
+
if (artifacts[0].size_in_bytes > ${maxBytes}) throw new Error("${name} holds " + artifacts[0].size_in_bytes + " bytes, over the ${maxBytes} bytes publish reads; this wake publishes nothing");
|
|
185
|
+
'
|
|
186
|
+
`,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/** What gather settled, as its job output: publish trusts it, and the work job checks out the base it names. */
|
|
190
|
+
const GATHERED = "${{ needs.gather.outputs.gathered }}";
|
|
191
|
+
|
|
192
|
+
const GATHERED_BASE = "${{ fromJSON(needs.gather.outputs.gathered).baseSha }}";
|
|
193
|
+
|
|
194
|
+
/** hum at this engine's own version from npm, which checks the package against the registry's integrity and installs each dependency at the version and hash its shrinkwrap pins; the jobs that hold GitHub's token run this hum and none of the repo's code. */
|
|
195
|
+
const PUBLISHED_HUM = `@moo.md/hum@${ENGINE_VERSION}`;
|
|
196
|
+
|
|
197
|
+
/** The tools every job installs at exact versions, each with the one install script that fetches its native binary. */
|
|
198
|
+
const TOOLS = [
|
|
199
|
+
{ spec: `bun@${BUN_VERSION}`, folder: "bun", script: "install.js" },
|
|
200
|
+
{ spec: `@anthropic-ai/claude-code@${CLAUDE_FLOOR}`, folder: "@anthropic-ai/claude-code", script: "install.cjs" },
|
|
201
|
+
] as const;
|
|
202
|
+
|
|
145
203
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* Claude Code install through npm into the job's temp folder, so the job needs only git, node and npm from its runner
|
|
149
|
-
* or container, and leaves nothing on a machine that outlives it. The Claude sign-in, the GitHub token and every
|
|
150
|
-
* `ciEnv` value that reads a secret reach the last step alone. An App's token lasts an hour, so it is minted last.
|
|
204
|
+
* Installs the tools, and `extra` packages, with no package's install script, so no dependency of theirs runs code at
|
|
205
|
+
* install; then the tools' own scripts alone fetch their native binaries.
|
|
151
206
|
*/
|
|
152
|
-
const
|
|
207
|
+
const installTools = (extra = "") => ({
|
|
208
|
+
run: [`npm install --global --prefix "${JOB_TOOLS}" --ignore-scripts ${TOOLS.map(({ spec }) => spec).join(" ")}${extra}`, ...TOOLS.map(({ folder, script }) => `(cd "${JOB_TOOLS}/lib/node_modules/${folder}" && node ${script})`)].join("\n"),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
/** Git in a job container trusts the checkout the runner's user owns; the global config is the job's own file. */
|
|
212
|
+
const SAFE_CHECKOUT = { run: 'git config --global --add safe.directory "$GITHUB_WORKSPACE"\n' } as const;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The wake, as three jobs. `gather` and `publish` hold GitHub's token and run hum as published, with none of the
|
|
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.
|
|
222
|
+
*/
|
|
223
|
+
const wake = ({ commitIdentity, ciWakeTimeoutMinutes, ciOutboxMaxMegabytes, pullRequestToken, ciRunner, ciContainer, ciEnv, ciClaudeAuth }: WorkflowSettings) => {
|
|
153
224
|
const claude = CLAUDE_SIGN_IN[ciClaudeAuth];
|
|
154
225
|
const github = githubToken(pullRequestToken);
|
|
155
226
|
const env = envByReach(ciEnv);
|
|
227
|
+
const where = { "runs-on": ciRunner, container: ciContainer ?? NO_KEY };
|
|
228
|
+
const humEnv = { ...env.humStep, ...claude.env, [ENV.githubToken]: github.token };
|
|
229
|
+
const checkout = (ref?: string) => ({ uses: ACTIONS.checkout.uses, with: { ...(ref && { ref }), "fetch-depth": 0, "persist-credentials": false } });
|
|
230
|
+
|
|
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 }) => ({
|
|
233
|
+
...where,
|
|
234
|
+
permissions,
|
|
235
|
+
"timeout-minutes": APP_TOKEN_MINUTES,
|
|
236
|
+
env: { ...env.everyStep, ...github.env, [ENV.event]: "${{ github.event_name }}" },
|
|
237
|
+
steps: [...github.check, checkout(ref), JOB_PATHS_STEP, installTools(` ${PUBLISHED_HUM}`), gitSetup(commitIdentity), ...before, ...github.steps, run, ...after],
|
|
238
|
+
});
|
|
156
239
|
|
|
157
240
|
return {
|
|
158
241
|
name: "hum wake",
|
|
159
242
|
on: { workflow_call: { secrets: { ...ownerSecrets({ ciRunner, ciContainer, ciEnv }), ...claude.secrets, ...github.secrets } } },
|
|
160
|
-
permissions:
|
|
243
|
+
permissions: {},
|
|
161
244
|
jobs: {
|
|
162
|
-
|
|
163
|
-
"
|
|
164
|
-
|
|
245
|
+
gather: {
|
|
246
|
+
...holdsToken({ before: [], run: { id: "gather", run: `hum wake gather --inbox ${handoverFolder(HANDOVER.inbox)}`, env: humEnv }, after: [upload(HANDOVER.inbox)] }),
|
|
247
|
+
outputs: { gathered: "${{ steps.gather.outputs.gathered }}" },
|
|
248
|
+
},
|
|
249
|
+
work: {
|
|
250
|
+
needs: "gather",
|
|
251
|
+
...where,
|
|
252
|
+
permissions: { contents: "read" },
|
|
165
253
|
"timeout-minutes": ciWakeTimeoutMinutes,
|
|
166
|
-
env:
|
|
254
|
+
env: envOrNone(env.everyStep),
|
|
167
255
|
steps: [
|
|
168
|
-
|
|
256
|
+
checkout(GATHERED_BASE),
|
|
169
257
|
JOB_PATHS_STEP,
|
|
170
|
-
|
|
258
|
+
installTools(),
|
|
171
259
|
{ run: "bun install --frozen-lockfile" },
|
|
172
|
-
{ run:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
{ run: `./node_modules/.bin/hum wake --
|
|
260
|
+
{ run: "./node_modules/.bin/hum plugins" },
|
|
261
|
+
SAFE_CHECKOUT,
|
|
262
|
+
download(HANDOVER.inbox),
|
|
263
|
+
{ run: `./node_modules/.bin/hum wake work --inbox ${handoverFolder(HANDOVER.inbox)} --outbox ${handoverFolder(HANDOVER.outbox)}`, env: envOrNone({ ...env.humStep, ...claude.env }) },
|
|
264
|
+
upload(HANDOVER.outbox),
|
|
176
265
|
],
|
|
177
266
|
},
|
|
267
|
+
publish: {
|
|
268
|
+
needs: ["gather", "work"],
|
|
269
|
+
...holdsToken({ ref: GATHERED_BASE, permissions: WORKFLOW_PERMISSIONS, before: [sizeCheck(HANDOVER.outbox, ciOutboxMaxMegabytes * MEGABYTE), download(HANDOVER.outbox)], run: { run: `hum wake publish --outbox ${handoverFolder(HANDOVER.outbox)} --event "$${ENV.event}"`, env: { ...humEnv, [ENV.gathered]: GATHERED } } }),
|
|
270
|
+
},
|
|
178
271
|
},
|
|
179
272
|
};
|
|
180
273
|
};
|
|
181
274
|
|
|
275
|
+
/** An item push wakes hum only on the default branch: a wake runs the checked-out branch's code with every secret, and anyone who may push a branch could change that code. */
|
|
276
|
+
const ON_DEFAULT_BRANCH = "github.ref_name == github.event.repository.default_branch";
|
|
277
|
+
|
|
182
278
|
/** A comment wakes hum only when a person the repo trusts wrote it: on a public repo anyone may comment, and a wake holds every secret. */
|
|
183
279
|
const TRUSTED_COMMENT = `github.event.comment.user.type != 'Bot' && contains(fromJSON('${JSON.stringify(TRUSTED_ASSOCIATIONS)}'), github.event.comment.author_association)`;
|
|
184
280
|
|
|
@@ -202,7 +298,7 @@ const render = (workflow: Workflow): string => {
|
|
|
202
298
|
const WORKFLOWS = {
|
|
203
299
|
[WORKFLOW_FILES.wake]: wake,
|
|
204
300
|
[WORKFLOW_FILES.comment]: () => trigger("hum on comment", { issue_comment: { types: ["created"] } }, { if: TRUSTED_COMMENT }),
|
|
205
|
-
[WORKFLOW_FILES.push]: ({ itemsDir, runBranchPrefix }) => trigger("hum on item push", { push: { branches: ["**", `!${runBranchPrefix}**`], paths: [`${itemsDir}/**`] } }),
|
|
301
|
+
[WORKFLOW_FILES.push]: ({ itemsDir, runBranchPrefix }) => trigger("hum on item push", { push: { branches: ["**", `!${runBranchPrefix}**`], paths: [`${itemsDir}/**`] } }, { if: ON_DEFAULT_BRANCH }),
|
|
206
302
|
[WORKFLOW_FILES.dispatch]: () => trigger("hum on dispatch", { repository_dispatch: { types: [DISPATCH_EVENT] } }),
|
|
207
303
|
[WORKFLOW_FILES.schedule]: ({ ciSchedule }) => trigger("hum on schedule", { schedule: [{ cron: ciSchedule }], workflow_dispatch: null }),
|
|
208
304
|
} as const satisfies Record<(typeof WORKFLOW_FILES)[keyof typeof WORKFLOW_FILES], (settings: WorkflowSettings) => object>;
|
package/src/setup/propose.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Item } from "../adapter-api.ts";
|
|
2
2
|
import { declaredKind } from "../decide/kind.ts";
|
|
3
3
|
import { usualSize } from "../decide/risk.ts";
|
|
4
|
-
import type { DefaultsConfig, HumConfig, PathRule, PullRequestToken, RunPlace, SlotRecipe } from "../config/schema.ts";
|
|
4
|
+
import type { DefaultsConfig, HumConfig, PathRule, PullRequestToken, RunPlace, Slot, SlotRecipe } from "../config/schema.ts";
|
|
5
5
|
import { APP_TOKEN_ACTION, CI_WORKFLOW_FILES, CLAUDE_TOKEN, isGitHubHosted, readsForeignContext, WAKE_OWN_ENV } from "../config/wake-job.ts";
|
|
6
6
|
import type { CiJob, RepoScan } from "./scan.ts";
|
|
7
7
|
import {
|
|
@@ -36,6 +36,8 @@ export type Proposal = {
|
|
|
36
36
|
readonly runSlots: Pick<HumConfig["runSlots"], "services" | "recipe">;
|
|
37
37
|
readonly runPlaces: readonly RunPlace[];
|
|
38
38
|
readonly wakeJob: Pick<HumConfig, "ciRunner" | "ciContainer" | "ciEnv" | "ciClaudeAuth" | "pullRequestToken">;
|
|
39
|
+
/** The adapter of each slot that does not use the markdown source; empty where the repo keeps no work in issues. */
|
|
40
|
+
readonly integrations: NonNullable<HumConfig["integrations"]>;
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
const isPullRequestJob = ({ triggers }: CiJob): boolean => triggers.includes("pull_request");
|
|
@@ -145,8 +147,18 @@ const claudeEnvOf = (job: CiJob): Record<string, string> => {
|
|
|
145
147
|
return Object.fromEntries([...Object.entries(job.env), ...fromInput].filter(([name, value]) => !WAKE_OWN_ENV.has(name) && !readsForeignContext(value)));
|
|
146
148
|
};
|
|
147
149
|
|
|
148
|
-
/** What a scan cannot read from the files: the repo's labels,
|
|
149
|
-
export type RepoFacts = { readonly labels?: readonly string[]; readonly isPublic?: boolean };
|
|
150
|
+
/** What a scan cannot read from the files: the repo's labels, whether anyone may read and comment on it, and how many issues are open on GitHub. */
|
|
151
|
+
export type RepoFacts = { readonly labels?: readonly string[]; readonly isPublic?: boolean; readonly openIssues?: number };
|
|
152
|
+
|
|
153
|
+
/** The slots GitHub issues serve: the items, the questions on them and the answers to those. */
|
|
154
|
+
const ISSUE_SLOTS = ["work-source", "questions", "answers"] as const satisfies readonly Slot[];
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A repo on GitHub that tracks work in issues, open ones or an issue template, takes its items, questions and answers
|
|
158
|
+
* from them; any other keeps markdown items under `.hum/work`. Without a GitHub read there is no issue to count.
|
|
159
|
+
*/
|
|
160
|
+
const integrationsOf = (scan: RepoScan, openIssues: number | undefined): Proposal["integrations"] =>
|
|
161
|
+
openIssues !== undefined && (openIssues > 0 || scan.issueTemplates.length > 0) ? Object.fromEntries(ISSUE_SLOTS.map((slot) => [slot, "github"])) : {};
|
|
150
162
|
|
|
151
163
|
/**
|
|
152
164
|
* The wake job's settings from the job most like it: the one that runs Claude Code gives its runner, container, env
|
|
@@ -174,7 +186,7 @@ const wakeJobOf = (ci: readonly CiJob[], shipped: DefaultsConfig, isPublic: bool
|
|
|
174
186
|
};
|
|
175
187
|
|
|
176
188
|
/** Everything setup proposes from a scan, before it asks. */
|
|
177
|
-
export const proposeSetup = (scan: RepoScan, shipped: DefaultsConfig, { labels = [], isPublic = false }: RepoFacts = {}): Proposal => {
|
|
189
|
+
export const proposeSetup = (scan: RepoScan, shipped: DefaultsConfig, { labels = [], isPublic = false, openIssues }: RepoFacts = {}): Proposal => {
|
|
178
190
|
const checks = checksOf(scan);
|
|
179
191
|
|
|
180
192
|
return {
|
|
@@ -187,5 +199,6 @@ export const proposeSetup = (scan: RepoScan, shipped: DefaultsConfig, { labels =
|
|
|
187
199
|
runSlots: { services: shipped.runSlots.services, recipe: recipeOf(scan, checks) },
|
|
188
200
|
runPlaces: shipped.runPlaces,
|
|
189
201
|
wakeJob: wakeJobOf(scan.ci, shipped, isPublic),
|
|
202
|
+
integrations: integrationsOf(scan, openIssues),
|
|
190
203
|
};
|
|
191
204
|
};
|
package/src/setup/prove.ts
CHANGED
|
@@ -40,7 +40,7 @@ export type ProveEnv = {
|
|
|
40
40
|
readonly now: () => number;
|
|
41
41
|
readonly processEnv: Env;
|
|
42
42
|
readonly newSessionId: () => string;
|
|
43
|
-
readonly
|
|
43
|
+
readonly installedSkills: ReadonlySet<string>;
|
|
44
44
|
readonly base: string;
|
|
45
45
|
/** Whether to run one item end to end through the real `claude`; each run spends live calls. */
|
|
46
46
|
readonly item: boolean;
|
|
@@ -76,7 +76,7 @@ const pinOf = (repo: string): string | undefined => {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
const configStep = (repo: string, env: ProveEnv): Outcome & { readonly config?: Config } => {
|
|
79
|
-
const loaded = loadConfig(readConfigDir(join(repo, ".hum")), { env: {
|
|
79
|
+
const loaded = loadConfig(readConfigDir(join(repo, ".hum")), { env: { installedSkills: env.installedSkills } });
|
|
80
80
|
|
|
81
81
|
return loaded.ok ? { ...passed("every state is reachable, reaches done or stuck, and every wait has a timeout"), config: loaded.value } : failed(loaded.refusal.message);
|
|
82
82
|
};
|
|
@@ -178,7 +178,7 @@ const runItem = async (scratch: Scratch, env: ProveEnv): Promise<Outcome> => {
|
|
|
178
178
|
now: env.now,
|
|
179
179
|
env: env.processEnv,
|
|
180
180
|
newSessionId: env.newSessionId,
|
|
181
|
-
|
|
181
|
+
installedSkills: env.installedSkills,
|
|
182
182
|
holder: Holder.parse("setup-proof"),
|
|
183
183
|
base: env.base,
|
|
184
184
|
where: "ci",
|
package/src/setup/write.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const SetupAnswers = z.strictObject({
|
|
|
36
36
|
export type SetupAnswers = z.infer<typeof SetupAnswers>;
|
|
37
37
|
|
|
38
38
|
export type SetupEnv = {
|
|
39
|
-
readonly
|
|
39
|
+
readonly installedSkills: ReadonlySet<string>;
|
|
40
40
|
/** Where a Mac or Linux service unit is written; default the user's home. */
|
|
41
41
|
readonly home?: string;
|
|
42
42
|
readonly platform?: NodeJS.Platform;
|
|
@@ -144,7 +144,7 @@ export const writeSetup = (repo: string, answers: SetupAnswers, env: SetupEnv):
|
|
|
144
144
|
const timed = withTimeouts(parsedKinds(base), answers.waitHours);
|
|
145
145
|
const kinds = Object.fromEntries(Object.entries(base.kinds).map(([name, file]) => [name, timed[name] ? asJson(timed[name]) : file]));
|
|
146
146
|
const roles = { ...shipped.roles, ...existing?.roles };
|
|
147
|
-
const loaded = loadConfig({ hum: asJson(hum), kinds, roles }, { env: {
|
|
147
|
+
const loaded = loadConfig({ hum: asJson(hum), kinds, roles }, { env: { installedSkills: env.installedSkills } });
|
|
148
148
|
|
|
149
149
|
if (!loaded.ok) return { ok: false, refusal: loaded.refusal };
|
|
150
150
|
|