@venizia/vulcan 0.4.0 → 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 +3 -3
- 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,289 @@
|
|
|
1
|
+
import { OwnerConstants, OwnerDetails, OwnerFormalities, OwnerTones } from './constants.ts';
|
|
2
|
+
import { OWNER_LABEL_SET, PROFILE_SCHEMA } from './schema.ts';
|
|
3
|
+
import type { TOwnerLabelSet, TProfile } from './schema.ts';
|
|
4
|
+
|
|
5
|
+
export interface ISurveyChoice {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* How the form asks: menus in a terminal, plain lines elsewhere. `null` is a cancel or the end of the
|
|
12
|
+
* input, and stops the survey with nothing written.
|
|
13
|
+
*/
|
|
14
|
+
export interface ISurveyIo {
|
|
15
|
+
text: (opts: {
|
|
16
|
+
message: string;
|
|
17
|
+
defaultValue: string;
|
|
18
|
+
validate?: (value: string) => string | undefined;
|
|
19
|
+
}) => Promise<string | null>;
|
|
20
|
+
select: (opts: {
|
|
21
|
+
message: string;
|
|
22
|
+
choices: ISurveyChoice[];
|
|
23
|
+
initial: string;
|
|
24
|
+
}) => Promise<string | null>;
|
|
25
|
+
confirm: (opts: { message: string; initial: boolean }) => Promise<boolean | null>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The language of the machine as a code (`vi` from `vi_VN.UTF-8`), or English. */
|
|
29
|
+
export const systemLanguageOf = (opts: { env: Record<string, string | undefined> }): string => {
|
|
30
|
+
const raw = opts.env.LC_ALL ?? opts.env.LC_MESSAGES ?? opts.env.LANG ?? '';
|
|
31
|
+
const code = /^([a-z]{2,3})(?:[_.@-]|$)/.exec(raw)?.[1];
|
|
32
|
+
|
|
33
|
+
return code ?? OwnerConstants.DEFAULT_LANGUAGE;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const labelProblem = (value: string): string | undefined =>
|
|
37
|
+
OwnerConstants.LABEL_PATTERN.test(value)
|
|
38
|
+
? undefined
|
|
39
|
+
: 'one line of at most 80 characters, with no backtick, pipe or quote';
|
|
40
|
+
|
|
41
|
+
const optionalLabelProblem = (value: string): string | undefined =>
|
|
42
|
+
value === '' ? undefined : labelProblem(value);
|
|
43
|
+
|
|
44
|
+
const aboutProblem = (value: string): string | undefined =>
|
|
45
|
+
value.length > 2000 ? 'at most 2000 characters' : undefined;
|
|
46
|
+
|
|
47
|
+
const codeTasteProblem = (value: string): string | undefined =>
|
|
48
|
+
value.length > 1000 ? 'at most 1000 characters' : undefined;
|
|
49
|
+
|
|
50
|
+
/** A single dash clears an optional value that an earlier run set: an empty answer keeps it. */
|
|
51
|
+
export const CLEAR_ANSWER = '-';
|
|
52
|
+
|
|
53
|
+
const languageProblem = (value: string): string | undefined =>
|
|
54
|
+
OwnerConstants.LANGUAGE_PATTERN.test(value) ? undefined : 'a language code such as en or pt-BR';
|
|
55
|
+
|
|
56
|
+
const choicesOf = (opts: { set: Set<string> }): ISurveyChoice[] =>
|
|
57
|
+
[...opts.set].map((value) => ({ value, label: value }));
|
|
58
|
+
|
|
59
|
+
/** The label set typed word by word, each default the English one; `null` when the user cancelled. */
|
|
60
|
+
const askLabels = async (opts: { io: ISurveyIo }): Promise<TOwnerLabelSet | null> => {
|
|
61
|
+
const english = OwnerConstants.DEFAULT_LABELS;
|
|
62
|
+
const ask = (
|
|
63
|
+
message: string,
|
|
64
|
+
defaultValue: string,
|
|
65
|
+
extra?: (value: string) => string | undefined,
|
|
66
|
+
) =>
|
|
67
|
+
opts.io.text({
|
|
68
|
+
message,
|
|
69
|
+
defaultValue,
|
|
70
|
+
validate: (value) => labelProblem(value) ?? extra?.(value),
|
|
71
|
+
});
|
|
72
|
+
const columns: string[] = [];
|
|
73
|
+
|
|
74
|
+
for (const [index, name] of [
|
|
75
|
+
'the number column',
|
|
76
|
+
'the task column',
|
|
77
|
+
'the status column',
|
|
78
|
+
].entries()) {
|
|
79
|
+
const answer = await ask(`Header of ${name}`, english.minimapColumns[index]);
|
|
80
|
+
|
|
81
|
+
if (answer === null) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
columns.push(answer === '' ? english.minimapColumns[index] : answer);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const status: Record<string, string> = {};
|
|
89
|
+
|
|
90
|
+
for (const [key, value] of Object.entries(english.status)) {
|
|
91
|
+
const answer = await ask(`Word for the status "${value}"`, value);
|
|
92
|
+
|
|
93
|
+
if (answer === null) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
status[key] = answer === '' ? value : answer;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const labels: Record<string, string> = {};
|
|
101
|
+
|
|
102
|
+
for (const [key, value] of Object.entries(english.labels)) {
|
|
103
|
+
const extra =
|
|
104
|
+
key === 'recommend'
|
|
105
|
+
? (text: string) =>
|
|
106
|
+
text.includes('{x}') ? undefined : 'must contain {x}, where the answer goes'
|
|
107
|
+
: undefined;
|
|
108
|
+
const answer = await ask(`Label "${value}"`, value, extra);
|
|
109
|
+
|
|
110
|
+
if (answer === null) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
labels[key] = answer === '' ? value : answer;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return OWNER_LABEL_SET.parse({
|
|
118
|
+
minimapColumns: columns,
|
|
119
|
+
status,
|
|
120
|
+
labels,
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The questions, in order, each with a default taken on an empty answer and each skippable: the
|
|
126
|
+
* reply language, how to address the person, tone, report detail, working habits, a free line in their
|
|
127
|
+
* words and code taste, and - for a language that is not English - the words for the report. Nothing is
|
|
128
|
+
* inferred from the answers. `existing` supplies the defaults when the form is run again. Returns the
|
|
129
|
+
* profile, or `null` when the user cancelled.
|
|
130
|
+
*/
|
|
131
|
+
export const runSurvey = async (opts: {
|
|
132
|
+
io: ISurveyIo;
|
|
133
|
+
existing?: TProfile;
|
|
134
|
+
systemLanguage: string;
|
|
135
|
+
}): Promise<TProfile | null> => {
|
|
136
|
+
const { io, existing } = opts;
|
|
137
|
+
const text = async (
|
|
138
|
+
message: string,
|
|
139
|
+
defaultValue: string,
|
|
140
|
+
validate?: (value: string) => string | undefined,
|
|
141
|
+
) => io.text({ message, defaultValue, validate });
|
|
142
|
+
/** An optional free value: a single dash clears what an earlier run set. */
|
|
143
|
+
const optional = async (
|
|
144
|
+
message: string,
|
|
145
|
+
defaultValue: string,
|
|
146
|
+
validate?: (value: string) => string | undefined,
|
|
147
|
+
) => {
|
|
148
|
+
const answer = await io.text({
|
|
149
|
+
message: defaultValue === '' ? message : `${message} (${CLEAR_ANSWER} clears it)`,
|
|
150
|
+
defaultValue,
|
|
151
|
+
validate: (value) => (value === CLEAR_ANSWER ? undefined : validate?.(value)),
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return answer === CLEAR_ANSWER ? '' : answer;
|
|
155
|
+
};
|
|
156
|
+
const language = await text(
|
|
157
|
+
'Reply language (a code such as en, fr, pt-BR)',
|
|
158
|
+
existing?.language ?? opts.systemLanguage,
|
|
159
|
+
languageProblem,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
if (language === null) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const you = await optional(
|
|
167
|
+
'How should I address you? (a name, a pronoun, an honorific, or leave empty for none)',
|
|
168
|
+
existing?.address.you ?? '',
|
|
169
|
+
optionalLabelProblem,
|
|
170
|
+
);
|
|
171
|
+
const self =
|
|
172
|
+
you === null
|
|
173
|
+
? null
|
|
174
|
+
: await optional(
|
|
175
|
+
'How should I refer to myself? (leave empty for neutral)',
|
|
176
|
+
existing?.address.self ?? '',
|
|
177
|
+
optionalLabelProblem,
|
|
178
|
+
);
|
|
179
|
+
const formality =
|
|
180
|
+
self === null
|
|
181
|
+
? null
|
|
182
|
+
: await io.select({
|
|
183
|
+
message: 'How formal should I be?',
|
|
184
|
+
choices: choicesOf({ set: OwnerFormalities.SCHEME_SET }),
|
|
185
|
+
initial: existing?.address.formality ?? OwnerFormalities.NEUTRAL,
|
|
186
|
+
});
|
|
187
|
+
const tone =
|
|
188
|
+
formality === null
|
|
189
|
+
? null
|
|
190
|
+
: await io.select({
|
|
191
|
+
message: 'Tone',
|
|
192
|
+
choices: choicesOf({ set: OwnerTones.SCHEME_SET }),
|
|
193
|
+
initial: existing?.tone ?? OwnerTones.NEUTRAL,
|
|
194
|
+
});
|
|
195
|
+
const reportDetail =
|
|
196
|
+
tone === null
|
|
197
|
+
? null
|
|
198
|
+
: await io.select({
|
|
199
|
+
message: 'Reports: headline only, or headline plus tables?',
|
|
200
|
+
choices: choicesOf({ set: OwnerDetails.SCHEME_SET }),
|
|
201
|
+
initial: existing?.reportDetail ?? OwnerDetails.TABLES,
|
|
202
|
+
});
|
|
203
|
+
const ask =
|
|
204
|
+
reportDetail === null
|
|
205
|
+
? null
|
|
206
|
+
: await io.confirm({
|
|
207
|
+
message:
|
|
208
|
+
'For a choice that can be undone, ask you first? (no: state a default and continue)',
|
|
209
|
+
initial: existing?.habits.askBeforeReversible ?? false,
|
|
210
|
+
});
|
|
211
|
+
const commits =
|
|
212
|
+
ask === null
|
|
213
|
+
? null
|
|
214
|
+
: await io.confirm({
|
|
215
|
+
message: 'Propose commits when a piece of work is done?',
|
|
216
|
+
initial: existing?.habits.proposeCommits ?? false,
|
|
217
|
+
});
|
|
218
|
+
const about =
|
|
219
|
+
commits === null
|
|
220
|
+
? null
|
|
221
|
+
: await optional(
|
|
222
|
+
'Anything about how you like to work, or to be worked with? (your own words, optional)',
|
|
223
|
+
existing?.about ?? '',
|
|
224
|
+
aboutProblem,
|
|
225
|
+
);
|
|
226
|
+
const codeTaste =
|
|
227
|
+
about === null
|
|
228
|
+
? null
|
|
229
|
+
: await optional(
|
|
230
|
+
'Taste in code that no formatter or lint rule already enforces? (optional)',
|
|
231
|
+
existing?.codeTaste ?? '',
|
|
232
|
+
codeTasteProblem,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
if (
|
|
236
|
+
[you, self, formality, tone, reportDetail, ask, commits, about, codeTaste].some(
|
|
237
|
+
(answer) => answer === null,
|
|
238
|
+
)
|
|
239
|
+
) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const labels: Record<string, TOwnerLabelSet> = { ...existing?.labels };
|
|
244
|
+
|
|
245
|
+
if (language !== OwnerConstants.DEFAULT_LANGUAGE && !(language in labels)) {
|
|
246
|
+
const typed = await io.select({
|
|
247
|
+
message: `Words for reports in ${language}: only English ships. Type them now, or keep English?`,
|
|
248
|
+
choices: [
|
|
249
|
+
{ value: 'keep', label: 'keep English' },
|
|
250
|
+
{ value: 'type', label: 'type them now' },
|
|
251
|
+
],
|
|
252
|
+
initial: 'keep',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if (typed === null) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (typed === 'type') {
|
|
260
|
+
const set = await askLabels({ io });
|
|
261
|
+
|
|
262
|
+
if (set === null) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
labels[language] = set;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return PROFILE_SCHEMA.parse({
|
|
271
|
+
schemaVersion: OwnerConstants.PROFILE_SCHEMA_VERSION,
|
|
272
|
+
language,
|
|
273
|
+
address: {
|
|
274
|
+
...(you === '' || you === null ? {} : { you }),
|
|
275
|
+
...(self === '' || self === null ? {} : { self }),
|
|
276
|
+
formality,
|
|
277
|
+
},
|
|
278
|
+
tone,
|
|
279
|
+
reportDetail,
|
|
280
|
+
habits: { askBeforeReversible: ask, proposeCommits: commits },
|
|
281
|
+
...(about === '' || about === null ? {} : { about }),
|
|
282
|
+
...(codeTaste === '' || codeTaste === null ? {} : { codeTaste }),
|
|
283
|
+
...(existing?.enforce === undefined ? {} : { enforce: existing.enforce }),
|
|
284
|
+
...(existing?.shortReplyWords === undefined
|
|
285
|
+
? {}
|
|
286
|
+
: { shortReplyWords: existing.shortReplyWords }),
|
|
287
|
+
labels,
|
|
288
|
+
});
|
|
289
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OwnerConstants, OwnerEnforcement } from './constants.ts';
|
|
2
|
+
import type { TOwnerConfig, TOwnerLabelSet, TProfile } from './schema.ts';
|
|
3
|
+
|
|
4
|
+
/** What one person's replies follow: the project's contract with that person's own settings laid over it. */
|
|
5
|
+
export interface IOwnerView {
|
|
6
|
+
language: string;
|
|
7
|
+
/** The words for `language`: the person's own set, the project's when the languages match, else English. */
|
|
8
|
+
labels: TOwnerLabelSet;
|
|
9
|
+
shape: string[];
|
|
10
|
+
headlineMaxSentences: number;
|
|
11
|
+
absolutePaths: boolean;
|
|
12
|
+
enforce: string;
|
|
13
|
+
/** Replies under this many words are exempt from the shape: the lower of the project's and the person's. */
|
|
14
|
+
shortReplyWords: number;
|
|
15
|
+
/** Words that add to the English ones when a reply is checked for a claim its turn does not back. */
|
|
16
|
+
claimWords: { public: string[]; done: string[] };
|
|
17
|
+
/** Personal settings; absent when the person has no profile. */
|
|
18
|
+
address: { you?: string; self?: string; formality: string } | undefined;
|
|
19
|
+
tone: string | undefined;
|
|
20
|
+
reportDetail: string | undefined;
|
|
21
|
+
habits: { askBeforeReversible: boolean; proposeCommits: boolean } | undefined;
|
|
22
|
+
about: string | undefined;
|
|
23
|
+
codeTaste: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The stricter of two enforcement levels. */
|
|
27
|
+
export const stricterEnforcement = (opts: {
|
|
28
|
+
first: string;
|
|
29
|
+
second: string | undefined;
|
|
30
|
+
}): string => {
|
|
31
|
+
const order: readonly string[] = OwnerEnforcement.STRICTNESS;
|
|
32
|
+
const second = opts.second ?? opts.first;
|
|
33
|
+
|
|
34
|
+
return order.indexOf(second) > order.indexOf(opts.first) ? second : opts.first;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Language, address, tone, detail and habits come from the person's profile; the shape, status set and
|
|
39
|
+
* label defaults from the project block, which a profile may not change; `enforce` is the stricter of
|
|
40
|
+
* the two. A language with no label set of its own gets English, never another language's words.
|
|
41
|
+
*/
|
|
42
|
+
export const resolveOwnerView = (opts: { owner: TOwnerConfig; profile?: TProfile }): IOwnerView => {
|
|
43
|
+
const { owner, profile } = opts;
|
|
44
|
+
const language = profile?.language ?? owner.language;
|
|
45
|
+
const projectLabels: TOwnerLabelSet = {
|
|
46
|
+
minimapColumns: owner.report.minimapColumns,
|
|
47
|
+
status: owner.report.status,
|
|
48
|
+
labels: owner.report.labels,
|
|
49
|
+
};
|
|
50
|
+
const own =
|
|
51
|
+
profile !== undefined && Object.hasOwn(profile.labels, language)
|
|
52
|
+
? profile.labels[language]
|
|
53
|
+
: undefined;
|
|
54
|
+
const labels =
|
|
55
|
+
own ?? (language === owner.language ? projectLabels : OwnerConstants.DEFAULT_LABELS);
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
language,
|
|
59
|
+
labels,
|
|
60
|
+
shape: owner.report.shape,
|
|
61
|
+
headlineMaxSentences: owner.report.headlineMaxSentences,
|
|
62
|
+
absolutePaths: owner.report.absolutePaths,
|
|
63
|
+
enforce: stricterEnforcement({ first: owner.report.enforce, second: profile?.enforce }),
|
|
64
|
+
claimWords: owner.report.claimWords,
|
|
65
|
+
shortReplyWords: Math.min(
|
|
66
|
+
owner.report.shortReplyWords,
|
|
67
|
+
profile?.shortReplyWords ?? owner.report.shortReplyWords,
|
|
68
|
+
),
|
|
69
|
+
address: profile?.address,
|
|
70
|
+
tone: profile?.tone,
|
|
71
|
+
reportDetail: profile?.reportDetail,
|
|
72
|
+
habits: profile?.habits,
|
|
73
|
+
about: profile?.about,
|
|
74
|
+
codeTaste: profile?.codeTaste,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { appendFileSync, lstatSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { localRootOf } from '../local/scan.ts';
|
|
4
|
+
import { ClaimClasses } from '../signals/constants.ts';
|
|
5
|
+
import { ShapeClasses } from './shape.ts';
|
|
6
|
+
|
|
7
|
+
const isKnownClass = (value: string): boolean =>
|
|
8
|
+
ShapeClasses.isValid(value) || ClaimClasses.isValid(value);
|
|
9
|
+
|
|
10
|
+
export class ViolationConstants {
|
|
11
|
+
/** One line per checked reply that broke the shape: the date and the classes, never the reply. */
|
|
12
|
+
static readonly LOG_FILE = 'violations.jsonl';
|
|
13
|
+
/** The last checked reply's classes, for the next turn's reminder. */
|
|
14
|
+
static readonly LAST_FILE = 'last-reply.json';
|
|
15
|
+
/** A cached last reply older than this is ignored: the reminder is about the reply just before. */
|
|
16
|
+
static readonly LAST_MAX_AGE_MS = 30 * 60 * 1000;
|
|
17
|
+
/** A reply was sent back this recently: it is not sent back again, whatever the client says about a retry. */
|
|
18
|
+
static readonly BLOCK_COOLDOWN_MS = 2 * 60 * 1000;
|
|
19
|
+
static readonly LOG_MAX_BYTES = 512 * 1024;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `.agents/local/<file>` of a trusted project, or `undefined`; a symlinked file is never followed. */
|
|
23
|
+
const fileOf = (opts: { root: string; name: string }): string | undefined => {
|
|
24
|
+
const local = localRootOf({ root: opts.root });
|
|
25
|
+
|
|
26
|
+
if (local === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const path = join(local, opts.name);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
return lstatSync(path).isFile() ? path : undefined;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// Not there yet is fine; anything else (no permission, not a file) means the path is not ours to write.
|
|
36
|
+
return error instanceof Error && 'code' in error && error.code === 'ENOENT' ? path : undefined;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const readNote = (opts: { root: string }): Record<string, unknown> => {
|
|
41
|
+
const last = fileOf({ root: opts.root, name: ViolationConstants.LAST_FILE });
|
|
42
|
+
|
|
43
|
+
if (last === undefined) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const note: unknown = JSON.parse(readFileSync(last, 'utf8'));
|
|
49
|
+
|
|
50
|
+
return typeof note === 'object' && note !== null
|
|
51
|
+
? Object.fromEntries(Object.entries(note))
|
|
52
|
+
: {};
|
|
53
|
+
} catch {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const isOversized = (opts: { path: string }): boolean => {
|
|
59
|
+
try {
|
|
60
|
+
return lstatSync(opts.path).size > ViolationConstants.LOG_MAX_BYTES;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Records one checked reply: the log when it broke the shape, and always the last-reply note. */
|
|
67
|
+
export const recordReply = (opts: { root: string; classes: string[]; now?: Date }): void => {
|
|
68
|
+
const now = opts.now ?? new Date();
|
|
69
|
+
const log = fileOf({ root: opts.root, name: ViolationConstants.LOG_FILE });
|
|
70
|
+
const last = fileOf({ root: opts.root, name: ViolationConstants.LAST_FILE });
|
|
71
|
+
|
|
72
|
+
if (log !== undefined && opts.classes.length > 0 && !isOversized({ path: log })) {
|
|
73
|
+
appendFileSync(
|
|
74
|
+
log,
|
|
75
|
+
`${JSON.stringify({ date: now.toISOString().slice(0, 10), classes: opts.classes })}\n`,
|
|
76
|
+
{ mode: 0o600 },
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (last !== undefined) {
|
|
81
|
+
const { blockedAt } = readNote({ root: opts.root });
|
|
82
|
+
|
|
83
|
+
writeFileSync(
|
|
84
|
+
last,
|
|
85
|
+
`${JSON.stringify({ at: now.getTime(), classes: opts.classes, ...(typeof blockedAt === 'number' ? { blockedAt } : {}) })}\n`,
|
|
86
|
+
{ mode: 0o600 },
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** Notes that a reply was just sent back, so a second one is never sent back right after it. */
|
|
92
|
+
export const markBlocked = (opts: { root: string; now?: Date }): void => {
|
|
93
|
+
const last = fileOf({ root: opts.root, name: ViolationConstants.LAST_FILE });
|
|
94
|
+
|
|
95
|
+
if (last !== undefined) {
|
|
96
|
+
writeFileSync(
|
|
97
|
+
last,
|
|
98
|
+
`${JSON.stringify({ ...readNote({ root: opts.root }), blockedAt: (opts.now ?? new Date()).getTime() })}\n`,
|
|
99
|
+
{ mode: 0o600 },
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const wasBlockedRecently = (opts: { root: string; now?: number }): boolean => {
|
|
105
|
+
const { blockedAt } = readNote({ root: opts.root });
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
typeof blockedAt === 'number' &&
|
|
109
|
+
(opts.now ?? Date.now()) - blockedAt <= ViolationConstants.BLOCK_COOLDOWN_MS
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** The size of the violation log in bytes, 0 when there is none or it is not ours to read. */
|
|
114
|
+
export const violationLogBytes = (opts: { root: string }): number => {
|
|
115
|
+
const log = fileOf({ root: opts.root, name: ViolationConstants.LOG_FILE });
|
|
116
|
+
|
|
117
|
+
return log === undefined ? 0 : (lstatSync(log, { throwIfNoEntry: false })?.size ?? 0);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** The classes the previous reply broke, or none when there is no note or it is stale. */
|
|
121
|
+
export const readLastClasses = (opts: { root: string; now?: number }): string[] => {
|
|
122
|
+
const last = fileOf({ root: opts.root, name: ViolationConstants.LAST_FILE });
|
|
123
|
+
|
|
124
|
+
if (last === undefined) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const note: unknown = JSON.parse(readFileSync(last, 'utf8'));
|
|
130
|
+
|
|
131
|
+
if (typeof note !== 'object' || note === null || !('at' in note) || !('classes' in note)) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { at, classes } = note;
|
|
136
|
+
|
|
137
|
+
if (
|
|
138
|
+
typeof at !== 'number' ||
|
|
139
|
+
(opts.now ?? Date.now()) - at > ViolationConstants.LAST_MAX_AGE_MS ||
|
|
140
|
+
!Array.isArray(classes)
|
|
141
|
+
) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return classes.filter(
|
|
146
|
+
(value): value is string => typeof value === 'string' && isKnownClass(value),
|
|
147
|
+
);
|
|
148
|
+
} catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/** Violations by class across the log, and the number of days it covers; empty when there is no log. */
|
|
154
|
+
export const readViolationCounts = (opts: {
|
|
155
|
+
root: string;
|
|
156
|
+
}): { byClass: Map<string, number>; replies: number; days: number } => {
|
|
157
|
+
const byClass = new Map<string, number>();
|
|
158
|
+
const days = new Set<string>();
|
|
159
|
+
let replies = 0;
|
|
160
|
+
const log = fileOf({ root: opts.root, name: ViolationConstants.LOG_FILE });
|
|
161
|
+
|
|
162
|
+
if (log === undefined) {
|
|
163
|
+
return { byClass, replies, days: 0 };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let text = '';
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
text = readFileSync(log, 'utf8');
|
|
170
|
+
} catch {
|
|
171
|
+
return { byClass, replies, days: 0 };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const line of text.split('\n')) {
|
|
175
|
+
try {
|
|
176
|
+
const entry: unknown = JSON.parse(line);
|
|
177
|
+
|
|
178
|
+
if (
|
|
179
|
+
typeof entry === 'object' &&
|
|
180
|
+
entry !== null &&
|
|
181
|
+
'classes' in entry &&
|
|
182
|
+
Array.isArray(entry.classes)
|
|
183
|
+
) {
|
|
184
|
+
replies += 1;
|
|
185
|
+
|
|
186
|
+
if ('date' in entry && typeof entry.date === 'string') {
|
|
187
|
+
days.add(entry.date);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
for (const value of entry.classes) {
|
|
191
|
+
if (typeof value === 'string' && isKnownClass(value)) {
|
|
192
|
+
byClass.set(value, (byClass.get(value) ?? 0) + 1);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch {
|
|
197
|
+
// A damaged line is skipped: the log is advisory.
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return { byClass, replies, days: days.size };
|
|
202
|
+
};
|
package/src/router.ts
CHANGED
|
@@ -52,7 +52,24 @@ const ACCEPTED_ARGS: Record<string, IAcceptedArgs> = {
|
|
|
52
52
|
positionals: 0,
|
|
53
53
|
},
|
|
54
54
|
[VulcanCommands.AGENTS]: { flags: ['--dry-run'], values: [], positionals: 2 },
|
|
55
|
+
[VulcanCommands.CLEAN]: {
|
|
56
|
+
flags: [
|
|
57
|
+
'--tmp',
|
|
58
|
+
'--worktrees',
|
|
59
|
+
'--clones',
|
|
60
|
+
'--cache',
|
|
61
|
+
'--reports',
|
|
62
|
+
'--prototypes',
|
|
63
|
+
'--profile',
|
|
64
|
+
'--all',
|
|
65
|
+
'--yes',
|
|
66
|
+
],
|
|
67
|
+
values: [],
|
|
68
|
+
positionals: 0,
|
|
69
|
+
},
|
|
55
70
|
[VulcanCommands.DOCTOR]: { flags: [], values: [], positionals: 0 },
|
|
71
|
+
[VulcanCommands.PROFILE]: { flags: ['--yes'], values: [], positionals: 1 },
|
|
72
|
+
[VulcanCommands.VISUALIZE]: { flags: ['--schema'], values: ['--out'], positionals: 1 },
|
|
56
73
|
[VulcanCommands.UPGRADE]: {
|
|
57
74
|
flags: [UpgradeFlags.STABLE, UpgradeFlags.NIGHTLY],
|
|
58
75
|
values: [],
|
|
@@ -114,7 +131,7 @@ export const runVulcan = async (opts: { argv: string[]; cwd: string }): Promise<
|
|
|
114
131
|
const accepted = ACCEPTED_ARGS[name];
|
|
115
132
|
|
|
116
133
|
if (accepted !== undefined) {
|
|
117
|
-
if (args.some(arg => HELP_ALIASES.has(arg))) {
|
|
134
|
+
if (args.some((arg) => HELP_ALIASES.has(arg))) {
|
|
118
135
|
return runHelpCommand();
|
|
119
136
|
}
|
|
120
137
|
|
package/src/rules/base.ts
CHANGED
|
@@ -8,7 +8,7 @@ const readBaseMarkdown = (): string => readFileSync(join(BASE_DIRECTORY, 'rules.
|
|
|
8
8
|
/** Each base rule's ID with its table row, verbatim. */
|
|
9
9
|
export const readBaseRules = (): Record<string, string> =>
|
|
10
10
|
Object.fromEntries(
|
|
11
|
-
extractRuleRows({ markdown: readBaseMarkdown() }).map(row => {
|
|
11
|
+
extractRuleRows({ markdown: readBaseMarkdown() }).map((row) => {
|
|
12
12
|
const [id] = parseRuleIds({ markdown: row });
|
|
13
13
|
|
|
14
14
|
return [id, row];
|
package/src/rules/parser.ts
CHANGED
|
@@ -6,12 +6,12 @@ const RULE_ROW = new RegExp(`^\\|\\s*(?:\\*\\*)?(${RuleConstants.ID_SOURCE})(?:\
|
|
|
6
6
|
export const parseRuleIds = (opts: { markdown: string }): string[] =>
|
|
7
7
|
opts.markdown
|
|
8
8
|
.split('\n')
|
|
9
|
-
.map(line => RULE_ROW.exec(line)?.[1])
|
|
9
|
+
.map((line) => RULE_ROW.exec(line)?.[1])
|
|
10
10
|
.filter((id): id is string => id !== undefined);
|
|
11
11
|
|
|
12
12
|
/** The table rows of every rule, verbatim, in order. */
|
|
13
13
|
export const extractRuleRows = (opts: { markdown: string }): string[] =>
|
|
14
|
-
opts.markdown.split('\n').filter(line => RULE_ROW.test(line));
|
|
14
|
+
opts.markdown.split('\n').filter((line) => RULE_ROW.test(line));
|
|
15
15
|
|
|
16
16
|
const BASE_ID = new RegExp(`(?<![A-Z-])${RuleConstants.BASE_ID_SOURCE}\\b`, 'g');
|
|
17
17
|
const EXTENDS_LIST = new RegExp(
|
|
@@ -27,9 +27,9 @@ const RETIRED_ITEM = new RegExp(`^- \`(${RuleConstants.BASE_ID_SOURCE})\` - `);
|
|
|
27
27
|
export const parseBaseReferences = (opts: { markdown: string }): string[] => {
|
|
28
28
|
const references = new Set<string>();
|
|
29
29
|
|
|
30
|
-
for (const line of opts.markdown.split('\n').filter(row => row.startsWith('|'))) {
|
|
30
|
+
for (const line of opts.markdown.split('\n').filter((row) => row.startsWith('|'))) {
|
|
31
31
|
const firstCell = line.split('|')[1] ?? '';
|
|
32
|
-
const lists = [...line.matchAll(EXTENDS_LIST)].map(match => match[0]);
|
|
32
|
+
const lists = [...line.matchAll(EXTENDS_LIST)].map((match) => match[0]);
|
|
33
33
|
|
|
34
34
|
for (const text of [...lists, firstCell]) {
|
|
35
35
|
for (const match of text.matchAll(BASE_ID)) {
|
|
@@ -45,5 +45,5 @@ export const parseBaseReferences = (opts: { markdown: string }): string[] => {
|
|
|
45
45
|
export const parseRetiredRuleIds = (opts: { markdown: string }): string[] =>
|
|
46
46
|
opts.markdown
|
|
47
47
|
.split('\n')
|
|
48
|
-
.map(line => RETIRED_ITEM.exec(line)?.[1])
|
|
48
|
+
.map((line) => RETIRED_ITEM.exec(line)?.[1])
|
|
49
49
|
.filter((id): id is string => id !== undefined);
|