Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor: take buildReviewWithArgs options as a named object so adjacent lists can't be transposed (#3452)
[._.]/ Adam Eivy54017468352e
diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.jsindex 4567fc413d..218d87779e 100644--- a/server/lib/cosValidation.js+++ b/server/lib/cosValidation.js@@ -482,8 +482,30 @@ export function buildReviewersCsv(reviewers, usernames = [], optionalReviewers =* the flag). A model pin can't trigger that exemption because `copilot[…]` isn't* a legal slashdo entry (see BRACKET_MODEL_REVIEWERS) — so a lone copilot with a* stray pin emits nothing extra, exactly as before.+ *+ * Everything past `reviewers` is an options object: the two reviewer-name lists+ * (`usernames` / `optionalReviewers`) and the two per-reviewer lookup maps+ * (`reviewerMaxRounds` / `reviewerModels`) are same-shaped and were silently+ * transposable as positionals.+ *+ * @param {string[]} reviewers - ordered keyed reviewer slugs+ * @param {Object} [options]+ * @param {string} [options.stopMode] - review stop mode (`all` / `on-findings` / `on-clean`)+ * @param {boolean} [options.reviewerApplies] - emit `--reviewer-applies`+ * @param {string[]} [options.usernames] - GitHub reviewer usernames (emitted as `@user`)+ * @param {string[]} [options.optionalReviewers] - reviewers that get the `~opt` suffix+ * @param {Object<string, number>} [options.reviewerMaxRounds] - per-reviewer `~max=<n>` caps+ * @param {Object<string, string>} [options.reviewerModels] - per-reviewer `[<model>]` pins+ * @returns {string} the slashdo review flag string (possibly empty)*/-export function buildReviewWithArgs(reviewers, stopMode = DEFAULT_REVIEW_STOP_MODE, reviewerApplies = false, usernames = [], optionalReviewers = [], reviewerMaxRounds = {}, reviewerModels = {}) {+export function buildReviewWithArgs(reviewers, {+ stopMode = DEFAULT_REVIEW_STOP_MODE,+ reviewerApplies = false,+ usernames = [],+ optionalReviewers = [],+ reviewerMaxRounds = {},+ reviewerModels = {},+} = {}) {const users = normalizeReviewUsernames(usernames);const keyed = resolveKeyedReviewers(reviewers, users.length > 0);const combined = [...keyed, ...users.map(u => `@${u}`)];diff --git a/server/lib/validation.test.js b/server/lib/validation.test.jsindex cf488f6c15..f53b3a6b1b 100644--- a/server/lib/validation.test.js+++ b/server/lib/validation.test.js@@ -1083,60 +1083,60 @@ describe('validation.js', () => {});it('adds stop-mode only for 2+ reviewers and reviewer-applies only with a CLI reviewer', () => {- expect(buildReviewWithArgs(['codex', 'copilot'], 'on-findings', true))+ expect(buildReviewWithArgs(['codex', 'copilot'], { stopMode: 'on-findings', reviewerApplies: true })).toBe('--review-with codex,copilot --review-stop-on-findings --reviewer-applies');// single reviewer → no stop-mode flag- expect(buildReviewWithArgs(['codex'], 'on-clean', true))+ expect(buildReviewWithArgs(['codex'], { stopMode: 'on-clean', reviewerApplies: true })).toBe('--review-with codex --reviewer-applies');// copilot-only → reviewer-applies suppressed (no-op on copilot)- expect(buildReviewWithArgs(['copilot'], 'all', true)).toBe('');+ expect(buildReviewWithArgs(['copilot'], { reviewerApplies: true })).toBe('');});it('appends username reviewers as @user tokens after the keyed reviewers', () => {// copilot + a username is no longer "lone default" → the flag is emitted.- expect(buildReviewWithArgs(['copilot'], 'all', false, ['CodeReviewbot']))+ expect(buildReviewWithArgs(['copilot'], { usernames: ['CodeReviewbot'] })).toBe('--review-with copilot,@CodeReviewbot');- expect(buildReviewWithArgs(['codex', 'copilot'], 'all', false, ['@Bot']))+ expect(buildReviewWithArgs(['codex', 'copilot'], { usernames: ['@Bot'] })).toBe('--review-with codex,copilot,@Bot');});it('counts usernames toward the 2+ stop-mode gate', () => {// one keyed reviewer + one username = two review sources → stop-mode applies.- expect(buildReviewWithArgs(['copilot'], 'on-clean', false, ['Bot']))+ expect(buildReviewWithArgs(['copilot'], { stopMode: 'on-clean', usernames: ['Bot'] })).toBe('--review-with copilot,@Bot --review-stop-on-clean');});it('does not enable reviewer-applies for username-only additions', () => {// usernames are external PR reviewers, not CLIs that apply fixes.- expect(buildReviewWithArgs(['copilot'], 'all', true, ['Bot']))+ expect(buildReviewWithArgs(['copilot'], { reviewerApplies: true, usernames: ['Bot'] })).toBe('--review-with copilot,@Bot');});it('normalizes/strips bogus usernames before emitting', () => {- expect(buildReviewWithArgs(['copilot'], 'all', false, ['@Bot', 'bad token', 'bot']))+ expect(buildReviewWithArgs(['copilot'], { usernames: ['@Bot', 'bad token', 'bot'] })).toBe('--review-with copilot,@Bot');});it('appends ~opt to the tokens named in optionalReviewers (keyed + @user)', () => {// ollama marked optional → its token carries ~opt; codex stays blocking.- expect(buildReviewWithArgs(['claude', 'ollama', 'codex'], 'all', false, [], ['ollama']))+ expect(buildReviewWithArgs(['claude', 'ollama', 'codex'], { optionalReviewers: ['ollama'] })).toBe('--review-with claude,ollama~opt,codex');// a username can be optional too — matched by its @-form.- expect(buildReviewWithArgs(['codex'], 'all', false, ['Bot'], ['@Bot']))+ expect(buildReviewWithArgs(['codex'], { usernames: ['Bot'], optionalReviewers: ['@Bot'] })).toBe('--review-with codex,@Bot~opt');// aliases resolve before matching: gemini→antigravity.- expect(buildReviewWithArgs(['antigravity', 'codex'], 'all', false, [], ['gemini']))+ expect(buildReviewWithArgs(['antigravity', 'codex'], { optionalReviewers: ['gemini'] })).toBe('--review-with antigravity~opt,codex');});it('forces the flag on for a lone default copilot marked optional (so ~opt is not lost)', () => {// Without the marker this is the suppressed lone-default case ('').- expect(buildReviewWithArgs(['copilot'], 'all', false, [], ['copilot']))+ expect(buildReviewWithArgs(['copilot'], { optionalReviewers: ['copilot'] })).toBe('--review-with copilot~opt');});it('ignores optionalReviewers entries not present in the emitted list', () => {- expect(buildReviewWithArgs(['codex', 'copilot'], 'all', false, [], ['ollama', 'bad token']))+ expect(buildReviewWithArgs(['codex', 'copilot'], { optionalReviewers: ['ollama', 'bad token'] })).toBe('--review-with codex,copilot');});});@@ -1247,36 +1247,36 @@ describe('validation.js', () => {describe('buildReviewWithArgs — ~max round caps', () => {it('emits <token>~max=<n> for exactly the tokens carrying a cap', () => {- expect(buildReviewWithArgs(['claude', 'ollama', 'codex'], 'all', false, [], [], { ollama: 1 }))+ expect(buildReviewWithArgs(['claude', 'ollama', 'codex'], { reviewerMaxRounds: { ollama: 1 } })).toBe('--review-with claude,ollama~max=1,codex');});it('emits ~opt before ~max when a reviewer carries both', () => {- expect(buildReviewWithArgs(['claude', 'ollama'], 'all', false, [], ['ollama'], { ollama: 1 }))+ expect(buildReviewWithArgs(['claude', 'ollama'], { optionalReviewers: ['ollama'], reviewerMaxRounds: { ollama: 1 } })).toBe('--review-with claude,ollama~opt~max=1');});it('round-trips ~max=0 and distinguishes it from no cap', () => {- expect(buildReviewWithArgs(['claude', 'ollama'], 'all', false, [], [], { ollama: 0 }))+ expect(buildReviewWithArgs(['claude', 'ollama'], { reviewerMaxRounds: { ollama: 0 } })).toBe('--review-with claude,ollama~max=0');- expect(buildReviewWithArgs(['claude', 'ollama'], 'all', false, [], [], {}))+ expect(buildReviewWithArgs(['claude', 'ollama'])).toBe('--review-with claude,ollama');});it('caps a @username reviewer by its @-form token', () => {- expect(buildReviewWithArgs(['codex'], 'all', false, ['Bot'], [], { '@Bot': 2 }))+ expect(buildReviewWithArgs(['codex'], { usernames: ['Bot'], reviewerMaxRounds: { '@Bot': 2 } })).toBe('--review-with codex,@Bot~max=2');});it('forces the flag on for a lone default copilot carrying a cap (so ~max is not lost)', () => {// Without the suffix this is the suppressed lone-default case ('').- expect(buildReviewWithArgs(['copilot'], 'all', false, [], [], { copilot: 2 }))+ expect(buildReviewWithArgs(['copilot'], { reviewerMaxRounds: { copilot: 2 } })).toBe('--review-with copilot~max=2');- expect(buildReviewWithArgs(['copilot'], 'all', false, [], [], {})).toBe('');+ expect(buildReviewWithArgs(['copilot'])).toBe('');});it('ignores caps for tokens not present in the emitted list, and invalid entries', () => {- expect(buildReviewWithArgs(['codex', 'copilot'], 'all', false, [], [], { ollama: 1, nope: 2, codex: -1 }))+ expect(buildReviewWithArgs(['codex', 'copilot'], { reviewerMaxRounds: { ollama: 1, nope: 2, codex: -1 } })).toBe('--review-with codex,copilot');});});@@ -1386,30 +1386,30 @@ describe('validation.js', () => {describe('buildReviewWithArgs — per-reviewer [model] selector', () => {it('emits <token>[<model>] for exactly the tokens carrying a pin', () => {- expect(buildReviewWithArgs(['claude', 'ollama', 'codex'], 'all', false, [], [], {}, { ollama: 'qwen2.5:7b' }))+ expect(buildReviewWithArgs(['claude', 'ollama', 'codex'], { reviewerModels: { ollama: 'qwen2.5:7b' } })).toBe('--review-with claude,ollama[qwen2.5:7b],codex');});it('places the bracket between the slug and the ~ suffixes (slashdo strips suffixes first)', () => {- expect(buildReviewWithArgs(['ollama'], 'all', false, [], ['ollama'], { ollama: 1 }, { ollama: 'qwen2.5:7b' }))+ expect(buildReviewWithArgs(['ollama'], { optionalReviewers: ['ollama'], reviewerMaxRounds: { ollama: 1 }, reviewerModels: { ollama: 'qwen2.5:7b' } })).toBe('--review-with ollama[qwen2.5:7b]~opt~max=1');});it('never brackets copilot, a @username, or lmstudio (no slashdo slug takes one)', () => {// lmstudio's model rides in the /api/code-review/local request body instead.- expect(buildReviewWithArgs(['copilot', 'lmstudio'], 'all', false, ['Bot'], [], {}, {+ expect(buildReviewWithArgs(['copilot', 'lmstudio'], { usernames: ['Bot'], reviewerModels: {copilot: 'x', lmstudio: 'local-a', '@Bot': 'y',- })).toBe('--review-with copilot,lmstudio,@Bot');+ } })).toBe('--review-with copilot,lmstudio,@Bot');});it('does not let a stray copilot pin force the suppressed lone-default flag on', () => {// Unlike ~opt / ~max, a model pin is not an explicit naming of copilot —// `copilot[…]` isn't even legal slashdo, so nothing would be emitted.- expect(buildReviewWithArgs(['copilot'], 'all', false, [], [], {}, { copilot: 'x' })).toBe('');+ expect(buildReviewWithArgs(['copilot'], { reviewerModels: { copilot: 'x' } })).toBe('');});it('ignores pins for tokens not in the emitted list, and invalid entries', () => {- expect(buildReviewWithArgs(['codex'], 'all', false, [], [], {}, { ollama: 'a', nope: 'b', codex: ' ' }))+ expect(buildReviewWithArgs(['codex'], { reviewerModels: { ollama: 'a', nope: 'b', codex: ' ' } })).toBe('--review-with codex');});});diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex 41d6114656..e747e577a3 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -565,7 +565,7 @@ export function buildReviewLoopFollowUpSection(metadata = {}, { verbose = false,...reviewers.map(r => `\`${r}\``),...usernames.map(u => `\`@${u}\``),].join(' → ');- const equivArgs = buildReviewWithArgs(reviewers, stopMode, reviewerApplies, usernames, optionalReviewers, reviewerMaxRounds, reviewerModelMap);+ const equivArgs = buildReviewWithArgs(reviewers, { stopMode, reviewerApplies, usernames, optionalReviewers, reviewerMaxRounds, reviewerModels: reviewerModelMap });const equiv = equivArgs ? ` (equivalent to \`/do:pr ${equivArgs}\`)` : '';// First step: how to obtain a review. For a single copilot/CLI reviewer keep the@@ -1869,7 +1869,7 @@ function buildTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLETIONS.M// when the task's Review Loop control is off so that default cannot start a// Copilot (or other external) review unexpectedly.const reviewArgs = willOpenPR- ? (runsReviewLoop ? buildReviewWithArgs(reviewers, reviewStopMode, reviewerApplies, reviewUsernames, optionalReviewers, reviewerMaxRounds, reviewerModels) : '--review-with none')+ ? (runsReviewLoop ? buildReviewWithArgs(reviewers, { stopMode: reviewStopMode, reviewerApplies, usernames: reviewUsernames, optionalReviewers, reviewerMaxRounds, reviewerModels }) : '--review-with none'): '';// A saved slashdo `merge: true` default would otherwise merge a PR that must// stay open — dropping our own merge steps isn't enough, `/do:pr` has to be@@ -2004,7 +2004,7 @@ function buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompletion = PRlines.push(`${step++}. \`/simplify\` — review the changed code for reuse, quality, and efficiency, and fix any findings.`);}const reviewArgs = runsReviewLoop- ? buildReviewWithArgs(reviewers, reviewStopMode, reviewerApplies, reviewUsernames, optionalReviewers, reviewerMaxRounds, reviewerModels)+ ? buildReviewWithArgs(reviewers, { stopMode: reviewStopMode, reviewerApplies, usernames: reviewUsernames, optionalReviewers, reviewerMaxRounds, reviewerModels }): '--review-with none';// `--no-merge` overrides a saved slashdo `merge: true` default, which would// otherwise merge a PR this task must leave open (see lib/prDisposition.js).