@fro.bot/systematic 3.37.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.
- package/dist/ce-connect-helper.d.ts +3 -0
- package/dist/cli.js +5 -3
- package/dist/{index-1cj1mrpb.js → index-ahm7y9zh.js} +150 -72
- package/dist/index.js +20 -20
- package/dist/lib/config-handler.d.ts +1 -1
- package/dist/lib/config-schema.d.ts +12 -0
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/connect-config.d.ts +81 -9
- package/dist/lib/connect-helper-core.d.ts +5 -0
- package/dist/lib/connect-pins.d.ts +131 -0
- package/dist/lib/connect-repo-identity.d.ts +30 -11
- package/dist/lib/discovered-skills.d.ts +3 -3
- package/dist/lib/opencode-config-dir.d.ts +26 -0
- package/dist/lib/opencode-v2.d.ts +1 -1
- package/dist/lib/search-user-config.d.ts +5 -3
- package/dist/pi.js +119 -41
- package/package.json +6 -6
- package/skills/ce-compound/assets/resolution-template.md +1 -1
- package/skills/ce-compound-refresh/assets/resolution-template.md +1 -1
- package/skills/ce-connect/SKILL.md +17 -5
- package/skills/ce-connect/references/candidate-contract.md +3 -1
- package/skills/ce-connect/references/headless-and-outcomes.md +20 -0
- package/skills/ce-connect/scripts/connect.mjs +924 -320
- package/skills/compound-docs/SKILL.md +1 -2
- package/skills/compound-docs/assets/resolution-template.md +1 -1
|
@@ -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:
|
|
5
|
+
// source-digest: 9c3d008aac1f38f179f2947ec1294e74478f5950ba822fe08e50d9a295920f55
|
|
6
6
|
// src/ce-connect-helper.ts
|
|
7
7
|
import { spawnSync as spawnSync3 } from 'node:child_process'
|
|
8
|
-
import
|
|
8
|
+
import fs11 from 'node:fs'
|
|
9
9
|
import os2 from 'node:os'
|
|
10
|
-
import
|
|
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
|
|
18
|
-
import
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
1066
|
+
return gitdir.split(path2.sep).includes('modules')
|
|
1055
1067
|
}
|
|
1056
1068
|
function resolveLinkedWorktree(gitFile, gitdir) {
|
|
1057
|
-
const commonFile =
|
|
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 !==
|
|
1078
|
+
if (gitdir !== path2.join(common, 'worktrees', path2.basename(gitdir))) {
|
|
1067
1079
|
return { reason: 'inconsistent' }
|
|
1068
1080
|
}
|
|
1069
|
-
const backRaw = firstLine(readSmallFile(
|
|
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 (
|
|
1088
|
+
if (path2.basename(common) !== '.git') {
|
|
1077
1089
|
return { reason: 'unsupported-layout' }
|
|
1078
1090
|
}
|
|
1079
|
-
if (setsCoreWorktree(readSmallFile(
|
|
1091
|
+
if (setsCoreWorktree(readSmallFile(path2.join(common, 'config')))) {
|
|
1080
1092
|
return { reason: 'core-worktree' }
|
|
1081
1093
|
}
|
|
1082
|
-
return { root:
|
|
1094
|
+
return { root: path2.dirname(common) }
|
|
1083
1095
|
}
|
|
1084
1096
|
function deriveMainRoot(checkoutRoot) {
|
|
1085
1097
|
const root = realpath(checkoutRoot)
|
|
1086
|
-
const gitPath =
|
|
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 (
|
|
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) =>
|
|
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
|
-
|
|
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 =
|
|
1309
|
+
const jsoncPath = path3.join(dir, `${basename}.jsonc`)
|
|
1207
1310
|
return entryExists(jsoncPath)
|
|
1208
1311
|
? jsoncPath
|
|
1209
|
-
:
|
|
1312
|
+
: path3.join(dir, `${basename}.json`)
|
|
1210
1313
|
}
|
|
1211
1314
|
function realpathOrResolved(dir) {
|
|
1212
|
-
const resolved =
|
|
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
|
-
|
|
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 =
|
|
1357
|
+
const relative = path3.relative(parent, child)
|
|
1256
1358
|
return (
|
|
1257
1359
|
relative === '' ||
|
|
1258
1360
|
(relative !== '..' &&
|
|
1259
|
-
!relative.startsWith(`..${
|
|
1260
|
-
!
|
|
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(
|
|
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(
|
|
1277
|
-
const parent =
|
|
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(`~${
|
|
1347
|
-
return
|
|
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 (!
|
|
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
|
|
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 =
|
|
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 (!
|
|
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
|
|
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
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
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 (
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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 !== '' &&
|
|
6638
|
+
xdg !== undefined && xdg !== '' && path5.isAbsolute(xdg)
|
|
5917
6639
|
? xdg
|
|
5918
|
-
:
|
|
5919
|
-
return
|
|
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 =
|
|
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
|
|
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]) =>
|
|
6217
|
-
.map(([, list]) => list.sort((a, b) =>
|
|
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]) =>
|
|
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 (
|
|
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
|
-
|
|
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
|
|
8033
|
+
return path5.join(stateRoot, WORK_DIR, runId)
|
|
7310
8034
|
}
|
|
7311
8035
|
function ensurePrivateDirectory(dir) {
|
|
7312
8036
|
try {
|
|
7313
|
-
const stat =
|
|
8037
|
+
const stat = fs6.lstatSync(dir)
|
|
7314
8038
|
if (stat.isSymbolicLink() || !stat.isDirectory()) return false
|
|
7315
|
-
if ((stat.mode & 511) !== 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
|
-
|
|
7322
|
-
|
|
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 =
|
|
8053
|
+
const work = path5.join(stateRoot, WORK_DIR)
|
|
7330
8054
|
try {
|
|
7331
|
-
const stat =
|
|
8055
|
+
const stat = fs6.lstatSync(work)
|
|
7332
8056
|
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
7333
|
-
|
|
8057
|
+
fs6.rmSync(work, { force: true })
|
|
7334
8058
|
return
|
|
7335
8059
|
}
|
|
7336
|
-
for (const name of
|
|
7337
|
-
|
|
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(
|
|
8067
|
+
if (!ensurePrivateDirectory(path5.join(stateRoot, WORK_DIR))) return
|
|
7344
8068
|
const dir = workDirPath(stateRoot, runId)
|
|
7345
8069
|
try {
|
|
7346
|
-
|
|
7347
|
-
|
|
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
|
-
|
|
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 =
|
|
8085
|
+
const target = path5.join(dir, name)
|
|
7362
8086
|
const temporary = `${target}.tmp-${randomUUID()}`
|
|
7363
|
-
const fd =
|
|
8087
|
+
const fd = fs6.openSync(temporary, 'wx', FILE_MODE)
|
|
7364
8088
|
try {
|
|
7365
8089
|
try {
|
|
7366
|
-
|
|
7367
|
-
|
|
8090
|
+
fs6.writeSync(fd, data)
|
|
8091
|
+
fs6.fsyncSync(fd)
|
|
7368
8092
|
} finally {
|
|
7369
|
-
|
|
8093
|
+
fs6.closeSync(fd)
|
|
7370
8094
|
}
|
|
7371
|
-
|
|
7372
|
-
|
|
8095
|
+
fs6.chmodSync(temporary, FILE_MODE)
|
|
8096
|
+
fs6.renameSync(temporary, target)
|
|
7373
8097
|
} catch (error) {
|
|
7374
|
-
|
|
8098
|
+
fs6.rmSync(temporary, { force: true })
|
|
7375
8099
|
throw error
|
|
7376
8100
|
}
|
|
7377
8101
|
}
|
|
@@ -7556,158 +8280,14 @@ function selectionLine(selection) {
|
|
|
7556
8280
|
}
|
|
7557
8281
|
}
|
|
7558
8282
|
|
|
7559
|
-
// src/lib/connect-repo-identity.ts
|
|
7560
|
-
var MAX_CONFIG_BYTES = 1024 * 1024
|
|
7561
|
-
var MAX_HEAD_BYTES = 4096
|
|
7562
|
-
var MAX_REF_BYTES = 4096
|
|
7563
|
-
var MAX_PACKED_REFS_BYTES = 8 * 1024 * 1024
|
|
7564
|
-
var OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/
|
|
7565
|
-
var REPO = /^[A-Za-z0-9._-]{1,100}$/
|
|
7566
|
-
function isGithubOwnerRepo(value) {
|
|
7567
|
-
const parts = value.split('/')
|
|
7568
|
-
const [owner, name] = parts
|
|
7569
|
-
return (
|
|
7570
|
-
parts.length === 2 &&
|
|
7571
|
-
owner !== undefined &&
|
|
7572
|
-
name !== undefined &&
|
|
7573
|
-
OWNER.test(owner) &&
|
|
7574
|
-
REPO.test(name) &&
|
|
7575
|
-
name !== '.' &&
|
|
7576
|
-
name !== '..'
|
|
7577
|
-
)
|
|
7578
|
-
}
|
|
7579
|
-
var HTTPS_FORM = /^https:\/\/(?:[^/@\s]*@)?github\.com\/(\S+)$/i
|
|
7580
|
-
var SSH_URL_FORM = /^ssh:\/\/(?:[A-Za-z0-9._-]+@)?github\.com\/(\S+)$/i
|
|
7581
|
-
var SCP_FORM = /^(?:[A-Za-z0-9._-]+@)?github\.com:(\S+)$/i
|
|
7582
|
-
function ownerAndRepo(pathPart) {
|
|
7583
|
-
const segments = pathPart.replace(/\/+$/, '').split('/')
|
|
7584
|
-
if (segments.length !== 2) return
|
|
7585
|
-
const [owner = '', named = ''] = segments
|
|
7586
|
-
const repo = named.endsWith('.git') ? named.slice(0, -'.git'.length) : named
|
|
7587
|
-
const slug = `${owner}/${repo}`
|
|
7588
|
-
return isGithubOwnerRepo(slug) ? slug.toLowerCase() : undefined
|
|
7589
|
-
}
|
|
7590
|
-
function normalizeGithubRemote(url) {
|
|
7591
|
-
const match =
|
|
7592
|
-
HTTPS_FORM.exec(url) ?? SSH_URL_FORM.exec(url) ?? SCP_FORM.exec(url)
|
|
7593
|
-
const rest = match?.[1]
|
|
7594
|
-
return rest === undefined ? undefined : ownerAndRepo(rest)
|
|
7595
|
-
}
|
|
7596
|
-
function configValue(raw) {
|
|
7597
|
-
let out = ''
|
|
7598
|
-
let quoted = false
|
|
7599
|
-
for (const ch of raw.trim()) {
|
|
7600
|
-
if (ch === '"') {
|
|
7601
|
-
quoted = !quoted
|
|
7602
|
-
continue
|
|
7603
|
-
}
|
|
7604
|
-
if (!quoted && (ch === '#' || ch === ';')) break
|
|
7605
|
-
out += ch
|
|
7606
|
-
}
|
|
7607
|
-
return out.trim()
|
|
7608
|
-
}
|
|
7609
|
-
function isOriginSection(header) {
|
|
7610
|
-
const match = /^([A-Za-z]+)[ \t]+"([^"]*)"$/.exec(header.trim())
|
|
7611
|
-
return match?.[1]?.toLowerCase() === 'remote' && match[2] === 'origin'
|
|
7612
|
-
}
|
|
7613
|
-
function originUrl(config) {
|
|
7614
|
-
let inOrigin = false
|
|
7615
|
-
for (const raw of config.split(`
|
|
7616
|
-
`)) {
|
|
7617
|
-
let line = raw.trim()
|
|
7618
|
-
if (line.startsWith('[')) {
|
|
7619
|
-
const end = line.indexOf(']')
|
|
7620
|
-
if (end === -1) {
|
|
7621
|
-
inOrigin = false
|
|
7622
|
-
continue
|
|
7623
|
-
}
|
|
7624
|
-
inOrigin = isOriginSection(line.slice(1, end))
|
|
7625
|
-
line = line.slice(end + 1).trim()
|
|
7626
|
-
}
|
|
7627
|
-
if (!inOrigin) continue
|
|
7628
|
-
const key = /^url[ \t]*=(.*)$/i.exec(line)
|
|
7629
|
-
if (key?.[1] !== undefined) return configValue(key[1])
|
|
7630
|
-
}
|
|
7631
|
-
return
|
|
7632
|
-
}
|
|
7633
|
-
var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
7634
|
-
var REF_NAME = /^refs\/[A-Za-z0-9._/-]+$/
|
|
7635
|
-
function readGitText(mainRoot, rel, maxBytes) {
|
|
7636
|
-
const read = readContainedFile(mainRoot, rel, { maxBytes })
|
|
7637
|
-
return read.kind === 'bytes' ? read.bytes.toString('utf8') : undefined
|
|
7638
|
-
}
|
|
7639
|
-
function firstLine2(text) {
|
|
7640
|
-
return (
|
|
7641
|
-
text.split(
|
|
7642
|
-
`
|
|
7643
|
-
`,
|
|
7644
|
-
1,
|
|
7645
|
-
)[0] ?? ''
|
|
7646
|
-
)
|
|
7647
|
-
.replace(/\r$/, '')
|
|
7648
|
-
.trim()
|
|
7649
|
-
}
|
|
7650
|
-
function safeRefName(ref) {
|
|
7651
|
-
return (
|
|
7652
|
-
REF_NAME.test(ref) &&
|
|
7653
|
-
ref
|
|
7654
|
-
.split('/')
|
|
7655
|
-
.every(
|
|
7656
|
-
(part) =>
|
|
7657
|
-
part !== '' && !part.startsWith('.') && !part.endsWith('.lock'),
|
|
7658
|
-
)
|
|
7659
|
-
)
|
|
7660
|
-
}
|
|
7661
|
-
function packedRef(packed, ref) {
|
|
7662
|
-
for (const raw of packed.split(`
|
|
7663
|
-
`)) {
|
|
7664
|
-
const line = raw.trim()
|
|
7665
|
-
if (line === '' || line.startsWith('#') || line.startsWith('^')) continue
|
|
7666
|
-
const [id, name, ...rest] = line.split(/\s+/)
|
|
7667
|
-
if (rest.length === 0 && name === ref && OBJECT_ID.test(id ?? '')) return id
|
|
7668
|
-
}
|
|
7669
|
-
return
|
|
7670
|
-
}
|
|
7671
|
-
function headCommit(mainRoot) {
|
|
7672
|
-
const head = readGitText(mainRoot, '.git/HEAD', MAX_HEAD_BYTES)
|
|
7673
|
-
if (head === undefined) return
|
|
7674
|
-
const line = firstLine2(head)
|
|
7675
|
-
if (OBJECT_ID.test(line)) return line
|
|
7676
|
-
const symbolic = /^ref:[ \t]*(\S+)$/.exec(line)?.[1]
|
|
7677
|
-
if (symbolic === undefined || !safeRefName(symbolic)) return
|
|
7678
|
-
const loose = readGitText(mainRoot, `.git/${symbolic}`, MAX_REF_BYTES)
|
|
7679
|
-
const looseId = loose === undefined ? '' : firstLine2(loose)
|
|
7680
|
-
if (OBJECT_ID.test(looseId)) return looseId
|
|
7681
|
-
const packed = readGitText(
|
|
7682
|
-
mainRoot,
|
|
7683
|
-
'.git/packed-refs',
|
|
7684
|
-
MAX_PACKED_REFS_BYTES,
|
|
7685
|
-
)
|
|
7686
|
-
return packed === undefined ? undefined : packedRef(packed, symbolic)
|
|
7687
|
-
}
|
|
7688
|
-
function readRepoIdentity(mainRoot) {
|
|
7689
|
-
try {
|
|
7690
|
-
const config = readGitText(mainRoot, '.git/config', MAX_CONFIG_BYTES)
|
|
7691
|
-
const url = config === undefined ? undefined : originUrl(config)
|
|
7692
|
-
const repo = url === undefined ? undefined : normalizeGithubRemote(url)
|
|
7693
|
-
const commit = headCommit(mainRoot)
|
|
7694
|
-
return {
|
|
7695
|
-
...(repo === undefined ? {} : { repo }),
|
|
7696
|
-
...(commit === undefined ? {} : { commit }),
|
|
7697
|
-
}
|
|
7698
|
-
} catch {
|
|
7699
|
-
return {}
|
|
7700
|
-
}
|
|
7701
|
-
}
|
|
7702
|
-
|
|
7703
8283
|
// src/lib/connect-state.ts
|
|
7704
8284
|
import { spawnSync as spawnSync2 } from 'node:child_process'
|
|
7705
8285
|
import {
|
|
7706
8286
|
createHash as createHash3,
|
|
7707
8287
|
randomUUID as randomUUID2,
|
|
7708
8288
|
} from 'node:crypto'
|
|
7709
|
-
import
|
|
7710
|
-
import
|
|
8289
|
+
import fs7 from 'node:fs'
|
|
8290
|
+
import path6 from 'node:path'
|
|
7711
8291
|
var DIR_MODE2 = 448
|
|
7712
8292
|
var FILE_MODE2 = 384
|
|
7713
8293
|
var HOLDERLESS_LOCK_MAX_AGE_MS = 10 * 60 * 1000
|
|
@@ -7742,7 +8322,7 @@ function isRecord3(value) {
|
|
|
7742
8322
|
}
|
|
7743
8323
|
function lstatMaybe(target) {
|
|
7744
8324
|
try {
|
|
7745
|
-
return
|
|
8325
|
+
return fs7.lstatSync(target)
|
|
7746
8326
|
} catch (error) {
|
|
7747
8327
|
const code = errorCode5(error)
|
|
7748
8328
|
if (code === 'ENOENT' || code === 'ENOTDIR') return
|
|
@@ -7751,24 +8331,24 @@ function lstatMaybe(target) {
|
|
|
7751
8331
|
}
|
|
7752
8332
|
function removeQuietly(target) {
|
|
7753
8333
|
try {
|
|
7754
|
-
|
|
8334
|
+
fs7.rmSync(target, { recursive: true, force: true })
|
|
7755
8335
|
} catch {}
|
|
7756
8336
|
}
|
|
7757
8337
|
function writeFileExclusive(file, data) {
|
|
7758
|
-
const fd =
|
|
8338
|
+
const fd = fs7.openSync(file, 'wx', FILE_MODE2)
|
|
7759
8339
|
try {
|
|
7760
|
-
|
|
7761
|
-
|
|
8340
|
+
fs7.writeSync(fd, data)
|
|
8341
|
+
fs7.fsyncSync(fd)
|
|
7762
8342
|
} finally {
|
|
7763
|
-
|
|
8343
|
+
fs7.closeSync(fd)
|
|
7764
8344
|
}
|
|
7765
|
-
|
|
8345
|
+
fs7.chmodSync(file, FILE_MODE2)
|
|
7766
8346
|
}
|
|
7767
8347
|
function writeFileAtomic(target, data) {
|
|
7768
8348
|
const temporary = `${target}.tmp-${randomUUID2()}`
|
|
7769
8349
|
try {
|
|
7770
8350
|
writeFileExclusive(temporary, data)
|
|
7771
|
-
|
|
8351
|
+
fs7.renameSync(temporary, target)
|
|
7772
8352
|
} catch (error) {
|
|
7773
8353
|
removeQuietly(temporary)
|
|
7774
8354
|
throw error
|
|
@@ -7789,8 +8369,8 @@ function codepointOrder2(a, b) {
|
|
|
7789
8369
|
function ensureOwnDirectory(dir) {
|
|
7790
8370
|
const existing = lstatMaybe(dir)
|
|
7791
8371
|
if (existing === undefined) {
|
|
7792
|
-
|
|
7793
|
-
|
|
8372
|
+
fs7.mkdirSync(dir, { recursive: true, mode: DIR_MODE2 })
|
|
8373
|
+
fs7.chmodSync(dir, DIR_MODE2)
|
|
7794
8374
|
return { ok: true, tightened: false }
|
|
7795
8375
|
}
|
|
7796
8376
|
if (existing.isSymbolicLink()) return { ok: false, reason: 'symlink' }
|
|
@@ -7800,19 +8380,19 @@ function ensureOwnDirectory(dir) {
|
|
|
7800
8380
|
return { ok: false, reason: 'foreign-owner' }
|
|
7801
8381
|
}
|
|
7802
8382
|
if ((existing.mode & 511) !== DIR_MODE2) {
|
|
7803
|
-
|
|
8383
|
+
fs7.chmodSync(dir, DIR_MODE2)
|
|
7804
8384
|
return { ok: true, tightened: true }
|
|
7805
8385
|
}
|
|
7806
8386
|
return { ok: true, tightened: false }
|
|
7807
8387
|
}
|
|
7808
8388
|
function prepareStateRoot(root, options) {
|
|
7809
|
-
const resolved =
|
|
8389
|
+
const resolved = path6.resolve(root)
|
|
7810
8390
|
const container = containerRefusal(resolved, options.allowedRoots)
|
|
7811
8391
|
if (container !== undefined) return { status: 'refused', reason: container }
|
|
7812
8392
|
try {
|
|
7813
8393
|
const rootCheck = ensureOwnDirectory(resolved)
|
|
7814
8394
|
if (!rootCheck.ok) return { status: 'refused', reason: rootCheck.reason }
|
|
7815
|
-
const runsCheck = ensureOwnDirectory(
|
|
8395
|
+
const runsCheck = ensureOwnDirectory(path6.join(resolved, RUNS_DIR))
|
|
7816
8396
|
if (!runsCheck.ok) return { status: 'refused', reason: runsCheck.reason }
|
|
7817
8397
|
return {
|
|
7818
8398
|
status: 'ok',
|
|
@@ -7837,7 +8417,7 @@ function processStartTime(pid) {
|
|
|
7837
8417
|
if (!Number.isSafeInteger(pid) || pid <= 0) return
|
|
7838
8418
|
try {
|
|
7839
8419
|
if (process.platform === 'linux') {
|
|
7840
|
-
return parseLinuxStartTime(
|
|
8420
|
+
return parseLinuxStartTime(fs7.readFileSync(`/proc/${pid}/stat`, 'utf8'))
|
|
7841
8421
|
}
|
|
7842
8422
|
if (process.platform === 'darwin') {
|
|
7843
8423
|
const probe = spawnSync2(
|
|
@@ -7904,9 +8484,9 @@ function holdsLock(handle) {
|
|
|
7904
8484
|
return read.kind === 'holder' && read.holder.nonce === handle.nonce
|
|
7905
8485
|
}
|
|
7906
8486
|
function createLock(root, pid, processes) {
|
|
7907
|
-
const lockDir =
|
|
8487
|
+
const lockDir = path6.join(root, LOCK_DIR)
|
|
7908
8488
|
try {
|
|
7909
|
-
|
|
8489
|
+
fs7.mkdirSync(lockDir, { mode: DIR_MODE2 })
|
|
7910
8490
|
} catch (error) {
|
|
7911
8491
|
return errorCode5(error) === 'EEXIST'
|
|
7912
8492
|
? { kind: 'exists' }
|
|
@@ -7920,15 +8500,15 @@ function createLock(root, pid, processes) {
|
|
|
7920
8500
|
nonce,
|
|
7921
8501
|
}
|
|
7922
8502
|
try {
|
|
7923
|
-
|
|
7924
|
-
const temporary =
|
|
8503
|
+
fs7.chmodSync(lockDir, DIR_MODE2)
|
|
8504
|
+
const temporary = path6.join(lockDir, `${HOLDER_FILE}.tmp-${randomUUID2()}`)
|
|
7925
8505
|
try {
|
|
7926
8506
|
writeFileExclusive(
|
|
7927
8507
|
temporary,
|
|
7928
8508
|
`${JSON.stringify(holder)}
|
|
7929
8509
|
`,
|
|
7930
8510
|
)
|
|
7931
|
-
|
|
8511
|
+
fs7.renameSync(temporary, path6.join(lockDir, HOLDER_FILE))
|
|
7932
8512
|
} catch (error) {
|
|
7933
8513
|
removeQuietly(temporary)
|
|
7934
8514
|
throw error
|
|
@@ -7943,7 +8523,7 @@ function createLock(root, pid, processes) {
|
|
|
7943
8523
|
function judgeLock(root, lockDir, processes, now) {
|
|
7944
8524
|
const read = readHolderAt(root, LOCK_DIR)
|
|
7945
8525
|
if (read.kind === 'none') {
|
|
7946
|
-
const age = now -
|
|
8526
|
+
const age = now - fs7.lstatSync(lockDir).mtimeMs
|
|
7947
8527
|
return age >= HOLDERLESS_LOCK_MAX_AGE_MS
|
|
7948
8528
|
? {
|
|
7949
8529
|
action: 'reclaim',
|
|
@@ -7977,7 +8557,7 @@ function judgeLock(root, lockDir, processes, now) {
|
|
|
7977
8557
|
function movedIsJudged(root, stale, expectedNonce, now) {
|
|
7978
8558
|
const stat = lstatMaybe(stale)
|
|
7979
8559
|
if (stat === undefined || !stat.isDirectory()) return false
|
|
7980
|
-
const read = readHolderAt(root,
|
|
8560
|
+
const read = readHolderAt(root, path6.basename(stale))
|
|
7981
8561
|
if (expectedNonce !== null) {
|
|
7982
8562
|
return read.kind === 'holder' && read.holder.nonce === expectedNonce
|
|
7983
8563
|
}
|
|
@@ -7987,13 +8567,13 @@ function movedIsJudged(root, stale, expectedNonce, now) {
|
|
|
7987
8567
|
}
|
|
7988
8568
|
function restoreLock(stale, lockDir) {
|
|
7989
8569
|
try {
|
|
7990
|
-
if (lstatMaybe(lockDir) === undefined)
|
|
8570
|
+
if (lstatMaybe(lockDir) === undefined) fs7.renameSync(stale, lockDir)
|
|
7991
8571
|
} catch {}
|
|
7992
8572
|
}
|
|
7993
8573
|
function reclaimLock(root, lockDir, verdict, pid, processes, now) {
|
|
7994
|
-
const stale =
|
|
8574
|
+
const stale = path6.join(root, `${LOCK_DIR}.stale-${randomUUID2()}`)
|
|
7995
8575
|
try {
|
|
7996
|
-
|
|
8576
|
+
fs7.renameSync(lockDir, stale)
|
|
7997
8577
|
} catch (error) {
|
|
7998
8578
|
return errorCode5(error) === 'ENOENT'
|
|
7999
8579
|
? { status: 'busy', reason: 'reclaim-contended' }
|
|
@@ -8020,7 +8600,7 @@ function acquireLock(root, options = {}) {
|
|
|
8020
8600
|
const pid = options.pid ?? process.pid
|
|
8021
8601
|
const processes = options.processes ?? systemProcessTable
|
|
8022
8602
|
const now = options.now ?? Date.now
|
|
8023
|
-
const lockDir =
|
|
8603
|
+
const lockDir = path6.join(root, LOCK_DIR)
|
|
8024
8604
|
try {
|
|
8025
8605
|
const created = createLock(root, pid, processes)
|
|
8026
8606
|
if (created.kind === 'created') {
|
|
@@ -8052,7 +8632,7 @@ function acquireLock(root, options = {}) {
|
|
|
8052
8632
|
function releaseLock(handle) {
|
|
8053
8633
|
if (!holdsLock(handle)) return 'lost'
|
|
8054
8634
|
try {
|
|
8055
|
-
|
|
8635
|
+
fs7.rmSync(path6.join(handle.root, LOCK_DIR), {
|
|
8056
8636
|
recursive: true,
|
|
8057
8637
|
force: true,
|
|
8058
8638
|
})
|
|
@@ -8062,13 +8642,13 @@ function releaseLock(handle) {
|
|
|
8062
8642
|
}
|
|
8063
8643
|
}
|
|
8064
8644
|
function forceUnlock(root) {
|
|
8065
|
-
const lockDir =
|
|
8645
|
+
const lockDir = path6.join(root, LOCK_DIR)
|
|
8066
8646
|
try {
|
|
8067
8647
|
if (lstatMaybe(lockDir) === undefined) return { status: 'no-lock' }
|
|
8068
8648
|
const read = readHolderAt(root, LOCK_DIR)
|
|
8069
|
-
const aside =
|
|
8070
|
-
|
|
8071
|
-
|
|
8649
|
+
const aside = path6.join(root, `${LOCK_DIR}.unlocked-${randomUUID2()}`)
|
|
8650
|
+
fs7.renameSync(lockDir, aside)
|
|
8651
|
+
fs7.rmSync(aside, { recursive: true, force: true })
|
|
8072
8652
|
return read.kind === 'holder'
|
|
8073
8653
|
? {
|
|
8074
8654
|
status: 'unlocked',
|
|
@@ -8090,7 +8670,7 @@ function isRunId(value) {
|
|
|
8090
8670
|
return SAFE_NAME.test(value) && !value.endsWith(STAGING_SUFFIX)
|
|
8091
8671
|
}
|
|
8092
8672
|
function normalizePath(value) {
|
|
8093
|
-
return
|
|
8673
|
+
return path6.posix.normalize(value)
|
|
8094
8674
|
}
|
|
8095
8675
|
function validPath(value) {
|
|
8096
8676
|
if (!plainText(value, MAX_PATH_LENGTH)) return false
|
|
@@ -8395,7 +8975,7 @@ function writeLedger(root, ledger) {
|
|
|
8395
8975
|
if (Buffer.byteLength(text) > MAX_LEDGER_BYTES) {
|
|
8396
8976
|
throw new Error('the ledger would be larger than the size limit')
|
|
8397
8977
|
}
|
|
8398
|
-
writeFileAtomic(
|
|
8978
|
+
writeFileAtomic(path6.join(root, LEDGER_FILE), text)
|
|
8399
8979
|
}
|
|
8400
8980
|
function sameSources(current, prior) {
|
|
8401
8981
|
return current.every((source) =>
|
|
@@ -8756,14 +9336,14 @@ function withEntries(ledger, entries) {
|
|
|
8756
9336
|
}
|
|
8757
9337
|
function stageRun(staging, files) {
|
|
8758
9338
|
try {
|
|
8759
|
-
|
|
9339
|
+
fs7.mkdirSync(staging, { mode: DIR_MODE2 })
|
|
8760
9340
|
} catch (error) {
|
|
8761
9341
|
return errorCode5(error) === 'EEXIST' ? 'run-exists' : 'write-failed'
|
|
8762
9342
|
}
|
|
8763
9343
|
try {
|
|
8764
|
-
|
|
9344
|
+
fs7.chmodSync(staging, DIR_MODE2)
|
|
8765
9345
|
for (const [name, content] of Object.entries(files)) {
|
|
8766
|
-
writeFileExclusive(
|
|
9346
|
+
writeFileExclusive(path6.join(staging, name), content)
|
|
8767
9347
|
}
|
|
8768
9348
|
return
|
|
8769
9349
|
} catch {
|
|
@@ -8779,8 +9359,8 @@ function publishRun(root, lock, input, options = {}) {
|
|
|
8779
9359
|
if (prior.status !== 'ok') {
|
|
8780
9360
|
return { status: 'failed', reason: 'ledger-unreadable' }
|
|
8781
9361
|
}
|
|
8782
|
-
const runs =
|
|
8783
|
-
const finalDir =
|
|
9362
|
+
const runs = path6.join(root, RUNS_DIR)
|
|
9363
|
+
const finalDir = path6.join(runs, input.runId)
|
|
8784
9364
|
const staging = `${finalDir}${STAGING_SUFFIX}`
|
|
8785
9365
|
try {
|
|
8786
9366
|
const runsStat = lstatMaybe(runs)
|
|
@@ -8797,7 +9377,7 @@ function publishRun(root, lock, input, options = {}) {
|
|
|
8797
9377
|
if (staged !== undefined) return { status: 'failed', reason: staged }
|
|
8798
9378
|
options.hooks?.beforeCommit?.()
|
|
8799
9379
|
try {
|
|
8800
|
-
|
|
9380
|
+
fs7.renameSync(staging, finalDir)
|
|
8801
9381
|
} catch {
|
|
8802
9382
|
removeQuietly(staging)
|
|
8803
9383
|
return { status: 'failed', reason: 'write-failed' }
|
|
@@ -8831,17 +9411,17 @@ function rewriteRunFiles(root, lock, runId, files) {
|
|
|
8831
9411
|
if (names.length > MAX_RUN_FILES || !names.every((n) => SAFE_NAME.test(n))) {
|
|
8832
9412
|
return 'failed'
|
|
8833
9413
|
}
|
|
8834
|
-
const dir =
|
|
9414
|
+
const dir = path6.join(root, RUNS_DIR, runId)
|
|
8835
9415
|
try {
|
|
8836
9416
|
const stat = lstatMaybe(dir)
|
|
8837
9417
|
if (stat === undefined || !stat.isDirectory()) return 'failed'
|
|
8838
9418
|
for (const name of names) {
|
|
8839
|
-
const target =
|
|
9419
|
+
const target = path6.join(dir, name)
|
|
8840
9420
|
const existing = lstatMaybe(target)
|
|
8841
9421
|
if (existing === undefined || !existing.isFile()) return 'failed'
|
|
8842
9422
|
}
|
|
8843
9423
|
for (const [name, content] of Object.entries(files)) {
|
|
8844
|
-
writeFileAtomic(
|
|
9424
|
+
writeFileAtomic(path6.join(dir, name), content)
|
|
8845
9425
|
}
|
|
8846
9426
|
return 'rewritten'
|
|
8847
9427
|
} catch {
|
|
@@ -8869,14 +9449,14 @@ function newImportRunId(now = Date.now()) {
|
|
|
8869
9449
|
function listImportRuns(root) {
|
|
8870
9450
|
let names
|
|
8871
9451
|
try {
|
|
8872
|
-
names =
|
|
9452
|
+
names = fs7.readdirSync(path6.join(root, RUNS_DIR))
|
|
8873
9453
|
} catch {
|
|
8874
9454
|
return []
|
|
8875
9455
|
}
|
|
8876
9456
|
return names
|
|
8877
9457
|
.filter((name) => name.startsWith(IMPORT_RUN_PREFIX) && isRunId(name))
|
|
8878
9458
|
.filter((name) =>
|
|
8879
|
-
lstatMaybe(
|
|
9459
|
+
lstatMaybe(path6.join(root, RUNS_DIR, name))?.isDirectory(),
|
|
8880
9460
|
)
|
|
8881
9461
|
.sort((a, b) => codepointOrder2(b, a))
|
|
8882
9462
|
.slice(0, MAX_IMPORT_RUNS_LISTED)
|
|
@@ -9048,7 +9628,7 @@ function writeInvocationRecord(root, record, options = {}) {
|
|
|
9048
9628
|
const stat = lstatMaybe(root)
|
|
9049
9629
|
if (stat === undefined || !stat.isDirectory()) return 'failed'
|
|
9050
9630
|
writeFileAtomic(
|
|
9051
|
-
|
|
9631
|
+
path6.join(root, INVOCATION_FILE),
|
|
9052
9632
|
`${JSON.stringify(clean, null, 2)}
|
|
9053
9633
|
`,
|
|
9054
9634
|
)
|
|
@@ -9070,19 +9650,19 @@ function readInvocationRecord(root) {
|
|
|
9070
9650
|
}
|
|
9071
9651
|
function pruneRuns(root, lock, options = {}) {
|
|
9072
9652
|
if (!holdsLock(lock)) return { status: 'failed', reason: 'lock-lost' }
|
|
9073
|
-
const runs =
|
|
9653
|
+
const runs = path6.join(root, RUNS_DIR)
|
|
9074
9654
|
const now = (options.now ?? Date.now)()
|
|
9075
9655
|
const removedRuns = []
|
|
9076
9656
|
const removedStaging = []
|
|
9077
9657
|
const failed = []
|
|
9078
9658
|
let names
|
|
9079
9659
|
try {
|
|
9080
|
-
names =
|
|
9660
|
+
names = fs7.readdirSync(runs)
|
|
9081
9661
|
} catch {
|
|
9082
9662
|
return { status: 'failed', reason: 'unreadable' }
|
|
9083
9663
|
}
|
|
9084
9664
|
for (const name of names) {
|
|
9085
|
-
const outcome = pruneEntry(
|
|
9665
|
+
const outcome = pruneEntry(path6.join(runs, name), name, now)
|
|
9086
9666
|
if (outcome === 'failed') failed.push(name)
|
|
9087
9667
|
else if (outcome === 'run') removedRuns.push(name)
|
|
9088
9668
|
else if (outcome === 'staging') removedStaging.push(name)
|
|
@@ -9097,7 +9677,7 @@ function pruneEntry(full, name, now) {
|
|
|
9097
9677
|
const stat = lstatMaybe(full)
|
|
9098
9678
|
if (stat === undefined || !stat.isDirectory()) return 'kept'
|
|
9099
9679
|
if (!staging && now - stat.mtimeMs <= RUN_RETENTION_MS) return 'kept'
|
|
9100
|
-
|
|
9680
|
+
fs7.rmSync(full, { recursive: true, force: true })
|
|
9101
9681
|
return staging ? 'staging' : 'run'
|
|
9102
9682
|
} catch {
|
|
9103
9683
|
return 'failed'
|
|
@@ -9182,9 +9762,9 @@ function clearLedger(root, options = {}) {
|
|
|
9182
9762
|
return { status: 'failed', reason: 'lock-failed' }
|
|
9183
9763
|
}
|
|
9184
9764
|
try {
|
|
9185
|
-
const file =
|
|
9765
|
+
const file = path6.join(root, LEDGER_FILE)
|
|
9186
9766
|
const existed = lstatMaybe(file) !== undefined
|
|
9187
|
-
|
|
9767
|
+
fs7.rmSync(file, { force: true })
|
|
9188
9768
|
return { status: 'cleared', removed: existed }
|
|
9189
9769
|
} catch {
|
|
9190
9770
|
return { status: 'failed', reason: 'write-failed' }
|
|
@@ -9277,17 +9857,17 @@ function lockOptions(options) {
|
|
|
9277
9857
|
function writeFileAtomic2(target, data) {
|
|
9278
9858
|
const temporary = `${target}.tmp-${randomUUID3()}`
|
|
9279
9859
|
try {
|
|
9280
|
-
const fd =
|
|
9860
|
+
const fd = fs8.openSync(temporary, 'wx', 384)
|
|
9281
9861
|
try {
|
|
9282
|
-
|
|
9283
|
-
|
|
9862
|
+
fs8.writeSync(fd, data)
|
|
9863
|
+
fs8.fsyncSync(fd)
|
|
9284
9864
|
} finally {
|
|
9285
|
-
|
|
9865
|
+
fs8.closeSync(fd)
|
|
9286
9866
|
}
|
|
9287
|
-
|
|
9288
|
-
|
|
9867
|
+
fs8.chmodSync(temporary, 384)
|
|
9868
|
+
fs8.renameSync(temporary, target)
|
|
9289
9869
|
} catch (error) {
|
|
9290
|
-
|
|
9870
|
+
fs8.rmSync(temporary, { force: true })
|
|
9291
9871
|
throw error
|
|
9292
9872
|
}
|
|
9293
9873
|
}
|
|
@@ -9407,11 +9987,11 @@ var MAX_BODY_BYTES = 512 * 1024
|
|
|
9407
9987
|
function readReportBody(file) {
|
|
9408
9988
|
let directory
|
|
9409
9989
|
try {
|
|
9410
|
-
directory =
|
|
9990
|
+
directory = fs8.realpathSync.native(path7.dirname(file))
|
|
9411
9991
|
} catch {
|
|
9412
9992
|
return { status: 'failed', reason: 'body-unreadable' }
|
|
9413
9993
|
}
|
|
9414
|
-
const read = readContainedFile(directory,
|
|
9994
|
+
const read = readContainedFile(directory, path7.basename(file), {
|
|
9415
9995
|
maxBytes: MAX_BODY_BYTES,
|
|
9416
9996
|
})
|
|
9417
9997
|
if (read.kind === 'bytes') {
|
|
@@ -9621,7 +10201,7 @@ function withManifest(stored, added) {
|
|
|
9621
10201
|
}
|
|
9622
10202
|
function writeManifestStore(root, manifests) {
|
|
9623
10203
|
writeFileAtomic2(
|
|
9624
|
-
|
|
10204
|
+
path7.join(root, MANIFEST_FILE),
|
|
9625
10205
|
`${JSON.stringify({ version: 1, manifests }, null, 2)}
|
|
9626
10206
|
`,
|
|
9627
10207
|
)
|
|
@@ -10085,10 +10665,10 @@ function renderState(root, request, recordState) {
|
|
|
10085
10665
|
if (recordState && Buffer.byteLength(storeText) > MAX_PAYLOAD_BYTES) {
|
|
10086
10666
|
return { status: 'failed', reason: 'payload-store-too-large' }
|
|
10087
10667
|
}
|
|
10088
|
-
const bodyFile =
|
|
10668
|
+
const bodyFile = path7.join(root, REPORT_FILE)
|
|
10089
10669
|
try {
|
|
10090
10670
|
if (loaded.stores.manifests !== undefined) {
|
|
10091
|
-
writeFileAtomic2(
|
|
10671
|
+
writeFileAtomic2(path7.join(root, PAYLOAD_FILE), storeText)
|
|
10092
10672
|
writeManifestStore(
|
|
10093
10673
|
root,
|
|
10094
10674
|
withManifest(loaded.stores.manifests, {
|
|
@@ -10298,8 +10878,8 @@ function applyTicks(root, request, options = {}) {
|
|
|
10298
10878
|
}
|
|
10299
10879
|
|
|
10300
10880
|
// src/lib/connect-import.ts
|
|
10301
|
-
import
|
|
10302
|
-
import
|
|
10881
|
+
import fs9 from 'node:fs'
|
|
10882
|
+
import path8 from 'node:path'
|
|
10303
10883
|
var IMPORT_RECORD_FILE = 'run.json'
|
|
10304
10884
|
var MAX_IMPORT_RECORD_BYTES = 2 * 1024 * 1024
|
|
10305
10885
|
var MAX_IMPORT_PROJECTS = 64
|
|
@@ -10326,7 +10906,7 @@ function plainString(value, max) {
|
|
|
10326
10906
|
function parseProject(value) {
|
|
10327
10907
|
if (!isRecord5(value)) return
|
|
10328
10908
|
const { root, key, name, repo, commit } = value
|
|
10329
|
-
if (!plainString(root, MAX_ROOT_LENGTH) || !
|
|
10909
|
+
if (!plainString(root, MAX_ROOT_LENGTH) || !path8.posix.isAbsolute(root)) {
|
|
10330
10910
|
return
|
|
10331
10911
|
}
|
|
10332
10912
|
if (key !== projectKey(root)) return
|
|
@@ -10389,8 +10969,8 @@ function parseImportRecord(value) {
|
|
|
10389
10969
|
function readImportRecord(directory) {
|
|
10390
10970
|
let real
|
|
10391
10971
|
try {
|
|
10392
|
-
real =
|
|
10393
|
-
if (!
|
|
10972
|
+
real = fs9.realpathSync.native(directory)
|
|
10973
|
+
if (!fs9.statSync(real).isDirectory()) {
|
|
10394
10974
|
return { status: 'failed', reason: 'directory-unreadable' }
|
|
10395
10975
|
}
|
|
10396
10976
|
} catch {
|
|
@@ -11026,12 +11606,12 @@ function verifyProvenance(input) {
|
|
|
11026
11606
|
}
|
|
11027
11607
|
|
|
11028
11608
|
// src/lib/main-module.ts
|
|
11029
|
-
import
|
|
11609
|
+
import fs10 from 'node:fs'
|
|
11030
11610
|
import { fileURLToPath } from 'node:url'
|
|
11031
11611
|
function resolveRealPath(value) {
|
|
11032
11612
|
if (value === undefined || value === '') return
|
|
11033
11613
|
try {
|
|
11034
|
-
return
|
|
11614
|
+
return fs10.realpathSync(value)
|
|
11035
11615
|
} catch {
|
|
11036
11616
|
return
|
|
11037
11617
|
}
|
|
@@ -11119,7 +11699,7 @@ function psField(pid, field) {
|
|
|
11119
11699
|
}
|
|
11120
11700
|
function procStat(pid) {
|
|
11121
11701
|
try {
|
|
11122
|
-
const stat =
|
|
11702
|
+
const stat = fs11.readFileSync(`/proc/${pid}/stat`, 'utf8')
|
|
11123
11703
|
const close = stat.lastIndexOf(')')
|
|
11124
11704
|
return close < 0
|
|
11125
11705
|
? undefined
|
|
@@ -11142,7 +11722,7 @@ var systemProcessInspector = {
|
|
|
11142
11722
|
if (process.platform === 'linux') {
|
|
11143
11723
|
try {
|
|
11144
11724
|
return (
|
|
11145
|
-
|
|
11725
|
+
fs11.readFileSync(`/proc/${pid}/comm`, 'utf8').trim() || undefined
|
|
11146
11726
|
)
|
|
11147
11727
|
} catch {
|
|
11148
11728
|
return
|
|
@@ -11152,7 +11732,7 @@ var systemProcessInspector = {
|
|
|
11152
11732
|
},
|
|
11153
11733
|
}
|
|
11154
11734
|
function isShell(command) {
|
|
11155
|
-
return SHELLS.has(
|
|
11735
|
+
return SHELLS.has(path9.basename(command).replace(/^-/, ''))
|
|
11156
11736
|
}
|
|
11157
11737
|
function findHolderPid(inspector, from = process.pid) {
|
|
11158
11738
|
let pid = inspector.parentOf(from)
|
|
@@ -11185,6 +11765,7 @@ function describeEnvironment(deps) {
|
|
|
11185
11765
|
allowedRoots: resolved.resolved.map((item) => item.mainRoot),
|
|
11186
11766
|
resolved,
|
|
11187
11767
|
groups: load.groups,
|
|
11768
|
+
pins: load.pins,
|
|
11188
11769
|
warnings: load.warnings,
|
|
11189
11770
|
configUnreadable: load.unreadable,
|
|
11190
11771
|
}
|
|
@@ -11235,6 +11816,7 @@ function rulesOverview(rules, offer) {
|
|
|
11235
11816
|
oneCell(rule.title ?? ''),
|
|
11236
11817
|
oneCell(rule.appliesWhen.map(oneCell).join(' | ')),
|
|
11237
11818
|
offered.has(id) ? 'offered' : 'later',
|
|
11819
|
+
projectKey(rule.project),
|
|
11238
11820
|
].join('\t'),
|
|
11239
11821
|
)
|
|
11240
11822
|
}
|
|
@@ -11292,7 +11874,8 @@ function isSnapshot(value) {
|
|
|
11292
11874
|
Array.isArray(value.offer.fresh) &&
|
|
11293
11875
|
Array.isArray(value.provenance) &&
|
|
11294
11876
|
Array.isArray(value.degradeReasons) &&
|
|
11295
|
-
Array.isArray(value.unread)
|
|
11877
|
+
Array.isArray(value.unread) &&
|
|
11878
|
+
(value.pinNotes === undefined || Array.isArray(value.pinNotes))
|
|
11296
11879
|
)
|
|
11297
11880
|
}
|
|
11298
11881
|
function isValidated(value) {
|
|
@@ -11699,15 +12282,15 @@ function prunedCounts(pruned) {
|
|
|
11699
12282
|
}
|
|
11700
12283
|
: { runs: 0, staging: 0, failed: 0 }
|
|
11701
12284
|
}
|
|
11702
|
-
function beginResponse(setup, snapshot, scans, workDir, limits) {
|
|
12285
|
+
function beginResponse(setup, snapshot, scans, workDir, limits, pins) {
|
|
11703
12286
|
return success('begin', {
|
|
11704
12287
|
status: 'begun',
|
|
11705
12288
|
runId: snapshot.runId,
|
|
11706
12289
|
stateRoot: setup.root,
|
|
11707
12290
|
workDir,
|
|
11708
|
-
rulesFile:
|
|
11709
|
-
filesIndex:
|
|
11710
|
-
rulesOverview:
|
|
12291
|
+
rulesFile: path9.join(workDir, 'rules.json'),
|
|
12292
|
+
filesIndex: path9.join(workDir, 'files.tsv'),
|
|
12293
|
+
rulesOverview: path9.join(workDir, 'rules.tsv'),
|
|
11711
12294
|
offeredRuleIds: snapshot.offer.offered,
|
|
11712
12295
|
offeredCount: snapshot.offer.offered.length,
|
|
11713
12296
|
sweep: {
|
|
@@ -11738,6 +12321,8 @@ function beginResponse(setup, snapshot, scans, workDir, limits) {
|
|
|
11738
12321
|
undecidedProvenance: snapshot.undecidedProvenance,
|
|
11739
12322
|
degradeReasons: snapshot.degradeReasons,
|
|
11740
12323
|
unread: snapshot.unread,
|
|
12324
|
+
pinHints: pins.hints,
|
|
12325
|
+
pinNotes: pins.notes,
|
|
11741
12326
|
configWarnings: setup.environment.warnings,
|
|
11742
12327
|
pruned: snapshot.pruned,
|
|
11743
12328
|
bounds: {
|
|
@@ -11776,6 +12361,23 @@ function indexRun(setup, deps) {
|
|
|
11776
12361
|
try {
|
|
11777
12362
|
const rules = scans.flatMap((scan) => scan.rules)
|
|
11778
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
|
+
)
|
|
11779
12381
|
const offer = planOffer({
|
|
11780
12382
|
rules,
|
|
11781
12383
|
coverage: ledger.ledger.coverage ?? [],
|
|
@@ -11803,6 +12405,7 @@ function indexRun(setup, deps) {
|
|
|
11803
12405
|
unmatched: setup.unmatched,
|
|
11804
12406
|
degradeReasons,
|
|
11805
12407
|
unread,
|
|
12408
|
+
pinNotes: pins.notes,
|
|
11806
12409
|
selection: setup.selection,
|
|
11807
12410
|
ruleIds: rules.map((rule) => rule.id),
|
|
11808
12411
|
ruleVersions: rules.map((rule) => ({
|
|
@@ -11853,7 +12456,7 @@ function indexRun(setup, deps) {
|
|
|
11853
12456
|
)
|
|
11854
12457
|
}
|
|
11855
12458
|
}
|
|
11856
|
-
return beginResponse(setup, snapshot, scans, workDir, limits)
|
|
12459
|
+
return beginResponse(setup, snapshot, scans, workDir, limits, pins)
|
|
11857
12460
|
} catch {
|
|
11858
12461
|
return releaseAndFail('begin', lock, root, runId, 'internal-error')
|
|
11859
12462
|
}
|
|
@@ -11974,15 +12577,15 @@ function readBatches(workDir, runId, requested) {
|
|
|
11974
12577
|
const batches = []
|
|
11975
12578
|
for (const given of requested) {
|
|
11976
12579
|
let name
|
|
11977
|
-
if (
|
|
11978
|
-
if (
|
|
12580
|
+
if (path9.isAbsolute(given)) {
|
|
12581
|
+
if (path9.dirname(path9.resolve(given)) !== workDir) {
|
|
11979
12582
|
return { ok: false, reason: 'batch-outside-work-dir' }
|
|
11980
12583
|
}
|
|
11981
|
-
name =
|
|
12584
|
+
name = path9.basename(given)
|
|
11982
12585
|
} else {
|
|
11983
12586
|
name = given
|
|
11984
12587
|
}
|
|
11985
|
-
if (!isWorkName(name) || name !==
|
|
12588
|
+
if (!isWorkName(name) || name !== path9.basename(name)) {
|
|
11986
12589
|
return { ok: false, reason: 'batch-outside-work-dir' }
|
|
11987
12590
|
}
|
|
11988
12591
|
if (RESERVED_WORK_FILES.has(name)) {
|
|
@@ -12519,6 +13122,7 @@ function digestModel(snapshot, state, outcome, degradeReasons) {
|
|
|
12519
13122
|
suppressed: state.suppressed,
|
|
12520
13123
|
staleCitations: snapshot.staleCitations,
|
|
12521
13124
|
undecidedProvenance: snapshot.undecidedProvenance,
|
|
13125
|
+
pinNotes: readPinNotes(snapshot.pinNotes),
|
|
12522
13126
|
}
|
|
12523
13127
|
}
|
|
12524
13128
|
function runRecord(snapshot, state, outcome, degradeReasons) {
|
|
@@ -12677,7 +13281,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
|
|
|
12677
13281
|
const released = releaseLock(handle)
|
|
12678
13282
|
removeWorkDir(root, snapshot.runId)
|
|
12679
13283
|
const finalOutcome = ledgerWritten ? outcome : 'degraded'
|
|
12680
|
-
const digestPath =
|
|
13284
|
+
const digestPath = path9.join(published.runDir, 'digest.md')
|
|
12681
13285
|
const recorded =
|
|
12682
13286
|
ciMarker === undefined
|
|
12683
13287
|
? 'written'
|
|
@@ -12697,7 +13301,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
|
|
|
12697
13301
|
runId: snapshot.runId,
|
|
12698
13302
|
runDir: published.runDir,
|
|
12699
13303
|
digestPath,
|
|
12700
|
-
runRecordPath:
|
|
13304
|
+
runRecordPath: path9.join(published.runDir, 'run.json'),
|
|
12701
13305
|
ledger: published.ledger,
|
|
12702
13306
|
...(recordsCurrent ? {} : { runRecordCurrent: false }),
|
|
12703
13307
|
...(recorded === 'written' ? {} : { invocationRecord: 'unwritten' }),
|
|
@@ -12708,7 +13312,7 @@ function commitRun(snapshot, state, handle, root, deps, ciMarker) {
|
|
|
12708
13312
|
summary: renderSummary(
|
|
12709
13313
|
final.model,
|
|
12710
13314
|
digestPath,
|
|
12711
|
-
|
|
13315
|
+
path9.join(published.runDir, 'run.json'),
|
|
12712
13316
|
),
|
|
12713
13317
|
})
|
|
12714
13318
|
}
|
|
@@ -13008,7 +13612,7 @@ function parseImportRequest(request) {
|
|
|
13008
13612
|
directory === '' ||
|
|
13009
13613
|
directory.length > MAX_DIRECTORY_LENGTH ||
|
|
13010
13614
|
CONTROL_IN_PATH.test(directory) ||
|
|
13011
|
-
!
|
|
13615
|
+
!path9.isAbsolute(directory)
|
|
13012
13616
|
) {
|
|
13013
13617
|
return
|
|
13014
13618
|
}
|
|
@@ -13179,7 +13783,7 @@ function placeCandidates(accepted, ledger, root, runs) {
|
|
|
13179
13783
|
const holder = kept.find((run) => run.evidence.get(item.id) === current)
|
|
13180
13784
|
return holder === undefined
|
|
13181
13785
|
? undefined
|
|
13182
|
-
:
|
|
13786
|
+
: path9.join(root, 'runs', holder.runId, 'run.json')
|
|
13183
13787
|
}
|
|
13184
13788
|
const fresh = []
|
|
13185
13789
|
const open = []
|
|
@@ -13260,9 +13864,9 @@ function importModel(
|
|
|
13260
13864
|
}
|
|
13261
13865
|
function importAnswer(model, verified, written) {
|
|
13262
13866
|
const runRecordPath =
|
|
13263
|
-
written === undefined ? undefined :
|
|
13867
|
+
written === undefined ? undefined : path9.join(written.runDir, 'run.json')
|
|
13264
13868
|
const digestPath =
|
|
13265
|
-
written === undefined ? undefined :
|
|
13869
|
+
written === undefined ? undefined : path9.join(written.runDir, 'digest.md')
|
|
13266
13870
|
return success('import', {
|
|
13267
13871
|
outcome: model.outcome,
|
|
13268
13872
|
finalLine: `Connect ${model.outcome}`,
|
|
@@ -13350,7 +13954,7 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
|
|
|
13350
13954
|
verified,
|
|
13351
13955
|
placement,
|
|
13352
13956
|
runId,
|
|
13353
|
-
|
|
13957
|
+
path9.join(root, 'runs', runId, 'run.json'),
|
|
13354
13958
|
)
|
|
13355
13959
|
const filesOf = (shown) => ({
|
|
13356
13960
|
'digest.md': renderImportDigest(shown, placement.fresh, createdAt),
|
|
@@ -13388,7 +13992,7 @@ function importWrite(parsed, sourceRunId, verified, root, deps) {
|
|
|
13388
13992
|
verified,
|
|
13389
13993
|
placement,
|
|
13390
13994
|
localRunId,
|
|
13391
|
-
written === undefined ? '' :
|
|
13995
|
+
written === undefined ? '' : path9.join(written.runDir, 'run.json'),
|
|
13392
13996
|
),
|
|
13393
13997
|
verified,
|
|
13394
13998
|
written,
|
|
@@ -13469,7 +14073,7 @@ function parseTicksRequest(request) {
|
|
|
13469
14073
|
bodyFile === '' ||
|
|
13470
14074
|
bodyFile.length > MAX_DIRECTORY_LENGTH ||
|
|
13471
14075
|
CONTROL_IN_PATH.test(bodyFile) ||
|
|
13472
|
-
!
|
|
14076
|
+
!path9.isAbsolute(bodyFile)
|
|
13473
14077
|
) {
|
|
13474
14078
|
return
|
|
13475
14079
|
}
|
|
@@ -13610,7 +14214,7 @@ function errorCodeOf(error) {
|
|
|
13610
14214
|
}
|
|
13611
14215
|
function readStdinChunk(chunk) {
|
|
13612
14216
|
try {
|
|
13613
|
-
return
|
|
14217
|
+
return fs11.readSync(0, chunk, 0, chunk.length, null)
|
|
13614
14218
|
} catch (error) {
|
|
13615
14219
|
const code = errorCodeOf(error)
|
|
13616
14220
|
if (code === 'EOF') return 0
|