@venizia/vulcan 0.4.10-2 → 0.4.10-21

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 (208) hide show
  1. package/README.md +30 -23
  2. package/base/checks/wiki-source-links.ts +17 -1
  3. package/base/claude/events.json +1 -11
  4. package/base/claude/settings.json +5 -76
  5. package/base/extensions/vulcan-guards.ts +81 -18
  6. package/base/hooks/guard-git.ts +95 -19
  7. package/base/hooks/guard-outside.ts +163 -43
  8. package/base/hooks/guard-writes.ts +15 -36
  9. package/base/hooks/session-start.ts +1 -1
  10. package/base/make/vulcan.mk +8 -5
  11. package/base/packs/venizia.md +16 -0
  12. package/base/references/delegation-brief.md +3 -5
  13. package/base/references/testing.md +1 -9
  14. package/base/rules.md +33 -38
  15. package/base/skills/build-a-feature/SKILL.md +4 -4
  16. package/base/skills/docs-update/SKILL.md +19 -8
  17. package/base/skills/fix-a-bug/SKILL.md +4 -2
  18. package/base/skills/plan-a-change/SKILL.md +1 -1
  19. package/base/skills/research/SKILL.md +1 -1
  20. package/base/skills/retro/SKILL.md +2 -2
  21. package/base/skills/review-a-change/SKILL.md +1 -1
  22. package/base/skills/visualize-work/SKILL.md +3 -3
  23. package/base/skills/visualize-work/references/spec.md +6 -3
  24. package/base/templates/AGENTS.md +9 -7
  25. package/base/templates/board.html +10 -110
  26. package/package.json +3 -3
  27. package/src/agents/atlas-block.ts +8 -31
  28. package/src/agents/codex-hooks.ts +1 -1
  29. package/src/agents/generated-block.ts +52 -0
  30. package/src/agents/hooks-json.ts +22 -3
  31. package/src/agents/index.ts +2 -0
  32. package/src/agents/render.ts +15 -2
  33. package/src/agents/resolve.ts +1 -0
  34. package/src/agents/rules-block.ts +92 -0
  35. package/src/board/command.ts +92 -30
  36. package/src/board/common/constants.ts +26 -0
  37. package/src/board/common/types.ts +10 -3
  38. package/src/board/fold.ts +1 -1
  39. package/src/board/github.ts +1 -2
  40. package/src/board/gitlab.ts +436 -0
  41. package/src/board/index.ts +1 -0
  42. package/src/board/logo.ts +49 -0
  43. package/src/board/open-file.ts +110 -0
  44. package/src/board/page.ts +57 -5
  45. package/src/board/schema.ts +4 -1
  46. package/src/board/server.ts +87 -3
  47. package/src/board/settings.ts +21 -24
  48. package/src/commands/changelog.command.ts +40 -0
  49. package/src/commands/clean.command.ts +6 -1
  50. package/src/commands/help.command.ts +2 -63
  51. package/src/commands/index.ts +6 -1
  52. package/src/commands/migrate.command.ts +71 -0
  53. package/src/commands/profile.command.ts +1 -1
  54. package/src/commands/runners.command.ts +43 -0
  55. package/src/commands/sync.command.ts +8 -4
  56. package/src/commands/table.ts +362 -0
  57. package/src/commit/check.ts +1 -0
  58. package/src/commit/common/constants.ts +4 -0
  59. package/src/commit/hook.ts +112 -8
  60. package/src/common/constants.ts +11 -9
  61. package/src/common/env-variables.ts +41 -0
  62. package/src/common/index.ts +1 -0
  63. package/src/common/layout-folder.ts +3 -4
  64. package/src/common/record.ts +5 -0
  65. package/src/config/common/constants.ts +28 -22
  66. package/src/config/loader.ts +22 -0
  67. package/src/config/schema.ts +330 -146
  68. package/src/create/add-app.ts +7 -2
  69. package/src/create/add-lib.ts +2 -4
  70. package/src/create/common/constants.ts +5 -3
  71. package/src/create/preset.ts +1 -0
  72. package/src/create/scratch.ts +2 -1
  73. package/src/doctor/checks.ts +277 -448
  74. package/src/doctor/common/constants.ts +27 -19
  75. package/src/doctor/private-values.ts +4 -1
  76. package/src/doctor/runner.ts +5 -12
  77. package/src/doctor/schema.ts +4 -0
  78. package/src/events/common/actor-names.ts +12 -0
  79. package/src/events/common/constants.ts +65 -38
  80. package/src/events/common/index.ts +1 -0
  81. package/src/events/hook.ts +5 -56
  82. package/src/events/text.ts +41 -6
  83. package/src/hooks/command-view.ts +80 -19
  84. package/src/hooks/common/constants.ts +26 -17
  85. package/src/hooks/common/types.ts +13 -24
  86. package/src/hooks/decision.ts +30 -12
  87. package/src/hooks/git-queries.ts +113 -0
  88. package/src/hooks/guard-git.ts +76 -24
  89. package/src/hooks/guard-outside.ts +334 -311
  90. package/src/hooks/guard-runner.ts +206 -0
  91. package/src/hooks/guard-writes.ts +87 -184
  92. package/src/hooks/hook-input.ts +57 -0
  93. package/src/hooks/index.ts +3 -6
  94. package/src/hooks/link-makers.ts +315 -0
  95. package/src/hooks/package-runners.ts +268 -0
  96. package/src/hooks/project-guards.ts +81 -44
  97. package/src/hooks/project-tmp.ts +39 -4
  98. package/src/hooks/runner-scan.ts +257 -0
  99. package/src/hooks/script-runners.ts +400 -0
  100. package/src/hooks/session-digest.ts +27 -117
  101. package/src/hooks/shell-folders.ts +760 -0
  102. package/src/hooks/shell-writes.ts +646 -0
  103. package/src/hooks/shell.ts +1421 -194
  104. package/src/hooks/subagent-card.ts +2 -2
  105. package/src/hooks/write-commands.ts +898 -0
  106. package/src/init/scaffold.ts +2 -3
  107. package/src/local/auto-clean.ts +2 -1
  108. package/src/local/browser-socket.ts +33 -0
  109. package/src/local/clean.ts +37 -6
  110. package/src/local/constants.ts +15 -1
  111. package/src/local/index.ts +1 -0
  112. package/src/local/scan.ts +41 -10
  113. package/src/manifest/render.ts +84 -30
  114. package/src/owner/constants.ts +4 -5
  115. package/src/owner/index.ts +0 -2
  116. package/src/owner/profile.ts +1 -0
  117. package/src/owner/schema.ts +51 -27
  118. package/src/owner/survey.ts +0 -3
  119. package/src/owner/view.ts +0 -9
  120. package/src/router.ts +8 -132
  121. package/src/rules/base.ts +12 -7
  122. package/src/rules/index.ts +1 -0
  123. package/src/rules/packs.ts +44 -0
  124. package/src/runners/check.ts +130 -0
  125. package/src/skills/frontmatter.ts +1 -0
  126. package/src/sync/agents-block.ts +104 -0
  127. package/src/sync/base-rules.ts +3 -3
  128. package/src/sync/claude-launch.ts +12 -12
  129. package/src/sync/common/constants.ts +0 -2
  130. package/src/sync/index.ts +1 -1
  131. package/src/sync/local-choice.ts +32 -3
  132. package/src/sync/planner.ts +2 -15
  133. package/src/sync/settings.ts +0 -17
  134. package/src/theme/index.ts +1 -0
  135. package/src/theme/tokens.ts +410 -0
  136. package/src/ui/prompt.ts +1 -0
  137. package/src/visualize/architecture.ts +504 -0
  138. package/src/visualize/assets.ts +41 -30
  139. package/src/visualize/compare-render.ts +22 -24
  140. package/src/visualize/constants.ts +27 -0
  141. package/src/visualize/diagrams.ts +13 -121
  142. package/src/visualize/kinds-render.ts +2 -2
  143. package/src/visualize/kinds-schema.ts +49 -0
  144. package/src/visualize/labels-vi.ts +25 -0
  145. package/src/visualize/labels.ts +2 -0
  146. package/src/visualize/layout.ts +415 -66
  147. package/src/visualize/page.ts +82 -15
  148. package/src/visualize/render.ts +2 -1
  149. package/src/visualize/schema.ts +29 -1
  150. package/src/visualize/sections.ts +78 -9
  151. package/src/visualize/theme.ts +49 -18
  152. package/src/wiki/anchors.ts +1 -0
  153. package/src/wiki/command.ts +10 -3
  154. package/src/wiki/source-links.ts +57 -18
  155. package/base/ci-global.json +0 -13
  156. package/base/claude/remote-hosts.json +0 -15
  157. package/base/hooks/guard-manifest.ts +0 -27
  158. package/base/hooks/guard-package.ts +0 -30
  159. package/base/hooks/guard-remote-hosts.ts +0 -70
  160. package/base/hooks/guard-scripting.ts +0 -32
  161. package/base/hooks/post-tool.ts +0 -37
  162. package/base/hooks/prompt-submit.ts +0 -54
  163. package/base/hooks/stop.ts +0 -40
  164. package/base/skills/build-a-feature/evals/evals.json +0 -29
  165. package/base/skills/docs-update/evals/evals.json +0 -23
  166. package/base/skills/docs-writing/evals/evals.json +0 -17
  167. package/base/skills/fix-a-bug/evals/evals.json +0 -17
  168. package/base/skills/knowledge-sync/SKILL.md +0 -81
  169. package/base/skills/knowledge-sync/knowledge-sync.workflow.js +0 -291
  170. package/base/skills/knowledge-sync/references/workflow.md +0 -44
  171. package/base/skills/plan-a-change/evals/evals.json +0 -47
  172. package/base/skills/report-back/evals/evals.json +0 -23
  173. package/base/skills/research/evals/evals.json +0 -17
  174. package/base/skills/retro/evals/evals.json +0 -17
  175. package/base/skills/review-a-change/evals/evals.json +0 -17
  176. package/base/skills/ship/evals/evals.json +0 -23
  177. package/base/skills/visualize-work/evals/evals.json +0 -17
  178. package/base/templates/ci/github-actions.yml +0 -75
  179. package/base/templates/ci/gitlab-ci.yml +0 -52
  180. package/base/templates/trusted-hosts.local.example +0 -11
  181. package/src/ci/affected.ts +0 -176
  182. package/src/ci/command.ts +0 -166
  183. package/src/ci/common/constants.ts +0 -76
  184. package/src/ci/common/index.ts +0 -2
  185. package/src/ci/common/types.ts +0 -37
  186. package/src/ci/git.ts +0 -72
  187. package/src/ci/global.ts +0 -48
  188. package/src/ci/graph.ts +0 -43
  189. package/src/ci/index.ts +0 -7
  190. package/src/ci/workspace.ts +0 -119
  191. package/src/commands/ci.command.ts +0 -4
  192. package/src/hooks/guard-manifest.ts +0 -109
  193. package/src/hooks/guard-package.ts +0 -226
  194. package/src/hooks/guard-scripting.ts +0 -36
  195. package/src/hooks/host-pattern.ts +0 -17
  196. package/src/hooks/owner-reply.ts +0 -162
  197. package/src/hooks/post-tool.ts +0 -138
  198. package/src/hooks/remote-hosts.ts +0 -1013
  199. package/src/hooks/trusted-scripts.ts +0 -212
  200. package/src/owner/shape.ts +0 -496
  201. package/src/owner/violations.ts +0 -332
  202. package/src/signals/claims.ts +0 -73
  203. package/src/signals/classify.ts +0 -137
  204. package/src/signals/constants.ts +0 -88
  205. package/src/signals/index.ts +0 -5
  206. package/src/signals/loop.ts +0 -48
  207. package/src/signals/state.ts +0 -271
  208. package/src/sync/atlas-block.ts +0 -56
