@oss-autopilot/core 3.43.0 → 3.44.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 +160 -6
- package/dist/cli.bundle.cjs +207 -180
- package/dist/commands/check-integration.js +4 -1
- package/dist/commands/cleanup.d.ts +6 -2
- package/dist/commands/cleanup.js +72 -7
- package/dist/commands/comments.d.ts +8 -1
- package/dist/commands/comments.js +11 -3
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +26 -1
- package/dist/commands/daily-ledger.d.ts +33 -5
- package/dist/commands/daily-ledger.js +36 -13
- package/dist/commands/daily-render.d.ts +2 -1
- package/dist/commands/daily-render.js +4 -1
- package/dist/commands/daily.d.ts +3 -0
- package/dist/commands/daily.js +25 -5
- package/dist/commands/dashboard-data.js +70 -61
- package/dist/commands/dashboard-lifecycle.d.ts +36 -8
- package/dist/commands/dashboard-lifecycle.js +131 -38
- package/dist/commands/dashboard-process.d.ts +35 -0
- package/dist/commands/dashboard-process.js +65 -5
- package/dist/commands/dismiss.js +7 -6
- package/dist/commands/doctor.js +1 -8
- package/dist/commands/fork-prune.d.ts +58 -0
- package/dist/commands/fork-prune.js +247 -0
- package/dist/commands/guidelines.d.ts +46 -1
- package/dist/commands/guidelines.js +111 -12
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.js +5 -0
- package/dist/commands/overnight-push-prep.d.ts +2 -1
- package/dist/commands/overnight-push-prep.js +3 -3
- package/dist/commands/policy.d.ts +5 -1
- package/dist/commands/policy.js +14 -1
- package/dist/commands/pr-create.d.ts +48 -0
- package/dist/commands/pr-create.js +200 -0
- package/dist/commands/pr-preflight.d.ts +28 -2
- package/dist/commands/pr-preflight.js +63 -9
- package/dist/commands/setup.js +120 -36
- package/dist/commands/startup.d.ts +7 -0
- package/dist/commands/startup.js +17 -0
- package/dist/commands/status.js +5 -0
- package/dist/commands/validation.d.ts +5 -0
- package/dist/commands/validation.js +5 -0
- package/dist/commands/vet-list.js +2 -2
- package/dist/commands/vet.d.ts +8 -0
- package/dist/commands/vet.js +15 -1
- package/dist/commands/work.d.ts +4 -0
- package/dist/commands/work.js +34 -11
- package/dist/core/commit-date.d.ts +31 -5
- package/dist/core/commit-date.js +36 -8
- package/dist/core/compliance-score.d.ts +3 -0
- package/dist/core/compliance-score.js +13 -9
- package/dist/core/config-registry.d.ts +27 -2
- package/dist/core/config-registry.js +83 -2
- package/dist/core/daily-logic.d.ts +4 -1
- package/dist/core/daily-logic.js +13 -2
- package/dist/core/fork-prune.d.ts +149 -0
- package/dist/core/fork-prune.js +333 -0
- package/dist/core/gist-state-store.js +4 -8
- package/dist/core/github-stats.d.ts +7 -1
- package/dist/core/github-stats.js +15 -15
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/local-config.js +2 -3
- package/dist/core/pacing.d.ts +41 -0
- package/dist/core/pacing.js +115 -0
- package/dist/core/pr-assembly.d.ts +2 -0
- package/dist/core/pr-graphql.d.ts +16 -1
- package/dist/core/pr-graphql.js +15 -3
- package/dist/core/pr-monitor.d.ts +6 -0
- package/dist/core/pr-monitor.js +46 -10
- package/dist/core/pr-preflight.d.ts +41 -0
- package/dist/core/pr-preflight.js +406 -17
- package/dist/core/prose-script.d.ts +72 -0
- package/dist/core/prose-script.js +223 -0
- package/dist/core/repo-policy.d.ts +8 -2
- package/dist/core/repo-policy.js +34 -6
- package/dist/core/repo-score-manager.d.ts +18 -0
- package/dist/core/repo-score-manager.js +29 -0
- package/dist/core/review-analysis.d.ts +15 -2
- package/dist/core/review-analysis.js +22 -5
- package/dist/core/stale-data.d.ts +44 -7
- package/dist/core/stale-data.js +46 -8
- package/dist/core/state-persistence.js +2 -4
- package/dist/core/state-schema.d.ts +39 -0
- package/dist/core/state-schema.js +68 -1
- package/dist/core/state.d.ts +21 -0
- package/dist/core/state.js +47 -0
- package/dist/core/status-determination.js +10 -8
- package/dist/core/untrusted-content.d.ts +3 -3
- package/dist/core/untrusted-content.js +26 -8
- package/dist/core/urls.d.ts +24 -0
- package/dist/core/urls.js +76 -0
- package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
- package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/formatters/json.d.ts +171 -5
- package/dist/formatters/json.js +79 -0
- package/package.json +6 -6
- package/dist/dashboard/assets/chart-panel-C_C1lFTI.js +0 -3
- package/dist/dashboard/assets/index-B--H66Jk.js +0 -55
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The writing system of outgoing prose against the one a repo uses (#1909).
|
|
3
|
+
*
|
|
4
|
+
* A cheap script check, not language detection: it counts letters per
|
|
5
|
+
* Unicode script outside code, quoted text, URLs and identifiers. English and
|
|
6
|
+
* Spanish are both Latin script and look the same here; Chinese text sent to
|
|
7
|
+
* an English-language repo, the failure this guards against, does not.
|
|
8
|
+
* Latin-script text is never refused: English is welcome in any repo, and a
|
|
9
|
+
* non-Latin README that names English products would otherwise block it.
|
|
10
|
+
*/
|
|
11
|
+
import { codeMask } from './compliance-score.js';
|
|
12
|
+
import { ValidationError } from './errors.js';
|
|
13
|
+
import { cachedRequest, getHttpCache } from './http-cache.js';
|
|
14
|
+
import { decodeBase64 } from './pr-template.js';
|
|
15
|
+
/**
|
|
16
|
+
* Each script with the weight of one of its letters. A Han or Kana character
|
|
17
|
+
* carries about a word, a Hangul syllable about a syllable, so they count for
|
|
18
|
+
* more than one alphabet letter: a Chinese body sprinkled with English terms
|
|
19
|
+
* still reads as Chinese.
|
|
20
|
+
*/
|
|
21
|
+
const SCRIPTS = [
|
|
22
|
+
{ script: 'Latin', pattern: /\p{Script=Latin}/u, weight: 1 },
|
|
23
|
+
{ script: 'Han/Kana', pattern: /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u, weight: 3 },
|
|
24
|
+
{ script: 'Hangul', pattern: /\p{Script=Hangul}/u, weight: 2 },
|
|
25
|
+
{ script: 'Cyrillic', pattern: /\p{Script=Cyrillic}/u, weight: 1 },
|
|
26
|
+
{ script: 'Arabic', pattern: /\p{Script=Arabic}/u, weight: 1 },
|
|
27
|
+
{ script: 'Hebrew', pattern: /\p{Script=Hebrew}/u, weight: 1 },
|
|
28
|
+
{ script: 'Thai', pattern: /\p{Script=Thai}/u, weight: 1 },
|
|
29
|
+
{ script: 'Devanagari', pattern: /\p{Script=Devanagari}/u, weight: 1 },
|
|
30
|
+
{ script: 'Greek', pattern: /\p{Script=Greek}/u, weight: 1 },
|
|
31
|
+
];
|
|
32
|
+
/** The script assumed when the repo's README and CONTRIBUTING cannot be read: English, per #1909. */
|
|
33
|
+
export const DEFAULT_REPO_SCRIPTS = ['Latin'];
|
|
34
|
+
/** A script with at least this share of a repo's doc prose is one the repo writes in; two can pass (bilingual docs). */
|
|
35
|
+
export const REPO_SCRIPT_MIN_SHARE = 0.2;
|
|
36
|
+
/** Below this much weighted prose the docs say nothing reliable about the repo's language. */
|
|
37
|
+
export const MIN_REPO_PROSE_WEIGHT = 40;
|
|
38
|
+
/** Text is refused only when foreign-script prose is the majority: names and quoted errors in another script pass. */
|
|
39
|
+
export const MISMATCH_SHARE = 0.5;
|
|
40
|
+
/** Less foreign-script prose than this never blocks, so a short reply with one foreign word passes. */
|
|
41
|
+
export const MIN_FOREIGN_WEIGHT = 12;
|
|
42
|
+
/** Titles count every letter as 1: a short English title naming a CJK product (`Add 微信支付 support`) stays English. */
|
|
43
|
+
export const MIN_TITLE_FOREIGN_LETTERS = 4;
|
|
44
|
+
/** A title is refused only when more than two thirds of its letters are foreign, so a name beside two English words passes. */
|
|
45
|
+
export const TITLE_MISMATCH_SHARE = 2 / 3;
|
|
46
|
+
/** A leading Conventional Commits prefix (`fix(scope)!: `) is boilerplate, not the language the title is written in. */
|
|
47
|
+
const CONVENTIONAL_PREFIX = /^\s*\w+(?:\([^)\n]*\))?!?:\s*/;
|
|
48
|
+
const MAX_EXCERPT_CHARS = 200;
|
|
49
|
+
const QUOTE_LINE = /^\s*>/;
|
|
50
|
+
const HTML_COMMENT = /<!--[\s\S]*?(?:-->|$)/g;
|
|
51
|
+
const URL = /(?:https?:\/\/|www\.)[\w$.,/\\?#&=%:;@~+!*'-]+/gi;
|
|
52
|
+
const HTML_TAG = /<[^<>\n]*>/g;
|
|
53
|
+
/** A run of code-like characters. CJK has no spaces, so the run, not the whole word, is what gets removed. */
|
|
54
|
+
const CODE_RUN = /[\w$./\\()-]+/g;
|
|
55
|
+
// A run that is a path, a snake_case or camelCase name, a dotted name or a call: code, not prose.
|
|
56
|
+
const IDENTIFIER = /[_/\\]|[A-Za-z\d]\.[A-Za-z\d]|[a-z][A-Z]|\(\)/;
|
|
57
|
+
/** `text` with fenced and inline code (closed spans only, as the compliance score reads them) blanked out. */
|
|
58
|
+
function withoutCode(text) {
|
|
59
|
+
const mask = codeMask(text);
|
|
60
|
+
return text.replaceAll(/[^\n]/g, (char, offset) => (mask[offset] === 1 ? ' ' : char));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The prose lines of `text`: no code, blockquotes, comments, URLs, tags or
|
|
64
|
+
* identifiers. A fence that never closes is text, so it cannot hide what follows.
|
|
65
|
+
*/
|
|
66
|
+
export function proseLines(text) {
|
|
67
|
+
const lines = [];
|
|
68
|
+
for (const line of withoutCode(text).replaceAll(HTML_COMMENT, ' ').split('\n')) {
|
|
69
|
+
const prose = QUOTE_LINE.test(line) ? '' : lineProse(line);
|
|
70
|
+
if (prose !== '')
|
|
71
|
+
lines.push(prose);
|
|
72
|
+
}
|
|
73
|
+
return lines;
|
|
74
|
+
}
|
|
75
|
+
function lineProse(line) {
|
|
76
|
+
return line
|
|
77
|
+
.replaceAll(URL, ' ')
|
|
78
|
+
.replaceAll(HTML_TAG, ' ')
|
|
79
|
+
.replaceAll(CODE_RUN, (run) => (IDENTIFIER.test(run) ? ' ' : run))
|
|
80
|
+
.replaceAll(/\s+/g, ' ')
|
|
81
|
+
.trim();
|
|
82
|
+
}
|
|
83
|
+
function scriptOf(char) {
|
|
84
|
+
return SCRIPTS.find((entry) => entry.pattern.test(char));
|
|
85
|
+
}
|
|
86
|
+
const byScriptWeight = (entry) => entry.weight;
|
|
87
|
+
/** Weighted letter count per script. Letters of scripts not listed (and digits, punctuation) are ignored. */
|
|
88
|
+
function scriptWeights(lines, weigh = byScriptWeight) {
|
|
89
|
+
const weights = new Map();
|
|
90
|
+
for (const char of lines.join(' ')) {
|
|
91
|
+
const entry = scriptOf(char);
|
|
92
|
+
if (entry)
|
|
93
|
+
weights.set(entry.script, (weights.get(entry.script) ?? 0) + weigh(entry));
|
|
94
|
+
}
|
|
95
|
+
return weights;
|
|
96
|
+
}
|
|
97
|
+
function total(weights) {
|
|
98
|
+
let sum = 0;
|
|
99
|
+
for (const weight of weights.values())
|
|
100
|
+
sum += weight;
|
|
101
|
+
return sum;
|
|
102
|
+
}
|
|
103
|
+
/** The scripts a repo's docs are written in; null when they hold too little prose to tell. */
|
|
104
|
+
export function docScripts(docs) {
|
|
105
|
+
const weights = scriptWeights(proseLines(docs));
|
|
106
|
+
const sum = total(weights);
|
|
107
|
+
if (sum < MIN_REPO_PROSE_WEIGHT)
|
|
108
|
+
return null;
|
|
109
|
+
return SCRIPTS.map((entry) => entry.script).filter((script) => (weights.get(script) ?? 0) / sum >= REPO_SCRIPT_MIN_SHARE);
|
|
110
|
+
}
|
|
111
|
+
const BODY_RULE = { weigh: byScriptWeight, minForeign: MIN_FOREIGN_WEIGHT, share: MISMATCH_SHARE };
|
|
112
|
+
const TITLE_RULE = { weigh: () => 1, minForeign: MIN_TITLE_FOREIGN_LETTERS, share: TITLE_MISMATCH_SHARE };
|
|
113
|
+
/**
|
|
114
|
+
* Null when `text` is written in the `accepted` scripts, in Latin script, or
|
|
115
|
+
* is too short to tell; else what does not match.
|
|
116
|
+
*/
|
|
117
|
+
export function scriptMismatch(text, accepted) {
|
|
118
|
+
return mismatchUnder(text, accepted, BODY_RULE);
|
|
119
|
+
}
|
|
120
|
+
/** {@link scriptMismatch} for a PR title: prefix dropped, every letter weighs 1, a stricter share. */
|
|
121
|
+
export function titleMismatch(title, accepted) {
|
|
122
|
+
return mismatchUnder(title.replace(CONVENTIONAL_PREFIX, ''), accepted, TITLE_RULE);
|
|
123
|
+
}
|
|
124
|
+
function mismatchUnder(text, accepted, rule) {
|
|
125
|
+
const lines = proseLines(text);
|
|
126
|
+
const weights = scriptWeights(lines, rule.weigh);
|
|
127
|
+
const foreignScripts = SCRIPTS.map((entry) => entry.script).filter(
|
|
128
|
+
// Latin is never foreign: English is welcome everywhere, so only a non-Latin majority is refused.
|
|
129
|
+
(script) => script !== 'Latin' && !accepted.includes(script) && weights.has(script));
|
|
130
|
+
let foreignWeight = 0;
|
|
131
|
+
for (const script of foreignScripts)
|
|
132
|
+
foreignWeight += weights.get(script) ?? 0;
|
|
133
|
+
const share = foreignWeight / (total(weights) || 1);
|
|
134
|
+
if (foreignWeight < rule.minForeign || share <= rule.share)
|
|
135
|
+
return null;
|
|
136
|
+
const isForeign = (char) => {
|
|
137
|
+
const script = scriptOf(char)?.script;
|
|
138
|
+
return script !== undefined && foreignScripts.includes(script);
|
|
139
|
+
};
|
|
140
|
+
const excerpt = lines.filter((line) => [...line].some((char) => isForeign(char))).join('\n');
|
|
141
|
+
return {
|
|
142
|
+
share,
|
|
143
|
+
foreign: foreignScripts,
|
|
144
|
+
excerpt: excerpt.length > MAX_EXCERPT_CHARS ? `${excerpt.slice(0, MAX_EXCERPT_CHARS)}…` : excerpt,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** The denial text: which repo, which scripts, how much, and the offending lines. */
|
|
148
|
+
export function describeMismatch(repo, repoScripts, mismatch) {
|
|
149
|
+
const assumed = repoScripts.isDefault
|
|
150
|
+
? ' (assumed: its README and CONTRIBUTING could not be read or say too little)'
|
|
151
|
+
: '';
|
|
152
|
+
const percent = Math.round(mismatch.share * 100);
|
|
153
|
+
return (`language mismatch: ${repo} writes in ${repoScripts.scripts.join(' and ')} script${assumed}, ` +
|
|
154
|
+
`but ${percent}% of this text's prose is in ${mismatch.foreign.join(' and ')} script; ` +
|
|
155
|
+
`rewrite it in the repo's language. Quoted log or error text in another script can go in a \`\`\` code fence or a > blockquote, which this check ignores. ` +
|
|
156
|
+
`Only if the user confirms the repo's language was misjudged, they can post from the terminal with --allow-script-mismatch. ` +
|
|
157
|
+
`Offending text: ${JSON.stringify(mismatch.excerpt)}`);
|
|
158
|
+
}
|
|
159
|
+
/** A doc's decoded text through the ETag cache (a repeat read is a free 304); '' when missing or unreadable. */
|
|
160
|
+
async function cachedDocText(url, fetch) {
|
|
161
|
+
let data;
|
|
162
|
+
try {
|
|
163
|
+
data = await cachedRequest(getHttpCache(), url, fetch);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return '';
|
|
167
|
+
}
|
|
168
|
+
const content = data.content;
|
|
169
|
+
return typeof content === 'string' ? decodeBase64(content) : '';
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The CONTRIBUTING file wherever GitHub finds it (root, `.github/`, `docs/`),
|
|
173
|
+
* located through the community profile. Both reads go through the ETag cache;
|
|
174
|
+
* the profile answers 200 even without the file, so a missing CONTRIBUTING
|
|
175
|
+
* costs a free 304 on later reads instead of fresh 404s.
|
|
176
|
+
*/
|
|
177
|
+
async function contributingText(octokit, owner, repo, base) {
|
|
178
|
+
let profile;
|
|
179
|
+
try {
|
|
180
|
+
profile = await cachedRequest(getHttpCache(), `${base}/community/profile`, (headers) => octokit.repos.getCommunityProfileMetrics({ owner, repo, headers }));
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return '';
|
|
184
|
+
}
|
|
185
|
+
const url = profile.files?.contributing?.url;
|
|
186
|
+
const path = typeof url === 'string' ? /\/contents\/([^?#]+)/.exec(url)?.[1] : undefined;
|
|
187
|
+
if (path === undefined)
|
|
188
|
+
return '';
|
|
189
|
+
return cachedDocText(`${base}/contents/${path}`, (headers) => octokit.repos.getContent({ owner, repo, path, headers }));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The scripts `owner/repo` writes in, read from its README and CONTRIBUTING
|
|
193
|
+
* through the shared ETag cache. Never throws: an unreadable repo gets the
|
|
194
|
+
* English default, marked `isDefault`.
|
|
195
|
+
*/
|
|
196
|
+
export async function readRepoScripts(octokit, owner, repo) {
|
|
197
|
+
const base = `/repos/${owner}/${repo}`;
|
|
198
|
+
const docs = await Promise.all([
|
|
199
|
+
cachedDocText(`${base}/readme`, (headers) => octokit.repos.getReadme({ owner, repo, headers })),
|
|
200
|
+
contributingText(octokit, owner, repo, base),
|
|
201
|
+
]);
|
|
202
|
+
const scripts = docScripts(docs.join('\n'));
|
|
203
|
+
return scripts && scripts.length > 0
|
|
204
|
+
? { scripts, isDefault: false }
|
|
205
|
+
: { scripts: DEFAULT_REPO_SCRIPTS, isDefault: true };
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check `text` against the script `owner/repo` writes in (#1909). Every
|
|
209
|
+
* comment `post` and `claim` send, from the CLI or MCP, crosses this before
|
|
210
|
+
* GitHub is written to. A mismatch is refused; with `isMismatchAllowed` (a CLI
|
|
211
|
+
* flag only, never an MCP argument) it comes back as a warning instead. No
|
|
212
|
+
* rewrite, no translation.
|
|
213
|
+
*/
|
|
214
|
+
export async function checkRepoScript(octokit, target, text, isMismatchAllowed) {
|
|
215
|
+
const repoScripts = await readRepoScripts(octokit, target.owner, target.repo);
|
|
216
|
+
const mismatch = scriptMismatch(text, repoScripts.scripts);
|
|
217
|
+
if (!mismatch)
|
|
218
|
+
return undefined;
|
|
219
|
+
const message = describeMismatch(`${target.owner}/${target.repo}`, repoScripts, mismatch);
|
|
220
|
+
if (isMismatchAllowed)
|
|
221
|
+
return message;
|
|
222
|
+
throw new ValidationError(message);
|
|
223
|
+
}
|
|
@@ -60,7 +60,8 @@ export declare function isUnreadable(state: PolicyState, repo: string): boolean;
|
|
|
60
60
|
/**
|
|
61
61
|
* The stored record for `repo`, or null when there is none. An entry that does
|
|
62
62
|
* not parse but says `aiPolicy: 'banned'` still reads as a ban (every other
|
|
63
|
-
* field unknown): a newer release's record must not lift a ban here.
|
|
63
|
+
* field unknown): a newer release's record must not lift a ban here. A
|
|
64
|
+
* disclosure excerpt an older release stored is dropped on read.
|
|
64
65
|
*/
|
|
65
66
|
export declare function storedPolicy(state: PolicyState, repo: string): RepoPolicy | null;
|
|
66
67
|
/** True when the raw stored entry says the user set it, even when this release cannot parse the rest. */
|
|
@@ -96,9 +97,14 @@ export declare function summarizePolicy(policy: RepoPolicy): RepoPolicySummary;
|
|
|
96
97
|
export declare function policyField(policy: RepoPolicy | null): {
|
|
97
98
|
policy?: RepoPolicySummary;
|
|
98
99
|
};
|
|
99
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Quoted lines, disclosure text and the gate label inside `<github-content>`
|
|
102
|
+
* fences, for agent-facing output. `disclosureText` and `gateLabel` are only
|
|
103
|
+
* ever what the user set.
|
|
104
|
+
*/
|
|
100
105
|
export declare function fencePolicyText(repo: string, policy: RepoPolicy): {
|
|
101
106
|
disclosureText?: string;
|
|
107
|
+
gateLabel?: string;
|
|
102
108
|
sources?: string;
|
|
103
109
|
};
|
|
104
110
|
/** Same rules, ignoring when they were recorded. */
|
package/dist/core/repo-policy.js
CHANGED
|
@@ -154,8 +154,8 @@ function scanAi(doc, found) {
|
|
|
154
154
|
const disclosure = scanAIDisclosureRequirement(doc.content).matches;
|
|
155
155
|
const asked = disclosure.find((m) => m.category !== 'invited');
|
|
156
156
|
if (asked) {
|
|
157
|
+
// The excerpt goes to `source` only: it is a window around the repo's rule, not a line to paste (#2040).
|
|
157
158
|
found.ai = { policy: 'disclosure-required', file: doc.file, line: asked.excerpt };
|
|
158
|
-
found.disclosure = asked.excerpt;
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
const invited = disclosure.at(0);
|
|
@@ -202,7 +202,7 @@ function scanAiPrLimit(doc, found) {
|
|
|
202
202
|
* as `none`. Silence on AI stays `unknown`: it is not permission.
|
|
203
203
|
*/
|
|
204
204
|
export function derivePolicy(docs, now = new Date()) {
|
|
205
|
-
const found = { ai: null,
|
|
205
|
+
const found = { ai: null, cla: null, commitRules: [], gates: new Map(), aiPrLimit: null };
|
|
206
206
|
const readable = docs.filter((d) => d.content.trim() !== '');
|
|
207
207
|
for (const doc of readable) {
|
|
208
208
|
scanAi(doc, found);
|
|
@@ -217,7 +217,6 @@ export function derivePolicy(docs, now = new Date()) {
|
|
|
217
217
|
.slice(0, 10);
|
|
218
218
|
return {
|
|
219
219
|
aiPolicy: found.ai?.policy ?? 'unknown',
|
|
220
|
-
...(found.disclosure !== null && { disclosureText: quote(found.disclosure) }),
|
|
221
220
|
cla: found.cla ? 'required' : silent,
|
|
222
221
|
commitRules: found.commitRules.map((r) => r.rule),
|
|
223
222
|
prGate: gate ?? silent,
|
|
@@ -286,16 +285,38 @@ export function isUnreadable(state, repo) {
|
|
|
286
285
|
const raw = state.repoPolicies?.[repo.toLowerCase()];
|
|
287
286
|
return raw !== undefined && !RepoPolicySchema.safeParse(raw).success;
|
|
288
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* `policy` with `disclosureText` and `gateLabel` only where the user set them
|
|
290
|
+
* (#2040). Neither is ever read from repo text, so an unreviewed record keeps
|
|
291
|
+
* neither. Releases before that stored the excerpt vet read as
|
|
292
|
+
* `disclosureText`; `policy set --ai-policy disclosure-required` without
|
|
293
|
+
* `--disclosure-text` then kept it and marked the record reviewed. Either way
|
|
294
|
+
* the text equals the quoted line `vet` put in `source`, which still carries it.
|
|
295
|
+
*/
|
|
296
|
+
function withUserTextOnly(policy) {
|
|
297
|
+
const { disclosureText, gateLabel, ...rest } = policy;
|
|
298
|
+
if (disclosureText === undefined && gateLabel === undefined)
|
|
299
|
+
return policy;
|
|
300
|
+
if (!policy.reviewedByUser)
|
|
301
|
+
return rest;
|
|
302
|
+
const isExcerpt = policy.source.some((s) => s.file !== 'user' && s.quotedLine === disclosureText);
|
|
303
|
+
return {
|
|
304
|
+
...rest,
|
|
305
|
+
...(disclosureText !== undefined && !isExcerpt && { disclosureText }),
|
|
306
|
+
...(gateLabel !== undefined && { gateLabel }),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
289
309
|
/**
|
|
290
310
|
* The stored record for `repo`, or null when there is none. An entry that does
|
|
291
311
|
* not parse but says `aiPolicy: 'banned'` still reads as a ban (every other
|
|
292
|
-
* field unknown): a newer release's record must not lift a ban here.
|
|
312
|
+
* field unknown): a newer release's record must not lift a ban here. A
|
|
313
|
+
* disclosure excerpt an older release stored is dropped on read.
|
|
293
314
|
*/
|
|
294
315
|
export function storedPolicy(state, repo) {
|
|
295
316
|
const raw = rawEntry(state, repo);
|
|
296
317
|
const parsed = RepoPolicySchema.safeParse(raw);
|
|
297
318
|
if (parsed.success)
|
|
298
|
-
return parsed.data;
|
|
319
|
+
return withUserTextOnly(parsed.data);
|
|
299
320
|
if (raw?.aiPolicy !== 'banned')
|
|
300
321
|
return null;
|
|
301
322
|
return { ...UNKNOWN_POLICY, aiPolicy: 'banned', reviewedByUser: raw.reviewedByUser === true, updatedAt: EPOCH };
|
|
@@ -384,13 +405,20 @@ export function summarizePolicy(policy) {
|
|
|
384
405
|
export function policyField(policy) {
|
|
385
406
|
return policy ? { policy: summarizePolicy(policy) } : {};
|
|
386
407
|
}
|
|
387
|
-
/**
|
|
408
|
+
/**
|
|
409
|
+
* Quoted lines, disclosure text and the gate label inside `<github-content>`
|
|
410
|
+
* fences, for agent-facing output. `disclosureText` and `gateLabel` are only
|
|
411
|
+
* ever what the user set.
|
|
412
|
+
*/
|
|
388
413
|
export function fencePolicyText(repo, policy) {
|
|
389
414
|
const lines = policy.source.map((s) => `${s.file}: ${s.quotedLine}`);
|
|
390
415
|
return {
|
|
391
416
|
...(policy.disclosureText !== undefined && {
|
|
392
417
|
disclosureText: wrapUntrustedContent(policy.disclosureText, repo, { source: 'repo-policy' }),
|
|
393
418
|
}),
|
|
419
|
+
...(policy.gateLabel !== undefined && {
|
|
420
|
+
gateLabel: wrapUntrustedContent(policy.gateLabel, repo, { source: 'repo-policy' }),
|
|
421
|
+
}),
|
|
394
422
|
...(lines.length > 0 && { sources: wrapUntrustedContent(lines.join('\n'), repo, { source: 'repo-policy' }) }),
|
|
395
423
|
};
|
|
396
424
|
}
|
|
@@ -35,6 +35,24 @@ export declare function getRepoScore(state: Readonly<AgentState>, repo: string):
|
|
|
35
35
|
* numeric score is recalculated.
|
|
36
36
|
*/
|
|
37
37
|
export declare function updateRepoScore(state: AgentState, repo: string, updates: RepoScoreUpdate): void;
|
|
38
|
+
/** Each repo's outcome evidence and lastEvaluatedAt, as {@link snapshotOutcomes} found them. */
|
|
39
|
+
export type OutcomeSnapshot = ReadonlyMap<string, {
|
|
40
|
+
fingerprint: string;
|
|
41
|
+
lastEvaluatedAt: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** Record every repo's outcome evidence before a run rewrites it in several steps. */
|
|
44
|
+
export declare function snapshotOutcomes(state: Readonly<AgentState>): OutcomeSnapshot;
|
|
45
|
+
/**
|
|
46
|
+
* Put back `lastEvaluatedAt` for every repo whose outcome evidence ends where
|
|
47
|
+
* `snapshot` found it (#2045). Daily writes a repo's counts in steps (a stale
|
|
48
|
+
* reset or a capped search count, then the ledger reconciliation raises it
|
|
49
|
+
* back), and updateRepoScore sees each step as a change. Without this a repo
|
|
50
|
+
* below minStars, or one whose PRs fall outside the count search, was
|
|
51
|
+
* re-evaluated on every run and its low score never expired.
|
|
52
|
+
*
|
|
53
|
+
* @returns how many repos had their time put back
|
|
54
|
+
*/
|
|
55
|
+
export declare function restoreUnchangedEvaluations(state: AgentState, snapshot: OutcomeSnapshot): number;
|
|
38
56
|
/**
|
|
39
57
|
* Get repositories where the user has at least one merged PR, sorted by merged count descending.
|
|
40
58
|
*/
|
|
@@ -155,6 +155,35 @@ export function updateRepoScore(state, repo, updates) {
|
|
|
155
155
|
}
|
|
156
156
|
debug(MODULE, `Updated repo score for ${repo}: ${repoScore.score}/10`);
|
|
157
157
|
}
|
|
158
|
+
/** Record every repo's outcome evidence before a run rewrites it in several steps. */
|
|
159
|
+
export function snapshotOutcomes(state) {
|
|
160
|
+
const snapshot = new Map();
|
|
161
|
+
for (const [repo, rs] of Object.entries(state.repoScores)) {
|
|
162
|
+
snapshot.set(repo, { fingerprint: outcomeFingerprint(rs), lastEvaluatedAt: rs.lastEvaluatedAt });
|
|
163
|
+
}
|
|
164
|
+
return snapshot;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Put back `lastEvaluatedAt` for every repo whose outcome evidence ends where
|
|
168
|
+
* `snapshot` found it (#2045). Daily writes a repo's counts in steps (a stale
|
|
169
|
+
* reset or a capped search count, then the ledger reconciliation raises it
|
|
170
|
+
* back), and updateRepoScore sees each step as a change. Without this a repo
|
|
171
|
+
* below minStars, or one whose PRs fall outside the count search, was
|
|
172
|
+
* re-evaluated on every run and its low score never expired.
|
|
173
|
+
*
|
|
174
|
+
* @returns how many repos had their time put back
|
|
175
|
+
*/
|
|
176
|
+
export function restoreUnchangedEvaluations(state, snapshot) {
|
|
177
|
+
let restored = 0;
|
|
178
|
+
for (const [repo, before] of snapshot) {
|
|
179
|
+
const rs = state.repoScores[repo];
|
|
180
|
+
if (rs && rs.lastEvaluatedAt !== before.lastEvaluatedAt && outcomeFingerprint(rs) === before.fingerprint) {
|
|
181
|
+
rs.lastEvaluatedAt = before.lastEvaluatedAt;
|
|
182
|
+
restored++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return restored;
|
|
186
|
+
}
|
|
158
187
|
/**
|
|
159
188
|
* Get repositories where the user has at least one merged PR, sorted by merged count descending.
|
|
160
189
|
*/
|
|
@@ -42,8 +42,6 @@ export declare function getStandingApprovalDate(reviews: VerdictReview[], login:
|
|
|
42
42
|
/**
|
|
43
43
|
* Get the date of the latest CHANGES_REQUESTED review (from any human reviewer).
|
|
44
44
|
* Used to detect needs_changes status when review feedback is in inline comments.
|
|
45
|
-
* Bot reviews are skipped (#1840): a bot re-reviewing every push would otherwise
|
|
46
|
-
* move the date past the author's fix commit.
|
|
47
45
|
*/
|
|
48
46
|
export declare function getLatestChangesRequestedDate(reviews: Array<{
|
|
49
47
|
state?: string | null;
|
|
@@ -53,6 +51,21 @@ export declare function getLatestChangesRequestedDate(reviews: Array<{
|
|
|
53
51
|
type?: string | null;
|
|
54
52
|
} | null;
|
|
55
53
|
}>): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The head commit the latest CHANGES_REQUESTED review (from any human
|
|
56
|
+
* reviewer) was submitted against. A head moved onto a new parent since then
|
|
57
|
+
* was rebased, not amended, so its new committer date says nothing about the
|
|
58
|
+
* review (#2042).
|
|
59
|
+
*/
|
|
60
|
+
export declare function getChangesRequestedCommitSha(reviews: Array<{
|
|
61
|
+
state?: string | null;
|
|
62
|
+
submitted_at?: string | null;
|
|
63
|
+
user?: {
|
|
64
|
+
login?: string;
|
|
65
|
+
type?: string | null;
|
|
66
|
+
} | null;
|
|
67
|
+
commit_id?: string | null;
|
|
68
|
+
}>): string | undefined;
|
|
56
69
|
/**
|
|
57
70
|
* Check if all inline comments in a COMMENTED review are self-replies.
|
|
58
71
|
* A self-reply is when an author replies to their own earlier inline comment.
|
|
@@ -64,22 +64,39 @@ export function getStandingApprovalDate(reviews, login) {
|
|
|
64
64
|
return approval?.submitted_at ?? undefined;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
* Used to detect needs_changes status when review feedback is in inline comments.
|
|
67
|
+
* The latest CHANGES_REQUESTED review (from any human reviewer).
|
|
69
68
|
* Bot reviews are skipped (#1840): a bot re-reviewing every push would otherwise
|
|
70
69
|
* move the date past the author's fix commit.
|
|
71
70
|
*/
|
|
72
|
-
|
|
71
|
+
function getLatestChangesRequestedReview(reviews) {
|
|
73
72
|
let latest;
|
|
73
|
+
let latestAt;
|
|
74
74
|
for (const review of reviews) {
|
|
75
75
|
if (review.state !== 'CHANGES_REQUESTED' || isBotReview(review))
|
|
76
76
|
continue;
|
|
77
|
-
if (review.submitted_at && (!
|
|
78
|
-
latest = review
|
|
77
|
+
if (review.submitted_at && (!latestAt || review.submitted_at > latestAt)) {
|
|
78
|
+
latest = review;
|
|
79
|
+
latestAt = review.submitted_at;
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
return latest;
|
|
82
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the date of the latest CHANGES_REQUESTED review (from any human reviewer).
|
|
86
|
+
* Used to detect needs_changes status when review feedback is in inline comments.
|
|
87
|
+
*/
|
|
88
|
+
export function getLatestChangesRequestedDate(reviews) {
|
|
89
|
+
return getLatestChangesRequestedReview(reviews)?.submitted_at ?? undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The head commit the latest CHANGES_REQUESTED review (from any human
|
|
93
|
+
* reviewer) was submitted against. A head moved onto a new parent since then
|
|
94
|
+
* was rebased, not amended, so its new committer date says nothing about the
|
|
95
|
+
* review (#2042).
|
|
96
|
+
*/
|
|
97
|
+
export function getChangesRequestedCommitSha(reviews) {
|
|
98
|
+
return getLatestChangesRequestedReview(reviews)?.commit_id ?? undefined;
|
|
99
|
+
}
|
|
83
100
|
/**
|
|
84
101
|
* Check if all inline comments in a COMMENTED review are self-replies.
|
|
85
102
|
* A self-reply is when an author replies to their own earlier inline comment.
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Retention for the rejected state copies under `~/.oss-autopilot` (#1956).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
4
|
+
* {@link preserveRejected} keeps a file that failed validation as
|
|
5
|
+
* `<name>.json.rejected-<ms>` beside it so the user can recover it by hand:
|
|
6
|
+
* `state.json` (state-persistence.ts), `state-cache.json`
|
|
7
|
+
* (gist-state-store.ts) and `local-config.json` (local-config.ts). Nothing
|
|
8
8
|
* reads them back, and one bad night can write dozens.
|
|
9
9
|
*
|
|
10
10
|
* Kept: the newest {@link REJECTED_KEEP} of each kind, the oldest of each kind
|
|
11
11
|
* (the first copy of an incident is the one most likely to hold the state
|
|
12
12
|
* from before it), and every copy younger than {@link REJECTED_MIN_AGE_DAYS}.
|
|
13
13
|
* Only direct children of the data
|
|
14
|
-
* directory
|
|
15
|
-
* only regular files: a symlink or a directory with a matching name is
|
|
16
|
-
* alone.
|
|
14
|
+
* directory named like what {@link preserveRejected} writes are considered,
|
|
15
|
+
* and only regular files: a symlink or a directory with a matching name is
|
|
16
|
+
* left alone.
|
|
17
17
|
*/
|
|
18
18
|
export declare const REJECTED_KEEP = 5;
|
|
19
19
|
export declare const REJECTED_MIN_AGE_DAYS = 7;
|
|
20
20
|
export declare const DAY_MS: number;
|
|
21
|
+
/** `cleanup` keeps a worktree touched within this many days (commands/cleanup.ts). */
|
|
22
|
+
export declare const WORKTREE_MIN_AGE_DAYS = 14;
|
|
21
23
|
/** Directory names the overnight preparer gives its worktrees: `<owner>-<repo>-<n>`, `...-issue-<n>`. */
|
|
22
24
|
export declare const WORKTREE_NAME: RegExp;
|
|
23
25
|
/** True when `child`, with every symlink resolved, sits strictly inside `parent`. */
|
|
@@ -27,6 +29,41 @@ export declare function isInside(parent: string, child: string): boolean;
|
|
|
27
29
|
* Read-only. Throws on an unreadable directory; a missing one is empty.
|
|
28
30
|
*/
|
|
29
31
|
export declare function staleRejectedCopies(dataDir: string, now?: number): string[];
|
|
32
|
+
export interface StaleDataCounts {
|
|
33
|
+
/** Directories under `worktrees/` named like the overnight preparer's; not judged, so not all removable. */
|
|
34
|
+
worktrees: number;
|
|
35
|
+
/**
|
|
36
|
+
* Those whose own mtime is at least {@link WORKTREE_MIN_AGE_DAYS} days old:
|
|
37
|
+
* an upper bound by age only. `cleanup` also checks the index's mtime and
|
|
38
|
+
* that the worktree is clean and pushed, so it may remove fewer.
|
|
39
|
+
*/
|
|
40
|
+
oldWorktrees: number;
|
|
41
|
+
/** Rejected state copies past retention. */
|
|
42
|
+
rejected: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Counts for `doctor` and `startup` from directory listings only: no Git runs,
|
|
46
|
+
* so nothing a worktree's config names is executed. Which worktrees `cleanup`
|
|
47
|
+
* would remove is its own (slower) dry run. Throws on an unreadable directory.
|
|
48
|
+
*/
|
|
49
|
+
export declare function countStaleData(dataDir: string, now?: number): StaleDataCounts;
|
|
50
|
+
/** How {@link preserveRejected} keeps the rejected file. */
|
|
51
|
+
export type RejectedCopySource =
|
|
52
|
+
/** Copy the file; the copy keeps its mode. */
|
|
53
|
+
'copy'
|
|
54
|
+
/** Rename the file out of the way, so the next write cannot overwrite it. */
|
|
55
|
+
| 'move'
|
|
56
|
+
/** Write this text instead (owner-only), for content that was never on disk. */
|
|
57
|
+
| {
|
|
58
|
+
content: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Keep a file that failed validation as `<filePath>.rejected-<ms>` for
|
|
62
|
+
* recovery by hand, then prune its directory's rejected copies past retention
|
|
63
|
+
* ({@link pruneRejectedCopies}, which never throws). Returns the copy's path.
|
|
64
|
+
* Throws when the copy cannot be made; callers report that their own way.
|
|
65
|
+
*/
|
|
66
|
+
export declare function preserveRejected(filePath: string, source: RejectedCopySource): string;
|
|
30
67
|
export interface PruneResult {
|
|
31
68
|
/** Paths deleted (or, from a dry run, the paths that would be). */
|
|
32
69
|
removed: string[];
|
package/dist/core/stale-data.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Retention for the rejected state copies under `~/.oss-autopilot` (#1956).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
4
|
+
* {@link preserveRejected} keeps a file that failed validation as
|
|
5
|
+
* `<name>.json.rejected-<ms>` beside it so the user can recover it by hand:
|
|
6
|
+
* `state.json` (state-persistence.ts), `state-cache.json`
|
|
7
|
+
* (gist-state-store.ts) and `local-config.json` (local-config.ts). Nothing
|
|
8
8
|
* reads them back, and one bad night can write dozens.
|
|
9
9
|
*
|
|
10
10
|
* Kept: the newest {@link REJECTED_KEEP} of each kind, the oldest of each kind
|
|
11
11
|
* (the first copy of an incident is the one most likely to hold the state
|
|
12
12
|
* from before it), and every copy younger than {@link REJECTED_MIN_AGE_DAYS}.
|
|
13
13
|
* Only direct children of the data
|
|
14
|
-
* directory
|
|
15
|
-
* only regular files: a symlink or a directory with a matching name is
|
|
16
|
-
* alone.
|
|
14
|
+
* directory named like what {@link preserveRejected} writes are considered,
|
|
15
|
+
* and only regular files: a symlink or a directory with a matching name is
|
|
16
|
+
* left alone.
|
|
17
17
|
*/
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
@@ -23,9 +23,12 @@ const MODULE = 'stale-data';
|
|
|
23
23
|
export const REJECTED_KEEP = 5;
|
|
24
24
|
export const REJECTED_MIN_AGE_DAYS = 7;
|
|
25
25
|
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
/** `cleanup` keeps a worktree touched within this many days (commands/cleanup.ts). */
|
|
27
|
+
export const WORKTREE_MIN_AGE_DAYS = 14;
|
|
26
28
|
/** Directory names the overnight preparer gives its worktrees: `<owner>-<repo>-<n>`, `...-issue-<n>`. */
|
|
27
29
|
export const WORKTREE_NAME = /^[\w.-]+-\d+$/;
|
|
28
|
-
|
|
30
|
+
/** `<kind>.json.rejected-<ms>`, the name {@link preserveRejected} gives any `<kind>.json`. */
|
|
31
|
+
const REJECTED_PATTERN = /^([\w-]+)\.json\.rejected-(\d+)$/;
|
|
29
32
|
/** True when `child`, with every symlink resolved, sits strictly inside `parent`. */
|
|
30
33
|
export function isInside(parent, child) {
|
|
31
34
|
const rel = path.relative(fs.realpathSync(parent), fs.realpathSync(child));
|
|
@@ -77,6 +80,41 @@ export function staleRejectedCopies(dataDir, now = Date.now()) {
|
|
|
77
80
|
copies.every((other) => !isNewer(copy, other));
|
|
78
81
|
return copies.filter((copy) => !isCovered(copy)).map((copy) => copy.file);
|
|
79
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Counts for `doctor` and `startup` from directory listings only: no Git runs,
|
|
85
|
+
* so nothing a worktree's config names is executed. Which worktrees `cleanup`
|
|
86
|
+
* would remove is its own (slower) dry run. Throws on an unreadable directory.
|
|
87
|
+
*/
|
|
88
|
+
export function countStaleData(dataDir, now = Date.now()) {
|
|
89
|
+
const root = path.join(dataDir, 'worktrees');
|
|
90
|
+
const hasRoot = fs.existsSync(root) && fs.lstatSync(root).isDirectory();
|
|
91
|
+
const entries = hasRoot ? fs.readdirSync(root, { withFileTypes: true }) : [];
|
|
92
|
+
const worktrees = entries.filter((entry) => entry.isDirectory() && WORKTREE_NAME.test(entry.name));
|
|
93
|
+
const cutoff = now - WORKTREE_MIN_AGE_DAYS * DAY_MS;
|
|
94
|
+
const old = worktrees.filter((entry) => fs.lstatSync(path.join(root, entry.name)).mtimeMs <= cutoff);
|
|
95
|
+
return {
|
|
96
|
+
worktrees: worktrees.length,
|
|
97
|
+
oldWorktrees: old.length,
|
|
98
|
+
rejected: staleRejectedCopies(dataDir, now).length,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Keep a file that failed validation as `<filePath>.rejected-<ms>` for
|
|
103
|
+
* recovery by hand, then prune its directory's rejected copies past retention
|
|
104
|
+
* ({@link pruneRejectedCopies}, which never throws). Returns the copy's path.
|
|
105
|
+
* Throws when the copy cannot be made; callers report that their own way.
|
|
106
|
+
*/
|
|
107
|
+
export function preserveRejected(filePath, source) {
|
|
108
|
+
const rejectedPath = `${filePath}.rejected-${Date.now()}`;
|
|
109
|
+
if (source === 'copy')
|
|
110
|
+
fs.copyFileSync(filePath, rejectedPath);
|
|
111
|
+
else if (source === 'move')
|
|
112
|
+
fs.renameSync(filePath, rejectedPath);
|
|
113
|
+
else
|
|
114
|
+
fs.writeFileSync(rejectedPath, source.content, { encoding: 'utf8', mode: 0o600 });
|
|
115
|
+
pruneRejectedCopies(path.dirname(rejectedPath));
|
|
116
|
+
return rejectedPath;
|
|
117
|
+
}
|
|
80
118
|
function didRemove(file, errors) {
|
|
81
119
|
try {
|
|
82
120
|
fs.unlinkSync(file);
|
|
@@ -9,7 +9,7 @@ import * as path from 'node:path';
|
|
|
9
9
|
import { AgentStateSchema, NEWER_WRITER_HINT, malformedWorkClaimCount, unknownStateKeys } from './state-schema.js';
|
|
10
10
|
import { serializeState } from './state-prune.js';
|
|
11
11
|
import { getStatePath, getBackupDir, getDataDir, getLegacyStatePath, getLegacyBackupDir } from './paths.js';
|
|
12
|
-
import {
|
|
12
|
+
import { preserveRejected } from './stale-data.js';
|
|
13
13
|
import { errorMessage, ConcurrencyError, NewerStateVersionError, StateLockTimeoutError } from './errors.js';
|
|
14
14
|
import { debug, warn } from './logger.js';
|
|
15
15
|
const MODULE = 'state';
|
|
@@ -475,10 +475,8 @@ function isSameIdentity(a, b) {
|
|
|
475
475
|
*/
|
|
476
476
|
function preserveRejectedStateFile(statePath) {
|
|
477
477
|
try {
|
|
478
|
-
const rejectedPath = statePath
|
|
479
|
-
fs.copyFileSync(statePath, rejectedPath);
|
|
478
|
+
const rejectedPath = preserveRejected(statePath, 'copy');
|
|
480
479
|
warn(MODULE, `Previous state preserved at: ${rejectedPath}`);
|
|
481
|
-
pruneRejectedCopies(path.dirname(rejectedPath));
|
|
482
480
|
return rejectedPath;
|
|
483
481
|
}
|
|
484
482
|
catch (preserveErr) {
|