@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,212 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { existsSync, realpathSync } from 'node:fs';
3
- import { isAbsolute, join, relative, resolve, sep } from 'node:path';
4
- import { HookConstants, TrustStates } from './common/index.ts';
5
- import type { IReadOnlyScript, IScriptInvocation, IScriptTrust } from './common/index.ts';
6
- import { ShellParser } from './shell.ts';
7
-
8
- /** Variables that point git at another repository or index than the one in `cwd`. */
9
- const REDIRECTING_VARIABLES = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE'];
10
-
11
- /** Git mode of a symlink entry in the index. */
12
- const SYMLINK_MODE = '120000';
13
-
14
- /**
15
- * A read-only `git` query in `cwd`; `undefined` when git is missing, slow or answers with an error.
16
- * The variables that point git somewhere else are dropped, so the answer is about this checkout.
17
- */
18
- const gitQuery = (opts: { cwd: string; args: string[] }): string | undefined => {
19
- const env: Record<string, string | undefined> = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
20
-
21
- for (const name of REDIRECTING_VARIABLES) {
22
- delete env[name];
23
- }
24
-
25
- const result = spawnSync('git', opts.args, {
26
- cwd: opts.cwd,
27
- encoding: 'utf8',
28
- timeout: HookConstants.QUERY_TIMEOUT_MS,
29
- env,
30
- });
31
-
32
- return result.status === 0 ? result.stdout.trim() : undefined;
33
- };
34
-
35
- const untrusted = (opts: { state: IScriptTrust['state']; reason: string }): IScriptTrust => opts;
36
-
37
- export class ScriptPaths {
38
- /**
39
- * The script word as the shell opens it: joined to the working folder without folding `..`, so a link
40
- * before a `..` is followed the way the shell follows it.
41
- */
42
- static targetPath(opts: { target: string; cwd: string }): string {
43
- return isAbsolute(opts.target) ? opts.target : `${opts.cwd}${sep}${opts.target}`;
44
- }
45
-
46
- /** The file `path` is on disk, links followed by the OS; the path folded as written when nothing is there. */
47
- static physicalOf(opts: { path: string }): string {
48
- try {
49
- return realpathSync.native(opts.path);
50
- } catch {
51
- return resolve(opts.path);
52
- }
53
- }
54
- }
55
-
56
- export class ScriptTrust {
57
- /**
58
- * Whether the listed script `script` (repo-relative) may skip the script checks of guard-writes: only
59
- * while git tracks it and its worktree file, its index entry and HEAD hold the same bytes. A script an
60
- * agent edited and then runs is therefore checked like any other; so is one that was never committed.
61
- * The blobs are compared, not `git status`, so `--assume-unchanged` and `--skip-worktree` hide nothing.
62
- */
63
- static trustOf(opts: { root: string; script: string }): IScriptTrust {
64
- const path = resolve(opts.root, opts.script);
65
-
66
- if (!existsSync(path)) {
67
- return untrusted({ state: TrustStates.MISSING, reason: 'the file does not exist' });
68
- }
69
-
70
- const root = realpathSync(opts.root);
71
- const real = realpathSync(path);
72
-
73
- // A link could point at an untracked file that git never looks at.
74
- if (real !== join(root, relative(resolve(opts.root), path))) {
75
- return untrusted({
76
- state: TrustStates.SYMLINK,
77
- reason: 'its path goes through a symlink, which git does not follow',
78
- });
79
- }
80
-
81
- const repoPath = relative(root, real).split(sep).join('/');
82
- const entry = gitQuery({
83
- cwd: root,
84
- args: ['ls-files', '--stage', '--', `:(literal)${repoPath}`],
85
- });
86
-
87
- if (entry === undefined) {
88
- return untrusted({
89
- state: TrustStates.UNKNOWN,
90
- reason: 'git could not say whether it is tracked',
91
- });
92
- }
93
-
94
- if (entry === '') {
95
- return untrusted({ state: TrustStates.UNTRACKED, reason: 'it is not tracked by git' });
96
- }
97
-
98
- const [mode, indexBlob, stage] = entry.split('\n')[0].split(/\s+/);
99
-
100
- if (mode === SYMLINK_MODE) {
101
- return untrusted({
102
- state: TrustStates.SYMLINK,
103
- reason: 'it is a symlink, which git does not follow',
104
- });
105
- }
106
-
107
- if (stage !== '0') {
108
- return untrusted({
109
- state: TrustStates.MODIFIED,
110
- reason: 'modified trusted script (it has an unresolved merge)',
111
- });
112
- }
113
-
114
- const headBlob = gitQuery({
115
- cwd: root,
116
- args: ['rev-parse', '--verify', '--quiet', `HEAD:./${repoPath}`],
117
- });
118
-
119
- if (headBlob === undefined) {
120
- return untrusted({
121
- state: TrustStates.UNCOMMITTED,
122
- reason: 'it is not in the last commit yet',
123
- });
124
- }
125
-
126
- const workBlob = gitQuery({ cwd: root, args: ['hash-object', '--', real] });
127
-
128
- if (workBlob === undefined) {
129
- return untrusted({
130
- state: TrustStates.UNKNOWN,
131
- reason: 'git could not read the file',
132
- });
133
- }
134
-
135
- if (workBlob !== headBlob || indexBlob !== headBlob) {
136
- return untrusted({
137
- state: TrustStates.MODIFIED,
138
- reason: `modified trusted script (${workBlob === headBlob ? 'the index' : 'the working tree'} differs from the last commit)`,
139
- });
140
- }
141
-
142
- return { state: TrustStates.TRUSTED, reason: 'tracked, and identical to the last commit' };
143
- }
144
-
145
- /** The listed script `target` names, if any: both resolved to the file on disk, an exact match. */
146
- static listedOf(opts: {
147
- target: string;
148
- cwd: string;
149
- root: string;
150
- scripts: string[];
151
- }): string | undefined {
152
- const path = ScriptPaths.physicalOf({
153
- path: ScriptPaths.targetPath({ target: opts.target, cwd: opts.cwd }),
154
- });
155
-
156
- return opts.scripts.find(
157
- (script) => ScriptPaths.physicalOf({ path: resolve(opts.root, script) }) === path,
158
- );
159
- }
160
- }
161
-
162
- export class ReadOnlyScripts {
163
- /**
164
- * The `bun x.ts` calls of a command line, in order, one per simple command: the script word and the word
165
- * right after it. The words are the shell's own, so a quoted `"plan x"` stays one word and a `;` or `&&`
166
- * ends the command and is never part of one.
167
- */
168
- static extractInvocations(opts: { command: string }): IScriptInvocation[] {
169
- let moved = false;
170
-
171
- return ShellParser.parse({ command: opts.command }).flatMap((command) => {
172
- const { name, args } = ShellParser.programOf({ command });
173
- const program = ShellParser.basenameOf({ word: name });
174
-
175
- if (ReadOnlyScripts.MOVING_COMMANDS.has(program)) {
176
- moved = true;
177
- }
178
-
179
- if (program !== 'bun') {
180
- return [];
181
- }
182
-
183
- const [script, subcommand] = args[0] === 'run' ? args.slice(1) : args;
184
-
185
- return script !== undefined && script.endsWith('.ts') ? [{ script, subcommand, moved }] : [];
186
- });
187
- }
188
-
189
- /** Commands that change the folder the next commands of the line run in, which the hook does not follow. */
190
- static readonly MOVING_COMMANDS = new Set(['cd', 'pushd', 'popd']);
191
-
192
- /**
193
- * The listed script a call to `target` with `subcommand` is read-only for: both resolved to absolute
194
- * paths, the subcommand matched as one whole word. `undefined` when no entry covers this call.
195
- */
196
- static find(opts: {
197
- target: string;
198
- subcommand: string;
199
- cwd: string;
200
- root: string;
201
- entries: IReadOnlyScript[];
202
- }): string | undefined {
203
- return ScriptTrust.listedOf({
204
- target: opts.target,
205
- cwd: opts.cwd,
206
- root: opts.root,
207
- scripts: opts.entries
208
- .filter((entry) => entry.readOnly.includes(opts.subcommand))
209
- .map((entry) => entry.script),
210
- });
211
- }
212
- }
@@ -1,496 +0,0 @@
1
- import { OwnerDetails, OwnerLabelModes, OwnerSections } from './constants.ts';
2
- import type { IOwnerView } from './view.ts';
3
-
4
- /** What a reply can get wrong. A structural one can be blocked; a style one is only ever logged. */
5
- export class ShapeClasses {
6
- static readonly HEADLINE_NOT_SENTENCE = 'headline-not-sentence';
7
- static readonly HEADLINE_TOO_LONG = 'headline-too-long';
8
- static readonly MINIMAP_MISSING = 'minimap-missing';
9
- static readonly MINIMAP_STATUS = 'minimap-status';
10
- static readonly BLOCKED_MISSING = 'blocked-missing';
11
- static readonly DECISIONS_MISSING = 'decisions-missing';
12
- static readonly DECISIONS_MALFORMED = 'decisions-malformed';
13
- static readonly DECISIONS_NO_RECOMMENDATION = 'decisions-no-recommendation';
14
- static readonly SECTION_ORDER = 'section-order';
15
- static readonly EMOJI = 'emoji';
16
- static readonly SHOUTING = 'shouting';
17
- static readonly RELATIVE_PATH = 'relative-path';
18
- static readonly STRUCTURAL = new Set<string>([
19
- this.HEADLINE_NOT_SENTENCE,
20
- this.HEADLINE_TOO_LONG,
21
- this.MINIMAP_MISSING,
22
- this.MINIMAP_STATUS,
23
- this.BLOCKED_MISSING,
24
- this.DECISIONS_MISSING,
25
- this.DECISIONS_MALFORMED,
26
- this.DECISIONS_NO_RECOMMENDATION,
27
- this.SECTION_ORDER,
28
- ]);
29
- static readonly SCHEME_SET = new Set<string>([
30
- ...this.STRUCTURAL,
31
- this.EMOJI,
32
- this.SHOUTING,
33
- this.RELATIVE_PATH,
34
- ]);
35
- static isValid(value: string): boolean {
36
- return this.SCHEME_SET.has(value);
37
- }
38
- static isStructural(value: string): boolean {
39
- return this.STRUCTURAL.has(value);
40
- }
41
- }
42
-
43
- interface IShapeResult {
44
- /** False for an empty reply or a short one the view exempts. */
45
- isChecked: boolean;
46
- classes: string[];
47
- }
48
-
49
- const FENCE = /^\s*(?:```|~~~)/;
50
- const NOT_A_SENTENCE = /^(?:#{1,6}\s|\||[-*+]\s|\d+[.)]\s|>)/;
51
- const TABLE_ROW = /^\s*\|.*\|\s*$/;
52
- /** Emphasis and quoting marks a label may be wrapped in: `**Blocked:**`, `*Blocked:*`, `__Blocked:__`. */
53
- const MARKS = /[*_`]/g;
54
- /** What may open a line before its text: a quote, a heading, a list marker or a table edge. */
55
- const LINE_OPENER = /^\s*(?:>\s*)*(?:#{1,6}\s+|[-*+]\s+|\d+[.)]\s+|\|\s*)?/;
56
- const ABBREVIATIONS = /\b(?:etc|e\.g|i\.e|vs|mr|mrs|ms|dr|approx|cf)\./gi;
57
-
58
- /** The reply without fenced code, one line per entry: code is data, never structure. An unclosed fence is not one. */
59
- const proseLinesOf = (opts: { text: string }): string[] => {
60
- const all = opts.text.split(/\r?\n/);
61
-
62
- if (all.filter((line) => FENCE.test(line)).length % 2 === 1) {
63
- return all;
64
- }
65
-
66
- const lines: string[] = [];
67
- let isFenced = false;
68
-
69
- for (const line of all) {
70
- if (FENCE.test(line)) {
71
- isFenced = !isFenced;
72
-
73
- continue;
74
- }
75
-
76
- if (!isFenced) {
77
- lines.push(line);
78
- }
79
- }
80
-
81
- return lines;
82
- };
83
-
84
- const plainOf = (opts: { text: string }): string => opts.text.replace(MARKS, '').trim();
85
-
86
- /** A line's words as compared: the opener, the emphasis and a closing full stop gone, lower case. */
87
- const normalizedOf = (opts: { line: string }): string =>
88
- plainOf({ text: opts.line.replace(LINE_OPENER, '') })
89
- .replace(/\s+/g, ' ')
90
- .toLowerCase();
91
-
92
- const cellsOf = (opts: { line: string }): string[] =>
93
- opts.line
94
- .trim()
95
- .replace(/^\|/, '')
96
- .replace(/\|$/, '')
97
- .split(/(?<!\\)\|/)
98
- .map((cell) => plainOf({ text: cell }));
99
-
100
- /** Sentences of one paragraph, counting no full stop inside backticks, in a number or an abbreviation. */
101
- const sentenceCountOf = (opts: { paragraph: string }): number => {
102
- const text = opts.paragraph
103
- .replace(/`[^`]*`/g, 'x')
104
- .replace(/\d\.\d/g, '0')
105
- .replace(ABBREVIATIONS, 'x');
106
-
107
- return text.split(/(?<=[.!?…。!?])\s+(?=\S)/).filter((part) => part.trim() !== '').length;
108
- };
109
-
110
- /** The first line at or after `from` whose words start with `label`, or -1. */
111
- const findLabelFrom = (opts: { lines: string[]; label: string; from: number }): number => {
112
- const label = normalizedOf({ line: opts.label });
113
-
114
- for (let at = opts.from; at < opts.lines.length; at += 1) {
115
- if (normalizedOf({ line: opts.lines[at] ?? '' }).startsWith(label)) {
116
- return at;
117
- }
118
- }
119
-
120
- return -1;
121
- };
122
-
123
- interface IFound {
124
- /** The line, or -1 when the section is nowhere. */
125
- at: number;
126
- problems: string[];
127
- }
128
-
129
- const headlineOf = (opts: {
130
- lines: string[];
131
- view: IOwnerView;
132
- }): { end: number; problems: string[] } => {
133
- const start = opts.lines.findIndex((line) => line.trim() !== '');
134
-
135
- if (start === -1) {
136
- return { end: 0, problems: [] };
137
- }
138
-
139
- if (NOT_A_SENTENCE.test(opts.lines[start]?.trim() ?? '')) {
140
- return { end: start + 1, problems: [ShapeClasses.HEADLINE_NOT_SENTENCE] };
141
- }
142
-
143
- const paragraph: string[] = [];
144
- let end = start;
145
-
146
- for (const line of opts.lines.slice(start)) {
147
- if (line.trim() === '') {
148
- break;
149
- }
150
-
151
- paragraph.push(line.trim());
152
- end += 1;
153
- }
154
-
155
- return {
156
- end,
157
- problems:
158
- sentenceCountOf({ paragraph: paragraph.join(' ') }) > opts.view.headlineMaxSentences
159
- ? [ShapeClasses.HEADLINE_TOO_LONG]
160
- : [],
161
- };
162
- };
163
-
164
- const minimapFrom = (opts: { lines: string[]; view: IOwnerView; from: number }): IFound => {
165
- const { labels } = opts.view;
166
- const expected = labels.minimapColumns.map((column) => column.toLowerCase());
167
- const at = opts.lines.findIndex(
168
- (line, index) =>
169
- index >= opts.from &&
170
- TABLE_ROW.test(line) &&
171
- expected.every(
172
- (column, position) => (cellsOf({ line })[position] ?? '').toLowerCase() === column,
173
- ),
174
- );
175
-
176
- if (at === -1) {
177
- return { at, problems: [ShapeClasses.MINIMAP_MISSING] };
178
- }
179
-
180
- const statuses = new Set(Object.values(labels.status).map((status) => status.toLowerCase()));
181
- const rows: string[][] = [];
182
-
183
- for (const line of opts.lines.slice(at + 2)) {
184
- if (!TABLE_ROW.test(line)) {
185
- break;
186
- }
187
-
188
- rows.push(cellsOf({ line }));
189
- }
190
-
191
- const isWrong = rows.some(
192
- (cells) =>
193
- !statuses.has(
194
- (cells[2] ?? '')
195
- .replace(/\s*\(.*\)\s*$/, '')
196
- .trim()
197
- .toLowerCase(),
198
- ),
199
- );
200
-
201
- return { at, problems: isWrong ? [ShapeClasses.MINIMAP_STATUS] : [] };
202
- };
203
-
204
- /** `prefix {x} suffix` as its two ends, emphasis and a closing full stop removed, lower case. */
205
- const recommendationEndsOf = (opts: { template: string }): { prefix: string; suffix: string } => {
206
- const [before = '', after = ''] = opts.template.split('{x}');
207
- const clean = (text: string): string => plainOf({ text }).replace(/\.$/, '').toLowerCase();
208
-
209
- return { prefix: clean(before), suffix: clean(after) };
210
- };
211
-
212
- const decisionsFrom = (opts: { lines: string[]; view: IOwnerView; from: number }): IFound => {
213
- const { labels } = opts.view.labels;
214
- const at = findLabelFrom({ lines: opts.lines, label: labels.decisions, from: opts.from });
215
-
216
- if (at === -1) {
217
- return { at, problems: [ShapeClasses.DECISIONS_MISSING] };
218
- }
219
-
220
- const none = normalizedOf({ line: labels.noDecision }).replace(/\.$/, '');
221
- const same = normalizedOf({ line: opts.lines[at] ?? '' })
222
- .slice(normalizedOf({ line: labels.decisions }).length)
223
- .replace(/^[:\s-]+/, '')
224
- .replace(/\.$/, '');
225
- const after = opts.lines.slice(at + 1);
226
- const first = after.find((line) => line.trim() !== '');
227
-
228
- if (
229
- same === none ||
230
- (same === '' &&
231
- first !== undefined &&
232
- normalizedOf({ line: first }).replace(/\.$/, '') === none)
233
- ) {
234
- return { at, problems: [] };
235
- }
236
-
237
- const items: string[] = [];
238
-
239
- for (const line of after) {
240
- if (/^\s*\d+[.)]\s/.test(line)) {
241
- items.push(line.trim());
242
- } else if (items.length > 0 && /^\s*#{1,6}\s/.test(line)) {
243
- break;
244
- } else if (items.length > 0 && line.trim() !== '' && /^\s/.test(line)) {
245
- items[items.length - 1] = `${items[items.length - 1]} ${line.trim()}`;
246
- } else if (items.length > 0 && line.trim() !== '') {
247
- break;
248
- }
249
- }
250
-
251
- if (items.length === 0) {
252
- return { at, problems: [ShapeClasses.DECISIONS_MALFORMED] };
253
- }
254
-
255
- const { prefix, suffix } = recommendationEndsOf({ template: labels.recommend });
256
- const hasRecommendation = (item: string): boolean => {
257
- const text = plainOf({ text: item }).replace(/\.$/, '').toLowerCase();
258
- const where = prefix === '' ? 0 : text.lastIndexOf(prefix);
259
-
260
- return (
261
- where !== -1 &&
262
- text.length - where - prefix.length - suffix.length > 0 &&
263
- (suffix === '' || text.endsWith(suffix) || text.slice(where).includes(suffix))
264
- );
265
- };
266
-
267
- return {
268
- at,
269
- problems: items.every(hasRecommendation) ? [] : [ShapeClasses.DECISIONS_NO_RECOMMENDATION],
270
- };
271
- };
272
-
273
- // ---- the free label mode: no word is expected, only the structure ----
274
-
275
- const TABLE_SEPARATOR = /^\s*\|?\s*:?-{2,}:?\s*(?:\|\s*:?-{2,}:?\s*)+\|?\s*$/;
276
- /** A short label ending in a colon, as the first words of a line: `Label: text`, `**Label:** text`, `- **Label**: text`. */
277
- const LABEL_LINE =
278
- /^\s*(?:>\s*)*(?:[-*+]\s+)?(?:\*\*|__)?([^\s:|#*_`][^:|`*_\n]{0,39}?)(?:\*\*|__)?\s*[::]\s*(?:\*\*|__)?\s*(.*)$/u;
279
- const MARKDOWN_HEADING = /^\s*#{1,6}\s+\S/;
280
- const BOLD_ONLY_LINE = /^\s*(?:\*\*|__)[^*_]{1,60}(?:\*\*|__)\s*:?\s*$/;
281
- const NUMBERED_ITEM = /^\s*\d+[.)]\s/;
282
- const FREE_LABEL_MAX_WORDS = 5;
283
- const FREE_NONE_LINE_MAX_CHARACTERS = 160;
284
-
285
- /** The label and the text after it when the line is a labelled line, else undefined. */
286
- const labelLineOf = (opts: { line: string }): { label: string; rest: string } | undefined => {
287
- const match = LABEL_LINE.exec(opts.line);
288
- const label = match?.[1]?.trim() ?? '';
289
- const rest = match?.[2]?.trim() ?? '';
290
-
291
- return label !== '' &&
292
- /\p{L}/u.test(label) &&
293
- label.split(/\s+/).length <= FREE_LABEL_MAX_WORDS &&
294
- !rest.startsWith('//')
295
- ? { label, rest }
296
- : undefined;
297
- };
298
-
299
- /** A table (a header row, its separator row) from `from`, whatever its words. */
300
- const freeMinimapFrom = (opts: { lines: string[]; from: number }): IFound => {
301
- const at = opts.lines.findIndex(
302
- (line, index) =>
303
- index >= opts.from &&
304
- TABLE_ROW.test(line) &&
305
- cellsOf({ line }).length >= 3 &&
306
- TABLE_SEPARATOR.test(opts.lines[index + 1] ?? ''),
307
- );
308
-
309
- return { at, problems: at === -1 ? [ShapeClasses.MINIMAP_MISSING] : [] };
310
- };
311
-
312
- /** The first labelled line outside a table from `from`: the blocker, or the word for none. */
313
- const freeBlockedFrom = (opts: { lines: string[]; from: number }): IFound => {
314
- const at = opts.lines.findIndex(
315
- (line, index) =>
316
- index >= opts.from && !TABLE_ROW.test(line) && labelLineOf({ line }) !== undefined,
317
- );
318
-
319
- return { at, problems: at === -1 ? [ShapeClasses.BLOCKED_MISSING] : [] };
320
- };
321
-
322
- /**
323
- * A decisions heading (a markdown heading, a bold-only line, or a label ending in a colon) followed by a
324
- * numbered list or by one short line, or a last line that is a label with the none text after it.
325
- */
326
- const freeDecisionsFrom = (opts: { lines: string[]; from: number }): IFound => {
327
- const lastText = opts.lines.findLastIndex((line) => line.trim() !== '');
328
- const isHeading = (index: number): boolean => {
329
- const line = opts.lines[index] ?? '';
330
- const labelled = labelLineOf({ line });
331
-
332
- return (
333
- MARKDOWN_HEADING.test(line) ||
334
- BOLD_ONLY_LINE.test(line) ||
335
- (labelled !== undefined && (labelled.rest === '' || index === lastText))
336
- );
337
- };
338
- const headings: number[] = [];
339
-
340
- for (let at = opts.from; at < opts.lines.length; at += 1) {
341
- if (isHeading(at)) {
342
- headings.push(at);
343
- }
344
- }
345
-
346
- if (headings.length === 0) {
347
- return { at: -1, problems: [ShapeClasses.DECISIONS_MISSING] };
348
- }
349
-
350
- for (const [position, heading] of headings.entries()) {
351
- const content = opts.lines
352
- .slice(heading + 1, headings[position + 1] ?? opts.lines.length)
353
- .filter((line) => line.trim() !== '');
354
- const own = labelLineOf({ line: opts.lines[heading] ?? '' });
355
- const isNoneOnTheLine = own !== undefined && own.rest !== '' && heading === lastText;
356
- const isShortLine =
357
- content.length === 1 &&
358
- !NOT_A_SENTENCE.test(content[0]?.trim() ?? '') &&
359
- (content[0]?.trim().length ?? 0) <= FREE_NONE_LINE_MAX_CHARACTERS;
360
-
361
- if (isNoneOnTheLine || content.some((line) => NUMBERED_ITEM.test(line)) || isShortLine) {
362
- return { at: heading, problems: [] };
363
- }
364
- }
365
-
366
- return { at: headings[0] ?? -1, problems: [ShapeClasses.DECISIONS_MALFORMED] };
367
- };
368
-
369
- const styleProblems = (opts: { lines: string[]; view: IOwnerView }): string[] => {
370
- // The owner's own status words and labels may carry symbols: they are the shape, not a fault.
371
- const configured = [
372
- ...Object.values(opts.view.labels.status),
373
- ...Object.values(opts.view.labels.labels),
374
- ].sort((first, second) => second.length - first.length);
375
- const prose = configured.reduce(
376
- (text, word) => text.replaceAll(word, ' '),
377
- opts.lines.map((line) => line.replace(/`[^`]*`/g, '')).join('\n'),
378
- );
379
- const classes: string[] = [];
380
-
381
- if (/\p{Emoji_Presentation}/u.test(prose)) {
382
- classes.push(ShapeClasses.EMOJI);
383
- }
384
-
385
- if (/\b[A-Z]{4,}(?:\s+[A-Z]{4,})+\b/.test(prose)) {
386
- classes.push(ShapeClasses.SHOUTING);
387
- }
388
-
389
- if (opts.view.absolutePaths) {
390
- const spans = opts.lines.flatMap((line) =>
391
- [...line.matchAll(/`([^`]+)`/g)].map((match) => match[1]),
392
- );
393
-
394
- if (
395
- spans.some((span) =>
396
- /^(?![/~]|[a-z]+:)[\w.-]+(?:\/[\w.@-]+)+\.[a-z0-9]{1,6}$/i.test(span ?? ''),
397
- )
398
- ) {
399
- classes.push(ShapeClasses.RELATIVE_PATH);
400
- }
401
- }
402
-
403
- return classes;
404
- };
405
-
406
- export class OwnerShape {
407
- /**
408
- * Checks one reply to the owner against the resolved shape: a headline that is a sentence within the
409
- * cap, the minimap table with the configured header and only the configured statuses, the Blocked line,
410
- * the decisions list with the recommendation in each item or exactly the none string, and the order. Each
411
- * section is looked for after the one before it, so a headline that begins with a label is still a
412
- * headline. Pure and deterministic; what it cannot see (whether a point has a plain meaning, whether the
413
- * answer is right) is for an eval or the owner. A reply under `shortReplyWords` is exempt, and a person
414
- * who asked for headline-only reports is held to the headline and the style only. In the `free` label mode
415
- * (a language that is not English with no label set) no word is expected: the table, a labelled blocker
416
- * line and a decisions heading with a numbered list or one line are looked for, and the status words and
417
- * the recommendation are not checked.
418
- */
419
- static check(opts: { text: string; view: IOwnerView }): IShapeResult {
420
- const { text, view } = opts;
421
-
422
- if (text.trim() === '' || text.trim().split(/\s+/).length < view.shortReplyWords) {
423
- return { isChecked: false, classes: [] };
424
- }
425
-
426
- const lines = proseLinesOf({ text });
427
- const classes: string[] = [];
428
- const isHeadlineOnly = view.reportDetail === OwnerDetails.HEADLINE;
429
- let cursor = 0;
430
- let isOutOfOrder = false;
431
-
432
- for (const section of view.shape) {
433
- if (section === OwnerSections.HEADLINE) {
434
- const found = headlineOf({ lines, view });
435
-
436
- classes.push(...found.problems);
437
- cursor = found.end;
438
-
439
- continue;
440
- }
441
-
442
- if (isHeadlineOnly) {
443
- continue;
444
- }
445
-
446
- const isFree = view.labelMode === OwnerLabelModes.FREE;
447
- const run = (from: number): IFound => {
448
- if (section === OwnerSections.MINIMAP) {
449
- return isFree ? freeMinimapFrom({ lines, from }) : minimapFrom({ lines, view, from });
450
- }
451
-
452
- if (section === OwnerSections.BLOCKED) {
453
- if (isFree) {
454
- return freeBlockedFrom({ lines, from });
455
- }
456
-
457
- const at = findLabelFrom({ lines, label: view.labels.labels.blocked, from });
458
-
459
- return { at, problems: at === -1 ? [ShapeClasses.BLOCKED_MISSING] : [] };
460
- }
461
-
462
- if (section === OwnerSections.DECISIONS) {
463
- return isFree ? freeDecisionsFrom({ lines, from }) : decisionsFrom({ lines, view, from });
464
- }
465
-
466
- return { at: -1, problems: [] };
467
- };
468
- const after = run(cursor);
469
-
470
- if (after.at !== -1 || section === OwnerSections.DETAIL) {
471
- classes.push(...after.problems);
472
- cursor = after.at === -1 ? cursor : after.at + 1;
473
-
474
- continue;
475
- }
476
-
477
- // Not after the section before it: present earlier means out of order, nowhere means missing.
478
- const anywhere = run(0);
479
-
480
- if (anywhere.at === -1) {
481
- classes.push(...anywhere.problems);
482
- } else {
483
- isOutOfOrder = true;
484
- classes.push(...anywhere.problems);
485
- }
486
- }
487
-
488
- if (isOutOfOrder) {
489
- classes.push(ShapeClasses.SECTION_ORDER);
490
- }
491
-
492
- classes.push(...styleProblems({ lines, view }));
493
-
494
- return { isChecked: true, classes: [...new Set(classes)] };
495
- }
496
- }