@oss-autopilot/core 3.36.0 → 3.38.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/dist/cli-registry.js +1 -1
- package/dist/cli.bundle.cjs +143 -130
- package/dist/commands/comments.js +4 -3
- package/dist/commands/config.js +18 -11
- package/dist/commands/daily.js +29 -2
- package/dist/commands/dashboard-gist-sync.d.ts +5 -1
- package/dist/commands/dashboard-gist-sync.js +19 -2
- package/dist/commands/dashboard-server.js +9 -5
- package/dist/commands/dismiss.js +4 -3
- package/dist/commands/guidelines.js +21 -14
- package/dist/commands/init.js +3 -2
- package/dist/commands/ledger-backfill.d.ts +7 -0
- package/dist/commands/ledger-backfill.js +120 -9
- package/dist/commands/move.js +9 -6
- package/dist/commands/overnight-push-prep.js +5 -2
- package/dist/commands/overnight.js +48 -23
- package/dist/commands/search.js +9 -6
- package/dist/commands/setup.js +7 -3
- package/dist/commands/validation.js +22 -0
- package/dist/commands/vet-list.js +18 -17
- package/dist/commands/vet.js +27 -2
- package/dist/core/daily-logic.d.ts +33 -0
- package/dist/core/daily-logic.js +102 -0
- package/dist/core/errors.js +1 -1
- package/dist/core/eval-report.d.ts +17 -0
- package/dist/core/eval-report.js +85 -4
- package/dist/core/gist-state-store.d.ts +5 -2
- package/dist/core/gist-state-store.js +7 -4
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/issue-verification.d.ts +12 -0
- package/dist/core/issue-verification.js +18 -0
- package/dist/core/pick-snapshot.d.ts +19 -2
- package/dist/core/pick-snapshot.js +28 -2
- package/dist/core/pr-monitor.d.ts +0 -6
- package/dist/core/pr-monitor.js +0 -13
- package/dist/core/repo-score-manager.d.ts +0 -13
- package/dist/core/repo-score-manager.js +0 -24
- package/dist/core/review-analysis.d.ts +34 -14
- package/dist/core/review-analysis.js +61 -32
- package/dist/core/state-persistence.js +4 -1
- package/dist/core/state-schema.d.ts +46 -0
- package/dist/core/state-schema.js +28 -0
- package/dist/core/state.d.ts +44 -18
- package/dist/core/state.js +164 -38
- package/dist/formatters/json.d.ts +4 -0
- package/dist/formatters/json.js +4 -0
- package/package.json +1 -1
package/dist/core/state.js
CHANGED
|
@@ -9,7 +9,7 @@ import { serializeState } from './state-prune.js';
|
|
|
9
9
|
import { loadState, saveState, reloadStateIfChanged, createFreshState, atomicWriteFileSync, } from './state-persistence.js';
|
|
10
10
|
import * as repoScoring from './repo-score-manager.js';
|
|
11
11
|
import { debug, warn } from './logger.js';
|
|
12
|
-
import { errorMessage, ConfigurationError, ConcurrencyError, isTransientNetworkError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, } from './errors.js';
|
|
12
|
+
import { errorMessage, ConfigurationError, ConcurrencyError, GistConcurrencyError, isTransientNetworkError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, } from './errors.js';
|
|
13
13
|
import { GistStateStore } from './gist-state-store.js';
|
|
14
14
|
import * as guidelinesStoreModule from './guidelines-store.js';
|
|
15
15
|
/** Gist file that carries the rendered overnight report across machines (#1698). */
|
|
@@ -46,6 +46,7 @@ const LEDGER_FIELDS = [
|
|
|
46
46
|
'lastReviewDecision',
|
|
47
47
|
'lastCiStatus',
|
|
48
48
|
'backfilledAt',
|
|
49
|
+
'responseRule',
|
|
49
50
|
'closeReason',
|
|
50
51
|
'selfCloseReason',
|
|
51
52
|
];
|
|
@@ -84,24 +85,77 @@ export const MAX_PICK_SNAPSHOTS = 300;
|
|
|
84
85
|
* after its retry — previously that was discarded everywhere except
|
|
85
86
|
* `state --sync`, so a failed cross-machine sync reported clean success
|
|
86
87
|
* (#1370). stderr `warn()` alone is invisible to MCP/dashboard consumers.
|
|
88
|
+
*
|
|
89
|
+
* Pass `reapply` (the same mutation the caller just performed) to make a
|
|
90
|
+
* `GistConcurrencyError` recoverable: the state is force-refreshed from the
|
|
91
|
+
* Gist, `reapply` runs on the fresh baseline, and the push is retried once.
|
|
87
92
|
*/
|
|
88
|
-
export async function maybeCheckpoint(stateManager, callerModule) {
|
|
93
|
+
export async function maybeCheckpoint(stateManager, callerModule, reapply) {
|
|
89
94
|
if (!stateManager.isGistMode())
|
|
90
95
|
return null;
|
|
96
|
+
// Re-apply before the push, not only on conflict: a sibling mutation's
|
|
97
|
+
// conflict recovery (another MCP tool body running in parallel) may have
|
|
98
|
+
// swapped `this.state` since the caller mutated, orphaning its change.
|
|
99
|
+
// `reapply` is an absolute set, so this is a no-op in the common case.
|
|
100
|
+
reapply?.();
|
|
91
101
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
|
|
102
|
+
return await pushOrWarn(stateManager, callerModule);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
if (err instanceof GistConcurrencyError && reapply)
|
|
106
|
+
return recoverConflict(stateManager, callerModule, reapply, err);
|
|
107
|
+
return notSynced(callerModule, err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function pushOrWarn(stateManager, callerModule) {
|
|
111
|
+
if (await stateManager.checkpoint())
|
|
98
112
|
return null;
|
|
113
|
+
const msg = 'Gist checkpoint push failed after retry; the local mutation is saved and will sync on the next successful push';
|
|
114
|
+
warn(callerModule, msg);
|
|
115
|
+
return msg;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Cross-machine conflict: another machine pushed since our last fetch. The
|
|
119
|
+
* in-memory mutation would otherwise be dropped by the next refresh or
|
|
120
|
+
* bootstrap with nothing ever retrying it (audit 2026-10-30 H1), so re-fetch
|
|
121
|
+
* (bypassing the 30s throttle), re-apply the caller's mutation on the fresh
|
|
122
|
+
* baseline, and push once more. Every caller's `reapply` is an absolute set
|
|
123
|
+
* operation, so re-running it is safe.
|
|
124
|
+
*/
|
|
125
|
+
async function recoverConflict(stateManager, callerModule, reapply, conflict) {
|
|
126
|
+
let isRefreshed;
|
|
127
|
+
try {
|
|
128
|
+
// Inside runMutation so the refresh counts as mutation-driven: a reapply
|
|
129
|
+
// follows, which is what distinguishes it from the depth-0 forced reload
|
|
130
|
+
// that refreshFromGist refuses while changes are un-pushed.
|
|
131
|
+
isRefreshed = await stateManager.runMutation(() => stateManager.refreshFromGist({ force: true }));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
return notSynced(callerModule, err);
|
|
135
|
+
}
|
|
136
|
+
if (!isRefreshed)
|
|
137
|
+
return notSynced(callerModule, conflict);
|
|
138
|
+
// From here the in-memory state is the Gist's copy: a reapply failure
|
|
139
|
+
// means the mutation is gone, not "saved".
|
|
140
|
+
try {
|
|
141
|
+
reapply();
|
|
99
142
|
}
|
|
100
143
|
catch (err) {
|
|
101
|
-
const msg = `Gist
|
|
144
|
+
const msg = `Gist conflict recovery failed; state was refreshed from the Gist and re-applying the mutation threw, so the mutation was LOST, re-run the command: ${errorMessage(err)}`;
|
|
102
145
|
warn(callerModule, msg);
|
|
103
146
|
return msg;
|
|
104
147
|
}
|
|
148
|
+
try {
|
|
149
|
+
return await pushOrWarn(stateManager, callerModule);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
return notSynced(callerModule, err);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function notSynced(callerModule, err) {
|
|
156
|
+
const msg = `Gist checkpoint failed; the local mutation is saved but NOT synced to the Gist, re-run the command to retry: ${errorMessage(err)}`;
|
|
157
|
+
warn(callerModule, msg);
|
|
158
|
+
return msg;
|
|
105
159
|
}
|
|
106
160
|
export class StateManager {
|
|
107
161
|
state;
|
|
@@ -113,6 +167,10 @@ export class StateManager {
|
|
|
113
167
|
gistDegraded = false;
|
|
114
168
|
staleness = null;
|
|
115
169
|
lastSuccessfulRefreshAt = null;
|
|
170
|
+
mutationDepth = 0;
|
|
171
|
+
/** Gist mode: a mutation was saved since the last successful push. */
|
|
172
|
+
unpushed = false;
|
|
173
|
+
refreshCount = 0;
|
|
116
174
|
loadRecovery = null;
|
|
117
175
|
/**
|
|
118
176
|
* Create a new StateManager instance.
|
|
@@ -289,6 +347,8 @@ export class StateManager {
|
|
|
289
347
|
*/
|
|
290
348
|
save(options = {}) {
|
|
291
349
|
this.state.lastRunAt = new Date().toISOString();
|
|
350
|
+
if (this.gistStore)
|
|
351
|
+
this.unpushed = true;
|
|
292
352
|
if (this.inMemoryOnly) {
|
|
293
353
|
return;
|
|
294
354
|
}
|
|
@@ -348,6 +408,8 @@ export class StateManager {
|
|
|
348
408
|
// left untouched here — a concurrent remote write is recoverable (refresh +
|
|
349
409
|
// retry), not a degradation of the Gist itself.
|
|
350
410
|
this.gistDegraded = !isPushed;
|
|
411
|
+
if (isPushed)
|
|
412
|
+
this.unpushed = false;
|
|
351
413
|
return isPushed;
|
|
352
414
|
}
|
|
353
415
|
/** Whether this StateManager is backed by a Gist. */
|
|
@@ -458,14 +520,63 @@ export class StateManager {
|
|
|
458
520
|
getLoadRecovery() {
|
|
459
521
|
return this.loadRecovery;
|
|
460
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Run `fn` as an in-flight mutation: non-forced `refreshFromGist()` calls
|
|
525
|
+
* are skipped until it settles so a concurrent refresh cannot swap
|
|
526
|
+
* `this.state` out from under it (audit 2026-10-30 M2).
|
|
527
|
+
*
|
|
528
|
+
* Deliberately a counter, not a serializing promise chain: parallel MCP
|
|
529
|
+
* tool bodies from one host message may depend on each other through the
|
|
530
|
+
* host, so queuing them would deadlock. The gap that leaves (a sibling's
|
|
531
|
+
* *forced* conflict-recovery refresh swaps the state object mid-body) is
|
|
532
|
+
* closed by `maybeCheckpoint` re-applying every mutation right before its
|
|
533
|
+
* push; bodies that cannot re-apply (`daily`) watch `refreshGeneration`.
|
|
534
|
+
*/
|
|
535
|
+
async runMutation(fn) {
|
|
536
|
+
this.mutationDepth++;
|
|
537
|
+
try {
|
|
538
|
+
return await fn();
|
|
539
|
+
}
|
|
540
|
+
finally {
|
|
541
|
+
this.mutationDepth--;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Number of times a Gist refresh replaced the in-memory state. A successful
|
|
546
|
+
* push resolves earlier un-pushed changes only if this did not advance in
|
|
547
|
+
* between (the #1443 loss-notice invariant); a long run compares it to the
|
|
548
|
+
* value at its start to learn its mutations were swapped out.
|
|
549
|
+
*/
|
|
550
|
+
get refreshGeneration() {
|
|
551
|
+
return this.refreshCount;
|
|
552
|
+
}
|
|
553
|
+
/** Gist mode: whether a saved mutation has not reached the Gist yet. */
|
|
554
|
+
hasUnpushedChanges() {
|
|
555
|
+
return this.unpushed;
|
|
556
|
+
}
|
|
461
557
|
/**
|
|
462
558
|
* Re-fetch state from the backing Gist (if in Gist mode).
|
|
463
|
-
* Throttled to once per 30 seconds by GistStateStore
|
|
559
|
+
* Throttled to once per 30 seconds by GistStateStore unless `force` is set.
|
|
560
|
+
* Returns true if state was refreshed.
|
|
464
561
|
*/
|
|
465
|
-
async refreshFromGist() {
|
|
562
|
+
async refreshFromGist(options = {}) {
|
|
466
563
|
if (!this.gistStore)
|
|
467
564
|
return false;
|
|
468
|
-
|
|
565
|
+
// A refresh replaces `this.state`, orphaning every mutation an in-flight
|
|
566
|
+
// command (e.g. a long `daily` run in the MCP server) has made so far
|
|
567
|
+
// (audit 2026-10-30 M2). Skip it while one is running; `force` is for
|
|
568
|
+
// the conflict-recovery path, which the mutation itself drives.
|
|
569
|
+
if (this.mutationDepth > 0 && !options.force)
|
|
570
|
+
return false;
|
|
571
|
+
// A forced refresh outside any mutation (the MCP/dashboard conflict
|
|
572
|
+
// retry) has nothing that will re-apply un-pushed changes afterwards, so
|
|
573
|
+
// it would silently push the remote back over them: refuse, and let the
|
|
574
|
+
// retried body surface the conflict honestly.
|
|
575
|
+
if (options.force && this.mutationDepth === 0 && this.unpushed) {
|
|
576
|
+
warn(MODULE, 'Forced Gist refresh refused: local changes are not pushed yet and nothing would re-apply them');
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
const result = await this.gistStore.refreshFromGist(options);
|
|
469
580
|
// StateManager keeps its boolean shape (callers rely on truthy-check
|
|
470
581
|
// semantics) but consults the discriminated union internally to know
|
|
471
582
|
// whether to reload state.json from the now-fresh cache (#1209 L9).
|
|
@@ -485,9 +596,9 @@ export class StateManager {
|
|
|
485
596
|
};
|
|
486
597
|
return false;
|
|
487
598
|
}
|
|
599
|
+
const wasUnpushed = this.unpushed;
|
|
488
600
|
try {
|
|
489
601
|
this.state = AgentStateSchema.parse(JSON.parse(raw));
|
|
490
|
-
this.tryReconcilePRCounts();
|
|
491
602
|
}
|
|
492
603
|
catch (err) {
|
|
493
604
|
warn(MODULE, `Failed to parse refreshed Gist state: ${errorMessage(err)}`);
|
|
@@ -501,9 +612,30 @@ export class StateManager {
|
|
|
501
612
|
};
|
|
502
613
|
return false;
|
|
503
614
|
}
|
|
615
|
+
// Derived bookkeeping on the fresh copy, not a user change: it must
|
|
616
|
+
// not count as un-pushed, so the flag is reset after it runs.
|
|
617
|
+
this.tryReconcilePRCounts();
|
|
618
|
+
this.unpushed = false;
|
|
504
619
|
// Successful refresh clears any prior staleness (#1193).
|
|
505
|
-
|
|
620
|
+
const now = new Date();
|
|
621
|
+
this.lastSuccessfulRefreshAt = now.toISOString();
|
|
506
622
|
this.staleness = null;
|
|
623
|
+
this.refreshCount++;
|
|
624
|
+
// Only the throttled depth-0 refresh gets here with un-pushed changes
|
|
625
|
+
// (a forced one is conflict recovery, which re-applies its mutation).
|
|
626
|
+
// Their push already failed once; this is the moment they are gone, so
|
|
627
|
+
// say so where commands and the dashboard read staleness (#1193).
|
|
628
|
+
if (wasUnpushed && !options.force) {
|
|
629
|
+
const reason = 'A Gist refresh replaced local state that still had un-pushed changes; they were NOT synced. ' +
|
|
630
|
+
'Re-run the command that made the change.';
|
|
631
|
+
warn(MODULE, reason);
|
|
632
|
+
this.staleness = {
|
|
633
|
+
reason,
|
|
634
|
+
source: 'cache',
|
|
635
|
+
lastSuccessfulRefresh: this.lastSuccessfulRefreshAt,
|
|
636
|
+
detectedAt: now.toISOString(),
|
|
637
|
+
};
|
|
638
|
+
}
|
|
507
639
|
}
|
|
508
640
|
else if (this.gistStore.lastRefreshError) {
|
|
509
641
|
// Distinguish "fetch failed" (set marker) from "throttled" (preserve
|
|
@@ -713,6 +845,24 @@ export class StateManager {
|
|
|
713
845
|
this.autoSave();
|
|
714
846
|
}
|
|
715
847
|
}
|
|
848
|
+
/**
|
|
849
|
+
* Overwrite the first-response lookup on the merged or closed PR matching
|
|
850
|
+
* `url`. Unlike addMergedPRs/addClosedPRs, which only fill missing fields,
|
|
851
|
+
* this replaces `firstMaintainerResponseAt` (clearing it when `at` is
|
|
852
|
+
* undefined) so ledger-backfill can recompute values recorded under an older
|
|
853
|
+
* maintainer rule. No-op when no PR with that URL is stored.
|
|
854
|
+
*/
|
|
855
|
+
setLedgerResponse(url, at, rule) {
|
|
856
|
+
const entry = this.state.mergedPRs?.find((pr) => pr.url === url) ?? this.state.closedPRs?.find((pr) => pr.url === url);
|
|
857
|
+
if (!entry)
|
|
858
|
+
return;
|
|
859
|
+
if (at === undefined)
|
|
860
|
+
delete entry.firstMaintainerResponseAt;
|
|
861
|
+
else
|
|
862
|
+
entry.firstMaintainerResponseAt = at;
|
|
863
|
+
entry.responseRule = rule;
|
|
864
|
+
this.autoSave();
|
|
865
|
+
}
|
|
716
866
|
/**
|
|
717
867
|
* Stamp `learningsExtractedAt` on the merged or closed PR matching `url` (#867).
|
|
718
868
|
* No-op when no PR with that URL is stored.
|
|
@@ -1040,30 +1190,6 @@ export class StateManager {
|
|
|
1040
1190
|
repoScoring.updateRepoScore(this.state, repo, updates);
|
|
1041
1191
|
this.autoSave();
|
|
1042
1192
|
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Increment the merged PR count for a repository.
|
|
1045
|
-
* @param repo - Repository in "owner/repo" format
|
|
1046
|
-
*/
|
|
1047
|
-
incrementMergedCount(repo) {
|
|
1048
|
-
repoScoring.incrementMergedCount(this.state, repo);
|
|
1049
|
-
this.autoSave();
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* Increment the closed-without-merge PR count.
|
|
1053
|
-
* @param repo - Repository in "owner/repo" format
|
|
1054
|
-
*/
|
|
1055
|
-
incrementClosedCount(repo) {
|
|
1056
|
-
repoScoring.incrementClosedCount(this.state, repo);
|
|
1057
|
-
this.autoSave();
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Mark a repository as hostile (score zeroed).
|
|
1061
|
-
* @param repo - Repository in "owner/repo" format
|
|
1062
|
-
*/
|
|
1063
|
-
markRepoHostile(repo) {
|
|
1064
|
-
repoScoring.markRepoHostile(this.state, repo);
|
|
1065
|
-
this.autoSave();
|
|
1066
|
-
}
|
|
1067
1193
|
/** Returns repository names that have at least one merged PR. */
|
|
1068
1194
|
getReposWithMergedPRs() {
|
|
1069
1195
|
return repoScoring.getReposWithMergedPRs(this.state);
|
|
@@ -921,6 +921,10 @@ export declare const VerifyIssueOutputSchema: z.ZodObject<{
|
|
|
921
921
|
}>>;
|
|
922
922
|
closedAt: z.ZodNullable<z.ZodString>;
|
|
923
923
|
assignees: z.ZodArray<z.ZodString>;
|
|
924
|
+
author: z.ZodNullable<z.ZodString>;
|
|
925
|
+
authorAssociation: z.ZodNullable<z.ZodString>;
|
|
926
|
+
authorIsBot: z.ZodBoolean;
|
|
927
|
+
commentCount: z.ZodNullable<z.ZodNumber>;
|
|
924
928
|
linkedPRs: z.ZodArray<z.ZodObject<{
|
|
925
929
|
number: z.ZodNumber;
|
|
926
930
|
url: z.ZodString;
|
package/dist/formatters/json.js
CHANGED
|
@@ -490,6 +490,10 @@ export const VerifyIssueOutputSchema = z.object({
|
|
|
490
490
|
stateReason: z.enum(['completed', 'not_planned', 'reopened', 'duplicate']).nullable(),
|
|
491
491
|
closedAt: z.string().nullable(),
|
|
492
492
|
assignees: z.array(z.string()),
|
|
493
|
+
author: z.string().nullable(),
|
|
494
|
+
authorAssociation: z.string().nullable(),
|
|
495
|
+
authorIsBot: z.boolean(),
|
|
496
|
+
commentCount: z.number().int().nonnegative().nullable(),
|
|
493
497
|
linkedPRs: z.array(z.object({
|
|
494
498
|
number: z.number().int().positive(),
|
|
495
499
|
url: z.string(),
|