@fro.bot/systematic 3.36.0 → 3.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,31 +2,31 @@
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: 2a649776a89b2e51c320bb4394c7acaa296f8368be659aba20bde41534ee036b
5
+ // source-digest: 9c3d008aac1f38f179f2947ec1294e74478f5950ba822fe08e50d9a295920f55
6
6
  // src/ce-connect-helper.ts
7
7
  import { spawnSync as spawnSync3 } from 'node:child_process'
8
- import fs10 from 'node:fs'
8
+ import fs11 from 'node:fs'
9
9
  import os2 from 'node:os'
10
- import path8 from 'node:path'
10
+ import path9 from 'node:path'
11
11
 
12
12
  // src/lib/connect-ci.ts
13
13
  import {
14
14
  createHash as createHash4,
15
15
  randomUUID as randomUUID3,
16
16
  } from 'node:crypto'
17
- import fs7 from 'node:fs'
18
- import path6 from 'node:path'
17
+ import fs8 from 'node:fs'
18
+ import path7 from 'node:path'
19
19
 
20
20
  // src/lib/connect-evidence.ts
21
21
  import { spawnSync } from 'node:child_process'
22
22
  import { createHash } from 'node:crypto'
23
23
  import fs4 from 'node:fs'
24
- import path3 from 'node:path'
24
+ import path4 from 'node:path'
25
25
 
26
26
  // src/lib/connect-config.ts
27
27
  import fs3 from 'node:fs'
28
28
  import os from 'node:os'
29
- import path2 from 'node:path'
29
+ import path3 from 'node:path'
30
30
 
31
31
  // node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
