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
address review (claude+codex): make fresh re-run sync-safe via reconcile
[._.]/ Adam Eivy708c56a6fe40
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex df1a46d57b..0e348e3a4f 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -4,7 +4,7 @@- **Daily budgets for the Chief of Staff's domains** — each domain (Brain auto-classify, Memory auto-extract, CoS auto-run, Messages auto-send) can now carry a daily cap on how many automatic actions it takes and how many minutes of work it does. When a domain reaches its cap it pauses that automatic work for the rest of the day and resumes after the counters reset at midnight; the Chief of Staff config panel shows each domain's usage so far today. Caps are off by default (blank means unlimited), so nothing changes until you set one. This rounds out the per-domain guardrails alongside the off / dry-run / execute controls.- **Scheduled "Claim Issue" task** — a new built-in CoS schedule (CoS → Schedule → Claim Issue) that runs the `/claim --issues` flow on a cadence: it picks the next open GitHub issue, creates its own `claim/issue-<num>` worktree, implements the fix, opens a PR that closes the issue, runs the configured reviewers, merges, and cleans up. Configurable per app via an **Issue Author Filter** — claim only issues filed by the repository owner (default) or any open issue regardless of author. Off by default; enable and pick a provider/model per app like the other improvement tasks.-- **Manuscript editorial review: "Start fresh" re-run mode** — re-running the editorial pass in the manuscript editor previously always *merged*, carrying every prior comment forward. A new "Start fresh" checkbox next to "Run editorial review" clears the current open and accepted notes and shows only the new pass's findings. Your dismissed notes are always kept so a dismissed finding can't quietly resurface, and accepted fixes are already applied to the manuscript so dropping their (historical) note loses nothing. Merge stays the default.+- **Manuscript editorial review: "Start fresh" re-run mode** — re-running the editorial pass in the manuscript editor previously always *merged*, leaving every prior open note in place even when a later pass no longer flagged it. A new "Start fresh" checkbox next to "Run editorial review" reconciles the open list against the latest pass: open notes it still finds stay open, open notes it no longer finds are auto-dismissed, and genuinely-new findings are added. Your accepted and dismissed decisions are left untouched. Clearing is done by moving notes to dismissed (never by deleting them), so the change syncs correctly across federated machines instead of being resurrected by a peer. Merge stays the default.## Changeddiff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsxindex a738c5c0f7..f97e9e0e49 100644--- a/client/src/pages/PipelineManuscriptEditor.jsx+++ b/client/src/pages/PipelineManuscriptEditor.jsx@@ -166,9 +166,9 @@ export default function PipelineManuscriptEditor() {// Re-run the editorial completeness pass over the manuscript with the chosen// provider. The route persists findings as the review comment set, so we just- // swap in the returned comments. `mode`: 'merge' (default) augments existing- // comments; 'fresh' clears prior open/accepted notes and shows only this- // run's findings (kept dismissals still suppress resurfacing).+ // swap in the returned comments. `mode`: 'merge' (default) leaves prior notes+ // as-is and appends new findings; 'fresh' also auto-dismisses open notes this+ // pass no longer finds (accepted/dismissed untouched).const [runEditorialReview, reviewing] = useAsyncAction(async (mode = 'merge') => {const result = await analyzePipelineManuscriptCompleteness(seriesId, { providerOverride, modelOverride, mode });@@ -303,10 +303,6 @@ export default function PipelineManuscriptEditor() {dismissed: comments.filter((c) => c.status === 'dismissed'),}), [comments]);- // How many notes a "Start fresh" re-run would replace (open + accepted;- // dismissed are kept). Drives the checkbox's explanatory count.- const freshClearCount = grouped.open.length + grouped.accepted.length;-// Only pin still-open comments — accepting/dismissing flips the status, which// resolves this to null and closes the overlay automatically (resolved// comments are navigational only, with no actions to keep on screen).@@ -439,9 +435,9 @@ export default function PipelineManuscriptEditor() {{reviewing ? <Loader2 size={12} className="animate-spin" /> : <ClipboardCheck size={12} />}{reviewing ? 'Running editorial review…' : 'Run editorial review'}</button>- {/* Re-run mode. Merge keeps prior notes; fresh clears the current- open/accepted notes and shows only the new pass (dismissed are- kept so they don't resurface). */}+ {/* Re-run mode. Merge keeps every prior note as-is; fresh reconciles+ the open list against this run — open notes it no longer finds+ are auto-dismissed (accepted & dismissed are left untouched). */}<label htmlFor="ms-fresh-review" className="flex items-start gap-1.5 text-[11px] text-gray-400 cursor-pointer"><inputid="ms-fresh-review"@@ -454,8 +450,8 @@ export default function PipelineManuscriptEditor() {<span>Start fresh<span className="text-gray-600">- {' '}— replace the current {freshClearCount} note{freshClearCount === 1 ? '' : 's'}- {' '}(open + accepted) with this run; dismissed kept.+ {' '}— auto-dismiss open notes this pass no longer finds; still-valid,+ accepted & dismissed notes are kept.</span></span></label>diff --git a/client/src/services/apiPipeline.js b/client/src/services/apiPipeline.jsindex a6699b3de9..8ec87c54ce 100644--- a/client/src/services/apiPipeline.js+++ b/client/src/services/apiPipeline.js@@ -412,9 +412,9 @@ export const commitPipelineArcFromManuscript = (seriesId, proposal = {}) =>// Manuscript-completeness ("finish the draft") editor pass — reads the actual// drafted script and returns categorized { severity, category, location,// problem, suggestion } findings. Advisory; no auto-resolve. Empty = complete.-// `mode`: 'merge' (default) augments existing comments; 'fresh' clears prior-// open/accepted comments and shows only this run's findings (kept dismissals-// still suppress resurfacing).+// `mode`: 'merge' (default) leaves prior comments as-is and appends new+// findings; 'fresh' also auto-dismisses open comments this pass no longer finds+// (accepted/dismissed untouched, dismissed still suppress resurfacing).export const analyzePipelineManuscriptCompleteness = (seriesId, { providerOverride, modelOverride, mode } = {}) =>request(`/pipeline/series/${encodeURIComponent(seriesId)}/manuscript/completeness`, {method: 'POST',diff --git a/server/routes/pipeline.js b/server/routes/pipeline.jsindex 7c6c5d6af9..c2e853226e 100644--- a/server/routes/pipeline.js+++ b/server/routes/pipeline.js@@ -649,9 +649,9 @@ const arcDeriveCommitSchema = z.object({});// Manuscript-completeness ("finish the draft") editor pass — override shape plus-// the re-run merge mode: 'merge' (default) augments existing comments; 'fresh'-// clears prior open/accepted comments and shows only this run's findings (kept-// dismissals still suppress resurfacing). See seedReviewFromFindings.+// the re-run mode: 'merge' (default) leaves prior comments as-is and appends new+// findings; 'fresh' also auto-dismisses open comments this pass no longer finds+// (accepted/dismissed untouched). See seedReviewFromFindings.const manuscriptCompletenessSchema = z.object({...providerOverrideShape,mode: z.enum(manuscriptReview.REVIEW_RUN_MODES).optional(),diff --git a/server/services/pipeline/manuscriptReview.js b/server/services/pipeline/manuscriptReview.jsindex 965089715e..c5b6087761 100644--- a/server/services/pipeline/manuscriptReview.js+++ b/server/services/pipeline/manuscriptReview.js@@ -149,22 +149,24 @@ const findingKey = (c) => `${c.issueNumber ?? ''}|${c.anchorQuote}|${c.problem}`/*** Merge a fresh set of shaped completeness findings into the review.*- * `mode` controls what survives a re-run:+ * In BOTH modes, existing comments are carried forward and only findings not+ * already present (by (issueNumber, anchorQuote, problem)) are appended — so+ * re-running augments the list instead of piling up duplicates or wiping work+ * in progress, and a `dismissed` decision keeps suppressing its finding.*- * - 'merge' (default): ALL existing comments are preserved — open ones (the- * user may be mid-fix, with a generated replacement attached) as well as- * accepted/dismissed decisions. Only findings not already present (by- * (issueNumber, anchorQuote, problem)) are appended, so re-running augments- * the list instead of piling up duplicates or wiping work in progress.+ * `mode` controls how the OPEN list reconciles against this run:*- * - 'fresh': clears the prior `open` and `accepted` comments and seeds only- * this run's findings, so the editor shows just the new editorial pass.- * `dismissed` comments are KEPT — they're the user's standing "ignore this"- * decisions and are NOT reflected in the manuscript, so dropping them would- * silently resurrect those findings as new open comments on the next run.- * `accepted` comments are dropped: their fix is already applied to the- * manuscript (see acceptManuscriptFix), so the record is only a historical- * marker. Fresh findings still dedupe against the surviving dismissed set.+ * - 'merge' (default): every existing comment is left exactly as-is. A prior+ * open comment the new pass no longer surfaces still lingers as open.+ *+ * - 'fresh': an existing `open` comment the new pass no longer surfaces is+ * auto-dismissed, so the open list reflects this run's findings (still-found+ * opens stay open; newly-absent ones move to dismissed; genuinely-new ones+ * are appended). Clearing is a status FLIP, never a deletion — a deletion+ * would not propagate across synced peers (`mergeReviewFromSync` is additive+ * LWW-per-id and never removes a comment), so an omitted comment would be+ * resurrected on the next inbound sync. A flip to `dismissed` rides the same+ * LWW path and converges. `accepted`/`dismissed` comments are untouched.** New findings resolve their issueId/stageId from the current manuscript* sections by issueNumber.@@ -174,21 +176,37 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,const byNumber = new Map(sections.map((s) => [s.number, s]));return queueReviewWrite(seriesId, async () => {const review = await readReview(seriesId);- // In 'fresh' mode the surviving base is just the dismissed decisions; in- // 'merge' mode every existing comment is carried forward.- const base = mode === 'fresh'- ? review.comments.filter((c) => c.status === 'dismissed')- : review.comments;- const removed = review.comments.length - base.length;- const seenKeys = new Set(base.map(findingKey));const now = new Date().toISOString();- const fresh = [];+ // Shape incoming findings up front so we can both dedupe against them and+ // (in fresh mode) reconcile existing open comments against what's still found.+ const candidates = [];for (const f of Array.isArray(findings) ? findings : []) {const candidate = sanitizeComment({ ...f, status: 'open', sourceRunId: runId, createdAt: now, updatedAt: now });- if (!candidate) continue;+ if (candidate) candidates.push(candidate);+ }+ const freshKeys = new Set(candidates.map(findingKey));++ // Carry every existing comment forward. In 'fresh' mode, an open comment the+ // new pass no longer surfaces is flipped to dismissed (a synced status+ // change, not a deletion — see the doc comment). Accepted/dismissed are+ // always left untouched.+ let dismissedCount = 0;+ const carried = review.comments.map((c) => {+ if (mode === 'fresh' && c.status === 'open' && !freshKeys.has(findingKey(c))) {+ dismissedCount += 1;+ return sanitizeComment({ ...c, status: 'dismissed', updatedAt: now });+ }+ return c;+ });++ // Append only findings not already represented by an existing comment (any+ // status) — re-reported findings don't duplicate, dismissed stay suppressed.+ const seenKeys = new Set(review.comments.map(findingKey));+ const fresh = [];+ for (const candidate of candidates) {const key = findingKey(candidate);- if (seenKeys.has(key)) continue; // already present (open or resolved) — don't duplicate+ if (seenKeys.has(key)) continue;const section = candidate.issueNumber != null ? byNumber.get(candidate.issueNumber) : null;if (section) {candidate.issueId = section.issueId;@@ -198,15 +216,15 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,fresh.push(candidate);}- const next = { schemaVersion: SCHEMA_VERSION, comments: [...base, ...fresh] };+ const next = { schemaVersion: SCHEMA_VERSION, comments: [...carried, ...fresh] };await writeReview(seriesId, next);// The review is a sibling of the series record, so a review-only change// doesn't move the series `index.json` — emit a series `updated` event so// the peer-sync push + bucket re-export fire (both hash the review into// their payload). Only when something actually changed — appended findings- // OR comments dropped by a 'fresh' re-run. Skipped on the sync RECEIVE path- // (`mergeReviewFromSync`) to avoid an echo loop.- if (fresh.length > 0 || removed > 0) emitRecordUpdated('series', seriesId);+ // OR opens auto-dismissed by a 'fresh' re-run. Skipped on the sync RECEIVE+ // path (`mergeReviewFromSync`) to avoid an echo loop.+ if (fresh.length > 0 || dismissedCount > 0) emitRecordUpdated('series', seriesId);return next;});}diff --git a/server/services/pipeline/manuscriptReview.test.js b/server/services/pipeline/manuscriptReview.test.jsindex c563a866ef..5e082dbbe0 100644--- a/server/services/pipeline/manuscriptReview.test.js+++ b/server/services/pipeline/manuscriptReview.test.js@@ -92,16 +92,21 @@ describe('manuscriptReview — record-event emission on write', () => {});});-describe('manuscriptReview — re-run merge vs fresh mode', () => {+describe('manuscriptReview — re-run merge vs fresh reconcile', () => {beforeEach(() => { fileStore.clear(); });- // Seed three findings, then flip one accepted and one dismissed, leaving one- // open — the realistic state when a user re-runs the editorial pass.+ const byStatus = (review, s) =>+ review.comments.filter((c) => c.status === s).map((c) => c.problem).sort();++ // Seed four findings, then flip one accepted and one dismissed, leaving two+ // open ('still-found' + 'gone-open') — the realistic state when a user re-runs+ // the editorial pass.async function seedDecidedState(seriesId) {const seeded = await seedReviewFromFindings(seriesId, [{ problem: 'kept-dismissed', anchorQuote: 'a' },{ problem: 'was-accepted', anchorQuote: 'b' },- { problem: 'stale-open', anchorQuote: 'c' },+ { problem: 'still-found', anchorQuote: 'c' },+ { problem: 'gone-open', anchorQuote: 'd' },]);const byProblem = Object.fromEntries(seeded.comments.map((c) => [c.problem, c]));await updateComment(seriesId, byProblem['kept-dismissed'].id, { status: 'dismissed' });@@ -109,26 +114,39 @@ describe('manuscriptReview — re-run merge vs fresh mode', () => {return byProblem;}- it("merge (default) preserves every prior comment and appends new findings", async () => {+ it('merge (default) leaves every prior comment as-is and appends new findings', async () => {await seedDecidedState('ser-merge');- const next = await seedReviewFromFindings('ser-merge', [{ problem: 'brand new', anchorQuote: 'd' }]);- const problems = next.comments.map((c) => c.problem).sort();- expect(problems).toEqual(['brand new', 'kept-dismissed', 'stale-open', 'was-accepted']);+ // 'gone-open' is NOT in this run, but merge must keep it open regardless.+ const next = await seedReviewFromFindings('ser-merge', [+ { problem: 'still-found', anchorQuote: 'c' },+ { problem: 'brand new', anchorQuote: 'e' },+ ]);+ expect(byStatus(next, 'open')).toEqual(['brand new', 'gone-open', 'still-found']);+ expect(byStatus(next, 'accepted')).toEqual(['was-accepted']);+ expect(byStatus(next, 'dismissed')).toEqual(['kept-dismissed']);});- it('fresh drops prior open + accepted, keeps dismissed, and seeds the new pass', async () => {- await seedDecidedState('ser-fresh');+ it('fresh reconciles: keeps still-found opens, auto-dismisses gone opens, appends new', async () => {+ const before = await seedDecidedState('ser-fresh');const next = await seedReviewFromFindings('ser-fresh',- [{ problem: 'brand new', anchorQuote: 'd' }],+ [+ { problem: 'still-found', anchorQuote: 'c' },+ { problem: 'brand new', anchorQuote: 'e' },+ ],{ mode: 'fresh' },);- const byStatus = (s) => next.comments.filter((c) => c.status === s).map((c) => c.problem).sort();- // dismissed survives; open is exactly the new run; accepted is gone.- expect(byStatus('dismissed')).toEqual(['kept-dismissed']);- expect(byStatus('open')).toEqual(['brand new']);- expect(byStatus('accepted')).toEqual([]);- expect(next.comments.find((c) => c.problem === 'stale-open')).toBeUndefined();+ // still-found stays open (same id — a flip-free carry-forward), gone-open is+ // auto-dismissed, brand new is appended, accepted/dismissed untouched.+ expect(byStatus(next, 'open')).toEqual(['brand new', 'still-found']);+ expect(byStatus(next, 'accepted')).toEqual(['was-accepted']);+ expect(byStatus(next, 'dismissed')).toEqual(['gone-open', 'kept-dismissed']);+ const stillFound = next.comments.find((c) => c.problem === 'still-found');+ expect(stillFound.id).toBe(before['still-found'].id);+ expect(stillFound.status).toBe('open');+ // Nothing is deleted — every prior comment is still present (synced flips,+ // not omissions), so a peer can't resurrect a cleared note.+ expect(next.comments).toHaveLength(5);});it('fresh does NOT resurrect a finding the user dismissed (deduped against survivors)', async () => {