统一 Rust 与 TypeScript 格式化门禁

纳入 AGC Cargo workspace 的统一 rustfmt 检查与格式化入口

完成项目 TypeScript/Prettier 与 Rust 全量格式化

修复 Pingora expected executable 门禁的空白敏感误报

同步开发运维文档与 AGC skill pack 格式化忽略规则
This commit is contained in:
2026-09-01 16:26:20 +08:00
parent ae79d50b14
commit 071faa482c
1051 changed files with 28412 additions and 19834 deletions
+43 -29
View File
@@ -1,4 +1,4 @@
import {randomBytes} from 'node:crypto';
import { randomBytes } from 'node:crypto';
import {
chmodSync,
existsSync,
@@ -8,11 +8,12 @@ import {
rmSync,
writeFileSync,
} from 'node:fs';
import {createServer} from 'node:net';
import {hostname, userInfo} from 'node:os';
import {dirname, resolve} from 'node:path';
import { createServer } from 'node:net';
import { hostname, userInfo } from 'node:os';
import { dirname, resolve } from 'node:path';
const LINUX_DEV_PORT_RANGE_REGISTRY_ROOT = '/var/tmp/genarrative-dev-port-ranges';
const LINUX_DEV_PORT_RANGE_REGISTRY_ROOT =
'/var/tmp/genarrative-dev-port-ranges';
const LINUX_DEV_PORT_RANGE_POOL_START = 10000;
const LINUX_DEV_PORT_RANGE_POOL_END = 39999;
const LINUX_DEV_PORT_RANGE_BLOCK_SIZE = 100;
@@ -48,20 +49,24 @@ function parsePortRangeSpecWithMinimum(value, minimumSize) {
const match = /^(\d+)\s*[-:]\s*(\d+)$/u.exec(spec);
if (!match) {
throw new Error(`端口段格式错误: ${spec},应为 start-end 形式,如 10000-10099`);
throw new Error(
`端口段格式错误: ${spec},应为 start-end 形式,如 10000-10099`,
);
}
const start = normalizePort(match[1], -1);
const end = normalizePort(match[2], -1);
if (start < 1024 || end < 1024 || start > end) {
throw new Error(`端口段无效: ${spec},端口必须在 1024-65535 且起始不大于结束`);
throw new Error(
`端口段无效: ${spec},端口必须在 1024-65535 且起始不大于结束`,
);
}
if (end - start + 1 < minimumSize) {
throw new Error(`端口段至少需要 ${minimumSize} 个端口: ${spec}`);
}
return {start, end, label: `${start}-${end}`};
return { start, end, label: `${start}-${end}` };
}
export function parsePortRangeSpec(value) {
@@ -70,7 +75,7 @@ export function parsePortRangeSpec(value) {
function normalizePortRange(
portRange,
{minimumSize = DEV_PORT_RANGE_MIN_SIZE} = {},
{ minimumSize = DEV_PORT_RANGE_MIN_SIZE } = {},
) {
if (!portRange) {
return null;
@@ -142,7 +147,7 @@ export function mapDevPortsToPortRange(portRange) {
}
function ensureWorldWritableDirectory(path) {
mkdirSync(path, {recursive: true});
mkdirSync(path, { recursive: true });
try {
chmodSync(path, 0o777);
} catch {
@@ -195,7 +200,7 @@ function atomicWriteJsonFile(path, value) {
renameSync(tempPath, path);
} catch (error) {
try {
rmSync(tempPath, {force: true});
rmSync(tempPath, { force: true });
} catch {
// ignore cleanup races
}
@@ -272,10 +277,10 @@ function readLinuxPortRangeRegistry(registryPath) {
function safeNormalizePortRange(
portRange,
{minimumSize = LEGACY_DEV_PORT_RANGE_MIN_SIZE} = {},
{ minimumSize = LEGACY_DEV_PORT_RANGE_MIN_SIZE } = {},
) {
try {
return normalizePortRange(portRange, {minimumSize});
return normalizePortRange(portRange, { minimumSize });
} catch {
return null;
}
@@ -327,7 +332,7 @@ function findRangeConflict(registry, portRange, excludingUsername = '') {
continue;
}
return {username, record, range: recordRange};
return { username, record, range: recordRange };
}
return null;
@@ -345,8 +350,8 @@ function nextLinuxPortRangeCandidate(registry) {
}
const label = `${start}-${end}`;
if (!findRangeConflict(registry, {start, end, label})) {
return {start, end, label};
if (!findRangeConflict(registry, { start, end, label })) {
return { start, end, label };
}
}
@@ -369,7 +374,7 @@ async function withLinuxPortRangeRegistryLock(lockPath, action) {
null,
2,
),
{encoding: 'utf8', flag: 'wx', mode: 0o666},
{ encoding: 'utf8', flag: 'wx', mode: 0o666 },
);
break;
} catch (error) {
@@ -386,7 +391,7 @@ async function withLinuxPortRangeRegistryLock(lockPath, action) {
if (!lockRecord || !isProcessAlive(lockRecord.pid)) {
try {
rmSync(lockPath, {force: true});
rmSync(lockPath, { force: true });
} catch {
// ignore cleanup races
}
@@ -401,7 +406,7 @@ async function withLinuxPortRangeRegistryLock(lockPath, action) {
return await action();
} finally {
try {
rmSync(lockPath, {force: true});
rmSync(lockPath, { force: true });
} catch {
// ignore cleanup races
}
@@ -443,7 +448,8 @@ export async function reserveLinuxDevPortRange({
return registry.allocations[username];
}
const rangeToUse = normalizedRequestedRange || nextLinuxPortRangeCandidate(registry);
const rangeToUse =
normalizedRequestedRange || nextLinuxPortRangeCandidate(registry);
if (!rangeToUse) {
throw new Error(
@@ -501,7 +507,7 @@ export async function releaseLinuxDevPortRange({
});
}
export async function isPortAvailable({host, port}) {
export async function isPortAvailable({ host, port }) {
if (port === 0) {
return true;
}
@@ -513,7 +519,7 @@ export async function isPortAvailable({host, port}) {
const server = createServer();
server.unref();
server.once('error', () => resolve(false));
server.listen({host: listenHost, port}, () => {
server.listen({ host: listenHost, port }, () => {
server.close(() => resolve(true));
});
});
@@ -559,10 +565,12 @@ export async function findAvailablePort({
if (strict && startPort !== 0) {
if (reservedPorts.has(startPort)) {
throw new Error(`端口 ${host}:${startPort} 已被当前 dev 启动流程占用,无法严格使用该端口`);
throw new Error(
`端口 ${host}:${startPort} 已被当前 dev 启动流程占用,无法严格使用该端口`,
);
}
if (await isPortAvailable({host, port: startPort})) {
if (await isPortAvailable({ host, port: startPort })) {
return startPort;
}
@@ -587,7 +595,7 @@ export async function findAvailablePort({
continue;
}
if (await isPortAvailable({host, port: candidate})) {
if (await isPortAvailable({ host, port: candidate })) {
return candidate;
}
}
@@ -602,9 +610,10 @@ async function reserveEphemeralPort(host, reservedPorts) {
const server = createServer();
server.unref();
server.once('error', reject);
server.listen({host, port: 0}, () => {
server.listen({ host, port: 0 }, () => {
const address = server.address();
const resolvedPort = typeof address === 'object' && address ? address.port : 0;
const resolvedPort =
typeof address === 'object' && address ? address.port : 0;
server.close(() => resolve(resolvedPort));
});
});
@@ -619,7 +628,7 @@ async function reserveEphemeralPort(host, reservedPorts) {
export async function resolveDevStackPorts(
config,
{reservedPorts: initialReservedPorts = new Set()} = {},
{ reservedPorts: initialReservedPorts = new Set() } = {},
) {
const reservedPorts = new Set(initialReservedPorts);
const entries = [
@@ -646,7 +655,12 @@ export async function resolveDevStackPorts(
return result;
}
export function formatPortDecision({name, host, preferredPort, resolvedPort}) {
export function formatPortDecision({
name,
host,
preferredPort,
resolvedPort,
}) {
if (preferredPort === resolvedPort && preferredPort !== 0) {
return `[dev:ports] ${name}: ${host}:${resolvedPort} 可用`;
}