@venizia/vulcan 0.3.13 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/claude/remote-hosts.json +1 -1
- package/base/claude/settings.json +75 -3
- package/base/hooks/guard-git.ts +55 -0
- package/base/hooks/guard-manifest.ts +1 -1
- package/base/hooks/guard-outside.ts +66 -0
- package/base/hooks/guard-package.ts +3 -2
- package/base/hooks/guard-remote-hosts.ts +3 -2
- package/base/hooks/guard-writes.ts +1 -1
- package/base/hooks/post-tool.ts +36 -0
- package/base/hooks/prompt-submit.ts +52 -0
- package/base/hooks/stop.ts +38 -0
- package/base/hooks/subagent-start.ts +18 -0
- package/base/references/delegation-brief.md +63 -0
- package/base/references/design-pass.md +39 -0
- package/base/references/evidence.md +36 -0
- package/base/references/phase-boundaries.md +20 -0
- package/base/references/testing.md +89 -0
- package/base/rules.md +11 -2
- package/base/skills/build-a-feature/SKILL.md +49 -23
- package/base/skills/docs-update/SKILL.md +12 -1
- package/base/skills/docs-writing/SKILL.md +2 -2
- package/base/skills/docs-writing/references/agent-documents.md +53 -0
- package/base/skills/fix-a-bug/SKILL.md +84 -0
- package/base/skills/fix-a-bug/evals/evals.json +17 -0
- package/base/skills/knowledge-sync/SKILL.md +4 -1
- package/base/skills/knowledge-sync/knowledge-sync.workflow.js +10 -10
- package/base/skills/plan-a-change/SKILL.md +95 -0
- package/base/skills/plan-a-change/evals/evals.json +23 -0
- package/base/skills/plan-a-change/references/spec-card.md +39 -0
- package/base/skills/report-back/SKILL.md +112 -0
- package/base/skills/report-back/evals/evals.json +23 -0
- package/base/skills/research/SKILL.md +64 -0
- package/base/skills/research/evals/evals.json +17 -0
- package/base/skills/retro/SKILL.md +69 -0
- package/base/skills/retro/evals/evals.json +17 -0
- package/base/skills/review-a-change/SKILL.md +90 -0
- package/base/skills/review-a-change/evals/evals.json +17 -0
- package/base/skills/ship/SKILL.md +82 -0
- package/base/skills/ship/evals/evals.json +23 -0
- package/base/skills/visualize-work/SKILL.md +87 -0
- package/base/skills/visualize-work/evals/evals.json +17 -0
- package/base/skills/visualize-work/references/spec.md +65 -0
- package/package.json +4 -4
- package/src/agents/common/schema.ts +2 -2
- package/src/agents/detect.ts +5 -5
- package/src/agents/exclude.ts +3 -3
- package/src/agents/local.ts +1 -1
- package/src/agents/prompt.ts +2 -2
- package/src/agents/render.ts +2 -2
- package/src/agents/resolve.ts +6 -6
- package/src/agents/table.ts +1 -1
- package/src/commands/agents.command.ts +4 -4
- package/src/commands/clean.command.ts +72 -0
- package/src/commands/help.command.ts +11 -0
- package/src/commands/index.ts +6 -0
- package/src/commands/init.command.ts +4 -1
- package/src/commands/profile.command.ts +255 -0
- package/src/commands/sync.command.ts +6 -4
- package/src/commands/upgrade.command.ts +1 -1
- package/src/commands/visualize.command.ts +107 -0
- package/src/common/constants.ts +23 -0
- package/src/config/common/constants.ts +2 -0
- package/src/config/loader.ts +4 -4
- package/src/config/packages.ts +1 -1
- package/src/config/schema.ts +16 -5
- package/src/create/add-app.ts +15 -15
- package/src/create/add-lib.ts +7 -7
- package/src/create/bunfig.ts +1 -1
- package/src/create/dockerignore.ts +4 -4
- package/src/create/init-monorepo.ts +3 -1
- package/src/create/lib-preset.ts +1 -1
- package/src/create/names.ts +7 -6
- package/src/create/next.ts +4 -4
- package/src/create/preset-menu.ts +4 -4
- package/src/create/preset.ts +3 -3
- package/src/create/scratch.ts +27 -6
- package/src/create/workspace.ts +11 -11
- package/src/doctor/checks.ts +231 -45
- package/src/doctor/common/constants.ts +4 -0
- package/src/doctor/makefile.ts +3 -3
- package/src/doctor/runner.ts +16 -1
- package/src/doctor/skills.ts +8 -8
- package/src/doctor/tags.ts +5 -5
- package/src/hooks/common/constants.ts +29 -0
- package/src/hooks/common/types.ts +20 -0
- package/src/hooks/decision.ts +15 -0
- package/src/hooks/guard-git.ts +288 -0
- package/src/hooks/guard-manifest.ts +1 -1
- package/src/hooks/guard-outside.ts +399 -0
- package/src/hooks/guard-package.ts +4 -4
- package/src/hooks/guard-writes.ts +5 -5
- package/src/hooks/index.ts +6 -0
- package/src/hooks/owner-reply.ts +148 -0
- package/src/hooks/post-tool.ts +137 -0
- package/src/hooks/remote-hosts.ts +25 -23
- package/src/hooks/session-digest.ts +24 -4
- package/src/hooks/shell.ts +325 -0
- package/src/hooks/subagent-card.ts +32 -0
- package/src/init/scaffold.ts +6 -6
- package/src/local/clean.ts +88 -0
- package/src/local/constants.ts +50 -0
- package/src/local/format.ts +25 -0
- package/src/local/index.ts +4 -0
- package/src/local/scan.ts +368 -0
- package/src/manifest/render.ts +1 -1
- package/src/owner/card.ts +85 -0
- package/src/owner/constants.ts +105 -0
- package/src/owner/index.ts +8 -0
- package/src/owner/profile.ts +123 -0
- package/src/owner/schema.ts +147 -0
- package/src/owner/shape.ts +380 -0
- package/src/owner/survey.ts +289 -0
- package/src/owner/view.ts +76 -0
- package/src/owner/violations.ts +202 -0
- package/src/router.ts +18 -1
- package/src/rules/base.ts +1 -1
- package/src/rules/parser.ts +5 -5
- package/src/signals/claims.ts +71 -0
- package/src/signals/classify.ts +132 -0
- package/src/signals/constants.ts +88 -0
- package/src/signals/index.ts +5 -0
- package/src/signals/loop.ts +46 -0
- package/src/signals/state.ts +276 -0
- package/src/sync/agent-files.ts +4 -4
- package/src/sync/agent-removal.ts +6 -6
- package/src/sync/atlas-block.ts +1 -1
- package/src/sync/base-rules.ts +1 -1
- package/src/sync/exclude.ts +9 -9
- package/src/sync/local-choice.ts +35 -5
- package/src/sync/planner.ts +16 -16
- package/src/sync/prune.ts +3 -3
- package/src/sync/settings.ts +15 -15
- package/src/ui/prompt.ts +3 -3
- package/src/visualize/assets.ts +80 -0
- package/src/visualize/constants.ts +126 -0
- package/src/visualize/index.ts +6 -0
- package/src/visualize/layout.ts +107 -0
- package/src/visualize/page.ts +211 -0
- package/src/visualize/render.ts +161 -0
- package/src/visualize/schema.ts +178 -0
- package/src/visualize/validate.ts +127 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import {
|
|
3
|
+
OwnerConstants,
|
|
4
|
+
OwnerDetails,
|
|
5
|
+
OwnerEnforcement,
|
|
6
|
+
OwnerFormalities,
|
|
7
|
+
OwnerSections,
|
|
8
|
+
OwnerTones,
|
|
9
|
+
} from './constants.ts';
|
|
10
|
+
|
|
11
|
+
const TEXT = z.string().regex(OwnerConstants.LABEL_PATTERN, {
|
|
12
|
+
message: 'one line of at most 80 characters, with no backtick, pipe or quote',
|
|
13
|
+
});
|
|
14
|
+
const LANGUAGE = z.string().regex(OwnerConstants.LANGUAGE_PATTERN, {
|
|
15
|
+
message: 'a language code such as en or pt-BR',
|
|
16
|
+
});
|
|
17
|
+
const choice = (opts: { isValid: (value: string) => boolean; set: Set<string> }) =>
|
|
18
|
+
z.string().refine((value) => opts.isValid(value), {
|
|
19
|
+
message: `one of: ${[...opts.set].join(', ')}`,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const SECTION = choice({
|
|
23
|
+
isValid: (value) => OwnerSections.isValid(value),
|
|
24
|
+
set: OwnerSections.SCHEME_SET,
|
|
25
|
+
});
|
|
26
|
+
const ENFORCE = choice({
|
|
27
|
+
isValid: (value) => OwnerEnforcement.isValid(value),
|
|
28
|
+
set: OwnerEnforcement.SCHEME_SET,
|
|
29
|
+
});
|
|
30
|
+
const TONE = choice({ isValid: (value) => OwnerTones.isValid(value), set: OwnerTones.SCHEME_SET });
|
|
31
|
+
const FORMALITY = choice({
|
|
32
|
+
isValid: (value) => OwnerFormalities.isValid(value),
|
|
33
|
+
set: OwnerFormalities.SCHEME_SET,
|
|
34
|
+
});
|
|
35
|
+
const DETAIL = choice({
|
|
36
|
+
isValid: (value) => OwnerDetails.isValid(value),
|
|
37
|
+
set: OwnerDetails.SCHEME_SET,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/** A phrase, not a stray letter pair: at least three characters, one of them not a space. */
|
|
41
|
+
const CLAIM_WORDS = z
|
|
42
|
+
.array(
|
|
43
|
+
z
|
|
44
|
+
.string()
|
|
45
|
+
.max(60)
|
|
46
|
+
.regex(/^(?=.*\S).{3,}$/u),
|
|
47
|
+
)
|
|
48
|
+
.max(20);
|
|
49
|
+
const SHORT_REPLY_WORDS = z.number().int().min(0).max(OwnerConstants.MAX_SHORT_REPLY_WORDS);
|
|
50
|
+
|
|
51
|
+
const DEFAULTS = OwnerConstants.DEFAULT_LABELS;
|
|
52
|
+
|
|
53
|
+
/** The words of one language: the minimap header, the six statuses and five labels. A closed list. */
|
|
54
|
+
export const OWNER_LABEL_SET = z.strictObject({
|
|
55
|
+
minimapColumns: z.tuple([TEXT, TEXT, TEXT]),
|
|
56
|
+
status: z.strictObject({
|
|
57
|
+
done: TEXT,
|
|
58
|
+
doing: TEXT,
|
|
59
|
+
waiting: TEXT,
|
|
60
|
+
todo: TEXT,
|
|
61
|
+
blocked: TEXT,
|
|
62
|
+
dropped: TEXT,
|
|
63
|
+
}),
|
|
64
|
+
labels: z.strictObject({
|
|
65
|
+
blocked: TEXT,
|
|
66
|
+
decisions: TEXT,
|
|
67
|
+
noBlocker: TEXT,
|
|
68
|
+
noDecision: TEXT,
|
|
69
|
+
/** `{x}` is where the recommended answer goes. */
|
|
70
|
+
recommend: TEXT.refine((value) => value.includes('{x}'), { message: 'must contain {x}' }),
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The project's report contract for answers to its owners: the shape, the status words, the labels and
|
|
76
|
+
* how hard the shape is held. English and `advise` unless the project says otherwise. A person's own
|
|
77
|
+
* language, address and tone live in their profile (`.agents/local/profile.json`), not here.
|
|
78
|
+
*/
|
|
79
|
+
export const OWNER_SCHEMA = z
|
|
80
|
+
.strictObject({
|
|
81
|
+
language: LANGUAGE.default(OwnerConstants.DEFAULT_LANGUAGE),
|
|
82
|
+
report: z
|
|
83
|
+
.strictObject({
|
|
84
|
+
shape: z.array(SECTION).min(1).default(OwnerConstants.DEFAULT_SHAPE),
|
|
85
|
+
minimapColumns: z.tuple([TEXT, TEXT, TEXT]).default(DEFAULTS.minimapColumns),
|
|
86
|
+
status: OWNER_LABEL_SET.shape.status.default(DEFAULTS.status),
|
|
87
|
+
labels: OWNER_LABEL_SET.shape.labels.default(DEFAULTS.labels),
|
|
88
|
+
headlineMaxSentences: z
|
|
89
|
+
.number()
|
|
90
|
+
.int()
|
|
91
|
+
.min(1)
|
|
92
|
+
.max(5)
|
|
93
|
+
.default(OwnerConstants.DEFAULT_HEADLINE_MAX_SENTENCES),
|
|
94
|
+
absolutePaths: z.boolean().default(true),
|
|
95
|
+
enforce: ENFORCE.default(OwnerEnforcement.ADVISE),
|
|
96
|
+
/** Words that say something is in public state, or that the checks pass, in the owner's language, added to the English ones. */
|
|
97
|
+
claimWords: z
|
|
98
|
+
.strictObject({
|
|
99
|
+
public: CLAIM_WORDS.default([]),
|
|
100
|
+
done: CLAIM_WORDS.default([]),
|
|
101
|
+
})
|
|
102
|
+
.prefault({}),
|
|
103
|
+
/** Replies under this many words are exempt from the shape; 0 holds every reply to it. */
|
|
104
|
+
shortReplyWords: SHORT_REPLY_WORDS.default(OwnerConstants.DEFAULT_SHORT_REPLY_WORDS),
|
|
105
|
+
})
|
|
106
|
+
.prefault({}),
|
|
107
|
+
})
|
|
108
|
+
.prefault({});
|
|
109
|
+
|
|
110
|
+
/** `.agents/local/profile.json`: what one developer told VULCAN about how to work with them. */
|
|
111
|
+
export const PROFILE_SCHEMA = z.strictObject({
|
|
112
|
+
schemaVersion: z.literal(OwnerConstants.PROFILE_SCHEMA_VERSION),
|
|
113
|
+
/** Reply language; labels for it come from `labels` below, else English. */
|
|
114
|
+
language: LANGUAGE.optional(),
|
|
115
|
+
address: z
|
|
116
|
+
.strictObject({
|
|
117
|
+
/** How to address the person: a name, a pronoun, an honorific, or nothing. */
|
|
118
|
+
you: TEXT.optional(),
|
|
119
|
+
/** How the agent refers to itself. */
|
|
120
|
+
self: TEXT.optional(),
|
|
121
|
+
formality: FORMALITY.default(OwnerFormalities.NEUTRAL),
|
|
122
|
+
})
|
|
123
|
+
.prefault({}),
|
|
124
|
+
tone: TONE.default(OwnerTones.NEUTRAL),
|
|
125
|
+
reportDetail: DETAIL.default(OwnerDetails.TABLES),
|
|
126
|
+
habits: z
|
|
127
|
+
.strictObject({
|
|
128
|
+
/** Ask before a reversible choice; false means state a default and continue (V-P-10). */
|
|
129
|
+
askBeforeReversible: z.boolean().default(false),
|
|
130
|
+
proposeCommits: z.boolean().default(false),
|
|
131
|
+
})
|
|
132
|
+
.prefault({}),
|
|
133
|
+
/** In the person's own words, never scored or used to infer traits. */
|
|
134
|
+
about: z.string().max(2000).optional(),
|
|
135
|
+
/** Taste in code that no formatter or lint rule already enforces. */
|
|
136
|
+
codeTaste: z.string().max(1000).optional(),
|
|
137
|
+
/** Stricter than the project's, never looser. */
|
|
138
|
+
enforce: ENFORCE.optional(),
|
|
139
|
+
/** Lower than the project's, never higher: 0 holds every reply to the shape. */
|
|
140
|
+
shortReplyWords: SHORT_REPLY_WORDS.optional(),
|
|
141
|
+
/** The label set of each language the person uses, keyed by language code. */
|
|
142
|
+
labels: z.record(LANGUAGE, OWNER_LABEL_SET).default({}),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export type TOwnerConfig = z.output<typeof OWNER_SCHEMA>;
|
|
146
|
+
export type TOwnerLabelSet = z.output<typeof OWNER_LABEL_SET>;
|
|
147
|
+
export type TProfile = z.output<typeof PROFILE_SCHEMA>;
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { OwnerDetails, 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
|
+
export 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
|
+
const styleProblems = (opts: { lines: string[]; view: IOwnerView }): string[] => {
|
|
274
|
+
const prose = opts.lines.map((line) => line.replace(/`[^`]*`/g, '')).join('\n');
|
|
275
|
+
const classes: string[] = [];
|
|
276
|
+
|
|
277
|
+
if (/\p{Emoji_Presentation}/u.test(prose)) {
|
|
278
|
+
classes.push(ShapeClasses.EMOJI);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (/\b[A-Z]{4,}(?:\s+[A-Z]{4,})+\b/.test(prose)) {
|
|
282
|
+
classes.push(ShapeClasses.SHOUTING);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (opts.view.absolutePaths) {
|
|
286
|
+
const spans = opts.lines.flatMap((line) =>
|
|
287
|
+
[...line.matchAll(/`([^`]+)`/g)].map((match) => match[1]),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
if (
|
|
291
|
+
spans.some((span) =>
|
|
292
|
+
/^(?![/~]|[a-z]+:)[\w.-]+(?:\/[\w.@-]+)+\.[a-z0-9]{1,6}$/i.test(span ?? ''),
|
|
293
|
+
)
|
|
294
|
+
) {
|
|
295
|
+
classes.push(ShapeClasses.RELATIVE_PATH);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return classes;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Checks one reply to the owner against the resolved shape: a headline that is a sentence within the
|
|
304
|
+
* cap, the minimap table with the configured header and only the configured statuses, the Blocked line,
|
|
305
|
+
* the decisions list with the recommendation in each item or exactly the none string, and the order. Each
|
|
306
|
+
* section is looked for after the one before it, so a headline that begins with a label is still a
|
|
307
|
+
* headline. Pure and deterministic; what it cannot see (whether a point has a plain meaning, whether the
|
|
308
|
+
* answer is right) is for an eval or the owner. A reply under `shortReplyWords` is exempt, and a person
|
|
309
|
+
* who asked for headline-only reports is held to the headline and the style only.
|
|
310
|
+
*/
|
|
311
|
+
export const checkOwnerShape = (opts: { text: string; view: IOwnerView }): IShapeResult => {
|
|
312
|
+
const { text, view } = opts;
|
|
313
|
+
|
|
314
|
+
if (text.trim() === '' || text.trim().split(/\s+/).length < view.shortReplyWords) {
|
|
315
|
+
return { isChecked: false, classes: [] };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const lines = proseLinesOf({ text });
|
|
319
|
+
const classes: string[] = [];
|
|
320
|
+
const isHeadlineOnly = view.reportDetail === OwnerDetails.HEADLINE;
|
|
321
|
+
let cursor = 0;
|
|
322
|
+
let isOutOfOrder = false;
|
|
323
|
+
|
|
324
|
+
for (const section of view.shape) {
|
|
325
|
+
if (section === OwnerSections.HEADLINE) {
|
|
326
|
+
const found = headlineOf({ lines, view });
|
|
327
|
+
|
|
328
|
+
classes.push(...found.problems);
|
|
329
|
+
cursor = found.end;
|
|
330
|
+
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (isHeadlineOnly) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const run = (from: number): IFound => {
|
|
339
|
+
if (section === OwnerSections.MINIMAP) {
|
|
340
|
+
return minimapFrom({ lines, view, from });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (section === OwnerSections.BLOCKED) {
|
|
344
|
+
const at = findLabelFrom({ lines, label: view.labels.labels.blocked, from });
|
|
345
|
+
|
|
346
|
+
return { at, problems: at === -1 ? [ShapeClasses.BLOCKED_MISSING] : [] };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return section === OwnerSections.DECISIONS
|
|
350
|
+
? decisionsFrom({ lines, view, from })
|
|
351
|
+
: { at: -1, problems: [] };
|
|
352
|
+
};
|
|
353
|
+
const after = run(cursor);
|
|
354
|
+
|
|
355
|
+
if (after.at !== -1 || section === OwnerSections.DETAIL) {
|
|
356
|
+
classes.push(...after.problems);
|
|
357
|
+
cursor = after.at === -1 ? cursor : after.at + 1;
|
|
358
|
+
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Not after the section before it: present earlier means out of order, nowhere means missing.
|
|
363
|
+
const anywhere = run(0);
|
|
364
|
+
|
|
365
|
+
if (anywhere.at === -1) {
|
|
366
|
+
classes.push(...anywhere.problems);
|
|
367
|
+
} else {
|
|
368
|
+
isOutOfOrder = true;
|
|
369
|
+
classes.push(...anywhere.problems);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (isOutOfOrder) {
|
|
374
|
+
classes.push(ShapeClasses.SECTION_ORDER);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
classes.push(...styleProblems({ lines, view }));
|
|
378
|
+
|
|
379
|
+
return { isChecked: true, classes: [...new Set(classes)] };
|
|
380
|
+
};
|