@intentius/chant 0.124.61 → 0.124.63

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.
Files changed (234) hide show
  1. package/dist/cli/handlers/approve.d.ts +18 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +142 -16
  4. package/dist/cli/handlers/plan.d.ts +10 -0
  5. package/dist/cli/handlers/plan.d.ts.map +1 -0
  6. package/dist/cli/handlers/plan.js +71 -0
  7. package/dist/cli/handlers/release.d.ts +6 -4
  8. package/dist/cli/handlers/release.d.ts.map +1 -1
  9. package/dist/cli/handlers/release.js +13 -7
  10. package/dist/cli/main.d.ts.map +1 -1
  11. package/dist/cli/main.js +34 -5
  12. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  13. package/dist/cli/mcp/workspace-tools.js +2 -1
  14. package/dist/cli/parse-args.d.ts.map +1 -1
  15. package/dist/cli/parse-args.js +31 -0
  16. package/dist/cli/registry.d.ts +13 -1
  17. package/dist/cli/registry.d.ts.map +1 -1
  18. package/dist/config.d.ts +32 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/gate-decision.d.ts +1 -1
  21. package/dist/gate-decision.d.ts.map +1 -1
  22. package/dist/gate-decision.js +4 -2
  23. package/dist/gate-statement.schema.json +44 -0
  24. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
  25. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  26. package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
  27. package/dist/lifecycle/gate-ledger.d.ts +17 -3
  28. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  29. package/dist/lifecycle/gate-seal.d.ts +39 -3
  30. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  31. package/dist/lifecycle/gate-seal.js +50 -10
  32. package/dist/lifecycle/gate-statement.d.ts +70 -0
  33. package/dist/lifecycle/gate-statement.d.ts.map +1 -0
  34. package/dist/lifecycle/gate-statement.js +74 -0
  35. package/dist/lifecycle/gate-webauthn.d.ts +79 -0
  36. package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
  37. package/dist/lifecycle/gate-webauthn.js +105 -0
  38. package/dist/lifecycle/git.d.ts +1 -1
  39. package/dist/lifecycle/git.d.ts.map +1 -1
  40. package/dist/lifecycle/git.js +24 -19
  41. package/dist/lifecycle/ledger-remote.d.ts +37 -0
  42. package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
  43. package/dist/lifecycle/ledger-remote.js +42 -0
  44. package/dist/lifecycle/plan-stale.d.ts +76 -0
  45. package/dist/lifecycle/plan-stale.d.ts.map +1 -0
  46. package/dist/lifecycle/plan-stale.js +121 -0
  47. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  48. package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
  49. package/dist/lifecycle/publish-credentials.js +2 -0
  50. package/dist/lifecycle/publish-declaration.d.ts +87 -0
  51. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  52. package/dist/lifecycle/publish-declaration.js +87 -1
  53. package/dist/lifecycle/publish-forge.d.ts +5 -1
  54. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  55. package/dist/lifecycle/publish-forge.js +14 -4
  56. package/dist/lifecycle/publish-github.d.ts +69 -0
  57. package/dist/lifecycle/publish-github.d.ts.map +1 -0
  58. package/dist/lifecycle/publish-github.js +153 -0
  59. package/dist/lifecycle/publish-homebrew.d.ts +66 -0
  60. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
  61. package/dist/lifecycle/publish-homebrew.js +173 -0
  62. package/dist/lifecycle/publish-marketplace.d.ts +51 -0
  63. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
  64. package/dist/lifecycle/publish-marketplace.js +254 -0
  65. package/dist/lifecycle/publish-targets.d.ts +6 -0
  66. package/dist/lifecycle/publish-targets.d.ts.map +1 -1
  67. package/dist/lifecycle/publish-targets.js +15 -0
  68. package/dist/lifecycle/publish-tauri.d.ts +61 -0
  69. package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
  70. package/dist/lifecycle/publish-tauri.js +182 -0
  71. package/dist/lifecycle/release-publish.d.ts +5 -2
  72. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  73. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  74. package/dist/lifecycle/snapshot-store.js +17 -9
  75. package/dist/lifecycle/test-passkey.d.ts +25 -0
  76. package/dist/lifecycle/test-passkey.d.ts.map +1 -0
  77. package/dist/lifecycle/test-passkey.js +39 -0
  78. package/dist/notify.d.ts +23 -3
  79. package/dist/notify.d.ts.map +1 -1
  80. package/dist/notify.js +8 -2
  81. package/dist/notify.schema.json +12 -3
  82. package/dist/op/activities/activity-contracts.d.ts +4 -4
  83. package/dist/pr-forge.d.ts +20 -0
  84. package/dist/pr-forge.d.ts.map +1 -1
  85. package/dist/pr-forge.js +61 -2
  86. package/dist/release-floors.d.ts +1 -1
  87. package/dist/release-floors.js +1 -1
  88. package/dist/wave-runtime.mjs +331 -330
  89. package/dist/workspace/ci-builds.d.ts +21 -0
  90. package/dist/workspace/ci-builds.d.ts.map +1 -1
  91. package/dist/workspace/ci-builds.js +14 -0
  92. package/dist/workspace/ci-green-workflow.d.ts +2 -0
  93. package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
  94. package/dist/workspace/ci-green-workflow.js +9 -0
  95. package/dist/workspace/ci-green.d.ts +45 -2
  96. package/dist/workspace/ci-green.d.ts.map +1 -1
  97. package/dist/workspace/ci-green.js +127 -9
  98. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  99. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  100. package/dist/workspace/ci-quarantine-report.js +205 -0
  101. package/dist/workspace/ci-quarantine.d.ts +73 -0
  102. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  103. package/dist/workspace/ci-quarantine.js +171 -0
  104. package/dist/workspace/ci-serve.d.ts.map +1 -1
  105. package/dist/workspace/ci-serve.js +7 -4
  106. package/dist/workspace/class-data.d.ts +3 -1
  107. package/dist/workspace/class-data.d.ts.map +1 -1
  108. package/dist/workspace/class-data.js +4 -1
  109. package/dist/workspace/declaration.d.ts +45 -2
  110. package/dist/workspace/declaration.d.ts.map +1 -1
  111. package/dist/workspace/declaration.js +45 -2
  112. package/dist/workspace/declaration.schema.json +51 -3
  113. package/dist/workspace/forge-work.d.ts +76 -0
  114. package/dist/workspace/forge-work.d.ts.map +1 -0
  115. package/dist/workspace/forge-work.js +160 -0
  116. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  117. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  118. package/dist/workspace/identity-gate-rule.js +5 -7
  119. package/dist/workspace/identity.d.ts +3 -2
  120. package/dist/workspace/identity.d.ts.map +1 -1
  121. package/dist/workspace/identity.js +6 -3
  122. package/dist/workspace/intent-cli.d.ts +3 -2
  123. package/dist/workspace/intent-cli.d.ts.map +1 -1
  124. package/dist/workspace/intent-cli.js +26 -5
  125. package/dist/workspace/intent-record.d.ts +3 -0
  126. package/dist/workspace/intent-record.d.ts.map +1 -1
  127. package/dist/workspace/intent-record.schema.json +32 -0
  128. package/dist/workspace/intent.d.ts +9 -0
  129. package/dist/workspace/intent.d.ts.map +1 -1
  130. package/dist/workspace/intent.js +3 -0
  131. package/dist/workspace/intent.schema.json +32 -0
  132. package/dist/workspace/kind-readers.d.ts.map +1 -1
  133. package/dist/workspace/kind-readers.js +2 -1
  134. package/dist/workspace/kinds.d.ts +6 -1
  135. package/dist/workspace/kinds.d.ts.map +1 -1
  136. package/dist/workspace/kinds.js +8 -3
  137. package/dist/workspace/plan-stale.schema.json +286 -0
  138. package/dist/workspace/release-candidates.d.ts +33 -6
  139. package/dist/workspace/release-candidates.d.ts.map +1 -1
  140. package/dist/workspace/release-candidates.js +49 -20
  141. package/dist/workspace/release-candidates.schema.json +48 -2
  142. package/dist/workspace/trust/policy.d.ts +10 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +19 -1
  145. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  146. package/dist/workspace/trust/run-commits.js +2 -1
  147. package/dist/workspace/trust/seal.d.ts.map +1 -1
  148. package/dist/workspace/trust/seal.js +34 -3
  149. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  150. package/dist/workspace/trust/trust-files.js +6 -1
  151. package/package.json +2 -1
  152. package/src/cli/handlers/approve-external-signature.test.ts +226 -0
  153. package/src/cli/handlers/approve.ts +174 -16
  154. package/src/cli/handlers/plan.ts +74 -0
  155. package/src/cli/handlers/release.ts +12 -7
  156. package/src/cli/main.ts +34 -5
  157. package/src/cli/mcp/workspace-tools.ts +2 -1
  158. package/src/cli/parse-args.ts +24 -0
  159. package/src/cli/registry.ts +13 -1
  160. package/src/gate-decision-bundle.test.ts +4 -2
  161. package/src/gate-decision.ts +11 -2
  162. package/src/gate-statement.schema.json +44 -0
  163. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  164. package/src/lifecycle/gate-ledger.ts +17 -3
  165. package/src/lifecycle/gate-seal.ts +62 -9
  166. package/src/lifecycle/gate-statement.ts +107 -0
  167. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  168. package/src/lifecycle/gate-webauthn.ts +133 -0
  169. package/src/lifecycle/git.ts +23 -19
  170. package/src/lifecycle/ledger-remote.test.ts +183 -0
  171. package/src/lifecycle/ledger-remote.ts +46 -0
  172. package/src/lifecycle/plan-stale.test.ts +150 -0
  173. package/src/lifecycle/plan-stale.ts +173 -0
  174. package/src/lifecycle/publish-credentials.ts +2 -0
  175. package/src/lifecycle/publish-declaration.ts +93 -1
  176. package/src/lifecycle/publish-forge.ts +15 -4
  177. package/src/lifecycle/publish-github.ts +174 -0
  178. package/src/lifecycle/publish-homebrew.test.ts +179 -0
  179. package/src/lifecycle/publish-homebrew.ts +187 -0
  180. package/src/lifecycle/publish-marketplace.test.ts +254 -0
  181. package/src/lifecycle/publish-marketplace.ts +259 -0
  182. package/src/lifecycle/publish-target-context.test.ts +2 -2
  183. package/src/lifecycle/publish-targets.test.ts +23 -0
  184. package/src/lifecycle/publish-targets.ts +15 -0
  185. package/src/lifecycle/publish-tauri.test.ts +163 -0
  186. package/src/lifecycle/publish-tauri.ts +199 -0
  187. package/src/lifecycle/release-publish.ts +5 -3
  188. package/src/lifecycle/snapshot-store.ts +16 -9
  189. package/src/lifecycle/test-passkey.ts +55 -0
  190. package/src/notify-bundle.test.ts +3 -1
  191. package/src/notify.schema.json +12 -3
  192. package/src/notify.ts +20 -3
  193. package/src/override-gate-bundle.test.ts +2 -0
  194. package/src/pr-forge-bundle.test.ts +2 -2
  195. package/src/pr-forge.test.ts +38 -0
  196. package/src/pr-forge.ts +68 -5
  197. package/src/release-floors.ts +1 -1
  198. package/src/stage-hooks-bundle.test.ts +2 -0
  199. package/src/wave-runtime-bundle.test.ts +3 -2
  200. package/src/workspace/ci-builds.ts +27 -0
  201. package/src/workspace/ci-green-stale.test.ts +193 -0
  202. package/src/workspace/ci-green-workflow.test.ts +9 -0
  203. package/src/workspace/ci-green-workflow.ts +9 -0
  204. package/src/workspace/ci-green.ts +141 -10
  205. package/src/workspace/ci-quarantine-report.test.ts +146 -0
  206. package/src/workspace/ci-quarantine-report.ts +235 -0
  207. package/src/workspace/ci-quarantine.test.ts +161 -0
  208. package/src/workspace/ci-quarantine.ts +189 -0
  209. package/src/workspace/ci-serve.ts +7 -4
  210. package/src/workspace/class-data.ts +5 -1
  211. package/src/workspace/declaration.schema.json +51 -3
  212. package/src/workspace/declaration.test.ts +1 -0
  213. package/src/workspace/declaration.ts +88 -5
  214. package/src/workspace/forge-work.test.ts +143 -0
  215. package/src/workspace/forge-work.ts +195 -0
  216. package/src/workspace/identity-gate-rule.ts +6 -8
  217. package/src/workspace/identity.ts +6 -3
  218. package/src/workspace/intent-cli.ts +24 -5
  219. package/src/workspace/intent-record.schema.json +32 -0
  220. package/src/workspace/intent-record.ts +3 -0
  221. package/src/workspace/intent.schema.json +32 -0
  222. package/src/workspace/intent.ts +10 -0
  223. package/src/workspace/kind-readers.ts +2 -1
  224. package/src/workspace/kinds.test.ts +13 -0
  225. package/src/workspace/kinds.ts +12 -3
  226. package/src/workspace/plan-stale.schema.json +286 -0
  227. package/src/workspace/release-candidates.schema.json +48 -2
  228. package/src/workspace/release-candidates.test.ts +77 -4
  229. package/src/workspace/release-candidates.ts +62 -20
  230. package/src/workspace/trust/policy.ts +24 -1
  231. package/src/workspace/trust/run-commits.ts +2 -1
  232. package/src/workspace/trust/seal.ts +35 -3
  233. package/src/workspace/trust/trust-files.test.ts +5 -0
  234. package/src/workspace/trust/trust-files.ts +15 -1
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Work items from the forge (#4649): the issues a squash-merged pull request
3
+ * closes.
4
+ *
5
+ * A project that squash-merges pull requests and tracks its work in forge
6
+ * issues writes no `Chant-Record` trailer. Its commit subjects end in
7
+ * `(#<n>)`, the pull request, and the pull request closes issues. Asked to
8
+ * (`--forge-issues`), `release candidates` and `workspace graph --intent` ask
9
+ * the forge which issues each pull request closes, through the forge clients
10
+ * of `../pr-forge.ts` ({@link PrForge.closingIssues}): one call per pull
11
+ * request, each answer kept for the rest of the read.
12
+ *
13
+ * The forge is the CI job's when the read runs in one ({@link detectForge}),
14
+ * else the one `origin` points at: github.com and hosts named for GitHub,
15
+ * hosts named for GitLab, and codeberg.org and hosts named for Forgejo or
16
+ * Gitea. The token is read in {@link FORGE_TOKEN_ORDER}, with
17
+ * `CHANT_FORGE_TOKEN` first, and on GitHub `gh auth token` for the host last.
18
+ *
19
+ * Nothing here fails a read. Without a forge or a token, offline, or when the
20
+ * forge answers an error, a pull request is `resolved: false` with the
21
+ * reason, and its number still stands. After a network failure, a 401 or a
22
+ * 403, the rest are answered with the same reason without another call.
23
+ */
24
+
25
+ import { execFileSync } from "node:child_process";
26
+ import { remoteRepoPath } from "../op/activities/forge-pull-request";
27
+ import { remoteHost } from "../op/activities/gh-host";
28
+ import { detectForge, FORGE_TOKEN_ORDER, ForgeApiError, forgeClient, forgeTargetFromEnv, type ForgeFetch, type ForgeKind, type ForgeTarget, type PrForge } from "../pr-forge";
29
+
30
+ /** What the forge says one pull request closes. */
31
+ export interface PullRequestCloses {
32
+ /** Whether the forge answered. When false, `issues` is empty and `reason` says why. */
33
+ resolved: boolean;
34
+ /** The issues of the repository the pull request closes, ascending. */
35
+ issues: number[];
36
+ /** Why the forge was not read, or null when it was. */
37
+ reason: string | null;
38
+ }
39
+
40
+ /** The forge a {@link ForgeWorkReader} reads, as the read found it. */
41
+ export interface ForgeWorkSource {
42
+ kind: ForgeKind;
43
+ host: string;
44
+ /** `owner/name`, or the GitLab project path. */
45
+ repo: string;
46
+ }
47
+
48
+ export interface ForgeWorkReader {
49
+ /** The forge read, or null when none could be worked out. */
50
+ source: ForgeWorkSource | null;
51
+ /** What pull request `pr` closes. Asked twice, the forge is called once. */
52
+ closes(pr: number): Promise<PullRequestCloses>;
53
+ /** {@link closes} for each of `prs`, a few at a time. */
54
+ closesAll(prs: Iterable<number>): Promise<Map<number, PullRequestCloses>>;
55
+ }
56
+
57
+ export interface ForgeWorkOptions {
58
+ /** Default `process.env`. */
59
+ env?: Record<string, string | undefined>;
60
+ fetch?: ForgeFetch;
61
+ /** `origin`'s URL. Default `git remote get-url origin` in `top`; null for none. */
62
+ remoteUrl?: string | null;
63
+ /** The token `gh` holds for a GitHub host, or undefined. Default `gh auth token --hostname <host>`. */
64
+ ghToken?: (host: string) => string | undefined;
65
+ /** How long one call may take. Default 15 seconds. */
66
+ timeoutMs?: number;
67
+ }
68
+
69
+ /** How many pull requests are asked about at once. */
70
+ const CONCURRENCY = 4;
71
+
72
+ function gitRemote(top: string): string | null {
73
+ try {
74
+ return execFileSync("git", ["remote", "get-url", "origin"], { cwd: top, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim() || null;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ function ghAuthToken(host: string): string | undefined {
81
+ try {
82
+ return execFileSync("gh", ["auth", "token", "--hostname", host], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 5_000 }).trim() || undefined;
83
+ } catch {
84
+ return undefined;
85
+ }
86
+ }
87
+
88
+ /** The forge kind a remote host is: github.com and hosts named for GitHub, GitLab, or Forgejo and Gitea (codeberg.org too). Null for any other. */
89
+ export function forgeKindOfHost(host: string): ForgeKind | null {
90
+ const h = host.toLowerCase().replace(/:\d+$/, "");
91
+ if (h === "github.com" || /(^|[.-])github([.-]|$)/.test(h)) return "github";
92
+ if (h === "gitlab.com" || /(^|[.-])gitlab([.-]|$)/.test(h)) return "gitlab";
93
+ if (h === "codeberg.org" || /(^|[.-])(forgejo|gitea)([.-]|$)/.test(h)) return "forgejo";
94
+ return null;
95
+ }
96
+
97
+ /** The REST base of a forge at `host`, as the clients take it. */
98
+ export function forgeApiBase(kind: ForgeKind, host: string): string {
99
+ if (kind === "github") return host === "github.com" ? "https://api.github.com" : `https://${host}/api/v3`;
100
+ return kind === "gitlab" ? `https://${host}/api/v4` : `https://${host}/api/v1`;
101
+ }
102
+
103
+ /** Where the issues are read from, or why they can't be. */
104
+ function locate(top: string, opts: ForgeWorkOptions): { target: ForgeTarget } | { source: ForgeWorkSource | null; reason: string } {
105
+ const env = opts.env ?? process.env;
106
+ const job = detectForge(env);
107
+ if (job) {
108
+ try {
109
+ return { target: forgeTargetFromEnv(env, { kind: job }) };
110
+ } catch (err) {
111
+ return { source: null, reason: err instanceof Error ? err.message : String(err) };
112
+ }
113
+ }
114
+ const url = opts.remoteUrl !== undefined ? opts.remoteUrl : gitRemote(top);
115
+ if (!url) return { source: null, reason: "there is no origin remote to name the forge" };
116
+ const host = remoteHost(url);
117
+ const repo = remoteRepoPath(url);
118
+ const kind = host ? forgeKindOfHost(host) : null;
119
+ if (!host || !repo || !kind) return { source: null, reason: `origin (${url}) is not on a forge chant reads issues from: GitHub, GitLab or Forgejo` };
120
+ const source = { kind, host, repo };
121
+ const names = ["CHANT_FORGE_TOKEN", ...FORGE_TOKEN_ORDER[kind]];
122
+ const tokenSource = names.find((n) => env[n]?.trim());
123
+ const token = tokenSource ? env[tokenSource]!.trim() : kind === "github" ? (opts.ghToken ?? ghAuthToken)(host) : undefined;
124
+ if (!token) return { source, reason: `no token for ${host}: set ${names.join(", ")}${kind === "github" ? ", or log in with gh auth login" : ""}` };
125
+ return { target: { kind, apiBase: forgeApiBase(kind, host), repo, host, token, tokenSource: tokenSource ?? "gh auth token" } };
126
+ }
127
+
128
+ /** Why a failed call stops the rest: the forge can't be reached, or won't let this token read. */
129
+ function stopsTheRest(err: unknown): boolean {
130
+ return !(err instanceof ForgeApiError) || err.status === 401 || err.status === 403;
131
+ }
132
+
133
+ /** A reader of what pull requests close, for the repository at `top`. */
134
+ export function forgeWorkReader(top: string, opts: ForgeWorkOptions = {}): ForgeWorkReader {
135
+ const where = locate(top, opts);
136
+ const cache = new Map<number, Promise<PullRequestCloses>>();
137
+ let stopped: string | null = "reason" in where ? where.reason : null;
138
+ const client: PrForge | null = "target" in where ? forgeClient(where.target, opts.fetch) : null;
139
+ const source: ForgeWorkSource | null = "target" in where ? { kind: where.target.kind, host: where.target.host, repo: where.target.repo } : where.source;
140
+ const timeoutMs = opts.timeoutMs ?? 15_000;
141
+ const unresolved = (reason: string): PullRequestCloses => ({ resolved: false, issues: [], reason });
142
+
143
+ const ask = async (pr: number): Promise<PullRequestCloses> => {
144
+ if (stopped !== null) return unresolved(stopped);
145
+ if (!client?.closingIssues) return unresolved(`the ${source?.kind ?? "forge"} client can't list the issues a pull request closes`);
146
+ let timer: ReturnType<typeof setTimeout> | undefined;
147
+ try {
148
+ const timeout = new Promise<never>((_, reject) => {
149
+ timer = setTimeout(() => reject(new Error(`no answer in ${timeoutMs / 1000}s`)), timeoutMs);
150
+ });
151
+ const issues = await Promise.race([client.closingIssues(pr), timeout]);
152
+ return { resolved: true, issues, reason: null };
153
+ } catch (err) {
154
+ const message = `${source?.host ?? "the forge"} could not be read: ${err instanceof Error ? err.message : String(err)}`;
155
+ if (stopsTheRest(err)) stopped = message;
156
+ return unresolved(message);
157
+ } finally {
158
+ clearTimeout(timer);
159
+ }
160
+ };
161
+
162
+ const closes = (pr: number): Promise<PullRequestCloses> => {
163
+ let hit = cache.get(pr);
164
+ if (!hit) {
165
+ hit = ask(pr);
166
+ cache.set(pr, hit);
167
+ }
168
+ return hit;
169
+ };
170
+
171
+ return {
172
+ source,
173
+ closes,
174
+ async closesAll(prs) {
175
+ const queue = [...new Set(prs)];
176
+ const out = new Map<number, PullRequestCloses>();
177
+ const worker = async (): Promise<void> => {
178
+ for (let pr = queue.shift(); pr !== undefined; pr = queue.shift()) out.set(pr, await closes(pr));
179
+ };
180
+ await Promise.all(Array.from({ length: Math.min(CONCURRENCY, queue.length) }, worker));
181
+ return out;
182
+ },
183
+ };
184
+ }
185
+
186
+ /**
187
+ * Set `closes` on each commit from what its `pullRequest` closes, asking the
188
+ * forge once per pull request; null for a commit with none. For
189
+ * `workspace graph --intent --forge-issues`, over the graph's commit nodes or
190
+ * a record walk's commits.
191
+ */
192
+ export async function setCommitCloses(commits: { pullRequest: number | null; closes?: PullRequestCloses | null }[], reader: ForgeWorkReader): Promise<void> {
193
+ const closed = await reader.closesAll(commits.map((c) => c.pullRequest).filter((n): n is number => n !== null));
194
+ for (const c of commits) c.closes = c.pullRequest !== null ? (closed.get(c.pullRequest) ?? null) : null;
195
+ }
@@ -14,7 +14,7 @@
14
14
  * else: no zod, no ajv, no package loading, so it bundles small.
15
15
  */
16
16
 
17
- import { GATE_SEAL_NAMESPACE, gateSealPayload, namespaceAllowed, sshKeyFingerprint, sshSignatureKey, verifySshSignatureWith, type SealedGateApproval } from "../lifecycle/gate-seal";
17
+ import { checkGateSignature, gateSealPayload, namespaceAllowed, sshKeyFingerprint, sshSignatureKey, unlistedWhat, unlistedWhere, verifySshSignatureWith, type PasskeySigner, type SealedGateApproval } from "../lifecycle/gate-seal";
18
18
  import type { Signer } from "./trust/trust-files";
19
19
 
20
20
  /** The core classes, in the order a principal's roles are tried; `human` holds no role and is the rest. */
@@ -46,8 +46,8 @@ export interface GateAdmissionRule {
46
46
  gate: string;
47
47
  /** The class the approver must be in, or null for any signer. */
48
48
  class: string | null;
49
- /** The signers file at base: its path, whether it exists, and its signers. */
50
- signers: { signersPath: string; active: boolean; signers: readonly Signer[] };
49
+ /** The signers file at base: its path, whether it exists, and its signers, with the passkeys `.chant/trust.json` lists (#4646). */
50
+ signers: { signersPath: string; active: boolean; signers: readonly Signer[]; passkeys?: readonly PasskeySigner[] };
51
51
  /** The role grants at base (`.chant/trust.json` `roles`). */
52
52
  roles: Readonly<Record<string, readonly string[]>>;
53
53
  /** Every class the rule knows, core first, then domain classes in pin order. */
@@ -185,9 +185,7 @@ function sealRefusal(gate: string, signers: GateAdmissionRule["signers"], a: Sea
185
185
  }
186
186
  if (normalise(seal.signer) !== normalise(a.resolvedBy)) return `the seal on ${what} is by ${seal.signer}, and its approver is ${a.resolvedBy || "empty"}`;
187
187
  const where = `${signers.signersPath} at base`;
188
- const listed = signers.signers.filter((s) => normalise(s.principal) === normalise(a.resolvedBy));
189
- if (listed.length === 0) return `${a.resolvedBy} has no key in ${where}, so the seal can't count`;
190
- const keys = listed.filter((s) => namespaceAllowed(s.namespaces, GATE_SEAL_NAMESPACE)).map((s) => Buffer.from(s.key.split(" ")[1] ?? "", "base64"));
191
- const r = verifySshSignatureWith(seal.signature, gateSealPayload(a), GATE_SEAL_NAMESPACE, keys);
192
- return r.ok ? null : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
188
+ const r = checkGateSignature(signers, a.resolvedBy, seal as { signature: string }, gateSealPayload(a));
189
+ if (r.ok) return null;
190
+ return r.unlisted ? `${a.resolvedBy} has no ${unlistedWhat(seal)} in ${unlistedWhere(seal, where)}, so the seal can't count` : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
193
191
  }
@@ -6,8 +6,9 @@
6
6
  * it to chant's write commands (`--by`, `--actor`). chant records what it is
7
7
  * given and says which form it is:
8
8
  *
9
- * - `signer`: a principal `.chant/allowed_signers` lists at base. A seal made
10
- * with that principal's key (`--sign`) attests it.
9
+ * - `signer`: a principal `.chant/allowed_signers` lists at base, or one with
10
+ * a passkey in `.chant/trust.json` (#4646). A seal made with that
11
+ * principal's key (`--sign`) or passkey (`--signature`) attests it.
11
12
  * - `forge`: a forge identity, `github:<login>`, `gitlab:<login>`, or
12
13
  * `<forge>@<host>:<login>` (forgejo, gitea, or a self-hosted github or
13
14
  * gitlab). The surface that signed the person in vouches for it; nothing
@@ -90,7 +91,9 @@ const NON_PERSON_CLASSES = new Set(["agent", "runner", "service"]);
90
91
  export function identify(principal: string, policy: TrustPolicy, declaration: Declaration | null = null): Identified {
91
92
  const name = normalisePrincipal(principal);
92
93
  const forge = parseForgeIdentity(principal);
93
- if (policy.active && policy.signers.some((s) => normalisePrincipal(s.principal) === name)) return { principal, form: "signer", forge };
94
+ // #4646: a principal with a passkey at base signs like one with a key.
95
+ const listed = (s: { principal: string }) => normalisePrincipal(s.principal) === name;
96
+ if (policy.active && (policy.signers.some(listed) || (policy.passkeys ?? []).some(listed))) return { principal, form: "signer", forge };
94
97
  if (forge) return { principal, form: "forge", forge };
95
98
  const session = (declaration?.agents ?? []).some((a) => a.principals.some((p) => normalisePrincipal(p) === name));
96
99
  if (session || classesOf(coreClassRegistry(), policy, principal).some((c) => NON_PERSON_CLASSES.has(c))) return { principal, form: "role", forge: null };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--json]`
2
+ * `chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--forge-issues] [--json]`
3
3
  * (#2651, #3034): the intent graph over one region (`intent.ts`), printed as JSON
4
4
  * with `--json` or as a walk, one line per node, in the order of #2650
5
5
  * section B: the region, its decisions, their artifacts, the commits, and the
@@ -9,18 +9,33 @@
9
9
  * to the person about it (#2656). Without `--kind`, the walk reads every
10
10
  * record kind the declaration names (#2680). Last comes the why chain (#4023):
11
11
  * each commit's work item, ci tag and release, and each release's gates and
12
- * deploys.
12
+ * deploys. With `--forge-issues` (#4649), each commit with a pull request
13
+ * also carries the issues the forge says it closes (`./forge-work.ts`).
13
14
  */
14
15
 
15
16
  import { resolve } from "node:path";
16
17
  import { formatError } from "../cli/format";
17
18
  import type { CommandContext } from "../cli/registry";
19
+ import type { PullRequestCloses } from "./forge-work";
18
20
  import { intentRecord, type IntentRecordDocument } from "./intent-record";
19
21
  import type { IntentTrace, TraceGate } from "./intent-trace";
20
22
  import { intentGraph, type ArtifactNode, type CommitNode, type DecisionNode, type IntentDocument, type IntentEdge, type IntentNode, type RunNode, type WhyAnswer, type WorkNode } from "./intent";
21
23
 
22
- const USAGE = "chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--json]";
23
- const RECORD_USAGE = "chant workspace graph --intent --record <id> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--json]";
24
+ const USAGE = "chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--forge-issues] [--json]";
25
+ const RECORD_USAGE = "chant workspace graph --intent --record <id> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--forge-issues] [--json]";
26
+
27
+ /** With `--forge-issues` (#4649): set each commit's `closes` from the forge. */
28
+ async function withCloses(cwd: string, commits: { pullRequest: number | null; closes?: PullRequestCloses | null }[]): Promise<void> {
29
+ const { forgeWorkReader, setCommitCloses } = await import("./forge-work");
30
+ await setCommitCloses(commits, forgeWorkReader(cwd));
31
+ }
32
+
33
+ /** ` closes #1, #2`, ` (issues not read: why)`, or nothing, after a pull request in the text. */
34
+ function closesText(closes: PullRequestCloses | null | undefined): string {
35
+ if (!closes) return "";
36
+ if (!closes.resolved) return ` (issues not read: ${closes.reason})`;
37
+ return closes.issues.length > 0 ? ` closes ${closes.issues.map((n) => `#${n}`).join(", ")}` : "";
38
+ }
24
39
 
25
40
  type Result = Exclude<IntentDocument, { error: unknown }>;
26
41
  type RecordResult = Exclude<IntentRecordDocument, { error: unknown }>;
@@ -113,6 +128,7 @@ function commitLine(doc: Result, c: CommitNode): string[] {
113
128
  for (const s of edgesFrom(doc, e.to, "cites-evidence")) out.push(` evidence ${s.to.slice("evidence:".length)}`);
114
129
  }
115
130
  out.push(...joinLines(c.joins));
131
+ if (c.closes && c.pullRequest !== null) out.push(` pr #${c.pullRequest}${closesText(c.closes)}`);
116
132
  if (c.squash) {
117
133
  const s = c.squash;
118
134
  out.push(` squash #${s.pullRequest}${s.followed ? `: ${s.commits.length} original ${s.commits.length === 1 ? "commit" : "commits"} from ${s.ref}${s.fetched ? ", fetched" : ""}` : ", not followed"}`);
@@ -254,7 +270,8 @@ export function formatIntentRecord(doc: RecordResult): string {
254
270
  : "nothing else accounts for it";
255
271
  const runs = (c.runs ?? []).map((r) => `run ${r.id}${r.model ? ` (${r.model})` : ""}${r.joinedBy?.includes("squash") && !r.joinedBy.some((j) => j !== "squash") ? " through the squash" : ""}`).join(", ");
256
272
  const squash = c.squash ? `; squash of #${c.squash.pullRequest}${c.squash.followed ? `, ${c.squash.commits.length} original ${c.squash.commits.length === 1 ? "commit" : "commits"}` : ", not followed"}` : "";
257
- out.push(`${c.bucket.padEnd(12)} ${short(c.sha)} ${c.date.slice(0, 10)} ${c.subject}; ${why}${runs ? `; ${runs}` : ""}${squash}; ${c.files.join(", ") || c.entries.join(", ")}`);
273
+ const pr = c.closes && c.pullRequest !== null ? `; #${c.pullRequest}${closesText(c.closes)}` : "";
274
+ out.push(`${c.bucket.padEnd(12)} ${short(c.sha)} ${c.date.slice(0, 10)} ${c.subject}; ${why}${runs ? `; ${runs}` : ""}${squash}${pr}; ${c.files.join(", ") || c.entries.join(", ")}`);
258
275
  }
259
276
  for (const x of doc.reasons) out.push(`reason ${x.code}: ${x.message}`);
260
277
  const n = doc.counts;
@@ -265,6 +282,7 @@ export function formatIntentRecord(doc: RecordResult): string {
265
282
  async function runRecord(ctx: CommandContext, cwd: string, kinds: string[] | undefined): Promise<number> {
266
283
  const { args } = ctx;
267
284
  const { doc, failed } = await intentRecord({ cwd, record: args.record!, at: args.at, kinds: kinds?.map((k) => resolve(k)), followSquash: args.followSquash });
285
+ if (args.forgeIssues && !("error" in doc)) await withCloses(cwd, doc.commits);
268
286
  if (args.json) console.log(JSON.stringify(doc, null, 2));
269
287
  if ("error" in doc) {
270
288
  console.error(formatError({ message: `${doc.error.code}: ${doc.error.message}`, hint: RECORD_USAGE }));
@@ -290,6 +308,7 @@ export async function runWorkspaceIntent(ctx: CommandContext, cwd: string): Prom
290
308
  // No --kind: undefined, so the walk reads the kinds the declaration names (#2680).
291
309
  const kinds = args.kinds ?? (args.kind !== undefined ? [args.kind] : undefined);
292
310
  const { doc, failed } = await intentGraph({ cwd, region: args.intent, at: args.at, kinds: kinds?.map((k) => resolve(k)), followSquash: args.followSquash });
311
+ if (args.forgeIssues && !("error" in doc)) await withCloses(cwd, ofKind(doc, "commit"));
293
312
  if (args.json) console.log(JSON.stringify(doc, null, 2));
294
313
  if ("error" in doc) {
295
314
  console.error(formatError({ message: `${doc.error.code}: ${doc.error.message}`, hint: USAGE }));
@@ -359,6 +359,38 @@
359
359
  ],
360
360
  "description": "The number in a (#n) that ends the subject, as a squash merge writes it, or null."
361
361
  },
362
+ "closes": {
363
+ "type": [
364
+ "object",
365
+ "null"
366
+ ],
367
+ "required": [
368
+ "resolved",
369
+ "issues",
370
+ "reason"
371
+ ],
372
+ "properties": {
373
+ "resolved": {
374
+ "type": "boolean",
375
+ "description": "Whether the forge answered. False without a forge chant reads, without a token, offline, or when the forge answered an error."
376
+ },
377
+ "issues": {
378
+ "type": "array",
379
+ "items": {
380
+ "type": "integer"
381
+ },
382
+ "description": "The issues of the repository the pull request closes, ascending. Empty when not resolved."
383
+ },
384
+ "reason": {
385
+ "type": [
386
+ "string",
387
+ "null"
388
+ ],
389
+ "description": "Why the forge was not read, or null when it was."
390
+ }
391
+ },
392
+ "description": "Only with --forge-issues (#4649): what the forge says pullRequest closes, or null for a commit with no pull request. Added within version 1 by chant 0.124.63."
393
+ },
362
394
  "unit": {
363
395
  "type": [
364
396
  "string",
@@ -60,6 +60,7 @@ import type { RecordView } from "./records-cli";
60
60
  import { addSquashRuns, runsForCommits, type RunRef } from "./runs";
61
61
  import { followSquashes, type Forge, type SquashFollow } from "./squash";
62
62
  import { readTrailerJoins, type CommitTrailerJoins } from "./trailer-joins";
63
+ import type { PullRequestCloses } from "./forge-work";
63
64
  import { joinPath } from "./tree";
64
65
  import { locateWorkspace } from "./which-chant";
65
66
  import { idList } from "./work";
@@ -97,6 +98,8 @@ export interface RecordCommit {
97
98
  date: string;
98
99
  trailers: Record<string, string[]>;
99
100
  pullRequest: number | null;
101
+ /** What the forge says `pullRequest` closes (#4649), only with `--forge-issues`: null for a commit with no pull request. */
102
+ closes?: PullRequestCloses | null;
100
103
  /** The unit a plugin joined the commit to, or null. */
101
104
  unit: string | null;
102
105
  /** What chant's own trailers join the commit to (#3149), as a commit node in `graph --intent` reports it. */
@@ -484,6 +484,38 @@
484
484
  ],
485
485
  "description": "The number in a (#n) that ends the subject, as a squash merge writes it, or null."
486
486
  },
487
+ "closes": {
488
+ "type": [
489
+ "object",
490
+ "null"
491
+ ],
492
+ "required": [
493
+ "resolved",
494
+ "issues",
495
+ "reason"
496
+ ],
497
+ "properties": {
498
+ "resolved": {
499
+ "type": "boolean",
500
+ "description": "Whether the forge answered. False without a forge chant reads, without a token, offline, or when the forge answered an error."
501
+ },
502
+ "issues": {
503
+ "type": "array",
504
+ "items": {
505
+ "type": "integer"
506
+ },
507
+ "description": "The issues of the repository the pull request closes, ascending. Empty when not resolved."
508
+ },
509
+ "reason": {
510
+ "type": [
511
+ "string",
512
+ "null"
513
+ ],
514
+ "description": "Why the forge was not read, or null when it was."
515
+ }
516
+ },
517
+ "description": "Only with --forge-issues (#4649): what the forge says pullRequest closes, or null for a commit with no pull request. Added within version 1 by chant 0.124.63."
518
+ },
487
519
  "signature": {
488
520
  "type": "object",
489
521
  "required": [
@@ -60,6 +60,8 @@
60
60
  import { execFileSync } from "node:child_process";
61
61
  import { realpathSync } from "node:fs";
62
62
  import { basename, dirname, relative, resolve, sep } from "node:path";
63
+ import { NEXT_RELEASE } from "../release-floors";
64
+ import type { PullRequestCloses } from "./forge-work";
63
65
  import { declaredRecordKinds, readDeclaration, readerVersion, resolveGroups, WORKSPACE_ERROR_CODES, WorkspaceReadError, type Declaration } from "./declaration";
64
66
  import { declaredKindFile } from "./declared-kinds";
65
67
  import { isGeneratedPath } from "./generated-files";
@@ -88,6 +90,8 @@ import { idList, isDecided, WORK_WARNING_CODES, type WorkLink, type WorkWarningC
88
90
 
89
91
  /** The version of the `intent` document this chant writes. */
90
92
  export const INTENT_CONTRACT_VERSION = 1;
93
+ /** The first chant whose intent graph and record walk carry a commit's `closes`, with `--forge-issues` (#4649). */
94
+ export const INTENT_CLOSES_FLOOR = NEXT_RELEASE;
91
95
 
92
96
  /** `$id` of the JSON Schema for the document, shipped beside this file. */
93
97
  export const INTENT_OUTPUT_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/intent/v1/intent.schema.json";
@@ -245,6 +249,12 @@ export interface CommitNode {
245
249
  trailers: Record<string, string[]>;
246
250
  /** The pull request number the subject ends with, as a squash merge writes it, or null. */
247
251
  pullRequest: number | null;
252
+ /**
253
+ * What the forge says `pullRequest` closes (#4649), only with
254
+ * `--forge-issues`: null for a commit with no pull request. Added within
255
+ * contract 1 by chant {@link INTENT_CLOSES_FLOOR}.
256
+ */
257
+ closes?: PullRequestCloses | null;
248
258
  signature: { level: ProvenanceLevel; reason: string; principal?: string };
249
259
  /** The line ranges the commit changed in the region, in the commit's own version of the file; null for a file or directory region. */
250
260
  lines: LineRange[] | null;
@@ -35,6 +35,7 @@
35
35
  import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
36
36
  import { tmpdir } from "node:os";
37
37
  import { join } from "node:path";
38
+ import { CHANT_INSTALL } from "./class-data";
38
39
  import { findInstalledPackage, lexiconPackageName, substituteGraphConfig } from "./kinds";
39
40
  import type { MemberPlan, RunUnit, SkippedEntry } from "./member-commands";
40
41
 
@@ -65,7 +66,7 @@ function lexiconModules(unit: RunUnit, root: string): { modules: string } | { me
65
66
  const reader = unit.reader!;
66
67
  if (!reader.lexicon) return { message: `kind ${unit.kind} names no lexicon` };
67
68
  const name = lexiconPackageName(reader.lexicon);
68
- const installed = findInstalledPackage(name, root);
69
+ const installed = findInstalledPackage(name, root) ?? findInstalledPackage(name, CHANT_INSTALL);
69
70
  if (!installed) {
70
71
  return {
71
72
  message: `kind ${unit.kind} is read by the ${reader.lexicon} lexicon, and ${name} is not installed in a node_modules at or above ${root}; install it there to read this member`,
@@ -14,6 +14,7 @@ import {
14
14
  kindsFileShips,
15
15
  loadKindRegistry,
16
16
  parseKindData,
17
+ pinnedPackageDir,
17
18
  probeKind,
18
19
  readPackageKinds,
19
20
  resolveKind,
@@ -259,6 +260,18 @@ describe("loadKindRegistry: kinds from the pins", () => {
259
260
  expect(existsSync(join(root, "node_modules/plain/IMPORTED"))).toBe(false);
260
261
  });
261
262
 
263
+ test("a pin the checkout does not hold is found beside chant's own install, at the pinned version", () => {
264
+ const checkout = dir({});
265
+ const install = dir(pkg("tf-kinds", "1.0.0", [tf]));
266
+ expect(pinnedPackageDir({ package: "tf-kinds", version: "1.0.0", path: null }, checkout, install)).toEqual({
267
+ dir: join(install, "node_modules/tf-kinds"),
268
+ source: "tf-kinds",
269
+ });
270
+ expect(pinnedPackageDir({ package: "tf-kinds", version: "2.0.0", path: null }, checkout, install)).toEqual({
271
+ problem: expect.stringContaining("tf-kinds is pinned at 2.0.0"),
272
+ });
273
+ });
274
+
262
275
  test("reads a local plugin by path, and leaves out a kind two sources both supply", () => {
263
276
  const root = dir({
264
277
  "plugins/tf/package.json": JSON.stringify({ name: "tf", exports: { "./workspace-kinds": "./k.json" } }),
@@ -23,7 +23,7 @@ import schema from "./workspace-kinds.schema.json" with { type: "json" };
23
23
  import type { WorkspaceTree } from "./tree";
24
24
  import { joinPath, skippedDir } from "./tree";
25
25
  import { checkPinIntegrity } from "./pin-integrity";
26
- import { dataExportTarget, findInstalledPackage } from "./class-data";
26
+ import { CHANT_INSTALL, dataExportTarget, findInstalledPackage } from "./class-data";
27
27
  import { loadAjv2020 } from "./ajv2020";
28
28
  import yaml from "js-yaml";
29
29
 
@@ -747,10 +747,19 @@ export interface LoadedKinds {
747
747
  * directory, checked against its integrity digest when it has one. Null for
748
748
  * a pin that names neither. Shared by the kinds and the principal classes
749
749
  * (#3080), so both read a pin the same way.
750
+ *
751
+ * A package the checkout does not hold is looked up from `beside`, this chant's
752
+ * own install (plywood#54): a product's image carries chant and the pinned
753
+ * package together, and a checkout needs no copy of its own. The version check
754
+ * below still applies.
750
755
  */
751
- export function pinnedPackageDir(pin: PinLike, workspaceRoot: string): { dir: string; source: string } | { problem: string } | null {
756
+ export function pinnedPackageDir(
757
+ pin: PinLike,
758
+ workspaceRoot: string,
759
+ beside: string = CHANT_INSTALL,
760
+ ): { dir: string; source: string } | { problem: string } | null {
752
761
  if (pin.package) {
753
- const dir = findInstalledPackage(pin.package, workspaceRoot);
762
+ const dir = findInstalledPackage(pin.package, workspaceRoot) ?? findInstalledPackage(pin.package, beside);
754
763
  if (!dir) return { problem: `pinned package ${pin.package} is not installed; install it to read the kinds it supplies` };
755
764
  let installed: unknown;
756
765
  try {