@@ -0,0 +1,436 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { RecordValue } from '../common/record.ts';
3
+ import { EventConstants } from '../events/common/index.ts';
4
+ import {
5
+ BoardConstants,
6
+ BoardKinds,
7
+ BoardSources,
8
+ BoardStages,
9
+ BoardStatuses,
10
+ } from './common/index.ts';
11
+ import type { IBoardEvent } from './common/index.ts';
12
+ import { BoardGithub } from './github.ts';
13
+
14
+ const text = RecordValue.textOf;
15
+ const FINISHED = new Set(['success', 'failed', 'canceled', 'skipped']);
16
+ const SCP_REMOTE = /^(?:[^@/\s]+@)?([\w.-]+):(?!\/\/)(.+)$/;
17
+
18
+ type TBase = Pick<IBoardEvent, 'flowId' | 'source' | 'ref' | 'link'>;
19
+
20
+ interface IKnownRequest {
21
+ iid: number;
22
+ branch: string;
23
+ base: TBase;
24
+ }
25
+
26
+ /** Merge requests, their approvals, pipelines and commits, read through `glab api`: an extra for projects on GitLab. */
27
+ export class BoardGitlab {
28
+ /**
29
+ * The lines of the GitLab projects `repos` (the project of `origin` when none is named and its host is `host`)
30
+ * that changed since `since`. Only GET requests are made, by `glab`, which owns the sign-in. When `glab` is
31
+ * missing, not logged in, or the folder is not a GitLab project it can read, the answer is no lines and a note
32
+ * that says why, never an error.
33
+ */
34
+ static read(opts: { repos: string[]; cwd: string; since: number; host: string }): {
35
+ events: IBoardEvent[];
36
+ note: string;
37
+ } {
38
+ if (Bun.which('glab', { PATH: process.env.PATH ?? '' }) === null) {
39
+ return { events: [], note: 'gitlab: skipped, glab is not installed' };
40
+ }
41
+
42
+ const projects =
43
+ opts.repos.length > 0
44
+ ? opts.repos
45
+ : BoardGitlab.currentProject({ cwd: opts.cwd, host: opts.host });
46
+
47
+ if (projects === undefined) {
48
+ return {
49
+ events: [],
50
+ note: 'gitlab: skipped, this folder is not a GitLab project glab can read',
51
+ };
52
+ }
53
+
54
+ const events: IBoardEvent[] = [];
55
+ const notes: string[] = [];
56
+
57
+ for (const project of projects) {
58
+ const read = BoardGitlab.readProject({ ...opts, project });
59
+
60
+ events.push(...read.events);
61
+ notes.push(read.note);
62
+ }
63
+
64
+ return { events, note: `gitlab: ${notes.join(', ')}` };
65
+ }
66
+
67
+ /** The host name and the project path of a remote URL (`ssh://`, `https://` or scp-style), or none; credentials are never kept. */
68
+ static parseRemote(opts: { url: string }): { host: string; path: string } | undefined {
69
+ const scp = SCP_REMOTE.exec(opts.url);
70
+ let host = scp?.[1] ?? '';
71
+ let path = scp?.[2] ?? '';
72
+
73
+ if (scp === null) {
74
+ try {
75
+ const parsed = new URL(opts.url);
76
+
77
+ host = parsed.hostname;
78
+ path = parsed.pathname;
79
+ } catch {
80
+ return undefined;
81
+ }
82
+ }
83
+
84
+ const cleaned = path.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
85
+
86
+ return host !== '' && BoardConstants.PROJECT_PATH.test(cleaned)
87
+ ? { host: host.toLowerCase(), path: cleaned }
88
+ : undefined;
89
+ }
90
+
91
+ private static currentProject(opts: { cwd: string; host: string }): string[] | undefined {
92
+ const result = spawnSync('git', ['remote', 'get-url', 'origin'], {
93
+ cwd: opts.cwd,
94
+ encoding: 'utf8',
95
+ timeout: BoardConstants.GH_TIMEOUT_MS,
96
+ });
97
+ const remote =
98
+ result.status === 0 ? BoardGitlab.parseRemote({ url: result.stdout.trim() }) : undefined;
99
+
100
+ return remote !== undefined && remote.host === opts.host.replace(/:\d+$/, '').toLowerCase()
101
+ ? [remote.path]
102
+ : undefined;
103
+ }
104
+
105
+ private static get(opts: { host: string; cwd: string; endpoint: string }): {
106
+ data?: unknown;
107
+ problem?: string;
108
+ } {
109
+ const result = spawnSync('glab', ['api', '--hostname', opts.host, opts.endpoint], {
110
+ cwd: opts.cwd,
111
+ encoding: 'utf8',
112
+ timeout: BoardConstants.GH_TIMEOUT_MS,
113
+ });
114
+
115
+ if (result.status !== 0) {
116
+ return { problem: (result.stderr ?? '').trim().split('\n')[0] || 'glab failed' };
117
+ }
118
+
119
+ try {
120
+ return { data: JSON.parse(result.stdout) };
121
+ } catch {
122
+ return { problem: 'glab did not answer with JSON' };
123
+ }
124
+ }
125
+
126
+ private static listOf(opts: {
127
+ host: string;
128
+ cwd: string;
129
+ endpoint: string;
130
+ label: string;
131
+ problems: string[];
132
+ since: number;
133
+ stamp: string;
134
+ }): Record<string, unknown>[] {
135
+ const { data, problem } = BoardGitlab.get(opts);
136
+
137
+ if (problem !== undefined) {
138
+ opts.problems.push(`${opts.label} skipped (${problem})`);
139
+ }
140
+
141
+ return (Array.isArray(data) ? data : []).filter(
142
+ (item): item is Record<string, unknown> =>
143
+ RecordValue.isRecord(item) && Date.parse(text({ value: item[opts.stamp] })) >= opts.since,
144
+ );
145
+ }
146
+
147
+ private static readProject(opts: { project: string; cwd: string; since: number; host: string }): {
148
+ events: IBoardEvent[];
149
+ note: string;
150
+ } {
151
+ const { project, since } = opts;
152
+ const base = `projects/${encodeURIComponent(project)}`;
153
+ const found = BoardGitlab.get({ ...opts, endpoint: base });
154
+
155
+ if (!RecordValue.isRecord(found.data)) {
156
+ return { events: [], note: `${project} skipped (${found.problem ?? 'not a project'})` };
157
+ }
158
+
159
+ const problems: string[] = [];
160
+ const moment = encodeURIComponent(new Date(since).toISOString());
161
+ const page = `per_page=${BoardConstants.GH_LIMIT}`;
162
+ const list = (endpoint: string, label: string, stamp: string) =>
163
+ BoardGitlab.listOf({ ...opts, endpoint: `${base}/${endpoint}`, label, problems, stamp });
164
+ const known = list(
165
+ `merge_requests?state=all&order_by=updated_at&updated_after=${moment}&${page}`,
166
+ 'merge requests',
167
+ 'updated_at',
168
+ )
169
+ .flatMap((mr) =>
170
+ typeof mr.iid === 'number'
171
+ ? [
172
+ {
173
+ mr,
174
+ iid: mr.iid,
175
+ branch: text({ value: mr.source_branch }),
176
+ base: BoardGitlab.baseOf({ mr, iid: mr.iid, project }),
177
+ },
178
+ ]
179
+ : [],
180
+ )
181
+ .slice(0, BoardConstants.GH_LIMIT);
182
+ const events: IBoardEvent[] = [];
183
+
184
+ for (const request of known) {
185
+ const approvals = BoardGitlab.get({
186
+ ...opts,
187
+ endpoint: `${base}/merge_requests/${request.iid}/approvals`,
188
+ });
189
+
190
+ if (approvals.problem !== undefined) {
191
+ problems.push(`approvals of !${request.iid} skipped (${approvals.problem})`);
192
+ }
193
+
194
+ events.push(...BoardGitlab.requestEvents({ ...request, project, approvals: approvals.data }));
195
+ }
196
+
197
+ const pipelines = list(
198
+ `pipelines?order_by=updated_at&updated_after=${moment}&${page}`,
199
+ 'pipelines',
200
+ 'updated_at',
201
+ );
202
+
203
+ for (const [index, pipeline] of pipelines.entries()) {
204
+ if (typeof pipeline.id !== 'number') {
205
+ continue;
206
+ }
207
+
208
+ const jobs =
209
+ index < BoardConstants.GITLAB_JOB_PIPELINES &&
210
+ FINISHED.has(text({ value: pipeline.status }))
211
+ ? BoardGitlab.get({
212
+ ...opts,
213
+ endpoint: `${base}/pipelines/${pipeline.id}/jobs?per_page=${BoardConstants.GH_LIMIT}`,
214
+ })
215
+ : {};
216
+
217
+ if (jobs.problem !== undefined) {
218
+ problems.push(`jobs of pipeline ${pipeline.id} skipped (${jobs.problem})`);
219
+ }
220
+
221
+ events.push(
222
+ ...BoardGitlab.pipelineEvents({ pipeline, jobs: jobs.data, project, requests: known }),
223
+ );
224
+ }
225
+
226
+ const branch = text({ value: found.data.default_branch });
227
+ const commits =
228
+ branch === ''
229
+ ? []
230
+ : list(
231
+ `repository/commits?ref_name=${encodeURIComponent(branch)}&since=${moment}&${page}`,
232
+ 'commits',
233
+ 'committed_date',
234
+ );
235
+
236
+ events.push(...commits.flatMap((commit) => BoardGitlab.commitEvents({ commit, project })));
237
+
238
+ const counted = `${project} ${known.length} merge request(s), ${pipelines.length} pipeline(s), ${commits.length} commit(s) since the date (the newest ${BoardConstants.GH_LIMIT} of each are asked for)`;
239
+
240
+ return {
241
+ events: events.filter((event) => event.ts !== ''),
242
+ note: problems.length === 0 ? counted : `${counted} (${problems.join('; ')})`,
243
+ };
244
+ }
245
+
246
+ /** `Flow: <id>` in the description of a merge request, else a flow id as a segment of its branch, else none. */
247
+ private static baseOf(opts: {
248
+ mr: Record<string, unknown>;
249
+ iid: number;
250
+ project: string;
251
+ }): TBase {
252
+ const { mr } = opts;
253
+
254
+ return {
255
+ flowId:
256
+ BoardGithub.flowOf({
257
+ body: text({ value: mr.description }),
258
+ branch: text({ value: mr.source_branch }),
259
+ }) ?? BoardConstants.UNSORTED,
260
+ source: BoardSources.GITLAB,
261
+ ref: { repo: opts.project, pr: opts.iid },
262
+ link: text({ value: mr.web_url }),
263
+ };
264
+ }
265
+
266
+ /** The lines one merge request stands for: opened, each approval, merged or closed. */
267
+ private static requestEvents(opts: {
268
+ mr: Record<string, unknown>;
269
+ iid: number;
270
+ base: TBase;
271
+ project: string;
272
+ approvals: unknown;
273
+ }): IBoardEvent[] {
274
+ const { mr, base, iid } = opts;
275
+ const author = RecordValue.isRecord(mr.author) ? text({ value: mr.author.username }) : '';
276
+ const id = (part: string): string => `gl:${opts.project}!${iid}:${part}`;
277
+ const events: IBoardEvent[] = [
278
+ {
279
+ ...base,
280
+ id: id('mr'),
281
+ ts: text({ value: mr.created_at }),
282
+ kind: BoardKinds.PR,
283
+ stage: BoardStages.PR_AND_CI,
284
+ actor: author,
285
+ status: BoardStatuses.OPEN,
286
+ summary: `!${iid} ${text({ value: mr.title })}`,
287
+ },
288
+ ];
289
+ const merged = text({ value: mr.merged_at });
290
+ const closed = text({ value: mr.closed_at });
291
+ const approvedAt = merged || closed || text({ value: mr.updated_at });
292
+ const approvers = RecordValue.isRecord(opts.approvals) ? opts.approvals.approved_by : undefined;
293
+
294
+ for (const [index, approval] of (Array.isArray(approvers) ? approvers : []).entries()) {
295
+ events.push({
296
+ ...base,
297
+ id: id(`review-${index}`),
298
+ ts: approvedAt,
299
+ kind: BoardKinds.REVIEW,
300
+ stage: BoardStages.REVIEW,
301
+ actor:
302
+ RecordValue.isRecord(approval) && RecordValue.isRecord(approval.user)
303
+ ? text({ value: approval.user.username }) || 'reviewer'
304
+ : 'reviewer',
305
+ status: BoardStatuses.PASS,
306
+ summary: 'approved',
307
+ });
308
+ }
309
+
310
+ if (merged !== '') {
311
+ events.push({
312
+ ...base,
313
+ id: id('merge'),
314
+ ts: merged,
315
+ kind: BoardKinds.MERGE,
316
+ stage: BoardStages.MERGE,
317
+ actor: author,
318
+ status: BoardStatuses.DONE,
319
+ summary: 'merged',
320
+ });
321
+ } else if (closed !== '' && text({ value: mr.state }) === 'closed') {
322
+ events.push({
323
+ ...base,
324
+ id: id('closed'),
325
+ ts: closed,
326
+ kind: BoardKinds.PR,
327
+ stage: BoardStages.PR_AND_CI,
328
+ actor: author,
329
+ status: BoardStatuses.CLOSED,
330
+ summary: 'closed without merge',
331
+ });
332
+ }
333
+
334
+ return events;
335
+ }
336
+
337
+ /** One line per finished job of a pipeline, or one for the pipeline when no job can be read. */
338
+ private static pipelineEvents(opts: {
339
+ pipeline: Record<string, unknown>;
340
+ jobs: unknown;
341
+ project: string;
342
+ requests: IKnownRequest[];
343
+ }): IBoardEvent[] {
344
+ const { pipeline, project } = opts;
345
+ const ref = text({ value: pipeline.ref });
346
+ const owner = opts.requests.find(
347
+ (request) => request.branch === ref || ref === `refs/merge-requests/${request.iid}/head`,
348
+ );
349
+ const base: TBase = owner?.base ?? {
350
+ flowId: BoardConstants.UNSORTED,
351
+ source: BoardSources.GITLAB,
352
+ ref: { repo: project },
353
+ };
354
+ const line = (part: {
355
+ id: string;
356
+ ts: string;
357
+ check: string;
358
+ status: string;
359
+ link: string;
360
+ }): IBoardEvent | undefined => {
361
+ if (part.ts === '' || (part.status !== 'success' && part.status !== 'failed')) {
362
+ return undefined;
363
+ }
364
+
365
+ return {
366
+ ...base,
367
+ ...(part.link === '' ? {} : { link: part.link }),
368
+ id: `gl:${project}:${part.id}`,
369
+ ts: part.ts,
370
+ kind: BoardKinds.CI,
371
+ stage: BoardStages.PR_AND_CI,
372
+ actor: BoardConstants.CI_ACTOR,
373
+ check: part.check,
374
+ status: part.status === 'success' ? BoardStatuses.PASS : BoardStatuses.FAIL,
375
+ summary: part.check,
376
+ };
377
+ };
378
+ const fromJobs = (Array.isArray(opts.jobs) ? opts.jobs : []).flatMap((job: unknown) =>
379
+ RecordValue.isRecord(job) && typeof job.id === 'number'
380
+ ? [
381
+ line({
382
+ id: `ci-${job.id}`,
383
+ ts: text({ value: job.finished_at }) || text({ value: job.started_at }),
384
+ check: text({ value: job.name }) || 'job',
385
+ status: text({ value: job.status }),
386
+ link: text({ value: job.web_url }),
387
+ }),
388
+ ]
389
+ : [],
390
+ );
391
+ const lines = fromJobs.filter((event): event is IBoardEvent => event !== undefined);
392
+
393
+ if (lines.length > 0) {
394
+ return lines;
395
+ }
396
+
397
+ const whole = line({
398
+ id: `ci-pipeline-${String(pipeline.id)}`,
399
+ ts: text({ value: pipeline.updated_at }),
400
+ check: 'pipeline',
401
+ status: text({ value: pipeline.status }),
402
+ link: text({ value: pipeline.web_url }),
403
+ });
404
+
405
+ return whole === undefined ? [] : [whole];
406
+ }
407
+
408
+ private static commitEvents(opts: {
409
+ commit: Record<string, unknown>;
410
+ project: string;
411
+ }): IBoardEvent[] {
412
+ const { commit } = opts;
413
+ const sha = text({ value: commit.id });
414
+
415
+ if (sha === '') {
416
+ return [];
417
+ }
418
+
419
+ return [
420
+ {
421
+ id: `gl:${opts.project}:commit-${sha.slice(0, 8)}`,
422
+ flowId:
423
+ EventConstants.FLOW_LINE.exec(text({ value: commit.message }))?.[1] ??
424
+ BoardConstants.UNSORTED,
425
+ ts: text({ value: commit.committed_date }),
426
+ kind: BoardKinds.COMMIT,
427
+ stage: BoardStages.CODE,
428
+ actor: text({ value: commit.author_name }),
429
+ source: BoardSources.GITLAB,
430
+ ref: { repo: opts.project },
431
+ link: text({ value: commit.web_url }),
432
+ summary: text({ value: commit.title }),
433
+ },
434
+ ];
435
+ }
436
+ }
@@ -2,6 +2,7 @@ export * from './common/index.ts';
2
2
  export * from './command.ts';
