@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
@@ -1,176 +0,0 @@
1
- import { AffectedReasons, CiChecks, CiConstants } from './common/index.ts';
2
- import type {
3
- IAffectedPackage,
4
- IAffectedResult,
5
- IWorkspacePackage,
6
- TAffectedReason,
7
- TCiCheck,
8
- } from './common/index.ts';
9
- import { CiGit } from './git.ts';
10
- import { CiGlobal } from './global.ts';
11
- import { CiGraph } from './graph.ts';
12
- import { CiWorkspace } from './workspace.ts';
13
-
14
- type TAffectedRun = { ok: true; result: IAffectedResult } | { ok: false; error: string };
15
-
16
- /** Which packages a change touches. */
17
- export class CiAffected {
18
- /**
19
- * Reads the workspace of the checked-out tree and the files that differ between `base` and `head`,
20
- * and says which packages are affected. `head` must be the commit that is checked out, because the
21
- * packages and their dependencies are read from the files on disk. A base of only zeros, what a
22
- * pipeline passes for a branch with no parent, has nothing to compare with: every package is affected.
23
- */
24
- static run(opts: { root: string; base: string; head: string }): TAffectedRun {
25
- const workspace = CiWorkspace.read({ root: opts.root });
26
-
27
- if (!workspace.ok) {
28
- return workspace;
29
- }
30
-
31
- const globs = CiGlobal.read({ root: opts.root });
32
-
33
- if (CiConstants.EMPTY_BASE.test(opts.base)) {
34
- return {
35
- ok: true,
36
- result: CiAffected.build({
37
- base: opts.base,
38
- head: opts.head,
39
- packages: workspace.packages,
40
- selection: {
41
- all: true,
42
- because: 'the base is empty (a new branch): nothing to compare with',
43
- reached: new Map(),
44
- },
45
- }),
46
- };
47
- }
48
-
49
- const head = CiGit.resolve({ root: opts.root, ref: opts.head });
50
- const base = CiGit.resolve({ root: opts.root, ref: opts.base });
51
- const checkedOut = CiGit.resolve({ root: opts.root, ref: 'HEAD' });
52
-
53
- if (!head.ok || !base.ok || !checkedOut.ok) {
54
- return {
55
- ok: false,
56
- error:
57
- [head, base, checkedOut].flatMap((step) => (step.ok ? [] : [step.error]))[0] ??
58
- 'git failed',
59
- };
60
- }
61
-
62
- if (head.stdout !== checkedOut.stdout) {
63
- return {
64
- ok: false,
65
- error: `--head ${opts.head} is not the checked-out commit: the packages are read from the files on disk, so check ${opts.head} out first`,
66
- };
67
- }
68
-
69
- const changes = CiGit.changedFiles({ root: opts.root, base: base.stdout, head: head.stdout });
70
-
71
- if (!changes.ok) {
72
- return changes;
73
- }
74
-
75
- return {
76
- ok: true,
77
- result: CiAffected.build({
78
- base: base.stdout,
79
- head: head.stdout,
80
- packages: workspace.packages,
81
- selection: CiAffected.select({
82
- packages: workspace.packages,
83
- files: changes.files,
84
- globs,
85
- }),
86
- }),
87
- };
88
- }
89
-
90
- /**
91
- * The packages a set of changed files touches. Everything is affected when a file matches `globs` or the
92
- * otherwise a package is affected when one of its files changed or when a package it depends on is.
93
- */
94
- static select(opts: { packages: IWorkspacePackage[]; files: string[]; globs: string[] }): {
95
- all: boolean;
96
- because?: string;
97
- reached: Map<string, TAffectedReason>;
98
- } {
99
- const hit = CiGlobal.firstHit({ files: opts.files, globs: opts.globs });
100
-
101
- if (hit !== undefined) {
102
- return { all: true, because: hit, reached: new Map() };
103
- }
104
-
105
- const seeds = new Map<string, TAffectedReason>();
106
-
107
- for (const file of opts.files) {
108
- const owner = CiAffected.ownerOf({ packages: opts.packages, file });
109
-
110
- if (owner !== undefined) {
111
- seeds.set(owner.name, AffectedReasons.CHANGED);
112
- }
113
- }
114
-
115
- return { all: false, reached: CiGraph.closure({ packages: opts.packages, seeds }) };
116
- }
117
-
118
- /** The package whose folder holds `file`: the deepest one when folders nest. */
119
- private static ownerOf(opts: {
120
- packages: IWorkspacePackage[];
121
- file: string;
122
- }): IWorkspacePackage | undefined {
123
- let owner: IWorkspacePackage | undefined;
124
-
125
- for (const entry of opts.packages) {
126
- const isInside = opts.file === entry.dir || opts.file.startsWith(`${entry.dir}/`);
127
-
128
- if (isInside && (owner === undefined || entry.dir.length > owner.dir.length)) {
129
- owner = entry;
130
- }
131
- }
132
-
133
- return owner;
134
- }
135
-
136
- private static build(opts: {
137
- base: string;
138
- head: string;
139
- packages: IWorkspacePackage[];
140
- selection: { all: boolean; because?: string; reached: Map<string, TAffectedReason> };
141
- }): IAffectedResult {
142
- const { selection } = opts;
143
- const listed: IAffectedPackage[] = opts.packages
144
- .filter((entry) => selection.all || selection.reached.has(entry.name))
145
- .map((entry) => ({
146
- name: entry.name,
147
- dir: entry.dir,
148
- reason: selection.all
149
- ? AffectedReasons.GLOBAL
150
- : (selection.reached.get(entry.name) ?? AffectedReasons.CHANGED),
151
- checks: CiAffected.checksOf({ scripts: entry.scripts }),
152
- }))
153
- .sort((left, right) => left.name.localeCompare(right.name));
154
-
155
- return {
156
- base: opts.base,
157
- head: opts.head,
158
- all: selection.all,
159
- ...(selection.all && selection.because !== undefined
160
- ? { allBecause: selection.because }
161
- : {}),
162
- packages: listed,
163
- };
164
- }
165
-
166
- /** The checks a package has: each standard script it defines, by the name that runs it. */
167
- private static checksOf(opts: {
168
- scripts: Record<string, string>;
169
- }): Partial<Record<TCiCheck, string>> {
170
- return Object.fromEntries(
171
- [...CiChecks.SCHEME_SET]
172
- .filter((check) => Object.hasOwn(opts.scripts, check))
173
- .map((check) => [check, check]),
174
- );
175
- }
176
- }
package/src/ci/command.ts DELETED
@@ -1,166 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { BASE_DIRECTORY } from '../common/paths.ts';
4
- import { ExitCodes } from '../common/index.ts';
5
- import type { ICommandContext } from '../common/index.ts';
6
- import { CiAffected } from './affected.ts';
7
- import { CiChecks, CiConstants, CiFlags, CiSubcommands, CiTemplates } from './common/index.ts';
8
- import type { IAffectedResult, TCiCheck } from './common/index.ts';
9
-
10
- const USAGE = `usage: vulcan ci affected ${CiFlags.BASE} <ref> [${CiFlags.HEAD} <ref>] [${CiFlags.CHECK} <check>] [${CiFlags.JSON} | ${CiFlags.NAMES}]
11
- vulcan ci template <${[...CiTemplates.SCHEME_SET].join('|')}>
12
- checks: ${[...CiChecks.SCHEME_SET].join(', ')}`;
13
-
14
- /** `vulcan ci`: which packages a change touches, and the CI templates that call it. */
15
- export class CiCommand {
16
- static async run(opts: ICommandContext): Promise<number> {
17
- const [subcommand, ...rest] = opts.args;
18
-
19
- if (subcommand === CiSubcommands.TEMPLATE) {
20
- return CiCommand.template({ args: rest });
21
- }
22
-
23
- if (subcommand === CiSubcommands.AFFECTED) {
24
- return CiCommand.affected({ cwd: opts.cwd, args: rest });
25
- }
26
-
27
- process.stderr.write(`ci: ${USAGE}\n`);
28
-
29
- return ExitCodes.USAGE;
30
- }
31
-
32
- private static template(opts: { args: string[] }): number {
33
- const [name, ...extra] = opts.args;
34
-
35
- if (name === undefined || extra.length > 0 || !CiTemplates.isValid(name)) {
36
- process.stderr.write(`ci: ${USAGE}\n`);
37
-
38
- return ExitCodes.USAGE;
39
- }
40
-
41
- process.stdout.write(
42
- readFileSync(
43
- join(BASE_DIRECTORY, CiConstants.TEMPLATE_FOLDER, CiTemplates.FILES[name]),
44
- 'utf8',
45
- ),
46
- );
47
-
48
- return ExitCodes.OK;
49
- }
50
-
51
- private static affected(opts: { cwd: string; args: string[] }): number {
52
- const parsed = CiCommand.parse({ args: opts.args });
53
-
54
- if (!parsed.ok) {
55
- process.stderr.write(`ci: ${parsed.error}\n${USAGE}\n`);
56
-
57
- return ExitCodes.USAGE;
58
- }
59
-
60
- const { base, head, check, json, names } = parsed;
61
- const run = CiAffected.run({ root: opts.cwd, base, head });
62
-
63
- if (!run.ok) {
64
- process.stderr.write(`ci: ${run.error}\n`);
65
-
66
- return ExitCodes.USAGE;
67
- }
68
-
69
- const result: IAffectedResult =
70
- check === undefined
71
- ? run.result
72
- : {
73
- ...run.result,
74
- packages: run.result.packages.filter((entry) => entry.checks[check] !== undefined),
75
- };
76
-
77
- if (json) {
78
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
79
- } else if (names) {
80
- process.stdout.write(result.packages.map((entry) => `${entry.name}\n`).join(''));
81
- } else {
82
- process.stdout.write(CiCommand.format({ result }));
83
- }
84
-
85
- return ExitCodes.OK;
86
- }
87
-
88
- private static parse(opts: { args: string[] }):
89
- | {
90
- ok: true;
91
- base: string;
92
- head: string;
93
- check: TCiCheck | undefined;
94
- json: boolean;
95
- names: boolean;
96
- }
97
- | { ok: false; error: string } {
98
- const values: Record<string, string> = {};
99
- let json = false;
100
- let names = false;
101
-
102
- for (let index = 0; index < opts.args.length; index++) {
103
- const arg = opts.args[index];
104
-
105
- if (arg === CiFlags.JSON) {
106
- json = true;
107
- continue;
108
- }
109
-
110
- if (arg === CiFlags.NAMES) {
111
- names = true;
112
- continue;
113
- }
114
-
115
- const value = opts.args[index + 1];
116
-
117
- if (value === undefined || Object.hasOwn(values, arg) || value.startsWith('-')) {
118
- return { ok: false, error: `${arg} needs a value, once` };
119
- }
120
-
121
- values[arg] = value;
122
- index++;
123
- }
124
-
125
- const base = values[CiFlags.BASE];
126
- const check = values[CiFlags.CHECK];
127
-
128
- if (base === undefined) {
129
- return { ok: false, error: `${CiFlags.BASE} is required` };
130
- }
131
-
132
- if (json && names) {
133
- return { ok: false, error: `${CiFlags.JSON} and ${CiFlags.NAMES} cannot be combined` };
134
- }
135
-
136
- if (check !== undefined && !CiChecks.isValid(check)) {
137
- return {
138
- ok: false,
139
- error: `${CiFlags.CHECK} must be one of ${[...CiChecks.SCHEME_SET].join(', ')}`,
140
- };
141
- }
142
-
143
- return {
144
- ok: true,
145
- base,
146
- head: values[CiFlags.HEAD] ?? 'HEAD',
147
- check: check as TCiCheck | undefined,
148
- json,
149
- names,
150
- };
151
- }
152
-
153
- private static format(opts: { result: IAffectedResult }): string {
154
- const { result } = opts;
155
- const header =
156
- result.all && result.allBecause !== undefined
157
- ? `all packages are affected: ${result.allBecause}\n`
158
- : '';
159
- const rows = result.packages.map(
160
- (entry) =>
161
- `${entry.name} ${entry.dir} ${entry.reason} ${Object.keys(entry.checks).join(',') || '-'}\n`,
162
- );
163
-
164
- return `${header}${rows.join('')}`;
165
- }
166
- }
@@ -1,76 +0,0 @@
1
- export class CiSubcommands {
2
- static readonly AFFECTED = 'affected';
3
- static readonly TEMPLATE = 'template';
4
- }
5
-
6
- export class CiFlags {
7
- static readonly BASE = '--base';
8
- static readonly HEAD = '--head';
9
- static readonly CHECK = '--check';
10
- static readonly JSON = '--json';
11
- static readonly NAMES = '--names';
12
- }
13
-
14
- /** The checks a package can have: each is the name of a `package.json` script, the standard names of an app. */
15
- export class CiChecks {
16
- static readonly TYPECHECK = 'typecheck';
17
- static readonly LINT = 'lint';
18
- static readonly TEST = 'test';
19
- static readonly COMPILE = 'compile';
20
-
21
- static readonly SCHEME_SET = new Set<string>([
22
- this.TYPECHECK,
23
- this.LINT,
24
- this.TEST,
25
- this.COMPILE,
26
- ]);
27
-
28
- static isValid(value: string): boolean {
29
- return this.SCHEME_SET.has(value);
30
- }
31
- }
32
-
33
- /** Why a package is on the list. */
34
- export class AffectedReasons {
35
- /** One of its files changed. */
36
- static readonly CHANGED = 'changed';
37
- /** A package it depends on is affected. */
38
- static readonly DEPENDENT = 'dependent';
39
- /** A file every package depends on changed, so all are on the list. */
40
- static readonly GLOBAL = 'global';
41
- }
42
-
43
- /** The CI systems that have a template. */
44
- export class CiTemplates {
45
- static readonly GITHUB = 'github';
46
- static readonly GITLAB = 'gitlab';
47
-
48
- static readonly FILES: Record<string, string> = {
49
- [this.GITHUB]: 'github-actions.yml',
50
- [this.GITLAB]: 'gitlab-ci.yml',
51
- };
52
-
53
- static readonly SCHEME_SET = new Set<string>([this.GITHUB, this.GITLAB]);
54
-
55
- static isValid(value: string): boolean {
56
- return this.SCHEME_SET.has(value);
57
- }
58
- }
59
-
60
- export class CiConstants {
61
- static readonly ROOT_MANIFEST = 'package.json';
62
- static readonly MANIFEST_FILE = '.agents/vulcan.manifest.json';
63
- /** The shipped list of files every package depends on, in the package's `base/`. */
64
- static readonly GLOBAL_FILE = 'ci-global.json';
65
- static readonly TEMPLATE_FOLDER = 'templates/ci';
66
- /** What a CI system passes as the base of a push that has no parent: nothing to compare with. */
67
- static readonly EMPTY_BASE = /^0{40}(?:0{24})?$/;
68
- static readonly DEPENDENCY_FIELDS = [
69
- 'dependencies',
70
- 'devDependencies',
71
- 'peerDependencies',
72
- 'optionalDependencies',
73
- ];
74
- static readonly GIT_TIMEOUT_MS = 30_000;
75
- static readonly GIT_MAX_BUFFER = 256 * 1024 * 1024;
76
- }
@@ -1,2 +0,0 @@
1
- export * from './constants.ts';
2
- export * from './types.ts';
@@ -1,37 +0,0 @@
1
- import type { TConstValue } from '../../common/index.ts';
2
- import type { AffectedReasons, CiChecks } from './constants.ts';
3
-
4
- export type TCiCheck = TConstValue<typeof CiChecks>;
5
- export type TAffectedReason = TConstValue<typeof AffectedReasons>;
6
-
7
- /** A package of the workspace, as its `package.json` says. */
8
- export interface IWorkspacePackage {
9
- name: string;
10
- /** Relative to the root, with `/`. */
11
- dir: string;
12
- scripts: Record<string, string>;
13
- /** Every dependency of every field: the name and the spec it is declared with. */
14
- dependencies: IDependency[];
15
- }
16
-
17
- export interface IDependency {
18
- name: string;
19
- spec: string;
20
- }
21
-
22
- export interface IAffectedPackage {
23
- name: string;
24
- dir: string;
25
- reason: TAffectedReason;
26
- /** The checks the package has: the check name to the script that runs it. */
27
- checks: Partial<Record<TCiCheck, string>>;
28
- }
29
-
30
- export interface IAffectedResult {
31
- base: string;
32
- head: string;
33
- /** Whether every package is on the list, and the file or the fact that made it so. */
34
- all: boolean;
35
- allBecause?: string;
36
- packages: IAffectedPackage[];
37
- }
package/src/ci/git.ts DELETED
@@ -1,72 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { CiConstants } from './common/index.ts';
3
-
4
- type TGitResult = { ok: true; stdout: string } | { ok: false; error: string };
5
-
6
- /** The few read-only git questions the command asks. */
7
- export class CiGit {
8
- static run(opts: { root: string; args: string[] }): TGitResult {
9
- const result = spawnSync('git', opts.args, {
10
- cwd: opts.root,
11
- encoding: 'utf8',
12
- timeout: CiConstants.GIT_TIMEOUT_MS,
13
- maxBuffer: CiConstants.GIT_MAX_BUFFER,
14
- });
15
-
16
- if (result.error !== undefined) {
17
- return { ok: false, error: `git could not run: ${result.error.message}` };
18
- }
19
-
20
- return result.status === 0
21
- ? { ok: true, stdout: result.stdout }
22
- : { ok: false, error: result.stderr.trim() || `git ${opts.args[0]} exited ${result.status}` };
23
- }
24
-
25
- /** The commit a revision names, or the reason it names none. */
26
- static resolve(opts: { root: string; ref: string }): TGitResult {
27
- const result = CiGit.run({
28
- root: opts.root,
29
- args: ['rev-parse', '--verify', '--quiet', '--end-of-options', `${opts.ref}^{commit}`],
30
- });
31
-
32
- return result.ok
33
- ? { ok: true, stdout: result.stdout.trim() }
34
- : {
35
- ok: false,
36
- error: `${opts.ref} is not a commit here (a shallow clone has only the recent ones: fetch-depth 0 in GitHub Actions, GIT_DEPTH 0 in GitLab CI)`,
37
- };
38
- }
39
-
40
- /** The files that differ between the merge base of two commits and the second one, deletions and both sides of a rename included. */
41
- static changedFiles(opts: {
42
- root: string;
43
- base: string;
44
- head: string;
45
- }): { ok: true; files: string[]; mergeBase: string } | { ok: false; error: string } {
46
- const mergeBase = CiGit.run({ root: opts.root, args: ['merge-base', opts.base, opts.head] });
47
-
48
- if (!mergeBase.ok) {
49
- return {
50
- ok: false,
51
- error: `${opts.base} and ${opts.head} share no history here (a shallow clone cuts it: fetch-depth 0 in GitHub Actions, GIT_DEPTH 0 in GitLab CI)`,
52
- };
53
- }
54
-
55
- const point = mergeBase.stdout.trim();
56
- const diff = CiGit.run({
57
- root: opts.root,
58
- args: ['diff', '--name-only', '--no-renames', '-z', point, opts.head],
59
- });
60
-
61
- return diff.ok
62
- ? { ok: true, files: diff.stdout.split('\0').filter((file) => file !== ''), mergeBase: point }
63
- : { ok: false, error: diff.error };
64
- }
65
-
66
- /** The text of a file at a commit, or `undefined` when the commit has no such file. */
67
- static show(opts: { root: string; commit: string; path: string }): string | undefined {
68
- const result = CiGit.run({ root: opts.root, args: ['show', `${opts.commit}:${opts.path}`] });
69
-
70
- return result.ok ? result.stdout : undefined;
71
- }
72
- }
package/src/ci/global.ts DELETED
@@ -1,48 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { BASE_DIRECTORY } from '../common/paths.ts';
4
- import { RecordValue } from '../common/record.ts';
5
- import { CiConstants } from './common/index.ts';
6
-
7
- /** The files every package depends on: when one changes, all of them are affected. */
8
- export class CiGlobal {
9
- /** The shipped list (data, `base/ci-global.json`) and the project's own from the manifest. */
10
- static read(opts: { root: string }): string[] {
11
- return [...CiGlobal.shipped(), ...CiGlobal.project({ root: opts.root })];
12
- }
13
-
14
- /** The first file of `files` that matches one of `globs` (root-relative, dotfiles included). */
15
- static firstHit(opts: { files: string[]; globs: string[] }): string | undefined {
16
- const matchers = opts.globs.map((glob) => new Bun.Glob(glob));
17
-
18
- return opts.files.find((file) => matchers.some((matcher) => matcher.match(file)));
19
- }
20
-
21
- private static shipped(): string[] {
22
- const list: unknown = JSON.parse(
23
- readFileSync(join(BASE_DIRECTORY, CiConstants.GLOBAL_FILE), 'utf8'),
24
- );
25
-
26
- return RecordValue.isRecord(list) ? CiGlobal.stringsOf({ value: list.files }) : [];
27
- }
28
-
29
- private static project(opts: { root: string }): string[] {
30
- try {
31
- const manifest: unknown = JSON.parse(
32
- readFileSync(join(opts.root, CiConstants.MANIFEST_FILE), 'utf8'),
33
- );
34
- const ci = RecordValue.isRecord(manifest) ? manifest.ci : undefined;
35
- const affected = RecordValue.isRecord(ci) ? ci.affected : undefined;
36
-
37
- return RecordValue.isRecord(affected) ? CiGlobal.stringsOf({ value: affected.global }) : [];
38
- } catch {
39
- return [];
40
- }
41
- }
42
-
43
- private static stringsOf(opts: { value: unknown }): string[] {
44
- return Array.isArray(opts.value)
45
- ? opts.value.filter((entry): entry is string => typeof entry === 'string' && entry !== '')
46
- : [];
47
- }
48
- }
package/src/ci/graph.ts DELETED
@@ -1,43 +0,0 @@
1
- import { AffectedReasons } from './common/index.ts';
2
- import type { IWorkspacePackage, TAffectedReason } from './common/index.ts';
3
-
4
- /** Who depends on whom, inside the workspace. */
5
- export class CiGraph {
6
- /**
7
- * `seeds` and every package that depends on one, directly or through others, each with the reason it is
8
- * on the list: a seed keeps its own, the others are `dependent`. A dependency on a workspace package
9
- * counts whatever its spec is (`workspace:*`, a range, `catalog:`), which can only add a package, never
10
- * lose one. Cycles end.
11
- */
12
- static closure(opts: {
13
- packages: IWorkspacePackage[];
14
- seeds: Map<string, TAffectedReason>;
15
- }): Map<string, TAffectedReason> {
16
- const names = new Set(opts.packages.map((entry) => entry.name));
17
- const dependents = new Map<string, string[]>();
18
-
19
- for (const entry of opts.packages) {
20
- for (const dependency of entry.dependencies) {
21
- if (names.has(dependency.name) && dependency.name !== entry.name) {
22
- dependents.set(dependency.name, [...(dependents.get(dependency.name) ?? []), entry.name]);
23
- }
24
- }
25
- }
26
-
27
- const reached = new Map<string, TAffectedReason>(opts.seeds);
28
- const queue = [...opts.seeds.keys()];
29
-
30
- while (queue.length > 0) {
31
- const name = queue.shift() ?? '';
32
-
33
- for (const dependent of dependents.get(name) ?? []) {
34
- if (!reached.has(dependent)) {
35
- reached.set(dependent, AffectedReasons.DEPENDENT);
36
- queue.push(dependent);
37
- }
38
- }
39
- }
40
-
41
- return reached;
42
- }
43
- }
package/src/ci/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './common/index.ts';
2
- export * from './affected.ts';
3
- export * from './command.ts';
4
- export * from './git.ts';
5
- export * from './global.ts';
6
- export * from './graph.ts';
7
- export * from './workspace.ts';