opencode-azure-devops-pr-review 0.3.7 → 0.4.1
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/CHANGELOG.md +137 -0
- package/README.md +123 -59
- package/package.json +1 -1
- package/src/attribution.mjs +47 -8
- package/src/azure.mjs +19 -13
- package/src/comments.mjs +26 -0
- package/src/config.mjs +7 -4
- package/src/diagnostics.mjs +1 -0
- package/src/host.mjs +13 -5
- package/src/output.mjs +24 -5
- package/src/review-tools.mjs +10 -4
- package/src/review-work.mjs +5 -0
- package/src/runtime.mjs +456 -65
- package/src/search.mjs +3 -2
- package/src/session.mjs +69 -16
- package/src/setup.mjs +2 -1
- package/src/store.mjs +121 -25
package/src/attribution.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ROLES } from './config.mjs';
|
|
1
|
+
import { ROLES, MAX_ARCHIVE_MEGABYTES } from './config.mjs';
|
|
2
2
|
// Deterministic attribution from invoked reviewer stages, not model-authored claims.
|
|
3
3
|
const vocabulary = {
|
|
4
4
|
en: { title: 'AI review provenance', disclaimer: 'AI-generated review, not human approval. Posting through a user account does not imply that person verified these conclusions.', method: 'Independent initial reviews, followed by source-based verification, duplicate merging, and rejection of unsupported findings; not majority voting.', roles: ['Source check', 'Functional review', 'Risk review', 'Verification', 'Duplicate check', 'Quick review', 'Severity rating'], stage: 'Stage', model: 'Selected provider/model ID', sessions: 'Sessions', count: 'Initial findings', dispositions: 'Finding dispositions', finding: 'Finding', result: 'Result', merged: 'Merged into', extra: 'New verifier findings', note: 'IDs identify the models selected in OpenCode, not independently verified provider backend identities. Host auxiliary models and the original chat model are not part of this ledger.', comment: 'AI-generated review; not human review or approval. Models:',
|
|
@@ -39,11 +39,30 @@ export function renderCommentActions(id, language, after) {
|
|
|
39
39
|
`**自動發布**(${source}):AZPR 接著以另一道指令規劃留言,並以 PAT 擁有者的身分發布,另送收據。含 @提及、圖片、嵌入內容、隱藏文字或指令碼連結的留言會留在預覽等人確認,其他照常發布;每個發現在 PR 上都已有討論時,不會再發布。沒有可留言的發現時不會留言。`,
|
|
40
40
|
`**自动发布**(${source}):AZPR 接着以另一条命令规划留言,并以 PAT 拥有者的身份发布,另送回执。含 @提及、图片、嵌入内容、隐藏文字或脚本链接的留言会留在预览等人确认,其他照常发布;每个发现在 PR 上都已有讨论时,不会再发布。没有可留言的发现时不会留言。`)
|
|
41
41
|
: after ? pick(language, `Automatic comments are off for this review (${source}).`, `這份審查不自動留言(${source})。`, `这份审查不自动留言(${source})。`) : '';
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
['PR
|
|
46
|
-
|
|
42
|
+
// The short commands come first: a person should not have to find or type the review ID. The
|
|
43
|
+
// ID form stays, since a short command copied from an old receipt acts on the current review.
|
|
44
|
+
const [heading, preview, adjust, publish, current, retention] = pick(language,
|
|
45
|
+
['PR comments', 'Preview the comments (a model runs; nothing is posted)', 'Leave findings out or change a level, with the IDs of the report, then read the new preview', 'Post the saved preview as the PAT owner',
|
|
46
|
+
`These commands need no review ID: they act on this conversation's current review, which is this one until another review completes or is used here. To act on this review later, add its ID, for example \`/pr-comment ${id} --publish\`; \`/pr-comment --list\` shows the saved reviews and \`/pr-comment --help\` every option.`,
|
|
47
|
+
'Reviews and previews are saved privately (latest 20) and survive an OpenCode restart. Publishing skips comments that already exist on the PR, so it is safe to run again.'],
|
|
48
|
+
['PR 留言', '預覽留言(會用到模型,不會發布)', '排除發現或改嚴重度(用報告裡的 ID),再看新的預覽', '以 PAT 擁有者的身分發布已保存的預覽',
|
|
49
|
+
`這些指令不需要 review ID:會作用在這個對話目前的 review,也就是這一份,直到這裡有另一份 review 完成或被使用。之後要指定這一份時加上 ID,例如 \`/pr-comment ${id} --publish\`;\`/pr-comment --list\` 列出保存的 review,\`/pr-comment --help\` 列出所有選項。`,
|
|
50
|
+
'Review 與預覽私下保存(最近 20 份),重啟 OpenCode 後仍可使用。發布時會跳過 PR 上已存在的留言,可以安全地重跑。'],
|
|
51
|
+
['PR 留言', '预览留言(会用到模型,不会发布)', '排除发现或改严重度(用报告里的 ID),再看新的预览', '以 PAT 拥有者的身份发布已保存的预览',
|
|
52
|
+
`这些命令不需要 review ID:会作用在这个对话当前的 review,也就是这一份,直到这里有另一份 review 完成或被使用。之后要指定这一份时加上 ID,例如 \`/pr-comment ${id} --publish\`;\`/pr-comment --list\` 列出保存的 review,\`/pr-comment --help\` 列出所有选项。`,
|
|
53
|
+
'Review 与预览私下保存(最近 20 份),重启 OpenCode 后仍可使用。发布时会跳过 PR 上已存在的留言,可以安全地重跑。']);
|
|
54
|
+
return `## ${heading}\n\n${automatic ? `${automatic}\n\n` : ''}- ${preview}: \`/pr-comment\`\n- ${adjust}: \`/pr-comment --exclude F-1,R-2\`, \`/pr-comment --severity F-3=low\`\n- ${publish}: \`/pr-comment --publish\`\n\n${current}\n\n${retention}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Which review a comment command acted on, so a command without an ID is
|
|
59
|
+
* checked at a glance: the PR by its number and repository, which come from
|
|
60
|
+
* the URL the person typed. The PR's title is text from the PR and stays
|
|
61
|
+
* inside the report's data block, never in a notice line.
|
|
62
|
+
*/
|
|
63
|
+
export function describeReview(review) {
|
|
64
|
+
const snapshot = review?.snapshot ?? {};
|
|
65
|
+
return `review ${review.id} (/pr-${review.profile}) of PR #${snapshot.prId ?? '?'}${snapshot.project && snapshot.repository ? ` in ${snapshot.project}/${snapshot.repository}` : ''}`;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
/** Models per role, aggregated over shards and retries. */
|
|
@@ -247,6 +266,7 @@ function renderStageReceipt(stage) {
|
|
|
247
266
|
['repair-turns', stage.repairs?.length],
|
|
248
267
|
['stream-continuations', stage.hostContinuations],
|
|
249
268
|
['continuation-restarts', stage.continuationRestarts],
|
|
269
|
+
['step-retries', stage.hostStepRetries],
|
|
250
270
|
['blocked-native-tools', stage.blockedNativeToolCalls],
|
|
251
271
|
['observed-tool-errors', stage.toolFailures],
|
|
252
272
|
['tool-timeouts', stage.toolTimeouts],
|
|
@@ -271,7 +291,8 @@ export function renderReceipt(run, report, status, error, settings) {
|
|
|
271
291
|
if (run.draft) body += run.mode === 'quick'
|
|
272
292
|
? '\nIncomplete draft notice: the quick review did not complete; its observations are unconfirmed and not input for PR comments.\n'
|
|
273
293
|
: '\nIncomplete draft notice: initial observations are unconfirmed because verification did not complete; they are not input for PR comments.\n';
|
|
274
|
-
body +=
|
|
294
|
+
if (run.sessionsRemoved) body += `\nSession notice: ${run.sessionsRemoved} reviewer session(s) of this run were deleted when it ended; only a session that holds the report or draft is kept (deletePrivateSessions). debug.enabled keeps them all.\n`;
|
|
295
|
+
body += renderDiagnosticNotices(run, settings);
|
|
275
296
|
body += run.mode === 'check'
|
|
276
297
|
? '\nStatus: READY means AZPR can read the PR through the Azure DevOps REST API; it does not review or approve the PR.\n'
|
|
277
298
|
: run.mode === 'comment'
|
|
@@ -300,7 +321,23 @@ export function renderReceipt(run, report, status, error, settings) {
|
|
|
300
321
|
return body;
|
|
301
322
|
}
|
|
302
323
|
|
|
303
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Content search that could not run limits the whole review, and the tool told
|
|
326
|
+
* only the models. The runtime states it in the report and the receipt, so it
|
|
327
|
+
* does not depend on a model mentioning it. Empty when every search ran.
|
|
328
|
+
*/
|
|
329
|
+
export function searchLimitation(run, settings) {
|
|
330
|
+
const refused = run?.searchUnavailable;
|
|
331
|
+
if (!refused?.size) return '';
|
|
332
|
+
const megabytes = settings?.azure?.archiveMegabytes;
|
|
333
|
+
// Only an archive over the limit is something the setting changes.
|
|
334
|
+
const setting = ![...refused.values()].some(Boolean) || !megabytes ? ''
|
|
335
|
+
: megabytes < MAX_ARCHIVE_MEGABYTES ? ` azure.archiveMegabytes is ${megabytes}; it accepts up to ${MAX_ARCHIVE_MEGABYTES}.`
|
|
336
|
+
: ` azure.archiveMegabytes is at its maximum of ${MAX_ARCHIVE_MEGABYTES}.`;
|
|
337
|
+
return `Content search (azpr_search_code) was unavailable: ${[...refused.keys()].join('; ')}. Sessions could find and read files but not search file contents, so callers and other uses of the changed code may not have been checked.${setting}`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function renderDiagnosticNotices(run, settings) {
|
|
304
341
|
const notices = [];
|
|
305
342
|
const sum = key => run.stages.reduce((n, s) => n + (s[key] ?? 0), 0);
|
|
306
343
|
const blocked = sum('blockedNativeToolCalls'), failures = sum('toolFailures'), timeouts = sum('toolTimeouts');
|
|
@@ -309,6 +346,8 @@ export function renderDiagnosticNotices(run) {
|
|
|
309
346
|
if (timeouts) notices.push(`\nTool timeout notice: ${timeouts} Azure DevOps read(s) exceeded the per-call timeout after retries and were abandoned.\n`);
|
|
310
347
|
const idle = run.stages.filter(stage => stage.failureClass === 'idle');
|
|
311
348
|
if (idle.length) notices.push(`\nInactivity notice: the stage inactivity watchdog stopped ${idle.length} stage(s) (failure=idle) after ${idle[0].idleStop?.idleSeconds ?? 'workflow.stageIdleSeconds'} s without activity: ${idle.map(stage => `${stage.role}${stage.label ? ` [${stage.label}]` : ''} after ${stage.idleStop?.lastActivity ?? 'an unknown activity'}`).join('; ')}. The model stream, a tool or OpenCode stopped responding; a stopped stage runs again in a new session while workflow.stageRetries allows.\n`);
|
|
349
|
+
const search = searchLimitation(run, settings);
|
|
350
|
+
if (search) notices.push(`\nContent search notice: ${search}\n`);
|
|
312
351
|
if (run.abortUnconfirmed) notices.push('\nCancellation warning: OpenCode did not confirm session settlement. Requests already sent may still be running or billed.\n');
|
|
313
352
|
if (run.debug?.directory) notices.push(`\nPrivate debug directory: ${run.debug.directory}\n`);
|
|
314
353
|
for (const warning of run.debug?.warnings ?? []) notices.push(`Debug warning: ${warning}\n`);
|
package/src/azure.mjs
CHANGED
|
@@ -106,7 +106,7 @@ export function targetKey(target) {
|
|
|
106
106
|
/**
|
|
107
107
|
* A REST base URL other than dev.azure.com is accepted only for loopback test
|
|
108
108
|
* servers, so a mistaken override can never send the PAT to another host. All
|
|
109
|
-
* of 127.0.0.0/8 is loopback: OpenCode 2.2.4 adds 127.0.0.1, localhost and ::1
|
|
109
|
+
* of 127.0.0.0/8 is loopback: OpenCode (2.2.4, 2.3.0) adds 127.0.0.1, localhost and ::1
|
|
110
110
|
* to NO_PROXY, and Bun then bypasses even an explicit proxy, so a proxied test
|
|
111
111
|
* server needs another loopback address.
|
|
112
112
|
*/
|
|
@@ -434,23 +434,26 @@ export function createAzureClient({ organization, pat, baseUrl = DEFAULT_BASE_UR
|
|
|
434
434
|
* One REST call through the shared queue. Reads retry transient failures
|
|
435
435
|
* (network, timeout, throttling, 5xx) twice; writes are never repeated
|
|
436
436
|
* because publication resolves uncertainty by reading markers back.
|
|
437
|
+
* `signal` also ends a call that only its caller waits for (a tool call
|
|
438
|
+
* the host stopped); a call whose result several callers share takes none.
|
|
437
439
|
*/
|
|
438
|
-
async function request(run, { method = 'GET', path, query = {}, body, accept = 'json', maxBytes, label, record = {} }) {
|
|
440
|
+
async function request(run, { method = 'GET', path, query = {}, body, accept = 'json', maxBytes, label, record = {}, signal }) {
|
|
439
441
|
const url = new URL(`${root}/${path}`);
|
|
440
442
|
for (const [key, value] of Object.entries(query)) if (value !== undefined && value !== null) url.searchParams.set(key, String(value));
|
|
441
443
|
url.searchParams.set('api-version', API_VERSION);
|
|
442
444
|
const retry = method === 'GET';
|
|
445
|
+
const stop = signal ? AbortSignal.any([run.controller.signal, signal]) : run.controller.signal;
|
|
443
446
|
for (let attempt = 1; ; attempt++) {
|
|
444
447
|
run.azureCalls = (run.azureCalls ?? 0) + 1;
|
|
445
448
|
const started = performance.now();
|
|
446
449
|
const entry = { method, call: label, ...record, attempt };
|
|
447
450
|
try {
|
|
448
|
-
const value = await queue.run(
|
|
451
|
+
const value = await queue.run(aborting => send({ method, url, body, accept, maxBytes }, label, aborting), { signal: stop, label: `Azure DevOps ${label}` });
|
|
449
452
|
onCall?.(run, { ...entry, ok: true, durationMs: Math.round(performance.now() - started),
|
|
450
453
|
...(value?.bytes ? { bytes: value.bytes.length } : value?.tooLarge ? { bytes: value.size, tooLarge: true } : {}) });
|
|
451
454
|
return value;
|
|
452
455
|
} catch (caught) {
|
|
453
|
-
if (
|
|
456
|
+
if (stop.aborted) throw caught;
|
|
454
457
|
const error = caught instanceof AzureError ? caught : caught?.timeout
|
|
455
458
|
? new AzureError(`Azure DevOps ${label} did not finish within the per-call timeout.`, { kind: 'timeout', transient: true, uncertain: method !== 'GET', cause: caught })
|
|
456
459
|
: new AzureError(`Azure DevOps ${label} failed: ${clean(caught?.message ?? caught)}`, { kind: 'unexpected', cause: caught });
|
|
@@ -459,7 +462,7 @@ export function createAzureClient({ organization, pat, baseUrl = DEFAULT_BASE_UR
|
|
|
459
462
|
error: error.message.slice(0, 300), transient: error.transient, willRetry: again });
|
|
460
463
|
if (again) {
|
|
461
464
|
run.azureRetries = (run.azureRetries ?? 0) + 1;
|
|
462
|
-
await pause(Math.max(retryDelayMs * (attempt === 1 ? 1 : 3), error.retryAfterMs ?? 0),
|
|
465
|
+
await pause(Math.max(retryDelayMs * (attempt === 1 ? 1 : 3), error.retryAfterMs ?? 0), stop);
|
|
463
466
|
continue;
|
|
464
467
|
}
|
|
465
468
|
if (attempt > 1) error.message = `${error.message.replace(/\.$/, '')} after ${attempt} attempts.`;
|
|
@@ -556,16 +559,19 @@ export function createAzureClient({ organization, pat, baseUrl = DEFAULT_BASE_UR
|
|
|
556
559
|
if (file.tooLarge) throw new AzureError(`${file.path} is larger than ${MAX_FILE_BYTES / 1048576} MB at ${version.slice(0, 12)}.`, { kind: 'too-large' });
|
|
557
560
|
return file.text;
|
|
558
561
|
},
|
|
559
|
-
/**
|
|
560
|
-
|
|
562
|
+
/**
|
|
563
|
+
* Folder entries at a commit; a recursive listing is read once per run and
|
|
564
|
+
* shared, so only a listing of one level ends with its caller's `signal`.
|
|
565
|
+
*/
|
|
566
|
+
async listItems(run, snapshot, path, version, recursive = false, signal) {
|
|
561
567
|
const scope = normalizePath(path);
|
|
562
|
-
const read = async
|
|
568
|
+
const read = async own => {
|
|
563
569
|
const result = await request(run, { path: `${repo(snapshot)}/items`, label: `folder ${scope}`, record: { path: scope, version: version.slice(0, 12), ...(recursive ? { recursive: true } : {}) },
|
|
564
|
-
query: { scopePath: scope, recursionLevel: recursive ? 'Full' : 'OneLevel', 'versionDescriptor.version': version, 'versionDescriptor.versionType': 'commit' } });
|
|
570
|
+
query: { scopePath: scope, recursionLevel: recursive ? 'Full' : 'OneLevel', 'versionDescriptor.version': version, 'versionDescriptor.versionType': 'commit' }, signal: own });
|
|
565
571
|
if (!Array.isArray(result?.value)) throw new AzureError('Azure DevOps returned no item list.');
|
|
566
572
|
return result.value;
|
|
567
573
|
};
|
|
568
|
-
if (!recursive) return read();
|
|
574
|
+
if (!recursive) return read(signal);
|
|
569
575
|
const cache = run.listCache ??= new Map(), key = `${version}\n${scope}`;
|
|
570
576
|
if (!cache.has(key)) {
|
|
571
577
|
const pending = read();
|
|
@@ -580,9 +586,9 @@ export function createAzureClient({ organization, pat, baseUrl = DEFAULT_BASE_UR
|
|
|
580
586
|
query: { scopePath: '/', recursionLevel: 'Full', $format: 'zip', 'versionDescriptor.version': version, 'versionDescriptor.versionType': 'commit' } });
|
|
581
587
|
return result.tooLarge ? { tooLarge: true, size: result.size } : { bytes: result.bytes };
|
|
582
588
|
},
|
|
583
|
-
/** Every thread on the PR (one call; the API returns all of them). */
|
|
584
|
-
async threads(run, snapshot) {
|
|
585
|
-
const result = await request(run, { path: `${pullRequest(snapshot)}/threads`, label: 'PR threads' });
|
|
589
|
+
/** Every thread on the PR (one call; the API returns all of them). `signal` ends this caller's read early. */
|
|
590
|
+
async threads(run, snapshot, signal) {
|
|
591
|
+
const result = await request(run, { path: `${pullRequest(snapshot)}/threads`, label: 'PR threads', signal });
|
|
586
592
|
if (!Array.isArray(result?.value)) throw new AzureError('Azure DevOps returned no thread list; existing comments could not be checked.');
|
|
587
593
|
return result.value;
|
|
588
594
|
},
|
package/src/comments.mjs
CHANGED
|
@@ -151,6 +151,32 @@ export function describeAdjustments(review) {
|
|
|
151
151
|
return `Adjusted by a person after the preview (not stated on the PR):\n${rows.join('\n')}`;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* After a preview: the commands a person is likely to want next, written
|
|
156
|
+
* without the review ID and with this review's own finding IDs. Each
|
|
157
|
+
* adjustment list replaces the saved one, so an example keeps what is saved
|
|
158
|
+
* and adds to it. `held` leaves out publication (the preview says why).
|
|
159
|
+
*/
|
|
160
|
+
export function previewNextSteps(review, { held = false } = {}) {
|
|
161
|
+
const { excluded, severity, active } = adjustmentsOf(review);
|
|
162
|
+
const remaining = commentFindings(review);
|
|
163
|
+
const rows = [];
|
|
164
|
+
if (!held && !everyFindingExcluded(review)) rows.push(['/pr-comment --publish', 'post this preview as the PAT owner (safe to repeat)']);
|
|
165
|
+
if (remaining.length) {
|
|
166
|
+
const more = remaining.slice(0, excluded.length ? 1 : 2).map(finding => finding.id);
|
|
167
|
+
rows.push([`/pr-comment --exclude ${[...excluded, ...more].join(',')}`, `leave ${more.join(' and ')} out${excluded.length ? ' as well' : ''}, then read the new preview`]);
|
|
168
|
+
const target = remaining.find(finding => !Object.hasOwn(severity, finding.id)) ?? remaining[0];
|
|
169
|
+
const level = target.severity === 'low' ? 'medium' : 'low';
|
|
170
|
+
const kept = Object.entries(severity).filter(([id]) => id !== target.id).map(([id, to]) => `${id}=${to}`);
|
|
171
|
+
rows.push([`/pr-comment --severity ${[...kept, `${target.id}=${level}`].join(',')}`, `publish ${target.id} as ${level}, then read the new preview`]);
|
|
172
|
+
}
|
|
173
|
+
if (active) rows.push(['/pr-comment --reset', 'undo your adjustments, then read the new preview']);
|
|
174
|
+
rows.push(['/pr-comment --show', 'show this preview again (no model)']);
|
|
175
|
+
const width = Math.max(...rows.map(([command]) => command.length));
|
|
176
|
+
return `Next (no review ID is needed while ${review.id} is this conversation's current review):\n${rows.map(([command, effect]) => ` ${command.padEnd(width)} ${effect}`).join('\n')}\n` +
|
|
177
|
+
`Each --exclude or --severity list replaces the saved one. For another review add its ID; /pr-comment --list shows them.`;
|
|
178
|
+
}
|
|
179
|
+
|
|
154
180
|
/**
|
|
155
181
|
* Apply a /pr-comment adjustment request to a review. `exclude` and `severity`
|
|
156
182
|
* each replace their whole list when given (empty: none); `reset` clears both.
|
package/src/config.mjs
CHANGED
|
@@ -107,10 +107,13 @@ export const allowedTools = (role, shell = 'deny') => Object.hasOwn(ROLES, role)
|
|
|
107
107
|
// The comment step that follows a COMPLETE review of each mode (afterReview).
|
|
108
108
|
export const AFTER_REVIEW = Object.freeze(['none', 'preview', 'publish']);
|
|
109
109
|
|
|
110
|
+
// The largest azure.archiveMegabytes: the repository zip for content search is held in memory.
|
|
111
|
+
export const MAX_ARCHIVE_MEGABYTES = 1024;
|
|
112
|
+
|
|
110
113
|
const DEFAULTS = Object.freeze({
|
|
111
|
-
afterReview: Object.freeze({ quick: '
|
|
112
|
-
azure: Object.freeze({ organization: '', pat: '', patFile: '', concurrency:
|
|
113
|
-
workflow: Object.freeze({ shardFiles: 25, shardFindings: 15, parallelSessions:
|
|
114
|
+
afterReview: Object.freeze({ quick: 'preview', review: 'preview', deep: 'preview' }),
|
|
115
|
+
azure: Object.freeze({ organization: '', pat: '', patFile: '', concurrency: 6, callTimeoutSeconds: 120, archiveMegabytes: 100, proxy: '', caFile: '', verifyTls: true }),
|
|
116
|
+
workflow: Object.freeze({ shardFiles: 25, shardFindings: 15, parallelSessions: 8, repairAttempts: 2, stageRetries: 1, stageIdleSeconds: 600 }),
|
|
114
117
|
});
|
|
115
118
|
const withDefault = (value, fallback) => value === undefined ? fallback : value;
|
|
116
119
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -215,7 +218,7 @@ export function validateSettings(raw) {
|
|
|
215
218
|
}
|
|
216
219
|
integer(azure.concurrency, 'azure.concurrency', 1, 8);
|
|
217
220
|
integer(azure.callTimeoutSeconds, 'azure.callTimeoutSeconds', 10, 1800);
|
|
218
|
-
integer(azure.archiveMegabytes, 'azure.archiveMegabytes', 1,
|
|
221
|
+
integer(azure.archiveMegabytes, 'azure.archiveMegabytes', 1, MAX_ARCHIVE_MEGABYTES);
|
|
219
222
|
proxyUrl(azure.proxy);
|
|
220
223
|
if (typeof azure.caFile !== 'string' || (azure.caFile !== '' && (!isAbsolute(azure.caFile) || /[\0\r\n]/.test(azure.caFile)))) {
|
|
221
224
|
throw new Error('azure.caFile must be empty or the absolute path of a PEM file with CA certificates.');
|
package/src/diagnostics.mjs
CHANGED
|
@@ -203,5 +203,6 @@ export function diagnosticResponse(response) {
|
|
|
203
203
|
text: raw, textCharacters: raw.length,
|
|
204
204
|
...(response?.continuation ? { continuation: { count: response.continuation.count,
|
|
205
205
|
fragments: response.continuation.fragments.map(diagnosticResponse) } } : {}),
|
|
206
|
+
...(response?.retriedSteps ? { retriedSteps: response.retriedSteps } : {}),
|
|
206
207
|
};
|
|
207
208
|
}
|
package/src/host.mjs
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
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.
|
|
9
|
+
export const TESTED_HOST_VERSION = '2.3.0';
|
|
10
10
|
|
|
11
|
-
// Text OpenCode
|
|
11
|
+
// Text OpenCode 2.0.32 through 2.2.7 queue after resuming an interrupted text stream. OpenCode 2.3.0 retries the
|
|
12
|
+
// interrupted step instead and queues nothing (see `retriedSteps` in session.mjs).
|
|
12
13
|
export const HOST_CONTINUATION_TEXT = 'The previous response was interrupted. Continue from where you left off without repeating completed content.';
|
|
13
14
|
|
|
14
15
|
// Context message types that mean someone other than the admitted prompt
|
|
@@ -57,7 +58,7 @@ export function packageNamed(target, name, repository) {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
|
-
* This plugin's entries in the host's plugin list. OpenCode 2.1.4 through 2.
|
|
61
|
+
* This plugin's entries in the host's plugin list. OpenCode 2.1.4 through 2.3.0 list
|
|
61
62
|
* { id?, source: { type: package|local|builtin|sdk, target?, version? },
|
|
62
63
|
* state: { status: active|failed, error? } } and keeps only the first entry
|
|
63
64
|
* of a plugin ID: a second one is listed as failed with "Duplicate plugin ID".
|
|
@@ -93,7 +94,7 @@ export function pluginSourceLabel(source) {
|
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
96
|
* Session events that show a turn progressing while no hook runs. OpenCode
|
|
96
|
-
* 2.1.2 through 2.
|
|
97
|
+
* 2.1.2 through 2.3.0 emit one delta event per streamed chunk of answer text,
|
|
97
98
|
* reasoning or tool-call input; the projected session context shows the text
|
|
98
99
|
* only once the step ends.
|
|
99
100
|
*/
|
|
@@ -122,7 +123,7 @@ export function sessionProgress(event) {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
/**
|
|
125
|
-
* OpenCode runs plugins on Bun (1.4.2 in 2.0.32 and 2.1.2, 1.4.4 in 2.1.4 through 2.
|
|
126
|
+
* OpenCode runs plugins on Bun (1.4.2 in 2.0.32 and 2.1.2, 1.4.4 in 2.1.4 through 2.3.0),
|
|
126
127
|
* whose fetch accepts per-request `proxy` and `tls` options. Node's fetch
|
|
127
128
|
* silently ignores both, so a configured proxy would be bypassed; callers
|
|
128
129
|
* refuse instead.
|
|
@@ -167,6 +168,13 @@ export const USED_UP_LIMITS = Object.freeze({
|
|
|
167
168
|
'provider.model-budget-limit': "OpenCode reports this model's spend limit as reached",
|
|
168
169
|
});
|
|
169
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Whether a rejected session call says the session does not exist. OpenCode
|
|
173
|
+
* 2.2.4 and 2.3.0 reject `session.get` and `session.remove` of such a session
|
|
174
|
+
* with an error whose `_tag` and `name` are `Session.NotFoundError`.
|
|
175
|
+
*/
|
|
176
|
+
export const isSessionNotFound = error => (error?._tag ?? error?.name) === 'Session.NotFoundError';
|
|
177
|
+
|
|
170
178
|
/** Throw one readable error naming every missing host method. */
|
|
171
179
|
export function requireMethods(context, paths, purpose) {
|
|
172
180
|
const missing = paths.filter(path => typeof path.split('.').reduce((value, key) => value?.[key], context) !== 'function');
|
package/src/output.mjs
CHANGED
|
@@ -219,6 +219,16 @@ function normalizeFinding(value, warnings) {
|
|
|
219
219
|
return row;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* A suggestion that is only a placeholder ("N/A", "No correction needed.", "-"). A
|
|
224
|
+
* confirmation states its correction, so one with such a suggestion contradicts
|
|
225
|
+
* itself. This is a check of form on a few fixed spellings: the runtime does not
|
|
226
|
+
* judge whether the defect is real, it asks the verifier which of the two it means.
|
|
227
|
+
*/
|
|
228
|
+
const NO_CORRECTION = /^[\s\p{P}\p{S}]*(?:n[\s.\/]*a|none|nothing|not applicable|no (?:changes?|corrections?|fix(?:es)?|action)(?: (?:is|are))? (?:needed|required|necessary)|無|无|不適用|不适用|(?:不需要|無需|无需|不需)(?:修正|修改))?[\s\p{P}\p{S}]*$/iu;
|
|
229
|
+
// Placeholders are short; the bound also keeps the match linear on long text.
|
|
230
|
+
export const givesNoCorrection = suggestion => text(suggestion) && suggestion.trim().length <= 60 && NO_CORRECTION.test(suggestion.trim());
|
|
231
|
+
|
|
222
232
|
/** Problems that make a finding unusable, phrased for a repair request. */
|
|
223
233
|
function findingProblems(row, { requireLocation }) {
|
|
224
234
|
const missing = FINDING_FIELDS.filter(key => key !== 'id' && (key !== 'location' || requireLocation) && !text(row[key]));
|
|
@@ -407,6 +417,10 @@ export function evaluateFinal(answerText, { originals, allIds = originals.map(f
|
|
|
407
417
|
row.verifiedFinding.id = id;
|
|
408
418
|
const problems = findingProblems(row.verifiedFinding, { requireLocation: true });
|
|
409
419
|
if (problems.length) { issues.push(`${id}: the confirmed finding is ${problems.join('; ')}.`); repairIds.add(id); invalid.confirm.add(id); continue; }
|
|
420
|
+
if (givesNoCorrection(row.verifiedFinding.suggestion)) {
|
|
421
|
+
issues.push(`${id}: confirmed, but its suggestion gives no correction (${JSON.stringify(row.verifiedFinding.suggestion.slice(0, 40))}). If the defect stands, state the correction; if your check refutes the claim, list ${id} under rejected with the refutation.`);
|
|
422
|
+
repairIds.add(id); invalid.confirm.add(id); continue;
|
|
423
|
+
}
|
|
410
424
|
const move = fileMove(candidates.get(id), row);
|
|
411
425
|
if (move) moves.set(id, move);
|
|
412
426
|
if (move && !move.acknowledged) {
|
|
@@ -525,6 +539,7 @@ function finishFinal(state, originals, invalid = { confirm: new Set(), merge: ne
|
|
|
525
539
|
}
|
|
526
540
|
if (row.status === 'CONFIRMED' && invalid.confirm.has(original.id)) {
|
|
527
541
|
const absent = FINDING_FIELDS.filter(key => !text(row.verifiedFinding?.[key]));
|
|
542
|
+
if (!absent.length && givesNoCorrection(row.verifiedFinding?.suggestion)) absent.push('a correction in suggestion');
|
|
528
543
|
dispositions.push({ id: original.id, status: 'NEEDS_INFO', reason: `${asText(row.reason)} [Runtime: the confirmation lacks ${absent.join(', ') || 'valid fields'}, so it is not eligible for comments.]`.trim(),
|
|
529
544
|
partialFinding: row.verifiedFinding });
|
|
530
545
|
continue;
|
|
@@ -714,15 +729,16 @@ export function normalizeFindingId(value) {
|
|
|
714
729
|
return match ? `${match[1].toUpperCase()}-${match[2]}` : null;
|
|
715
730
|
}
|
|
716
731
|
|
|
717
|
-
const COMMENT_USAGE = '[AZPR] Usage: /pr-comment [review-id] [--publish | --show], or
|
|
718
|
-
const COMMENT_OPTIONS = ['publish', 'show', 'exclude', 'severity', 'reset'];
|
|
732
|
+
const COMMENT_USAGE = '[AZPR] Usage: /pr-comment [review-id] [--publish | --show], or with --exclude <IDs|none> and/or --severity <ID=high|medium|low,…|none>, or --reset; /pr-comment --list shows the saved reviews. Without an ID the command acts on this conversation\'s current review. /pr-comment --help has examples.';
|
|
733
|
+
const COMMENT_OPTIONS = ['publish', 'show', 'list', 'exclude', 'severity', 'reset'];
|
|
719
734
|
|
|
720
735
|
/**
|
|
721
736
|
* /pr-comment's arguments: an optional review ID, then at most one of
|
|
722
|
-
* --publish and --show, or adjustments of
|
|
737
|
+
* --publish and --show, or adjustments of the review's findings:
|
|
723
738
|
* --exclude and --severity (each at most once, each a complete list; `none`
|
|
724
739
|
* for an empty one) or --reset alone. List items are separated by commas or
|
|
725
|
-
* spaces. Anything else is refused.
|
|
740
|
+
* spaces. --list stands alone and names no review. Anything else is refused.
|
|
741
|
+
* Without an ID the runtime picks the conversation's current review.
|
|
726
742
|
*/
|
|
727
743
|
export function parseCommentRequest(raw) {
|
|
728
744
|
const args = String(raw ?? '').trim().split(/\s+/).filter(Boolean);
|
|
@@ -743,12 +759,15 @@ export function parseCommentRequest(raw) {
|
|
|
743
759
|
}
|
|
744
760
|
const named = [...values.keys()];
|
|
745
761
|
const request = { ...(reviewId ? { reviewId } : {}), publish: values.has('publish'), show: values.has('show') };
|
|
762
|
+
if (values.has('list')) {
|
|
763
|
+
if (named.length > 1 || reviewId) throw new Error(COMMENT_USAGE);
|
|
764
|
+
return { list: true };
|
|
765
|
+
}
|
|
746
766
|
if (!named.some(name => ['exclude', 'severity', 'reset'].includes(name))) {
|
|
747
767
|
if (named.length > 1) throw new Error(COMMENT_USAGE);
|
|
748
768
|
return request;
|
|
749
769
|
}
|
|
750
770
|
if (named.some(name => ['publish', 'show'].includes(name)) || (values.has('reset') && named.length > 1)) throw new Error(COMMENT_USAGE);
|
|
751
|
-
if (!reviewId) throw new Error('[AZPR] Name the review whose findings you adjust: /pr-comment <review-id> --exclude … (the ID is in its receipt).');
|
|
752
771
|
const items = name => values.get(name).join(' ').split(/[\s,]+/).filter(Boolean);
|
|
753
772
|
const adjust = values.has('reset') ? { reset: true } : {};
|
|
754
773
|
if (values.has('exclude')) {
|
package/src/review-tools.mjs
CHANGED
|
@@ -394,7 +394,8 @@ export async function runReviewTool(name, input, context) {
|
|
|
394
394
|
return { ...result, reads: [], text: `${result.text.slice(0, fitEnd(result.text, 0, OUTPUT_BYTES - 200))}\n[Output cut to the tool-output limit; request a narrower range.]` };
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
|
|
397
|
+
// `signal` is the caller's own stop: it goes only to reads no other session of the run shares.
|
|
398
|
+
async function reviewTool(name, input, { azure, run, snapshot, signal }) {
|
|
398
399
|
const raw = input && typeof input === 'object' && !Array.isArray(input) ? input : {};
|
|
399
400
|
// Models often send an optional argument as null or "": that means not given.
|
|
400
401
|
const args = Object.fromEntries(Object.entries(raw).filter(([, value]) => value !== null && !(typeof value === 'string' && !value.trim())));
|
|
@@ -423,7 +424,12 @@ async function reviewTool(name, input, { azure, run, snapshot }) {
|
|
|
423
424
|
const include = scopeFilter(args.path);
|
|
424
425
|
const { sha, label } = resolveVersion(args.version, snapshot);
|
|
425
426
|
const archive = await repositoryArchive(run, azure, snapshot, sha);
|
|
426
|
-
if (archive.unavailable)
|
|
427
|
+
if (archive.unavailable) {
|
|
428
|
+
// A limit of the whole run that only the model is told here: the runtime states it in the report and receipt.
|
|
429
|
+
// The byte count is what was read before stopping, not the archive's size, so it is left out there.
|
|
430
|
+
(run.searchUnavailable ??= new Map()).set(archive.tooLarge ? 'the repository archive is larger than the azure.archiveMegabytes setting allows' : archive.unavailable, archive.tooLarge === true);
|
|
431
|
+
return { text: `Content search is unavailable for this repository: ${archive.unavailable}. Find files with azpr_find_files and read them with azpr_read_file.` };
|
|
432
|
+
}
|
|
427
433
|
return { text: renderSearch(searchArchive(archive, { query, caseSensitive: args.caseSensitive === true, wholeWord: args.wholeWord === true, include }), { query, label, version: sha, archive }) };
|
|
428
434
|
}
|
|
429
435
|
if (name === REVIEW_TOOLS.findFiles) {
|
|
@@ -449,12 +455,12 @@ async function reviewTool(name, input, { azure, run, snapshot }) {
|
|
|
449
455
|
const path = pathArgument(args.path, '/');
|
|
450
456
|
const { sha, label } = resolveVersion(args.version, snapshot);
|
|
451
457
|
if (args.recursive !== undefined && typeof args.recursive !== 'boolean') throw new ToolInputError('recursive must be true or false.');
|
|
452
|
-
return renderListing(await azure.listItems(run, snapshot, path, sha, args.recursive === true), { path, label, version: sha });
|
|
458
|
+
return renderListing(await azure.listItems(run, snapshot, path, sha, args.recursive === true, signal), { path, label, version: sha });
|
|
453
459
|
}
|
|
454
460
|
if (name === REVIEW_TOOLS.threads) {
|
|
455
461
|
const path = args.path === undefined ? undefined : pathArgument(args.path);
|
|
456
462
|
if (args.threadId !== undefined && (!Number.isInteger(args.threadId) || args.threadId < 1)) throw new ToolInputError('threadId must be a positive integer.');
|
|
457
|
-
return renderThreads(await azure.threads(run, snapshot), { path, threadId: args.threadId });
|
|
463
|
+
return renderThreads(await azure.threads(run, snapshot, signal), { path, threadId: args.threadId });
|
|
458
464
|
}
|
|
459
465
|
throw new ToolInputError(`Unknown AZPR tool ${name}.`);
|
|
460
466
|
}
|
package/src/review-work.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* only the form and source of its findings, never whether they are right.
|
|
7
7
|
*/
|
|
8
8
|
import { ROLES, initialRoles, roleFor, stageModel } from './config.mjs';
|
|
9
|
+
import { searchLimitation } from './attribution.mjs';
|
|
9
10
|
import { breakMergeCycles, settleMergeTargets, evaluateInitial, evaluateFinal, evaluateDuplicates, evaluateRatings, initialRepairPrompt, finalRepairPrompt, duplicateRepairPrompt, ratingRepairPrompt, quickRepairPrompt, quickFollowUpPrompt, syntaxProblem, locationPath, FINDING_FIELDS } from './output.mjs';
|
|
10
11
|
|
|
11
12
|
export { locationPath };
|
|
@@ -412,6 +413,8 @@ export async function runReview(ctx, run, request) {
|
|
|
412
413
|
|
|
413
414
|
const ratings = await rateSeverities(ctx, run, { snapshot, dispositions, newFindings, warnings });
|
|
414
415
|
|
|
416
|
+
const search = searchLimitation(run, settings);
|
|
417
|
+
if (search) warnings.push(search);
|
|
415
418
|
const { freshness, stale } = await finalRecheck(ctx, run, snapshot, warnings);
|
|
416
419
|
const status = stale ? 'STALE' : verified ? 'COMPLETE' : 'PARTIAL';
|
|
417
420
|
return {
|
|
@@ -597,6 +600,8 @@ export async function runQuickReview(ctx, run, request) {
|
|
|
597
600
|
duplicates++;
|
|
598
601
|
}
|
|
599
602
|
if (duplicates) warnings.push(`Removed ${duplicates} exact duplicate finding(s); findings that differ in any field are kept.`);
|
|
603
|
+
const search = searchLimitation(run, settings);
|
|
604
|
+
if (search) warnings.push(search);
|
|
600
605
|
if (discovered.size) warnings.push(`The quick reviewer reported ${discovered.size} changed path(s) missing from Azure's list: ${[...discovered].slice(0, 20).join(', ')}${discovered.size > 20 ? ', ...' : ''}`);
|
|
601
606
|
const unreviewedFiles = snapshot.files.filter(path => !covered.has(path)).length;
|
|
602
607
|
const reasons = [...(failedShards ? ['shard-failed'] : []), ...(snapshot.filesComplete ? [] : ['partial-file-list']), ...(reviewerGaps ? ['reviewer-gaps'] : [])];
|