3
3
  export * from './fold.ts';
4
4
  export * from './github.ts';
5
+ export * from './gitlab.ts';
5
6
  export * from './agent-setting.ts';
6
7
  export * from './page.ts';
7
8
  export * from './schema.ts';
@@ -0,0 +1,49 @@
1
+ import { readFileSync, realpathSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { PresetPath } from '../create/common/preset-path.ts';
4
+ import { BoardConstants } from './common/index.ts';
5
+
6
+ /** The `board.logo` file: which paths the config accepts and the one place that reads the file. */
7
+ export class BoardLogo {
8
+ /** The rule of the config: an `.svg` path that is relative and has no `..` segment. */
9
+ static isPath(opts: { path: string }): boolean {
10
+ return (
11
+ opts.path.toLowerCase().endsWith('.svg') &&
12
+ !opts.path.startsWith('/') &&
13
+ !opts.path.split('/').includes('..')
14
+ );
15
+ }
16
+
17
+ /**
18
+ * The SVG at `path` in the project as a `data:` URL; a picture in an `img` runs no script, whatever the file
19
+ * holds. Nothing is read unless the path passes `isPath` and the file, with every link resolved, lies inside the
20
+ * project. `undefined` for anything else, a missing file, one over the size cap and one that is no SVG included.
21
+ */
22
+ static read(opts: { root: string; path: string }): string | undefined {
23
+ if (!BoardLogo.isPath({ path: opts.path })) {
24
+ return undefined;
25
+ }
26
+
27
+ try {
28
+ const real = realpathSync(join(opts.root, opts.path));
29
+
30
+ if (PresetPath.escapes({ root: realpathSync(opts.root), path: real })) {
31
+ return undefined;
32
+ }
33
+
34
+ const stat = statSync(real);
35
+
36
+ if (!stat.isFile() || stat.size > BoardConstants.LOGO_MAX_BYTES) {
37
+ return undefined;
38
+ }
39
+
40
+ const svg = readFileSync(real);
41
+
42
+ return /<svg[\s>]/i.test(svg.toString('utf8', 0, 2000))
43
+ ? `data:image/svg+xml;base64,${svg.toString('base64')}`
44
+ : undefined;
45
+ } catch {
46
+ return undefined;
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,110 @@
1
+ import {
2
+ chmodSync,
3
+ existsSync,
4
+ lstatSync,
5
+ mkdirSync,
6
+ mkdtempSync,
7
+ readdirSync,
8
+ rmSync,
9
+ writeFileSync,
10
+ } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ import { BoardServe } from './common/index.ts';
13
+
14
+ /**
15
+ * The page `--open` gives the program that opens the browser, so the address with the token is in no argument list. It
16
+ * lives in a folder of its own that only this user can enter: the tmp folder it is made in can be written by others,
17
+ * and a page they put under a name we chose would be run by the browser.
18
+ */
19
+ export class BoardOpenFile {
20
+ /** A page that sends the browser to `url`, with a link for one that does not follow it. */
21
+ static htmlOf(opts: { url: string }): string {
22
+ const url = opts.url
23
+ .replaceAll('&', '&amp;')
24
+ .replaceAll('"', '&quot;')
25
+ .replaceAll('<', '&lt;')
26
+ .replaceAll('>', '&gt;');
27
+
28
+ return `<!doctype html>\n<meta charset="utf-8">\n<meta http-equiv="refresh" content="0;url=${url}">\n<title>Board</title>\n<a href="${url}">Open the board</a>\n`;
29
+ }
30
+
31
+ /**
32
+ * Makes a private folder (mode 0700, owned by `uid`, default the process user) in `folder`, which is made when
33
+ * missing, and writes `index.html` in it for its owner only. Throws when the folder made is not private; nothing
34
+ * is left behind then. Mode and owner are not checked where the system has no user id (Windows).
35
+ */
36
+ static write(opts: { folder: string; url: string; uid?: number }): {
37
+ directory: string;
38
+ path: string;
39
+ } {
40
+ const uid = opts.uid ?? process.getuid?.();
41
+
42
+ mkdirSync(opts.folder, { recursive: true });
43
+ BoardOpenFile.sweep({ folder: opts.folder, ...(uid === undefined ? {} : { uid }) });
44
+
45
+ const directory = mkdtempSync(join(opts.folder, BoardServe.OPEN_DIRECTORY_PREFIX));
46
+
47
+ try {
48
+ chmodSync(directory, 0o700);
49
+
50
+ const stat = lstatSync(directory);
51
+
52
+ if (
53
+ !stat.isDirectory() ||
54
+ (uid !== undefined && (stat.uid !== uid || (stat.mode & 0o077) !== 0))
55
+ ) {
56
+ throw new Error(`${directory} is not a private folder of this user`);
57
+ }
58
+
59
+ const path = join(directory, BoardServe.OPEN_FILE_NAME);
60
+
61
+ writeFileSync(path, BoardOpenFile.htmlOf({ url: opts.url }), { flag: 'wx', mode: 0o600 });
62
+
63
+ return { directory, path };
64
+ } catch (error) {
65
+ rmSync(directory, { recursive: true, force: true });
66
+
67
+ throw error;
68
+ }
69
+ }
70
+
71
+ /** Removes the folder and the page in it; a folder that is already gone is not an error. */
72
+ static remove(opts: { directory: string }): void {
73
+ rmSync(opts.directory, { recursive: true, force: true });
74
+ }
75
+
76
+ /**
77
+ * Removes the folders `write` made in `folder` that belong to `uid` and are older than `OPEN_STALE_MS`, left by a
78
+ * run that was killed. A link is not followed and a folder that cannot be removed is reported, not thrown.
79
+ */
80
+ static sweep(opts: { folder: string; uid?: number }): void {
81
+ if (!existsSync(opts.folder)) {
82
+ return;
83
+ }
84
+
85
+ const uid = opts.uid ?? process.getuid?.();
86
+
87
+ try {
88
+ for (const entry of readdirSync(opts.folder, { withFileTypes: true })) {
89
+ if (!entry.isDirectory() || !entry.name.startsWith(BoardServe.OPEN_DIRECTORY_PREFIX)) {
90
+ continue;
91
+ }
92
+
93
+ const directory = join(opts.folder, entry.name);
94
+ const stat = lstatSync(directory);
95
+
96
+ if (
97
+ stat.isDirectory() &&
98
+ (uid === undefined || stat.uid === uid) &&
99
+ Date.now() - stat.mtimeMs > BoardServe.OPEN_STALE_MS
100
+ ) {
101
+ rmSync(directory, { recursive: true, force: true });
102
+ }
103
+ }
104
+ } catch (error) {
105
+ process.stderr.write(
106
+ `board: cannot clear old pages in ${opts.folder}: ${error instanceof Error ? error.message : String(error)}\n`,
107
+ );
108
+ }
109
+ }
110
+ }
package/src/board/page.ts CHANGED
@@ -2,15 +2,42 @@ import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { BASE_DIRECTORY } from '../common/paths.ts';
4
4
  import { BoardConstants } from './common/index.ts';
5
+ import { ThemeTokens } from '../theme/index.ts';
6
+ import type { IThemeTokens } from '../theme/index.ts';
5
7
  import type { IBoardData } from './common/index.ts';
6
8
 
9
+ /** The token the board calls by another name: the custom properties of its shell. `--focus` and `--r` follow below. */
10
+ const TOKEN_PROPERTIES: Record<string, string> = {
11
+ ground: 'ground',
12
+ bg: 'bg',
13
+ line: 'line',
14
+ 'line-strong': 'stroke-strong',
15
+ ink: 'ink',
16
+ body: 'body',
17
+ muted: 'muted',
18
+ accent: 'accent',
19
+ 'accent-ink': 'accent-ink',
20
+ 'accent-soft': 'accent-soft',
21
+ 'accent-text': 'accent-text',
22
+ ok: 'ok',
23
+ 'ok-soft': 'ok-soft',
24
+ wait: 'wait',
25
+ 'wait-soft': 'wait-soft',
26
+ fail: 'fail',
27
+ 'fail-soft': 'fail-soft',
28
+ // The greys of the board's panes (ThemeTokens.SURFACES), written beside the tokens.
29
+ head: 'head',
30
+ soft: 'soft',
31
+ sunk: 'sunk',
32
+ };
33
+
7
34
  /** The board as one HTML file: the page of `base/templates/board.html` with the data inside it. */
8
35
  export class BoardPage {
9
36
  /**
10
37
  * The page with `data` embedded as JSON in a `script` of type `application/json`. `<` and the two line separators
11
38
  * are escaped, so no text in the data can close the script or break it. Nothing is fetched when the page opens.
12
39
  */
13
- static render(opts: { data: IBoardData; template?: string }): string {
40
+ static render(opts: { data: IBoardData; template?: string; tokens?: IThemeTokens }): string {
14
41
  const template =
15
42
  opts.template ?? readFileSync(join(BASE_DIRECTORY, BoardConstants.TEMPLATE), 'utf8');
16
43
  const json = JSON.stringify(opts.data)
@@ -18,9 +45,34 @@ export class BoardPage {
18
45
  .replaceAll('
', '\\u2028')
19
46
  .replaceAll('
', '\\u2029');
20
47
 
21
- return template.replace(
22
- BoardConstants.DATA_MARKER,
23
- () => `<script type="application/json" id="board-data">${json}</script>`,
24
- );
48
+ return template
49
+ .replace(BoardConstants.TOKENS_MARKER, () => BoardPage.tokensStyle({ tokens: opts.tokens }))
50
+ .replace(
51
+ BoardConstants.DATA_MARKER,
52
+ () => `<script type="application/json" id="board-data">${json}</script>`,
53
+ );
54
+ }
55
+
56
+ /**
57
+ * The `style` with the tokens as the shell names them: light on `:root`, the system dark setting unless the page
58
+ * was set to light, then each explicit setting (the embedding wiki's `data-theme` and the board's own). The default
59
+ * preset when no tokens are given.
60
+ */
61
+ static tokensStyle(opts: { tokens?: IThemeTokens }): string {
62
+ const tokens = opts.tokens ?? ThemeTokens.defaults();
63
+ const declare = (mode: 'light' | 'dark'): string =>
64
+ `${ThemeTokens.declarations({ mode: { ...tokens[mode], ...ThemeTokens.SURFACES[mode] }, names: TOKEN_PROPERTIES })};--focus:${tokens[mode].accent}`;
65
+ const light = `${declare('light')};--r:${tokens.radius}`;
66
+ const dark = declare('dark');
67
+
68
+ return [
69
+ '<style id="board-tokens">',
70
+ `:root{${light}}`,
71
+ `@media (prefers-color-scheme: dark){:root:not([data-theme='light']):not([data-board-theme='light']){${dark}}}`,
72
+ `:root[data-theme='dark']{${dark}}`,
73
+ `:root[data-board-theme='dark']{${dark}}`,
74
+ `:root[data-board-theme='light']{${light}}`,
75
+ '</style>',
76
+ ].join('\n');
25
77
  }
26
78
  }