opencode-azure-devops-pr-review 0.4.5 → 0.5.0

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/src/config.mjs CHANGED
@@ -21,58 +21,57 @@ export const SHELL_MODES = Object.freeze(['deny', 'ask', 'inherit']);
21
21
  // Native tools every private role may use besides AZPR's own Azure DevOps tools.
22
22
  export const READ_TOOLS = Object.freeze(['read', 'glob', 'grep']);
23
23
 
24
- // Model slots per mode. The quick mode has one reviewer, which also plans comments.
25
- const MODEL_SLOTS = Object.freeze({ review: ['functional', 'risk', 'verifier'], deep: ['functional', 'risk', 'verifier'], quick: ['reviewer'] });
26
- // Slots a mode may leave empty. Without a rater no severity rating runs and the verifier's severity is final.
27
- const OPTIONAL_SLOTS = Object.freeze({ review: ['rater'], deep: ['rater'], quick: [] });
28
- const verifiedStages = {
29
- functional: { slot: 'functional', prompt: 'functional', format: 'initial', prefix: 'F', order: 1, label: 'Initial F' },
30
- risk: { slot: 'risk', prompt: 'risk', format: 'initial', prefix: 'R', order: 2, label: 'Initial R' },
31
- verifier: { slot: 'verifier', prompt: 'final', format: 'final', order: 3, label: 'Verification' },
32
- dedupe: { slot: 'verifier', prompt: 'dedupe', format: 'dedupe', order: 4, label: 'Duplicate check' },
33
- // Optional: rates the surviving findings from their text alone, without tools and without the verifier's level.
34
- // It exists only where models.<mode>.rater names a model.
35
- rating: { slot: 'rater', prompt: 'rating', format: 'rating', order: 6, label: 'Severity rating', tools: false },
36
- 'comment-plan': { slot: 'risk', prompt: 'comment-plan', format: 'comment-plan', comment: true, label: 'Comment plan' },
24
+ // One pipeline for every mode: reviewer passes, a duplicate check, a severity rating, comment planning.
25
+ // A mode's models are a list (models.<mode>.reviewers): pass i of every shard runs with entry i, so each
26
+ // position has a role of its own (a private agent is pinned to one model). The first entry also runs the
27
+ // duplicate check, plans the comments, and rates the severities unless models.<mode>.rater names a model.
28
+ export const MAX_REVIEWERS = 4;
29
+ const REVIEWER_STAGES = Object.freeze(['reviewer', 'reviewerb', 'reviewerc', 'reviewerd']);
30
+ const reviewerStages = Object.fromEntries(REVIEWER_STAGES.map((stage, slot) =>
31
+ [stage, { slot, prompt: 'review', format: 'initial', kind: 'review', order: 1, label: 'Review' }]));
32
+ const stages = {
33
+ ...reviewerStages,
34
+ dedupe: { slot: 0, prompt: 'dedupe', format: 'dedupe', kind: 'dedupe', order: 2, label: 'Duplicate check' },
35
+ // Rates the findings from their text alone, without tools and without the level their reviewer gave them.
36
+ rating: { slot: 'rater', prompt: 'rating', format: 'rating', kind: 'rating', order: 3, label: 'Severity rating', tools: false },
37
+ 'comment-plan': { slot: 0, prompt: 'comment-plan', format: 'comment-plan', comment: true, label: 'Comment plan' },
37
38
  };
38
- // One reviewer per shard covers both focuses; no verifier or duplicate check follows.
39
- const quickStages = {
40
- reviewer: { slot: 'reviewer', prompt: 'quick', format: 'initial', prefix: 'Q', order: 5, label: 'Quick review' },
41
- 'comment-plan': { slot: 'reviewer', prompt: 'comment-plan', format: 'comment-plan', comment: true, label: 'Comment plan' },
42
- };
43
- // Deep is the review with the models of models.deep: the same stages and prompts.
44
- const STAGES = Object.freeze({ review: verifiedStages, deep: verifiedStages, quick: quickStages });
39
+ // Reviews saved by 0.4.x whose findings a verifier confirmed are planned with the wording that describes them.
40
+ const verifiedPlanner = { slot: 0, prompt: 'comment-plan', format: 'comment-plan', comment: true, variant: 'verified', label: 'Comment plan' };
41
+ const STAGES = Object.freeze({ review: { ...stages, 'comment-plan-verified': verifiedPlanner }, deep: { ...stages, 'comment-plan-verified': verifiedPlanner }, quick: stages });
45
42
  export const roleFor = (mode, stage) => `azpr-${mode}-${stage}`;
46
43
  export const ROLES = Object.freeze(Object.fromEntries(MODES.flatMap(mode => Object.entries(STAGES[mode]).map(([stage, spec]) =>
47
44
  [roleFor(mode, stage), Object.freeze({ ...spec, mode, stage })]))));
45
+ // Roles of the 0.4.x pipeline: sessions that saved reviews still name stay AZPR's private sessions.
46
+ const RETIRED_ROLES = Object.freeze(['review', 'deep'].flatMap(mode => ['functional', 'risk', 'verifier'].map(stage => roleFor(mode, stage))));
48
47
  export const PROMPTS = Object.freeze([...new Set(['common', 'comment-policy', ...MODES.flatMap(mode => Object.values(STAGES[mode]).map(spec => spec.prompt))])]);
49
- export const initialRoles = mode => Object.entries(ROLES).filter(([, spec]) => spec.mode === mode && spec.format === 'initial').map(([role]) => role);
48
+ /** The reviewer roles a mode's settings use, in list order: one per entry of models.<mode>.reviewers. */
49
+ export const reviewerRoles = (settings, mode) => settings.models[mode].reviewers.map((_, slot) => roleFor(mode, REVIEWER_STAGES[slot]));
50
50
  export const commentRole = role => ROLES[role]?.comment === true;
51
- export const privateAgent = name => typeof name === 'string' && Object.hasOwn(ROLES, name);
52
- /** The model slots a mode's review stages need. */
53
- export const modelSlots = mode => MODEL_SLOTS[mode];
54
- /** The optional slots a mode's settings set (an empty one turns its stage off). */
55
- export const configuredOptionalSlots = (settings, mode) => OPTIONAL_SLOTS[mode].filter(slot => settings.models[mode][slot]);
56
- /** The model a private role runs with; '' when its optional slot is empty, which turns the stage off. */
51
+ export const privateAgent = name => typeof name === 'string' && (Object.hasOwn(ROLES, name) || RETIRED_ROLES.includes(name));
52
+ /** How a mode's rating is set: 'off' (rater: false), 'named' (rater names a model) or 'first' (the first reviewer model rates). */
53
+ export const raterState = (settings, mode) => settings.models[mode].rater === false ? 'off' : settings.models[mode].rater ? 'named' : 'first';
54
+ /** The model a private role runs with; '' when the mode has no such position or its rating is off. */
57
55
  export function stageModel(settings, role) {
58
- const spec = ROLES[role];
59
- return settings.models[spec.mode][spec.slot] || '';
56
+ const spec = ROLES[role], models = settings.models[spec.mode];
57
+ if (spec.slot === 'rater') return models.rater === false ? '' : models.rater || models.reviewers[0] || '';
58
+ return models.reviewers[spec.slot] ?? '';
60
59
  }
61
- /** The model slot that plans comments for a review of this mode. */
62
- export const commentSlot = mode => STAGES[mode]['comment-plan'].slot;
60
+ /** The model that checks duplicates and plans comments for a mode: the first of its reviewers ('' when the mode is off). */
61
+ export const firstModel = (settings, mode) => settings.models[mode].reviewers[0] ?? '';
63
62
  /**
64
- * Whether a mode's findings are independently verified. Shared prompts carry
65
- * mode-dependent passages about where findings come from; review and deep use
66
- * the "verified" text, quick the "quick" text.
63
+ * Shared prompts carry passages about where findings come from in two wordings: "reviewers" for reviews of
64
+ * this pipeline (each reviewer checked its own findings; no separate verification) and "verified" for reviews
65
+ * saved by 0.4.x whose findings a verifier confirmed, which only their comment planner still reads.
67
66
  */
68
- export const promptVariant = mode => mode === 'quick' ? 'quick' : 'verified';
69
- /** Whether the settings configure every model a mode needs. */
70
- export const modeReady = (settings, mode) => mode === 'review' ? true : mode === 'deep' ? settings.deepReady : mode === 'quick' ? settings.quickReady : false;
67
+ export const promptVariant = role => ROLES[role]?.variant ?? 'reviewers';
68
+ /** Whether the settings configure a mode: it has at least one reviewer model. */
69
+ export const modeReady = (settings, mode) => MODES.includes(mode) && settings.models[mode].reviewers.length > 0;
71
70
 
72
- const VARIANT_MARKER = /^<!-- azpr:(verified|quick|end) -->\r?$/;
71
+ const VARIANT_MARKER = /^<!-- azpr:(verified|reviewers|end) -->\r?$/;
73
72
  /**
74
73
  * Keep the passages of one variant. A block starts with `<!-- azpr:verified -->`
75
- * or `<!-- azpr:quick -->` on its own line, may switch to the other variant the
74
+ * or `<!-- azpr:reviewers -->` on its own line, may switch to the other variant the
76
75
  * same way and ends with `<!-- azpr:end -->`; lines outside blocks are shared.
77
76
  * Marker lines are removed, so a file's verified text is reproduced exactly.
78
77
  */
@@ -116,11 +115,12 @@ export const TERMINAL_PANEL = Object.freeze(['auto', 'manual']);
116
115
  const deepFreeze = value => { for (const item of Object.values(value)) if (item !== null && typeof item === 'object') deepFreeze(item); return Object.freeze(value); };
117
116
  /**
118
117
  * Every setting that has a default, with it, in the order of config/settings.example.json. The review
119
- * models and azure.organization have none: a person chooses them. Validation applies these values to
118
+ * models (models.review.reviewers) and azure.organization have none: a person chooses them. An empty list
119
+ * of reviewers leaves /pr-deep or /pr-quick off; an empty rater lets the first reviewer model rate. Validation applies these values to
120
120
  * what a settings file leaves out, and withMissingSettings writes them into the file.
121
121
  */
122
122
  export const SETTING_DEFAULTS = deepFreeze({
123
- models: { review: { rater: '' }, deep: { functional: '', risk: '', verifier: '', rater: '' }, quick: { reviewer: '' } },
123
+ models: { review: { rater: '' }, deep: { reviewers: [], rater: '' }, quick: { reviewers: [], rater: '' } },
124
124
  enabled: true,
125
125
  returnReport: 'receipt',
126
126
  debug: { enabled: false, directory: '', keepRuns: 20 },
@@ -132,7 +132,7 @@ export const SETTING_DEFAULTS = deepFreeze({
132
132
  terminalPanel: 'auto',
133
133
  afterReview: { quick: 'preview', review: 'preview', deep: 'preview' },
134
134
  azure: { pat: '', patFile: '', concurrency: 6, callTimeoutSeconds: 120, archiveMegabytes: 100, proxy: '', caFile: '', verifyTls: true },
135
- workflow: { shardFiles: 25, shardFindings: 15, parallelSessions: 8, repairAttempts: 2, stageRetries: 1, stageIdleSeconds: 600 },
135
+ workflow: { shardFiles: 25, parallelSessions: 8, repairAttempts: 2, stageRetries: 1, stageIdleSeconds: 600 },
136
136
  });
137
137
  const DEFAULTS = Object.freeze({
138
138
  afterReview: SETTING_DEFAULTS.afterReview,
@@ -149,7 +149,7 @@ const isObject = value => value !== null && typeof value === 'object' && !Array.
149
149
  */
150
150
  export function withMissingSettings(raw) {
151
151
  const added = [];
152
- const copy = value => isObject(value) ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, copy(item)])) : value;
152
+ const copy = value => Array.isArray(value) ? value.map(copy) : isObject(value) ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, copy(item)])) : value;
153
153
  const fill = (existing, defaults, prefix) => {
154
154
  const result = { ...existing };
155
155
  for (const [key, value] of Object.entries(defaults)) {
@@ -175,13 +175,29 @@ function integer(value, at, min, max) {
175
175
  if (!Number.isInteger(value) || value < min || value > max) throw new Error(`${at} must be an integer from ${min} to ${max}.`);
176
176
  return value;
177
177
  }
178
+ /** Whether a value is a model reference as settings take one: provider/model, optionally #variant; no placeholder. */
179
+ export const isModelReference = value => typeof value === 'string' && value.length <= 512 &&
180
+ /^[A-Za-z0-9][A-Za-z0-9._:-]*\/[A-Za-z0-9][A-Za-z0-9._:@/+=-]*(?:#[A-Za-z0-9][A-Za-z0-9._-]*)?$/.test(value) && !/REPLACE_|YOUR_PROVIDER|YOUR_MODEL/.test(value);
178
181
  function model(value, at, optional = false) {
179
182
  if (optional && value === '') return '';
180
- if (typeof value !== 'string' || value.length > 512 ||
181
- !/^[A-Za-z0-9][A-Za-z0-9._:-]*\/[A-Za-z0-9][A-Za-z0-9._:@/+=-]*(?:#[A-Za-z0-9][A-Za-z0-9._-]*)?$/.test(value) ||
182
- /REPLACE_|YOUR_PROVIDER|YOUR_MODEL/.test(value)) throw new Error(`${at}: select an actual provider/model ID from opencode models, optionally with a variant as provider/model#variant; do not use a display name or placeholder.`);
183
+ if (!isModelReference(value)) throw new Error(`${at}: select an actual provider/model ID from opencode models, optionally with a variant as provider/model#variant; do not use a display name or placeholder.`);
183
184
  return value;
184
185
  }
186
+ /** A mode's reviewer models: one entry per review pass, in order; an entry may repeat. Only review needs one. */
187
+ function reviewerList(value, at, optional) {
188
+ if (!Array.isArray(value)) throw new Error(`${at} must be a list of models, one per review pass (1 to ${MAX_REVIEWERS}${optional ? '; an empty list leaves the mode off' : ''}).`);
189
+ if (value.length > MAX_REVIEWERS) throw new Error(`${at} takes at most ${MAX_REVIEWERS} models, one per review pass.`);
190
+ if (!value.length && !optional) throw new Error(`${at} needs at least one model: /pr-review runs one pass per entry.`);
191
+ return value.map((item, index) => model(item, `${at}[${index}]`));
192
+ }
193
+ /** A mode's rater: '' (the first reviewer model rates), a model, or false (no severity rating). */
194
+ function raterOf(value, at) {
195
+ if (value === false || value === '') return value;
196
+ if (typeof value !== 'string') throw new Error(`${at} must be "" (the first reviewer model rates), a provider/model ID, or false (no severity rating).`);
197
+ return model(value, at);
198
+ }
199
+ /** What a settings file of AZPR 0.4.x gets instead of being used: /pr-setup shows the change and writes the new file. */
200
+ export const MIGRATION_NEEDED = 'settings.json is from AZPR 0.4.x (settings version 2). This version reviews with a list of reviewer models per mode and has no verifier: run /pr-setup to see what changes and to update the file. Nothing is changed until you confirm.';
185
201
  /** A forward proxy for Azure DevOps calls. Never echo it: it may carry credentials. */
186
202
  function proxyUrl(value) {
187
203
  const message = 'azure.proxy must be empty or a proxy URL such as http://proxy.example.com:8080, optionally with percent-encoded credentials (http://user:password@host:port), without a path, query or fragment.';
@@ -206,33 +222,26 @@ export const patProblem = value => typeof value !== 'string' || !/^[\x21-\x7e]{2
206
222
 
207
223
  /** Validate local values only; model pricing, access and quality are external. */
208
224
  export function validateSettings(raw) {
225
+ // A settings file of AZPR 0.4.x is not read at all, whatever else it holds: its update comes before any repair.
226
+ if (isObject(raw) && raw.version === 2) throw Object.assign(new Error(MIGRATION_NEEDED), { needsMigration: true });
209
227
  if (raw !== null && typeof raw === 'object' && Object.hasOwn(raw, 'mcp')) {
210
228
  throw new Error('settings.mcp is no longer used: AZPR calls the Azure DevOps REST API itself. Move concurrency and callTimeoutSeconds to azure, set azure.organization and azure.patFile (or azure.pat), and remove mcp.');
211
229
  }
212
230
  keys(raw, ['$schema', 'version', 'enabled', 'models', 'debug', 'outputLanguage', 'returnReport', 'runTimeoutSeconds',
213
231
  'shell', 'progressNotices', 'deletePrivateSessions', 'terminalPanel', 'afterReview', 'azure', 'workflow'], 'settings');
214
- if (raw.version !== 2) throw new Error('settings.version must be 2. Use the V2 settings example; older host layouts are not supported.');
232
+ if (raw.version !== 3) throw new Error('settings.version must be 3. Use the settings example of this version; older layouts are not supported.');
215
233
  if (raw.enabled !== undefined && typeof raw.enabled !== 'boolean') throw new Error('enabled must be boolean.');
216
234
  if (raw.$schema !== undefined && typeof raw.$schema !== 'string') throw new Error('$schema must be a string.');
217
- keys(raw.models, ['_help', ...MODES], 'models');
218
- // Legacy documentation stays readable; the installer removes it.
219
- if (raw.models._help !== undefined) {
220
- keys(raw.models._help, MODEL_SLOTS.review, 'models._help');
221
- if (Object.values(raw.models._help).some(value => typeof value !== 'string')) throw new Error('models._help values must be documentation strings.');
222
- }
235
+ keys(raw.models, MODES, 'models');
223
236
  const models = {};
224
237
  for (const mode of MODES) {
225
- // Only the review models are required; empty deep or quick models disable that mode.
238
+ // Only the review models are required; an empty list of reviewers leaves deep or quick off.
226
239
  const optional = mode !== 'review';
227
240
  const group = raw.models[mode] === undefined && optional ? {} : raw.models[mode];
228
- keys(group, [...MODEL_SLOTS[mode], ...OPTIONAL_SLOTS[mode]], `models.${mode}`);
229
- models[mode] = Object.fromEntries([
230
- ...MODEL_SLOTS[mode].map(slot => [slot, model(group[slot] === undefined && optional ? '' : group[slot], `models.${mode}.${slot}`, optional)]),
231
- ...OPTIONAL_SLOTS[mode].map(slot => [slot, model(group[slot] === undefined ? '' : group[slot], `models.${mode}.${slot}`, true)]),
232
- ]);
241
+ keys(group, ['reviewers', 'rater'], `models.${mode}`);
242
+ models[mode] = { reviewers: reviewerList(group.reviewers === undefined && optional ? [] : group.reviewers, `models.${mode}.reviewers`, optional),
243
+ rater: raterOf(group.rater === undefined ? '' : group.rater, `models.${mode}.rater`) };
233
244
  }
234
- // The optional rater does not count: deep mode is on when its three review roles are set.
235
- const deepConfigured = MODEL_SLOTS.deep.filter(slot => models.deep[slot]).length;
236
245
  const returnReport = withDefault(raw.returnReport, SETTING_DEFAULTS.returnReport);
237
246
  if (!['receipt', 'full'].includes(returnReport)) throw new Error('returnReport must be receipt or full.');
238
247
  const outputLanguage = languageTag(withDefault(raw.outputLanguage, SETTING_DEFAULTS.outputLanguage));
@@ -278,30 +287,108 @@ export function validateSettings(raw) {
278
287
  if (typeof azure.verifyTls !== 'boolean') throw new Error('azure.verifyTls must be boolean.');
279
288
  const workflow = { ...DEFAULTS.workflow, ...(raw.workflow === undefined ? {} : (keys(raw.workflow, Object.keys(DEFAULTS.workflow), 'workflow'), raw.workflow)) };
280
289
  integer(workflow.shardFiles, 'workflow.shardFiles', 1, 1000);
281
- integer(workflow.shardFindings, 'workflow.shardFindings', 1, 500);
282
290
  integer(workflow.parallelSessions, 'workflow.parallelSessions', 1, 16);
283
291
  integer(workflow.repairAttempts, 'workflow.repairAttempts', 0, 3);
284
292
  integer(workflow.stageRetries, 'workflow.stageRetries', 0, 2);
285
293
  const idle = workflow.stageIdleSeconds;
286
294
  if (idle !== 0 && (!Number.isInteger(idle) || idle < 60 || idle > 7200)) throw new Error('workflow.stageIdleSeconds must be 0 (off) or an integer from 60 to 7200.');
287
295
  return { models, debug: { enabled: debug.enabled, directory: debug.directory ?? '', keepRuns },
288
- enabled: raw.enabled !== false, outputLanguage, returnReport, runTimeoutSeconds, shell, progressNotices, deletePrivateSessions, terminalPanel, afterReview, azure, workflow,
289
- deepReady: deepConfigured === MODEL_SLOTS.deep.length,
290
- deepPartial: deepConfigured > 0 && deepConfigured < MODEL_SLOTS.deep.length,
291
- quickReady: models.quick.reviewer !== '' };
296
+ enabled: raw.enabled !== false, outputLanguage, returnReport, runTimeoutSeconds, shell, progressNotices, deletePrivateSessions, terminalPanel, afterReview, azure, workflow };
297
+ }
298
+
299
+ /**
300
+ * What a version-2 settings file (AZPR 0.4.x) becomes, without reading or writing anything: setup shows
301
+ * `summary` and writes `settings` only after a person confirmed that very change.
302
+ * - review and deep: the two reviewer models become the list's two entries, in their order; the verifier
303
+ * model is dropped. Deep was on only with all three roles set, so anything less stays off.
304
+ * - quick: its reviewer becomes a list of one.
305
+ * - rater: a named model stays, and so does false. An empty one used to mean no rating; it now lets the first
306
+ * reviewer model rate (rater: false keeps it off), which the summary says.
307
+ * - workflow.shardFindings (the verifier's batch size) and the documentation-only models._help are dropped.
308
+ * Every other value stays as it is, in its place. The update repairs nothing: a value 0.4.x refused in a slot
309
+ * that still exists (a reviewer, a rater) is kept where it goes now, and so is a key it does not know, so that
310
+ * a file 0.4.x could not use is not usable after the update either, and the settings check names what is
311
+ * wrong. Only what no longer exists goes whatever it held: the verifier, the help texts, shardFindings.
312
+ */
313
+ export function migrateSettings(raw) {
314
+ if (!isObject(raw) || raw.version !== 2) throw new Error('Only settings of version 2 are migrated.');
315
+ // What 0.4.x accepted in a model slot: a model reference, or nothing where the slot could stay empty.
316
+ const accepted = (value, optional) => isModelReference(value) || (optional && (value === undefined || value === ''));
317
+ // The keys of a group that the update does not map, with their values.
318
+ const unknown = (group, known) => Object.fromEntries(Object.entries(group).filter(([key]) => !known.includes(key)));
319
+ const empty = { reviewers: [], rater: '' };
320
+ const models = {}, modes = {};
321
+ const old = raw.models;
322
+ if (old !== undefined && !isObject(old)) {
323
+ // Not a group of models at all: kept as it is, for the settings check to name.
324
+ for (const mode of MODES) modes[mode] = { before: {}, after: empty, state: 'kept', value: true };
325
+ } else {
326
+ const groups = isObject(old) ? old : {};
327
+ // A group that names reviewers already was written for neither version: 0.4.x refused that key, and mapping its
328
+ // models would collide with it. It is kept as it is. One written wholly as this version writes a group (its
329
+ // reviewers as a list of model IDs, and a rater or none) runs as it is after the update, and the summary names
330
+ // its passes; the settings check names any other.
331
+ const clashing = value => isObject(value) && Object.hasOwn(value, 'reviewers');
332
+ const asWritten = (mode, value) => {
333
+ const { reviewers } = value;
334
+ const current = Object.keys(value).every(key => key === 'reviewers' || key === 'rater') && Array.isArray(reviewers)
335
+ && reviewers.length <= MAX_REVIEWERS && reviewers.every(isModelReference) && (reviewers.length > 0 || mode !== 'review');
336
+ return current ? { before: {}, after: { reviewers: [...reviewers], rater: value.rater === undefined ? '' : value.rater }, state: reviewers.length ? 'on' : 'off', current: true }
337
+ : { before: {}, after: empty, state: 'kept', clash: true };
338
+ };
339
+ for (const mode of ['review', 'deep']) {
340
+ const value = groups[mode];
341
+ if (value !== undefined && !isObject(value)) { models[mode] = value; modes[mode] = { before: {}, after: empty, state: 'kept', value: true }; continue; }
342
+ if (clashing(value)) { models[mode] = { ...value }; modes[mode] = asWritten(mode, value); continue; }
343
+ const group = isObject(value) ? value : {}, optional = mode === 'deep';
344
+ const before = Object.fromEntries(['functional', 'risk', 'verifier', 'rater'].map(role => [role, group[role] === undefined ? '' : group[role]]));
345
+ // A reviewer model 0.4.x refused stays in the list, where the settings check names its entry. A missing one
346
+ // is no value to keep: the list stays empty, and the check says that /pr-review needs a model.
347
+ const faulty = [group.functional, group.risk].some(item => ![undefined, ''].includes(item) && !accepted(item, optional));
348
+ // The verifier no longer exists: that it was set is what counts, not whether 0.4.x could use its value.
349
+ const complete = !faulty && Boolean(before.functional && before.risk) && ![undefined, ''].includes(group.verifier);
350
+ const rater = group.rater === undefined ? '' : group.rater;
351
+ models[mode] = { reviewers: faulty ? [before.functional, before.risk].map(item => item === '' ? null : item) : complete ? [before.functional, before.risk] : [], rater,
352
+ ...unknown(group, ['functional', 'risk', 'verifier', 'rater']) };
353
+ modes[mode] = { before, after: models[mode], state: faulty ? 'kept' : complete ? 'on' : before.functional || before.risk || before.verifier ? 'partial' : 'off' };
354
+ }
355
+ const value = groups.quick;
356
+ if (value !== undefined && !isObject(value)) { models.quick = value; modes.quick = { before: {}, after: empty, state: 'kept', value: true }; }
357
+ else if (clashing(value)) { models.quick = { ...value }; modes.quick = asWritten('quick', value); }
358
+ else {
359
+ const group = isObject(value) ? value : {}, reviewer = group.reviewer === undefined ? '' : group.reviewer;
360
+ const faulty = !accepted(group.reviewer, true);
361
+ // 0.4.x had no rater for /pr-quick; one the file names anyway is kept, and the summary says so.
362
+ models.quick = { reviewers: reviewer === '' ? [] : [reviewer], rater: group.rater === undefined ? '' : group.rater, ...unknown(group, ['reviewer', 'rater']) };
363
+ modes.quick = { before: { reviewer }, after: models.quick, state: faulty ? 'kept' : reviewer ? 'on' : 'off' };
364
+ }
365
+ // Groups the update does not know stay, and so does documentation that 0.4.x could not read either.
366
+ const help = groups._help;
367
+ const readableHelp = help === undefined || (isObject(help) && Object.entries(help).every(([key, text]) => ['functional', 'risk', 'verifier'].includes(key) && typeof text === 'string'));
368
+ // As own data properties, also a key such as __proto__, which an assignment would take as the prototype.
369
+ for (const [key, content] of Object.entries({ ...unknown(groups, ['_help', ...MODES]), ...(readableHelp ? {} : { _help: help }) })) {
370
+ Object.defineProperty(models, key, { value: content, enumerable: true, writable: true, configurable: true });
371
+ }
372
+ }
373
+ const settings = Object.fromEntries(Object.entries(raw).map(([key, value]) => key === 'version' ? [key, 3]
374
+ : key === 'models' ? [key, isObject(value) ? models : value]
375
+ : key === 'workflow' && isObject(value) ? [key, Object.fromEntries(Object.entries(value).filter(([name]) => name !== 'shardFindings'))] : [key, value]));
376
+ if (!Object.hasOwn(settings, 'models')) settings.models = models;
377
+ const after = isObject(raw.afterReview) ? raw.afterReview : {};
378
+ return { settings, summary: { modes,
379
+ shardFindings: isObject(raw.workflow) && Object.hasOwn(raw.workflow, 'shardFindings') ? raw.workflow.shardFindings : undefined,
380
+ publish: MODES.filter(mode => after[mode] === 'publish') } };
292
381
  }
293
382
 
294
383
  export function languagePrompt(role, language) {
295
- // A quick reviewer writes no dispositions; only verified modes mention them.
296
- // A role without tools writes no finding, only a reason per answer and a report.
384
+ // A reviewer writes findings and a report. The duplicate check and the rating write no finding, only a
385
+ // reason per answer and a report.
297
386
  const toolless = ROLES[role]?.tools === false;
298
387
  const scope = commentRole(role)
299
388
  ? 'Write comment titles, explanations, skip reasons and summary prose in this language.'
300
- : toolless
389
+ : toolless || ROLES[role]?.format === 'dedupe'
301
390
  ? 'Write each reason and the report in this language.'
302
- : ROLES[role]?.mode === 'quick'
303
- ? 'Write human-readable finding fields (summary, evidence, counterevidence, suggestion) and the report in this language.'
304
- : 'Write human-readable finding fields (summary, evidence, counterevidence, suggestion), disposition reasons and the report in this language.';
391
+ : 'Write human-readable finding fields (summary, evidence, counterevidence, suggestion) and the report in this language.';
305
392
  const voice = toolless ? '' : ' Write as one developer explaining a bug to another: trigger, effect and correction in plain sentences.';
306
393
  return `\n\n# Configured output language\noutputLanguage: ${language}\n${scope} Use Traditional Chinese for zh-TW and Simplified Chinese for zh-CN; for zh-TW prefer familiar Taiwanese engineering wording (for example "錯誤處理", "測試案例").${voice} Keep identifiers, API names, paths, source quotes, JSON keys, IDs, status values and severity labels exactly as they are. Do not infer another language from PR content.`;
307
394
  }
@@ -352,12 +439,13 @@ function severityRules(common) {
352
439
  export function buildAgents(settings, prompts) {
353
440
  for (const name of PROMPTS) if (typeof prompts[name] !== 'string' || !prompts[name].trim()) throw new Error(`Missing or empty prompt: ${name}.md`);
354
441
  // Every prompt must compose in both variants, even when a mode is not configured.
355
- const composed = Object.fromEntries(['verified', 'quick'].map(variant =>
442
+ const composed = Object.fromEntries(['verified', 'reviewers'].map(variant =>
356
443
  [variant, Object.fromEntries(PROMPTS.map(name => [name, selectVariant(prompts[name], variant, name)]))]));
357
444
  if (!settings.enabled) return {};
358
- // A role is built only where its mode is configured and its model is set (the rater is optional).
445
+ // A role is built only where its mode is configured and it has a model: one reviewer role per entry of the
446
+ // mode's list, and no rating role where the rating is off.
359
447
  const agents = Object.fromEntries(Object.entries(ROLES).filter(([role, spec]) => modeReady(settings, spec.mode) && stageModel(settings, role)).map(([role, spec]) => {
360
- const text = composed[promptVariant(spec.mode)];
448
+ const text = composed[promptVariant(role)];
361
449
  // A role without tools reads only its own text and the severity rules: nothing about reading source or filing findings applies to it.
362
450
  const system = spec.tools === false
363
451
  ? text[spec.prompt] + '\n\n' + severityRules(text.common) + languagePrompt(role, settings.outputLanguage) + OUTPUT
package/src/host.mjs CHANGED
@@ -6,7 +6,7 @@
6
6
  * constant and response normalization lives here so an upgrade has one place
7
7
  * to adjust.
8
8
  */
9
- export const TESTED_HOST_VERSION = '2.3.0';
9
+ export const TESTED_HOST_VERSION = '2.3.2';
10
10
 
11
11
  // Text OpenCode 2.0.32 through 2.2.7 queue after resuming an interrupted text stream. OpenCode 2.3.0 retries the
12
12
  // interrupted step instead and queues nothing (see `retriedSteps` in session.mjs).