@fro.bot/systematic 3.35.2 → 3.36.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/agents/research/connections-researcher.md +21 -12
- package/dist/index.js +14 -1
- package/dist/lib/connect-ci.d.ts +130 -8
- package/dist/lib/connect-helper-core.d.ts +62 -7
- package/dist/lib/connect-import.d.ts +10 -0
- package/dist/lib/connect-state.d.ts +99 -4
- package/dist/lib/opencode-v2-skills.d.ts +5 -4
- package/package.json +1 -1
- package/skills/ce-compound/references/candidate-input.md +1 -1
- package/skills/ce-compound-refresh/SKILL.md +2 -1
- package/skills/ce-connect/SKILL.md +7 -5
- package/skills/ce-connect/references/candidate-contract.md +13 -8
- package/skills/ce-connect/scripts/connect.mjs +875 -148
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// biome-ignore-all assist/source/organizeImports: generated bundle
|
|
3
3
|
// Generated by scripts/generate-ce-connect-helper.ts; do not edit by hand.
|
|
4
4
|
// Run `bun run ce-connect-helper:build` to regenerate.
|
|
5
|
-
// source-digest:
|
|
5
|
+
// source-digest: 2a649776a89b2e51c320bb4394c7acaa296f8368be659aba20bde41534ee036b
|
|
6
6
|
// src/ce-connect-helper.ts
|
|
7
7
|
import { spawnSync as spawnSync3 } from 'node:child_process'
|
|
8
8
|
import fs10 from 'node:fs'
|
|
@@ -2069,7 +2069,8 @@ function classifyPath(rel) {
|
|
|
2069
2069
|
if (
|
|
2070
2070
|
CONFIG_EXTENSIONS.has(extension) ||
|
|
2071
2071
|
name === 'Dockerfile' ||
|
|
2072
|
-
name === 'Makefile'
|
|
2072
|
+
name === 'Makefile' ||
|
|
2073
|
+
name === 'Caddyfile'
|
|
2073
2074
|
) {
|
|
2074
2075
|
return 'config'
|
|
2075
2076
|
}
|
|
@@ -6072,6 +6073,7 @@ var MAX_BATCH_RULE_IDS = 500
|
|
|
6072
6073
|
var MAX_BATCH_PROJECTS = 64
|
|
6073
6074
|
var MAX_BATCH_LIST = 50
|
|
6074
6075
|
var MAX_BATCH_ITEM_LENGTH = 300
|
|
6076
|
+
var MAX_BATCH_FILE_LENGTH = 4096 + 1 + MAX_BATCH_ITEM_LENGTH
|
|
6075
6077
|
var MAX_BATCH_CANDIDATES = 200
|
|
6076
6078
|
function isRecord2(value) {
|
|
6077
6079
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
@@ -6118,7 +6120,7 @@ function parseBatch(text, runId) {
|
|
|
6118
6120
|
}
|
|
6119
6121
|
const ruleIds = stringList(value.ruleIds, MAX_BATCH_RULE_IDS, 100)
|
|
6120
6122
|
const projects = stringList(value.projects, MAX_BATCH_PROJECTS, 4096)
|
|
6121
|
-
const files = stringList(value.files, MAX_BATCH_LIST,
|
|
6123
|
+
const files = stringList(value.files, MAX_BATCH_LIST, MAX_BATCH_FILE_LENGTH)
|
|
6122
6124
|
const searches = stringList(
|
|
6123
6125
|
value.searches,
|
|
6124
6126
|
MAX_BATCH_LIST,
|
|
@@ -6147,21 +6149,54 @@ function parseBatch(text, runId) {
|
|
|
6147
6149
|
},
|
|
6148
6150
|
}
|
|
6149
6151
|
}
|
|
6152
|
+
function sharedWithOtherProject(input, id, learning, root) {
|
|
6153
|
+
for (const [other, path] of input.learningPaths ?? []) {
|
|
6154
|
+
if (
|
|
6155
|
+
other !== id &&
|
|
6156
|
+
path === learning &&
|
|
6157
|
+
input.learningProjects?.get(other) !== root
|
|
6158
|
+
) {
|
|
6159
|
+
return true
|
|
6160
|
+
}
|
|
6161
|
+
}
|
|
6162
|
+
return false
|
|
6163
|
+
}
|
|
6164
|
+
function listsLearning(input, listed, id) {
|
|
6165
|
+
const learning = input.learningPaths?.get(id)
|
|
6166
|
+
if (learning === undefined) return true
|
|
6167
|
+
const root = input.learningProjects?.get(id)
|
|
6168
|
+
if (root === undefined) return listed.has(learning)
|
|
6169
|
+
if (listed.has(`${root.replace(/\/+$/, '')}/${learning}`)) return true
|
|
6170
|
+
return (
|
|
6171
|
+
listed.has(learning) && !sharedWithOtherProject(input, id, learning, root)
|
|
6172
|
+
)
|
|
6173
|
+
}
|
|
6150
6174
|
function checkCoverage(input) {
|
|
6151
6175
|
const incompleteFamilies = input.batches
|
|
6152
6176
|
.filter((batch) => !batch.complete)
|
|
6153
6177
|
.map((batch) => batch.family)
|
|
6154
6178
|
if (input.ruleIds.length === 0) {
|
|
6155
|
-
return {
|
|
6179
|
+
return {
|
|
6180
|
+
uncoveredRuleIds: [],
|
|
6181
|
+
learningUnreadRuleIds: [],
|
|
6182
|
+
untouchedProjects: [],
|
|
6183
|
+
incompleteFamilies,
|
|
6184
|
+
}
|
|
6156
6185
|
}
|
|
6186
|
+
const complete = input.batches.filter((batch) => batch.complete)
|
|
6187
|
+
const named = new Set(complete.flatMap((batch) => batch.ruleIds))
|
|
6157
6188
|
const covered = new Set(
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
.
|
|
6189
|
+
complete.flatMap((batch) => {
|
|
6190
|
+
const listed = new Set(batch.files)
|
|
6191
|
+
return batch.ruleIds.filter((id) => listsLearning(input, listed, id))
|
|
6192
|
+
}),
|
|
6161
6193
|
)
|
|
6162
6194
|
const touched = new Set(input.batches.flatMap((batch) => batch.projects))
|
|
6163
6195
|
return {
|
|
6164
6196
|
uncoveredRuleIds: input.ruleIds.filter((id) => !covered.has(id)),
|
|
6197
|
+
learningUnreadRuleIds: input.ruleIds.filter(
|
|
6198
|
+
(id) => named.has(id) && !covered.has(id),
|
|
6199
|
+
),
|
|
6165
6200
|
untouchedProjects: input.projects.filter((root) => !touched.has(root)),
|
|
6166
6201
|
incompleteFamilies,
|
|
6167
6202
|
}
|
|
@@ -6256,8 +6291,12 @@ function renderSweepLine(progress) {
|
|
|
6256
6291
|
const runs = progress.runsLeft === 1 ? 'run' : 'runs'
|
|
6257
6292
|
return `${head} about ${progress.runsLeft} ${runs} left in the sweep.`
|
|
6258
6293
|
}
|
|
6259
|
-
var CANDIDATE_KINDS = ['contradiction', 'transferable-lesson']
|
|
6294
|
+
var CANDIDATE_KINDS = ['contradiction', 'transferable-lesson', 'code-mismatch']
|
|
6260
6295
|
var NEXT_STEPS = ['refresh-learning', 'compound-learning', 'investigate']
|
|
6296
|
+
var MISMATCH_REASONS = ['stale', 'unscoped']
|
|
6297
|
+
function isMismatchReason(value) {
|
|
6298
|
+
return MISMATCH_REASONS.some((reason) => reason === value)
|
|
6299
|
+
}
|
|
6261
6300
|
var CANDIDATE_LIMITS = Object.freeze({
|
|
6262
6301
|
title: 160,
|
|
6263
6302
|
summary: 800,
|
|
@@ -6452,6 +6491,13 @@ function validSymbol(value) {
|
|
|
6452
6491
|
if (symbol === '' || symbol.length > CANDIDATE_LIMITS.symbol) return
|
|
6453
6492
|
return /\s/.test(symbol) || CONTROL.test(symbol) ? undefined : symbol
|
|
6454
6493
|
}
|
|
6494
|
+
function spanHoldsExcerpt(verified, start, end) {
|
|
6495
|
+
return lines(verified.content)
|
|
6496
|
+
.slice(start - 1, end)
|
|
6497
|
+
.join(`
|
|
6498
|
+
`)
|
|
6499
|
+
.includes(verified.excerpt)
|
|
6500
|
+
}
|
|
6455
6501
|
function verifyTargetEvidence(ctx, target, raw) {
|
|
6456
6502
|
if (!isRecord2(raw)) return drop('malformed-candidate')
|
|
6457
6503
|
const verified = verifyFile(ctx, target.root, raw)
|
|
@@ -6478,11 +6524,9 @@ function verifyTargetEvidence(ctx, target, raw) {
|
|
|
6478
6524
|
if (verdict.verdict === 'unchecked') {
|
|
6479
6525
|
return drop('citation-unchecked', verdict.reason)
|
|
6480
6526
|
}
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
`)
|
|
6485
|
-
if (!span.includes(verified.excerpt)) return drop('excerpt-outside-span')
|
|
6527
|
+
if (!spanHoldsExcerpt(verified, start, end)) {
|
|
6528
|
+
return drop('excerpt-outside-span')
|
|
6529
|
+
}
|
|
6486
6530
|
return {
|
|
6487
6531
|
path: verified.path,
|
|
6488
6532
|
start,
|
|
@@ -6506,6 +6550,36 @@ function toValidSource(verified) {
|
|
|
6506
6550
|
),
|
|
6507
6551
|
}
|
|
6508
6552
|
}
|
|
6553
|
+
function verifySpanEvidence(ctx, item) {
|
|
6554
|
+
if (!isRecord2(item)) return drop('malformed-candidate')
|
|
6555
|
+
const verified = verifyFile(ctx, item.project, item)
|
|
6556
|
+
if (verified.status !== 'ok') return verified
|
|
6557
|
+
const { start, end } = item
|
|
6558
|
+
if (!isSpan(start, end)) return drop('malformed-candidate')
|
|
6559
|
+
if (!spanHoldsExcerpt(verified, start, end)) {
|
|
6560
|
+
return drop('excerpt-outside-span')
|
|
6561
|
+
}
|
|
6562
|
+
return { ...toValidSource(verified), start, end }
|
|
6563
|
+
}
|
|
6564
|
+
function mismatchProblem(
|
|
6565
|
+
nextStep,
|
|
6566
|
+
reason,
|
|
6567
|
+
target,
|
|
6568
|
+
sourceCount,
|
|
6569
|
+
sourceProjects,
|
|
6570
|
+
targetEvidenceCount,
|
|
6571
|
+
evidenceCount,
|
|
6572
|
+
) {
|
|
6573
|
+
if (!isMismatchReason(reason)) return 'invalid-structure'
|
|
6574
|
+
if (sourceCount !== 1 || !sourceProjects.has(target)) {
|
|
6575
|
+
return 'invalid-structure'
|
|
6576
|
+
}
|
|
6577
|
+
if (targetEvidenceCount > 0) return 'invalid-structure'
|
|
6578
|
+
if (nextStep === 'compound-learning') return 'invalid-structure'
|
|
6579
|
+
return nextStep === 'refresh-learning' && evidenceCount < 1
|
|
6580
|
+
? 'invalid-structure'
|
|
6581
|
+
: undefined
|
|
6582
|
+
}
|
|
6509
6583
|
function contradictionProblem(nextStep, target, sourceCount, sourceProjects) {
|
|
6510
6584
|
if (sourceCount < 2 || !sourceProjects.has(target)) return 'invalid-structure'
|
|
6511
6585
|
if (![...sourceProjects].some((project) => project !== target)) {
|
|
@@ -6513,7 +6587,18 @@ function contradictionProblem(nextStep, target, sourceCount, sourceProjects) {
|
|
|
6513
6587
|
}
|
|
6514
6588
|
return nextStep === 'compound-learning' ? 'invalid-structure' : undefined
|
|
6515
6589
|
}
|
|
6516
|
-
function shapeProblem(
|
|
6590
|
+
function shapeProblem(
|
|
6591
|
+
kind,
|
|
6592
|
+
nextStep,
|
|
6593
|
+
target,
|
|
6594
|
+
sources,
|
|
6595
|
+
targetEvidenceCount,
|
|
6596
|
+
evidenceCount,
|
|
6597
|
+
reason,
|
|
6598
|
+
) {
|
|
6599
|
+
if (kind !== 'code-mismatch' && reason !== undefined) {
|
|
6600
|
+
return 'invalid-structure'
|
|
6601
|
+
}
|
|
6517
6602
|
if (sources.length < 1) return 'invalid-structure'
|
|
6518
6603
|
const seen = new Set()
|
|
6519
6604
|
const sourceProjects = new Set()
|
|
@@ -6532,6 +6617,17 @@ function shapeProblem(kind, nextStep, target, sources, targetEvidenceCount) {
|
|
|
6532
6617
|
sourceProjects,
|
|
6533
6618
|
)
|
|
6534
6619
|
}
|
|
6620
|
+
if (kind === 'code-mismatch') {
|
|
6621
|
+
return mismatchProblem(
|
|
6622
|
+
nextStep,
|
|
6623
|
+
reason,
|
|
6624
|
+
target,
|
|
6625
|
+
sources.length,
|
|
6626
|
+
sourceProjects,
|
|
6627
|
+
targetEvidenceCount,
|
|
6628
|
+
evidenceCount,
|
|
6629
|
+
)
|
|
6630
|
+
}
|
|
6535
6631
|
if (sourceProjects.has(target) || targetEvidenceCount < 1) {
|
|
6536
6632
|
return 'invalid-structure'
|
|
6537
6633
|
}
|
|
@@ -6602,6 +6698,8 @@ function checkCandidate(raw, ctx) {
|
|
|
6602
6698
|
header.target.root,
|
|
6603
6699
|
sources,
|
|
6604
6700
|
evidence.length,
|
|
6701
|
+
counter.length,
|
|
6702
|
+
raw.reason,
|
|
6605
6703
|
)
|
|
6606
6704
|
if (shape !== undefined) return drop(shape)
|
|
6607
6705
|
const validSources = verifyEach(sources, (item) =>
|
|
@@ -6617,7 +6715,9 @@ function checkCandidate(raw, ctx) {
|
|
|
6617
6715
|
)
|
|
6618
6716
|
if (isHalt(validEvidence)) return validEvidence
|
|
6619
6717
|
const validCounter = verifyEach(counter, (item) =>
|
|
6620
|
-
|
|
6718
|
+
header.kind === 'code-mismatch'
|
|
6719
|
+
? verifySpanEvidence(ctx, item)
|
|
6720
|
+
: verifySource(ctx, item, false),
|
|
6621
6721
|
)
|
|
6622
6722
|
if (isHalt(validCounter)) return validCounter
|
|
6623
6723
|
return {
|
|
@@ -6630,6 +6730,9 @@ function checkCandidate(raw, ctx) {
|
|
|
6630
6730
|
title: header.title,
|
|
6631
6731
|
summary: header.summary,
|
|
6632
6732
|
nextStep: header.nextStep,
|
|
6733
|
+
...(header.kind === 'code-mismatch' && isMismatchReason(raw.reason)
|
|
6734
|
+
? { reason: raw.reason }
|
|
6735
|
+
: {}),
|
|
6633
6736
|
overlapCheck: header.overlapCheck,
|
|
6634
6737
|
sources: validSources,
|
|
6635
6738
|
targetEvidence: validEvidence,
|
|
@@ -6637,8 +6740,31 @@ function checkCandidate(raw, ctx) {
|
|
|
6637
6740
|
},
|
|
6638
6741
|
}
|
|
6639
6742
|
}
|
|
6743
|
+
function claimFingerprint(excerpt) {
|
|
6744
|
+
return createHash2('sha256').update(excerpt).digest('hex')
|
|
6745
|
+
}
|
|
6746
|
+
function mismatchRecord(candidate) {
|
|
6747
|
+
const [claim] = candidate.sources
|
|
6748
|
+
if (
|
|
6749
|
+
candidate.kind !== 'code-mismatch' ||
|
|
6750
|
+
candidate.reason === undefined ||
|
|
6751
|
+
claim === undefined
|
|
6752
|
+
) {
|
|
6753
|
+
return
|
|
6754
|
+
}
|
|
6755
|
+
return {
|
|
6756
|
+
mismatchReason: candidate.reason,
|
|
6757
|
+
claim: claimFingerprint(claim.excerpt),
|
|
6758
|
+
evidence: candidate.counterevidence.map((item) => ({
|
|
6759
|
+
project: projectKey(item.project),
|
|
6760
|
+
path: item.path,
|
|
6761
|
+
fingerprint: item.fingerprint,
|
|
6762
|
+
})),
|
|
6763
|
+
}
|
|
6764
|
+
}
|
|
6640
6765
|
function toCandidateRecord(candidate) {
|
|
6641
6766
|
return {
|
|
6767
|
+
...mismatchRecord(candidate),
|
|
6642
6768
|
kind: candidate.kind,
|
|
6643
6769
|
target: candidate.target,
|
|
6644
6770
|
ruleId: candidate.ruleId,
|
|
@@ -6773,7 +6899,35 @@ function renderSourceBlock(heading, items) {
|
|
|
6773
6899
|
}
|
|
6774
6900
|
return out
|
|
6775
6901
|
}
|
|
6776
|
-
function
|
|
6902
|
+
function renderMismatchEvidence(items, heads, recorded) {
|
|
6903
|
+
if (items.length === 0) return []
|
|
6904
|
+
const out = ['Evidence:', '']
|
|
6905
|
+
for (const [index, item] of items.entries()) {
|
|
6906
|
+
const head =
|
|
6907
|
+
recorded === undefined ? heads.get(item.project) : recorded[index]
|
|
6908
|
+
const span = `${item.path}:${item.start ?? '?'}-${item.end ?? '?'}`
|
|
6909
|
+
out.push(
|
|
6910
|
+
`- ${inline(item.projectName)} ${inline(span)} fingerprint ${inline(item.fingerprint)} ${head === undefined ? 'HEAD unavailable' : `HEAD ${inline(head)}`}`,
|
|
6911
|
+
'',
|
|
6912
|
+
fenced(item.excerpt),
|
|
6913
|
+
'',
|
|
6914
|
+
)
|
|
6915
|
+
}
|
|
6916
|
+
return out
|
|
6917
|
+
}
|
|
6918
|
+
function headsOf(projects) {
|
|
6919
|
+
const heads = new Map()
|
|
6920
|
+
for (const project of projects) {
|
|
6921
|
+
if (project.commit !== undefined) heads.set(project.root, project.commit)
|
|
6922
|
+
}
|
|
6923
|
+
return heads
|
|
6924
|
+
}
|
|
6925
|
+
function revisionLines(item, prefix) {
|
|
6926
|
+
return item.revision === undefined
|
|
6927
|
+
? []
|
|
6928
|
+
: [`${prefix}Revision: ${item.revision}`]
|
|
6929
|
+
}
|
|
6930
|
+
function renderCandidate(item, index, heads = new Map()) {
|
|
6777
6931
|
const { candidate } = item
|
|
6778
6932
|
const out = [
|
|
6779
6933
|
`### Candidate ${index + 1}: ${candidate.kind} (${item.standing})`,
|
|
@@ -6781,8 +6935,12 @@ function renderCandidate(item, index) {
|
|
|
6781
6935
|
`- Id: ${inline(item.id)}`,
|
|
6782
6936
|
`- Target: ${inline(candidate.targetName)} ${inline(candidate.target)}`,
|
|
6783
6937
|
`- Rule: ${inline(candidate.ruleId)}`,
|
|
6938
|
+
...(candidate.reason === undefined
|
|
6939
|
+
? []
|
|
6940
|
+
: [`- Reason: ${candidate.reason}`]),
|
|
6784
6941
|
`- Next step: ${candidate.nextStep}`,
|
|
6785
6942
|
`- Status: candidate`,
|
|
6943
|
+
...revisionLines(item, '- '),
|
|
6786
6944
|
]
|
|
6787
6945
|
if (item.refreshPointer !== undefined) {
|
|
6788
6946
|
out.push(`- Refresh pointer: ${inline(item.refreshPointer)}`)
|
|
@@ -6806,7 +6964,15 @@ function renderCandidate(item, index) {
|
|
|
6806
6964
|
)
|
|
6807
6965
|
}
|
|
6808
6966
|
}
|
|
6809
|
-
out.push(
|
|
6967
|
+
out.push(
|
|
6968
|
+
...(candidate.kind === 'code-mismatch'
|
|
6969
|
+
? renderMismatchEvidence(
|
|
6970
|
+
candidate.counterevidence,
|
|
6971
|
+
heads,
|
|
6972
|
+
item.evidenceHeads,
|
|
6973
|
+
)
|
|
6974
|
+
: renderSourceBlock('Counterevidence:', candidate.counterevidence)),
|
|
6975
|
+
)
|
|
6810
6976
|
out.push(
|
|
6811
6977
|
`Overlap check: ${candidate.overlapCheck.result}; searched ${candidate.overlapCheck.queries.length} quer${candidate.overlapCheck.queries.length === 1 ? 'y' : 'ies'}.`,
|
|
6812
6978
|
)
|
|
@@ -6851,12 +7017,16 @@ function projectLines(model) {
|
|
|
6851
7017
|
const out = ['', 'Projects:']
|
|
6852
7018
|
for (const project of model.projects) {
|
|
6853
7019
|
const flags = [
|
|
7020
|
+
project.commit === undefined
|
|
7021
|
+
? 'HEAD unavailable'
|
|
7022
|
+
: `HEAD ${inline(project.commit)}`,
|
|
7023
|
+
...(project.evidenceOnly === true ? ['read only as evidence'] : []),
|
|
6854
7024
|
...(project.citationsUnsupported
|
|
6855
7025
|
? ['no path-and-line citations to check']
|
|
6856
7026
|
: []),
|
|
6857
7027
|
...(project.truncated ? ['inventory reached a bound'] : []),
|
|
6858
7028
|
]
|
|
6859
|
-
const suffix =
|
|
7029
|
+
const suffix = `; ${flags.join('; ')}`
|
|
6860
7030
|
out.push(
|
|
6861
7031
|
`- ${inline(project.name)} ${inline(project.root)}: ${project.files} files${suffix}`,
|
|
6862
7032
|
)
|
|
@@ -6974,8 +7144,9 @@ function renderDigest(model) {
|
|
|
6974
7144
|
} else if (model.candidates.length === 0) {
|
|
6975
7145
|
out.push('No new candidate. See the connections already recorded.', '')
|
|
6976
7146
|
}
|
|
7147
|
+
const heads = headsOf(model.projects)
|
|
6977
7148
|
model.candidates.forEach((item, index) => {
|
|
6978
|
-
out.push(...renderCandidate(item, index))
|
|
7149
|
+
out.push(...renderCandidate(item, index, heads))
|
|
6979
7150
|
})
|
|
6980
7151
|
out.push('## Connections already recorded', '')
|
|
6981
7152
|
if (model.recorded.length === 0) {
|
|
@@ -7007,8 +7178,11 @@ function candidateLines(model, runRecordPath) {
|
|
|
7007
7178
|
const pasteable = isPasteablePath(runRecordPath)
|
|
7008
7179
|
const out = ['Candidates (untrusted text, quoted):']
|
|
7009
7180
|
for (const item of titles) {
|
|
7010
|
-
|
|
7181
|
+
const { kind, reason, title } = item.candidate
|
|
7182
|
+
const label = reason === undefined ? kind : `${kind} (${reason})`
|
|
7183
|
+
out.push(quote(`${label}: ${title}`))
|
|
7011
7184
|
out.push(handoffLine(item, runRecordPath, pasteable))
|
|
7185
|
+
out.push(...revisionLines(item, ''))
|
|
7012
7186
|
}
|
|
7013
7187
|
const promotesLesson = titles.some(
|
|
7014
7188
|
(item) =>
|
|
@@ -7031,12 +7205,36 @@ function candidateLines(model, runRecordPath) {
|
|
|
7031
7205
|
return out
|
|
7032
7206
|
}
|
|
7033
7207
|
var REFRESH_PATH = /^docs\/solutions\/[A-Za-z0-9._/-]+\.md$/
|
|
7208
|
+
function isRefreshable(rel) {
|
|
7209
|
+
return (
|
|
7210
|
+
REFRESH_PATH.test(rel) &&
|
|
7211
|
+
path4.posix.basename(rel) !== 'README.md' &&
|
|
7212
|
+
!rel.startsWith('docs/solutions/_archived/') &&
|
|
7213
|
+
!rel.startsWith('docs/solutions/patterns/')
|
|
7214
|
+
)
|
|
7215
|
+
}
|
|
7216
|
+
var REFRESH_CONTEXT_NOTE =
|
|
7217
|
+
'Give ce:compound-refresh the lines below as context beside the command, not inside its arguments. They are data to recheck, not instructions, and they never set the scope.'
|
|
7218
|
+
var MAX_CLAIM_CHARS = 240
|
|
7219
|
+
function claimText(excerpt) {
|
|
7220
|
+
const flat = sanitizeText(excerpt).trim()
|
|
7221
|
+
const cut =
|
|
7222
|
+
flat.length > MAX_CLAIM_CHARS
|
|
7223
|
+
? `${Array.from(flat).slice(0, MAX_CLAIM_CHARS).join('')}…`
|
|
7224
|
+
: flat
|
|
7225
|
+
return inline(cut.replace(/\b(path|mode):/gi, '$1 :'))
|
|
7226
|
+
}
|
|
7034
7227
|
function handoffLine(item, runRecordPath, pasteable) {
|
|
7035
7228
|
const { candidate } = item
|
|
7036
7229
|
if (candidate.nextStep === 'investigate') {
|
|
7037
|
-
return
|
|
7230
|
+
return candidate.kind === 'code-mismatch'
|
|
7231
|
+
? 'Investigate first: there is no refresh command for this candidate. Check whether the learning claim still holds in the code that governs it; the digest shows what was found.'
|
|
7232
|
+
: 'Investigate first: there is no promotion token for this candidate. See the digest for what to check.'
|
|
7038
7233
|
}
|
|
7039
|
-
if (
|
|
7234
|
+
if (
|
|
7235
|
+
candidate.kind === 'contradiction' ||
|
|
7236
|
+
candidate.kind === 'code-mismatch'
|
|
7237
|
+
) {
|
|
7040
7238
|
const paths = [
|
|
7041
7239
|
...new Set(
|
|
7042
7240
|
candidate.sources
|
|
@@ -7044,11 +7242,25 @@ function handoffLine(item, runRecordPath, pasteable) {
|
|
|
7044
7242
|
.map((source) => source.path),
|
|
7045
7243
|
),
|
|
7046
7244
|
]
|
|
7047
|
-
if (paths.length === 0 || !paths.every(
|
|
7245
|
+
if (paths.length === 0 || !paths.every(isRefreshable)) {
|
|
7048
7246
|
return 'Review by hand: the target learning has a path that a refresh scope cannot take. See the digest.'
|
|
7049
7247
|
}
|
|
7050
7248
|
const scope = paths.map((p) => `path:${p}`).join(' ')
|
|
7051
|
-
|
|
7249
|
+
const command = `Review in ${inline(candidate.targetName)}: /ce:compound-refresh ${scope}`
|
|
7250
|
+
if (candidate.kind !== 'code-mismatch') return command
|
|
7251
|
+
const evidence = candidate.counterevidence.map(
|
|
7252
|
+
(cited) =>
|
|
7253
|
+
`${inline(cited.projectName)} ${inline(`${cited.path}:${cited.start ?? '?'}-${cited.end ?? '?'}`)}`,
|
|
7254
|
+
)
|
|
7255
|
+
return [
|
|
7256
|
+
command,
|
|
7257
|
+
REFRESH_CONTEXT_NOTE,
|
|
7258
|
+
` Claim (${candidate.reason ?? 'unknown'}): ${claimText(candidate.sources[0]?.excerpt ?? '')}`,
|
|
7259
|
+
...(evidence.length === 0
|
|
7260
|
+
? []
|
|
7261
|
+
: [` Evidence to recheck before you confirm: ${evidence.join(', ')}`]),
|
|
7262
|
+
].join(`
|
|
7263
|
+
`)
|
|
7052
7264
|
}
|
|
7053
7265
|
return pasteable
|
|
7054
7266
|
? `candidate:${runRecordPath} candidate-id:${item.id}`
|
|
@@ -7368,6 +7580,7 @@ var MAX_PATH_LENGTH = 4096
|
|
|
7368
7580
|
var MAX_REASON_LENGTH = 500
|
|
7369
7581
|
var MAX_SOURCES = 32
|
|
7370
7582
|
var MAX_TARGET_EVIDENCE = 64
|
|
7583
|
+
var MAX_EVIDENCE = 64
|
|
7371
7584
|
var MAX_HISTORY = 10
|
|
7372
7585
|
var MAX_POSSIBLE_MATCHES = 5
|
|
7373
7586
|
var MAX_RUN_FILES = 16
|
|
@@ -7747,6 +7960,13 @@ function validPath(value) {
|
|
|
7747
7960
|
function validFingerprint(value) {
|
|
7748
7961
|
return plainText(value, 128)
|
|
7749
7962
|
}
|
|
7963
|
+
function validEvidenceRef(value) {
|
|
7964
|
+
return (
|
|
7965
|
+
isProjectKey(value.project) &&
|
|
7966
|
+
validPath(value.path) &&
|
|
7967
|
+
validFingerprint(value.fingerprint)
|
|
7968
|
+
)
|
|
7969
|
+
}
|
|
7750
7970
|
function validCandidate(value) {
|
|
7751
7971
|
if (!plainText(value.kind, MAX_STRING_LENGTH)) return false
|
|
7752
7972
|
if (!plainText(value.target, MAX_PATH_LENGTH)) return false
|
|
@@ -7765,9 +7985,20 @@ function validCandidate(value) {
|
|
|
7765
7985
|
}
|
|
7766
7986
|
}
|
|
7767
7987
|
if (value.targetEvidence.length > MAX_TARGET_EVIDENCE) return false
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7988
|
+
if (
|
|
7989
|
+
!value.targetEvidence.every(
|
|
7990
|
+
(ref) => validPath(ref.path) && validFingerprint(ref.fingerprint),
|
|
7991
|
+
)
|
|
7992
|
+
) {
|
|
7993
|
+
return false
|
|
7994
|
+
}
|
|
7995
|
+
return validMismatchFields(value)
|
|
7996
|
+
}
|
|
7997
|
+
function validMismatchFields(value) {
|
|
7998
|
+
if (!isOptionalText(value.mismatchReason, MAX_STRING_LENGTH)) return false
|
|
7999
|
+
if (!isOptionalText(value.claim, MAX_STRING_LENGTH)) return false
|
|
8000
|
+
const evidence = value.evidence ?? []
|
|
8001
|
+
return evidence.length <= MAX_EVIDENCE && evidence.every(validEvidenceRef)
|
|
7771
8002
|
}
|
|
7772
8003
|
function normalizedSources(candidate) {
|
|
7773
8004
|
const seen = new Set()
|
|
@@ -7798,19 +8029,50 @@ function normalizedTargetEvidence(candidate) {
|
|
|
7798
8029
|
}
|
|
7799
8030
|
return [...byPath.values()].sort((a, b) => codepointOrder2(a.path, b.path))
|
|
7800
8031
|
}
|
|
8032
|
+
function normalizedEvidence(candidate) {
|
|
8033
|
+
const seen = new Map()
|
|
8034
|
+
for (const ref of candidate.evidence ?? []) {
|
|
8035
|
+
const normalized = normalizePath(ref.path)
|
|
8036
|
+
const key = `${ref.project}\x00${normalized}`
|
|
8037
|
+
if (!seen.has(key)) {
|
|
8038
|
+
seen.set(key, {
|
|
8039
|
+
project: ref.project,
|
|
8040
|
+
path: normalized,
|
|
8041
|
+
fingerprint: ref.fingerprint,
|
|
8042
|
+
})
|
|
8043
|
+
}
|
|
8044
|
+
}
|
|
8045
|
+
return [...seen.values()].sort(
|
|
8046
|
+
(a, b) =>
|
|
8047
|
+
codepointOrder2(a.project, b.project) || codepointOrder2(a.path, b.path),
|
|
8048
|
+
)
|
|
8049
|
+
}
|
|
8050
|
+
function recordsEvidenceOf(entry, candidate) {
|
|
8051
|
+
const recorded = entry.evidence ?? []
|
|
8052
|
+
const cited = normalizedEvidence(candidate)
|
|
8053
|
+
return (
|
|
8054
|
+
recorded.length === cited.length &&
|
|
8055
|
+
recorded.every(
|
|
8056
|
+
(ref, index) =>
|
|
8057
|
+
ref.project === cited[index]?.project &&
|
|
8058
|
+
ref.path === cited[index]?.path &&
|
|
8059
|
+
ref.fingerprint === cited[index]?.fingerprint,
|
|
8060
|
+
)
|
|
8061
|
+
)
|
|
8062
|
+
}
|
|
7801
8063
|
function candidateIdentity(candidate) {
|
|
7802
8064
|
const sources = normalizedSources(candidate).map((s) => [s.role, s.path])
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
8065
|
+
const parts = [
|
|
8066
|
+
'connect-candidate-v1',
|
|
8067
|
+
candidate.kind,
|
|
8068
|
+
candidate.target,
|
|
8069
|
+
candidate.ruleId,
|
|
8070
|
+
sources,
|
|
8071
|
+
]
|
|
8072
|
+
if (candidate.mismatchReason !== undefined || candidate.claim !== undefined) {
|
|
8073
|
+
parts.push(candidate.mismatchReason ?? null, candidate.claim ?? null)
|
|
8074
|
+
}
|
|
8075
|
+
return createHash3('sha256').update(JSON.stringify(parts)).digest('hex')
|
|
7814
8076
|
}
|
|
7815
8077
|
var LEDGER_VERSION = 2
|
|
7816
8078
|
var LEDGER_STATUSES = ['candidate', 'promoted', 'rejected']
|
|
@@ -7818,11 +8080,25 @@ function isLedgerStatus(value) {
|
|
|
7818
8080
|
return LEDGER_STATUSES.some((status) => status === value)
|
|
7819
8081
|
}
|
|
7820
8082
|
function isReopenReason(value) {
|
|
7821
|
-
return
|
|
8083
|
+
return (
|
|
8084
|
+
value === 'sources changed' ||
|
|
8085
|
+
value === 'target changed' ||
|
|
8086
|
+
value === 'evidence changed'
|
|
8087
|
+
)
|
|
8088
|
+
}
|
|
8089
|
+
function isOptionalReopenedFor(value) {
|
|
8090
|
+
return value === undefined || value === 'evidence changed'
|
|
7822
8091
|
}
|
|
7823
8092
|
function isOptionalText(value, maxLength) {
|
|
7824
8093
|
return value === undefined || plainText(value, maxLength)
|
|
7825
8094
|
}
|
|
8095
|
+
var REVISION = /^[0-9a-f]{12}$/
|
|
8096
|
+
function isRevision(value) {
|
|
8097
|
+
return typeof value === 'string' && REVISION.test(value)
|
|
8098
|
+
}
|
|
8099
|
+
function isOptionalRevision(value) {
|
|
8100
|
+
return value === undefined || isRevision(value)
|
|
8101
|
+
}
|
|
7826
8102
|
function isLedgerSource(value) {
|
|
7827
8103
|
return (
|
|
7828
8104
|
isRecord3(value) &&
|
|
@@ -7838,13 +8114,32 @@ function isTargetEvidenceRef(value) {
|
|
|
7838
8114
|
validFingerprint(value.fingerprint)
|
|
7839
8115
|
)
|
|
7840
8116
|
}
|
|
8117
|
+
function isEvidenceRef(value) {
|
|
8118
|
+
return (
|
|
8119
|
+
isRecord3(value) &&
|
|
8120
|
+
isProjectKey(value.project) &&
|
|
8121
|
+
plainText(value.path, MAX_PATH_LENGTH) &&
|
|
8122
|
+
validFingerprint(value.fingerprint)
|
|
8123
|
+
)
|
|
8124
|
+
}
|
|
8125
|
+
function isOptionalEvidence(value) {
|
|
8126
|
+
return (
|
|
8127
|
+
value === undefined ||
|
|
8128
|
+
(Array.isArray(value) &&
|
|
8129
|
+
value.length <= MAX_EVIDENCE &&
|
|
8130
|
+
value.every(isEvidenceRef))
|
|
8131
|
+
)
|
|
8132
|
+
}
|
|
7841
8133
|
function isHistoryItem(value) {
|
|
7842
8134
|
return (
|
|
7843
8135
|
isRecord3(value) &&
|
|
7844
8136
|
isLedgerStatus(value.status) &&
|
|
8137
|
+
isOptionalText(value.mismatchReason, MAX_STRING_LENGTH) &&
|
|
8138
|
+
isOptionalEvidence(value.evidence) &&
|
|
7845
8139
|
isOptionalText(value.reason, MAX_REASON_LENGTH) &&
|
|
7846
8140
|
isOptionalText(value.destination, MAX_PATH_LENGTH) &&
|
|
7847
8141
|
(value.reopened === undefined || isReopenReason(value.reopened)) &&
|
|
8142
|
+
isOptionalReopenedFor(value.reopenedFor) &&
|
|
7848
8143
|
Array.isArray(value.sources) &&
|
|
7849
8144
|
value.sources.every(isLedgerSource) &&
|
|
7850
8145
|
Array.isArray(value.targetEvidence) &&
|
|
@@ -7863,10 +8158,14 @@ function isLedgerEntry(value) {
|
|
|
7863
8158
|
value.sources.every(isLedgerSource) &&
|
|
7864
8159
|
Array.isArray(value.targetEvidence) &&
|
|
7865
8160
|
value.targetEvidence.every(isTargetEvidenceRef) &&
|
|
8161
|
+
isOptionalText(value.mismatchReason, MAX_STRING_LENGTH) &&
|
|
8162
|
+
isOptionalEvidence(value.evidence) &&
|
|
7866
8163
|
isLedgerStatus(value.status) &&
|
|
7867
8164
|
isOptionalText(value.reason, MAX_REASON_LENGTH) &&
|
|
7868
8165
|
isOptionalText(value.destination, MAX_PATH_LENGTH) &&
|
|
7869
8166
|
(value.reopened === undefined || isReopenReason(value.reopened)) &&
|
|
8167
|
+
isOptionalReopenedFor(value.reopenedFor) &&
|
|
8168
|
+
isOptionalRevision(value.revision) &&
|
|
7870
8169
|
Array.isArray(value.history) &&
|
|
7871
8170
|
value.history.every(isHistoryItem) &&
|
|
7872
8171
|
plainText(value.recordedAt, MAX_STRING_LENGTH)
|
|
@@ -7970,6 +8269,21 @@ function sameTargetEvidence(current, prior) {
|
|
|
7970
8269
|
return known === undefined || known.fingerprint === ref.fingerprint
|
|
7971
8270
|
})
|
|
7972
8271
|
}
|
|
8272
|
+
function evidenceChanged(prior, lookup) {
|
|
8273
|
+
if (lookup === undefined) return false
|
|
8274
|
+
return (prior.evidence ?? []).some((ref) => {
|
|
8275
|
+
const now = lookup(ref.project, ref.path)
|
|
8276
|
+
if (now.status === 'gone') return true
|
|
8277
|
+
return now.status === 'present' && now.fingerprint !== ref.fingerprint
|
|
8278
|
+
})
|
|
8279
|
+
}
|
|
8280
|
+
function evidenceArrived(prior, candidate) {
|
|
8281
|
+
return (
|
|
8282
|
+
candidate.kind === 'code-mismatch' &&
|
|
8283
|
+
(prior.evidence ?? []).length === 0 &&
|
|
8284
|
+
normalizedEvidence(candidate).length > 0
|
|
8285
|
+
)
|
|
8286
|
+
}
|
|
7973
8287
|
function possibleRenames(ledger, candidate, id, sources) {
|
|
7974
8288
|
const matches = []
|
|
7975
8289
|
for (const entry of ledger.entries) {
|
|
@@ -7993,7 +8307,7 @@ function possibleRenames(ledger, candidate, id, sources) {
|
|
|
7993
8307
|
}
|
|
7994
8308
|
return matches
|
|
7995
8309
|
}
|
|
7996
|
-
function classifyCandidate(ledger, candidate) {
|
|
8310
|
+
function classifyCandidate(ledger, candidate, evidence) {
|
|
7997
8311
|
const id = candidateIdentity(candidate)
|
|
7998
8312
|
const sources = normalizedSources(candidate)
|
|
7999
8313
|
const missing = sources
|
|
@@ -8009,28 +8323,36 @@ function classifyCandidate(ledger, candidate) {
|
|
|
8009
8323
|
}
|
|
8010
8324
|
}
|
|
8011
8325
|
const sourcesSame = sameSources(sources, prior)
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8326
|
+
const pointer =
|
|
8327
|
+
prior.status === 'promoted' && prior.destination !== undefined
|
|
8328
|
+
? { refreshPointer: prior.destination }
|
|
8329
|
+
: {}
|
|
8330
|
+
if (!sourcesSame) {
|
|
8331
|
+
return {
|
|
8332
|
+
standing: 'reopened',
|
|
8333
|
+
id,
|
|
8334
|
+
reason: 'sources changed',
|
|
8335
|
+
priorStatus: prior.status,
|
|
8336
|
+
...pointer,
|
|
8337
|
+
}
|
|
8017
8338
|
}
|
|
8018
|
-
if (
|
|
8339
|
+
if (evidenceChanged(prior, evidence) || evidenceArrived(prior, candidate)) {
|
|
8019
8340
|
return {
|
|
8020
8341
|
standing: 'reopened',
|
|
8021
8342
|
id,
|
|
8022
|
-
reason: '
|
|
8343
|
+
reason: 'evidence changed',
|
|
8023
8344
|
priorStatus: prior.status,
|
|
8345
|
+
...pointer,
|
|
8024
8346
|
}
|
|
8025
8347
|
}
|
|
8348
|
+
if (sameTargetEvidence(normalizedTargetEvidence(candidate), prior)) {
|
|
8349
|
+
return { standing: 'suppressed', id, priorStatus: prior.status }
|
|
8350
|
+
}
|
|
8026
8351
|
return {
|
|
8027
8352
|
standing: 'reopened',
|
|
8028
8353
|
id,
|
|
8029
|
-
reason: '
|
|
8354
|
+
reason: 'target changed',
|
|
8030
8355
|
priorStatus: prior.status,
|
|
8031
|
-
...(prior.status === 'promoted' && prior.destination !== undefined
|
|
8032
|
-
? { refreshPointer: prior.destination }
|
|
8033
|
-
: {}),
|
|
8034
8356
|
}
|
|
8035
8357
|
}
|
|
8036
8358
|
function ledgerSources(candidate) {
|
|
@@ -8046,26 +8368,86 @@ function ledgerSources(candidate) {
|
|
|
8046
8368
|
],
|
|
8047
8369
|
)
|
|
8048
8370
|
}
|
|
8371
|
+
function mismatchFields(candidate) {
|
|
8372
|
+
const evidence = normalizedEvidence(candidate)
|
|
8373
|
+
return {
|
|
8374
|
+
...(candidate.mismatchReason === undefined
|
|
8375
|
+
? {}
|
|
8376
|
+
: { mismatchReason: candidate.mismatchReason }),
|
|
8377
|
+
...(evidence.length === 0 ? {} : { evidence }),
|
|
8378
|
+
}
|
|
8379
|
+
}
|
|
8380
|
+
function withEvidence(entry, evidence) {
|
|
8381
|
+
const { evidence: _recorded, revision: _stale, ...rest } = entry
|
|
8382
|
+
const next =
|
|
8383
|
+
evidence.length === 0 ? rest : { ...rest, evidence: [...evidence] }
|
|
8384
|
+
return { ...next, revision: revisionOf(next) }
|
|
8385
|
+
}
|
|
8386
|
+
function reopenedFields(reason) {
|
|
8387
|
+
return reason === 'evidence changed'
|
|
8388
|
+
? { reopened: 'target changed', reopenedFor: reason }
|
|
8389
|
+
: { reopened: reason }
|
|
8390
|
+
}
|
|
8391
|
+
function revisionOfParts(sources, targetEvidence, evidence) {
|
|
8392
|
+
return createHash3('sha256')
|
|
8393
|
+
.update(
|
|
8394
|
+
JSON.stringify([
|
|
8395
|
+
'connect-revision-v1',
|
|
8396
|
+
sources.map((x) => [x.role, x.path, x.fingerprint]),
|
|
8397
|
+
targetEvidence.map((x) => [x.path, x.fingerprint]),
|
|
8398
|
+
evidence.map((x) => [x.project, x.path, x.fingerprint]),
|
|
8399
|
+
]),
|
|
8400
|
+
)
|
|
8401
|
+
.digest('hex')
|
|
8402
|
+
.slice(0, 12)
|
|
8403
|
+
}
|
|
8404
|
+
function revisionOfCandidate(candidate) {
|
|
8405
|
+
return revisionOfParts(
|
|
8406
|
+
ledgerSources(candidate),
|
|
8407
|
+
normalizedTargetEvidence(candidate),
|
|
8408
|
+
normalizedEvidence(candidate),
|
|
8409
|
+
)
|
|
8410
|
+
}
|
|
8411
|
+
function revisionOf(entry) {
|
|
8412
|
+
return (
|
|
8413
|
+
entry.revision ??
|
|
8414
|
+
revisionOfParts(entry.sources, entry.targetEvidence, entry.evidence ?? [])
|
|
8415
|
+
)
|
|
8416
|
+
}
|
|
8049
8417
|
function snapshot(entry) {
|
|
8050
8418
|
return {
|
|
8051
8419
|
status: entry.status,
|
|
8420
|
+
...(entry.mismatchReason === undefined
|
|
8421
|
+
? {}
|
|
8422
|
+
: { mismatchReason: entry.mismatchReason }),
|
|
8423
|
+
...(entry.evidence === undefined ? {} : { evidence: entry.evidence }),
|
|
8052
8424
|
...(entry.reason === undefined ? {} : { reason: entry.reason }),
|
|
8053
8425
|
...(entry.destination === undefined
|
|
8054
8426
|
? {}
|
|
8055
8427
|
: { destination: entry.destination }),
|
|
8056
8428
|
...(entry.reopened === undefined ? {} : { reopened: entry.reopened }),
|
|
8429
|
+
...(entry.reopenedFor === undefined
|
|
8430
|
+
? {}
|
|
8431
|
+
: { reopenedFor: entry.reopenedFor }),
|
|
8057
8432
|
sources: entry.sources,
|
|
8058
8433
|
targetEvidence: entry.targetEvidence,
|
|
8059
8434
|
recordedAt: entry.recordedAt,
|
|
8060
8435
|
}
|
|
8061
8436
|
}
|
|
8062
|
-
function applyCandidates(
|
|
8437
|
+
function applyCandidates(
|
|
8438
|
+
ledger,
|
|
8439
|
+
candidates,
|
|
8440
|
+
recordedAt,
|
|
8441
|
+
evidence,
|
|
8442
|
+
evidenceFor,
|
|
8443
|
+
) {
|
|
8063
8444
|
let entries = [...ledger.entries]
|
|
8064
8445
|
const outcomes = []
|
|
8065
8446
|
for (const candidate of candidates) {
|
|
8066
8447
|
const outcome = classifyCandidate(
|
|
8067
8448
|
{ version: LEDGER_VERSION, entries },
|
|
8068
8449
|
candidate,
|
|
8450
|
+
evidenceFor?.(candidate) ?? evidence,
|
|
8069
8451
|
)
|
|
8070
8452
|
outcomes.push(outcome)
|
|
8071
8453
|
if (outcome.standing === 'new') {
|
|
@@ -8076,10 +8458,21 @@ function applyCandidates(ledger, candidates, recordedAt) {
|
|
|
8076
8458
|
ruleId: candidate.ruleId,
|
|
8077
8459
|
sources: ledgerSources(candidate),
|
|
8078
8460
|
targetEvidence: normalizedTargetEvidence(candidate),
|
|
8461
|
+
...mismatchFields(candidate),
|
|
8462
|
+
revision: revisionOfCandidate(candidate),
|
|
8079
8463
|
status: 'candidate',
|
|
8080
8464
|
history: [],
|
|
8081
8465
|
recordedAt,
|
|
8082
8466
|
})
|
|
8467
|
+
} else if (
|
|
8468
|
+
outcome.standing === 'suppressed' &&
|
|
8469
|
+
outcome.priorStatus === 'candidate'
|
|
8470
|
+
) {
|
|
8471
|
+
entries = entries.map((entry) =>
|
|
8472
|
+
entry.id === outcome.id
|
|
8473
|
+
? withEvidence(entry, normalizedEvidence(candidate))
|
|
8474
|
+
: entry,
|
|
8475
|
+
)
|
|
8083
8476
|
} else if (outcome.standing === 'reopened') {
|
|
8084
8477
|
entries = entries.map((entry) =>
|
|
8085
8478
|
entry.id === outcome.id
|
|
@@ -8090,8 +8483,10 @@ function applyCandidates(ledger, candidates, recordedAt) {
|
|
|
8090
8483
|
ruleId: entry.ruleId,
|
|
8091
8484
|
sources: ledgerSources(candidate),
|
|
8092
8485
|
targetEvidence: normalizedTargetEvidence(candidate),
|
|
8486
|
+
...mismatchFields(candidate),
|
|
8093
8487
|
status: 'candidate',
|
|
8094
|
-
|
|
8488
|
+
...reopenedFields(outcome.reason),
|
|
8489
|
+
revision: revisionOfCandidate(candidate),
|
|
8095
8490
|
history: [...entry.history, snapshot(entry)].slice(-MAX_HISTORY),
|
|
8096
8491
|
recordedAt,
|
|
8097
8492
|
}
|
|
@@ -8193,7 +8588,13 @@ function applyCoverage(allPrior, update, at) {
|
|
|
8193
8588
|
return records.sort(byRule)
|
|
8194
8589
|
}
|
|
8195
8590
|
function foldRun(prior, input, recordedAt) {
|
|
8196
|
-
const applied = applyCandidates(
|
|
8591
|
+
const applied = applyCandidates(
|
|
8592
|
+
prior,
|
|
8593
|
+
input.candidates,
|
|
8594
|
+
recordedAt,
|
|
8595
|
+
input.evidence,
|
|
8596
|
+
input.evidenceFor,
|
|
8597
|
+
)
|
|
8197
8598
|
const coverage =
|
|
8198
8599
|
input.coverage === undefined
|
|
8199
8600
|
? prior.coverage
|
|
@@ -8369,6 +8770,9 @@ function insertImportRun(root, plan, options = {}) {
|
|
|
8369
8770
|
runId: decision.runId,
|
|
8370
8771
|
files: decision.files,
|
|
8371
8772
|
candidates: decision.candidates,
|
|
8773
|
+
...(decision.evidenceFor === undefined
|
|
8774
|
+
? {}
|
|
8775
|
+
: { evidenceFor: decision.evidenceFor }),
|
|
8372
8776
|
},
|
|
8373
8777
|
options,
|
|
8374
8778
|
)
|
|
@@ -8559,8 +8963,17 @@ function validDecision(input) {
|
|
|
8559
8963
|
if (!plainText(input.id, MAX_STRING_LENGTH)) return false
|
|
8560
8964
|
if (input.status !== 'promoted' && input.status !== 'rejected') return false
|
|
8561
8965
|
if (!plainText(input.reason.trim(), MAX_REASON_LENGTH)) return false
|
|
8966
|
+
if (input.revision !== undefined && !isRevision(input.revision)) return false
|
|
8562
8967
|
return isOptionalText(input.destination, MAX_PATH_LENGTH)
|
|
8563
8968
|
}
|
|
8969
|
+
function refusalOf(input, prior) {
|
|
8970
|
+
if (input.onlyIfOpen === true && prior.status !== 'candidate') {
|
|
8971
|
+
return 'not-open'
|
|
8972
|
+
}
|
|
8973
|
+
const stale =
|
|
8974
|
+
input.revision !== undefined && input.revision !== revisionOf(prior)
|
|
8975
|
+
return stale ? 'stale-revision' : undefined
|
|
8976
|
+
}
|
|
8564
8977
|
function decideLedgerEntry(root, input, options = {}) {
|
|
8565
8978
|
if (!validDecision(input))
|
|
8566
8979
|
return { status: 'failed', reason: 'invalid-input' }
|
|
@@ -8578,9 +8991,8 @@ function decideLedgerEntry(root, input, options = {}) {
|
|
|
8578
8991
|
if (prior === undefined) {
|
|
8579
8992
|
return { status: 'failed', reason: 'unknown-candidate' }
|
|
8580
8993
|
}
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
}
|
|
8994
|
+
const refused = refusalOf(input, prior)
|
|
8995
|
+
if (refused !== undefined) return { status: 'failed', reason: refused }
|
|
8584
8996
|
const decided = {
|
|
8585
8997
|
id: prior.id,
|
|
8586
8998
|
kind: prior.kind,
|
|
@@ -8588,6 +9000,11 @@ function decideLedgerEntry(root, input, options = {}) {
|
|
|
8588
9000
|
ruleId: prior.ruleId,
|
|
8589
9001
|
sources: prior.sources,
|
|
8590
9002
|
targetEvidence: prior.targetEvidence,
|
|
9003
|
+
...(prior.mismatchReason === undefined
|
|
9004
|
+
? {}
|
|
9005
|
+
: { mismatchReason: prior.mismatchReason }),
|
|
9006
|
+
...(prior.evidence === undefined ? {} : { evidence: prior.evidence }),
|
|
9007
|
+
...(prior.revision === undefined ? {} : { revision: prior.revision }),
|
|
8591
9008
|
status: input.status,
|
|
8592
9009
|
reason: input.reason.trim(),
|
|
8593
9010
|
...(input.status === 'promoted' && input.destination !== undefined
|
|
@@ -8634,6 +9051,7 @@ function clearLedger(root, options = {}) {
|
|
|
8634
9051
|
|
|
8635
9052
|
// src/lib/connect-ci.ts
|
|
8636
9053
|
var REPORT_MAX_CHARS = 60000
|
|
9054
|
+
var MAX_UNVERIFIED_IDS = 20
|
|
8637
9055
|
var MANIFESTS_KEPT = 14
|
|
8638
9056
|
var REPORT_FILE = 'report.md'
|
|
8639
9057
|
var PAYLOAD_FILE = 'ci-payloads.json'
|
|
@@ -8651,15 +9069,17 @@ var DIGITS = /^[0-9]{1,20}$/
|
|
|
8651
9069
|
var DATE = /^\d{4}-\d{2}-\d{2}$/
|
|
8652
9070
|
var REPO = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
|
|
8653
9071
|
var TOKEN = /^[a-z][a-z0-9-]{0,39}$/
|
|
9072
|
+
var OBJECT_ID2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
8654
9073
|
function manifestMarker(hash) {
|
|
8655
9074
|
return `<!-- connect-manifest:${hash} -->`
|
|
8656
9075
|
}
|
|
8657
|
-
function decisionLine(id, status, ticked) {
|
|
8658
|
-
|
|
9076
|
+
function decisionLine(id, status, ticked, revision) {
|
|
9077
|
+
const suffix = revision === undefined ? '' : `:r${revision}`
|
|
9078
|
+
return `- [${ticked ? 'x' : ' '}] ${STATUS_LABEL[status]} <!-- connect-decision:${status}:${id}${suffix} -->`
|
|
8659
9079
|
}
|
|
8660
9080
|
var MANIFEST_LINE = /^<!-- connect-manifest:([0-9a-f]{16}) -->[ \t]*$/
|
|
8661
9081
|
var DECISION_LINE =
|
|
8662
|
-
/^- \[([ xX])\] (Promoted|Rejected) <!-- connect-decision:(promoted|rejected):([0-9a-f]{64}) -->[ \t]*$/
|
|
9082
|
+
/^- \[([ xX])\] (Promoted|Rejected) <!-- connect-decision:(promoted|rejected):([0-9a-f]{64})(?::r([0-9a-f]{12}))? -->[ \t]*$/
|
|
8663
9083
|
var FENCE_LINE2 = /^ {0,3}(`{3,}|~{3,})(.*)$/
|
|
8664
9084
|
function isRecord4(value) {
|
|
8665
9085
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
@@ -8790,13 +9210,13 @@ function inFence(scan, line) {
|
|
|
8790
9210
|
function boxOf(line) {
|
|
8791
9211
|
const match = DECISION_LINE.exec(line)
|
|
8792
9212
|
if (match === null) return
|
|
8793
|
-
const [, mark, label, status, id] = match
|
|
9213
|
+
const [, mark, label, status, id, named] = match
|
|
8794
9214
|
if (id === undefined || label === undefined || mark === undefined) {
|
|
8795
9215
|
return
|
|
8796
9216
|
}
|
|
8797
9217
|
if (status !== 'promoted' && status !== 'rejected') return
|
|
8798
9218
|
if (STATUS_LABEL[status] !== label) return
|
|
8799
|
-
return { id, status, ticked: mark !== ' ' }
|
|
9219
|
+
return { id, status, ticked: mark !== ' ', revision: named }
|
|
8800
9220
|
}
|
|
8801
9221
|
function scanLine(scan, line) {
|
|
8802
9222
|
if (inFence(scan, line)) return
|
|
@@ -8892,7 +9312,54 @@ function sourceOf(item) {
|
|
|
8892
9312
|
...(excerpt === undefined ? {} : { excerpt }),
|
|
8893
9313
|
}
|
|
8894
9314
|
}
|
|
8895
|
-
function
|
|
9315
|
+
function spanOf(start, end) {
|
|
9316
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end)) {
|
|
9317
|
+
return
|
|
9318
|
+
}
|
|
9319
|
+
const from = start
|
|
9320
|
+
const to = end
|
|
9321
|
+
return from >= 1 && to >= from ? { start: from, end: to } : undefined
|
|
9322
|
+
}
|
|
9323
|
+
function evidenceItemOf(item, heads, repos) {
|
|
9324
|
+
if (!isRecord4(item)) return
|
|
9325
|
+
const evidencePath = lineOf(item.path, LIMITS.path)
|
|
9326
|
+
if (evidencePath === undefined) return
|
|
9327
|
+
const span = spanOf(item.start, item.end)
|
|
9328
|
+
const head =
|
|
9329
|
+
typeof item.head === 'string' && OBJECT_ID2.test(item.head)
|
|
9330
|
+
? item.head
|
|
9331
|
+
: typeof item.project === 'string'
|
|
9332
|
+
? heads.get(item.project)
|
|
9333
|
+
: undefined
|
|
9334
|
+
const repo =
|
|
9335
|
+
typeof item.repo === 'string' && REPO.test(item.repo)
|
|
9336
|
+
? item.repo
|
|
9337
|
+
: typeof item.project === 'string'
|
|
9338
|
+
? repos.get(item.project)
|
|
9339
|
+
: undefined
|
|
9340
|
+
return {
|
|
9341
|
+
projectName: lineOf(item.projectName, LIMITS.name) ?? 'unknown',
|
|
9342
|
+
...(repo === undefined ? {} : { repo }),
|
|
9343
|
+
path: evidencePath,
|
|
9344
|
+
...(span === undefined ? {} : span),
|
|
9345
|
+
...(head === undefined ? {} : { head }),
|
|
9346
|
+
}
|
|
9347
|
+
}
|
|
9348
|
+
function mismatchFields2(raw, kind, heads, repos) {
|
|
9349
|
+
if (kind !== 'code-mismatch') return {}
|
|
9350
|
+
const reason = MISMATCH_REASONS.find((known) => known === raw.reason)
|
|
9351
|
+
const list = Array.isArray(raw.evidence) ? raw.evidence : raw.counterevidence
|
|
9352
|
+
const evidence = Array.isArray(list)
|
|
9353
|
+
? list
|
|
9354
|
+
.slice(0, CANDIDATE_LIMITS.counterevidence)
|
|
9355
|
+
.flatMap((item) => evidenceItemOf(item, heads, repos) ?? [])
|
|
9356
|
+
: []
|
|
9357
|
+
return {
|
|
9358
|
+
...(reason === undefined ? {} : { reason }),
|
|
9359
|
+
...(evidence.length === 0 ? {} : { evidence }),
|
|
9360
|
+
}
|
|
9361
|
+
}
|
|
9362
|
+
function payloadText(raw, heads, repos) {
|
|
8896
9363
|
if (!isRecord4(raw) || !Array.isArray(raw.sources)) return
|
|
8897
9364
|
const title = lineOf(raw.title, LIMITS.title)
|
|
8898
9365
|
const summary = paragraphOf(raw.summary, LIMITS.summary)
|
|
@@ -8900,18 +9367,28 @@ function payloadText(raw) {
|
|
|
8900
9367
|
const sources = raw.sources
|
|
8901
9368
|
.slice(0, LIMITS.sources)
|
|
8902
9369
|
.flatMap((item) => sourceOf(item) ?? [])
|
|
9370
|
+
const kind = tokenOf(raw.kind)
|
|
8903
9371
|
return {
|
|
8904
9372
|
title,
|
|
8905
9373
|
summary,
|
|
8906
|
-
kind
|
|
9374
|
+
kind,
|
|
8907
9375
|
nextStep: tokenOf(raw.nextStep),
|
|
8908
9376
|
targetName: lineOf(raw.targetName, LIMITS.name) ?? 'unknown',
|
|
8909
9377
|
sources,
|
|
9378
|
+
...mismatchFields2(raw, kind, heads, repos),
|
|
8910
9379
|
}
|
|
8911
9380
|
}
|
|
9381
|
+
var REVISION2 = /^[0-9a-f]{12}$/
|
|
9382
|
+
function revisionField(value) {
|
|
9383
|
+
const revision = revisionFrom(value)
|
|
9384
|
+
return revision === undefined ? {} : { revision }
|
|
9385
|
+
}
|
|
9386
|
+
function revisionFrom(value) {
|
|
9387
|
+
return typeof value === 'string' && REVISION2.test(value) ? value : undefined
|
|
9388
|
+
}
|
|
8912
9389
|
function payloadFromStore(raw) {
|
|
8913
9390
|
if (!isRecord4(raw) || !isCandidateId(raw.id)) return
|
|
8914
|
-
const text = payloadText(raw)
|
|
9391
|
+
const text = payloadText(raw, new Map(), new Map())
|
|
8915
9392
|
if (text === undefined) return
|
|
8916
9393
|
if (!isDigits(raw.runId) || !isDigits(raw.attempt)) return
|
|
8917
9394
|
const { repo, firstShown } = raw
|
|
@@ -8924,6 +9401,7 @@ function payloadFromStore(raw) {
|
|
|
8924
9401
|
: {}),
|
|
8925
9402
|
runId: raw.runId,
|
|
8926
9403
|
attempt: raw.attempt,
|
|
9404
|
+
...revisionField(raw.revision),
|
|
8927
9405
|
}
|
|
8928
9406
|
}
|
|
8929
9407
|
function readPayloadStore(root) {
|
|
@@ -8951,11 +9429,14 @@ function payloadStoreText(payloads) {
|
|
|
8951
9429
|
targetName: payload.targetName,
|
|
8952
9430
|
...(payload.repo === undefined ? {} : { repo: payload.repo }),
|
|
8953
9431
|
sources: payload.sources,
|
|
9432
|
+
...(payload.reason === undefined ? {} : { reason: payload.reason }),
|
|
9433
|
+
...(payload.evidence === undefined ? {} : { evidence: payload.evidence }),
|
|
8954
9434
|
...(payload.firstShown === undefined
|
|
8955
9435
|
? {}
|
|
8956
9436
|
: { firstShown: payload.firstShown }),
|
|
8957
9437
|
runId: payload.runId,
|
|
8958
9438
|
attempt: payload.attempt,
|
|
9439
|
+
...(payload.revision === undefined ? {} : { revision: payload.revision }),
|
|
8959
9440
|
}))
|
|
8960
9441
|
return `${JSON.stringify({ version: 1, payloads: stored }, null, 2)}
|
|
8961
9442
|
`
|
|
@@ -9054,6 +9535,22 @@ function repoMap(value) {
|
|
|
9054
9535
|
}
|
|
9055
9536
|
return out
|
|
9056
9537
|
}
|
|
9538
|
+
function commitMap(value) {
|
|
9539
|
+
const out = new Map()
|
|
9540
|
+
if (!Array.isArray(value)) return out
|
|
9541
|
+
for (const item of value.slice(0, MAX_PROJECTS)) {
|
|
9542
|
+
if (!isRecord4(item)) continue
|
|
9543
|
+
const { root, commit } = item
|
|
9544
|
+
if (
|
|
9545
|
+
typeof root === 'string' &&
|
|
9546
|
+
typeof commit === 'string' &&
|
|
9547
|
+
OBJECT_ID2.test(commit)
|
|
9548
|
+
) {
|
|
9549
|
+
out.set(root, commit)
|
|
9550
|
+
}
|
|
9551
|
+
}
|
|
9552
|
+
return out
|
|
9553
|
+
}
|
|
9057
9554
|
function candidatesOf(value) {
|
|
9058
9555
|
if (!isRecord4(value) || !Array.isArray(value.candidates)) return []
|
|
9059
9556
|
return value.candidates.slice(0, MAX_CANDIDATES)
|
|
@@ -9073,6 +9570,7 @@ function readRunSummary(root, runId) {
|
|
|
9073
9570
|
...(selection === undefined ? {} : { selection }),
|
|
9074
9571
|
...(sweep === undefined ? {} : { sweep }),
|
|
9075
9572
|
repoByRoot: repoMap(record.projects),
|
|
9573
|
+
commitByRoot: commitMap(record.projects),
|
|
9076
9574
|
candidates: candidatesOf(record.candidateBlock),
|
|
9077
9575
|
}
|
|
9078
9576
|
}
|
|
@@ -9105,6 +9603,7 @@ function factsOf(id, payload) {
|
|
|
9105
9603
|
const lines = [
|
|
9106
9604
|
`Id: ${id}`,
|
|
9107
9605
|
`Kind: ${payload.kind}`,
|
|
9606
|
+
...(payload.reason === undefined ? [] : [`Reason: ${payload.reason}`]),
|
|
9108
9607
|
`Target: ${target}`,
|
|
9109
9608
|
`Title: ${payload.title}`,
|
|
9110
9609
|
`Summary: ${payload.summary}`,
|
|
@@ -9115,27 +9614,41 @@ function factsOf(id, payload) {
|
|
|
9115
9614
|
lines.push(`- ${source.projectName} ${source.path}`)
|
|
9116
9615
|
if (source.excerpt !== undefined) lines.push(` Excerpt: ${source.excerpt}`)
|
|
9117
9616
|
}
|
|
9617
|
+
if (payload.evidence !== undefined) lines.push('Evidence:')
|
|
9618
|
+
for (const item of payload.evidence ?? []) {
|
|
9619
|
+
const span =
|
|
9620
|
+
item.start === undefined || item.end === undefined
|
|
9621
|
+
? '?'
|
|
9622
|
+
: `${item.start}-${item.end}`
|
|
9623
|
+
lines.push(
|
|
9624
|
+
`- ${item.projectName}:${item.path}:${span}:${item.head ?? 'unavailable'}`,
|
|
9625
|
+
)
|
|
9626
|
+
}
|
|
9118
9627
|
return lines.join(`
|
|
9119
9628
|
`)
|
|
9120
9629
|
}
|
|
9121
9630
|
function fetchWord(payload) {
|
|
9122
9631
|
return `${payload.runId}.${payload.attempt}`
|
|
9123
9632
|
}
|
|
9124
|
-
function blockOf(position,
|
|
9125
|
-
const
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
}
|
|
9633
|
+
function blockOf(position, entry, revision, payload, isNew) {
|
|
9634
|
+
const { id } = entry
|
|
9635
|
+
const marks = [
|
|
9636
|
+
...(isNew ? ['new'] : []),
|
|
9637
|
+
...(entry.reopened === undefined ? [] : ['reopened']),
|
|
9638
|
+
]
|
|
9639
|
+
const lines = [
|
|
9640
|
+
`### Candidate ${position}${marks.length === 0 ? '' : ` (${marks.join(', ')})`}`,
|
|
9641
|
+
'',
|
|
9642
|
+
]
|
|
9135
9643
|
lines.push(
|
|
9644
|
+
`- Fetch: \`/ce:connect fetch:${fetchWord(payload)}\` (run ${payload.runId}, attempt ${payload.attempt})`,
|
|
9136
9645
|
'',
|
|
9137
|
-
|
|
9138
|
-
|
|
9646
|
+
fenceText(factsOf(id, payload)),
|
|
9647
|
+
)
|
|
9648
|
+
lines.push(
|
|
9649
|
+
'',
|
|
9650
|
+
decisionLine(id, 'promoted', false, revision),
|
|
9651
|
+
decisionLine(id, 'rejected', false, revision),
|
|
9139
9652
|
'',
|
|
9140
9653
|
)
|
|
9141
9654
|
return lines.join(`
|
|
@@ -9155,7 +9668,6 @@ function ranges(positions) {
|
|
|
9155
9668
|
function fetchLines(rows) {
|
|
9156
9669
|
const byFetch = new Map()
|
|
9157
9670
|
rows.forEach((row, index) => {
|
|
9158
|
-
if (row.payload === undefined) return
|
|
9159
9671
|
const word = fetchWord(row.payload)
|
|
9160
9672
|
const list = byFetch.get(word) ?? []
|
|
9161
9673
|
list.push(index + 1)
|
|
@@ -9192,7 +9704,27 @@ function hiddenLine(hidden) {
|
|
|
9192
9704
|
const noun = hidden === 1 ? 'candidate is' : 'candidates are'
|
|
9193
9705
|
return `**${hidden} open ${noun} not shown.** They stay open and appear here, oldest first, as the ones above are settled.`
|
|
9194
9706
|
}
|
|
9195
|
-
function
|
|
9707
|
+
function unverifiedSection(ids, named) {
|
|
9708
|
+
if (ids.length === 0) return []
|
|
9709
|
+
const listed = ids.slice(0, named).map((id) => `\`${id}\``)
|
|
9710
|
+
const more = ids.length - listed.length
|
|
9711
|
+
const count =
|
|
9712
|
+
ids.length === 1
|
|
9713
|
+
? '1 open candidate has'
|
|
9714
|
+
: `${ids.length} open candidates have`
|
|
9715
|
+
const list =
|
|
9716
|
+
listed.length === 0
|
|
9717
|
+
? ''
|
|
9718
|
+
: ` Oldest first: ${listed.join(', ')}${more > 0 ? `, and ${more} more` : ''}.`
|
|
9719
|
+
return [
|
|
9720
|
+
UNVERIFIED_HEADING,
|
|
9721
|
+
'',
|
|
9722
|
+
`${count} no verified details for the current revision, so there is nothing to tick.${list}`,
|
|
9723
|
+
'',
|
|
9724
|
+
]
|
|
9725
|
+
}
|
|
9726
|
+
var UNVERIFIED_HEADING = '## No verified details'
|
|
9727
|
+
function assembleReport(input, shown, named) {
|
|
9196
9728
|
const rows = input.rows.slice(0, shown)
|
|
9197
9729
|
const ids = rows.map((row) => row.id)
|
|
9198
9730
|
const hash = manifestHash(ids)
|
|
@@ -9221,6 +9753,7 @@ function assemble(input, shown) {
|
|
|
9221
9753
|
for (const row of rows) out.push(row.block)
|
|
9222
9754
|
out.push(DECISIONS_END, '')
|
|
9223
9755
|
if (shown < open) out.push(hiddenLine(open - shown), '')
|
|
9756
|
+
out.push(...unverifiedSection(input.unverified, named))
|
|
9224
9757
|
return {
|
|
9225
9758
|
body: out.join(`
|
|
9226
9759
|
`),
|
|
@@ -9230,18 +9763,32 @@ function assemble(input, shown) {
|
|
|
9230
9763
|
fresh,
|
|
9231
9764
|
}
|
|
9232
9765
|
}
|
|
9233
|
-
function
|
|
9766
|
+
function rowsThatFit(input, named) {
|
|
9234
9767
|
const total = input.rows.length
|
|
9235
|
-
|
|
9768
|
+
const fits = (count) =>
|
|
9769
|
+
assembleReport(input, count, named).body.length <= REPORT_MAX_CHARS
|
|
9770
|
+
if (fits(total)) return total
|
|
9236
9771
|
let low = 0
|
|
9237
9772
|
let high = total - 1
|
|
9238
9773
|
while (low < high) {
|
|
9239
9774
|
const middle = Math.ceil((low + high) / 2)
|
|
9240
|
-
if (
|
|
9775
|
+
if (fits(middle)) low = middle
|
|
9241
9776
|
else high = middle - 1
|
|
9242
9777
|
}
|
|
9243
9778
|
return low
|
|
9244
9779
|
}
|
|
9780
|
+
function fitReport(input) {
|
|
9781
|
+
const wanted = Math.min(1, input.rows.length)
|
|
9782
|
+
for (
|
|
9783
|
+
let named = Math.min(MAX_UNVERIFIED_IDS, input.unverified.length);
|
|
9784
|
+
named > 0;
|
|
9785
|
+
named = Math.floor(named / 2)
|
|
9786
|
+
) {
|
|
9787
|
+
const shown = rowsThatFit(input, named)
|
|
9788
|
+
if (shown >= wanted) return { shown, named }
|
|
9789
|
+
}
|
|
9790
|
+
return { shown: rowsThatFit(input, 0), named: 0 }
|
|
9791
|
+
}
|
|
9245
9792
|
function openOldestFirst(entries) {
|
|
9246
9793
|
return entries
|
|
9247
9794
|
.filter((entry) => entry.status === 'candidate')
|
|
@@ -9255,7 +9802,11 @@ function proposed(run, open, request) {
|
|
|
9255
9802
|
const out = new Map()
|
|
9256
9803
|
for (const raw of run?.candidates ?? []) {
|
|
9257
9804
|
if (!isRecord4(raw) || !isCandidateId(raw.id) || !open.has(raw.id)) continue
|
|
9258
|
-
const text = payloadText(
|
|
9805
|
+
const text = payloadText(
|
|
9806
|
+
raw,
|
|
9807
|
+
run?.commitByRoot ?? new Map(),
|
|
9808
|
+
run?.repoByRoot ?? new Map(),
|
|
9809
|
+
)
|
|
9259
9810
|
if (text === undefined) continue
|
|
9260
9811
|
const target = typeof raw.target === 'string' ? raw.target : undefined
|
|
9261
9812
|
const repo = target === undefined ? undefined : run?.repoByRoot.get(target)
|
|
@@ -9265,6 +9816,7 @@ function proposed(run, open, request) {
|
|
|
9265
9816
|
...(repo === undefined ? {} : { repo }),
|
|
9266
9817
|
runId: request.runId,
|
|
9267
9818
|
attempt: request.attempt,
|
|
9819
|
+
...revisionField(raw.revision),
|
|
9268
9820
|
})
|
|
9269
9821
|
}
|
|
9270
9822
|
return out
|
|
@@ -9272,18 +9824,19 @@ function proposed(run, open, request) {
|
|
|
9272
9824
|
function mergedPayloads(open, stored, fresh) {
|
|
9273
9825
|
const out = new Map()
|
|
9274
9826
|
for (const entry of open) {
|
|
9827
|
+
const live = revisionOf(entry)
|
|
9275
9828
|
const earlier = stored.get(entry.id)
|
|
9276
|
-
const
|
|
9277
|
-
const
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9829
|
+
const proposedNow = fresh.get(entry.id)
|
|
9830
|
+
const chosen =
|
|
9831
|
+
[proposedNow, earlier].find((bundle) => bundle?.revision === live) ??
|
|
9832
|
+
proposedNow ??
|
|
9833
|
+
earlier
|
|
9834
|
+
if (chosen === undefined) continue
|
|
9835
|
+
const firstShown = chosen.firstShown ?? earlier?.firstShown
|
|
9836
|
+
out.set(entry.id, {
|
|
9837
|
+
...chosen,
|
|
9838
|
+
...(firstShown === undefined ? {} : { firstShown }),
|
|
9839
|
+
})
|
|
9287
9840
|
}
|
|
9288
9841
|
return out
|
|
9289
9842
|
}
|
|
@@ -9299,16 +9852,24 @@ function factLines(invocation, run) {
|
|
|
9299
9852
|
return lines
|
|
9300
9853
|
}
|
|
9301
9854
|
function rowsOf(open, payloads, date) {
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9855
|
+
const rows = []
|
|
9856
|
+
const unverified = []
|
|
9857
|
+
for (const entry of open) {
|
|
9858
|
+
const held = payloads.get(entry.id)
|
|
9859
|
+
const revision = revisionOf(entry)
|
|
9860
|
+
if (held === undefined || held.revision !== revision) {
|
|
9861
|
+
unverified.push(entry.id)
|
|
9862
|
+
continue
|
|
9863
|
+
}
|
|
9864
|
+
const isNew = (held.firstShown ?? date) === date
|
|
9865
|
+
rows.push({
|
|
9306
9866
|
id: entry.id,
|
|
9307
|
-
payload,
|
|
9867
|
+
payload: held,
|
|
9308
9868
|
isNew,
|
|
9309
|
-
block: blockOf(
|
|
9310
|
-
}
|
|
9311
|
-
}
|
|
9869
|
+
block: blockOf(rows.length + 1, entry, revision, held, isNew),
|
|
9870
|
+
})
|
|
9871
|
+
}
|
|
9872
|
+
return { rows, unverified }
|
|
9312
9873
|
}
|
|
9313
9874
|
function loadStores(root, recordState) {
|
|
9314
9875
|
const payloads = readPayloadStore(root)
|
|
@@ -9348,15 +9909,17 @@ function renderState(root, request, recordState) {
|
|
|
9348
9909
|
proposed(run, new Set(open.map((entry) => entry.id)), request),
|
|
9349
9910
|
)
|
|
9350
9911
|
const outcome = outcomeOf(invocation)
|
|
9912
|
+
const { rows, unverified } = rowsOf(open, payloads, request.date)
|
|
9351
9913
|
const input = {
|
|
9352
9914
|
outcome,
|
|
9353
9915
|
facts: factLines(invocation, run),
|
|
9354
9916
|
cacheRestored: request.cacheRestored,
|
|
9355
9917
|
stateUpdated: recordState,
|
|
9356
|
-
rows
|
|
9918
|
+
rows,
|
|
9919
|
+
unverified,
|
|
9357
9920
|
}
|
|
9358
|
-
const shown =
|
|
9359
|
-
const result =
|
|
9921
|
+
const { shown, named } = fitReport(input)
|
|
9922
|
+
const result = assembleReport(input, shown, named)
|
|
9360
9923
|
for (const id of result.ids) {
|
|
9361
9924
|
const payload = payloads.get(id)
|
|
9362
9925
|
if (payload !== undefined && payload.firstShown === undefined) {
|
|
@@ -9390,7 +9953,8 @@ function renderState(root, request, recordState) {
|
|
|
9390
9953
|
manifest: result.hash,
|
|
9391
9954
|
open: open.length,
|
|
9392
9955
|
shown,
|
|
9393
|
-
hidden:
|
|
9956
|
+
hidden: rows.length - shown,
|
|
9957
|
+
unverified: unverified.length,
|
|
9394
9958
|
fresh: result.fresh,
|
|
9395
9959
|
fetches: result.fetches,
|
|
9396
9960
|
outcome,
|
|
@@ -9439,10 +10003,10 @@ function tickedBoxes(boxes) {
|
|
|
9439
10003
|
const seen = new Set()
|
|
9440
10004
|
const out = []
|
|
9441
10005
|
for (const box of boxes) {
|
|
9442
|
-
const key = `${box.id}:${box.status}`
|
|
10006
|
+
const key = `${box.id}:${box.status}:${box.revision ?? ''}`
|
|
9443
10007
|
if (!box.ticked || seen.has(key)) continue
|
|
9444
10008
|
seen.add(key)
|
|
9445
|
-
out.push({ id: box.id, status: box.status })
|
|
10009
|
+
out.push({ id: box.id, status: box.status, revision: box.revision })
|
|
9446
10010
|
}
|
|
9447
10011
|
return out
|
|
9448
10012
|
}
|
|
@@ -9458,18 +10022,19 @@ function emptyApplied(section) {
|
|
|
9458
10022
|
function groupById(ticks) {
|
|
9459
10023
|
const byId = new Map()
|
|
9460
10024
|
for (const tick of ticks) {
|
|
9461
|
-
byId.set(tick.id, [...(byId.get(tick.id) ?? []), tick
|
|
10025
|
+
byId.set(tick.id, [...(byId.get(tick.id) ?? []), tick])
|
|
9462
10026
|
}
|
|
9463
10027
|
return byId
|
|
9464
10028
|
}
|
|
9465
|
-
function judge(id,
|
|
9466
|
-
const [
|
|
9467
|
-
if (
|
|
10029
|
+
function judge(id, ticks, manifest, entry, reason) {
|
|
10030
|
+
const [first] = ticks
|
|
10031
|
+
if (first === undefined) return
|
|
10032
|
+
const { status } = first
|
|
9468
10033
|
const skip = (why) => ({
|
|
9469
10034
|
kind: 'skip',
|
|
9470
10035
|
skipped: { id, status, reason: why },
|
|
9471
10036
|
})
|
|
9472
|
-
if (
|
|
10037
|
+
if (ticks.length > 1) {
|
|
9473
10038
|
return { kind: 'skip', skipped: { id, reason: 'conflict' } }
|
|
9474
10039
|
}
|
|
9475
10040
|
if (!manifest.ids.includes(id)) return skip('not-in-manifest')
|
|
@@ -9479,23 +10044,30 @@ function judge(id, statuses, manifest, entry, reason) {
|
|
|
9479
10044
|
unresolved: { id, status, reason: 'unknown-candidate' },
|
|
9480
10045
|
}
|
|
9481
10046
|
}
|
|
10047
|
+
if (first.revision === undefined) return skip('unversioned')
|
|
10048
|
+
const current = revisionOf(entry)
|
|
10049
|
+
if (first.revision !== current) return skip('stale')
|
|
9482
10050
|
if (entry.status === status && entry.reason === reason) {
|
|
9483
10051
|
return skip('already-recorded')
|
|
9484
10052
|
}
|
|
9485
10053
|
if (entry.status !== 'candidate') return skip('not-open')
|
|
9486
|
-
return { kind: 'record', tick: {
|
|
10054
|
+
return { kind: 'record', tick: { ...first, revision: current } }
|
|
9487
10055
|
}
|
|
9488
10056
|
function triage(ticks, manifest, entries, reason) {
|
|
9489
10057
|
const out = { record: [], skipped: [], unresolved: [] }
|
|
9490
10058
|
if (manifest === undefined) {
|
|
9491
10059
|
for (const tick of ticks) {
|
|
9492
|
-
out.unresolved.push({
|
|
10060
|
+
out.unresolved.push({
|
|
10061
|
+
id: tick.id,
|
|
10062
|
+
status: tick.status,
|
|
10063
|
+
reason: 'manifest-missing',
|
|
10064
|
+
})
|
|
9493
10065
|
}
|
|
9494
10066
|
return out
|
|
9495
10067
|
}
|
|
9496
|
-
for (const [id,
|
|
10068
|
+
for (const [id, group] of groupById(ticks)) {
|
|
9497
10069
|
const entry = entries.find((item) => item.id === id)
|
|
9498
|
-
const verdict = judge(id,
|
|
10070
|
+
const verdict = judge(id, group, manifest, entry, reason)
|
|
9499
10071
|
if (verdict?.kind === 'record') out.record.push(verdict.tick)
|
|
9500
10072
|
else if (verdict?.kind === 'skip') out.skipped.push(verdict.skipped)
|
|
9501
10073
|
else if (verdict?.kind === 'unresolved') {
|
|
@@ -9509,6 +10081,10 @@ function failureOf(reason) {
|
|
|
9509
10081
|
? reason
|
|
9510
10082
|
: 'write-failed'
|
|
9511
10083
|
}
|
|
10084
|
+
function skipReasonOf(reason) {
|
|
10085
|
+
if (reason === 'not-open') return 'not-open'
|
|
10086
|
+
return reason === 'stale-revision' ? 'stale' : undefined
|
|
10087
|
+
}
|
|
9512
10088
|
function applyTicks(root, request, options = {}) {
|
|
9513
10089
|
if (!Number.isSafeInteger(request.issue) || request.issue < 1) {
|
|
9514
10090
|
return { status: 'failed', reason: 'invalid-request', accepted: [] }
|
|
@@ -9535,20 +10111,27 @@ function applyTicks(root, request, options = {}) {
|
|
|
9535
10111
|
for (const tick of sorted.record) {
|
|
9536
10112
|
const decided = decideLedgerEntry(
|
|
9537
10113
|
root,
|
|
9538
|
-
{
|
|
10114
|
+
{
|
|
10115
|
+
id: tick.id,
|
|
10116
|
+
status: tick.status,
|
|
10117
|
+
reason,
|
|
10118
|
+
onlyIfOpen: true,
|
|
10119
|
+
revision: tick.revision,
|
|
10120
|
+
},
|
|
9539
10121
|
lockOptions(options),
|
|
9540
10122
|
)
|
|
9541
10123
|
if (decided.status === 'busy') {
|
|
9542
10124
|
return { status: 'busy', reason: decided.reason, accepted }
|
|
9543
10125
|
}
|
|
9544
|
-
if (decided.status === 'failed' && decided.reason === 'not-open') {
|
|
9545
|
-
skipped.push({ id: tick.id, status: tick.status, reason: 'not-open' })
|
|
9546
|
-
continue
|
|
9547
|
-
}
|
|
9548
10126
|
if (decided.status === 'failed') {
|
|
9549
|
-
|
|
10127
|
+
const why = skipReasonOf(decided.reason)
|
|
10128
|
+
if (why === undefined) {
|
|
10129
|
+
return { status: 'failed', reason: failureOf(decided.reason), accepted }
|
|
10130
|
+
}
|
|
10131
|
+
skipped.push({ id: tick.id, status: tick.status, reason: why })
|
|
10132
|
+
continue
|
|
9550
10133
|
}
|
|
9551
|
-
accepted.push(tick)
|
|
10134
|
+
accepted.push({ id: tick.id, status: tick.status })
|
|
9552
10135
|
}
|
|
9553
10136
|
return {
|
|
9554
10137
|
status: 'applied',
|
|
@@ -9570,7 +10153,7 @@ var MAX_ROOT_LENGTH = 4096
|
|
|
9570
10153
|
var RUN_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
|
|
9571
10154
|
var PROJECT_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/
|
|
9572
10155
|
var REPO_SLUG2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
|
|
9573
|
-
var
|
|
10156
|
+
var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
9574
10157
|
var CANDIDATE_ID2 = /^[0-9a-f]{64}$/
|
|
9575
10158
|
var CONTROL2 = /[\p{Cc}\p{Cf}]/u
|
|
9576
10159
|
var CORPUS_PATH = /^docs\/(?:solutions|plans|brainstorms)\//
|
|
@@ -9601,7 +10184,7 @@ function parseProject(value) {
|
|
|
9601
10184
|
}
|
|
9602
10185
|
if (
|
|
9603
10186
|
commit !== undefined &&
|
|
9604
|
-
!(typeof commit === 'string' &&
|
|
10187
|
+
!(typeof commit === 'string' && OBJECT_ID3.test(commit))
|
|
9605
10188
|
) {
|
|
9606
10189
|
return
|
|
9607
10190
|
}
|
|
@@ -9724,6 +10307,10 @@ var REFUSAL_TEXT = Object.freeze({
|
|
|
9724
10307
|
'file-vanished': 'a cited file is gone from the local checkout',
|
|
9725
10308
|
'check-failed': 'the candidate failed a check against the local files',
|
|
9726
10309
|
})
|
|
10310
|
+
function evidenceRemedy(repo) {
|
|
10311
|
+
const named = repo === undefined ? 'that repository' : repo
|
|
10312
|
+
return `allow-list a checkout of ${named} (at the pinned ref for a dependency), then import again`
|
|
10313
|
+
}
|
|
9727
10314
|
function fileRefs(value, max) {
|
|
9728
10315
|
if (value === undefined) return []
|
|
9729
10316
|
if (!Array.isArray(value) || value.length > max) return
|
|
@@ -9791,14 +10378,30 @@ function shapeOf(raw) {
|
|
|
9791
10378
|
title: raw.title,
|
|
9792
10379
|
summary: raw.summary,
|
|
9793
10380
|
nextStep: raw.nextStep,
|
|
10381
|
+
reason: raw.reason,
|
|
9794
10382
|
overlapCheck: raw.overlapCheck,
|
|
9795
10383
|
sources,
|
|
9796
10384
|
counterevidence,
|
|
9797
10385
|
targetEvidence,
|
|
9798
10386
|
}
|
|
9799
10387
|
}
|
|
10388
|
+
function mismatchIdentity(shape) {
|
|
10389
|
+
const [claim] = shape.sources
|
|
10390
|
+
if (
|
|
10391
|
+
shape.kind !== 'code-mismatch' ||
|
|
10392
|
+
!isMismatchReason(shape.reason) ||
|
|
10393
|
+
claim === undefined
|
|
10394
|
+
) {
|
|
10395
|
+
return
|
|
10396
|
+
}
|
|
10397
|
+
return {
|
|
10398
|
+
mismatchReason: shape.reason,
|
|
10399
|
+
claim: claimFingerprint(claim.excerpt),
|
|
10400
|
+
}
|
|
10401
|
+
}
|
|
9800
10402
|
function recordedIdentity(shape) {
|
|
9801
10403
|
return candidateIdentity({
|
|
10404
|
+
...mismatchIdentity(shape),
|
|
9802
10405
|
kind: shape.kind,
|
|
9803
10406
|
target: shape.target,
|
|
9804
10407
|
ruleId: shape.ruleId,
|
|
@@ -9843,6 +10446,13 @@ function createLandings(projects, locals, factsFor) {
|
|
|
9843
10446
|
},
|
|
9844
10447
|
}
|
|
9845
10448
|
}
|
|
10449
|
+
function unmappedRemedy(shape, root, reason, repo) {
|
|
10450
|
+
const evidenceProject =
|
|
10451
|
+
shape.kind === 'code-mismatch' &&
|
|
10452
|
+
reason === 'repo-not-allowed' &&
|
|
10453
|
+
shape.counterevidence.some((source) => source.project === root)
|
|
10454
|
+
return evidenceProject ? { remedy: evidenceRemedy(repo) } : {}
|
|
10455
|
+
}
|
|
9846
10456
|
function land(shape, landings) {
|
|
9847
10457
|
const roots = new Set([
|
|
9848
10458
|
shape.target,
|
|
@@ -9860,6 +10470,7 @@ function land(shape, landings) {
|
|
|
9860
10470
|
return refuse(mapping.reason, {
|
|
9861
10471
|
...(mapping.keys === undefined ? {} : { keys: mapping.keys }),
|
|
9862
10472
|
...(project.repo === undefined ? {} : { repo: project.repo }),
|
|
10473
|
+
...unmappedRemedy(shape, root, mapping.reason, project.repo),
|
|
9863
10474
|
})
|
|
9864
10475
|
}
|
|
9865
10476
|
const facts = landings.factsOf(mapping.local)
|
|
@@ -9930,6 +10541,11 @@ function localRaw(shape, ruleId, landed) {
|
|
|
9930
10541
|
fingerprint: ref.fingerprint,
|
|
9931
10542
|
excerpt: ref.excerpt,
|
|
9932
10543
|
})
|
|
10544
|
+
const evidence = (ref) => ({
|
|
10545
|
+
...source(ref),
|
|
10546
|
+
...(ref.rest.start === undefined ? {} : { start: ref.rest.start }),
|
|
10547
|
+
...(ref.rest.end === undefined ? {} : { end: ref.rest.end }),
|
|
10548
|
+
})
|
|
9933
10549
|
return {
|
|
9934
10550
|
kind: shape.kind,
|
|
9935
10551
|
ruleId,
|
|
@@ -9937,6 +10553,7 @@ function localRaw(shape, ruleId, landed) {
|
|
|
9937
10553
|
title: shape.title,
|
|
9938
10554
|
summary: shape.summary,
|
|
9939
10555
|
nextStep: shape.nextStep,
|
|
10556
|
+
...(shape.reason === undefined ? {} : { reason: shape.reason }),
|
|
9940
10557
|
overlapCheck: shape.overlapCheck,
|
|
9941
10558
|
sources: shape.sources.map(source),
|
|
9942
10559
|
targetEvidence: shape.targetEvidence.map((item) => ({
|
|
@@ -9947,7 +10564,7 @@ function localRaw(shape, ruleId, landed) {
|
|
|
9947
10564
|
fingerprint: item.fingerprint,
|
|
9948
10565
|
excerpt: item.excerpt,
|
|
9949
10566
|
})),
|
|
9950
|
-
counterevidence: shape.counterevidence.map(
|
|
10567
|
+
counterevidence: shape.counterevidence.map(evidence),
|
|
9951
10568
|
}
|
|
9952
10569
|
}
|
|
9953
10570
|
function contextOf(landed) {
|
|
@@ -9994,6 +10611,9 @@ function verifyOne(raw, landings, seen) {
|
|
|
9994
10611
|
return {
|
|
9995
10612
|
recordedId: shape.id,
|
|
9996
10613
|
candidate: checked.candidate,
|
|
10614
|
+
evidenceHeads: shape.counterevidence.map(
|
|
10615
|
+
(ref) => landings.projectOf(ref.project)?.commit,
|
|
10616
|
+
),
|
|
9997
10617
|
record,
|
|
9998
10618
|
id: candidateIdentity(record),
|
|
9999
10619
|
}
|
|
@@ -10095,9 +10715,10 @@ function refusalLines(refused) {
|
|
|
10095
10715
|
item.keys === undefined
|
|
10096
10716
|
? ''
|
|
10097
10717
|
: ` Local project keys: ${item.keys.map(inline).join(', ')}.`
|
|
10718
|
+
const remedy = item.remedy === undefined ? '' : ` Fix: ${item.remedy}.`
|
|
10098
10719
|
out.push(
|
|
10099
10720
|
quote(item.title),
|
|
10100
|
-
` ${item.reason}${detail}: ${item.reasonText}.${where}${keys}`,
|
|
10721
|
+
` ${item.reason}${detail}: ${item.reasonText}.${where}${keys}${remedy}`,
|
|
10101
10722
|
)
|
|
10102
10723
|
}
|
|
10103
10724
|
return out
|
|
@@ -10248,7 +10869,7 @@ function originUrl(config) {
|
|
|
10248
10869
|
}
|
|
10249
10870
|
return
|
|
10250
10871
|
}
|
|
10251
|
-
var
|
|
10872
|
+
var OBJECT_ID4 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
10252
10873
|
var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
|
|
10253
10874
|
function readGitText(mainRoot, rel, maxBytes) {
|
|
10254
10875
|
const read = readContainedFile(mainRoot, rel, { maxBytes })
|
|
@@ -10282,7 +10903,7 @@ function packedRef(packed, ref) {
|
|
|
10282
10903
|
const line = raw.trim()
|
|
10283
10904
|
if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
|
|
10284
10905
|
const [id, name, ...rest] = line.split(/\s+/)
|
|
10285
|
-
if (rest.length === 0 && name === ref &&
|
|
10906
|
+
if (rest.length === 0 && name === ref && OBJECT_ID4.test(id ?? ''))
|
|
10286
10907
|
return id
|
|
10287
10908
|
}
|
|
10288
10909
|
return
|
|
@@ -10291,12 +10912,12 @@ function headCommit(mainRoot) {
|
|
|
10291
10912
|
const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
|
|
10292
10913
|
if (head === undefined) return
|
|
10293
10914
|
const line = firstLine2(head)
|
|
10294
|
-
if (
|
|
10915
|
+
if (OBJECT_ID4.test(line)) return line
|
|
10295
10916
|
const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
|
|
10296
10917
|
if (symbolic === undefined || !safeRefName(symbolic)) return
|
|
10297
10918
|
const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
|
|
10298
10919
|
const looseId = loose === undefined ? '' : firstLine2(loose)
|
|
10299
|
-
if (
|
|
10920
|
+
if (OBJECT_ID4.test(looseId)) return looseId
|
|
10300
10921
|
const packed = readGitText(
|
|
10301
10922
|
mainRoot,
|
|
10302
10923
|
'.git/packed-refs',
|
|
@@ -10853,6 +11474,8 @@ function scanProject(entry, root, deps, limits) {
|
|
|
10853
11474
|
citationsChecked: report.citations.length,
|
|
10854
11475
|
citationsTruncated: report.truncated,
|
|
10855
11476
|
truncated: inventory.truncated.files || inventory.truncated.hashCap,
|
|
11477
|
+
skipped: inventory.skipped.map((file) => file.path),
|
|
11478
|
+
skipsUnnamed: inventory.skippedCount > inventory.skipped.length,
|
|
10856
11479
|
inventory: inventory.files.map((file) => ({
|
|
10857
11480
|
path: file.path,
|
|
10858
11481
|
role: file.role,
|
|
@@ -11099,6 +11722,7 @@ function indexRun(setup, deps) {
|
|
|
11099
11722
|
id: rule.id,
|
|
11100
11723
|
sha256: rule.sha256,
|
|
11101
11724
|
project: projectKey(rule.project),
|
|
11725
|
+
path: rule.path,
|
|
11102
11726
|
})),
|
|
11103
11727
|
coverageScope,
|
|
11104
11728
|
offer: {
|
|
@@ -11347,8 +11971,29 @@ function standingOf(outcome) {
|
|
|
11347
11971
|
}
|
|
11348
11972
|
return 'skip'
|
|
11349
11973
|
}
|
|
11350
|
-
function
|
|
11351
|
-
const
|
|
11974
|
+
function evidenceLookup(snapshot) {
|
|
11975
|
+
const projects = new Map(
|
|
11976
|
+
snapshot.projects.map((project) => [
|
|
11977
|
+
project.key,
|
|
11978
|
+
{
|
|
11979
|
+
complete: !project.truncated && !project.skipsUnnamed,
|
|
11980
|
+
skipped: new Set(project.skipped),
|
|
11981
|
+
files: new Map(project.inventory.map((f) => [f.path, f.sha256])),
|
|
11982
|
+
},
|
|
11983
|
+
]),
|
|
11984
|
+
)
|
|
11985
|
+
return (key, rel) => {
|
|
11986
|
+
const project = projects.get(key)
|
|
11987
|
+
if (project === undefined) return { status: 'unread' }
|
|
11988
|
+
const fingerprint = project.files.get(rel)
|
|
11989
|
+
if (fingerprint !== undefined) return { status: 'present', fingerprint }
|
|
11990
|
+
if (project.skipped.has(rel)) return { status: 'unread' }
|
|
11991
|
+
return project.complete ? { status: 'gone' } : { status: 'unread' }
|
|
11992
|
+
}
|
|
11993
|
+
}
|
|
11994
|
+
function classifyAgainstLedger(candidate, record, input, result) {
|
|
11995
|
+
const { ledger } = input
|
|
11996
|
+
const outcome = classifyCandidate(ledger, record, input.evidence)
|
|
11352
11997
|
const standing = standingOf(outcome)
|
|
11353
11998
|
if (standing === 'skip') {
|
|
11354
11999
|
if (outcome.standing === 'unresolved') result.unresolved++
|
|
@@ -11372,10 +12017,11 @@ function classifyAgainstLedger(candidate, record, ledger, result) {
|
|
|
11372
12017
|
: { refreshPointer: standing.refreshPointer }),
|
|
11373
12018
|
possibleMatches,
|
|
11374
12019
|
candidate,
|
|
12020
|
+
revision: revisionOfCandidate(record),
|
|
11375
12021
|
})
|
|
11376
12022
|
}
|
|
11377
12023
|
function reopensForChangedSources(record, input) {
|
|
11378
|
-
const outcome = classifyCandidate(input.ledger, record)
|
|
12024
|
+
const outcome = classifyCandidate(input.ledger, record, input.evidence)
|
|
11379
12025
|
return outcome.standing === 'reopened' && outcome.reason === 'sources changed'
|
|
11380
12026
|
}
|
|
11381
12027
|
function holdBack(raw, input, result) {
|
|
@@ -11406,7 +12052,10 @@ function classifyOne(raw, family, input, seen, result) {
|
|
|
11406
12052
|
return
|
|
11407
12053
|
}
|
|
11408
12054
|
seen.add(identity)
|
|
11409
|
-
const recorded =
|
|
12055
|
+
const recorded =
|
|
12056
|
+
check.candidate.kind === 'code-mismatch'
|
|
12057
|
+
? undefined
|
|
12058
|
+
: findRecorded(check.candidate, input.snapshot.provenance)
|
|
11410
12059
|
if (recorded !== undefined && !reopensForChangedSources(record, input)) {
|
|
11411
12060
|
result.recorded.push({
|
|
11412
12061
|
pointer: recorded.pointer,
|
|
@@ -11414,7 +12063,7 @@ function classifyOne(raw, family, input, seen, result) {
|
|
|
11414
12063
|
})
|
|
11415
12064
|
return
|
|
11416
12065
|
}
|
|
11417
|
-
classifyAgainstLedger(check.candidate, record, input
|
|
12066
|
+
classifyAgainstLedger(check.candidate, record, input, result)
|
|
11418
12067
|
}
|
|
11419
12068
|
function classifyBatches(batches, input, limits) {
|
|
11420
12069
|
const result = {
|
|
@@ -11460,8 +12109,13 @@ function classifyBatches(batches, input, limits) {
|
|
|
11460
12109
|
var MAX_UNREAD_LINES = 50
|
|
11461
12110
|
function coverageLines(coverage, snapshot, classified) {
|
|
11462
12111
|
const lines = []
|
|
12112
|
+
const learningUnread = new Set(coverage.learningUnreadRuleIds)
|
|
11463
12113
|
for (const id of coverage.uncoveredRuleIds.slice(0, MAX_UNREAD_LINES)) {
|
|
11464
|
-
lines.push(
|
|
12114
|
+
lines.push(
|
|
12115
|
+
learningUnread.has(id)
|
|
12116
|
+
? `rule ${id} was not covered: its learning was not among the files the family read`
|
|
12117
|
+
: `rule ${id} was not covered by a complete family`,
|
|
12118
|
+
)
|
|
11465
12119
|
}
|
|
11466
12120
|
if (coverage.uncoveredRuleIds.length > MAX_UNREAD_LINES) {
|
|
11467
12121
|
lines.push(
|
|
@@ -11510,6 +12164,7 @@ function validateResponse(runId, state, classified) {
|
|
|
11510
12164
|
...(item.refreshPointer === undefined
|
|
11511
12165
|
? {}
|
|
11512
12166
|
: { refreshPointer: item.refreshPointer }),
|
|
12167
|
+
...(item.revision === undefined ? {} : { revision: item.revision }),
|
|
11513
12168
|
})),
|
|
11514
12169
|
recorded: classified.recorded.map((item) => ({
|
|
11515
12170
|
pointer: item.pointer,
|
|
@@ -11556,13 +12211,35 @@ function runValidation(snapshot, workDir, batchesRead, ledger, deps) {
|
|
|
11556
12211
|
}
|
|
11557
12212
|
const classified = classifyBatches(
|
|
11558
12213
|
batches,
|
|
11559
|
-
{
|
|
12214
|
+
{
|
|
12215
|
+
ctx: contextFrom(snapshot),
|
|
12216
|
+
snapshot,
|
|
12217
|
+
ledger,
|
|
12218
|
+
evidence: evidenceLookup(snapshot),
|
|
12219
|
+
},
|
|
11560
12220
|
limits,
|
|
11561
12221
|
)
|
|
11562
12222
|
const coverage = checkCoverage({
|
|
11563
12223
|
ruleIds: snapshot.offer.offered,
|
|
11564
|
-
projects: snapshot.projects
|
|
12224
|
+
projects: snapshot.projects
|
|
12225
|
+
.filter((project) =>
|
|
12226
|
+
project.inventory.some((file) => file.role === 'learning'),
|
|
12227
|
+
)
|
|
12228
|
+
.map((project) => project.root),
|
|
11565
12229
|
batches,
|
|
12230
|
+
learningPaths: new Map(
|
|
12231
|
+
snapshot.ruleVersions.flatMap((rule) =>
|
|
12232
|
+
rule.path === undefined ? [] : [[rule.id, rule.path]],
|
|
12233
|
+
),
|
|
12234
|
+
),
|
|
12235
|
+
learningProjects: new Map(
|
|
12236
|
+
snapshot.ruleVersions.flatMap((rule) => {
|
|
12237
|
+
const root = snapshot.projects.find(
|
|
12238
|
+
(project) => project.key === rule.project,
|
|
12239
|
+
)?.root
|
|
12240
|
+
return root === undefined ? [] : [[rule.id, root]]
|
|
12241
|
+
}),
|
|
12242
|
+
),
|
|
11566
12243
|
})
|
|
11567
12244
|
const uncovered = new Set(coverage.uncoveredRuleIds)
|
|
11568
12245
|
const heldBackRuleIds = snapshot.offer.offered.filter(
|
|
@@ -11700,10 +12377,14 @@ function buildCandidateBlock(accepted) {
|
|
|
11700
12377
|
title: item.candidate.title,
|
|
11701
12378
|
summary: item.candidate.summary,
|
|
11702
12379
|
nextStep: item.candidate.nextStep,
|
|
12380
|
+
...(item.candidate.reason === undefined
|
|
12381
|
+
? {}
|
|
12382
|
+
: { reason: item.candidate.reason }),
|
|
11703
12383
|
overlapCheck: item.candidate.overlapCheck,
|
|
11704
12384
|
sources: item.candidate.sources,
|
|
11705
12385
|
targetEvidence: item.candidate.targetEvidence,
|
|
11706
12386
|
counterevidence: item.candidate.counterevidence,
|
|
12387
|
+
...(item.revision === undefined ? {} : { revision: item.revision }),
|
|
11707
12388
|
})),
|
|
11708
12389
|
}
|
|
11709
12390
|
}
|
|
@@ -11716,6 +12397,7 @@ function digestModel(snapshot, state, outcome, degradeReasons) {
|
|
|
11716
12397
|
: { refreshPointer: item.refreshPointer }),
|
|
11717
12398
|
possibleMatches: item.possibleMatches,
|
|
11718
12399
|
candidate: item.candidate,
|
|
12400
|
+
...(item.revision === undefined ? {} : { revision: item.revision }),
|
|
11719
12401
|
}))
|
|
11720
12402
|
const projects = snapshot.projects.map((project) => ({
|
|
11721
12403
|
name: project.name,
|
|
@@ -11723,6 +12405,10 @@ function digestModel(snapshot, state, outcome, degradeReasons) {
|
|
|
11723
12405
|
files: project.files,
|
|
11724
12406
|
citationsUnsupported: project.citationsUnsupported,
|
|
11725
12407
|
truncated: project.truncated,
|
|
12408
|
+
...(project.commit === undefined ? {} : { commit: project.commit }),
|
|
12409
|
+
...(project.inventory.some((file) => file.role === 'learning')
|
|
12410
|
+
? {}
|
|
12411
|
+
: { evidenceOnly: true }),
|
|
11726
12412
|
}))
|
|
11727
12413
|
return {
|
|
11728
12414
|
runId: snapshot.runId,
|
|
@@ -11852,6 +12538,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
|
|
|
11852
12538
|
candidates: state.accepted.map((item) =>
|
|
11853
12539
|
toCandidateRecord(item.candidate),
|
|
11854
12540
|
),
|
|
12541
|
+
evidence: evidenceLookup(snapshot),
|
|
11855
12542
|
coverage: {
|
|
11856
12543
|
runId: snapshot.runId,
|
|
11857
12544
|
indexed: snapshot.ruleVersions.map((rule) => ({
|
|
@@ -12000,19 +12687,24 @@ function publishRunOp(request, deps, ciMarker) {
|
|
|
12000
12687
|
)
|
|
12001
12688
|
}
|
|
12002
12689
|
}
|
|
12690
|
+
function isRevision2(value) {
|
|
12691
|
+
return typeof value === 'string' && /^[0-9a-f]{12}$/.test(value)
|
|
12692
|
+
}
|
|
12003
12693
|
function parseDecision(request) {
|
|
12004
12694
|
if (!isRecord6(request)) return
|
|
12005
|
-
const { id, status, reason, destination } = request
|
|
12695
|
+
const { id, status, reason, destination, revision } = request
|
|
12006
12696
|
if (typeof id !== 'string' || typeof reason !== 'string') return
|
|
12007
12697
|
if (status !== 'promoted' && status !== 'rejected') return
|
|
12008
12698
|
if (destination !== undefined && typeof destination !== 'string') {
|
|
12009
12699
|
return
|
|
12010
12700
|
}
|
|
12701
|
+
if (revision !== undefined && !isRevision2(revision)) return
|
|
12011
12702
|
return {
|
|
12012
12703
|
id,
|
|
12013
12704
|
status,
|
|
12014
12705
|
reason,
|
|
12015
12706
|
...(destination === undefined ? {} : { destination }),
|
|
12707
|
+
...(revision === undefined ? {} : { revision }),
|
|
12016
12708
|
}
|
|
12017
12709
|
}
|
|
12018
12710
|
function decisionResult(result) {
|
|
@@ -12036,6 +12728,11 @@ function decisionResult(result) {
|
|
|
12036
12728
|
body: { ok: false, op: 'decide', outcome: 'busy', reason: result.reason },
|
|
12037
12729
|
}
|
|
12038
12730
|
}
|
|
12731
|
+
if (result.reason === 'stale-revision') {
|
|
12732
|
+
return failure2('decide', result.reason, {
|
|
12733
|
+
hint: 'The candidate has other evidence than the digest you decided from. Nothing was recorded. Read the current digest or run again, then decide against the revision it shows.',
|
|
12734
|
+
})
|
|
12735
|
+
}
|
|
12039
12736
|
return failure2('decide', result.reason)
|
|
12040
12737
|
}
|
|
12041
12738
|
function decide(request, deps) {
|
|
@@ -12161,6 +12858,12 @@ function ledgerShow(request, deps) {
|
|
|
12161
12858
|
? {}
|
|
12162
12859
|
: { destination: entry.destination }),
|
|
12163
12860
|
...(entry.reopened === undefined ? {} : { reopened: entry.reopened }),
|
|
12861
|
+
...(entry.reopenedFor === undefined
|
|
12862
|
+
? {}
|
|
12863
|
+
: { reopenedFor: entry.reopenedFor }),
|
|
12864
|
+
...(entry.mismatchReason === undefined
|
|
12865
|
+
? {}
|
|
12866
|
+
: { mismatchReason: entry.mismatchReason }),
|
|
12164
12867
|
sources: entry.sources.map((source) => ({
|
|
12165
12868
|
role: source.role,
|
|
12166
12869
|
path: source.path,
|
|
@@ -12278,6 +12981,7 @@ function evidenceOf(candidate) {
|
|
|
12278
12981
|
candidate.sources,
|
|
12279
12982
|
candidate.targetEvidence,
|
|
12280
12983
|
candidate.counterevidence,
|
|
12984
|
+
candidate.reason ?? null,
|
|
12281
12985
|
])
|
|
12282
12986
|
}
|
|
12283
12987
|
function keptImportRuns(root, runs) {
|
|
@@ -12307,6 +13011,9 @@ function freshOf(item, standing, extra = {}) {
|
|
|
12307
13011
|
: { refreshPointer: extra.refreshPointer }),
|
|
12308
13012
|
possibleMatches: extra.possibleMatches ?? [],
|
|
12309
13013
|
candidate: item.candidate,
|
|
13014
|
+
...(item.evidenceHeads === undefined
|
|
13015
|
+
? {}
|
|
13016
|
+
: { evidenceHeads: item.evidenceHeads }),
|
|
12310
13017
|
record: item.record,
|
|
12311
13018
|
}
|
|
12312
13019
|
}
|
|
@@ -12325,8 +13032,22 @@ function skippedOf(item, entry) {
|
|
|
12325
13032
|
: { refreshPointer: entry.destination }),
|
|
12326
13033
|
}
|
|
12327
13034
|
}
|
|
13035
|
+
function importedEvidence(item) {
|
|
13036
|
+
const cited = new Map(
|
|
13037
|
+
(item.record.evidence ?? []).map((ref) => [
|
|
13038
|
+
`${ref.project}\x00${ref.path}`,
|
|
13039
|
+
ref.fingerprint,
|
|
13040
|
+
]),
|
|
13041
|
+
)
|
|
13042
|
+
return (project, rel) => {
|
|
13043
|
+
const fingerprint = cited.get(`${project}\x00${rel}`)
|
|
13044
|
+
return fingerprint === undefined
|
|
13045
|
+
? { status: 'unread' }
|
|
13046
|
+
: { status: 'present', fingerprint }
|
|
13047
|
+
}
|
|
13048
|
+
}
|
|
12328
13049
|
function placeOne(item, ledger, heldIn) {
|
|
12329
|
-
const outcome = classifyCandidate(ledger, item.record)
|
|
13050
|
+
const outcome = classifyCandidate(ledger, item.record, importedEvidence(item))
|
|
12330
13051
|
if (outcome.standing === 'new') {
|
|
12331
13052
|
return {
|
|
12332
13053
|
placed: freshOf(item, 'new', {
|
|
@@ -12350,12 +13071,13 @@ function placeOne(item, ledger, heldIn) {
|
|
|
12350
13071
|
),
|
|
12351
13072
|
}
|
|
12352
13073
|
}
|
|
12353
|
-
const
|
|
12354
|
-
|
|
12355
|
-
ledger.entries.find((known) => known.id === item.id),
|
|
12356
|
-
)
|
|
13074
|
+
const entry = ledger.entries.find((known) => known.id === item.id)
|
|
13075
|
+
const skipped = skippedOf(item, entry)
|
|
12357
13076
|
if (skipped !== undefined) return { skipped }
|
|
12358
|
-
const held =
|
|
13077
|
+
const held =
|
|
13078
|
+
entry !== undefined && !recordsEvidenceOf(entry, item.record)
|
|
13079
|
+
? undefined
|
|
13080
|
+
: heldIn(item)
|
|
12359
13081
|
return {
|
|
12360
13082
|
placed:
|
|
12361
13083
|
held === undefined
|
|
@@ -12530,6 +13252,9 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
|
|
|
12530
13252
|
view.importRuns,
|
|
12531
13253
|
)
|
|
12532
13254
|
if (placement.fresh.length === 0) return { publish: false }
|
|
13255
|
+
const lookups = new Map(
|
|
13256
|
+
placement.fresh.map((item) => [item.record, importedEvidence(item)]),
|
|
13257
|
+
)
|
|
12533
13258
|
const runId = newImportRunId(now())
|
|
12534
13259
|
localRunId = runId
|
|
12535
13260
|
const createdAt = new Date(now()).toISOString()
|
|
@@ -12551,6 +13276,7 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
|
|
|
12551
13276
|
runId,
|
|
12552
13277
|
files: filesOf(model),
|
|
12553
13278
|
candidates: placement.fresh.map((item) => item.record),
|
|
13279
|
+
evidenceFor: (candidate) => lookups.get(candidate),
|
|
12554
13280
|
onLedgerWriteFailed: () =>
|
|
12555
13281
|
filesOf({
|
|
12556
13282
|
...model,
|
|
@@ -12708,6 +13434,7 @@ function renderReportOp(request, deps) {
|
|
|
12708
13434
|
open: result.open,
|
|
12709
13435
|
shown: result.shown,
|
|
12710
13436
|
hidden: result.hidden,
|
|
13437
|
+
unverified: result.unverified,
|
|
12711
13438
|
fresh: result.fresh,
|
|
12712
13439
|
fetches: result.fetches,
|
|
12713
13440
|
outcome: result.outcome,
|