@fro.bot/systematic 3.35.3 → 3.37.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/HARNESSES.md +2 -1
- package/agents/research/connections-researcher.md +21 -12
- package/dist/ce-connect-helper.d.ts +1 -1
- package/dist/lib/connect-ci.d.ts +139 -9
- package/dist/lib/connect-helper-core.d.ts +62 -7
- package/dist/lib/connect-import.d.ts +10 -0
- package/dist/lib/connect-provenance.d.ts +34 -0
- package/dist/lib/connect-repo-identity.d.ts +8 -0
- package/dist/lib/connect-state.d.ts +99 -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 +11 -8
- package/skills/ce-connect/references/candidate-contract.md +13 -8
- package/skills/ce-connect/references/fetch-and-import.md +162 -20
- package/skills/ce-connect/references/headless-and-outcomes.md +4 -3
- package/skills/ce-connect/scripts/connect.mjs +1162 -285
|
@@ -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: 0682b8db8f1a46b9df0605a1ba5d6962ce4eafd935f828fe3acff769cebc33e6
|
|
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}`
|
|
@@ -7344,6 +7556,150 @@ function selectionLine(selection) {
|
|
|
7344
7556
|
}
|
|
7345
7557
|
}
|
|
7346
7558
|
|
|
7559
|
+
// src/lib/connect-repo-identity.ts
|
|
7560
|
+
var MAX_CONFIG_BYTES = 1024 * 1024
|
|
7561
|
+
var MAX_HEAD_BYTES = 4096
|
|
7562
|
+
var MAX_REF_BYTES = 4096
|
|
7563
|
+
var MAX_PACKED_REFS_BYTES = 8 * 1024 * 1024
|
|
7564
|
+
var OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/
|
|
7565
|
+
var REPO = /^[A-Za-z0-9._-]{1,100}$/
|
|
7566
|
+
function isGithubOwnerRepo(value) {
|
|
7567
|
+
const parts = value.split('/')
|
|
7568
|
+
const [owner, name] = parts
|
|
7569
|
+
return (
|
|
7570
|
+
parts.length === 2 &&
|
|
7571
|
+
owner !== undefined &&
|
|
7572
|
+
name !== undefined &&
|
|
7573
|
+
OWNER.test(owner) &&
|
|
7574
|
+
REPO.test(name) &&
|
|
7575
|
+
name !== '.' &&
|
|
7576
|
+
name !== '..'
|
|
7577
|
+
)
|
|
7578
|
+
}
|
|
7579
|
+
var HTTPS_FORM = /^https:\/\/(?:[^/@\s]*@)?github\.com\/(\S+)$/i
|
|
7580
|
+
var SSH_URL_FORM = /^ssh:\/\/(?:[A-Za-z0-9._-]+@)?github\.com\/(\S+)$/i
|
|
7581
|
+
var SCP_FORM = /^(?:[A-Za-z0-9._-]+@)?github\.com:(\S+)$/i
|
|
7582
|
+
function ownerAndRepo(pathPart) {
|
|
7583
|
+
const segments = pathPart.replace(/\/+$/, '').split('/')
|
|
7584
|
+
if (segments.length !== 2) return
|
|
7585
|
+
const [owner = '', named = ''] = segments
|
|
7586
|
+
const repo = named.endsWith('.git') ? named.slice(0, -'.git'.length) : named
|
|
7587
|
+
const slug = `${owner}/${repo}`
|
|
7588
|
+
return isGithubOwnerRepo(slug) ? slug.toLowerCase() : undefined
|
|
7589
|
+
}
|
|
7590
|
+
function normalizeGithubRemote(url) {
|
|
7591
|
+
const match =
|
|
7592
|
+
HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
|
|
7593
|
+
const rest = match?.[1]
|
|
7594
|
+
return rest === undefined ? undefined : ownerAndRepo(rest)
|
|
7595
|
+
}
|
|
7596
|
+
function configValue(raw) {
|
|
7597
|
+
let out = ''
|
|
7598
|
+
let quoted = false
|
|
7599
|
+
for (const ch of raw.trim()) {
|
|
7600
|
+
if (ch === '"') {
|
|
7601
|
+
quoted = !quoted
|
|
7602
|
+
continue
|
|
7603
|
+
}
|
|
7604
|
+
if (!quoted && (ch === '#' || ch === ';')) break
|
|
7605
|
+
out += ch
|
|
7606
|
+
}
|
|
7607
|
+
return out.trim()
|
|
7608
|
+
}
|
|
7609
|
+
function isOriginSection(header) {
|
|
7610
|
+
const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
|
|
7611
|
+
return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
|
|
7612
|
+
}
|
|
7613
|
+
function originUrl(config) {
|
|
7614
|
+
let inOrigin = false
|
|
7615
|
+
for (const raw of config.split(`
|
|
7616
|
+
`)) {
|
|
7617
|
+
let line = raw.trim()
|
|
7618
|
+
if (line.startsWith('[')) {
|
|
7619
|
+
const end = line.indexOf(']')
|
|
7620
|
+
if (end === -1) {
|
|
7621
|
+
inOrigin = false
|
|
7622
|
+
continue
|
|
7623
|
+
}
|
|
7624
|
+
inOrigin = isOriginSection(line.slice(1, end))
|
|
7625
|
+
line = line.slice(end + 1).trim()
|
|
7626
|
+
}
|
|
7627
|
+
if (!inOrigin) continue
|
|
7628
|
+
const key = /^url[ \t]*=(.*)$/i.exec(line)
|
|
7629
|
+
if (key?.[1] !== undefined) return configValue(key[1])
|
|
7630
|
+
}
|
|
7631
|
+
return
|
|
7632
|
+
}
|
|
7633
|
+
var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
7634
|
+
var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
|
|
7635
|
+
function readGitText(mainRoot, rel, maxBytes) {
|
|
7636
|
+
const read = readContainedFile(mainRoot, rel, { maxBytes })
|
|
7637
|
+
return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
|
|
7638
|
+
}
|
|
7639
|
+
function firstLine2(text) {
|
|
7640
|
+
return (
|
|
7641
|
+
text.split(
|
|
7642
|
+
`
|
|
7643
|
+
`,
|
|
7644
|
+
1,
|
|
7645
|
+
)[0] ?? ''
|
|
7646
|
+
)
|
|
7647
|
+
.replace(/\r$/, '')
|
|
7648
|
+
.trim()
|
|
7649
|
+
}
|
|
7650
|
+
function safeRefName(ref) {
|
|
7651
|
+
return (
|
|
7652
|
+
REF_NAME.test(ref) &&
|
|
7653
|
+
ref
|
|
7654
|
+
.split('/')
|
|
7655
|
+
.every(
|
|
7656
|
+
(part) =>
|
|
7657
|
+
part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
|
|
7658
|
+
)
|
|
7659
|
+
)
|
|
7660
|
+
}
|
|
7661
|
+
function packedRef(packed, ref) {
|
|
7662
|
+
for (const raw of packed.split(`
|
|
7663
|
+
`)) {
|
|
7664
|
+
const line = raw.trim()
|
|
7665
|
+
if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
|
|
7666
|
+
const [id, name, ...rest] = line.split(/\s+/)
|
|
7667
|
+
if (rest.length === 0 && name === ref && OBJECT_ID.test(id ?? '')) return id
|
|
7668
|
+
}
|
|
7669
|
+
return
|
|
7670
|
+
}
|
|
7671
|
+
function headCommit(mainRoot) {
|
|
7672
|
+
const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
|
|
7673
|
+
if (head === undefined) return
|
|
7674
|
+
const line = firstLine2(head)
|
|
7675
|
+
if (OBJECT_ID.test(line)) return line
|
|
7676
|
+
const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
|
|
7677
|
+
if (symbolic === undefined || !safeRefName(symbolic)) return
|
|
7678
|
+
const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
|
|
7679
|
+
const looseId = loose === undefined ? '' : firstLine2(loose)
|
|
7680
|
+
if (OBJECT_ID.test(looseId)) return looseId
|
|
7681
|
+
const packed = readGitText(
|
|
7682
|
+
mainRoot,
|
|
7683
|
+
'.git/packed-refs',
|
|
7684
|
+
MAX_PACKED_REFS_BYTES,
|
|
7685
|
+
)
|
|
7686
|
+
return packed === undefined ? undefined : packedRef(packed, symbolic)
|
|
7687
|
+
}
|
|
7688
|
+
function readRepoIdentity(mainRoot) {
|
|
7689
|
+
try {
|
|
7690
|
+
const config = readGitText(mainRoot, '.git/config', MAX_CONFIG_BYTES)
|
|
7691
|
+
const url = config === undefined ? undefined : originUrl(config)
|
|
7692
|
+
const repo = url === undefined ? undefined : normalizeGithubRemote(url)
|
|
7693
|
+
const commit = headCommit(mainRoot)
|
|
7694
|
+
return {
|
|
7695
|
+
...(repo === undefined ? {} : { repo }),
|
|
7696
|
+
...(commit === undefined ? {} : { commit }),
|
|
7697
|
+
}
|
|
7698
|
+
} catch {
|
|
7699
|
+
return {}
|
|
7700
|
+
}
|
|
7701
|
+
}
|
|
7702
|
+
|
|
7347
7703
|
// src/lib/connect-state.ts
|
|
7348
7704
|
import { spawnSync as spawnSync2 } from 'node:child_process'
|
|
7349
7705
|
import {
|
|
@@ -7368,6 +7724,7 @@ var MAX_PATH_LENGTH = 4096
|
|
|
7368
7724
|
var MAX_REASON_LENGTH = 500
|
|
7369
7725
|
var MAX_SOURCES = 32
|
|
7370
7726
|
var MAX_TARGET_EVIDENCE = 64
|
|
7727
|
+
var MAX_EVIDENCE = 64
|
|
7371
7728
|
var MAX_HISTORY = 10
|
|
7372
7729
|
var MAX_POSSIBLE_MATCHES = 5
|
|
7373
7730
|
var MAX_RUN_FILES = 16
|
|
@@ -7747,6 +8104,13 @@ function validPath(value) {
|
|
|
7747
8104
|
function validFingerprint(value) {
|
|
7748
8105
|
return plainText(value, 128)
|
|
7749
8106
|
}
|
|
8107
|
+
function validEvidenceRef(value) {
|
|
8108
|
+
return (
|
|
8109
|
+
isProjectKey(value.project) &&
|
|
8110
|
+
validPath(value.path) &&
|
|
8111
|
+
validFingerprint(value.fingerprint)
|
|
8112
|
+
)
|
|
8113
|
+
}
|
|
7750
8114
|
function validCandidate(value) {
|
|
7751
8115
|
if (!plainText(value.kind, MAX_STRING_LENGTH)) return false
|
|
7752
8116
|
if (!plainText(value.target, MAX_PATH_LENGTH)) return false
|
|
@@ -7765,9 +8129,20 @@ function validCandidate(value) {
|
|
|
7765
8129
|
}
|
|
7766
8130
|
}
|
|
7767
8131
|
if (value.targetEvidence.length > MAX_TARGET_EVIDENCE) return false
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
8132
|
+
if (
|
|
8133
|
+
!value.targetEvidence.every(
|
|
8134
|
+
(ref) => validPath(ref.path) && validFingerprint(ref.fingerprint),
|
|
8135
|
+
)
|
|
8136
|
+
) {
|
|
8137
|
+
return false
|
|
8138
|
+
}
|
|
8139
|
+
return validMismatchFields(value)
|
|
8140
|
+
}
|
|
8141
|
+
function validMismatchFields(value) {
|
|
8142
|
+
if (!isOptionalText(value.mismatchReason, MAX_STRING_LENGTH)) return false
|
|
8143
|
+
if (!isOptionalText(value.claim, MAX_STRING_LENGTH)) return false
|
|
8144
|
+
const evidence = value.evidence ?? []
|
|
8145
|
+
return evidence.length <= MAX_EVIDENCE && evidence.every(validEvidenceRef)
|
|
7771
8146
|
}
|
|
7772
8147
|
function normalizedSources(candidate) {
|
|
7773
8148
|
const seen = new Set()
|
|
@@ -7798,19 +8173,50 @@ function normalizedTargetEvidence(candidate) {
|
|
|
7798
8173
|
}
|
|
7799
8174
|
return [...byPath.values()].sort((a, b) => codepointOrder2(a.path, b.path))
|
|
7800
8175
|
}
|
|
8176
|
+
function normalizedEvidence(candidate) {
|
|
8177
|
+
const seen = new Map()
|
|
8178
|
+
for (const ref of candidate.evidence ?? []) {
|
|
8179
|
+
const normalized = normalizePath(ref.path)
|
|
8180
|
+
const key = `${ref.project}\x00${normalized}`
|
|
8181
|
+
if (!seen.has(key)) {
|
|
8182
|
+
seen.set(key, {
|
|
8183
|
+
project: ref.project,
|
|
8184
|
+
path: normalized,
|
|
8185
|
+
fingerprint: ref.fingerprint,
|
|
8186
|
+
})
|
|
8187
|
+
}
|
|
8188
|
+
}
|
|
8189
|
+
return [...seen.values()].sort(
|
|
8190
|
+
(a, b) =>
|
|
8191
|
+
codepointOrder2(a.project, b.project) || codepointOrder2(a.path, b.path),
|
|
8192
|
+
)
|
|
8193
|
+
}
|
|
8194
|
+
function recordsEvidenceOf(entry, candidate) {
|
|
8195
|
+
const recorded = entry.evidence ?? []
|
|
8196
|
+
const cited = normalizedEvidence(candidate)
|
|
8197
|
+
return (
|
|
8198
|
+
recorded.length === cited.length &&
|
|
8199
|
+
recorded.every(
|
|
8200
|
+
(ref, index) =>
|
|
8201
|
+
ref.project === cited[index]?.project &&
|
|
8202
|
+
ref.path === cited[index]?.path &&
|
|
8203
|
+
ref.fingerprint === cited[index]?.fingerprint,
|
|
8204
|
+
)
|
|
8205
|
+
)
|
|
8206
|
+
}
|
|
7801
8207
|
function candidateIdentity(candidate) {
|
|
7802
8208
|
const sources = normalizedSources(candidate).map((s) => [s.role, s.path])
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
8209
|
+
const parts = [
|
|
8210
|
+
'connect-candidate-v1',
|
|
8211
|
+
candidate.kind,
|
|
8212
|
+
candidate.target,
|
|
8213
|
+
candidate.ruleId,
|
|
8214
|
+
sources,
|
|
8215
|
+
]
|
|
8216
|
+
if (candidate.mismatchReason !== undefined || candidate.claim !== undefined) {
|
|
8217
|
+
parts.push(candidate.mismatchReason ?? null, candidate.claim ?? null)
|
|
8218
|
+
}
|
|
8219
|
+
return createHash3('sha256').update(JSON.stringify(parts)).digest('hex')
|
|
7814
8220
|
}
|
|
7815
8221
|
var LEDGER_VERSION = 2
|
|
7816
8222
|
var LEDGER_STATUSES = ['candidate', 'promoted', 'rejected']
|
|
@@ -7818,11 +8224,25 @@ function isLedgerStatus(value) {
|
|
|
7818
8224
|
return LEDGER_STATUSES.some((status) => status === value)
|
|
7819
8225
|
}
|
|
7820
8226
|
function isReopenReason(value) {
|
|
7821
|
-
return
|
|
8227
|
+
return (
|
|
8228
|
+
value === 'sources changed' ||
|
|
8229
|
+
value === 'target changed' ||
|
|
8230
|
+
value === 'evidence changed'
|
|
8231
|
+
)
|
|
8232
|
+
}
|
|
8233
|
+
function isOptionalReopenedFor(value) {
|
|
8234
|
+
return value === undefined || value === 'evidence changed'
|
|
7822
8235
|
}
|
|
7823
8236
|
function isOptionalText(value, maxLength) {
|
|
7824
8237
|
return value === undefined || plainText(value, maxLength)
|
|
7825
8238
|
}
|
|
8239
|
+
var REVISION = /^[0-9a-f]{12}$/
|
|
8240
|
+
function isRevision(value) {
|
|
8241
|
+
return typeof value === 'string' && REVISION.test(value)
|
|
8242
|
+
}
|
|
8243
|
+
function isOptionalRevision(value) {
|
|
8244
|
+
return value === undefined || isRevision(value)
|
|
8245
|
+
}
|
|
7826
8246
|
function isLedgerSource(value) {
|
|
7827
8247
|
return (
|
|
7828
8248
|
isRecord3(value) &&
|
|
@@ -7838,13 +8258,32 @@ function isTargetEvidenceRef(value) {
|
|
|
7838
8258
|
validFingerprint(value.fingerprint)
|
|
7839
8259
|
)
|
|
7840
8260
|
}
|
|
8261
|
+
function isEvidenceRef(value) {
|
|
8262
|
+
return (
|
|
8263
|
+
isRecord3(value) &&
|
|
8264
|
+
isProjectKey(value.project) &&
|
|
8265
|
+
plainText(value.path, MAX_PATH_LENGTH) &&
|
|
8266
|
+
validFingerprint(value.fingerprint)
|
|
8267
|
+
)
|
|
8268
|
+
}
|
|
8269
|
+
function isOptionalEvidence(value) {
|
|
8270
|
+
return (
|
|
8271
|
+
value === undefined ||
|
|
8272
|
+
(Array.isArray(value) &&
|
|
8273
|
+
value.length <= MAX_EVIDENCE &&
|
|
8274
|
+
value.every(isEvidenceRef))
|
|
8275
|
+
)
|
|
8276
|
+
}
|
|
7841
8277
|
function isHistoryItem(value) {
|
|
7842
8278
|
return (
|
|
7843
8279
|
isRecord3(value) &&
|
|
7844
8280
|
isLedgerStatus(value.status) &&
|
|
8281
|
+
isOptionalText(value.mismatchReason, MAX_STRING_LENGTH) &&
|
|
8282
|
+
isOptionalEvidence(value.evidence) &&
|
|
7845
8283
|
isOptionalText(value.reason, MAX_REASON_LENGTH) &&
|
|
7846
8284
|
isOptionalText(value.destination, MAX_PATH_LENGTH) &&
|
|
7847
8285
|
(value.reopened === undefined || isReopenReason(value.reopened)) &&
|
|
8286
|
+
isOptionalReopenedFor(value.reopenedFor) &&
|
|
7848
8287
|
Array.isArray(value.sources) &&
|
|
7849
8288
|
value.sources.every(isLedgerSource) &&
|
|
7850
8289
|
Array.isArray(value.targetEvidence) &&
|
|
@@ -7863,10 +8302,14 @@ function isLedgerEntry(value) {
|
|
|
7863
8302
|
value.sources.every(isLedgerSource) &&
|
|
7864
8303
|
Array.isArray(value.targetEvidence) &&
|
|
7865
8304
|
value.targetEvidence.every(isTargetEvidenceRef) &&
|
|
8305
|
+
isOptionalText(value.mismatchReason, MAX_STRING_LENGTH) &&
|
|
8306
|
+
isOptionalEvidence(value.evidence) &&
|
|
7866
8307
|
isLedgerStatus(value.status) &&
|
|
7867
8308
|
isOptionalText(value.reason, MAX_REASON_LENGTH) &&
|
|
7868
8309
|
isOptionalText(value.destination, MAX_PATH_LENGTH) &&
|
|
7869
8310
|
(value.reopened === undefined || isReopenReason(value.reopened)) &&
|
|
8311
|
+
isOptionalReopenedFor(value.reopenedFor) &&
|
|
8312
|
+
isOptionalRevision(value.revision) &&
|
|
7870
8313
|
Array.isArray(value.history) &&
|
|
7871
8314
|
value.history.every(isHistoryItem) &&
|
|
7872
8315
|
plainText(value.recordedAt, MAX_STRING_LENGTH)
|
|
@@ -7970,6 +8413,21 @@ function sameTargetEvidence(current, prior) {
|
|
|
7970
8413
|
return known === undefined || known.fingerprint === ref.fingerprint
|
|
7971
8414
|
})
|
|
7972
8415
|
}
|
|
8416
|
+
function evidenceChanged(prior, lookup) {
|
|
8417
|
+
if (lookup === undefined) return false
|
|
8418
|
+
return (prior.evidence ?? []).some((ref) => {
|
|
8419
|
+
const now = lookup(ref.project, ref.path)
|
|
8420
|
+
if (now.status === 'gone') return true
|
|
8421
|
+
return now.status === 'present' && now.fingerprint !== ref.fingerprint
|
|
8422
|
+
})
|
|
8423
|
+
}
|
|
8424
|
+
function evidenceArrived(prior, candidate) {
|
|
8425
|
+
return (
|
|
8426
|
+
candidate.kind === 'code-mismatch' &&
|
|
8427
|
+
(prior.evidence ?? []).length === 0 &&
|
|
8428
|
+
normalizedEvidence(candidate).length > 0
|
|
8429
|
+
)
|
|
8430
|
+
}
|
|
7973
8431
|
function possibleRenames(ledger, candidate, id, sources) {
|
|
7974
8432
|
const matches = []
|
|
7975
8433
|
for (const entry of ledger.entries) {
|
|
@@ -7993,7 +8451,7 @@ function possibleRenames(ledger, candidate, id, sources) {
|
|
|
7993
8451
|
}
|
|
7994
8452
|
return matches
|
|
7995
8453
|
}
|
|
7996
|
-
function classifyCandidate(ledger, candidate) {
|
|
8454
|
+
function classifyCandidate(ledger, candidate, evidence) {
|
|
7997
8455
|
const id = candidateIdentity(candidate)
|
|
7998
8456
|
const sources = normalizedSources(candidate)
|
|
7999
8457
|
const missing = sources
|
|
@@ -8009,28 +8467,36 @@ function classifyCandidate(ledger, candidate) {
|
|
|
8009
8467
|
}
|
|
8010
8468
|
}
|
|
8011
8469
|
const sourcesSame = sameSources(sources, prior)
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8470
|
+
const pointer =
|
|
8471
|
+
prior.status === 'promoted' && prior.destination !== undefined
|
|
8472
|
+
? { refreshPointer: prior.destination }
|
|
8473
|
+
: {}
|
|
8474
|
+
if (!sourcesSame) {
|
|
8475
|
+
return {
|
|
8476
|
+
standing: 'reopened',
|
|
8477
|
+
id,
|
|
8478
|
+
reason: 'sources changed',
|
|
8479
|
+
priorStatus: prior.status,
|
|
8480
|
+
...pointer,
|
|
8481
|
+
}
|
|
8017
8482
|
}
|
|
8018
|
-
if (
|
|
8483
|
+
if (evidenceChanged(prior, evidence) || evidenceArrived(prior, candidate)) {
|
|
8019
8484
|
return {
|
|
8020
8485
|
standing: 'reopened',
|
|
8021
8486
|
id,
|
|
8022
|
-
reason: '
|
|
8487
|
+
reason: 'evidence changed',
|
|
8023
8488
|
priorStatus: prior.status,
|
|
8489
|
+
...pointer,
|
|
8024
8490
|
}
|
|
8025
8491
|
}
|
|
8492
|
+
if (sameTargetEvidence(normalizedTargetEvidence(candidate), prior)) {
|
|
8493
|
+
return { standing: 'suppressed', id, priorStatus: prior.status }
|
|
8494
|
+
}
|
|
8026
8495
|
return {
|
|
8027
8496
|
standing: 'reopened',
|
|
8028
8497
|
id,
|
|
8029
|
-
reason: '
|
|
8498
|
+
reason: 'target changed',
|
|
8030
8499
|
priorStatus: prior.status,
|
|
8031
|
-
...(prior.status === 'promoted' && prior.destination !== undefined
|
|
8032
|
-
? { refreshPointer: prior.destination }
|
|
8033
|
-
: {}),
|
|
8034
8500
|
}
|
|
8035
8501
|
}
|
|
8036
8502
|
function ledgerSources(candidate) {
|
|
@@ -8046,26 +8512,86 @@ function ledgerSources(candidate) {
|
|
|
8046
8512
|
],
|
|
8047
8513
|
)
|
|
8048
8514
|
}
|
|
8515
|
+
function mismatchFields(candidate) {
|
|
8516
|
+
const evidence = normalizedEvidence(candidate)
|
|
8517
|
+
return {
|
|
8518
|
+
...(candidate.mismatchReason === undefined
|
|
8519
|
+
? {}
|
|
8520
|
+
: { mismatchReason: candidate.mismatchReason }),
|
|
8521
|
+
...(evidence.length === 0 ? {} : { evidence }),
|
|
8522
|
+
}
|
|
8523
|
+
}
|
|
8524
|
+
function withEvidence(entry, evidence) {
|
|
8525
|
+
const { evidence: _recorded, revision: _stale, ...rest } = entry
|
|
8526
|
+
const next =
|
|
8527
|
+
evidence.length === 0 ? rest : { ...rest, evidence: [...evidence] }
|
|
8528
|
+
return { ...next, revision: revisionOf(next) }
|
|
8529
|
+
}
|
|
8530
|
+
function reopenedFields(reason) {
|
|
8531
|
+
return reason === 'evidence changed'
|
|
8532
|
+
? { reopened: 'target changed', reopenedFor: reason }
|
|
8533
|
+
: { reopened: reason }
|
|
8534
|
+
}
|
|
8535
|
+
function revisionOfParts(sources, targetEvidence, evidence) {
|
|
8536
|
+
return createHash3('sha256')
|
|
8537
|
+
.update(
|
|
8538
|
+
JSON.stringify([
|
|
8539
|
+
'connect-revision-v1',
|
|
8540
|
+
sources.map((x) => [x.role, x.path, x.fingerprint]),
|
|
8541
|
+
targetEvidence.map((x) => [x.path, x.fingerprint]),
|
|
8542
|
+
evidence.map((x) => [x.project, x.path, x.fingerprint]),
|
|
8543
|
+
]),
|
|
8544
|
+
)
|
|
8545
|
+
.digest('hex')
|
|
8546
|
+
.slice(0, 12)
|
|
8547
|
+
}
|
|
8548
|
+
function revisionOfCandidate(candidate) {
|
|
8549
|
+
return revisionOfParts(
|
|
8550
|
+
ledgerSources(candidate),
|
|
8551
|
+
normalizedTargetEvidence(candidate),
|
|
8552
|
+
normalizedEvidence(candidate),
|
|
8553
|
+
)
|
|
8554
|
+
}
|
|
8555
|
+
function revisionOf(entry) {
|
|
8556
|
+
return (
|
|
8557
|
+
entry.revision ??
|
|
8558
|
+
revisionOfParts(entry.sources, entry.targetEvidence, entry.evidence ?? [])
|
|
8559
|
+
)
|
|
8560
|
+
}
|
|
8049
8561
|
function snapshot(entry) {
|
|
8050
8562
|
return {
|
|
8051
8563
|
status: entry.status,
|
|
8564
|
+
...(entry.mismatchReason === undefined
|
|
8565
|
+
? {}
|
|
8566
|
+
: { mismatchReason: entry.mismatchReason }),
|
|
8567
|
+
...(entry.evidence === undefined ? {} : { evidence: entry.evidence }),
|
|
8052
8568
|
...(entry.reason === undefined ? {} : { reason: entry.reason }),
|
|
8053
8569
|
...(entry.destination === undefined
|
|
8054
8570
|
? {}
|
|
8055
8571
|
: { destination: entry.destination }),
|
|
8056
8572
|
...(entry.reopened === undefined ? {} : { reopened: entry.reopened }),
|
|
8573
|
+
...(entry.reopenedFor === undefined
|
|
8574
|
+
? {}
|
|
8575
|
+
: { reopenedFor: entry.reopenedFor }),
|
|
8057
8576
|
sources: entry.sources,
|
|
8058
8577
|
targetEvidence: entry.targetEvidence,
|
|
8059
8578
|
recordedAt: entry.recordedAt,
|
|
8060
8579
|
}
|
|
8061
8580
|
}
|
|
8062
|
-
function applyCandidates(
|
|
8581
|
+
function applyCandidates(
|
|
8582
|
+
ledger,
|
|
8583
|
+
candidates,
|
|
8584
|
+
recordedAt,
|
|
8585
|
+
evidence,
|
|
8586
|
+
evidenceFor,
|
|
8587
|
+
) {
|
|
8063
8588
|
let entries = [...ledger.entries]
|
|
8064
8589
|
const outcomes = []
|
|
8065
8590
|
for (const candidate of candidates) {
|
|
8066
8591
|
const outcome = classifyCandidate(
|
|
8067
8592
|
{ version: LEDGER_VERSION, entries },
|
|
8068
8593
|
candidate,
|
|
8594
|
+
evidenceFor?.(candidate) ?? evidence,
|
|
8069
8595
|
)
|
|
8070
8596
|
outcomes.push(outcome)
|
|
8071
8597
|
if (outcome.standing === 'new') {
|
|
@@ -8076,10 +8602,21 @@ function applyCandidates(ledger, candidates, recordedAt) {
|
|
|
8076
8602
|
ruleId: candidate.ruleId,
|
|
8077
8603
|
sources: ledgerSources(candidate),
|
|
8078
8604
|
targetEvidence: normalizedTargetEvidence(candidate),
|
|
8605
|
+
...mismatchFields(candidate),
|
|
8606
|
+
revision: revisionOfCandidate(candidate),
|
|
8079
8607
|
status: 'candidate',
|
|
8080
8608
|
history: [],
|
|
8081
8609
|
recordedAt,
|
|
8082
8610
|
})
|
|
8611
|
+
} else if (
|
|
8612
|
+
outcome.standing === 'suppressed' &&
|
|
8613
|
+
outcome.priorStatus === 'candidate'
|
|
8614
|
+
) {
|
|
8615
|
+
entries = entries.map((entry) =>
|
|
8616
|
+
entry.id === outcome.id
|
|
8617
|
+
? withEvidence(entry, normalizedEvidence(candidate))
|
|
8618
|
+
: entry,
|
|
8619
|
+
)
|
|
8083
8620
|
} else if (outcome.standing === 'reopened') {
|
|
8084
8621
|
entries = entries.map((entry) =>
|
|
8085
8622
|
entry.id === outcome.id
|
|
@@ -8090,8 +8627,10 @@ function applyCandidates(ledger, candidates, recordedAt) {
|
|
|
8090
8627
|
ruleId: entry.ruleId,
|
|
8091
8628
|
sources: ledgerSources(candidate),
|
|
8092
8629
|
targetEvidence: normalizedTargetEvidence(candidate),
|
|
8630
|
+
...mismatchFields(candidate),
|
|
8093
8631
|
status: 'candidate',
|
|
8094
|
-
|
|
8632
|
+
...reopenedFields(outcome.reason),
|
|
8633
|
+
revision: revisionOfCandidate(candidate),
|
|
8095
8634
|
history: [...entry.history, snapshot(entry)].slice(-MAX_HISTORY),
|
|
8096
8635
|
recordedAt,
|
|
8097
8636
|
}
|
|
@@ -8193,7 +8732,13 @@ function applyCoverage(allPrior, update, at) {
|
|
|
8193
8732
|
return records.sort(byRule)
|
|
8194
8733
|
}
|
|
8195
8734
|
function foldRun(prior, input, recordedAt) {
|
|
8196
|
-
const applied = applyCandidates(
|
|
8735
|
+
const applied = applyCandidates(
|
|
8736
|
+
prior,
|
|
8737
|
+
input.candidates,
|
|
8738
|
+
recordedAt,
|
|
8739
|
+
input.evidence,
|
|
8740
|
+
input.evidenceFor,
|
|
8741
|
+
)
|
|
8197
8742
|
const coverage =
|
|
8198
8743
|
input.coverage === undefined
|
|
8199
8744
|
? prior.coverage
|
|
@@ -8369,6 +8914,9 @@ function insertImportRun(root, plan, options = {}) {
|
|
|
8369
8914
|
runId: decision.runId,
|
|
8370
8915
|
files: decision.files,
|
|
8371
8916
|
candidates: decision.candidates,
|
|
8917
|
+
...(decision.evidenceFor === undefined
|
|
8918
|
+
? {}
|
|
8919
|
+
: { evidenceFor: decision.evidenceFor }),
|
|
8372
8920
|
},
|
|
8373
8921
|
options,
|
|
8374
8922
|
)
|
|
@@ -8399,7 +8947,7 @@ var INVOCATION_FILE = 'invocation.json'
|
|
|
8399
8947
|
var MAX_CI_RUN_BYTES = 1024
|
|
8400
8948
|
var MAX_INVOCATION_BYTES = 1024 * 1024
|
|
8401
8949
|
var MAX_INVOCATION_NAME_LENGTH = 200
|
|
8402
|
-
var
|
|
8950
|
+
var OBJECT_ID2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
8403
8951
|
var REPO_SLUG = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
|
|
8404
8952
|
var INVOCATION_OUTCOMES = ['complete', 'degraded', 'busy', 'failed']
|
|
8405
8953
|
function isInvocationOutcome(value) {
|
|
@@ -8434,7 +8982,7 @@ function parseInvocationProject(item) {
|
|
|
8434
8982
|
if (!isProjectKey(key) || !plainText(name, MAX_INVOCATION_NAME_LENGTH)) {
|
|
8435
8983
|
return
|
|
8436
8984
|
}
|
|
8437
|
-
if (!optionalMatch(repo, REPO_SLUG) || !optionalMatch(commit,
|
|
8985
|
+
if (!optionalMatch(repo, REPO_SLUG) || !optionalMatch(commit, OBJECT_ID2)) {
|
|
8438
8986
|
return
|
|
8439
8987
|
}
|
|
8440
8988
|
return {
|
|
@@ -8559,8 +9107,17 @@ function validDecision(input) {
|
|
|
8559
9107
|
if (!plainText(input.id, MAX_STRING_LENGTH)) return false
|
|
8560
9108
|
if (input.status !== 'promoted' && input.status !== 'rejected') return false
|
|
8561
9109
|
if (!plainText(input.reason.trim(), MAX_REASON_LENGTH)) return false
|
|
9110
|
+
if (input.revision !== undefined && !isRevision(input.revision)) return false
|
|
8562
9111
|
return isOptionalText(input.destination, MAX_PATH_LENGTH)
|
|
8563
9112
|
}
|
|
9113
|
+
function refusalOf(input, prior) {
|
|
9114
|
+
if (input.onlyIfOpen === true && prior.status !== 'candidate') {
|
|
9115
|
+
return 'not-open'
|
|
9116
|
+
}
|
|
9117
|
+
const stale =
|
|
9118
|
+
input.revision !== undefined && input.revision !== revisionOf(prior)
|
|
9119
|
+
return stale ? 'stale-revision' : undefined
|
|
9120
|
+
}
|
|
8564
9121
|
function decideLedgerEntry(root, input, options = {}) {
|
|
8565
9122
|
if (!validDecision(input))
|
|
8566
9123
|
return { status: 'failed', reason: 'invalid-input' }
|
|
@@ -8578,9 +9135,8 @@ function decideLedgerEntry(root, input, options = {}) {
|
|
|
8578
9135
|
if (prior === undefined) {
|
|
8579
9136
|
return { status: 'failed', reason: 'unknown-candidate' }
|
|
8580
9137
|
}
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
}
|
|
9138
|
+
const refused = refusalOf(input, prior)
|
|
9139
|
+
if (refused !== undefined) return { status: 'failed', reason: refused }
|
|
8584
9140
|
const decided = {
|
|
8585
9141
|
id: prior.id,
|
|
8586
9142
|
kind: prior.kind,
|
|
@@ -8588,6 +9144,11 @@ function decideLedgerEntry(root, input, options = {}) {
|
|
|
8588
9144
|
ruleId: prior.ruleId,
|
|
8589
9145
|
sources: prior.sources,
|
|
8590
9146
|
targetEvidence: prior.targetEvidence,
|
|
9147
|
+
...(prior.mismatchReason === undefined
|
|
9148
|
+
? {}
|
|
9149
|
+
: { mismatchReason: prior.mismatchReason }),
|
|
9150
|
+
...(prior.evidence === undefined ? {} : { evidence: prior.evidence }),
|
|
9151
|
+
...(prior.revision === undefined ? {} : { revision: prior.revision }),
|
|
8591
9152
|
status: input.status,
|
|
8592
9153
|
reason: input.reason.trim(),
|
|
8593
9154
|
...(input.status === 'promoted' && input.destination !== undefined
|
|
@@ -8634,6 +9195,7 @@ function clearLedger(root, options = {}) {
|
|
|
8634
9195
|
|
|
8635
9196
|
// src/lib/connect-ci.ts
|
|
8636
9197
|
var REPORT_MAX_CHARS = 60000
|
|
9198
|
+
var MAX_UNVERIFIED_IDS = 20
|
|
8637
9199
|
var MANIFESTS_KEPT = 14
|
|
8638
9200
|
var REPORT_FILE = 'report.md'
|
|
8639
9201
|
var PAYLOAD_FILE = 'ci-payloads.json'
|
|
@@ -8649,17 +9211,19 @@ var CANDIDATE_ID = /^[0-9a-f]{64}$/
|
|
|
8649
9211
|
var MANIFEST_HASH = /^[0-9a-f]{16}$/
|
|
8650
9212
|
var DIGITS = /^[0-9]{1,20}$/
|
|
8651
9213
|
var DATE = /^\d{4}-\d{2}-\d{2}$/
|
|
8652
|
-
var
|
|
9214
|
+
var REPO2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
|
|
8653
9215
|
var TOKEN = /^[a-z][a-z0-9-]{0,39}$/
|
|
9216
|
+
var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
8654
9217
|
function manifestMarker(hash) {
|
|
8655
9218
|
return `<!-- connect-manifest:${hash} -->`
|
|
8656
9219
|
}
|
|
8657
|
-
function decisionLine(id, status, ticked) {
|
|
8658
|
-
|
|
9220
|
+
function decisionLine(id, status, ticked, revision) {
|
|
9221
|
+
const suffix = revision === undefined ? '' : `:r${revision}`
|
|
9222
|
+
return `- [${ticked ? 'x' : ' '}] ${STATUS_LABEL[status]} <!-- connect-decision:${status}:${id}${suffix} -->`
|
|
8659
9223
|
}
|
|
8660
9224
|
var MANIFEST_LINE = /^<!-- connect-manifest:([0-9a-f]{16}) -->[ \t]*$/
|
|
8661
9225
|
var DECISION_LINE =
|
|
8662
|
-
/^- \[([ xX])\] (Promoted|Rejected) <!-- connect-decision:(promoted|rejected):([0-9a-f]{64}) -->[ \t]*$/
|
|
9226
|
+
/^- \[([ xX])\] (Promoted|Rejected) <!-- connect-decision:(promoted|rejected):([0-9a-f]{64})(?::r([0-9a-f]{12}))? -->[ \t]*$/
|
|
8663
9227
|
var FENCE_LINE2 = /^ {0,3}(`{3,}|~{3,})(.*)$/
|
|
8664
9228
|
function isRecord4(value) {
|
|
8665
9229
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
@@ -8790,13 +9354,13 @@ function inFence(scan, line) {
|
|
|
8790
9354
|
function boxOf(line) {
|
|
8791
9355
|
const match = DECISION_LINE.exec(line)
|
|
8792
9356
|
if (match === null) return
|
|
8793
|
-
const [, mark, label, status, id] = match
|
|
9357
|
+
const [, mark, label, status, id, named] = match
|
|
8794
9358
|
if (id === undefined || label === undefined || mark === undefined) {
|
|
8795
9359
|
return
|
|
8796
9360
|
}
|
|
8797
9361
|
if (status !== 'promoted' && status !== 'rejected') return
|
|
8798
9362
|
if (STATUS_LABEL[status] !== label) return
|
|
8799
|
-
return { id, status, ticked: mark !== ' ' }
|
|
9363
|
+
return { id, status, ticked: mark !== ' ', revision: named }
|
|
8800
9364
|
}
|
|
8801
9365
|
function scanLine(scan, line) {
|
|
8802
9366
|
if (inFence(scan, line)) return
|
|
@@ -8892,7 +9456,54 @@ function sourceOf(item) {
|
|
|
8892
9456
|
...(excerpt === undefined ? {} : { excerpt }),
|
|
8893
9457
|
}
|
|
8894
9458
|
}
|
|
8895
|
-
function
|
|
9459
|
+
function spanOf(start, end) {
|
|
9460
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end)) {
|
|
9461
|
+
return
|
|
9462
|
+
}
|
|
9463
|
+
const from = start
|
|
9464
|
+
const to = end
|
|
9465
|
+
return from >= 1 && to >= from ? { start: from, end: to } : undefined
|
|
9466
|
+
}
|
|
9467
|
+
function evidenceItemOf(item, heads, repos) {
|
|
9468
|
+
if (!isRecord4(item)) return
|
|
9469
|
+
const evidencePath = lineOf(item.path, LIMITS.path)
|
|
9470
|
+
if (evidencePath === undefined) return
|
|
9471
|
+
const span = spanOf(item.start, item.end)
|
|
9472
|
+
const head =
|
|
9473
|
+
typeof item.head === 'string' && OBJECT_ID3.test(item.head)
|
|
9474
|
+
? item.head
|
|
9475
|
+
: typeof item.project === 'string'
|
|
9476
|
+
? heads.get(item.project)
|
|
9477
|
+
: undefined
|
|
9478
|
+
const repo =
|
|
9479
|
+
typeof item.repo === 'string' && REPO2.test(item.repo)
|
|
9480
|
+
? item.repo
|
|
9481
|
+
: typeof item.project === 'string'
|
|
9482
|
+
? repos.get(item.project)
|
|
9483
|
+
: undefined
|
|
9484
|
+
return {
|
|
9485
|
+
projectName: lineOf(item.projectName, LIMITS.name) ?? 'unknown',
|
|
9486
|
+
...(repo === undefined ? {} : { repo }),
|
|
9487
|
+
path: evidencePath,
|
|
9488
|
+
...(span === undefined ? {} : span),
|
|
9489
|
+
...(head === undefined ? {} : { head }),
|
|
9490
|
+
}
|
|
9491
|
+
}
|
|
9492
|
+
function mismatchFields2(raw, kind, heads, repos) {
|
|
9493
|
+
if (kind !== 'code-mismatch') return {}
|
|
9494
|
+
const reason = MISMATCH_REASONS.find((known) => known === raw.reason)
|
|
9495
|
+
const list = Array.isArray(raw.evidence) ? raw.evidence : raw.counterevidence
|
|
9496
|
+
const evidence = Array.isArray(list)
|
|
9497
|
+
? list
|
|
9498
|
+
.slice(0, CANDIDATE_LIMITS.counterevidence)
|
|
9499
|
+
.flatMap((item) => evidenceItemOf(item, heads, repos) ?? [])
|
|
9500
|
+
: []
|
|
9501
|
+
return {
|
|
9502
|
+
...(reason === undefined ? {} : { reason }),
|
|
9503
|
+
...(evidence.length === 0 ? {} : { evidence }),
|
|
9504
|
+
}
|
|
9505
|
+
}
|
|
9506
|
+
function payloadText(raw, heads, repos) {
|
|
8896
9507
|
if (!isRecord4(raw) || !Array.isArray(raw.sources)) return
|
|
8897
9508
|
const title = lineOf(raw.title, LIMITS.title)
|
|
8898
9509
|
const summary = paragraphOf(raw.summary, LIMITS.summary)
|
|
@@ -8900,30 +9511,41 @@ function payloadText(raw) {
|
|
|
8900
9511
|
const sources = raw.sources
|
|
8901
9512
|
.slice(0, LIMITS.sources)
|
|
8902
9513
|
.flatMap((item) => sourceOf(item) ?? [])
|
|
9514
|
+
const kind = tokenOf(raw.kind)
|
|
8903
9515
|
return {
|
|
8904
9516
|
title,
|
|
8905
9517
|
summary,
|
|
8906
|
-
kind
|
|
9518
|
+
kind,
|
|
8907
9519
|
nextStep: tokenOf(raw.nextStep),
|
|
8908
9520
|
targetName: lineOf(raw.targetName, LIMITS.name) ?? 'unknown',
|
|
8909
9521
|
sources,
|
|
9522
|
+
...mismatchFields2(raw, kind, heads, repos),
|
|
8910
9523
|
}
|
|
8911
9524
|
}
|
|
9525
|
+
var REVISION2 = /^[0-9a-f]{12}$/
|
|
9526
|
+
function revisionField(value) {
|
|
9527
|
+
const revision = revisionFrom(value)
|
|
9528
|
+
return revision === undefined ? {} : { revision }
|
|
9529
|
+
}
|
|
9530
|
+
function revisionFrom(value) {
|
|
9531
|
+
return typeof value === 'string' && REVISION2.test(value) ? value : undefined
|
|
9532
|
+
}
|
|
8912
9533
|
function payloadFromStore(raw) {
|
|
8913
9534
|
if (!isRecord4(raw) || !isCandidateId(raw.id)) return
|
|
8914
|
-
const text = payloadText(raw)
|
|
9535
|
+
const text = payloadText(raw, new Map(), new Map())
|
|
8915
9536
|
if (text === undefined) return
|
|
8916
9537
|
if (!isDigits(raw.runId) || !isDigits(raw.attempt)) return
|
|
8917
9538
|
const { repo, firstShown } = raw
|
|
8918
9539
|
return {
|
|
8919
9540
|
id: raw.id,
|
|
8920
9541
|
...text,
|
|
8921
|
-
...(typeof repo === 'string' &&
|
|
9542
|
+
...(typeof repo === 'string' && REPO2.test(repo) ? { repo } : {}),
|
|
8922
9543
|
...(typeof firstShown === 'string' && validDate(firstShown)
|
|
8923
9544
|
? { firstShown }
|
|
8924
9545
|
: {}),
|
|
8925
9546
|
runId: raw.runId,
|
|
8926
9547
|
attempt: raw.attempt,
|
|
9548
|
+
...revisionField(raw.revision),
|
|
8927
9549
|
}
|
|
8928
9550
|
}
|
|
8929
9551
|
function readPayloadStore(root) {
|
|
@@ -8951,11 +9573,14 @@ function payloadStoreText(payloads) {
|
|
|
8951
9573
|
targetName: payload.targetName,
|
|
8952
9574
|
...(payload.repo === undefined ? {} : { repo: payload.repo }),
|
|
8953
9575
|
sources: payload.sources,
|
|
9576
|
+
...(payload.reason === undefined ? {} : { reason: payload.reason }),
|
|
9577
|
+
...(payload.evidence === undefined ? {} : { evidence: payload.evidence }),
|
|
8954
9578
|
...(payload.firstShown === undefined
|
|
8955
9579
|
? {}
|
|
8956
9580
|
: { firstShown: payload.firstShown }),
|
|
8957
9581
|
runId: payload.runId,
|
|
8958
9582
|
attempt: payload.attempt,
|
|
9583
|
+
...(payload.revision === undefined ? {} : { revision: payload.revision }),
|
|
8959
9584
|
}))
|
|
8960
9585
|
return `${JSON.stringify({ version: 1, payloads: stored }, null, 2)}
|
|
8961
9586
|
`
|
|
@@ -9047,13 +9672,29 @@ function repoMap(value) {
|
|
|
9047
9672
|
if (
|
|
9048
9673
|
typeof root === 'string' &&
|
|
9049
9674
|
typeof repo === 'string' &&
|
|
9050
|
-
|
|
9675
|
+
REPO2.test(repo)
|
|
9051
9676
|
) {
|
|
9052
9677
|
out.set(root, repo)
|
|
9053
9678
|
}
|
|
9054
9679
|
}
|
|
9055
9680
|
return out
|
|
9056
9681
|
}
|
|
9682
|
+
function commitMap(value) {
|
|
9683
|
+
const out = new Map()
|
|
9684
|
+
if (!Array.isArray(value)) return out
|
|
9685
|
+
for (const item of value.slice(0, MAX_PROJECTS)) {
|
|
9686
|
+
if (!isRecord4(item)) continue
|
|
9687
|
+
const { root, commit } = item
|
|
9688
|
+
if (
|
|
9689
|
+
typeof root === 'string' &&
|
|
9690
|
+
typeof commit === 'string' &&
|
|
9691
|
+
OBJECT_ID3.test(commit)
|
|
9692
|
+
) {
|
|
9693
|
+
out.set(root, commit)
|
|
9694
|
+
}
|
|
9695
|
+
}
|
|
9696
|
+
return out
|
|
9697
|
+
}
|
|
9057
9698
|
function candidatesOf(value) {
|
|
9058
9699
|
if (!isRecord4(value) || !Array.isArray(value.candidates)) return []
|
|
9059
9700
|
return value.candidates.slice(0, MAX_CANDIDATES)
|
|
@@ -9073,6 +9714,7 @@ function readRunSummary(root, runId) {
|
|
|
9073
9714
|
...(selection === undefined ? {} : { selection }),
|
|
9074
9715
|
...(sweep === undefined ? {} : { sweep }),
|
|
9075
9716
|
repoByRoot: repoMap(record.projects),
|
|
9717
|
+
commitByRoot: commitMap(record.projects),
|
|
9076
9718
|
candidates: candidatesOf(record.candidateBlock),
|
|
9077
9719
|
}
|
|
9078
9720
|
}
|
|
@@ -9090,13 +9732,21 @@ var OUTCOME_SENTENCE = {
|
|
|
9090
9732
|
function isRed(outcome) {
|
|
9091
9733
|
return outcome === 'failed' || outcome === 'no-final-line'
|
|
9092
9734
|
}
|
|
9735
|
+
var SYSTEMATIC_REPO = 'marcusrbrown/systematic'
|
|
9093
9736
|
function validRequest(request) {
|
|
9094
9737
|
return (
|
|
9095
9738
|
validDate(request.date) &&
|
|
9096
9739
|
isDigits(request.runId) &&
|
|
9097
|
-
isDigits(request.attempt)
|
|
9740
|
+
isDigits(request.attempt) &&
|
|
9741
|
+
(request.repo === undefined || isGithubOwnerRepo(request.repo))
|
|
9098
9742
|
)
|
|
9099
9743
|
}
|
|
9744
|
+
function fetchRepoOf(request) {
|
|
9745
|
+
const { repo } = request
|
|
9746
|
+
return repo === undefined || repo.toLowerCase() === SYSTEMATIC_REPO
|
|
9747
|
+
? undefined
|
|
9748
|
+
: repo
|
|
9749
|
+
}
|
|
9100
9750
|
function factsOf(id, payload) {
|
|
9101
9751
|
const target =
|
|
9102
9752
|
payload.repo === undefined
|
|
@@ -9105,6 +9755,7 @@ function factsOf(id, payload) {
|
|
|
9105
9755
|
const lines = [
|
|
9106
9756
|
`Id: ${id}`,
|
|
9107
9757
|
`Kind: ${payload.kind}`,
|
|
9758
|
+
...(payload.reason === undefined ? [] : [`Reason: ${payload.reason}`]),
|
|
9108
9759
|
`Target: ${target}`,
|
|
9109
9760
|
`Title: ${payload.title}`,
|
|
9110
9761
|
`Summary: ${payload.summary}`,
|
|
@@ -9115,27 +9766,42 @@ function factsOf(id, payload) {
|
|
|
9115
9766
|
lines.push(`- ${source.projectName} ${source.path}`)
|
|
9116
9767
|
if (source.excerpt !== undefined) lines.push(` Excerpt: ${source.excerpt}`)
|
|
9117
9768
|
}
|
|
9769
|
+
if (payload.evidence !== undefined) lines.push('Evidence:')
|
|
9770
|
+
for (const item of payload.evidence ?? []) {
|
|
9771
|
+
const span =
|
|
9772
|
+
item.start === undefined || item.end === undefined
|
|
9773
|
+
? '?'
|
|
9774
|
+
: `${item.start}-${item.end}`
|
|
9775
|
+
lines.push(
|
|
9776
|
+
`- ${item.projectName}:${item.path}:${span}:${item.head ?? 'unavailable'}`,
|
|
9777
|
+
)
|
|
9778
|
+
}
|
|
9118
9779
|
return lines.join(`
|
|
9119
9780
|
`)
|
|
9120
9781
|
}
|
|
9121
|
-
function fetchWord(payload) {
|
|
9122
|
-
|
|
9782
|
+
function fetchWord(payload, repo) {
|
|
9783
|
+
const run = `${payload.runId}.${payload.attempt}`
|
|
9784
|
+
return repo === undefined ? run : `${repo}:${run}`
|
|
9123
9785
|
}
|
|
9124
|
-
function blockOf(position,
|
|
9125
|
-
const
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
}
|
|
9786
|
+
function blockOf(position, entry, revision, payload, isNew, fetchRepo) {
|
|
9787
|
+
const { id } = entry
|
|
9788
|
+
const marks = [
|
|
9789
|
+
...(isNew ? ['new'] : []),
|
|
9790
|
+
...(entry.reopened === undefined ? [] : ['reopened']),
|
|
9791
|
+
]
|
|
9792
|
+
const lines = [
|
|
9793
|
+
`### Candidate ${position}${marks.length === 0 ? '' : ` (${marks.join(', ')})`}`,
|
|
9794
|
+
'',
|
|
9795
|
+
]
|
|
9135
9796
|
lines.push(
|
|
9797
|
+
`- Fetch: \`/ce:connect fetch:${fetchWord(payload, fetchRepo)}\` (run ${payload.runId}, attempt ${payload.attempt})`,
|
|
9136
9798
|
'',
|
|
9137
|
-
|
|
9138
|
-
|
|
9799
|
+
fenceText(factsOf(id, payload)),
|
|
9800
|
+
)
|
|
9801
|
+
lines.push(
|
|
9802
|
+
'',
|
|
9803
|
+
decisionLine(id, 'promoted', false, revision),
|
|
9804
|
+
decisionLine(id, 'rejected', false, revision),
|
|
9139
9805
|
'',
|
|
9140
9806
|
)
|
|
9141
9807
|
return lines.join(`
|
|
@@ -9152,11 +9818,10 @@ function ranges(positions) {
|
|
|
9152
9818
|
.map(([from, to]) => (from === to ? `${from}` : `${from}-${to}`))
|
|
9153
9819
|
.join(', ')
|
|
9154
9820
|
}
|
|
9155
|
-
function fetchLines(rows) {
|
|
9821
|
+
function fetchLines(rows, repo) {
|
|
9156
9822
|
const byFetch = new Map()
|
|
9157
9823
|
rows.forEach((row, index) => {
|
|
9158
|
-
|
|
9159
|
-
const word = fetchWord(row.payload)
|
|
9824
|
+
const word = fetchWord(row.payload, repo)
|
|
9160
9825
|
const list = byFetch.get(word) ?? []
|
|
9161
9826
|
list.push(index + 1)
|
|
9162
9827
|
byFetch.set(word, list)
|
|
@@ -9192,11 +9857,31 @@ function hiddenLine(hidden) {
|
|
|
9192
9857
|
const noun = hidden === 1 ? 'candidate is' : 'candidates are'
|
|
9193
9858
|
return `**${hidden} open ${noun} not shown.** They stay open and appear here, oldest first, as the ones above are settled.`
|
|
9194
9859
|
}
|
|
9195
|
-
function
|
|
9860
|
+
function unverifiedSection(ids, named) {
|
|
9861
|
+
if (ids.length === 0) return []
|
|
9862
|
+
const listed = ids.slice(0, named).map((id) => `\`${id}\``)
|
|
9863
|
+
const more = ids.length - listed.length
|
|
9864
|
+
const count =
|
|
9865
|
+
ids.length === 1
|
|
9866
|
+
? '1 open candidate has'
|
|
9867
|
+
: `${ids.length} open candidates have`
|
|
9868
|
+
const list =
|
|
9869
|
+
listed.length === 0
|
|
9870
|
+
? ''
|
|
9871
|
+
: ` Oldest first: ${listed.join(', ')}${more > 0 ? `, and ${more} more` : ''}.`
|
|
9872
|
+
return [
|
|
9873
|
+
UNVERIFIED_HEADING,
|
|
9874
|
+
'',
|
|
9875
|
+
`${count} no verified details for the current revision, so there is nothing to tick.${list}`,
|
|
9876
|
+
'',
|
|
9877
|
+
]
|
|
9878
|
+
}
|
|
9879
|
+
var UNVERIFIED_HEADING = '## No verified details'
|
|
9880
|
+
function assembleReport(input, shown, named) {
|
|
9196
9881
|
const rows = input.rows.slice(0, shown)
|
|
9197
9882
|
const ids = rows.map((row) => row.id)
|
|
9198
9883
|
const hash = manifestHash(ids)
|
|
9199
|
-
const fetch = fetchLines(rows)
|
|
9884
|
+
const fetch = fetchLines(rows, input.fetchRepo)
|
|
9200
9885
|
const fresh = rows.filter((row) => row.isNew).length
|
|
9201
9886
|
const open = input.rows.length
|
|
9202
9887
|
const out = [manifestMarker(hash), '', ...headOf(input)]
|
|
@@ -9221,6 +9906,7 @@ function assemble(input, shown) {
|
|
|
9221
9906
|
for (const row of rows) out.push(row.block)
|
|
9222
9907
|
out.push(DECISIONS_END, '')
|
|
9223
9908
|
if (shown < open) out.push(hiddenLine(open - shown), '')
|
|
9909
|
+
out.push(...unverifiedSection(input.unverified, named))
|
|
9224
9910
|
return {
|
|
9225
9911
|
body: out.join(`
|
|
9226
9912
|
`),
|
|
@@ -9230,18 +9916,32 @@ function assemble(input, shown) {
|
|
|
9230
9916
|
fresh,
|
|
9231
9917
|
}
|
|
9232
9918
|
}
|
|
9233
|
-
function
|
|
9919
|
+
function rowsThatFit(input, named) {
|
|
9234
9920
|
const total = input.rows.length
|
|
9235
|
-
|
|
9921
|
+
const fits = (count) =>
|
|
9922
|
+
assembleReport(input, count, named).body.length <= REPORT_MAX_CHARS
|
|
9923
|
+
if (fits(total)) return total
|
|
9236
9924
|
let low = 0
|
|
9237
9925
|
let high = total - 1
|
|
9238
9926
|
while (low < high) {
|
|
9239
9927
|
const middle = Math.ceil((low + high) / 2)
|
|
9240
|
-
if (
|
|
9928
|
+
if (fits(middle)) low = middle
|
|
9241
9929
|
else high = middle - 1
|
|
9242
9930
|
}
|
|
9243
9931
|
return low
|
|
9244
9932
|
}
|
|
9933
|
+
function fitReport(input) {
|
|
9934
|
+
const wanted = Math.min(1, input.rows.length)
|
|
9935
|
+
for (
|
|
9936
|
+
let named = Math.min(MAX_UNVERIFIED_IDS, input.unverified.length);
|
|
9937
|
+
named > 0;
|
|
9938
|
+
named = Math.floor(named / 2)
|
|
9939
|
+
) {
|
|
9940
|
+
const shown = rowsThatFit(input, named)
|
|
9941
|
+
if (shown >= wanted) return { shown, named }
|
|
9942
|
+
}
|
|
9943
|
+
return { shown: rowsThatFit(input, 0), named: 0 }
|
|
9944
|
+
}
|
|
9245
9945
|
function openOldestFirst(entries) {
|
|
9246
9946
|
return entries
|
|
9247
9947
|
.filter((entry) => entry.status === 'candidate')
|
|
@@ -9255,7 +9955,11 @@ function proposed(run, open, request) {
|
|
|
9255
9955
|
const out = new Map()
|
|
9256
9956
|
for (const raw of run?.candidates ?? []) {
|
|
9257
9957
|
if (!isRecord4(raw) || !isCandidateId(raw.id) || !open.has(raw.id)) continue
|
|
9258
|
-
const text = payloadText(
|
|
9958
|
+
const text = payloadText(
|
|
9959
|
+
raw,
|
|
9960
|
+
run?.commitByRoot ?? new Map(),
|
|
9961
|
+
run?.repoByRoot ?? new Map(),
|
|
9962
|
+
)
|
|
9259
9963
|
if (text === undefined) continue
|
|
9260
9964
|
const target = typeof raw.target === 'string' ? raw.target : undefined
|
|
9261
9965
|
const repo = target === undefined ? undefined : run?.repoByRoot.get(target)
|
|
@@ -9265,6 +9969,7 @@ function proposed(run, open, request) {
|
|
|
9265
9969
|
...(repo === undefined ? {} : { repo }),
|
|
9266
9970
|
runId: request.runId,
|
|
9267
9971
|
attempt: request.attempt,
|
|
9972
|
+
...revisionField(raw.revision),
|
|
9268
9973
|
})
|
|
9269
9974
|
}
|
|
9270
9975
|
return out
|
|
@@ -9272,18 +9977,19 @@ function proposed(run, open, request) {
|
|
|
9272
9977
|
function mergedPayloads(open, stored, fresh) {
|
|
9273
9978
|
const out = new Map()
|
|
9274
9979
|
for (const entry of open) {
|
|
9980
|
+
const live = revisionOf(entry)
|
|
9275
9981
|
const earlier = stored.get(entry.id)
|
|
9276
|
-
const
|
|
9277
|
-
const
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9982
|
+
const proposedNow = fresh.get(entry.id)
|
|
9983
|
+
const chosen =
|
|
9984
|
+
[proposedNow, earlier].find((bundle) => bundle?.revision === live) ??
|
|
9985
|
+
proposedNow ??
|
|
9986
|
+
earlier
|
|
9987
|
+
if (chosen === undefined) continue
|
|
9988
|
+
const firstShown = chosen.firstShown ?? earlier?.firstShown
|
|
9989
|
+
out.set(entry.id, {
|
|
9990
|
+
...chosen,
|
|
9991
|
+
...(firstShown === undefined ? {} : { firstShown }),
|
|
9992
|
+
})
|
|
9287
9993
|
}
|
|
9288
9994
|
return out
|
|
9289
9995
|
}
|
|
@@ -9298,17 +10004,25 @@ function factLines(invocation, run) {
|
|
|
9298
10004
|
}
|
|
9299
10005
|
return lines
|
|
9300
10006
|
}
|
|
9301
|
-
function rowsOf(open, payloads, date) {
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
10007
|
+
function rowsOf(open, payloads, date, fetchRepo) {
|
|
10008
|
+
const rows = []
|
|
10009
|
+
const unverified = []
|
|
10010
|
+
for (const entry of open) {
|
|
10011
|
+
const held = payloads.get(entry.id)
|
|
10012
|
+
const revision = revisionOf(entry)
|
|
10013
|
+
if (held === undefined || held.revision !== revision) {
|
|
10014
|
+
unverified.push(entry.id)
|
|
10015
|
+
continue
|
|
10016
|
+
}
|
|
10017
|
+
const isNew = (held.firstShown ?? date) === date
|
|
10018
|
+
rows.push({
|
|
9306
10019
|
id: entry.id,
|
|
9307
|
-
payload,
|
|
10020
|
+
payload: held,
|
|
9308
10021
|
isNew,
|
|
9309
|
-
block: blockOf(
|
|
9310
|
-
}
|
|
9311
|
-
}
|
|
10022
|
+
block: blockOf(rows.length + 1, entry, revision, held, isNew, fetchRepo),
|
|
10023
|
+
})
|
|
10024
|
+
}
|
|
10025
|
+
return { rows, unverified }
|
|
9312
10026
|
}
|
|
9313
10027
|
function loadStores(root, recordState) {
|
|
9314
10028
|
const payloads = readPayloadStore(root)
|
|
@@ -9348,15 +10062,19 @@ function renderState(root, request, recordState) {
|
|
|
9348
10062
|
proposed(run, new Set(open.map((entry) => entry.id)), request),
|
|
9349
10063
|
)
|
|
9350
10064
|
const outcome = outcomeOf(invocation)
|
|
10065
|
+
const fetchRepo = fetchRepoOf(request)
|
|
10066
|
+
const { rows, unverified } = rowsOf(open, payloads, request.date, fetchRepo)
|
|
9351
10067
|
const input = {
|
|
9352
10068
|
outcome,
|
|
9353
10069
|
facts: factLines(invocation, run),
|
|
9354
10070
|
cacheRestored: request.cacheRestored,
|
|
9355
10071
|
stateUpdated: recordState,
|
|
9356
|
-
rows
|
|
10072
|
+
rows,
|
|
10073
|
+
unverified,
|
|
10074
|
+
...(fetchRepo === undefined ? {} : { fetchRepo }),
|
|
9357
10075
|
}
|
|
9358
|
-
const shown =
|
|
9359
|
-
const result =
|
|
10076
|
+
const { shown, named } = fitReport(input)
|
|
10077
|
+
const result = assembleReport(input, shown, named)
|
|
9360
10078
|
for (const id of result.ids) {
|
|
9361
10079
|
const payload = payloads.get(id)
|
|
9362
10080
|
if (payload !== undefined && payload.firstShown === undefined) {
|
|
@@ -9390,7 +10108,8 @@ function renderState(root, request, recordState) {
|
|
|
9390
10108
|
manifest: result.hash,
|
|
9391
10109
|
open: open.length,
|
|
9392
10110
|
shown,
|
|
9393
|
-
hidden:
|
|
10111
|
+
hidden: rows.length - shown,
|
|
10112
|
+
unverified: unverified.length,
|
|
9394
10113
|
fresh: result.fresh,
|
|
9395
10114
|
fetches: result.fetches,
|
|
9396
10115
|
outcome,
|
|
@@ -9439,10 +10158,10 @@ function tickedBoxes(boxes) {
|
|
|
9439
10158
|
const seen = new Set()
|
|
9440
10159
|
const out = []
|
|
9441
10160
|
for (const box of boxes) {
|
|
9442
|
-
const key = `${box.id}:${box.status}`
|
|
10161
|
+
const key = `${box.id}:${box.status}:${box.revision ?? ''}`
|
|
9443
10162
|
if (!box.ticked || seen.has(key)) continue
|
|
9444
10163
|
seen.add(key)
|
|
9445
|
-
out.push({ id: box.id, status: box.status })
|
|
10164
|
+
out.push({ id: box.id, status: box.status, revision: box.revision })
|
|
9446
10165
|
}
|
|
9447
10166
|
return out
|
|
9448
10167
|
}
|
|
@@ -9458,18 +10177,19 @@ function emptyApplied(section) {
|
|
|
9458
10177
|
function groupById(ticks) {
|
|
9459
10178
|
const byId = new Map()
|
|
9460
10179
|
for (const tick of ticks) {
|
|
9461
|
-
byId.set(tick.id, [...(byId.get(tick.id) ?? []), tick
|
|
10180
|
+
byId.set(tick.id, [...(byId.get(tick.id) ?? []), tick])
|
|
9462
10181
|
}
|
|
9463
10182
|
return byId
|
|
9464
10183
|
}
|
|
9465
|
-
function judge(id,
|
|
9466
|
-
const [
|
|
9467
|
-
if (
|
|
10184
|
+
function judge(id, ticks, manifest, entry, reason) {
|
|
10185
|
+
const [first] = ticks
|
|
10186
|
+
if (first === undefined) return
|
|
10187
|
+
const { status } = first
|
|
9468
10188
|
const skip = (why) => ({
|
|
9469
10189
|
kind: 'skip',
|
|
9470
10190
|
skipped: { id, status, reason: why },
|
|
9471
10191
|
})
|
|
9472
|
-
if (
|
|
10192
|
+
if (ticks.length > 1) {
|
|
9473
10193
|
return { kind: 'skip', skipped: { id, reason: 'conflict' } }
|
|
9474
10194
|
}
|
|
9475
10195
|
if (!manifest.ids.includes(id)) return skip('not-in-manifest')
|
|
@@ -9479,23 +10199,30 @@ function judge(id, statuses, manifest, entry, reason) {
|
|
|
9479
10199
|
unresolved: { id, status, reason: 'unknown-candidate' },
|
|
9480
10200
|
}
|
|
9481
10201
|
}
|
|
10202
|
+
if (first.revision === undefined) return skip('unversioned')
|
|
10203
|
+
const current = revisionOf(entry)
|
|
10204
|
+
if (first.revision !== current) return skip('stale')
|
|
9482
10205
|
if (entry.status === status && entry.reason === reason) {
|
|
9483
10206
|
return skip('already-recorded')
|
|
9484
10207
|
}
|
|
9485
10208
|
if (entry.status !== 'candidate') return skip('not-open')
|
|
9486
|
-
return { kind: 'record', tick: {
|
|
10209
|
+
return { kind: 'record', tick: { ...first, revision: current } }
|
|
9487
10210
|
}
|
|
9488
10211
|
function triage(ticks, manifest, entries, reason) {
|
|
9489
10212
|
const out = { record: [], skipped: [], unresolved: [] }
|
|
9490
10213
|
if (manifest === undefined) {
|
|
9491
10214
|
for (const tick of ticks) {
|
|
9492
|
-
out.unresolved.push({
|
|
10215
|
+
out.unresolved.push({
|
|
10216
|
+
id: tick.id,
|
|
10217
|
+
status: tick.status,
|
|
10218
|
+
reason: 'manifest-missing',
|
|
10219
|
+
})
|
|
9493
10220
|
}
|
|
9494
10221
|
return out
|
|
9495
10222
|
}
|
|
9496
|
-
for (const [id,
|
|
10223
|
+
for (const [id, group] of groupById(ticks)) {
|
|
9497
10224
|
const entry = entries.find((item) => item.id === id)
|
|
9498
|
-
const verdict = judge(id,
|
|
10225
|
+
const verdict = judge(id, group, manifest, entry, reason)
|
|
9499
10226
|
if (verdict?.kind === 'record') out.record.push(verdict.tick)
|
|
9500
10227
|
else if (verdict?.kind === 'skip') out.skipped.push(verdict.skipped)
|
|
9501
10228
|
else if (verdict?.kind === 'unresolved') {
|
|
@@ -9509,6 +10236,10 @@ function failureOf(reason) {
|
|
|
9509
10236
|
? reason
|
|
9510
10237
|
: 'write-failed'
|
|
9511
10238
|
}
|
|
10239
|
+
function skipReasonOf(reason) {
|
|
10240
|
+
if (reason === 'not-open') return 'not-open'
|
|
10241
|
+
return reason === 'stale-revision' ? 'stale' : undefined
|
|
10242
|
+
}
|
|
9512
10243
|
function applyTicks(root, request, options = {}) {
|
|
9513
10244
|
if (!Number.isSafeInteger(request.issue) || request.issue < 1) {
|
|
9514
10245
|
return { status: 'failed', reason: 'invalid-request', accepted: [] }
|
|
@@ -9535,20 +10266,27 @@ function applyTicks(root, request, options = {}) {
|
|
|
9535
10266
|
for (const tick of sorted.record) {
|
|
9536
10267
|
const decided = decideLedgerEntry(
|
|
9537
10268
|
root,
|
|
9538
|
-
{
|
|
10269
|
+
{
|
|
10270
|
+
id: tick.id,
|
|
10271
|
+
status: tick.status,
|
|
10272
|
+
reason,
|
|
10273
|
+
onlyIfOpen: true,
|
|
10274
|
+
revision: tick.revision,
|
|
10275
|
+
},
|
|
9539
10276
|
lockOptions(options),
|
|
9540
10277
|
)
|
|
9541
10278
|
if (decided.status === 'busy') {
|
|
9542
10279
|
return { status: 'busy', reason: decided.reason, accepted }
|
|
9543
10280
|
}
|
|
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
10281
|
if (decided.status === 'failed') {
|
|
9549
|
-
|
|
10282
|
+
const why = skipReasonOf(decided.reason)
|
|
10283
|
+
if (why === undefined) {
|
|
10284
|
+
return { status: 'failed', reason: failureOf(decided.reason), accepted }
|
|
10285
|
+
}
|
|
10286
|
+
skipped.push({ id: tick.id, status: tick.status, reason: why })
|
|
10287
|
+
continue
|
|
9550
10288
|
}
|
|
9551
|
-
accepted.push(tick)
|
|
10289
|
+
accepted.push({ id: tick.id, status: tick.status })
|
|
9552
10290
|
}
|
|
9553
10291
|
return {
|
|
9554
10292
|
status: 'applied',
|
|
@@ -9570,7 +10308,7 @@ var MAX_ROOT_LENGTH = 4096
|
|
|
9570
10308
|
var RUN_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
|
|
9571
10309
|
var PROJECT_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/
|
|
9572
10310
|
var REPO_SLUG2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
|
|
9573
|
-
var
|
|
10311
|
+
var OBJECT_ID4 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
9574
10312
|
var CANDIDATE_ID2 = /^[0-9a-f]{64}$/
|
|
9575
10313
|
var CONTROL2 = /[\p{Cc}\p{Cf}]/u
|
|
9576
10314
|
var CORPUS_PATH = /^docs\/(?:solutions|plans|brainstorms)\//
|
|
@@ -9601,7 +10339,7 @@ function parseProject(value) {
|
|
|
9601
10339
|
}
|
|
9602
10340
|
if (
|
|
9603
10341
|
commit !== undefined &&
|
|
9604
|
-
!(typeof commit === 'string' &&
|
|
10342
|
+
!(typeof commit === 'string' && OBJECT_ID4.test(commit))
|
|
9605
10343
|
) {
|
|
9606
10344
|
return
|
|
9607
10345
|
}
|
|
@@ -9724,6 +10462,10 @@ var REFUSAL_TEXT = Object.freeze({
|
|
|
9724
10462
|
'file-vanished': 'a cited file is gone from the local checkout',
|
|
9725
10463
|
'check-failed': 'the candidate failed a check against the local files',
|
|
9726
10464
|
})
|
|
10465
|
+
function evidenceRemedy(repo) {
|
|
10466
|
+
const named = repo === undefined ? 'that repository' : repo
|
|
10467
|
+
return `allow-list a checkout of ${named} (at the pinned ref for a dependency), then import again`
|
|
10468
|
+
}
|
|
9727
10469
|
function fileRefs(value, max) {
|
|
9728
10470
|
if (value === undefined) return []
|
|
9729
10471
|
if (!Array.isArray(value) || value.length > max) return
|
|
@@ -9791,14 +10533,30 @@ function shapeOf(raw) {
|
|
|
9791
10533
|
title: raw.title,
|
|
9792
10534
|
summary: raw.summary,
|
|
9793
10535
|
nextStep: raw.nextStep,
|
|
10536
|
+
reason: raw.reason,
|
|
9794
10537
|
overlapCheck: raw.overlapCheck,
|
|
9795
10538
|
sources,
|
|
9796
10539
|
counterevidence,
|
|
9797
10540
|
targetEvidence,
|
|
9798
10541
|
}
|
|
9799
10542
|
}
|
|
10543
|
+
function mismatchIdentity(shape) {
|
|
10544
|
+
const [claim] = shape.sources
|
|
10545
|
+
if (
|
|
10546
|
+
shape.kind !== 'code-mismatch' ||
|
|
10547
|
+
!isMismatchReason(shape.reason) ||
|
|
10548
|
+
claim === undefined
|
|
10549
|
+
) {
|
|
10550
|
+
return
|
|
10551
|
+
}
|
|
10552
|
+
return {
|
|
10553
|
+
mismatchReason: shape.reason,
|
|
10554
|
+
claim: claimFingerprint(claim.excerpt),
|
|
10555
|
+
}
|
|
10556
|
+
}
|
|
9800
10557
|
function recordedIdentity(shape) {
|
|
9801
10558
|
return candidateIdentity({
|
|
10559
|
+
...mismatchIdentity(shape),
|
|
9802
10560
|
kind: shape.kind,
|
|
9803
10561
|
target: shape.target,
|
|
9804
10562
|
ruleId: shape.ruleId,
|
|
@@ -9843,6 +10601,13 @@ function createLandings(projects, locals, factsFor) {
|
|
|
9843
10601
|
},
|
|
9844
10602
|
}
|
|
9845
10603
|
}
|
|
10604
|
+
function unmappedRemedy(shape, root, reason, repo) {
|
|
10605
|
+
const evidenceProject =
|
|
10606
|
+
shape.kind === 'code-mismatch' &&
|
|
10607
|
+
reason === 'repo-not-allowed' &&
|
|
10608
|
+
shape.counterevidence.some((source) => source.project === root)
|
|
10609
|
+
return evidenceProject ? { remedy: evidenceRemedy(repo) } : {}
|
|
10610
|
+
}
|
|
9846
10611
|
function land(shape, landings) {
|
|
9847
10612
|
const roots = new Set([
|
|
9848
10613
|
shape.target,
|
|
@@ -9860,6 +10625,7 @@ function land(shape, landings) {
|
|
|
9860
10625
|
return refuse(mapping.reason, {
|
|
9861
10626
|
...(mapping.keys === undefined ? {} : { keys: mapping.keys }),
|
|
9862
10627
|
...(project.repo === undefined ? {} : { repo: project.repo }),
|
|
10628
|
+
...unmappedRemedy(shape, root, mapping.reason, project.repo),
|
|
9863
10629
|
})
|
|
9864
10630
|
}
|
|
9865
10631
|
const facts = landings.factsOf(mapping.local)
|
|
@@ -9930,6 +10696,11 @@ function localRaw(shape, ruleId, landed) {
|
|
|
9930
10696
|
fingerprint: ref.fingerprint,
|
|
9931
10697
|
excerpt: ref.excerpt,
|
|
9932
10698
|
})
|
|
10699
|
+
const evidence = (ref) => ({
|
|
10700
|
+
...source(ref),
|
|
10701
|
+
...(ref.rest.start === undefined ? {} : { start: ref.rest.start }),
|
|
10702
|
+
...(ref.rest.end === undefined ? {} : { end: ref.rest.end }),
|
|
10703
|
+
})
|
|
9933
10704
|
return {
|
|
9934
10705
|
kind: shape.kind,
|
|
9935
10706
|
ruleId,
|
|
@@ -9937,6 +10708,7 @@ function localRaw(shape, ruleId, landed) {
|
|
|
9937
10708
|
title: shape.title,
|
|
9938
10709
|
summary: shape.summary,
|
|
9939
10710
|
nextStep: shape.nextStep,
|
|
10711
|
+
...(shape.reason === undefined ? {} : { reason: shape.reason }),
|
|
9940
10712
|
overlapCheck: shape.overlapCheck,
|
|
9941
10713
|
sources: shape.sources.map(source),
|
|
9942
10714
|
targetEvidence: shape.targetEvidence.map((item) => ({
|
|
@@ -9947,7 +10719,7 @@ function localRaw(shape, ruleId, landed) {
|
|
|
9947
10719
|
fingerprint: item.fingerprint,
|
|
9948
10720
|
excerpt: item.excerpt,
|
|
9949
10721
|
})),
|
|
9950
|
-
counterevidence: shape.counterevidence.map(
|
|
10722
|
+
counterevidence: shape.counterevidence.map(evidence),
|
|
9951
10723
|
}
|
|
9952
10724
|
}
|
|
9953
10725
|
function contextOf(landed) {
|
|
@@ -9994,6 +10766,9 @@ function verifyOne(raw, landings, seen) {
|
|
|
9994
10766
|
return {
|
|
9995
10767
|
recordedId: shape.id,
|
|
9996
10768
|
candidate: checked.candidate,
|
|
10769
|
+
evidenceHeads: shape.counterevidence.map(
|
|
10770
|
+
(ref) => landings.projectOf(ref.project)?.commit,
|
|
10771
|
+
),
|
|
9997
10772
|
record,
|
|
9998
10773
|
id: candidateIdentity(record),
|
|
9999
10774
|
}
|
|
@@ -10095,9 +10870,10 @@ function refusalLines(refused) {
|
|
|
10095
10870
|
item.keys === undefined
|
|
10096
10871
|
? ''
|
|
10097
10872
|
: ` Local project keys: ${item.keys.map(inline).join(', ')}.`
|
|
10873
|
+
const remedy = item.remedy === undefined ? '' : ` Fix: ${item.remedy}.`
|
|
10098
10874
|
out.push(
|
|
10099
10875
|
quote(item.title),
|
|
10100
|
-
` ${item.reason}${detail}: ${item.reasonText}.${where}${keys}`,
|
|
10876
|
+
` ${item.reason}${detail}: ${item.reasonText}.${where}${keys}${remedy}`,
|
|
10101
10877
|
)
|
|
10102
10878
|
}
|
|
10103
10879
|
return out
|
|
@@ -10186,137 +10962,67 @@ function renderImportDigest(model, written, generatedAt) {
|
|
|
10186
10962
|
`
|
|
10187
10963
|
}
|
|
10188
10964
|
|
|
10189
|
-
// src/lib/connect-
|
|
10190
|
-
var
|
|
10191
|
-
var
|
|
10192
|
-
var
|
|
10193
|
-
var
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
var
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
function normalizeGithubRemote(url) {
|
|
10209
|
-
const match =
|
|
10210
|
-
HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
|
|
10211
|
-
const rest = match?.[1]
|
|
10212
|
-
return rest === undefined ? undefined : ownerAndRepo(rest)
|
|
10213
|
-
}
|
|
10214
|
-
function configValue(raw) {
|
|
10215
|
-
let out = ''
|
|
10216
|
-
let quoted = false
|
|
10217
|
-
for (const ch of raw.trim()) {
|
|
10218
|
-
if (ch === '"') {
|
|
10219
|
-
quoted = !quoted
|
|
10220
|
-
continue
|
|
10221
|
-
}
|
|
10222
|
-
if (!quoted && (ch === '#' || ch === ';')) break
|
|
10223
|
-
out += ch
|
|
10965
|
+
// src/lib/connect-provenance.ts
|
|
10966
|
+
var OWNER_REPO = 'marcusrbrown/systematic'
|
|
10967
|
+
var WORKFLOW_FILE = '/.github/workflows/connect.yaml'
|
|
10968
|
+
var FULL_SHA = /^[0-9a-f]{40}$/
|
|
10969
|
+
var UNPROVABLE = {
|
|
10970
|
+
status: 'refused',
|
|
10971
|
+
reason: 'provenance-unprovable',
|
|
10972
|
+
}
|
|
10973
|
+
var NOT_A_CONNECT_RUN = {
|
|
10974
|
+
status: 'refused',
|
|
10975
|
+
reason: 'not-a-connect-run',
|
|
10976
|
+
}
|
|
10977
|
+
function parseList(text) {
|
|
10978
|
+
if (typeof text !== 'string') return
|
|
10979
|
+
try {
|
|
10980
|
+
const value = JSON.parse(text)
|
|
10981
|
+
return Array.isArray(value) && value.length > 0 ? value : undefined
|
|
10982
|
+
} catch {
|
|
10983
|
+
return
|
|
10224
10984
|
}
|
|
10225
|
-
return out.trim()
|
|
10226
|
-
}
|
|
10227
|
-
function isOriginSection(header) {
|
|
10228
|
-
const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
|
|
10229
|
-
return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
|
|
10230
10985
|
}
|
|
10231
|
-
function
|
|
10232
|
-
|
|
10233
|
-
for (const
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
if (line.startsWith('[')) {
|
|
10237
|
-
const end = line.indexOf(']')
|
|
10238
|
-
if (end === -1) {
|
|
10239
|
-
inOrigin = false
|
|
10240
|
-
continue
|
|
10241
|
-
}
|
|
10242
|
-
inOrigin = isOriginSection(line.slice(1, end))
|
|
10243
|
-
line = line.slice(end + 1).trim()
|
|
10986
|
+
function pathsOf(list) {
|
|
10987
|
+
const paths = []
|
|
10988
|
+
for (const entry of list) {
|
|
10989
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
10990
|
+
return
|
|
10244
10991
|
}
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10992
|
+
const { path } = entry
|
|
10993
|
+
if (typeof path !== 'string') return
|
|
10994
|
+
paths.push(path)
|
|
10248
10995
|
}
|
|
10249
|
-
return
|
|
10250
|
-
}
|
|
10251
|
-
var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
10252
|
-
var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
|
|
10253
|
-
function readGitText(mainRoot, rel, maxBytes) {
|
|
10254
|
-
const read = readContainedFile(mainRoot, rel, { maxBytes })
|
|
10255
|
-
return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
|
|
10996
|
+
return paths
|
|
10256
10997
|
}
|
|
10257
|
-
function
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
`
|
|
10261
|
-
`,
|
|
10262
|
-
1,
|
|
10263
|
-
)[0] ?? ''
|
|
10264
|
-
)
|
|
10265
|
-
.replace(/\r$/, '')
|
|
10266
|
-
.trim()
|
|
10998
|
+
function workflowOf(path) {
|
|
10999
|
+
const at = path.indexOf('@')
|
|
11000
|
+
return at === -1 ? path : path.slice(0, at)
|
|
10267
11001
|
}
|
|
10268
|
-
function
|
|
11002
|
+
function isSystematicConnect(path) {
|
|
11003
|
+
const workflow = workflowOf(path)
|
|
10269
11004
|
return (
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
.split('/')
|
|
10273
|
-
.every(
|
|
10274
|
-
(part) =>
|
|
10275
|
-
part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
|
|
10276
|
-
)
|
|
10277
|
-
)
|
|
10278
|
-
}
|
|
10279
|
-
function packedRef(packed, ref) {
|
|
10280
|
-
for (const raw of packed.split(`
|
|
10281
|
-
`)) {
|
|
10282
|
-
const line = raw.trim()
|
|
10283
|
-
if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
|
|
10284
|
-
const [id, name, ...rest] = line.split(/\s+/)
|
|
10285
|
-
if (rest.length === 0 && name === ref && OBJECT_ID3.test(id ?? ''))
|
|
10286
|
-
return id
|
|
10287
|
-
}
|
|
10288
|
-
return
|
|
10289
|
-
}
|
|
10290
|
-
function headCommit(mainRoot) {
|
|
10291
|
-
const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
|
|
10292
|
-
if (head === undefined) return
|
|
10293
|
-
const line = firstLine2(head)
|
|
10294
|
-
if (OBJECT_ID3.test(line)) return line
|
|
10295
|
-
const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
|
|
10296
|
-
if (symbolic === undefined || !safeRefName(symbolic)) return
|
|
10297
|
-
const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
|
|
10298
|
-
const looseId = loose === undefined ? '' : firstLine2(loose)
|
|
10299
|
-
if (OBJECT_ID3.test(looseId)) return looseId
|
|
10300
|
-
const packed = readGitText(
|
|
10301
|
-
mainRoot,
|
|
10302
|
-
'.git/packed-refs',
|
|
10303
|
-
MAX_PACKED_REFS_BYTES,
|
|
11005
|
+
workflow.endsWith(WORKFLOW_FILE) &&
|
|
11006
|
+
workflow.slice(0, -WORKFLOW_FILE.length).toLowerCase() === OWNER_REPO
|
|
10304
11007
|
)
|
|
10305
|
-
return packed === undefined ? undefined : packedRef(packed, symbolic)
|
|
10306
11008
|
}
|
|
10307
|
-
function
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
11009
|
+
function verifyProvenance(input) {
|
|
11010
|
+
const list = parseList(input.referencedWorkflows)
|
|
11011
|
+
if (list === undefined) return UNPROVABLE
|
|
11012
|
+
const paths = pathsOf(list)
|
|
11013
|
+
if (paths === undefined) return UNPROVABLE
|
|
11014
|
+
const matches = list.filter((_entry, index) => {
|
|
11015
|
+
const path = paths[index]
|
|
11016
|
+
return path !== undefined && isSystematicConnect(path)
|
|
11017
|
+
})
|
|
11018
|
+
if (matches.length === 0) return NOT_A_CONNECT_RUN
|
|
11019
|
+
if (matches.length > 1) return UNPROVABLE
|
|
11020
|
+
const { sha } = matches[0]
|
|
11021
|
+
if (typeof sha !== 'string' || !FULL_SHA.test(sha)) return UNPROVABLE
|
|
11022
|
+
if (input.status === undefined) return { status: 'selected', sha }
|
|
11023
|
+
return input.status === 'behind' || input.status === 'identical'
|
|
11024
|
+
? { status: 'accepted', sha }
|
|
11025
|
+
: UNPROVABLE
|
|
10320
11026
|
}
|
|
10321
11027
|
|
|
10322
11028
|
// src/lib/main-module.ts
|
|
@@ -10349,7 +11055,7 @@ function isMainModule(moduleUrl, argv = process.argv) {
|
|
|
10349
11055
|
|
|
10350
11056
|
// src/ce-connect-helper.ts
|
|
10351
11057
|
var CE_CONNECT_USAGE =
|
|
10352
|
-
'Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|ledger show [--offset N]|ledger clear|ledger unlock>'
|
|
11058
|
+
'Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|allowed-origins|verify-provenance|ledger show [--offset N]|ledger clear|ledger unlock>'
|
|
10353
11059
|
var OPS = [
|
|
10354
11060
|
'begin',
|
|
10355
11061
|
'validate',
|
|
@@ -10358,6 +11064,8 @@ var OPS = [
|
|
|
10358
11064
|
'import',
|
|
10359
11065
|
'apply-ticks',
|
|
10360
11066
|
'render-report',
|
|
11067
|
+
'allowed-origins',
|
|
11068
|
+
'verify-provenance',
|
|
10361
11069
|
'ledger-show',
|
|
10362
11070
|
'ledger-clear',
|
|
10363
11071
|
'ledger-unlock',
|
|
@@ -10853,6 +11561,8 @@ function scanProject(entry, root, deps, limits) {
|
|
|
10853
11561
|
citationsChecked: report.citations.length,
|
|
10854
11562
|
citationsTruncated: report.truncated,
|
|
10855
11563
|
truncated: inventory.truncated.files || inventory.truncated.hashCap,
|
|
11564
|
+
skipped: inventory.skipped.map((file) => file.path),
|
|
11565
|
+
skipsUnnamed: inventory.skippedCount > inventory.skipped.length,
|
|
10856
11566
|
inventory: inventory.files.map((file) => ({
|
|
10857
11567
|
path: file.path,
|
|
10858
11568
|
role: file.role,
|
|
@@ -11099,6 +11809,7 @@ function indexRun(setup, deps) {
|
|
|
11099
11809
|
id: rule.id,
|
|
11100
11810
|
sha256: rule.sha256,
|
|
11101
11811
|
project: projectKey(rule.project),
|
|
11812
|
+
path: rule.path,
|
|
11102
11813
|
})),
|
|
11103
11814
|
coverageScope,
|
|
11104
11815
|
offer: {
|
|
@@ -11347,8 +12058,29 @@ function standingOf(outcome) {
|
|
|
11347
12058
|
}
|
|
11348
12059
|
return 'skip'
|
|
11349
12060
|
}
|
|
11350
|
-
function
|
|
11351
|
-
const
|
|
12061
|
+
function evidenceLookup(snapshot) {
|
|
12062
|
+
const projects = new Map(
|
|
12063
|
+
snapshot.projects.map((project) => [
|
|
12064
|
+
project.key,
|
|
12065
|
+
{
|
|
12066
|
+
complete: !project.truncated && !project.skipsUnnamed,
|
|
12067
|
+
skipped: new Set(project.skipped),
|
|
12068
|
+
files: new Map(project.inventory.map((f) => [f.path, f.sha256])),
|
|
12069
|
+
},
|
|
12070
|
+
]),
|
|
12071
|
+
)
|
|
12072
|
+
return (key, rel) => {
|
|
12073
|
+
const project = projects.get(key)
|
|
12074
|
+
if (project === undefined) return { status: 'unread' }
|
|
12075
|
+
const fingerprint = project.files.get(rel)
|
|
12076
|
+
if (fingerprint !== undefined) return { status: 'present', fingerprint }
|
|
12077
|
+
if (project.skipped.has(rel)) return { status: 'unread' }
|
|
12078
|
+
return project.complete ? { status: 'gone' } : { status: 'unread' }
|
|
12079
|
+
}
|
|
12080
|
+
}
|
|
12081
|
+
function classifyAgainstLedger(candidate, record, input, result) {
|
|
12082
|
+
const { ledger } = input
|
|
12083
|
+
const outcome = classifyCandidate(ledger, record, input.evidence)
|
|
11352
12084
|
const standing = standingOf(outcome)
|
|
11353
12085
|
if (standing === 'skip') {
|
|
11354
12086
|
if (outcome.standing === 'unresolved') result.unresolved++
|
|
@@ -11372,10 +12104,11 @@ function classifyAgainstLedger(candidate, record, ledger, result) {
|
|
|
11372
12104
|
: { refreshPointer: standing.refreshPointer }),
|
|
11373
12105
|
possibleMatches,
|
|
11374
12106
|
candidate,
|
|
12107
|
+
revision: revisionOfCandidate(record),
|
|
11375
12108
|
})
|
|
11376
12109
|
}
|
|
11377
12110
|
function reopensForChangedSources(record, input) {
|
|
11378
|
-
const outcome = classifyCandidate(input.ledger, record)
|
|
12111
|
+
const outcome = classifyCandidate(input.ledger, record, input.evidence)
|
|
11379
12112
|
return outcome.standing === 'reopened' && outcome.reason === 'sources changed'
|
|
11380
12113
|
}
|
|
11381
12114
|
function holdBack(raw, input, result) {
|
|
@@ -11406,7 +12139,10 @@ function classifyOne(raw, family, input, seen, result) {
|
|
|
11406
12139
|
return
|
|
11407
12140
|
}
|
|
11408
12141
|
seen.add(identity)
|
|
11409
|
-
const recorded =
|
|
12142
|
+
const recorded =
|
|
12143
|
+
check.candidate.kind === 'code-mismatch'
|
|
12144
|
+
? undefined
|
|
12145
|
+
: findRecorded(check.candidate, input.snapshot.provenance)
|
|
11410
12146
|
if (recorded !== undefined && !reopensForChangedSources(record, input)) {
|
|
11411
12147
|
result.recorded.push({
|
|
11412
12148
|
pointer: recorded.pointer,
|
|
@@ -11414,7 +12150,7 @@ function classifyOne(raw, family, input, seen, result) {
|
|
|
11414
12150
|
})
|
|
11415
12151
|
return
|
|
11416
12152
|
}
|
|
11417
|
-
classifyAgainstLedger(check.candidate, record, input
|
|
12153
|
+
classifyAgainstLedger(check.candidate, record, input, result)
|
|
11418
12154
|
}
|
|
11419
12155
|
function classifyBatches(batches, input, limits) {
|
|
11420
12156
|
const result = {
|
|
@@ -11460,8 +12196,13 @@ function classifyBatches(batches, input, limits) {
|
|
|
11460
12196
|
var MAX_UNREAD_LINES = 50
|
|
11461
12197
|
function coverageLines(coverage, snapshot, classified) {
|
|
11462
12198
|
const lines = []
|
|
12199
|
+
const learningUnread = new Set(coverage.learningUnreadRuleIds)
|
|
11463
12200
|
for (const id of coverage.uncoveredRuleIds.slice(0, MAX_UNREAD_LINES)) {
|
|
11464
|
-
lines.push(
|
|
12201
|
+
lines.push(
|
|
12202
|
+
learningUnread.has(id)
|
|
12203
|
+
? `rule ${id} was not covered: its learning was not among the files the family read`
|
|
12204
|
+
: `rule ${id} was not covered by a complete family`,
|
|
12205
|
+
)
|
|
11465
12206
|
}
|
|
11466
12207
|
if (coverage.uncoveredRuleIds.length > MAX_UNREAD_LINES) {
|
|
11467
12208
|
lines.push(
|
|
@@ -11510,6 +12251,7 @@ function validateResponse(runId, state, classified) {
|
|
|
11510
12251
|
...(item.refreshPointer === undefined
|
|
11511
12252
|
? {}
|
|
11512
12253
|
: { refreshPointer: item.refreshPointer }),
|
|
12254
|
+
...(item.revision === undefined ? {} : { revision: item.revision }),
|
|
11513
12255
|
})),
|
|
11514
12256
|
recorded: classified.recorded.map((item) => ({
|
|
11515
12257
|
pointer: item.pointer,
|
|
@@ -11556,13 +12298,35 @@ function runValidation(snapshot, workDir, batchesRead, ledger, deps) {
|
|
|
11556
12298
|
}
|
|
11557
12299
|
const classified = classifyBatches(
|
|
11558
12300
|
batches,
|
|
11559
|
-
{
|
|
12301
|
+
{
|
|
12302
|
+
ctx: contextFrom(snapshot),
|
|
12303
|
+
snapshot,
|
|
12304
|
+
ledger,
|
|
12305
|
+
evidence: evidenceLookup(snapshot),
|
|
12306
|
+
},
|
|
11560
12307
|
limits,
|
|
11561
12308
|
)
|
|
11562
12309
|
const coverage = checkCoverage({
|
|
11563
12310
|
ruleIds: snapshot.offer.offered,
|
|
11564
|
-
projects: snapshot.projects
|
|
12311
|
+
projects: snapshot.projects
|
|
12312
|
+
.filter((project) =>
|
|
12313
|
+
project.inventory.some((file) => file.role === 'learning'),
|
|
12314
|
+
)
|
|
12315
|
+
.map((project) => project.root),
|
|
11565
12316
|
batches,
|
|
12317
|
+
learningPaths: new Map(
|
|
12318
|
+
snapshot.ruleVersions.flatMap((rule) =>
|
|
12319
|
+
rule.path === undefined ? [] : [[rule.id, rule.path]],
|
|
12320
|
+
),
|
|
12321
|
+
),
|
|
12322
|
+
learningProjects: new Map(
|
|
12323
|
+
snapshot.ruleVersions.flatMap((rule) => {
|
|
12324
|
+
const root = snapshot.projects.find(
|
|
12325
|
+
(project) => project.key === rule.project,
|
|
12326
|
+
)?.root
|
|
12327
|
+
return root === undefined ? [] : [[rule.id, root]]
|
|
12328
|
+
}),
|
|
12329
|
+
),
|
|
11566
12330
|
})
|
|
11567
12331
|
const uncovered = new Set(coverage.uncoveredRuleIds)
|
|
11568
12332
|
const heldBackRuleIds = snapshot.offer.offered.filter(
|
|
@@ -11700,10 +12464,14 @@ function buildCandidateBlock(accepted) {
|
|
|
11700
12464
|
title: item.candidate.title,
|
|
11701
12465
|
summary: item.candidate.summary,
|
|
11702
12466
|
nextStep: item.candidate.nextStep,
|
|
12467
|
+
...(item.candidate.reason === undefined
|
|
12468
|
+
? {}
|
|
12469
|
+
: { reason: item.candidate.reason }),
|
|
11703
12470
|
overlapCheck: item.candidate.overlapCheck,
|
|
11704
12471
|
sources: item.candidate.sources,
|
|
11705
12472
|
targetEvidence: item.candidate.targetEvidence,
|
|
11706
12473
|
counterevidence: item.candidate.counterevidence,
|
|
12474
|
+
...(item.revision === undefined ? {} : { revision: item.revision }),
|
|
11707
12475
|
})),
|
|
11708
12476
|
}
|
|
11709
12477
|
}
|
|
@@ -11716,6 +12484,7 @@ function digestModel(snapshot, state, outcome, degradeReasons) {
|
|
|
11716
12484
|
: { refreshPointer: item.refreshPointer }),
|
|
11717
12485
|
possibleMatches: item.possibleMatches,
|
|
11718
12486
|
candidate: item.candidate,
|
|
12487
|
+
...(item.revision === undefined ? {} : { revision: item.revision }),
|
|
11719
12488
|
}))
|
|
11720
12489
|
const projects = snapshot.projects.map((project) => ({
|
|
11721
12490
|
name: project.name,
|
|
@@ -11723,6 +12492,10 @@ function digestModel(snapshot, state, outcome, degradeReasons) {
|
|
|
11723
12492
|
files: project.files,
|
|
11724
12493
|
citationsUnsupported: project.citationsUnsupported,
|
|
11725
12494
|
truncated: project.truncated,
|
|
12495
|
+
...(project.commit === undefined ? {} : { commit: project.commit }),
|
|
12496
|
+
...(project.inventory.some((file) => file.role === 'learning')
|
|
12497
|
+
? {}
|
|
12498
|
+
: { evidenceOnly: true }),
|
|
11726
12499
|
}))
|
|
11727
12500
|
return {
|
|
11728
12501
|
runId: snapshot.runId,
|
|
@@ -11852,6 +12625,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
|
|
|
11852
12625
|
candidates: state.accepted.map((item) =>
|
|
11853
12626
|
toCandidateRecord(item.candidate),
|
|
11854
12627
|
),
|
|
12628
|
+
evidence: evidenceLookup(snapshot),
|
|
11855
12629
|
coverage: {
|
|
11856
12630
|
runId: snapshot.runId,
|
|
11857
12631
|
indexed: snapshot.ruleVersions.map((rule) => ({
|
|
@@ -12000,19 +12774,24 @@ function publishRunOp(request, deps, ciMarker) {
|
|
|
12000
12774
|
)
|
|
12001
12775
|
}
|
|
12002
12776
|
}
|
|
12777
|
+
function isRevision2(value) {
|
|
12778
|
+
return typeof value === 'string' && /^[0-9a-f]{12}$/.test(value)
|
|
12779
|
+
}
|
|
12003
12780
|
function parseDecision(request) {
|
|
12004
12781
|
if (!isRecord6(request)) return
|
|
12005
|
-
const { id, status, reason, destination } = request
|
|
12782
|
+
const { id, status, reason, destination, revision } = request
|
|
12006
12783
|
if (typeof id !== 'string' || typeof reason !== 'string') return
|
|
12007
12784
|
if (status !== 'promoted' && status !== 'rejected') return
|
|
12008
12785
|
if (destination !== undefined && typeof destination !== 'string') {
|
|
12009
12786
|
return
|
|
12010
12787
|
}
|
|
12788
|
+
if (revision !== undefined && !isRevision2(revision)) return
|
|
12011
12789
|
return {
|
|
12012
12790
|
id,
|
|
12013
12791
|
status,
|
|
12014
12792
|
reason,
|
|
12015
12793
|
...(destination === undefined ? {} : { destination }),
|
|
12794
|
+
...(revision === undefined ? {} : { revision }),
|
|
12016
12795
|
}
|
|
12017
12796
|
}
|
|
12018
12797
|
function decisionResult(result) {
|
|
@@ -12036,6 +12815,11 @@ function decisionResult(result) {
|
|
|
12036
12815
|
body: { ok: false, op: 'decide', outcome: 'busy', reason: result.reason },
|
|
12037
12816
|
}
|
|
12038
12817
|
}
|
|
12818
|
+
if (result.reason === 'stale-revision') {
|
|
12819
|
+
return failure2('decide', result.reason, {
|
|
12820
|
+
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.',
|
|
12821
|
+
})
|
|
12822
|
+
}
|
|
12039
12823
|
return failure2('decide', result.reason)
|
|
12040
12824
|
}
|
|
12041
12825
|
function decide(request, deps) {
|
|
@@ -12161,6 +12945,12 @@ function ledgerShow(request, deps) {
|
|
|
12161
12945
|
? {}
|
|
12162
12946
|
: { destination: entry.destination }),
|
|
12163
12947
|
...(entry.reopened === undefined ? {} : { reopened: entry.reopened }),
|
|
12948
|
+
...(entry.reopenedFor === undefined
|
|
12949
|
+
? {}
|
|
12950
|
+
: { reopenedFor: entry.reopenedFor }),
|
|
12951
|
+
...(entry.mismatchReason === undefined
|
|
12952
|
+
? {}
|
|
12953
|
+
: { mismatchReason: entry.mismatchReason }),
|
|
12164
12954
|
sources: entry.sources.map((source) => ({
|
|
12165
12955
|
role: source.role,
|
|
12166
12956
|
path: source.path,
|
|
@@ -12207,7 +12997,6 @@ function ledgerUnlock(deps) {
|
|
|
12207
12997
|
: {}),
|
|
12208
12998
|
})
|
|
12209
12999
|
}
|
|
12210
|
-
var GITHUB_REPO = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/
|
|
12211
13000
|
var GITHUB_RUN_ID = /^[0-9]{1,20}$/
|
|
12212
13001
|
var COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
12213
13002
|
var MAX_DIRECTORY_LENGTH = 4096
|
|
@@ -12225,7 +13014,7 @@ function parseImportRequest(request) {
|
|
|
12225
13014
|
}
|
|
12226
13015
|
if (!isRecord6(provenance)) return
|
|
12227
13016
|
const { repo, runId, commit } = provenance
|
|
12228
|
-
if (typeof repo !== 'string' || !
|
|
13017
|
+
if (typeof repo !== 'string' || !isGithubOwnerRepo(repo)) return
|
|
12229
13018
|
if (typeof runId !== 'string' || !GITHUB_RUN_ID.test(runId)) return
|
|
12230
13019
|
if (
|
|
12231
13020
|
commit !== undefined &&
|
|
@@ -12278,6 +13067,7 @@ function evidenceOf(candidate) {
|
|
|
12278
13067
|
candidate.sources,
|
|
12279
13068
|
candidate.targetEvidence,
|
|
12280
13069
|
candidate.counterevidence,
|
|
13070
|
+
candidate.reason ?? null,
|
|
12281
13071
|
])
|
|
12282
13072
|
}
|
|
12283
13073
|
function keptImportRuns(root, runs) {
|
|
@@ -12307,6 +13097,9 @@ function freshOf(item, standing, extra = {}) {
|
|
|
12307
13097
|
: { refreshPointer: extra.refreshPointer }),
|
|
12308
13098
|
possibleMatches: extra.possibleMatches ?? [],
|
|
12309
13099
|
candidate: item.candidate,
|
|
13100
|
+
...(item.evidenceHeads === undefined
|
|
13101
|
+
? {}
|
|
13102
|
+
: { evidenceHeads: item.evidenceHeads }),
|
|
12310
13103
|
record: item.record,
|
|
12311
13104
|
}
|
|
12312
13105
|
}
|
|
@@ -12325,8 +13118,22 @@ function skippedOf(item, entry) {
|
|
|
12325
13118
|
: { refreshPointer: entry.destination }),
|
|
12326
13119
|
}
|
|
12327
13120
|
}
|
|
13121
|
+
function importedEvidence(item) {
|
|
13122
|
+
const cited = new Map(
|
|
13123
|
+
(item.record.evidence ?? []).map((ref) => [
|
|
13124
|
+
`${ref.project}\x00${ref.path}`,
|
|
13125
|
+
ref.fingerprint,
|
|
13126
|
+
]),
|
|
13127
|
+
)
|
|
13128
|
+
return (project, rel) => {
|
|
13129
|
+
const fingerprint = cited.get(`${project}\x00${rel}`)
|
|
13130
|
+
return fingerprint === undefined
|
|
13131
|
+
? { status: 'unread' }
|
|
13132
|
+
: { status: 'present', fingerprint }
|
|
13133
|
+
}
|
|
13134
|
+
}
|
|
12328
13135
|
function placeOne(item, ledger, heldIn) {
|
|
12329
|
-
const outcome = classifyCandidate(ledger, item.record)
|
|
13136
|
+
const outcome = classifyCandidate(ledger, item.record, importedEvidence(item))
|
|
12330
13137
|
if (outcome.standing === 'new') {
|
|
12331
13138
|
return {
|
|
12332
13139
|
placed: freshOf(item, 'new', {
|
|
@@ -12350,12 +13157,13 @@ function placeOne(item, ledger, heldIn) {
|
|
|
12350
13157
|
),
|
|
12351
13158
|
}
|
|
12352
13159
|
}
|
|
12353
|
-
const
|
|
12354
|
-
|
|
12355
|
-
ledger.entries.find((known) => known.id === item.id),
|
|
12356
|
-
)
|
|
13160
|
+
const entry = ledger.entries.find((known) => known.id === item.id)
|
|
13161
|
+
const skipped = skippedOf(item, entry)
|
|
12357
13162
|
if (skipped !== undefined) return { skipped }
|
|
12358
|
-
const held =
|
|
13163
|
+
const held =
|
|
13164
|
+
entry !== undefined && !recordsEvidenceOf(entry, item.record)
|
|
13165
|
+
? undefined
|
|
13166
|
+
: heldIn(item)
|
|
12359
13167
|
return {
|
|
12360
13168
|
placed:
|
|
12361
13169
|
held === undefined
|
|
@@ -12530,6 +13338,9 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
|
|
|
12530
13338
|
view.importRuns,
|
|
12531
13339
|
)
|
|
12532
13340
|
if (placement.fresh.length === 0) return { publish: false }
|
|
13341
|
+
const lookups = new Map(
|
|
13342
|
+
placement.fresh.map((item) => [item.record, importedEvidence(item)]),
|
|
13343
|
+
)
|
|
12533
13344
|
const runId = newImportRunId(now())
|
|
12534
13345
|
localRunId = runId
|
|
12535
13346
|
const createdAt = new Date(now()).toISOString()
|
|
@@ -12551,6 +13362,7 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
|
|
|
12551
13362
|
runId,
|
|
12552
13363
|
files: filesOf(model),
|
|
12553
13364
|
candidates: placement.fresh.map((item) => item.record),
|
|
13365
|
+
evidenceFor: (candidate) => lookups.get(candidate),
|
|
12554
13366
|
onLedgerWriteFailed: () =>
|
|
12555
13367
|
filesOf({
|
|
12556
13368
|
...model,
|
|
@@ -12615,6 +13427,39 @@ function importRun(request, deps) {
|
|
|
12615
13427
|
}
|
|
12616
13428
|
return importWrite(parsed, sourceRunId, verified, state.root, deps)
|
|
12617
13429
|
}
|
|
13430
|
+
function allowedOrigins(deps) {
|
|
13431
|
+
const environment = describeEnvironment(deps)
|
|
13432
|
+
const seen = new Set()
|
|
13433
|
+
const shared = new Set()
|
|
13434
|
+
for (const { mainRoot } of environment.resolved.resolved) {
|
|
13435
|
+
const { repo } = readRepoIdentity(mainRoot)
|
|
13436
|
+
if (repo === undefined) continue
|
|
13437
|
+
if (seen.has(repo)) shared.add(repo)
|
|
13438
|
+
seen.add(repo)
|
|
13439
|
+
}
|
|
13440
|
+
return success('allowed-origins', {
|
|
13441
|
+
outcome: 'complete',
|
|
13442
|
+
origins: [...seen].sort(),
|
|
13443
|
+
ambiguous: [...shared].sort(),
|
|
13444
|
+
configUnreadable: environment.configUnreadable,
|
|
13445
|
+
})
|
|
13446
|
+
}
|
|
13447
|
+
function verifyProvenanceOp(request) {
|
|
13448
|
+
if (!isRecord6(request))
|
|
13449
|
+
return failure2('verify-provenance', 'invalid-request')
|
|
13450
|
+
const verdict = verifyProvenance({
|
|
13451
|
+
referencedWorkflows: request.referencedWorkflows,
|
|
13452
|
+
...(request.status === undefined ? {} : { status: request.status }),
|
|
13453
|
+
})
|
|
13454
|
+
if (verdict.status === 'refused') {
|
|
13455
|
+
return failure2('verify-provenance', verdict.reason)
|
|
13456
|
+
}
|
|
13457
|
+
return success('verify-provenance', {
|
|
13458
|
+
outcome: 'complete',
|
|
13459
|
+
stage: verdict.status,
|
|
13460
|
+
sha: verdict.sha,
|
|
13461
|
+
})
|
|
13462
|
+
}
|
|
12618
13463
|
var ISSUE_DIGITS = /^[0-9]{1,10}$/
|
|
12619
13464
|
function parseTicksRequest(request) {
|
|
12620
13465
|
if (!isRecord6(request)) return
|
|
@@ -12639,16 +13484,23 @@ function parseTicksRequest(request) {
|
|
|
12639
13484
|
}
|
|
12640
13485
|
function parseRenderRequest(request) {
|
|
12641
13486
|
if (!isRecord6(request)) return
|
|
12642
|
-
const { date, runId, attempt, cacheRestored } = request
|
|
13487
|
+
const { date, runId, attempt, cacheRestored, repo } = request
|
|
12643
13488
|
if (
|
|
12644
13489
|
typeof date !== 'string' ||
|
|
12645
13490
|
typeof runId !== 'string' ||
|
|
12646
13491
|
typeof attempt !== 'string' ||
|
|
12647
|
-
typeof cacheRestored !== 'boolean'
|
|
13492
|
+
typeof cacheRestored !== 'boolean' ||
|
|
13493
|
+
(repo !== undefined && typeof repo !== 'string')
|
|
12648
13494
|
) {
|
|
12649
13495
|
return
|
|
12650
13496
|
}
|
|
12651
|
-
return {
|
|
13497
|
+
return {
|
|
13498
|
+
date,
|
|
13499
|
+
runId,
|
|
13500
|
+
attempt,
|
|
13501
|
+
cacheRestored,
|
|
13502
|
+
...(repo === undefined ? {} : { repo }),
|
|
13503
|
+
}
|
|
12652
13504
|
}
|
|
12653
13505
|
function ciOptions(deps) {
|
|
12654
13506
|
return {
|
|
@@ -12708,6 +13560,7 @@ function renderReportOp(request, deps) {
|
|
|
12708
13560
|
open: result.open,
|
|
12709
13561
|
shown: result.shown,
|
|
12710
13562
|
hidden: result.hidden,
|
|
13563
|
+
unverified: result.unverified,
|
|
12711
13564
|
fresh: result.fresh,
|
|
12712
13565
|
fetches: result.fetches,
|
|
12713
13566
|
outcome: result.outcome,
|
|
@@ -12733,6 +13586,10 @@ function runHelperOp(op, request, deps = {}) {
|
|
|
12733
13586
|
return applyTicksOp(request, deps)
|
|
12734
13587
|
case 'render-report':
|
|
12735
13588
|
return renderReportOp(request, deps)
|
|
13589
|
+
case 'allowed-origins':
|
|
13590
|
+
return allowedOrigins(deps)
|
|
13591
|
+
case 'verify-provenance':
|
|
13592
|
+
return verifyProvenanceOp(request)
|
|
12736
13593
|
case 'ledger-show':
|
|
12737
13594
|
return ledgerShow(request, deps)
|
|
12738
13595
|
case 'ledger-clear':
|
|
@@ -12785,6 +13642,7 @@ var REQUEST_OPS = new Set([
|
|
|
12785
13642
|
'import',
|
|
12786
13643
|
'apply-ticks',
|
|
12787
13644
|
'render-report',
|
|
13645
|
+
'verify-provenance',
|
|
12788
13646
|
])
|
|
12789
13647
|
function resolveCliOp(argv) {
|
|
12790
13648
|
const [first, second] = argv
|
|
@@ -12805,6 +13663,14 @@ function showRequestFromArgv(argv) {
|
|
|
12805
13663
|
? { offset: Number(value) }
|
|
12806
13664
|
: { offset: value }
|
|
12807
13665
|
}
|
|
13666
|
+
function provenanceArgsFromArgv(argv) {
|
|
13667
|
+
const rest = argv.slice(1)
|
|
13668
|
+
if (rest.length === 0) return {}
|
|
13669
|
+
const [flag, value] = rest
|
|
13670
|
+
return rest.length === 2 && flag === '--status' && value !== undefined
|
|
13671
|
+
? { status: value }
|
|
13672
|
+
: undefined
|
|
13673
|
+
}
|
|
12808
13674
|
function refusedBegin(result, options) {
|
|
12809
13675
|
const deps = options.deps ?? {}
|
|
12810
13676
|
const marker = ciRunMarker(deps)
|
|
@@ -12840,6 +13706,7 @@ function readCliRequest(op, options, out, err) {
|
|
|
12840
13706
|
if (text === 'too-large' || text === 'unreadable') {
|
|
12841
13707
|
return refuse(`request-${text}`)
|
|
12842
13708
|
}
|
|
13709
|
+
if (op === 'verify-provenance') return { ok: true, request: text }
|
|
12843
13710
|
if (text.trim() === '') return { ok: true, request: {} }
|
|
12844
13711
|
try {
|
|
12845
13712
|
return { ok: true, request: JSON.parse(text) }
|
|
@@ -12863,10 +13730,20 @@ function runConnectHelper(options) {
|
|
|
12863
13730
|
err(CE_CONNECT_USAGE)
|
|
12864
13731
|
return 2
|
|
12865
13732
|
}
|
|
13733
|
+
const provenanceArgs =
|
|
13734
|
+
op === 'verify-provenance' ? provenanceArgsFromArgv(options.argv) : {}
|
|
13735
|
+
if (provenanceArgs === undefined) {
|
|
13736
|
+
out(JSON.stringify(failure2(op, 'invalid-request').body))
|
|
13737
|
+
return 2
|
|
13738
|
+
}
|
|
12866
13739
|
const read = readCliRequest(op, options, out, err)
|
|
12867
13740
|
if (!read.ok) return read.exitCode
|
|
12868
13741
|
const request =
|
|
12869
|
-
op === 'ledger-show'
|
|
13742
|
+
op === 'ledger-show'
|
|
13743
|
+
? showRequestFromArgv(options.argv)
|
|
13744
|
+
: op === 'verify-provenance'
|
|
13745
|
+
? { referencedWorkflows: read.request, ...provenanceArgs }
|
|
13746
|
+
: read.request
|
|
12870
13747
|
const result = runHelperOp(op, request, options.deps ?? {})
|
|
12871
13748
|
out(JSON.stringify(result.body))
|
|
12872
13749
|
return result.ok ? 0 : 1
|