32
32
  function createScanner(text, ignoreTrivia = false) {
@@ -957,6 +957,16 @@ function printParseErrorCode(code) {
957
957
  return '<unknown ParseErrorCode>'
958
958
  }
959
959
 
960
+ // src/lib/opencode-config-dir.ts
961
+ import path from 'node:path'
962
+ function opencodeUserConfigDir(homeDir, env = process.env) {
963
+ const xdg = env.XDG_CONFIG_HOME
964
+ return path.join(
965
+ xdg && path.isAbsolute(xdg) ? xdg : path.join(homeDir, '.config'),
966
+ 'opencode',
967
+ )
968
+ }
969
+
960
970
  // src/lib/search-bounded-read.ts
961
971
  import fs from 'node:fs'
962
972
  var READ_CHUNK_BYTES = 64 * 1024
@@ -1004,7 +1014,7 @@ function readBytesBounded(filePath, maxBytes) {
1004
1014
 
1005
1015
  // src/lib/search-project-identity.ts
1006
1016
  import fs2 from 'node:fs'
1007
- import path from 'node:path'
1017
+ import path2 from 'node:path'
1008
1018
  var MAX_IDENTITY_FILE_BYTES = 1024 * 1024
1009
1019
  function realpath(target) {
1010
1020
  return fs2.realpathSync.native(target)
@@ -1012,7 +1022,9 @@ function realpath(target) {
1012
1022
  function readSmallFile(file) {
1013
1023
  const read = readBytesBounded(file, MAX_IDENTITY_FILE_BYTES)
1014
1024
  if (read.kind !== 'bytes') {
1015
- throw new Error(`${path.basename(file)} cannot be read as an identity file`)
1025
+ throw new Error(
1026
+ `${path2.basename(file)} cannot be read as an identity file`,
1027
+ )
1016
1028
  }
1017
1029
  return read.bytes.toString('utf8')
1018
1030
  }
@@ -1028,7 +1040,7 @@ function firstLine(text) {
1028
1040
  .trim()
1029
1041
  }
1030
1042
  function resolveFrom(base, value) {
1031
- return path.isAbsolute(value) ? value : path.resolve(base, value)
1043
+ return path2.isAbsolute(value) ? value : path2.resolve(base, value)
1032
1044
  }
1033
1045
  function setsCoreWorktree(config) {
1034
1046
  let inCore = false
@@ -1051,10 +1063,10 @@ function setsCoreWorktree(config) {
1051
1063
  return false
1052
1064
  }
1053
1065
  function isSubmoduleGitdir(gitdir) {
1054
- return gitdir.split(path.sep).includes('modules')
1066
+ return gitdir.split(path2.sep).includes('modules')
1055
1067
  }
1056
1068
  function resolveLinkedWorktree(gitFile, gitdir) {
1057
- const commonFile = path.join(gitdir, 'commondir')
1069
+ const commonFile = path2.join(gitdir, 'commondir')
1058
1070
  if (!fs2.existsSync(commonFile)) {
1059
1071
  return { reason: 'missing-commondir' }
1060
1072
  }
@@ -1063,27 +1075,27 @@ function resolveLinkedWorktree(gitFile, gitdir) {
1063
1075
  return { reason: 'corrupt-git-file' }
1064
1076
  }
1065
1077
  const common = realpath(resolveFrom(gitdir, commonRaw))
1066
- if (gitdir !== path.join(common, 'worktrees', path.basename(gitdir))) {
1078
+ if (gitdir !== path2.join(common, 'worktrees', path2.basename(gitdir))) {
1067
1079
  return { reason: 'inconsistent' }
1068
1080
  }
1069
- const backRaw = firstLine(readSmallFile(path.join(gitdir, 'gitdir')))
1081
+ const backRaw = firstLine(readSmallFile(path2.join(gitdir, 'gitdir')))
1070
1082
  if (backRaw === '') {
1071
1083
  return { reason: 'corrupt-git-file' }
1072
1084
  }
1073
1085
  if (realpath(resolveFrom(gitdir, backRaw)) !== realpath(gitFile)) {
1074
1086
  return { reason: 'inconsistent' }
1075
1087
  }
1076
- if (path.basename(common) !== '.git') {
1088
+ if (path2.basename(common) !== '.git') {
1077
1089
  return { reason: 'unsupported-layout' }
1078
1090
  }
1079
- if (setsCoreWorktree(readSmallFile(path.join(common, 'config')))) {
1091
+ if (setsCoreWorktree(readSmallFile(path2.join(common, 'config')))) {
1080
1092
  return { reason: 'core-worktree' }
1081
1093
  }
1082
- return { root: path.dirname(common) }
1094
+ return { root: path2.dirname(common) }
1083
1095
  }
1084
1096
  function deriveMainRoot(checkoutRoot) {
1085
1097
  const root = realpath(checkoutRoot)
1086
- const gitPath = path.join(root, '.git')
1098
+ const gitPath = path2.join(root, '.git')
1087
1099
  let stat
1088
1100
  try {
1089
1101
  stat = fs2.lstatSync(gitPath)
@@ -1108,7 +1120,7 @@ function deriveMainRoot(checkoutRoot) {
1108
1120
  if (!fs2.statSync(gitdir).isDirectory()) {
1109
1121
  return { reason: 'corrupt-git-file' }
1110
1122
  }
1111
- if (path.basename(path.dirname(gitdir)) === 'worktrees') {
1123
+ if (path2.basename(path2.dirname(gitdir)) === 'worktrees') {
1112
1124
  return resolveLinkedWorktree(gitPath, gitdir)
1113
1125
  }
1114
1126
  if (isSubmoduleGitdir(gitdir)) {
@@ -1134,8 +1146,43 @@ var MAX_CONNECT_CONFIG_BYTES = 1024 * 1024
1134
1146
  var MAX_DIAGNOSTIC_LENGTH = 200
1135
1147
  var MAX_CONNECT_GROUPS = 32
1136
1148
  var CONNECT_GROUP_NAME_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/
1149
+ var MAX_CONNECT_PINS = 64
1150
+ var MAX_PIN_FILE_LENGTH = 256
1151
+ var MAX_PIN_KEY_LENGTH = 256
1152
+ var PIN_FILE_PATTERN = /^(?!\/)(?!(?:.*\/)?\.\.(?:\/|$))[A-Za-z0-9._/-]+$/
1137
1153
  var ALLOW_PROJECTS_KEY = 'allow_projects'
1138
1154
  var GROUPS_KEY = 'groups'
1155
+ var PINS_KEY = 'pins'
1156
+ var OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/
1157
+ var REPO = /^[A-Za-z0-9._-]{1,100}$/
1158
+ function isGithubOwnerRepo(value) {
1159
+ const parts = value.split('/')
1160
+ const [owner, name] = parts
1161
+ return (
1162
+ parts.length === 2 &&
1163
+ owner !== undefined &&
1164
+ name !== undefined &&
1165
+ OWNER.test(owner) &&
1166
+ REPO.test(name) &&
1167
+ name !== '.' &&
1168
+ name !== '..'
1169
+ )
1170
+ }
1171
+ function hasControlCharacter(value) {
1172
+ for (const char of value) {
1173
+ const code = char.codePointAt(0) ?? 0
1174
+ if (code < 32 || (code >= 127 && code <= 159)) return true
1175
+ }
1176
+ return false
1177
+ }
1178
+ function isPinKey(value) {
1179
+ return (
1180
+ value.length > 0 &&
1181
+ value.length <= MAX_PIN_KEY_LENGTH &&
1182
+ !hasControlCharacter(value) &&
1183
+ value.split('.').every((segment) => segment.length > 0)
1184
+ )
1185
+ }
1139
1186
  function isRecord(value) {
1140
1187
  return typeof value === 'object' && value !== null && !Array.isArray(value)
1141
1188
  }
@@ -1169,11 +1216,65 @@ function readGroups(value) {
1169
1216
  }
1170
1217
  return groups
1171
1218
  }
1219
+ function unionPins(lists) {
1220
+ const seen = new Map()
1221
+ for (const list of lists) {
1222
+ for (const pin of list ?? []) {
1223
+ const identity = JSON.stringify([
1224
+ pin.project,
1225
+ pin.upstream,
1226
+ pin.file,
1227
+ pin.key,
1228
+ ])
1229
+ if (!seen.has(identity)) seen.set(identity, pin)
1230
+ }
1231
+ }
1232
+ return [...seen.values()]
1233
+ }
1234
+ var PIN_FIELDS = ['project', 'upstream', 'file', 'key']
1235
+ function readPin(value) {
1236
+ if (!isRecord(value)) return
1237
+ const keys = Object.keys(value)
1238
+ if (
1239
+ keys.length !== PIN_FIELDS.length ||
1240
+ !PIN_FIELDS.every((field) => Object.hasOwn(value, field))
1241
+ ) {
1242
+ return
1243
+ }
1244
+ const { project, upstream, file, key } = value
1245
+ if (
1246
+ typeof project !== 'string' ||
1247
+ project.length === 0 ||
1248
+ project.length > MAX_ALLOW_PROJECT_LENGTH ||
1249
+ typeof upstream !== 'string' ||
1250
+ !isGithubOwnerRepo(upstream) ||
1251
+ typeof file !== 'string' ||
1252
+ file.length === 0 ||
1253
+ file.length > MAX_PIN_FILE_LENGTH ||
1254
+ !PIN_FILE_PATTERN.test(file) ||
1255
+ typeof key !== 'string' ||
1256
+ !isPinKey(key)
1257
+ ) {
1258
+ return
1259
+ }
1260
+ return { project, upstream, file, key }
1261
+ }
1262
+ function readPins(value) {
1263
+ if (!Array.isArray(value) || value.length > MAX_CONNECT_PINS) return
1264
+ const pins = []
1265
+ for (const entry of value) {
1266
+ const pin = readPin(entry)
1267
+ if (pin === undefined) return
1268
+ pins.push(pin)
1269
+ }
1270
+ return pins
1271
+ }
1172
1272
  function validateConnectBlock(value) {
1173
1273
  if (!isRecord(value)) return { ok: false }
1174
1274
  if (
1175
1275
  Object.keys(value).some(
1176
- (key) => key !== ALLOW_PROJECTS_KEY && key !== GROUPS_KEY,
1276
+ (key) =>
1277
+ key !== ALLOW_PROJECTS_KEY && key !== GROUPS_KEY && key !== PINS_KEY,
1177
1278
  )
1178
1279
  ) {
1179
1280
  return { ok: false }
@@ -1188,7 +1289,9 @@ function validateConnectBlock(value) {
1188
1289
  Object.hasOwn(value, GROUPS_KEY) ? value[GROUPS_KEY] : {},
1189
1290
  )
1190
1291
  if (groups === undefined) return { ok: false }
1191
- return { ok: true, allowProjects, groups }
1292
+ const pins = readPins(Object.hasOwn(value, PINS_KEY) ? value[PINS_KEY] : [])
1293
+ if (pins === undefined) return { ok: false }
1294
+ return { ok: true, allowProjects, groups, pins }
1192
1295
  }
1193
1296
  function errorCode2(error) {
1194
1297
  return error instanceof Error && 'code' in error ? error.code : undefined
@@ -1203,13 +1306,13 @@ function entryExists(target) {
1203
1306
  }
1204
1307
  }
1205
1308
  function selectConfigFile(dir, basename) {
1206
- const jsoncPath = path2.join(dir, `${basename}.jsonc`)
1309
+ const jsoncPath = path3.join(dir, `${basename}.jsonc`)
1207
1310
  return entryExists(jsoncPath)
1208
1311
  ? jsoncPath
1209
- : path2.join(dir, `${basename}.json`)
1312
+ : path3.join(dir, `${basename}.json`)
1210
1313
  }
1211
1314
  function realpathOrResolved(dir) {
1212
- const resolved = path2.resolve(dir)
1315
+ const resolved = path3.resolve(dir)
1213
1316
  try {
1214
1317
  return fs3.realpathSync(resolved)
1215
1318
  } catch {
@@ -1218,8 +1321,7 @@ function realpathOrResolved(dir) {
1218
1321
  }
1219
1322
  function resolveConnectConfigDirs(options) {
1220
1323
  const homeDir = options?.homeDir ?? os.homedir()
1221
- const userConfigDir =
1222
- options?.userConfigDir ?? path2.join(homeDir, '.config/opencode')
1324
+ const userConfigDir = options?.userConfigDir ?? opencodeUserConfigDir(homeDir)
1223
1325
  const rawCustom =
1224
1326
  options !== undefined && Object.hasOwn(options, 'customConfigDir')
1225
1327
  ? options.customConfigDir?.trim()
@@ -1247,17 +1349,17 @@ function selectConnectConfigFiles(dirs) {
1247
1349
  },
1248
1350
  )
1249
1351
  const aliased =
1250
- path2.resolve(custom) === path2.resolve(dirs.userConfigDir) ||
1352
+ path3.resolve(custom) === path3.resolve(dirs.userConfigDir) ||
1251
1353
  realpathOrResolved(custom) === realpathOrResolved(dirs.userConfigDir)
1252
1354
  return { files, aliased }
1253
1355
  }
1254
1356
  function isInside(child, parent) {
1255
- const relative = path2.relative(parent, child)
1357
+ const relative = path3.relative(parent, child)
1256
1358
  return (
1257
1359
  relative === '' ||
1258
1360
  (relative !== '..' &&
1259
- !relative.startsWith(`..${path2.sep}`) &&
1260
- !path2.isAbsolute(relative))
1361
+ !relative.startsWith(`..${path3.sep}`) &&
1362
+ !path3.isAbsolute(relative))
1261
1363
  )
1262
1364
  }
1263
1365
  function isGitEntry(target) {
@@ -1268,13 +1370,13 @@ function isGitEntry(target) {
1268
1370
  const code = errorCode2(error)
1269
1371
  return code !== 'ENOENT' && code !== 'ENOTDIR'
1270
1372
  }
1271
- return stat.isDirectory() ? entryExists(path2.join(target, 'HEAD')) : true
1373
+ return stat.isDirectory() ? entryExists(path3.join(target, 'HEAD')) : true
1272
1374
  }
1273
1375
  function insideCheckout(dir) {
1274
1376
  let current = dir
1275
1377
  for (;;) {
1276
- if (isGitEntry(path2.join(current, '.git'))) return true
1277
- const parent = path2.dirname(current)
1378
+ if (isGitEntry(path3.join(current, '.git'))) return true
1379
+ const parent = path3.dirname(current)
1278
1380
  if (parent === current) return false
1279
1381
  current = parent
1280
1382
  }
@@ -1330,7 +1432,7 @@ function readConnectBlock(filePath) {
1330
1432
  return { kind: 'failed', reason: 'root must be an object' }
1331
1433
  }
1332
1434
  if (!Object.hasOwn(parsed, 'connect')) {
1333
- return { kind: 'read', allowProjects: [], groups: {} }
1435
+ return { kind: 'read', allowProjects: [], groups: {}, pins: [] }
1334
1436
  }
1335
1437
  const validation = validateConnectBlock(parsed.connect)
1336
1438
  return validation.ok
@@ -1338,13 +1440,14 @@ function readConnectBlock(filePath) {
1338
1440
  kind: 'read',
1339
1441
  allowProjects: validation.allowProjects,
1340
1442
  groups: validation.groups,
1443
+ pins: validation.pins,
1341
1444
  }
1342
1445
  : { kind: 'failed', reason: 'the connect block is not valid' }
1343
1446
  }
1344
1447
  function expandHome(entry, homeDir) {
1345
1448
  if (entry === '~') return homeDir
1346
- if (entry.startsWith('~/') || entry.startsWith(`~${path2.sep}`)) {
1347
- return path2.join(homeDir, entry.slice(2))
1449
+ if (entry.startsWith('~/') || entry.startsWith(`~${path3.sep}`)) {
1450
+ return path3.join(homeDir, entry.slice(2))
1348
1451
  }
1349
1452
  return entry
1350
1453
  }
@@ -1352,7 +1455,7 @@ function existingRoots(entries, homeDir) {
1352
1455
  const roots = []
1353
1456
  for (const entry of entries) {
1354
1457
  const expanded = expandHome(entry, homeDir)
1355
- if (!path2.isAbsolute(expanded)) continue
1458
+ if (!path3.isAbsolute(expanded)) continue
1356
1459
  try {
1357
1460
  roots.push(fs3.realpathSync.native(expanded))
1358
1461
  } catch {}
@@ -1365,6 +1468,7 @@ function loadConnectAllowList(options) {
1365
1468
  const warnings = []
1366
1469
  const entries = new Set()
1367
1470
  const groups = {}
1471
+ const layerPins = []
1368
1472
  let unreadable = false
1369
1473
  const readLayer = (file) => {
1370
1474
  const read = readConnectBlock(file.path)
@@ -1372,7 +1476,7 @@ function loadConnectAllowList(options) {
1372
1476
  if (read.kind === 'failed') {
1373
1477
  unreadable = true
1374
1478
  warnings.push(
1375
- `[systematic] connect settings in ${displaySafe(file.path)} could not be read (${read.reason}); the allow list and groups from that file were ignored.`,
1479
+ `[systematic] connect settings in ${displaySafe(file.path)} could not be read (${read.reason}); the allow list, groups and pins from that file were ignored.`,
1376
1480
  )
1377
1481
  return
1378
1482
  }
@@ -1380,6 +1484,7 @@ function loadConnectAllowList(options) {
1380
1484
  for (const [name, members] of Object.entries(read.groups)) {
1381
1485
  groups[name] = [...members]
1382
1486
  }
1487
+ layerPins.push(read.pins)
1383
1488
  }
1384
1489
  const isUserLayer = (file) =>
1385
1490
  file.layer === 'user' || file.layer === 'user.local'
@@ -1402,6 +1507,7 @@ function loadConnectAllowList(options) {
1402
1507
  return {
1403
1508
  allowProjects: [...entries],
1404
1509
  groups,
1510
+ pins: unionPins(layerPins),
1405
1511
  unreadable,
1406
1512
  warnings,
1407
1513
  ...(customDirRefused !== undefined && { customDirRefused }),
@@ -1411,12 +1517,12 @@ function unmatched(entry, reason) {
1411
1517
  return { status: 'unmatched', entry, reason }
1412
1518
  }
1413
1519
  function enclosedByCheckout(dir) {
1414
- const parent = path2.dirname(dir)
1520
+ const parent = path3.dirname(dir)
1415
1521
  return parent !== dir && insideCheckout(parent)
1416
1522
  }
1417
1523
  function resolveAllowEntry(entry, options = {}) {
1418
1524
  const expanded = expandHome(entry, options.homeDir ?? os.homedir())
1419
- if (!path2.isAbsolute(expanded)) return unmatched(entry, 'not-absolute')
1525
+ if (!path3.isAbsolute(expanded)) return unmatched(entry, 'not-absolute')
1420
1526
  let real
1421
1527
  try {
1422
1528
  real = fs3.realpathSync.native(expanded)
@@ -1451,16 +1557,21 @@ function resolveAllowEntry(entry, options = {}) {
1451
1557
  function resolveAllowList(entries, options = {}) {
1452
1558
  const resolved = []
1453
1559
  const missed = []
1454
- const seen = new Set()
1560
+ const kept = new Map()
1455
1561
  for (const entry of entries) {
1456
1562
  const resolution = resolveAllowEntry(entry, options)
1457
1563
  if (resolution.status === 'unmatched') {
1458
1564
  missed.push({ entry, reason: resolution.reason })
1459
1565
  continue
1460
1566
  }
1461
- if (seen.has(resolution.mainRoot)) continue
1462
- seen.add(resolution.mainRoot)
1463
- resolved.push({ entry, mainRoot: resolution.mainRoot })
1567
+ const first = kept.get(resolution.mainRoot)
1568
+ if (first === undefined) {
1569
+ const item = { entry, mainRoot: resolution.mainRoot }
1570
+ kept.set(resolution.mainRoot, item)
1571
+ resolved.push(item)
1572
+ } else if (entry !== first.entry && !first.aliases?.includes(entry)) {
1573
+ first.aliases = [...(first.aliases ?? []), entry]
1574
+ }
1464
1575
  }
1465
1576
  return { resolved, unmatched: missed }
1466
1577
  }
@@ -1673,7 +1784,7 @@ function lstatOrCode(target) {
1673
1784
  function relativeSegments(rel) {
1674
1785
  if (typeof rel !== 'string' || rel === '') return
1675
1786
  if (rel.length > MAX_RELATIVE_PATH_LENGTH || rel.includes('\x00')) return
1676
- if (path3.posix.isAbsolute(rel) || path3.win32.isAbsolute(rel)) return
1787
+ if (path4.posix.isAbsolute(rel) || path4.win32.isAbsolute(rel)) return
1677
1788
  const segments = rel.split('/')
1678
1789
  return segments.some((part) => part === '' || part === '.' || part === '..')
1679
1790
  ? undefined
@@ -1705,14 +1816,14 @@ function walkToFile(root, segments) {
1705
1816
  const ancestors = []
1706
1817
  let current = root
1707
1818
  for (const part of segments.slice(0, -1)) {
1708
- current = path3.join(current, part)
1819
+ current = path4.join(current, part)
1709
1820
  const stat = lstatOrCode(current)
1710
1821
  if (typeof stat === 'string') return stat
1711
1822
  if (stat.isSymbolicLink()) return 'symlink'
1712
1823
  if (!stat.isDirectory()) return 'missing'
1713
1824
  ancestors.push({ dir: current, stat })
1714
1825
  }
1715
- const full = path3.join(current, segments.at(-1) ?? '')
1826
+ const full = path4.join(current, segments.at(-1) ?? '')
1716
1827
  const before = lstatOrCode(full)
1717
1828
  if (typeof before === 'string') return before
1718
1829
  if (before.isSymbolicLink()) return 'symlink'
@@ -2057,7 +2168,7 @@ function classifyPath(rel) {
2057
2168
  const segments = rel.split('/')
2058
2169
  const name = segments.at(-1) ?? ''
2059
2170
  if (isExcludedPath(segments, name)) return
2060
- const extension = path3.posix.extname(name)
2171
+ const extension = path4.posix.extname(name)
2061
2172
  const corpus = CORPUS_DIRECTORIES.find(([prefix]) => rel.startsWith(prefix))
2062
2173
  if (corpus !== undefined && extension === '.md') return corpus[1]
2063
2174
  if (
@@ -2234,8 +2345,619 @@ function inventoryProject(entry, options = {}) {
2234
2345
 
2235
2346
  // src/lib/connect-helper-core.ts
2236
2347
  import { createHash as createHash2, randomUUID } from 'node:crypto'
2348
+ import fs6 from 'node:fs'
2349
+ import path5 from 'node:path'
2350
+
2351
+ // src/lib/connect-repo-identity.ts
2237
2352
  import fs5 from 'node:fs'
2238
- import path4 from 'node:path'
2353
+ import zlib from 'node:zlib'
2354
+ var MAX_CONFIG_BYTES = 1024 * 1024
2355
+ var MAX_HEAD_BYTES = 4096
2356
+ var MAX_REF_BYTES = 4096
2357
+ var MAX_PACKED_REFS_BYTES = 8 * 1024 * 1024
2358
+ var HTTPS_FORM = /^https:\/\/(?:[^/@\s]*@)?github\.com\/(\S+)$/i
2359
+ var SSH_URL_FORM = /^ssh:\/\/(?:[A-Za-z0-9._-]+@)?github\.com\/(\S+)$/i
2360
+ var SCP_FORM = /^(?:[A-Za-z0-9._-]+@)?github\.com:(\S+)$/i
2361
+ function ownerAndRepo(pathPart) {
2362
+ const segments = pathPart.replace(/\/+$/, '').split('/')
2363
+ if (segments.length !== 2) return
2364
+ const [owner = '', named = ''] = segments
2365
+ const repo = named.endsWith('.git') ? named.slice(0, -'.git'.length) : named
2366
+ const slug = `${owner}/${repo}`
2367
+ return isGithubOwnerRepo(slug) ? slug.toLowerCase() : undefined
2368
+ }
2369
+ function normalizeGithubRemote(url) {
2370
+ const match =
2371
+ HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
2372
+ const rest = match?.[1]
2373
+ return rest === undefined ? undefined : ownerAndRepo(rest)
2374
+ }
2375
+ function configValue(raw) {
2376
+ let out = ''
2377
+ let quoted = false
2378
+ for (const ch of raw.trim()) {
2379
+ if (ch === '"') {
2380
+ quoted = !quoted
2381
+ continue
2382
+ }
2383
+ if (!quoted && (ch === '#' || ch === ';')) break
2384
+ out += ch
2385
+ }
2386
+ return out.trim()
2387
+ }
2388
+ function isOriginSection(header) {
2389
+ const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
2390
+ return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
2391
+ }
2392
+ function originUrl(config) {
2393
+ let inOrigin = false
2394
+ for (const raw of config.split(`
2395
+ `)) {
2396
+ let line = raw.trim()
2397
+ if (line.startsWith('[')) {
2398
+ const end = line.indexOf(']')
2399
+ if (end === -1) {
2400
+ inOrigin = false
2401
+ continue
2402
+ }
2403
+ inOrigin = isOriginSection(line.slice(1, end))
2404
+ line = line.slice(end + 1).trim()
2405
+ }
2406
+ if (!inOrigin) continue
2407
+ const key = /^url[ \t]*=(.*)$/i.exec(line)
2408
+ if (key?.[1] !== undefined) return configValue(key[1])
2409
+ }
2410
+ return
2411
+ }
2412
+ var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
2413
+ var REF_NAME = /^refs\/[A-Za-z0-9._+/-]+$/
2414
+ function readGitText(mainRoot, rel, maxBytes) {
2415
+ const read = readContainedFile(mainRoot, rel, { maxBytes })
2416
+ return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
2417
+ }
2418
+ function firstLine2(text) {
2419
+ return (
2420
+ text.split(
2421
+ `
2422
+ `,
2423
+ 1,
2424
+ )[0] ?? ''
2425
+ )
2426
+ .replace(/\r$/, '')
2427
+ .trim()
2428
+ }
2429
+ function safeRefName(ref) {
2430
+ return (
2431
+ REF_NAME.test(ref) &&
2432
+ ref
2433
+ .split('/')
2434
+ .every(
2435
+ (part) =>
2436
+ part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
2437
+ )
2438
+ )
2439
+ }
2440
+ function packedRef(packed, ref) {
2441
+ for (const raw of packed.split(`
2442
+ `)) {
2443
+ const line = raw.trim()
2444
+ if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
2445
+ const [id, name, ...rest] = line.split(/\s+/)
2446
+ if (rest.length === 0 && name === ref && OBJECT_ID.test(id ?? '')) return id
2447
+ }
2448
+ return
2449
+ }
2450
+ function headCommit(mainRoot) {
2451
+ const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
2452
+ if (head === undefined) return
2453
+ const line = firstLine2(head)
2454
+ if (OBJECT_ID.test(line)) return line
2455
+ const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
2456
+ if (symbolic === undefined || !safeRefName(symbolic)) return
2457
+ const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
2458
+ const looseId = loose === undefined ? '' : firstLine2(loose)
2459
+ if (OBJECT_ID.test(looseId)) return looseId
2460
+ const packed = readGitText(
2461
+ mainRoot,
2462
+ '.git/packed-refs',
2463
+ MAX_PACKED_REFS_BYTES,
2464
+ )
2465
+ return packed === undefined ? undefined : packedRef(packed, symbolic)
2466
+ }
2467
+ function readRepoIdentity(mainRoot) {
2468
+ try {
2469
+ const config = readGitText(mainRoot, '.git/config', MAX_CONFIG_BYTES)
2470
+ const url = config === undefined ? undefined : originUrl(config)
2471
+ const repo = url === undefined ? undefined : normalizeGithubRemote(url)
2472
+ const commit = headCommit(mainRoot)
2473
+ return {
2474
+ ...(repo === undefined ? {} : { repo }),
2475
+ ...(commit === undefined ? {} : { commit }),
2476
+ }
2477
+ } catch {
2478
+ return {}
2479
+ }
2480
+ }
2481
+ var MAX_TAG_ENTRIES = 1024
2482
+ var MAX_TAG_DEPTH = 8
2483
+ var MAX_PACKED_TAG_LINES = 50000
2484
+ var MAX_LOOSE_OBJECT_BYTES = 4096
2485
+ var MAX_INFLATED_OBJECT_BYTES = 8192
2486
+ var MAX_TAG_INFLATIONS = 16
2487
+ var MAX_TOTAL_INFLATED_BYTES = 64 * 1024
2488
+ var TAG_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._+/-]{0,63}$/
2489
+ var UNKNOWN_TAG = { kind: 'unknown' }
2490
+ var TAGS_PREFIX = 'refs/tags/'
2491
+ function entryKind(target) {
2492
+ try {
2493
+ const stat = fs5.lstatSync(target)
2494
+ if (stat.isSymbolicLink()) return 'other'
2495
+ if (stat.isDirectory()) return 'directory'
2496
+ return stat.isFile() ? 'file' : 'other'
2497
+ } catch (error) {
2498
+ const code = error?.code
2499
+ return code === 'ENOENT' || code === 'ENOTDIR' ? 'missing' : 'other'
2500
+ }
2501
+ }
2502
+ function tagsDirectory(mainRoot) {
2503
+ const chain = ['.git', '.git/refs', '.git/refs/tags']
2504
+ for (const [index, rel] of chain.entries()) {
2505
+ const kind = entryKind(`${mainRoot}/${rel}`)
2506
+ if (kind === 'missing') return index === 0 ? 'unsafe' : 'absent'
2507
+ if (kind !== 'directory') return 'unsafe'
2508
+ }
2509
+ return 'present'
2510
+ }
2511
+ function visitTagEntry(walk, rel, depth) {
2512
+ if (!safeRefName(`${TAGS_PREFIX}${rel}`)) return false
2513
+ const kind = entryKind(`${walk.root}/.git/refs/tags/${rel}`)
2514
+ if (kind === 'file') {
2515
+ walk.names.push(rel)
2516
+ return true
2517
+ }
2518
+ return (
2519
+ kind === 'directory' &&
2520
+ depth < MAX_TAG_DEPTH &&
2521
+ walkTagDir(walk, rel, depth + 1)
2522
+ )
2523
+ }
2524
+ function walkTagDir(walk, relDir, depth) {
2525
+ const dir = fs5.opendirSync(`${walk.root}/.git/refs/tags/${relDir}`)
2526
+ try {
2527
+ for (let next = dir.readSync(); next !== null; next = dir.readSync()) {
2528
+ walk.entries += 1
2529
+ if (walk.entries > MAX_TAG_ENTRIES) return false
2530
+ const rel = relDir === '' ? next.name : `${relDir}/${next.name}`
2531
+ if (!visitTagEntry(walk, rel, depth)) return false
2532
+ }
2533
+ return true
2534
+ } finally {
2535
+ dir.closeSync()
2536
+ }
2537
+ }
2538
+ function looseTagNames(mainRoot) {
2539
+ const state = tagsDirectory(mainRoot)
2540
+ if (state === 'unsafe') return
2541
+ if (state === 'absent') return []
2542
+ const walk = { root: mainRoot, names: [], entries: 0 }
2543
+ return walkTagDir(walk, '', 0) ? walk.names : undefined
2544
+ }
2545
+ var OBJECT_HEADER = /^(commit|tag|tree|blob) (\d{1,6})$/
2546
+ var TAG_HEAD = /^object (\S+)\ntype (\S+)\n/
2547
+ function looseObjectNamesHead(mainRoot, id, head, budget) {
2548
+ if (!OBJECT_ID.test(id)) return
2549
+ const read = readContainedFile(
2550
+ mainRoot,
2551
+ `.git/objects/${id.slice(0, 2)}/${id.slice(2)}`,
2552
+ { maxBytes: MAX_LOOSE_OBJECT_BYTES },
2553
+ )
2554
+ if (read.kind !== 'bytes') return
2555
+ const room = MAX_TOTAL_INFLATED_BYTES - budget.bytes
2556
+ if (budget.inflations >= MAX_TAG_INFLATIONS || room <= 0) return
2557
+ budget.inflations += 1
2558
+ let raw
2559
+ try {
2560
+ raw = zlib.inflateSync(read.bytes, {
2561
+ maxOutputLength: Math.min(MAX_INFLATED_OBJECT_BYTES, room),
2562
+ })
2563
+ } catch {
2564
+ return
2565
+ }
2566
+ budget.bytes += raw.length
2567
+ const nul = raw.indexOf(0)
2568
+ if (nul < 1) return
2569
+ const header = OBJECT_HEADER.exec(raw.subarray(0, nul).toString('latin1'))
2570
+ const type = header?.[1]
2571
+ if (type === undefined || Number(header?.[2]) !== raw.length - nul - 1) {
2572
+ return
2573
+ }
2574
+ if (type !== 'tag') return false
2575
+ const body = TAG_HEAD.exec(raw.subarray(nul + 1).toString('utf8'))
2576
+ const target = body?.[1]
2577
+ const targetType = body?.[2]
2578
+ if (target === undefined || !OBJECT_ID.test(target)) return
2579
+ if (targetType === 'commit') return target === head
2580
+ return targetType === 'tree' || targetType === 'blob' ? false : undefined
2581
+ }
2582
+ function packedTagLine(line) {
2583
+ const [id = '', ref = '', ...rest] = line.split(/\s+/)
2584
+ if (!ref.startsWith(TAGS_PREFIX)) return 'none'
2585
+ if (rest.length > 0 || !OBJECT_ID.test(id) || !safeRefName(ref)) return 'bad'
2586
+ return { name: ref.slice(TAGS_PREFIX.length), id }
2587
+ }
2588
+ function scanPackedLine(scan, line) {
2589
+ if (line === '' || line.startsWith('#')) return true
2590
+ const { last } = scan
2591
+ scan.last = undefined
2592
+ if (line.startsWith('^')) {
2593
+ const peeled = line.slice(1)
2594
+ if (last === undefined) return true
2595
+ if (!OBJECT_ID.test(peeled)) return false
2596
+ last.peeled = peeled
2597
+ return true
2598
+ }
2599
+ const entry = packedTagLine(line)
2600
+ if (entry === 'none') return true
2601
+ if (entry === 'bad' || scan.tags.length >= MAX_PACKED_TAG_LINES) return false
2602
+ scan.tags.push(entry)
2603
+ scan.last = entry
2604
+ return true
2605
+ }
2606
+ var NO_PACKED_TAGS = { tags: [], fullyPeeled: false }
2607
+ function isFullyPeeled(text) {
2608
+ const [header = ''] = text.split(
2609
+ `
2610
+ `,
2611
+ 1,
2612
+ )
2613
+ const traits = /^# pack-refs with: (.*)$/.exec(header)?.[1]
2614
+ return traits?.split(' ').includes('fully-peeled') ?? false
2615
+ }
2616
+ function packedTags(mainRoot) {
2617
+ const read = readContainedFile(mainRoot, '.git/packed-refs', {
2618
+ maxBytes: MAX_PACKED_REFS_BYTES,
2619
+ })
2620
+ if (read.kind === 'refused') {
2621
+ return read.reason === 'missing' ? NO_PACKED_TAGS : undefined
2622
+ }
2623
+ const text = read.bytes.toString('utf8')
2624
+ const scan = { tags: [], last: undefined }
2625
+ for (const raw of text.split(`
2626
+ `)) {
2627
+ if (!scanPackedLine(scan, raw.trim())) return
2628
+ }
2629
+ return { tags: scan.tags, fullyPeeled: isFullyPeeled(text) }
2630
+ }
2631
+ function looseMatches(mainRoot, head, names, budget) {
2632
+ const matched = new Set()
2633
+ for (const name of names) {
2634
+ const text = readGitText(
2635
+ mainRoot,
2636
+ `.git/${TAGS_PREFIX}${name}`,
2637
+ MAX_REF_BYTES,
2638
+ )
2639
+ const id = text === undefined ? '' : firstLine2(text)
2640
+ if (!OBJECT_ID.test(id)) return
2641
+ const names =
2642
+ id === head || looseObjectNamesHead(mainRoot, id, head, budget)
2643
+ if (names === undefined) return
2644
+ if (names) matched.add(name)
2645
+ }
2646
+ return matched
2647
+ }
2648
+ function packedEntryNamesHead(mainRoot, head, entry, packed, budget) {
2649
+ if (
2650
+ entry.id === head &&
2651
+ entry.peeled !== undefined &&
2652
+ entry.peeled !== head
2653
+ ) {
2654
+ return
2655
+ }
2656
+ if (entry.id === head || entry.peeled === head) return true
2657
+ if (entry.peeled !== undefined || packed.fullyPeeled) return false
2658
+ return looseObjectNamesHead(mainRoot, entry.id, head, budget)
2659
+ }
2660
+ function resolveTagAtHead(mainRoot, head) {
2661
+ if (!OBJECT_ID.test(head)) return UNKNOWN_TAG
2662
+ const budget = { inflations: 0, bytes: 0 }
2663
+ const loose = looseTagNames(mainRoot)
2664
+ const matched = loose && looseMatches(mainRoot, head, loose, budget)
2665
+ const packed = packedTags(mainRoot)
2666
+ if (loose === undefined || matched === undefined || packed === undefined) {
2667
+ return UNKNOWN_TAG
2668
+ }
2669
+ const seen = new Set(loose)
2670
+ for (const entry of packed.tags) {
2671
+ if (seen.has(entry.name)) continue
2672
+ seen.add(entry.name)
2673
+ const names = packedEntryNamesHead(mainRoot, head, entry, packed, budget)
2674
+ if (names === undefined) return UNKNOWN_TAG
2675
+ if (names) matched.add(entry.name)
2676
+ }
2677
+ const [name, ...others] = matched
2678
+ if (name === undefined || others.length > 0) return UNKNOWN_TAG
2679
+ return TAG_NAME_PATTERN.test(name) ? { kind: 'tag', name } : UNKNOWN_TAG
2680
+ }
2681
+ function readTagAtHead(mainRoot, head) {
2682
+ try {
2683
+ return resolveTagAtHead(mainRoot, head)
2684
+ } catch {
2685
+ return UNKNOWN_TAG
2686
+ }
2687
+ }
2688
+
2689
+ // src/lib/connect-pins.ts
2690
+ var PIN_VALUE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/
2691
+ function failed(code) {
2692
+ return { kind: 'failed', code }
2693
+ }
2694
+ function isPlainObject(value) {
2695
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
2696
+ }
2697
+ function walkKey(root, key) {
2698
+ let current = root
2699
+ for (const segment of key.split('.')) {
2700
+ if (!isPlainObject(current) || !Object.hasOwn(current, segment)) {
2701
+ return
2702
+ }
2703
+ current = current[segment]
2704
+ }
2705
+ return current
2706
+ }
2707
+ function readPinValue(root, file, key) {
2708
+ const read = readContainedFile(root, file)
2709
+ if (read.kind === 'refused') {
2710
+ return failed(
2711
+ read.reason === 'too-large' ? 'pin-file-too-large' : 'pin-file-missing',
2712
+ )
2713
+ }
2714
+ let text
2715
+ try {
2716
+ text = new TextDecoder('utf-8', { fatal: true }).decode(read.bytes)
2717
+ } catch {
2718
+ return failed('pin-file-invalid')
2719
+ }
2720
+ const errors = []
2721
+ let parsed
2722
+ try {
2723
+ parsed = parse2(text, errors, { allowTrailingComma: true })
2724
+ } catch {
2725
+ return failed('pin-file-invalid')
2726
+ }
2727
+ if (errors.length > 0 || parsed === undefined)
2728
+ return failed('pin-file-invalid')
2729
+ if (!isPinKey(key)) return failed('pin-key-absent')
2730
+ const value = walkKey(parsed, key)
2731
+ if (value === undefined) return failed('pin-key-absent')
2732
+ if (typeof value !== 'string' || !PIN_VALUE_PATTERN.test(value)) {
2733
+ return failed('pin-value-invalid')
2734
+ }
2735
+ return { kind: 'ok', value }
2736
+ }
2737
+ var MAX_PIN_HINTS = 8
2738
+ var MAX_PIN_NOTES = 8
2739
+ var MAX_PIN_ROOT_LENGTH = 256
2740
+ var PIN_ROOT_PATTERN = /^\/[A-Za-z0-9._/-]*$/
2741
+ var PROJECT_KEY_PATTERN = /^[0-9a-f]{12}$/
2742
+ var NOTE_CODES = new Set([
2743
+ 'pin-file-missing',
2744
+ 'pin-file-too-large',
2745
+ 'pin-file-invalid',
2746
+ 'pin-key-absent',
2747
+ 'pin-value-invalid',
2748
+ 'pin-conflict',
2749
+ 'hints-truncated',
2750
+ 'notes-truncated',
2751
+ ])
2752
+ var REAL_READERS = {
2753
+ readPin: readPinValue,
2754
+ readTag: readTagAtHead,
2755
+ }
2756
+ function validRoot(root) {
2757
+ return root.length <= MAX_PIN_ROOT_LENGTH && PIN_ROOT_PATTERN.test(root)
2758
+ }
2759
+ function renderLine(parts) {
2760
+ const { projectRoot, upstream, value, file, checkoutRoot, tag } = parts
2761
+ return `pin: ${projectRoot} pins ${upstream} at ${value} (${file}); allowed checkout ${checkoutRoot} is ${upstream} at ${tag}. Check claims about ${upstream} at both versions; a claim that holds at the pinned version, fails at the other checkout and names no version is \`unscoped\`: report a \`code-mismatch\` with reason \`unscoped\` and cite the evidence from the other checkout; a claim that fails at the pinned version is \`stale\`.`
2762
+ }
2763
+ function tagLabel(tag) {
2764
+ return tag.kind === 'tag' && TAG_NAME_PATTERN.test(tag.name)
2765
+ ? tag.name
2766
+ : 'unknown'
2767
+ }
2768
+ function compareText(a, b) {
2769
+ return a < b ? -1 : a > b ? 1 : 0
2770
+ }
2771
+ function matchProject(declared, projects) {
2772
+ return (
2773
+ projects.find(
2774
+ (item) => item.entry === declared || item.aliases?.includes(declared),
2775
+ ) ?? projects.find((item) => item.root === declared)
2776
+ )
2777
+ }
2778
+ function groupPins(pins, projects) {
2779
+ const groups = new Map()
2780
+ for (const pin of pins) {
2781
+ if (!isGithubOwnerRepo(pin.upstream)) continue
2782
+ const pinning = matchProject(pin.project, projects)
2783
+ if (pinning === undefined) continue
2784
+ const upstream = pin.upstream.toLowerCase()
2785
+ const identity = JSON.stringify([pinning.root, upstream, pin.key])
2786
+ const group = groups.get(identity)
2787
+ if (group === undefined) {
2788
+ groups.set(identity, {
2789
+ pinning,
2790
+ upstream,
2791
+ key: pin.key,
2792
+ files: new Set([pin.file]),
2793
+ })
2794
+ } else {
2795
+ group.files.add(pin.file)
2796
+ }
2797
+ }
2798
+ return [...groups.values()]
2799
+ }
2800
+ function sortNotes(notes) {
2801
+ return [...notes].sort(
2802
+ (a, b) =>
2803
+ compareText(a.code, b.code) ||
2804
+ compareText(a.project ?? '', b.project ?? ''),
2805
+ )
2806
+ }
2807
+ function capNotes(notes) {
2808
+ const sorted = sortNotes(notes)
2809
+ if (sorted.length <= MAX_PIN_NOTES) return sorted
2810
+ return sortNotes([
2811
+ ...sorted.slice(0, MAX_PIN_NOTES - 1),
2812
+ { code: 'notes-truncated' },
2813
+ ])
2814
+ }
2815
+ function usableDeclaration(file, pinning) {
2816
+ return (
2817
+ file.length <= MAX_PIN_FILE_LENGTH &&
2818
+ PIN_FILE_PATTERN.test(file) &&
2819
+ PROJECT_KEY_PATTERN.test(pinning.key)
2820
+ )
2821
+ }
2822
+ function readyGroup(group, projects, readers, addNote) {
2823
+ const { pinning, upstream } = group
2824
+ const checkouts = projects.filter(
2825
+ (item) => item.root !== pinning.root && item.repo === upstream,
2826
+ )
2827
+ if (checkouts.length === 0) return
2828
+ const [file] = group.files
2829
+ if (group.files.size > 1 || file === undefined) {
2830
+ addNote({ code: 'pin-conflict' })
2831
+ return
2832
+ }
2833
+ const invalid = () =>
2834
+ addNote({ code: 'pin-value-invalid', project: pinning.key })
2835
+ if (!usableDeclaration(file, pinning)) {
2836
+ invalid()
2837
+ return
2838
+ }
2839
+ const renderable = checkouts.filter((item) => validRoot(item.root))
2840
+ const pinningRenderable = validRoot(pinning.root)
2841
+ if (renderable.length < checkouts.length || !pinningRenderable) invalid()
2842
+ if (renderable.length === 0 || !pinningRenderable) return
2843
+ const value = readers.readPin(pinning.root, file, group.key)
2844
+ if (value.kind === 'failed') {
2845
+ addNote({ code: value.code, project: pinning.key })
2846
+ return
2847
+ }
2848
+ if (!PIN_VALUE_PATTERN.test(value.value)) {
2849
+ invalid()
2850
+ return
2851
+ }
2852
+ return { group, file, value: value.value, checkouts: renderable }
2853
+ }
2854
+ function hintEntries(ready, tagOf) {
2855
+ const { group, file, value, checkouts } = ready
2856
+ const { pinning, upstream } = group
2857
+ return checkouts.map((checkout) => ({
2858
+ pinKey: pinning.key,
2859
+ upstream,
2860
+ key: group.key,
2861
+ checkoutKey: checkout.key,
2862
+ line: renderLine({
2863
+ projectRoot: pinning.root,
2864
+ upstream,
2865
+ value,
2866
+ file,
2867
+ checkoutRoot: checkout.root,
2868
+ tag: tagLabel(tagOf(checkout)),
2869
+ }),
2870
+ }))
2871
+ }
2872
+ function memoizedTags(readTag) {
2873
+ const seen = new Map()
2874
+ return (checkout) => {
2875
+ const { commit } = checkout
2876
+ if (commit === undefined) return { kind: 'unknown' }
2877
+ const memo = `${checkout.root}\x00${commit}`
2878
+ const known = seen.get(memo)
2879
+ if (known !== undefined) return known
2880
+ const tag = readTag(checkout.root, commit)
2881
+ seen.set(memo, tag)
2882
+ return tag
2883
+ }
2884
+ }
2885
+ function compareGroups(a, b) {
2886
+ return (
2887
+ compareText(a.pinning.key, b.pinning.key) ||
2888
+ compareText(a.upstream, b.upstream) ||
2889
+ compareText(a.key, b.key)
2890
+ )
2891
+ }
2892
+ function resolvePins(pins, projects, overrides = {}) {
2893
+ const readers = { ...REAL_READERS, ...overrides }
2894
+ const notes = new Map()
2895
+ const addNote = (note) => {
2896
+ notes.set(`${note.code}\x00${note.project ?? ''}`, note)
2897
+ }
2898
+ const tagOf = memoizedTags(readers.readTag)
2899
+ const entries = []
2900
+ let cut = false
2901
+ for (const group of groupPins(pins, projects).sort(compareGroups)) {
2902
+ if (cut) break
2903
+ const ready = readyGroup(group, projects, readers, addNote)
2904
+ if (ready === undefined) continue
2905
+ if (entries.length >= MAX_PIN_HINTS) {
2906
+ cut = true
2907
+ continue
2908
+ }
2909
+ entries.push(...hintEntries(ready, tagOf))
2910
+ cut = entries.length > MAX_PIN_HINTS
2911
+ }
2912
+ entries.sort(
2913
+ (a, b) =>
2914
+ compareText(a.pinKey, b.pinKey) ||
2915
+ compareText(a.upstream, b.upstream) ||
2916
+ compareText(a.key, b.key) ||
2917
+ compareText(a.checkoutKey, b.checkoutKey),
2918
+ )
2919
+ const kept = entries.slice(0, MAX_PIN_HINTS)
2920
+ if (cut) addNote({ code: 'hints-truncated' })
2921
+ const hints = {}
2922
+ for (const entry of kept) {
2923
+ const lines = hints[entry.pinKey] ?? []
2924
+ lines.push(entry.line)
2925
+ hints[entry.pinKey] = lines
2926
+ }
2927
+ return { hints, notes: capNotes([...notes.values()]) }
2928
+ }
2929
+ function readPinNotes(value) {
2930
+ if (!Array.isArray(value)) return []
2931
+ const notes = []
2932
+ for (const item of value) {
2933
+ const note = readPinNote(item)
2934
+ if (note !== undefined) notes.push(note)
2935
+ }
2936
+ return notes.slice(0, MAX_PIN_NOTES)
2937
+ }
2938
+ var GLOBAL_NOTE_CODES = new Set([
2939
+ 'pin-conflict',
2940
+ 'hints-truncated',
2941
+ 'notes-truncated',
2942
+ ])
2943
+ function readPinNote(item) {
2944
+ if (typeof item !== 'object' || item === null) return
2945
+ const { code, project } = item
2946
+ if (typeof code !== 'string' || !NOTE_CODES.has(code)) return
2947
+ if (GLOBAL_NOTE_CODES.has(code)) {
2948
+ return project === undefined ? { code } : undefined
2949
+ }
2950
+ return typeof project === 'string' && PROJECT_KEY_PATTERN.test(project)
2951
+ ? { code, project }
2952
+ : undefined
2953
+ }
2954
+ function renderPinsLine(notes) {
2955
+ if (notes.length === 0) return ''
2956
+ const parts = notes.map((note) =>
2957
+ note.project === undefined ? note.code : `${note.code} (${note.project})`,
2958
+ )
2959
+ return `Pins: ${parts.join(', ')}.`
2960
+ }
2239
2961
 
2240
2962
  // node_modules/.bun/js-yaml@4.3.2/node_modules/js-yaml/dist/js-yaml.mjs
2241
2963
  function getDefaultExportFromCjs(x) {
@@ -5913,10 +6635,10 @@ function parseFrontmatter(content) {
5913
6635
  function resolveStateRoot(env, homeDir) {
5914
6636
  const xdg = env.XDG_STATE_HOME
5915
6637
  const base =
5916
- xdg !== undefined && xdg !== '' && path4.isAbsolute(xdg)
6638
+ xdg !== undefined && xdg !== '' && path5.isAbsolute(xdg)
5917
6639
  ? xdg
5918
- : path4.join(homeDir, '.local', 'state')
5919
- return path4.join(base, 'systematic', 'connect')
6640
+ : path5.join(homeDir, '.local', 'state')
6641
+ return path5.join(base, 'systematic', 'connect')
5920
6642
  }
5921
6643
  var MAX_PROJECT_NAME = 100
5922
6644
  function projectKey(mainRoot) {
@@ -5926,7 +6648,7 @@ function projectKey(mainRoot) {
5926
6648
  .slice(0, 12)
5927
6649
  }
5928
6650
  function projectName(mainRoot) {
5929
- const base = path4.basename(mainRoot).replace(/[^A-Za-z0-9._-]+/g, '-')
6651
+ const base = path5.basename(mainRoot).replace(/[^A-Za-z0-9._-]+/g, '-')
5930
6652
  const trimmed = base.replace(/^[^A-Za-z0-9]+/, '').slice(0, MAX_PROJECT_NAME)
5931
6653
  return trimmed === '' ? 'project' : trimmed
5932
6654
  }
@@ -6201,7 +6923,7 @@ function checkCoverage(input) {
6201
6923
  incompleteFamilies,
6202
6924
  }
6203
6925
  }
6204
- function compareText(a, b) {
6926
+ function compareText2(a, b) {
6205
6927
  if (a < b) return -1
6206
6928
  return a > b ? 1 : 0
6207
6929
  }
@@ -6213,8 +6935,8 @@ function roundRobin(rules) {
6213
6935
  else list.push(rule)
6214
6936
  }
6215
6937
  const lists = [...byProject.entries()]
6216
- .sort(([a], [b]) => compareText(a, b))
6217
- .map(([, list]) => list.sort((a, b) => compareText(a.path, b.path)))
6938
+ .sort(([a], [b]) => compareText2(a, b))
6939
+ .map(([, list]) => list.sort((a, b) => compareText2(a.path, b.path)))
6218
6940
  const out = []
6219
6941
  for (let round = 0; out.length < rules.length; round++) {
6220
6942
  for (const list of lists) {
@@ -6243,7 +6965,7 @@ function planOffer(input) {
6243
6965
  else group.push(rule)
6244
6966
  }
6245
6967
  const ordered = [...groups.entries()]
6246
- .sort(([a], [b]) => compareText(a, b))
6968
+ .sort(([a], [b]) => compareText2(a, b))
6247
6969
  .flatMap(([, rules]) => roundRobin(rules))
6248
6970
  const order = ordered.map((rule) => rule.id)
6249
6971
  const offered = order.slice(0, size)
@@ -6391,7 +7113,7 @@ function pathProblem(rel) {
6391
7113
  if (rel.length > CANDIDATE_LIMITS.pathLength || CONTROL.test(rel)) {
6392
7114
  return 'malformed-candidate'
6393
7115
  }
6394
- if (path4.posix.isAbsolute(rel) || path4.win32.isAbsolute(rel)) {
7116
+ if (path5.posix.isAbsolute(rel) || path5.win32.isAbsolute(rel)) {
6395
7117
  return 'absolute-path'
6396
7118
  }
6397
7119
  if (rel.includes('\\')) return 'path-escape'
@@ -7208,7 +7930,7 @@ var REFRESH_PATH = /^docs\/solutions\/[A-Za-z0-9._/-]+\.md$/
7208
7930
  function isRefreshable(rel) {
7209
7931
  return (
7210
7932
  REFRESH_PATH.test(rel) &&
7211
- path4.posix.basename(rel) !== 'README.md' &&
7933
+ path5.posix.basename(rel) !== 'README.md' &&
7212
7934
  !rel.startsWith('docs/solutions/_archived/') &&
7213
7935
  !rel.startsWith('docs/solutions/patterns/')
7214
7936
  )
@@ -7279,6 +8001,8 @@ function renderSummary(model, digestPath, runRecordPath) {
7279
8001
  `Degraded because: ${model.degradeReasons.join(', ')}. This is not proof of absence.`,
7280
8002
  )
7281
8003
  }
8004
+ const pins = renderPinsLine(model.pinNotes ?? [])
8005
+ if (pins !== '') out.push(pins)
7282
8006
  if (model.candidates.length === 0 && model.recorded.length === 0) {
7283
8007
  out.push('No candidate in searched scope.')
7284
8008
  }
@@ -7306,45 +8030,45 @@ function isWorkName(name) {
7306
8030
  return WORK_NAME.test(name)
7307
8031
  }
7308
8032
  function workDirPath(stateRoot, runId) {
7309
- return path4.join(stateRoot, WORK_DIR, runId)
8033
+ return path5.join(stateRoot, WORK_DIR, runId)
7310
8034
  }
7311
8035
  function ensurePrivateDirectory(dir) {
7312
8036
  try {
7313
- const stat = fs5.lstatSync(dir)
8037
+ const stat = fs6.lstatSync(dir)
7314
8038
  if (stat.isSymbolicLink() || !stat.isDirectory()) return false
7315
- if ((stat.mode & 511) !== DIR_MODE) fs5.chmodSync(dir, DIR_MODE)
8039
+ if ((stat.mode & 511) !== DIR_MODE) fs6.chmodSync(dir, DIR_MODE)
7316
8040
  return true
7317
8041
  } catch (error) {
7318
8042
  if (errorCode4(error) !== 'ENOENT') return false
7319
8043
  }
7320
8044
  try {
7321
- fs5.mkdirSync(dir, { mode: DIR_MODE })
7322
- fs5.chmodSync(dir, DIR_MODE)
8045
+ fs6.mkdirSync(dir, { mode: DIR_MODE })
8046
+ fs6.chmodSync(dir, DIR_MODE)
7323
8047
  return true
7324
8048
  } catch {
7325
8049
  return false
7326
8050
  }
7327
8051
  }
7328
8052
  function cleanWorkRoot(stateRoot) {
7329
- const work = path4.join(stateRoot, WORK_DIR)
8053
+ const work = path5.join(stateRoot, WORK_DIR)
7330
8054
  try {
7331
- const stat = fs5.lstatSync(work)
8055
+ const stat = fs6.lstatSync(work)
7332
8056
  if (stat.isSymbolicLink() || !stat.isDirectory()) {
7333
- fs5.rmSync(work, { force: true })
8057
+ fs6.rmSync(work, { force: true })
7334
8058
  return
7335
8059
  }
7336
- for (const name of fs5.readdirSync(work)) {
7337
- fs5.rmSync(path4.join(work, name), { recursive: true, force: true })
8060
+ for (const name of fs6.readdirSync(work)) {
8061
+ fs6.rmSync(path5.join(work, name), { recursive: true, force: true })
7338
8062
  }
7339
8063
  } catch {}
7340
8064
  }
7341
8065
  function prepareWorkDir(stateRoot, runId) {
7342
8066
  if (!WORK_NAME.test(runId)) return
7343
- if (!ensurePrivateDirectory(path4.join(stateRoot, WORK_DIR))) return
8067
+ if (!ensurePrivateDirectory(path5.join(stateRoot, WORK_DIR))) return
7344
8068
  const dir = workDirPath(stateRoot, runId)
7345
8069
  try {
7346
- fs5.mkdirSync(dir, { mode: DIR_MODE })
7347
- fs5.chmodSync(dir, DIR_MODE)
8070
+ fs6.mkdirSync(dir, { mode: DIR_MODE })
8071
+ fs6.chmodSync(dir, DIR_MODE)
7348
8072
  return dir
7349
8073
  } catch {
7350
8074
  return
@@ -7353,25 +8077,25 @@ function prepareWorkDir(stateRoot, runId) {
7353
8077
  function removeWorkDir(stateRoot, runId) {
7354
8078
  if (!WORK_NAME.test(runId)) return
7355
8079
  try {
7356
- fs5.rmSync(workDirPath(stateRoot, runId), { recursive: true, force: true })
8080
+ fs6.rmSync(workDirPath(stateRoot, runId), { recursive: true, force: true })
7357
8081
  } catch {}
7358
8082
  }
7359
8083
  function writeWorkFile(dir, name, data) {
7360
8084
  if (!WORK_NAME.test(name)) throw new Error('invalid work file name')
7361
- const target = path4.join(dir, name)
8085
+ const target = path5.join(dir, name)
7362
8086
  const temporary = `${target}.tmp-${randomUUID()}`
7363
- const fd = fs5.openSync(temporary, 'wx', FILE_MODE)
8087
+ const fd = fs6.openSync(temporary, 'wx', FILE_MODE)
7364
8088
  try {
7365
8089
  try {
7366
- fs5.writeSync(fd, data)
7367
- fs5.fsyncSync(fd)
8090
+ fs6.writeSync(fd, data)
8091
+ fs6.fsyncSync(fd)
7368
8092
  } finally {
7369
- fs5.closeSync(fd)
8093
+ fs6.closeSync(fd)
7370
8094
  }
7371
- fs5.chmodSync(temporary, FILE_MODE)
7372
- fs5.renameSync(temporary, target)
8095
+ fs6.chmodSync(temporary, FILE_MODE)
8096
+ fs6.renameSync(temporary, target)
7373
8097
  } catch (error) {
7374
- fs5.rmSync(temporary, { force: true })
8098
+ fs6.rmSync(temporary, { force: true })
7375
8099
  throw error
7376
8100
  }
7377
8101
  }
@@ -7562,8 +8286,8 @@ import {
7562
8286
  createHash as createHash3,
7563
8287
  randomUUID as randomUUID2,
7564
8288
  } from 'node:crypto'
7565
- import fs6 from 'node:fs'
7566
- import path5 from 'node:path'
8289
+ import fs7 from 'node:fs'
8290
+ import path6 from 'node:path'
7567
8291
  var DIR_MODE2 = 448
7568
8292
  var FILE_MODE2 = 384
7569
8293
  var HOLDERLESS_LOCK_MAX_AGE_MS = 10 * 60 * 1000
@@ -7598,7 +8322,7 @@ function isRecord3(value) {
7598
8322
  }
7599
8323
  function lstatMaybe(target) {
7600
8324
  try {
7601
- return fs6.lstatSync(target)
8325
+ return fs7.lstatSync(target)
7602
8326
  } catch (error) {
7603
8327
  const code = errorCode5(error)
7604
8328
  if (code === 'ENOENT' || code === 'ENOTDIR') return
@@ -7607,24 +8331,24 @@ function lstatMaybe(target) {
7607
8331
  }
7608
8332
  function removeQuietly(target) {
7609
8333
  try {
7610
- fs6.rmSync(target, { recursive: true, force: true })
8334
+ fs7.rmSync(target, { recursive: true, force: true })
7611
8335
  } catch {}
7612
8336
  }
7613
8337
  function writeFileExclusive(file, data) {
7614
- const fd = fs6.openSync(file, 'wx', FILE_MODE2)
8338
+ const fd = fs7.openSync(file, 'wx', FILE_MODE2)
7615
8339
  try {
7616
- fs6.writeSync(fd, data)
7617
- fs6.fsyncSync(fd)
8340
+ fs7.writeSync(fd, data)
8341
+ fs7.fsyncSync(fd)
7618
8342
  } finally {
7619
- fs6.closeSync(fd)
8343
+ fs7.closeSync(fd)
7620
8344
  }
7621
- fs6.chmodSync(file, FILE_MODE2)
8345
+ fs7.chmodSync(file, FILE_MODE2)
7622
8346
  }
7623
8347
  function writeFileAtomic(target, data) {
7624
8348
  const temporary = `${target}.tmp-${randomUUID2()}`
7625
8349
  try {
7626
8350
  writeFileExclusive(temporary, data)
7627
- fs6.renameSync(temporary, target)
8351
+ fs7.renameSync(temporary, target)
7628
8352
  } catch (error) {
7629
8353
  removeQuietly(temporary)
7630
8354
  throw error
@@ -7645,8 +8369,8 @@ function codepointOrder2(a, b) {
7645
8369
  function ensureOwnDirectory(dir) {
7646
8370
  const existing = lstatMaybe(dir)
7647
8371
  if (existing === undefined) {
7648
- fs6.mkdirSync(dir, { recursive: true, mode: DIR_MODE2 })
7649
- fs6.chmodSync(dir, DIR_MODE2)
8372
+ fs7.mkdirSync(dir, { recursive: true, mode: DIR_MODE2 })
8373
+ fs7.chmodSync(dir, DIR_MODE2)
7650
8374
  return { ok: true, tightened: false }
7651
8375
  }
7652
8376
  if (existing.isSymbolicLink()) return { ok: false, reason: 'symlink' }
@@ -7656,19 +8380,19 @@ function ensureOwnDirectory(dir) {
7656
8380
  return { ok: false, reason: 'foreign-owner' }
7657
8381
  }
7658
8382
  if ((existing.mode & 511) !== DIR_MODE2) {
7659
- fs6.chmodSync(dir, DIR_MODE2)
8383
+ fs7.chmodSync(dir, DIR_MODE2)
7660
8384
  return { ok: true, tightened: true }
7661
8385
  }
7662
8386
  return { ok: true, tightened: false }
7663
8387
  }
7664
8388
  function prepareStateRoot(root, options) {
7665
- const resolved = path5.resolve(root)
8389
+ const resolved = path6.resolve(root)
7666
8390
  const container = containerRefusal(resolved, options.allowedRoots)
7667
8391
  if (container !== undefined) return { status: 'refused', reason: container }
7668
8392
  try {
7669
8393
  const rootCheck = ensureOwnDirectory(resolved)
7670
8394
  if (!rootCheck.ok) return { status: 'refused', reason: rootCheck.reason }
7671
- const runsCheck = ensureOwnDirectory(path5.join(resolved, RUNS_DIR))
8395
+ const runsCheck = ensureOwnDirectory(path6.join(resolved, RUNS_DIR))
7672
8396
  if (!runsCheck.ok) return { status: 'refused', reason: runsCheck.reason }
7673
8397
  return {
7674
8398
  status: 'ok',
@@ -7693,7 +8417,7 @@ function processStartTime(pid) {
7693
8417
  if (!Number.isSafeInteger(pid) || pid <= 0) return
7694
8418
  try {
7695
8419
  if (process.platform === 'linux') {
7696
- return parseLinuxStartTime(fs6.readFileSync(`/proc/${pid}/stat`, 'utf8'))
8420
+ return parseLinuxStartTime(fs7.readFileSync(`/proc/${pid}/stat`, 'utf8'))
7697
8421
  }
7698
8422
  if (process.platform === 'darwin') {
7699
8423
  const probe = spawnSync2(
@@ -7760,9 +8484,9 @@ function holdsLock(handle) {
7760
8484
  return read.kind === 'holder' && read.holder.nonce === handle.nonce
7761
8485
  }
7762
8486
  function createLock(root, pid, processes) {
7763
- const lockDir = path5.join(root, LOCK_DIR)
8487
+ const lockDir = path6.join(root, LOCK_DIR)
7764
8488
  try {
7765
- fs6.mkdirSync(lockDir, { mode: DIR_MODE2 })
8489
+ fs7.mkdirSync(lockDir, { mode: DIR_MODE2 })
7766
8490
  } catch (error) {
7767
8491
  return errorCode5(error) === 'EEXIST'
7768
8492
  ? { kind: 'exists' }
@@ -7776,15 +8500,15 @@ function createLock(root, pid, processes) {
7776
8500
  nonce,
7777
8501
  }
7778
8502
  try {
7779
- fs6.chmodSync(lockDir, DIR_MODE2)
7780
- const temporary = path5.join(lockDir, `${HOLDER_FILE}.tmp-${randomUUID2()}`)
8503
+ fs7.chmodSync(lockDir, DIR_MODE2)
8504
+ const temporary = path6.join(lockDir, `${HOLDER_FILE}.tmp-${randomUUID2()}`)
7781
8505
  try {
7782
8506
  writeFileExclusive(
7783
8507
  temporary,
7784
8508
  `${JSON.stringify(holder)}
7785
8509
  `,
7786
8510
  )
7787
- fs6.renameSync(temporary, path5.join(lockDir, HOLDER_FILE))
8511
+ fs7.renameSync(temporary, path6.join(lockDir, HOLDER_FILE))
7788
8512
  } catch (error) {
7789
8513
  removeQuietly(temporary)
7790
8514
  throw error
@@ -7799,7 +8523,7 @@ function createLock(root, pid, processes) {
7799
8523
  function judgeLock(root, lockDir, processes, now) {
7800
8524
  const read = readHolderAt(root, LOCK_DIR)
7801
8525
  if (read.kind === 'none') {
7802
- const age = now - fs6.lstatSync(lockDir).mtimeMs
8526
+ const age = now - fs7.lstatSync(lockDir).mtimeMs
7803
8527
  return age >= HOLDERLESS_LOCK_MAX_AGE_MS
7804
8528
  ? {
7805
8529
  action: 'reclaim',
@@ -7833,7 +8557,7 @@ function judgeLock(root, lockDir, processes, now) {
7833
8557
  function movedIsJudged(root, stale, expectedNonce, now) {
7834
8558
  const stat = lstatMaybe(stale)
7835
8559
  if (stat === undefined || !stat.isDirectory()) return false
7836
- const read = readHolderAt(root, path5.basename(stale))
8560
+ const read = readHolderAt(root, path6.basename(stale))
7837
8561
  if (expectedNonce !== null) {
7838
8562
  return read.kind === 'holder' && read.holder.nonce === expectedNonce
7839
8563
  }
@@ -7843,13 +8567,13 @@ function movedIsJudged(root, stale, expectedNonce, now) {
7843
8567
  }
7844
8568
  function restoreLock(stale, lockDir) {
7845
8569
  try {
7846
- if (lstatMaybe(lockDir) === undefined) fs6.renameSync(stale, lockDir)
8570
+ if (lstatMaybe(lockDir) === undefined) fs7.renameSync(stale, lockDir)
7847
8571
  } catch {}
7848
8572
  }
7849
8573
  function reclaimLock(root, lockDir, verdict, pid, processes, now) {
7850
- const stale = path5.join(root, `${LOCK_DIR}.stale-${randomUUID2()}`)
8574
+ const stale = path6.join(root, `${LOCK_DIR}.stale-${randomUUID2()}`)
7851
8575
  try {
7852
- fs6.renameSync(lockDir, stale)
8576
+ fs7.renameSync(lockDir, stale)
7853
8577
  } catch (error) {
7854
8578
  return errorCode5(error) === 'ENOENT'
7855
8579
  ? { status: 'busy', reason: 'reclaim-contended' }
@@ -7876,7 +8600,7 @@ function acquireLock(root, options = {}) {
7876
8600
  const pid = options.pid ?? process.pid
7877
8601
  const processes = options.processes ?? systemProcessTable
7878
8602
  const now = options.now ?? Date.now
7879
- const lockDir = path5.join(root, LOCK_DIR)
8603
+ const lockDir = path6.join(root, LOCK_DIR)
7880
8604
  try {
7881
8605
  const created = createLock(root, pid, processes)
7882
8606
  if (created.kind === 'created') {
@@ -7908,7 +8632,7 @@ function acquireLock(root, options = {}) {
7908
8632
  function releaseLock(handle) {
7909
8633
  if (!holdsLock(handle)) return 'lost'
7910
8634
  try {
7911
- fs6.rmSync(path5.join(handle.root, LOCK_DIR), {
8635
+ fs7.rmSync(path6.join(handle.root, LOCK_DIR), {
7912
8636
  recursive: true,
7913
8637
  force: true,
7914
8638
  })
@@ -7918,13 +8642,13 @@ function releaseLock(handle) {
7918
8642
  }
7919
8643
  }
7920
8644
  function forceUnlock(root) {
7921
- const lockDir = path5.join(root, LOCK_DIR)
8645
+ const lockDir = path6.join(root, LOCK_DIR)
7922
8646
  try {
7923
8647
  if (lstatMaybe(lockDir) === undefined) return { status: 'no-lock' }
7924
8648
  const read = readHolderAt(root, LOCK_DIR)
7925
- const aside = path5.join(root, `${LOCK_DIR}.unlocked-${randomUUID2()}`)
7926
- fs6.renameSync(lockDir, aside)
7927
- fs6.rmSync(aside, { recursive: true, force: true })
8649
+ const aside = path6.join(root, `${LOCK_DIR}.unlocked-${randomUUID2()}`)
8650
+ fs7.renameSync(lockDir, aside)
8651
+ fs7.rmSync(aside, { recursive: true, force: true })
7928
8652
  return read.kind === 'holder'
7929
8653
  ? {
7930
8654
  status: 'unlocked',
@@ -7946,7 +8670,7 @@ function isRunId(value) {
7946
8670
  return SAFE_NAME.test(value) && !value.endsWith(STAGING_SUFFIX)
7947
8671
  }
7948
8672
  function normalizePath(value) {
7949
- return path5.posix.normalize(value)
8673
+ return path6.posix.normalize(value)
7950
8674
  }
7951
8675
  function validPath(value) {
7952
8676
  if (!plainText(value, MAX_PATH_LENGTH)) return false
@@ -8251,7 +8975,7 @@ function writeLedger(root, ledger) {
8251
8975
  if (Buffer.byteLength(text) > MAX_LEDGER_BYTES) {
8252
8976
  throw new Error('the ledger would be larger than the size limit')
8253
8977
  }
8254
- writeFileAtomic(path5.join(root, LEDGER_FILE), text)
8978
+ writeFileAtomic(path6.join(root, LEDGER_FILE), text)
8255
8979
  }
8256
8980
  function sameSources(current, prior) {
8257
8981
  return current.every((source) =>
@@ -8612,14 +9336,14 @@ function withEntries(ledger, entries) {
8612
9336
  }
8613
9337
  function stageRun(staging, files) {
8614
9338
  try {
8615
- fs6.mkdirSync(staging, { mode: DIR_MODE2 })
9339
+ fs7.mkdirSync(staging, { mode: DIR_MODE2 })
8616
9340
  } catch (error) {
8617
9341
  return errorCode5(error) === 'EEXIST' ? 'run-exists' : 'write-failed'
8618
9342
  }
8619
9343
  try {
8620
- fs6.chmodSync(staging, DIR_MODE2)
9344
+ fs7.chmodSync(staging, DIR_MODE2)
8621
9345
  for (const [name, content] of Object.entries(files)) {
8622
- writeFileExclusive(path5.join(staging, name), content)
9346
+ writeFileExclusive(path6.join(staging, name), content)
8623
9347
  }
8624
9348
  return
8625
9349
  } catch {
@@ -8635,8 +9359,8 @@ function publishRun(root, lock, input, options = {}) {
8635
9359
  if (prior.status !== 'ok') {
8636
9360
  return { status: 'failed', reason: 'ledger-unreadable' }
8637
9361
  }
8638
- const runs = path5.join(root, RUNS_DIR)
8639
- const finalDir = path5.join(runs, input.runId)
9362
+ const runs = path6.join(root, RUNS_DIR)
9363
+ const finalDir = path6.join(runs, input.runId)
8640
9364
  const staging = `${finalDir}${STAGING_SUFFIX}`
8641
9365
  try {
8642
9366
  const runsStat = lstatMaybe(runs)
@@ -8653,7 +9377,7 @@ function publishRun(root, lock, input, options = {}) {
8653
9377
  if (staged !== undefined) return { status: 'failed', reason: staged }
8654
9378
  options.hooks?.beforeCommit?.()
8655
9379
  try {
8656
- fs6.renameSync(staging, finalDir)
9380
+ fs7.renameSync(staging, finalDir)
8657
9381
  } catch {
8658
9382
  removeQuietly(staging)
8659
9383
  return { status: 'failed', reason: 'write-failed' }
@@ -8687,17 +9411,17 @@ function rewriteRunFiles(root, lock, runId, files) {
8687
9411
  if (names.length > MAX_RUN_FILES || !names.every((n) => SAFE_NAME.test(n))) {
8688
9412
  return 'failed'
8689
9413
  }
8690
- const dir = path5.join(root, RUNS_DIR, runId)
9414
+ const dir = path6.join(root, RUNS_DIR, runId)
8691
9415
  try {
8692
9416
  const stat = lstatMaybe(dir)
8693
9417
  if (stat === undefined || !stat.isDirectory()) return 'failed'
8694
9418
  for (const name of names) {
8695
- const target = path5.join(dir, name)
9419
+ const target = path6.join(dir, name)
8696
9420
  const existing = lstatMaybe(target)
8697
9421
  if (existing === undefined || !existing.isFile()) return 'failed'
8698
9422
  }
8699
9423
  for (const [name, content] of Object.entries(files)) {
8700
- writeFileAtomic(path5.join(dir, name), content)
9424
+ writeFileAtomic(path6.join(dir, name), content)
8701
9425
  }
8702
9426
  return 'rewritten'
8703
9427
  } catch {
@@ -8725,14 +9449,14 @@ function newImportRunId(now = Date.now()) {
8725
9449
  function listImportRuns(root) {
8726
9450
  let names
8727
9451
  try {
8728
- names = fs6.readdirSync(path5.join(root, RUNS_DIR))
9452
+ names = fs7.readdirSync(path6.join(root, RUNS_DIR))
8729
9453
  } catch {
8730
9454
  return []
8731
9455
  }
8732
9456
  return names
8733
9457
  .filter((name) => name.startsWith(IMPORT_RUN_PREFIX) && isRunId(name))
8734
9458
  .filter((name) =>
8735
- lstatMaybe(path5.join(root, RUNS_DIR, name))?.isDirectory(),
9459
+ lstatMaybe(path6.join(root, RUNS_DIR, name))?.isDirectory(),
8736
9460
  )
8737
9461
  .sort((a, b) => codepointOrder2(b, a))
8738
9462
  .slice(0, MAX_IMPORT_RUNS_LISTED)
@@ -8803,7 +9527,7 @@ var INVOCATION_FILE = 'invocation.json'
8803
9527
  var MAX_CI_RUN_BYTES = 1024
8804
9528
  var MAX_INVOCATION_BYTES = 1024 * 1024
8805
9529
  var MAX_INVOCATION_NAME_LENGTH = 200
8806
- var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
9530
+ var OBJECT_ID2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
8807
9531
  var REPO_SLUG = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
8808
9532
  var INVOCATION_OUTCOMES = ['complete', 'degraded', 'busy', 'failed']
8809
9533
  function isInvocationOutcome(value) {
@@ -8838,7 +9562,7 @@ function parseInvocationProject(item) {
8838
9562
  if (!isProjectKey(key) || !plainText(name, MAX_INVOCATION_NAME_LENGTH)) {
8839
9563
  return
8840
9564
  }
8841
- if (!optionalMatch(repo, REPO_SLUG) || !optionalMatch(commit, OBJECT_ID)) {
9565
+ if (!optionalMatch(repo, REPO_SLUG) || !optionalMatch(commit, OBJECT_ID2)) {
8842
9566
  return
8843
9567
  }
8844
9568
  return {
@@ -8904,7 +9628,7 @@ function writeInvocationRecord(root, record, options = {}) {
8904
9628
  const stat = lstatMaybe(root)
8905
9629
  if (stat === undefined || !stat.isDirectory()) return 'failed'
8906
9630
  writeFileAtomic(
8907
- path5.join(root, INVOCATION_FILE),
9631
+ path6.join(root, INVOCATION_FILE),
8908
9632
  `${JSON.stringify(clean, null, 2)}
8909
9633
  `,
8910
9634
  )
@@ -8926,19 +9650,19 @@ function readInvocationRecord(root) {
8926
9650
  }
8927
9651
  function pruneRuns(root, lock, options = {}) {
8928
9652
  if (!holdsLock(lock)) return { status: 'failed', reason: 'lock-lost' }
8929
- const runs = path5.join(root, RUNS_DIR)
9653
+ const runs = path6.join(root, RUNS_DIR)
8930
9654
  const now = (options.now ?? Date.now)()
8931
9655
  const removedRuns = []
8932
9656
  const removedStaging = []
8933
9657
  const failed = []
8934
9658
  let names
8935
9659
  try {
8936
- names = fs6.readdirSync(runs)
9660
+ names = fs7.readdirSync(runs)
8937
9661
  } catch {
8938
9662
  return { status: 'failed', reason: 'unreadable' }
8939
9663
  }
8940
9664
  for (const name of names) {
8941
- const outcome = pruneEntry(path5.join(runs, name), name, now)
9665
+ const outcome = pruneEntry(path6.join(runs, name), name, now)
8942
9666
  if (outcome === 'failed') failed.push(name)
8943
9667
  else if (outcome === 'run') removedRuns.push(name)
8944
9668
  else if (outcome === 'staging') removedStaging.push(name)
@@ -8953,7 +9677,7 @@ function pruneEntry(full, name, now) {
8953
9677
  const stat = lstatMaybe(full)
8954
9678
  if (stat === undefined || !stat.isDirectory()) return 'kept'
8955
9679
  if (!staging && now - stat.mtimeMs <= RUN_RETENTION_MS) return 'kept'
8956
- fs6.rmSync(full, { recursive: true, force: true })
9680
+ fs7.rmSync(full, { recursive: true, force: true })
8957
9681
  return staging ? 'staging' : 'run'
8958
9682
  } catch {
8959
9683
  return 'failed'
@@ -9038,9 +9762,9 @@ function clearLedger(root, options = {}) {
9038
9762
  return { status: 'failed', reason: 'lock-failed' }
9039
9763
  }
9040
9764
  try {
9041
- const file = path5.join(root, LEDGER_FILE)
9765
+ const file = path6.join(root, LEDGER_FILE)
9042
9766
  const existed = lstatMaybe(file) !== undefined
9043
- fs6.rmSync(file, { force: true })
9767
+ fs7.rmSync(file, { force: true })
9044
9768
  return { status: 'cleared', removed: existed }
9045
9769
  } catch {
9046
9770
  return { status: 'failed', reason: 'write-failed' }
@@ -9067,9 +9791,9 @@ var CANDIDATE_ID = /^[0-9a-f]{64}$/
9067
9791
  var MANIFEST_HASH = /^[0-9a-f]{16}$/
9068
9792
  var DIGITS = /^[0-9]{1,20}$/
9069
9793
  var DATE = /^\d{4}-\d{2}-\d{2}$/
9070
- var REPO = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
9794
+ var REPO2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
9071
9795
  var TOKEN = /^[a-z][a-z0-9-]{0,39}$/
9072
- var OBJECT_ID2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
9796
+ var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
9073
9797
  function manifestMarker(hash) {
9074
9798
  return `<!-- connect-manifest:${hash} -->`
9075
9799
  }
@@ -9133,17 +9857,17 @@ function lockOptions(options) {
9133
9857
  function writeFileAtomic2(target, data) {
9134
9858
  const temporary = `${target}.tmp-${randomUUID3()}`
9135
9859
  try {
9136
- const fd = fs7.openSync(temporary, 'wx', 384)
9860
+ const fd = fs8.openSync(temporary, 'wx', 384)
9137
9861
  try {
9138
- fs7.writeSync(fd, data)
9139
- fs7.fsyncSync(fd)
9862
+ fs8.writeSync(fd, data)
9863
+ fs8.fsyncSync(fd)
9140
9864
  } finally {
9141
- fs7.closeSync(fd)
9865
+ fs8.closeSync(fd)
9142
9866
  }
9143
- fs7.chmodSync(temporary, 384)
9144
- fs7.renameSync(temporary, target)
9867
+ fs8.chmodSync(temporary, 384)
9868
+ fs8.renameSync(temporary, target)
9145
9869
  } catch (error) {
9146
- fs7.rmSync(temporary, { force: true })
9870
+ fs8.rmSync(temporary, { force: true })
9147
9871
  throw error
9148
9872
  }
9149
9873
  }
@@ -9263,11 +9987,11 @@ var MAX_BODY_BYTES = 512 * 1024
9263
9987
  function readReportBody(file) {
9264
9988
  let directory
9265
9989
  try {
9266
- directory = fs7.realpathSync.native(path6.dirname(file))
9990
+ directory = fs8.realpathSync.native(path7.dirname(file))
9267
9991
  } catch {
9268
9992
  return { status: 'failed', reason: 'body-unreadable' }
9269
9993
  }
9270
- const read = readContainedFile(directory, path6.basename(file), {
9994
+ const read = readContainedFile(directory, path7.basename(file), {
9271
9995
  maxBytes: MAX_BODY_BYTES,
9272
9996
  })
9273
9997
  if (read.kind === 'bytes') {
@@ -9326,13 +10050,13 @@ function evidenceItemOf(item, heads, repos) {
9326
10050
  if (evidencePath === undefined) return
9327
10051
  const span = spanOf(item.start, item.end)
9328
10052
  const head =
9329
- typeof item.head === 'string' && OBJECT_ID2.test(item.head)
10053
+ typeof item.head === 'string' && OBJECT_ID3.test(item.head)
9330
10054
  ? item.head
9331
10055
  : typeof item.project === 'string'
9332
10056
  ? heads.get(item.project)
9333
10057
  : undefined
9334
10058
  const repo =
9335
- typeof item.repo === 'string' && REPO.test(item.repo)
10059
+ typeof item.repo === 'string' && REPO2.test(item.repo)
9336
10060
  ? item.repo
9337
10061
  : typeof item.project === 'string'
9338
10062
  ? repos.get(item.project)
@@ -9395,7 +10119,7 @@ function payloadFromStore(raw) {
9395
10119
  return {
9396
10120
  id: raw.id,
9397
10121
  ...text,
9398
- ...(typeof repo === 'string' && REPO.test(repo) ? { repo } : {}),
10122
+ ...(typeof repo === 'string' && REPO2.test(repo) ? { repo } : {}),
9399
10123
  ...(typeof firstShown === 'string' && validDate(firstShown)
9400
10124
  ? { firstShown }
9401
10125
  : {}),
@@ -9477,7 +10201,7 @@ function withManifest(stored, added) {
9477
10201
  }
9478
10202
  function writeManifestStore(root, manifests) {
9479
10203
  writeFileAtomic2(
9480
- path6.join(root, MANIFEST_FILE),
10204
+ path7.join(root, MANIFEST_FILE),
9481
10205
  `${JSON.stringify({ version: 1, manifests }, null, 2)}
9482
10206
  `,
9483
10207
  )
@@ -9528,7 +10252,7 @@ function repoMap(value) {
9528
10252
  if (
9529
10253
  typeof root === 'string' &&
9530
10254
  typeof repo === 'string' &&
9531
- REPO.test(repo)
10255
+ REPO2.test(repo)
9532
10256
  ) {
9533
10257
  out.set(root, repo)
9534
10258
  }
@@ -9544,7 +10268,7 @@ function commitMap(value) {
9544
10268
  if (
9545
10269
  typeof root === 'string' &&
9546
10270
  typeof commit === 'string' &&
9547
- OBJECT_ID2.test(commit)
10271
+ OBJECT_ID3.test(commit)
9548
10272
  ) {
9549
10273
  out.set(root, commit)
9550
10274
  }
@@ -9588,13 +10312,21 @@ var OUTCOME_SENTENCE = {
9588
10312
  function isRed(outcome) {
9589
10313
  return outcome === 'failed' || outcome === 'no-final-line'
9590
10314
  }
10315
+ var SYSTEMATIC_REPO = 'marcusrbrown/systematic'
9591
10316
  function validRequest(request) {
9592
10317
  return (
9593
10318
  validDate(request.date) &&
9594
10319
  isDigits(request.runId) &&
9595
- isDigits(request.attempt)
10320
+ isDigits(request.attempt) &&
10321
+ (request.repo === undefined || isGithubOwnerRepo(request.repo))
9596
10322
  )
9597
10323
  }
10324
+ function fetchRepoOf(request) {
10325
+ const { repo } = request
10326
+ return repo === undefined || repo.toLowerCase() === SYSTEMATIC_REPO
10327
+ ? undefined
10328
+ : repo
10329
+ }
9598
10330
  function factsOf(id, payload) {
9599
10331
  const target =
9600
10332
  payload.repo === undefined
@@ -9627,10 +10359,11 @@ function factsOf(id, payload) {
9627
10359
  return lines.join(`
9628
10360
  `)
9629
10361
  }
9630
- function fetchWord(payload) {
9631
- return `${payload.runId}.${payload.attempt}`
10362
+ function fetchWord(payload, repo) {
10363
+ const run = `${payload.runId}.${payload.attempt}`
10364
+ return repo === undefined ? run : `${repo}:${run}`
9632
10365
  }
9633
- function blockOf(position, entry, revision, payload, isNew) {
10366
+ function blockOf(position, entry, revision, payload, isNew, fetchRepo) {
9634
10367
  const { id } = entry
9635
10368
  const marks = [
9636
10369
  ...(isNew ? ['new'] : []),
@@ -9641,7 +10374,7 @@ function blockOf(position, entry, revision, payload, isNew) {
9641
10374
  '',
9642
10375
  ]
9643
10376
  lines.push(
9644
- `- Fetch: \`/ce:connect fetch:${fetchWord(payload)}\` (run ${payload.runId}, attempt ${payload.attempt})`,
10377
+ `- Fetch: \`/ce:connect fetch:${fetchWord(payload, fetchRepo)}\` (run ${payload.runId}, attempt ${payload.attempt})`,
9645
10378
  '',
9646
10379
  fenceText(factsOf(id, payload)),
9647
10380
  )
@@ -9665,10 +10398,10 @@ function ranges(positions) {
9665
10398
  .map(([from, to]) => (from === to ? `${from}` : `${from}-${to}`))
9666
10399
  .join(', ')
9667
10400
  }
9668
- function fetchLines(rows) {
10401
+ function fetchLines(rows, repo) {
9669
10402
  const byFetch = new Map()
9670
10403
  rows.forEach((row, index) => {
9671
- const word = fetchWord(row.payload)
10404
+ const word = fetchWord(row.payload, repo)
9672
10405
  const list = byFetch.get(word) ?? []
9673
10406
  list.push(index + 1)
9674
10407
  byFetch.set(word, list)
@@ -9728,7 +10461,7 @@ function assembleReport(input, shown, named) {
9728
10461
  const rows = input.rows.slice(0, shown)
9729
10462
  const ids = rows.map((row) => row.id)
9730
10463
  const hash = manifestHash(ids)
9731
- const fetch = fetchLines(rows)
10464
+ const fetch = fetchLines(rows, input.fetchRepo)
9732
10465
  const fresh = rows.filter((row) => row.isNew).length
9733
10466
  const open = input.rows.length
9734
10467
  const out = [manifestMarker(hash), '', ...headOf(input)]
@@ -9851,7 +10584,7 @@ function factLines(invocation, run) {
9851
10584
  }
9852
10585
  return lines
9853
10586
  }
9854
- function rowsOf(open, payloads, date) {
10587
+ function rowsOf(open, payloads, date, fetchRepo) {
9855
10588
  const rows = []
9856
10589
  const unverified = []
9857
10590
  for (const entry of open) {
@@ -9866,7 +10599,7 @@ function rowsOf(open, payloads, date) {
9866
10599
  id: entry.id,
9867
10600
  payload: held,
9868
10601
  isNew,
9869
- block: blockOf(rows.length + 1, entry, revision, held, isNew),
10602
+ block: blockOf(rows.length + 1, entry, revision, held, isNew, fetchRepo),
9870
10603
  })
9871
10604
  }
9872
10605
  return { rows, unverified }
@@ -9909,7 +10642,8 @@ function renderState(root, request, recordState) {
9909
10642
  proposed(run, new Set(open.map((entry) => entry.id)), request),
9910
10643
  )
9911
10644
  const outcome = outcomeOf(invocation)
9912
- const { rows, unverified } = rowsOf(open, payloads, request.date)
10645
+ const fetchRepo = fetchRepoOf(request)
10646
+ const { rows, unverified } = rowsOf(open, payloads, request.date, fetchRepo)
9913
10647
  const input = {
9914
10648
  outcome,
9915
10649
  facts: factLines(invocation, run),
@@ -9917,6 +10651,7 @@ function renderState(root, request, recordState) {
9917
10651
  stateUpdated: recordState,
9918
10652
  rows,
9919
10653
  unverified,
10654
+ ...(fetchRepo === undefined ? {} : { fetchRepo }),
9920
10655
  }
9921
10656
  const { shown, named } = fitReport(input)
9922
10657
  const result = assembleReport(input, shown, named)
@@ -9930,10 +10665,10 @@ function renderState(root, request, recordState) {
9930
10665
  if (recordState && Buffer.byteLength(storeText) > MAX_PAYLOAD_BYTES) {
9931
10666
  return { status: 'failed', reason: 'payload-store-too-large' }
9932
10667
  }
9933
- const bodyFile = path6.join(root, REPORT_FILE)
10668
+ const bodyFile = path7.join(root, REPORT_FILE)
9934
10669
  try {
9935
10670
  if (loaded.stores.manifests !== undefined) {
9936
- writeFileAtomic2(path6.join(root, PAYLOAD_FILE), storeText)
10671
+ writeFileAtomic2(path7.join(root, PAYLOAD_FILE), storeText)
9937
10672
  writeManifestStore(
9938
10673
  root,
9939
10674
  withManifest(loaded.stores.manifests, {
@@ -10143,8 +10878,8 @@ function applyTicks(root, request, options = {}) {
10143
10878
  }
10144
10879
 
10145
10880
  // src/lib/connect-import.ts
10146
- import fs8 from 'node:fs'
10147
- import path7 from 'node:path'
10881
+ import fs9 from 'node:fs'
10882
+ import path8 from 'node:path'
10148
10883
  var IMPORT_RECORD_FILE = 'run.json'
10149
10884
  var MAX_IMPORT_RECORD_BYTES = 2 * 1024 * 1024
10150
10885
  var MAX_IMPORT_PROJECTS = 64
@@ -10153,7 +10888,7 @@ var MAX_ROOT_LENGTH = 4096
10153
10888
  var RUN_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
10154
10889
  var PROJECT_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/
10155
10890
  var REPO_SLUG2 = /^[a-z0-9][a-z0-9-]{0,38}\/[a-z0-9._-]{1,100}$/
10156
- var OBJECT_ID3 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
10891
+ var OBJECT_ID4 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
10157
10892
  var CANDIDATE_ID2 = /^[0-9a-f]{64}$/
10158
10893
  var CONTROL2 = /[\p{Cc}\p{Cf}]/u
10159
10894
  var CORPUS_PATH = /^docs\/(?:solutions|plans|brainstorms)\//
@@ -10171,7 +10906,7 @@ function plainString(value, max) {
10171
10906
  function parseProject(value) {
10172
10907
  if (!isRecord5(value)) return
10173
10908
  const { root, key, name, repo, commit } = value
10174
- if (!plainString(root, MAX_ROOT_LENGTH) || !path7.posix.isAbsolute(root)) {
10909
+ if (!plainString(root, MAX_ROOT_LENGTH) || !path8.posix.isAbsolute(root)) {
10175
10910
  return
10176
10911
  }
10177
10912
  if (key !== projectKey(root)) return
@@ -10184,7 +10919,7 @@ function parseProject(value) {
10184
10919
  }
10185
10920
  if (
10186
10921
  commit !== undefined &&
10187
- !(typeof commit === 'string' && OBJECT_ID3.test(commit))
10922
+ !(typeof commit === 'string' && OBJECT_ID4.test(commit))
10188
10923
  ) {
10189
10924
  return
10190
10925
  }
@@ -10234,8 +10969,8 @@ function parseImportRecord(value) {
10234
10969
  function readImportRecord(directory) {
10235
10970
  let real
10236
10971
  try {
10237
- real = fs8.realpathSync.native(directory)
10238
- if (!fs8.statSync(real).isDirectory()) {
10972
+ real = fs9.realpathSync.native(directory)
10973
+ if (!fs9.statSync(real).isDirectory()) {
10239
10974
  return { status: 'failed', reason: 'directory-unreadable' }
10240
10975
  }
10241
10976
  } catch {
@@ -10807,146 +11542,76 @@ function renderImportDigest(model, written, generatedAt) {
10807
11542
  `
10808
11543
  }
10809
11544
 
10810
- // src/lib/connect-repo-identity.ts
10811
- var MAX_CONFIG_BYTES = 1024 * 1024
10812
- var MAX_HEAD_BYTES = 4096
10813
- var MAX_REF_BYTES = 4096
10814
- var MAX_PACKED_REFS_BYTES = 8 * 1024 * 1024
10815
- var OWNER = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/
10816
- var REPO2 = /^[A-Za-z0-9._-]{1,100}$/
10817
- var HTTPS_FORM = /^https:\/\/(?:[^/@\s]*@)?github\.com\/(\S+)$/i
10818
- var SSH_URL_FORM = /^ssh:\/\/(?:[A-Za-z0-9._-]+@)?github\.com\/(\S+)$/i
10819
- var SCP_FORM = /^(?:[A-Za-z0-9._-]+@)?github\.com:(\S+)$/i
10820
- function ownerAndRepo(pathPart) {
10821
- const segments = pathPart.replace(/\/+$/, '').split('/')
10822
- if (segments.length !== 2) return
10823
- const [owner = '', named = ''] = segments
10824
- const repo = named.endsWith('.git') ? named.slice(0, -'.git'.length) : named
10825
- if (!OWNER.test(owner) || !REPO2.test(repo)) return
10826
- if (repo === '.' || repo === '..') return
10827
- return `${owner}/${repo}`.toLowerCase()
10828
- }
10829
- function normalizeGithubRemote(url) {
10830
- const match =
10831
- HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
10832
- const rest = match?.[1]
10833
- return rest === undefined ? undefined : ownerAndRepo(rest)
10834
- }
10835
- function configValue(raw) {
10836
- let out = ''
10837
- let quoted = false
10838
- for (const ch of raw.trim()) {
10839
- if (ch === '"') {
10840
- quoted = !quoted
10841
- continue
10842
- }
10843
- if (!quoted && (ch === '#' || ch === ';')) break
10844
- out += ch
11545
+ // src/lib/connect-provenance.ts
11546
+ var OWNER_REPO = 'marcusrbrown/systematic'
11547
+ var WORKFLOW_FILE = '/.github/workflows/connect.yaml'
11548
+ var FULL_SHA = /^[0-9a-f]{40}$/
11549
+ var UNPROVABLE = {
11550
+ status: 'refused',
11551
+ reason: 'provenance-unprovable',
11552
+ }
11553
+ var NOT_A_CONNECT_RUN = {
11554
+ status: 'refused',
11555
+ reason: 'not-a-connect-run',
11556
+ }
11557
+ function parseList(text) {
11558
+ if (typeof text !== 'string') return
11559
+ try {
11560
+ const value = JSON.parse(text)
11561
+ return Array.isArray(value) && value.length > 0 ? value : undefined
11562
+ } catch {
11563
+ return
10845
11564
  }
10846
- return out.trim()
10847
11565
  }
10848
- function isOriginSection(header) {
10849
- const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
10850
- return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
10851
- }
10852
- function originUrl(config) {
10853
- let inOrigin = false
10854
- for (const raw of config.split(`
10855
- `)) {
10856
- let line = raw.trim()
10857
- if (line.startsWith('[')) {
10858
- const end = line.indexOf(']')
10859
- if (end === -1) {
10860
- inOrigin = false
10861
- continue
10862
- }
10863
- inOrigin = isOriginSection(line.slice(1, end))
10864
- line = line.slice(end + 1).trim()
11566
+ function pathsOf(list) {
11567
+ const paths = []
11568
+ for (const entry of list) {
11569
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
11570
+ return
10865
11571
  }
10866
- if (!inOrigin) continue
10867
- const key = /^url[ \t]*=(.*)$/i.exec(line)
10868
- if (key?.[1] !== undefined) return configValue(key[1])
11572
+ const { path } = entry
11573
+ if (typeof path !== 'string') return
11574
+ paths.push(path)
10869
11575
  }
10870
- return
11576
+ return paths
10871
11577
  }
10872
- var OBJECT_ID4 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
10873
- var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
10874
- function readGitText(mainRoot, rel, maxBytes) {
10875
- const read = readContainedFile(mainRoot, rel, { maxBytes })
10876
- return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
11578
+ function workflowOf(path) {
11579
+ const at = path.indexOf('@')
11580
+ return at === -1 ? path : path.slice(0, at)
10877
11581
  }
10878
- function firstLine2(text) {
11582
+ function isSystematicConnect(path) {
11583
+ const workflow = workflowOf(path)
10879
11584
  return (
10880
- text.split(
10881
- `
10882
- `,
10883
- 1,
10884
- )[0] ?? ''
11585
+ workflow.endsWith(WORKFLOW_FILE) &&
11586
+ workflow.slice(0, -WORKFLOW_FILE.length).toLowerCase() === OWNER_REPO
10885
11587
  )
10886
- .replace(/\r$/, '')
10887
- .trim()
10888
11588
  }
10889
- function safeRefName(ref) {
10890
- return (
10891
- REF_NAME.test(ref) &&
10892
- ref
10893
- .split('/')
10894
- .every(
10895
- (part) =>
10896
- part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
10897
- )
10898
- )
10899
- }
10900
- function packedRef(packed, ref) {
10901
- for (const raw of packed.split(`
10902
- `)) {
10903
- const line = raw.trim()
10904
- if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
10905
- const [id, name, ...rest] = line.split(/\s+/)
10906
- if (rest.length === 0 && name === ref && OBJECT_ID4.test(id ?? ''))
10907
- return id
10908
- }
10909
- return
10910
- }
10911
- function headCommit(mainRoot) {
10912
- const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
10913
- if (head === undefined) return
10914
- const line = firstLine2(head)
10915
- if (OBJECT_ID4.test(line)) return line
10916
- const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
10917
- if (symbolic === undefined || !safeRefName(symbolic)) return
10918
- const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
10919
- const looseId = loose === undefined ? '' : firstLine2(loose)
10920
- if (OBJECT_ID4.test(looseId)) return looseId
10921
- const packed = readGitText(
10922
- mainRoot,
10923
- '.git/packed-refs',
10924
- MAX_PACKED_REFS_BYTES,
10925
- )
10926
- return packed === undefined ? undefined : packedRef(packed, symbolic)
10927
- }
10928
- function readRepoIdentity(mainRoot) {
10929
- try {
10930
- const config = readGitText(mainRoot, '.git/config', MAX_CONFIG_BYTES)
10931
- const url = config === undefined ? undefined : originUrl(config)
10932
- const repo = url === undefined ? undefined : normalizeGithubRemote(url)
10933
- const commit = headCommit(mainRoot)
10934
- return {
10935
- ...(repo === undefined ? {} : { repo }),
10936
- ...(commit === undefined ? {} : { commit }),
10937
- }
10938
- } catch {
10939
- return {}
10940
- }
11589
+ function verifyProvenance(input) {
11590
+ const list = parseList(input.referencedWorkflows)
11591
+ if (list === undefined) return UNPROVABLE
11592
+ const paths = pathsOf(list)
11593
+ if (paths === undefined) return UNPROVABLE
11594
+ const matches = list.filter((_entry, index) => {
11595
+ const path = paths[index]
11596
+ return path !== undefined && isSystematicConnect(path)
11597
+ })
11598
+ if (matches.length === 0) return NOT_A_CONNECT_RUN
11599
+ if (matches.length > 1) return UNPROVABLE
11600
+ const { sha } = matches[0]
11601
+ if (typeof sha !== 'string' || !FULL_SHA.test(sha)) return UNPROVABLE
11602
+ if (input.status === undefined) return { status: 'selected', sha }
11603
+ return input.status === 'behind' || input.status === 'identical'
11604
+ ? { status: 'accepted', sha }
11605
+ : UNPROVABLE
10941
11606
  }
10942
11607
 
10943
11608
  // src/lib/main-module.ts
10944
- import fs9 from 'node:fs'
11609
+ import fs10 from 'node:fs'
10945
11610
  import { fileURLToPath } from 'node:url'
10946
11611
  function resolveRealPath(value) {
10947
11612
  if (value === undefined || value === '') return
10948
11613
  try {
10949
- return fs9.realpathSync(value)
11614
+ return fs10.realpathSync(value)
10950
11615
  } catch {
10951
11616
  return
10952
11617
  }
@@ -10970,7 +11635,7 @@ function isMainModule(moduleUrl, argv = process.argv) {
10970
11635
 
10971
11636
  // src/ce-connect-helper.ts
10972
11637
  var CE_CONNECT_USAGE =
10973
- 'Usage: node connect.mjs <begin|validate|publish|decide|import|apply-ticks|render-report|ledger show [--offset N]|ledger clear|ledger unlock>'
11638
+ '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>'
10974
11639
  var OPS = [
10975
11640
  'begin',
10976
11641
  'validate',
@@ -10979,6 +11644,8 @@ var OPS = [
10979
11644
  'import',
10980
11645
  'apply-ticks',
10981
11646
  'render-report',
11647
+ 'allowed-origins',
11648
+ 'verify-provenance',
10982
11649
  'ledger-show',
10983
11650
  'ledger-clear',
10984
11651
  'ledger-unlock',
@@ -11032,7 +11699,7 @@ function psField(pid, field) {
11032
11699
  }
11033
11700
  function procStat(pid) {
11034
11701
  try {
11035
- const stat = fs10.readFileSync(`/proc/${pid}/stat`, 'utf8')
11702
+ const stat = fs11.readFileSync(`/proc/${pid}/stat`, 'utf8')
11036
11703
  const close = stat.lastIndexOf(')')
11037
11704
  return close < 0
11038
11705
  ? undefined
@@ -11055,7 +11722,7 @@ var systemProcessInspector = {
11055
11722
  if (process.platform === 'linux') {
11056
11723
  try {
11057
11724
  return (
11058
- fs10.readFileSync(`/proc/${pid}/comm`, 'utf8').trim() || undefined
11725
+ fs11.readFileSync(`/proc/${pid}/comm`, 'utf8').trim() || undefined
11059
11726
  )
11060
11727
  } catch {
11061
11728
  return
@@ -11065,7 +11732,7 @@ var systemProcessInspector = {
11065
11732
  },
11066
11733
  }
11067
11734
  function isShell(command) {
11068
- return SHELLS.has(path8.basename(command).replace(/^-/, ''))
11735
+ return SHELLS.has(path9.basename(command).replace(/^-/, ''))
11069
11736
  }
11070
11737
  function findHolderPid(inspector, from = process.pid) {
11071
11738
  let pid = inspector.parentOf(from)
@@ -11098,6 +11765,7 @@ function describeEnvironment(deps) {
11098
11765
  allowedRoots: resolved.resolved.map((item) => item.mainRoot),
11099
11766
  resolved,
11100
11767
  groups: load.groups,
11768
+ pins: load.pins,
11101
11769
  warnings: load.warnings,
11102
11770
  configUnreadable: load.unreadable,
11103
11771
  }
@@ -11148,6 +11816,7 @@ function rulesOverview(rules, offer) {
11148
11816
  oneCell(rule.title ?? ''),
11149
11817
  oneCell(rule.appliesWhen.map(oneCell).join(' | ')),
11150
11818
  offered.has(id) ? 'offered' : 'later',
11819
+ projectKey(rule.project),
11151
11820
  ].join('\t'),
11152
11821
  )
11153
11822
  }
@@ -11205,7 +11874,8 @@ function isSnapshot(value) {
11205
11874
  Array.isArray(value.offer.fresh) &&
11206
11875
  Array.isArray(value.provenance) &&
11207
11876
  Array.isArray(value.degradeReasons) &&
11208
- Array.isArray(value.unread)
11877
+ Array.isArray(value.unread) &&
11878
+ (value.pinNotes === undefined || Array.isArray(value.pinNotes))
11209
11879
  )
11210
11880
  }
11211
11881
  function isValidated(value) {
@@ -11612,15 +12282,15 @@ function prunedCounts(pruned) {
11612
12282
  }
11613
12283
  : { runs: 0, staging: 0, failed: 0 }
11614
12284
  }
11615
- function beginResponse(setup, snapshot, scans, workDir, limits) {
12285
+ function beginResponse(setup, snapshot, scans, workDir, limits, pins) {
11616
12286
  return success('begin', {
11617
12287
  status: 'begun',
11618
12288
  runId: snapshot.runId,
11619
12289
  stateRoot: setup.root,
11620
12290
  workDir,
11621
- rulesFile: path8.join(workDir, 'rules.json'),
11622
- filesIndex: path8.join(workDir, 'files.tsv'),
11623
- rulesOverview: path8.join(workDir, 'rules.tsv'),
12291
+ rulesFile: path9.join(workDir, 'rules.json'),
12292
+ filesIndex: path9.join(workDir, 'files.tsv'),
12293
+ rulesOverview: path9.join(workDir, 'rules.tsv'),
11624
12294
  offeredRuleIds: snapshot.offer.offered,
11625
12295
  offeredCount: snapshot.offer.offered.length,
11626
12296
  sweep: {
@@ -11651,6 +12321,8 @@ function beginResponse(setup, snapshot, scans, workDir, limits) {
11651
12321
  undecidedProvenance: snapshot.undecidedProvenance,
11652
12322
  degradeReasons: snapshot.degradeReasons,
11653
12323
  unread: snapshot.unread,
12324
+ pinHints: pins.hints,
12325
+ pinNotes: pins.notes,
11654
12326
  configWarnings: setup.environment.warnings,
11655
12327
  pruned: snapshot.pruned,
11656
12328
  bounds: {
@@ -11689,6 +12361,23 @@ function indexRun(setup, deps) {
11689
12361
  try {
11690
12362
  const rules = scans.flatMap((scan) => scan.rules)
11691
12363
  const provenance = scans.flatMap((scan) => scan.provenance)
12364
+ const aliasesByRoot = new Map(
12365
+ setup.projects.map((item) => [item.mainRoot, item.aliases ?? []]),
12366
+ )
12367
+ const pins = resolvePins(
12368
+ setup.environment.pins,
12369
+ scans.map((scan) => ({
12370
+ entry: scan.digest.entry,
12371
+ aliases: aliasesByRoot.get(scan.digest.root) ?? [],
12372
+ root: scan.digest.root,
12373
+ key: scan.digest.key,
12374
+ ...(scan.digest.repo === undefined ? {} : { repo: scan.digest.repo }),
12375
+ ...(scan.digest.commit === undefined
12376
+ ? {}
12377
+ : { commit: scan.digest.commit }),
12378
+ })),
12379
+ deps.pinReaders,
12380
+ )
11692
12381
  const offer = planOffer({
11693
12382
  rules,
11694
12383
  coverage: ledger.ledger.coverage ?? [],
@@ -11716,6 +12405,7 @@ function indexRun(setup, deps) {
11716
12405
  unmatched: setup.unmatched,
11717
12406
  degradeReasons,
11718
12407
  unread,
12408
+ pinNotes: pins.notes,
11719
12409
  selection: setup.selection,
11720
12410
  ruleIds: rules.map((rule) => rule.id),
11721
12411
  ruleVersions: rules.map((rule) => ({
@@ -11766,7 +12456,7 @@ function indexRun(setup, deps) {
11766
12456
  )
11767
12457
  }
11768
12458
  }
11769
- return beginResponse(setup, snapshot, scans, workDir, limits)
12459
+ return beginResponse(setup, snapshot, scans, workDir, limits, pins)
11770
12460
  } catch {
11771
12461
  return releaseAndFail('begin', lock, root, runId, 'internal-error')
11772
12462
  }
@@ -11887,15 +12577,15 @@ function readBatches(workDir, runId, requested) {
11887
12577
  const batches = []
11888
12578
  for (const given of requested) {
11889
12579
  let name
11890
- if (path8.isAbsolute(given)) {
11891
- if (path8.dirname(path8.resolve(given)) !== workDir) {
12580
+ if (path9.isAbsolute(given)) {
12581
+ if (path9.dirname(path9.resolve(given)) !== workDir) {
11892
12582
  return { ok: false, reason: 'batch-outside-work-dir' }
11893
12583
  }
11894
- name = path8.basename(given)
12584
+ name = path9.basename(given)
11895
12585
  } else {
11896
12586
  name = given
11897
12587
  }
11898
- if (!isWorkName(name) || name !== path8.basename(name)) {
12588
+ if (!isWorkName(name) || name !== path9.basename(name)) {
11899
12589
  return { ok: false, reason: 'batch-outside-work-dir' }
11900
12590
  }
11901
12591
  if (RESERVED_WORK_FILES.has(name)) {
@@ -12432,6 +13122,7 @@ function digestModel(snapshot, state, outcome, degradeReasons) {
12432
13122
  suppressed: state.suppressed,
12433
13123
  staleCitations: snapshot.staleCitations,
12434
13124
  undecidedProvenance: snapshot.undecidedProvenance,
13125
+ pinNotes: readPinNotes(snapshot.pinNotes),
12435
13126
  }
12436
13127
  }
12437
13128
  function runRecord(snapshot, state, outcome, degradeReasons) {
@@ -12590,7 +13281,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
12590
13281
  const released = releaseLock(handle)
12591
13282
  removeWorkDir(root, snapshot.runId)
12592
13283
  const finalOutcome = ledgerWritten ? outcome : 'degraded'
12593
- const digestPath = path8.join(published.runDir, 'digest.md')
13284
+ const digestPath = path9.join(published.runDir, 'digest.md')
12594
13285
  const recorded =
12595
13286
  ciMarker === undefined
12596
13287
  ? 'written'
@@ -12610,7 +13301,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
12610
13301
  runId: snapshot.runId,
12611
13302
  runDir: published.runDir,
12612
13303
  digestPath,
12613
- runRecordPath: path8.join(published.runDir, 'run.json'),
13304
+ runRecordPath: path9.join(published.runDir, 'run.json'),
12614
13305
  ledger: published.ledger,
12615
13306
  ...(recordsCurrent ? {} : { runRecordCurrent: false }),
12616
13307
  ...(recorded === 'written' ? {} : { invocationRecord: 'unwritten' }),
@@ -12621,7 +13312,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
12621
13312
  summary: renderSummary(
12622
13313
  final.model,
12623
13314
  digestPath,
12624
- path8.join(published.runDir, 'run.json'),
13315
+ path9.join(published.runDir, 'run.json'),
12625
13316
  ),
12626
13317
  })
12627
13318
  }
@@ -12910,7 +13601,6 @@ function ledgerUnlock(deps) {
12910
13601
  : {}),
12911
13602
  })
12912
13603
  }
12913
- var GITHUB_REPO = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/
12914
13604
  var GITHUB_RUN_ID = /^[0-9]{1,20}$/
12915
13605
  var COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
12916
13606
  var MAX_DIRECTORY_LENGTH = 4096
@@ -12922,13 +13612,13 @@ function parseImportRequest(request) {
12922
13612
  directory === '' ||
12923
13613
  directory.length > MAX_DIRECTORY_LENGTH ||
12924
13614
  CONTROL_IN_PATH.test(directory) ||
12925
- !path8.isAbsolute(directory)
13615
+ !path9.isAbsolute(directory)
12926
13616
  ) {
12927
13617
  return
12928
13618
  }
12929
13619
  if (!isRecord6(provenance)) return
12930
13620
  const { repo, runId, commit } = provenance
12931
- if (typeof repo !== 'string' || !GITHUB_REPO.test(repo)) return
13621
+ if (typeof repo !== 'string' || !isGithubOwnerRepo(repo)) return
12932
13622
  if (typeof runId !== 'string' || !GITHUB_RUN_ID.test(runId)) return
12933
13623
  if (
12934
13624
  commit !== undefined &&
@@ -13093,7 +13783,7 @@ function placeCandidates(accepted, ledger, root, runs) {
13093
13783
  const holder = kept.find((run) => run.evidence.get(item.id) === current)
13094
13784
  return holder === undefined
13095
13785
  ? undefined
13096
- : path8.join(root, 'runs', holder.runId, 'run.json')
13786
+ : path9.join(root, 'runs', holder.runId, 'run.json')
13097
13787
  }
13098
13788
  const fresh = []
13099
13789
  const open = []
@@ -13174,9 +13864,9 @@ function importModel(
13174
13864
  }
13175
13865
  function importAnswer(model, verified, written) {
13176
13866
  const runRecordPath =
13177
- written === undefined ? undefined : path8.join(written.runDir, 'run.json')
13867
+ written === undefined ? undefined : path9.join(written.runDir, 'run.json')
13178
13868
  const digestPath =
13179
- written === undefined ? undefined : path8.join(written.runDir, 'digest.md')
13869
+ written === undefined ? undefined : path9.join(written.runDir, 'digest.md')
13180
13870
  return success('import', {
13181
13871
  outcome: model.outcome,
13182
13872
  finalLine: `Connect ${model.outcome}`,
@@ -13264,7 +13954,7 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
13264
13954
  verified,
13265
13955
  placement,
13266
13956
  runId,
13267
- path8.join(root, 'runs', runId, 'run.json'),
13957
+ path9.join(root, 'runs', runId, 'run.json'),
13268
13958
  )
13269
13959
  const filesOf = (shown) => ({
13270
13960
  'digest.md': renderImportDigest(shown, placement.fresh, createdAt),
@@ -13302,7 +13992,7 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
13302
13992
  verified,
13303
13993
  placement,
13304
13994
  localRunId,
13305
- written === undefined ? '' : path8.join(written.runDir, 'run.json'),
13995
+ written === undefined ? '' : path9.join(written.runDir, 'run.json'),
13306
13996
  ),
13307
13997
  verified,
13308
13998
  written,
@@ -13341,6 +14031,39 @@ function importRun(request, deps) {
13341
14031
  }
13342
14032
  return importWrite(parsed, sourceRunId, verified, state.root, deps)
13343
14033
  }
14034
+ function allowedOrigins(deps) {
14035
+ const environment = describeEnvironment(deps)
14036
+ const seen = new Set()
14037
+ const shared = new Set()
14038
+ for (const { mainRoot } of environment.resolved.resolved) {
14039
+ const { repo } = readRepoIdentity(mainRoot)
14040
+ if (repo === undefined) continue
14041
+ if (seen.has(repo)) shared.add(repo)
14042
+ seen.add(repo)
14043
+ }
14044
+ return success('allowed-origins', {
14045
+ outcome: 'complete',
14046
+ origins: [...seen].sort(),
14047
+ ambiguous: [...shared].sort(),
14048
+ configUnreadable: environment.configUnreadable,
14049
+ })
14050
+ }
14051
+ function verifyProvenanceOp(request) {
14052
+ if (!isRecord6(request))
14053
+ return failure2('verify-provenance', 'invalid-request')
14054
+ const verdict = verifyProvenance({
14055
+ referencedWorkflows: request.referencedWorkflows,
14056
+ ...(request.status === undefined ? {} : { status: request.status }),
14057
+ })
14058
+ if (verdict.status === 'refused') {
14059
+ return failure2('verify-provenance', verdict.reason)
14060
+ }
14061
+ return success('verify-provenance', {
14062
+ outcome: 'complete',
14063
+ stage: verdict.status,
14064
+ sha: verdict.sha,
14065
+ })
14066
+ }
13344
14067
  var ISSUE_DIGITS = /^[0-9]{1,10}$/
13345
14068
  function parseTicksRequest(request) {
13346
14069
  if (!isRecord6(request)) return
@@ -13350,7 +14073,7 @@ function parseTicksRequest(request) {
13350
14073
  bodyFile === '' ||
13351
14074
  bodyFile.length > MAX_DIRECTORY_LENGTH ||
13352
14075
  CONTROL_IN_PATH.test(bodyFile) ||
13353
- !path8.isAbsolute(bodyFile)
14076
+ !path9.isAbsolute(bodyFile)
13354
14077
  ) {
13355
14078
  return
13356
14079
  }
@@ -13365,16 +14088,23 @@ function parseTicksRequest(request) {
13365
14088
  }
13366
14089
  function parseRenderRequest(request) {
13367
14090
  if (!isRecord6(request)) return
13368
- const { date, runId, attempt, cacheRestored } = request
14091
+ const { date, runId, attempt, cacheRestored, repo } = request
13369
14092
  if (
13370
14093
  typeof date !== 'string' ||
13371
14094
  typeof runId !== 'string' ||
13372
14095
  typeof attempt !== 'string' ||
13373
- typeof cacheRestored !== 'boolean'
14096
+ typeof cacheRestored !== 'boolean' ||
14097
+ (repo !== undefined && typeof repo !== 'string')
13374
14098
  ) {
13375
14099
  return
13376
14100
  }
13377
- return { date, runId, attempt, cacheRestored }
14101
+ return {
14102
+ date,
14103
+ runId,
14104
+ attempt,
14105
+ cacheRestored,
14106
+ ...(repo === undefined ? {} : { repo }),
14107
+ }
13378
14108
  }
13379
14109
  function ciOptions(deps) {
13380
14110
  return {
@@ -13460,6 +14190,10 @@ function runHelperOp(op, request, deps = {}) {
13460
14190
  return applyTicksOp(request, deps)
13461
14191
  case 'render-report':
13462
14192
  return renderReportOp(request, deps)
14193
+ case 'allowed-origins':
14194
+ return allowedOrigins(deps)
14195
+ case 'verify-provenance':
14196
+ return verifyProvenanceOp(request)
13463
14197
  case 'ledger-show':
13464
14198
  return ledgerShow(request, deps)
13465
14199
  case 'ledger-clear':
@@ -13480,7 +14214,7 @@ function errorCodeOf(error) {
13480
14214
  }
13481
14215
  function readStdinChunk(chunk) {
13482
14216
  try {
13483
- return fs10.readSync(0, chunk, 0, chunk.length, null)
14217
+ return fs11.readSync(0, chunk, 0, chunk.length, null)
13484
14218
  } catch (error) {
13485
14219
  const code = errorCodeOf(error)
13486
14220
  if (code === 'EOF') return 0
@@ -13512,6 +14246,7 @@ var REQUEST_OPS = new Set([
13512
14246
  'import',
13513
14247
  'apply-ticks',
13514
14248
  'render-report',
14249
+ 'verify-provenance',
13515
14250
  ])
13516
14251
  function resolveCliOp(argv) {
13517
14252
  const [first, second] = argv
@@ -13532,6 +14267,14 @@ function showRequestFromArgv(argv) {
13532
14267
  ? { offset: Number(value) }
13533
14268
  : { offset: value }
13534
14269
  }
14270
+ function provenanceArgsFromArgv(argv) {
14271
+ const rest = argv.slice(1)
14272
+ if (rest.length === 0) return {}
14273
+ const [flag, value] = rest
14274
+ return rest.length === 2 && flag === '--status' && value !== undefined
14275
+ ? { status: value }
14276
+ : undefined
14277
+ }
13535
14278
  function refusedBegin(result, options) {
13536
14279
  const deps = options.deps ?? {}
13537
14280
  const marker = ciRunMarker(deps)
@@ -13567,6 +14310,7 @@ function readCliRequest(op, options, out, err) {
13567
14310
  if (text === 'too-large' || text === 'unreadable') {
13568
14311
  return refuse(`request-${text}`)
13569
14312
  }
14313
+ if (op === 'verify-provenance') return { ok: true, request: text }
13570
14314
  if (text.trim() === '') return { ok: true, request: {} }
13571
14315
  try {
13572
14316
  return { ok: true, request: JSON.parse(text) }
@@ -13590,10 +14334,20 @@ function runConnectHelper(options) {
13590
14334
  err(CE_CONNECT_USAGE)
13591
14335
  return 2
13592
14336
  }
14337
+ const provenanceArgs =
14338
+ op === 'verify-provenance' ? provenanceArgsFromArgv(options.argv) : {}
14339
+ if (provenanceArgs === undefined) {
14340
+ out(JSON.stringify(failure2(op, 'invalid-request').body))
14341
+ return 2
14342
+ }
13593
14343
  const read = readCliRequest(op, options, out, err)
13594
14344
  if (!read.ok) return read.exitCode
13595
14345
  const request =
13596
- op === 'ledger-show' ? showRequestFromArgv(options.argv) : read.request
14346
+ op === 'ledger-show'
14347
+ ? showRequestFromArgv(options.argv)
14348
+ : op === 'verify-provenance'
14349
+ ? { referencedWorkflows: read.request, ...provenanceArgs }
14350
+ : read.request
13597
14351
  const result = runHelperOp(op, request, options.deps ?? {})
13598
14352
  out(JSON.stringify(result.body))
13599
14353
  return result.ok ? 0 : 1