@alint-js/config 0.5.0 → 0.6.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/README.md +3 -0
- package/dist/index.d.mts +20 -2
- package/dist/index.mjs +120 -32
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ This package owns the file-system side of configuration:
|
|
|
11
11
|
- parses and stringifies setup TOML
|
|
12
12
|
- merges setup layers
|
|
13
13
|
- writes provider setup files
|
|
14
|
+
- reads Stop Gate integration settings and writes their non-default TOML overrides
|
|
14
15
|
- installs remote plugin packages or local plugin directories and writes `.alint/plugins/lock.json`
|
|
15
16
|
- exports built-in ignore pattern groups for lower-level tooling
|
|
16
17
|
|
|
@@ -40,6 +41,8 @@ const config = await loadAlintConfig(cwd)
|
|
|
40
41
|
await writeSetupConfig(setupPath, setup)
|
|
41
42
|
```
|
|
42
43
|
|
|
44
|
+
Stop Gate configuration uses the project config's `integrations.stopGate` field and remains inactive unless that field explicitly contains `enabled = true`. `setStopGateConfig` only extends the existing TOML write path; it does not add new writable formats or output-path selection.
|
|
45
|
+
|
|
43
46
|
Static configs can use TOML, YAML, JSON, JSONC, or JSON5. They are data-only alternatives to executable JavaScript and TypeScript flat configs, and identify plugin sources with strings.
|
|
44
47
|
|
|
45
48
|
For example, TOML supports exact remote packages, config-relative directories, and native absolute paths:
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AlintConfig, AlintConfig as AlintConfig$1, AlintConfigItem, ModelSize, PluginDefinition, ProviderDefinition, ProviderType, ProviderType as ProviderType$1, RunnerConfig, RunnerConfig as RunnerConfig$1, RunnerStatsConfig, SetupConfig as SetupConfig$1, SetupModelDefinition, SetupModelDefinition as SetupModelDefinition$1 } from "@alint-js/core";
|
|
1
|
+
import { AlintConfig, AlintConfig as AlintConfig$1, AlintConfigItem, ModelSize, PluginDefinition, ProviderDefinition, ProviderType, ProviderType as ProviderType$1, ResolvedStopGateConfig, RunnerConfig, RunnerConfig as RunnerConfig$1, RunnerStatsConfig, SetupConfig as SetupConfig$1, SetupModelDefinition, SetupModelDefinition as SetupModelDefinition$1, StopGateTarget } from "@alint-js/core";
|
|
2
2
|
//#region src/plugins/spec.d.ts
|
|
3
3
|
interface DirectoryPluginSpecifier {
|
|
4
4
|
directory: string;
|
|
@@ -46,9 +46,27 @@ declare function parseStaticConfig(value: unknown, options?: ParseStaticConfigOp
|
|
|
46
46
|
declare function toAlintConfig(config: ParsedStaticConfig, options: ToAlintConfigOptions): Promise<AlintConfig$1>;
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region src/config/load.d.ts
|
|
49
|
+
interface LoadedAlintConfig {
|
|
50
|
+
config: AlintConfig$1;
|
|
51
|
+
configFile?: string;
|
|
52
|
+
}
|
|
49
53
|
declare function loadAlintConfig(cwd: string, configFile?: string): Promise<AlintConfig$1>;
|
|
54
|
+
declare function loadAlintConfigWithMetadata(cwd: string, configFile?: string): Promise<LoadedAlintConfig>;
|
|
50
55
|
declare function loadStaticConfig(cwd: string, configFile?: string): Promise<ParsedStaticConfig>;
|
|
51
56
|
//#endregion
|
|
57
|
+
//#region src/config/stop-gate-write.d.ts
|
|
58
|
+
interface SetStopGateConfigOptions {
|
|
59
|
+
configFile?: string;
|
|
60
|
+
cwd: string;
|
|
61
|
+
enabled?: boolean;
|
|
62
|
+
target?: StopGateTarget;
|
|
63
|
+
timeoutMs?: number;
|
|
64
|
+
}
|
|
65
|
+
declare function setStopGateConfig(options: SetStopGateConfigOptions): Promise<{
|
|
66
|
+
config: ResolvedStopGateConfig;
|
|
67
|
+
configFile: string;
|
|
68
|
+
}>;
|
|
69
|
+
//#endregion
|
|
52
70
|
//#region src/constants/patterns/ignore.d.ts
|
|
53
71
|
declare const ignorePatternsEslintDefaults: readonly ["**/node_modules/**", ".git/**", "**/.git/**"];
|
|
54
72
|
declare const ignorePatternsBuildOutputs: readonly ["**/dist/**", "**/coverage/**", "**/output/**", "**/.output/**", "**/.next/**", "**/.nuxt/**", "**/.svelte-kit/**", "**/.vercel/**"];
|
|
@@ -294,4 +312,4 @@ declare function stringifySetupConfigToml(config: SetupConfig): string;
|
|
|
294
312
|
//#region src/setup/write.d.ts
|
|
295
313
|
declare function writeSetupConfig(filePath: string, config: SetupConfig): Promise<void>;
|
|
296
314
|
//#endregion
|
|
297
|
-
export { type AcpModelConfig, type AcpProviderConfig, type AlintConfig, BuiltInAgentName, CreateDeclarativePluginOptions, CreateReportScopeOptions, DeclarativeFinding, DeclarativeFindingResponse, DeclarativeRuleDefinition, type DirectoryPluginLockEntry, type GlobalSetupConfigPathOptions, LoadDeclarativeRulesOptions, type ModelAdapterProvider, type ModelConfig, type ModelSize, type ParseStaticConfigOptions, type ParsedDirectoryPluginLockEntry, type ParsedPluginLockEntry, type ParsedPluginLockFile, type ParsedPluginSpecifier, type ParsedRegistryPluginLockEntry, type ParsedStaticConfig, type ParsedStaticConfigGroup, type PluginLockEntry, type PluginLockFile, type ProviderConfig, type ProviderConfig as ProviderDefinition, type ProviderType, type RegistryPluginLockEntry, ReportScope, type RunnerConfig, type RunnerStatsConfig, type SetupConfig, type SetupModelAdapters, type SetupModelDefinition, type StaticConfigInput, type StaticConfigItem, type StaticPluginInstallOptions, type StaticPluginInstallResult, type StaticPluginReference, type StaticPluginResolver, type ToAlintConfigOptions, addProviderModels, builtInAgentNames, createDeclarativePlugin, createEmptyPluginLockFile, createReportScope, declarativeFindingResponseSchema, declarativeFindingSchema, declarativeRuleFilePattern, emptySetupConfig, getGlobalSetupConfigPath, getProjectPluginLockPath, getProjectPluginStorePath, getProjectSetupConfigPath, getStatsDir, hasDeclarativeRuleFiles, ignorePatternsAIAgents, ignorePatternsBuildOutputs, ignorePatternsCaches, ignorePatternsCommon, ignorePatternsEslintDefaults, ignorePatternsGenerated, installStaticPlugins, isAcpModel, isBuiltInAgentName, listMissing, listUnresolved, loadAlintConfig, loadDeclarativeRules, loadPluginLockFile, loadSetupConfig, loadStaticConfig, mergeSetupConfigs, modelFromAcpModel, normalizeSetupConfig, parsePluginLockFile, parsePluginSpecifier, parseSetupConfigToml, parseStaticConfig, pruneProviderModels, removeProviderModels, replaceSetupProvider, setProviderEndpoint, setProviderHeader, stringifySetupConfigToml, toAlintConfig, unsetProviderHeader, writePluginLockFile, writeSetupConfig };
|
|
315
|
+
export { type AcpModelConfig, type AcpProviderConfig, type AlintConfig, BuiltInAgentName, CreateDeclarativePluginOptions, CreateReportScopeOptions, DeclarativeFinding, DeclarativeFindingResponse, DeclarativeRuleDefinition, type DirectoryPluginLockEntry, type GlobalSetupConfigPathOptions, LoadDeclarativeRulesOptions, type LoadedAlintConfig, type ModelAdapterProvider, type ModelConfig, type ModelSize, type ParseStaticConfigOptions, type ParsedDirectoryPluginLockEntry, type ParsedPluginLockEntry, type ParsedPluginLockFile, type ParsedPluginSpecifier, type ParsedRegistryPluginLockEntry, type ParsedStaticConfig, type ParsedStaticConfigGroup, type PluginLockEntry, type PluginLockFile, type ProviderConfig, type ProviderConfig as ProviderDefinition, type ProviderType, type RegistryPluginLockEntry, ReportScope, type RunnerConfig, type RunnerStatsConfig, type SetStopGateConfigOptions, type SetupConfig, type SetupModelAdapters, type SetupModelDefinition, type StaticConfigInput, type StaticConfigItem, type StaticPluginInstallOptions, type StaticPluginInstallResult, type StaticPluginReference, type StaticPluginResolver, type ToAlintConfigOptions, addProviderModels, builtInAgentNames, createDeclarativePlugin, createEmptyPluginLockFile, createReportScope, declarativeFindingResponseSchema, declarativeFindingSchema, declarativeRuleFilePattern, emptySetupConfig, getGlobalSetupConfigPath, getProjectPluginLockPath, getProjectPluginStorePath, getProjectSetupConfigPath, getStatsDir, hasDeclarativeRuleFiles, ignorePatternsAIAgents, ignorePatternsBuildOutputs, ignorePatternsCaches, ignorePatternsCommon, ignorePatternsEslintDefaults, ignorePatternsGenerated, installStaticPlugins, isAcpModel, isBuiltInAgentName, listMissing, listUnresolved, loadAlintConfig, loadAlintConfigWithMetadata, loadDeclarativeRules, loadPluginLockFile, loadSetupConfig, loadStaticConfig, mergeSetupConfigs, modelFromAcpModel, normalizeSetupConfig, parsePluginLockFile, parsePluginSpecifier, parseSetupConfigToml, parseStaticConfig, pruneProviderModels, removeProviderModels, replaceSetupProvider, setProviderEndpoint, setProviderHeader, setStopGateConfig, stringifySetupConfigToml, toAlintConfig, unsetProviderHeader, writePluginLockFile, writeSetupConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -3,12 +3,13 @@ import { loadConfig } from "c12";
|
|
|
3
3
|
import { createJiti } from "jiti/static";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { access, mkdir, open, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
|
-
import { array, boolean, check, description, finite, integer, literal, looseObject, minValue, nonEmpty, number, object, optional, parse, picklist, pipe, record, strictObject, string, transform, tupleWithRest, undefined_, union, unknown, variant } from "valibot";
|
|
6
|
+
import { array, boolean, check, description, finite, integer, literal, looseObject, maxValue, minValue, nonEmpty, number, object, optional, parse, picklist, pipe, record, strictObject, string, transform, tupleWithRest, undefined_, union, unknown, variant } from "valibot";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
|
-
import { dirname as dirname$1, extname, join as join$1, normalize as normalize$1 } from "pathe";
|
|
9
|
+
import { dirname as dirname$1, extname, join as join$1, normalize as normalize$1, resolve as resolve$1 } from "pathe";
|
|
10
10
|
import { xdgConfig } from "xdg-basedir";
|
|
11
|
-
import {
|
|
11
|
+
import { isNodeErrorCode } from "@alint-js/utils/node";
|
|
12
|
+
import { errorMessageFrom } from "@moeru/std/error";
|
|
12
13
|
import { formatOutputLanguageInstruction, formatSourceWithLineNumbers, generateStructured, toolParametersFromSchema } from "@alint-js/core/structured-output";
|
|
13
14
|
import { createTools, listFiles } from "@alint-js/tools-fs";
|
|
14
15
|
import { chat, hasToolCall, or, rawTool, stepCountAtLeast, user } from "apeira";
|
|
@@ -23,8 +24,9 @@ import tar from "tar-stream";
|
|
|
23
24
|
import { ofetch } from "ofetch";
|
|
24
25
|
import { pathToFileURL } from "node:url";
|
|
25
26
|
import { isPlainObject } from "es-toolkit/compat";
|
|
26
|
-
import {
|
|
27
|
+
import { defaultStopGateConfig, maximumStopGateTimeoutMs, resolveStopGateConfig } from "@alint-js/core";
|
|
27
28
|
import { parse as parse$1, stringify } from "smol-toml";
|
|
29
|
+
import { merge } from "@moeru/std/merge";
|
|
28
30
|
//#region src/paths.ts
|
|
29
31
|
function getGlobalSetupConfigPath(env = process.env, options = {}) {
|
|
30
32
|
return join$1(resolveAlintHome(env, options), "config.toml");
|
|
@@ -63,9 +65,6 @@ async function exists(path) {
|
|
|
63
65
|
function isENOENTError(error) {
|
|
64
66
|
return isNodeErrorCode(error, "ENOENT");
|
|
65
67
|
}
|
|
66
|
-
function isNodeErrorCode(error, code) {
|
|
67
|
-
return isError(error) && "code" in error && error.code === code;
|
|
68
|
-
}
|
|
69
68
|
function isPathInside(path, parent) {
|
|
70
69
|
const childRelativePath = relative(parent, path);
|
|
71
70
|
return childRelativePath === "" || childRelativePath !== ".." && !childRelativePath.startsWith(`..${sep}`) && !isAbsolute(childRelativePath);
|
|
@@ -157,12 +156,12 @@ async function findDeclarativeRuleFiles(root) {
|
|
|
157
156
|
await collectDeclarativeRuleFiles(root, files);
|
|
158
157
|
return files.sort((left, right) => left.localeCompare(right));
|
|
159
158
|
}
|
|
160
|
-
function isPlainObject$
|
|
159
|
+
function isPlainObject$3(value) {
|
|
161
160
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
162
161
|
}
|
|
163
162
|
async function loadDeclarativeRuleFile(filePath) {
|
|
164
163
|
const input = await loadDeclarativeRuleFileContent(filePath);
|
|
165
|
-
if (!isPlainObject$
|
|
164
|
+
if (!isPlainObject$3(input)) throw new Error(`Declarative rule file ${filePath} must contain an object.`);
|
|
166
165
|
const parsed = parseDeclarativeRuleFileInput(input, filePath);
|
|
167
166
|
return {
|
|
168
167
|
builtInAgent: parsed.builtInAgent,
|
|
@@ -543,7 +542,7 @@ async function install$1(options) {
|
|
|
543
542
|
type: "directory"
|
|
544
543
|
};
|
|
545
544
|
}
|
|
546
|
-
async function resolve$
|
|
545
|
+
async function resolve$3(entry) {
|
|
547
546
|
const lockedPath = isAbsolute(entry.lockEntry.path) || win32.isAbsolute(entry.lockEntry.path) ? entry.lockEntry.path : resolve(entry.cwd, entry.lockEntry.path);
|
|
548
547
|
const [packageDir, lockedPackageDir] = await Promise.all([lockedRoot(entry.alias, entry.specifier.directory, "configured"), lockedRoot(entry.alias, lockedPath, "locked")]);
|
|
549
548
|
if (packageDir !== lockedPackageDir) throw new Error(`Directory plugin "${entry.alias}" has moved or its symlink target changed. Run: alint plugin install`);
|
|
@@ -697,7 +696,7 @@ async function install(options) {
|
|
|
697
696
|
version
|
|
698
697
|
};
|
|
699
698
|
}
|
|
700
|
-
async function resolve$
|
|
699
|
+
async function resolve$2(entry) {
|
|
701
700
|
const projectRoot = resolve(entry.cwd);
|
|
702
701
|
const pluginRoot = join(projectRoot, ".alint", "plugins", "store");
|
|
703
702
|
const rawEntryPath = entry.lockEntry.entry;
|
|
@@ -822,7 +821,7 @@ async function resolvePhysicalPath(path) {
|
|
|
822
821
|
//#endregion
|
|
823
822
|
//#region src/plugins/resolve.ts
|
|
824
823
|
function resolvePluginImportTarget(entry) {
|
|
825
|
-
return entry.type === "directory" ? resolve$
|
|
824
|
+
return entry.type === "directory" ? resolve$3(entry) : resolve$2(entry);
|
|
826
825
|
}
|
|
827
826
|
//#endregion
|
|
828
827
|
//#region src/plugins/spec.ts
|
|
@@ -1059,6 +1058,11 @@ const staticConfigItemSchema = looseObject({
|
|
|
1059
1058
|
files: optional(array(filePatternSchema)),
|
|
1060
1059
|
ignore: optional(looseObject({ gitignore: optional(boolean()) })),
|
|
1061
1060
|
ignores: optional(array(string())),
|
|
1061
|
+
integrations: optional(looseObject({ stopGate: optional(looseObject({
|
|
1062
|
+
enabled: optional(boolean()),
|
|
1063
|
+
target: optional(picklist(["all", "dirty-files"])),
|
|
1064
|
+
timeoutMs: optional(pipe(number(), integer(), minValue(1), maxValue(maximumStopGateTimeoutMs)))
|
|
1065
|
+
})) })),
|
|
1062
1066
|
language: optional(string()),
|
|
1063
1067
|
languageOptions: optional(record(string(), unknown())),
|
|
1064
1068
|
linterOptions: optional(looseObject({
|
|
@@ -1087,7 +1091,7 @@ async function toAlintConfig(config, options) {
|
|
|
1087
1091
|
const pluginCache = /* @__PURE__ */ new Map();
|
|
1088
1092
|
return Promise.all(config.groups.map((group) => resolveStaticPlugins(group, options, pluginCache)));
|
|
1089
1093
|
}
|
|
1090
|
-
function isPlainObject$
|
|
1094
|
+
function isPlainObject$2(value) {
|
|
1091
1095
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1092
1096
|
}
|
|
1093
1097
|
function isTomlConfig(configFile) {
|
|
@@ -1105,14 +1109,14 @@ function parseStaticConfigItems(value) {
|
|
|
1105
1109
|
return value.map(parseStaticConfigItem);
|
|
1106
1110
|
}
|
|
1107
1111
|
function readConfigGroup(value) {
|
|
1108
|
-
if (!isPlainObject$
|
|
1112
|
+
if (!isPlainObject$2(value)) return;
|
|
1109
1113
|
const wrapper = value;
|
|
1110
1114
|
if (wrapper.config === void 0) return;
|
|
1111
|
-
if (!isPlainObject$
|
|
1115
|
+
if (!isPlainObject$2(wrapper.config) || !Array.isArray(wrapper.config.group)) throw new TypeError("Static config field \"config.group\" must be an array.");
|
|
1112
1116
|
return wrapper.config.group;
|
|
1113
1117
|
}
|
|
1114
1118
|
function readStaticPluginReferences(item, pluginsByAlias, options) {
|
|
1115
|
-
if (!isPlainObject$
|
|
1119
|
+
if (!isPlainObject$2(item.plugins)) return [];
|
|
1116
1120
|
const references = [];
|
|
1117
1121
|
for (const [alias, plugin] of Object.entries(item.plugins)) {
|
|
1118
1122
|
if (typeof plugin !== "string") continue;
|
|
@@ -1164,23 +1168,39 @@ function toAlintConfigItems(value, options = {}) {
|
|
|
1164
1168
|
//#endregion
|
|
1165
1169
|
//#region src/config/load.ts
|
|
1166
1170
|
async function loadAlintConfig(cwd, configFile) {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
+
return (await loadAlintConfigWithMetadata(cwd, configFile)).config;
|
|
1172
|
+
}
|
|
1173
|
+
async function loadAlintConfigWithMetadata(cwd, configFile) {
|
|
1174
|
+
const source = await loadStaticConfigSource(cwd, configFile);
|
|
1175
|
+
const staticConfig = source.config;
|
|
1176
|
+
if (staticConfig.groups.flatMap((group) => group.plugins).length === 0) return {
|
|
1177
|
+
config: await toAlintConfig(staticConfig, { pluginResolver: async (reference) => {
|
|
1178
|
+
throw new Error(`Static plugin "${reference.alias}" was not expected to require resolution.`);
|
|
1179
|
+
} }),
|
|
1180
|
+
configFile: source.configFile
|
|
1181
|
+
};
|
|
1171
1182
|
const lock = parsePluginLockFile(await loadPluginLockFile(cwd), { cwd });
|
|
1172
1183
|
const missing = listMissing(staticConfig, lock);
|
|
1173
|
-
if (missing.length > 0) throw new Error(`Static plugin references are missing from the lock file: ${
|
|
1184
|
+
if (missing.length > 0) throw new Error(`Static plugin references are missing from the lock file: ${formatPluginReferences(missing)}.\nRun: alint plugin install`);
|
|
1174
1185
|
const unresolved = await listUnresolved(staticConfig, lock);
|
|
1175
1186
|
if (unresolved.length > 0) {
|
|
1176
|
-
const message = `Static plugins could not be resolved from the lock file: ${
|
|
1187
|
+
const message = `Static plugins could not be resolved from the lock file: ${formatPluginReferences(unresolved)}.\nRun: alint plugin install`;
|
|
1177
1188
|
throw new Error(message, { cause: unresolved[0]?.resolutionError });
|
|
1178
1189
|
}
|
|
1179
|
-
return
|
|
1180
|
-
|
|
1181
|
-
|
|
1190
|
+
return {
|
|
1191
|
+
config: await toAlintConfig(staticConfig, { async pluginResolver(reference) {
|
|
1192
|
+
return importPlugin(await resolvePluginImportTarget(lock.get(reference)));
|
|
1193
|
+
} }),
|
|
1194
|
+
configFile: source.configFile
|
|
1195
|
+
};
|
|
1182
1196
|
}
|
|
1183
1197
|
async function loadStaticConfig(cwd, configFile) {
|
|
1198
|
+
return (await loadStaticConfigSource(cwd, configFile)).config;
|
|
1199
|
+
}
|
|
1200
|
+
function formatPluginReferences(references) {
|
|
1201
|
+
return references.map((reference) => `${reference.alias} (${reference.specifier.raw})`).join(", ");
|
|
1202
|
+
}
|
|
1203
|
+
async function loadStaticConfigSource(cwd, configFile) {
|
|
1184
1204
|
const jiti = createJiti(resolve(cwd, configFile ?? "alint.config"), {
|
|
1185
1205
|
interopDefault: true,
|
|
1186
1206
|
moduleCache: false
|
|
@@ -1192,14 +1212,82 @@ async function loadStaticConfig(cwd, configFile) {
|
|
|
1192
1212
|
import: (id) => jiti.import(id),
|
|
1193
1213
|
name: "alint"
|
|
1194
1214
|
});
|
|
1195
|
-
if (result._configFile === void 0) return parseStaticConfig(void 0);
|
|
1196
|
-
|
|
1215
|
+
if (result._configFile === void 0) return { config: parseStaticConfig(void 0) };
|
|
1216
|
+
const resolvedConfigFile = result._configFile;
|
|
1217
|
+
return {
|
|
1218
|
+
config: parseStaticConfig(result.config, { configFile: resolvedConfigFile }),
|
|
1219
|
+
configFile: resolvedConfigFile
|
|
1220
|
+
};
|
|
1197
1221
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1222
|
+
//#endregion
|
|
1223
|
+
//#region src/config/stop-gate-write.ts
|
|
1224
|
+
async function setStopGateConfig(options) {
|
|
1225
|
+
if (options.enabled === void 0 && options.target === void 0 && options.timeoutMs === void 0) throw new Error("Stop Gate config write requires enabled, target, or timeoutMs.");
|
|
1226
|
+
const loaded = await loadAlintConfigWithMetadata(options.cwd, options.configFile);
|
|
1227
|
+
if (options.configFile !== void 0 && loaded.configFile === void 0) throw new Error(`Config file "${options.configFile}" does not exist.`);
|
|
1228
|
+
const config = resolveStopGateConfig([...loaded.config, { integrations: { stopGate: {
|
|
1229
|
+
enabled: options.enabled,
|
|
1230
|
+
target: options.target,
|
|
1231
|
+
timeoutMs: options.timeoutMs
|
|
1232
|
+
} } }], options.cwd);
|
|
1233
|
+
const configFile = loaded.configFile === void 0 ? join$1(options.cwd, "alint.config.toml") : resolve$1(options.cwd, loaded.configFile);
|
|
1234
|
+
if (extname(configFile).toLowerCase() !== ".toml") throw new Error("Stop Gate config writes require an alint.config.toml file.");
|
|
1235
|
+
const document = loaded.configFile === void 0 ? { config: { group: [] } } : parseStaticConfigDocument(await readFile(configFile, "utf8"));
|
|
1236
|
+
const stopGates = [];
|
|
1237
|
+
for (const group of document.config.group) if (isPlainObject$1(group.integrations) && isPlainObject$1(group.integrations.stopGate)) stopGates.push(group.integrations.stopGate);
|
|
1238
|
+
setOverride(document, stopGates, "enabled", options.enabled, defaultStopGateConfig.enabled);
|
|
1239
|
+
setOverride(document, stopGates, "target", options.target, defaultStopGateConfig.target);
|
|
1240
|
+
setOverride(document, stopGates, "timeoutMs", options.timeoutMs, defaultStopGateConfig.timeoutMs);
|
|
1241
|
+
for (const stopGate of stopGates) removeEmptyStopGateConfig(document, stopGate);
|
|
1242
|
+
await writeConfigAtomically(configFile, stringify(document));
|
|
1243
|
+
return {
|
|
1244
|
+
config,
|
|
1245
|
+
configFile
|
|
1246
|
+
};
|
|
1200
1247
|
}
|
|
1201
|
-
function
|
|
1202
|
-
return
|
|
1248
|
+
function isPlainObject$1(value) {
|
|
1249
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1250
|
+
}
|
|
1251
|
+
function parseStaticConfigDocument(toml) {
|
|
1252
|
+
const document = parse$1(toml);
|
|
1253
|
+
if (!isPlainObject$1(document) || !isPlainObject$1(document.config) || !Array.isArray(document.config.group)) throw new Error("Static TOML config must use [[config.group]].");
|
|
1254
|
+
if (!document.config.group.every(isPlainObject$1)) throw new TypeError("Static config field \"config.group\" must contain only tables.");
|
|
1255
|
+
return document;
|
|
1256
|
+
}
|
|
1257
|
+
function removeEmptyStopGateConfig(document, stopGate) {
|
|
1258
|
+
if (Object.keys(stopGate).length > 0) return;
|
|
1259
|
+
for (let index = document.config.group.length - 1; index >= 0; index -= 1) {
|
|
1260
|
+
const group = document.config.group[index];
|
|
1261
|
+
const integrations = group?.integrations;
|
|
1262
|
+
if (!isPlainObject$1(integrations) || integrations.stopGate !== stopGate) continue;
|
|
1263
|
+
delete integrations.stopGate;
|
|
1264
|
+
if (Object.keys(integrations).length === 0) delete group.integrations;
|
|
1265
|
+
if (group.name === "alint stop gate" && Object.keys(group).length === 1) document.config.group.splice(index, 1);
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
function setOverride(document, stopGates, key, value, defaultValue) {
|
|
1270
|
+
if (value === void 0) return;
|
|
1271
|
+
if (value === defaultValue) {
|
|
1272
|
+
for (const stopGate of stopGates) delete stopGate[key];
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
let stopGate = stopGates.at(-1);
|
|
1276
|
+
if (stopGate === void 0) {
|
|
1277
|
+
stopGate = {};
|
|
1278
|
+
document.config.group.push({
|
|
1279
|
+
integrations: { stopGate },
|
|
1280
|
+
name: "alint stop gate"
|
|
1281
|
+
});
|
|
1282
|
+
stopGates.push(stopGate);
|
|
1283
|
+
}
|
|
1284
|
+
stopGate[key] = value;
|
|
1285
|
+
}
|
|
1286
|
+
async function writeConfigAtomically(configFile, content) {
|
|
1287
|
+
await mkdir(dirname$1(configFile), { recursive: true });
|
|
1288
|
+
const tempFile = `${configFile}.${randomUUID()}.tmp`;
|
|
1289
|
+
await writeFile(tempFile, content, "utf8");
|
|
1290
|
+
await rename(tempFile, configFile);
|
|
1203
1291
|
}
|
|
1204
1292
|
//#endregion
|
|
1205
1293
|
//#region src/constants/patterns/ignore.ts
|
|
@@ -1719,4 +1807,4 @@ async function writeSetupConfig(filePath, config) {
|
|
|
1719
1807
|
await writeFile(filePath, stringifySetupConfigToml(config), "utf8");
|
|
1720
1808
|
}
|
|
1721
1809
|
//#endregion
|
|
1722
|
-
export { addProviderModels, builtInAgentNames, createDeclarativePlugin, createEmptyPluginLockFile, createReportScope, declarativeFindingResponseSchema, declarativeFindingSchema, declarativeRuleFilePattern, emptySetupConfig, getGlobalSetupConfigPath, getProjectPluginLockPath, getProjectPluginStorePath, getProjectSetupConfigPath, getStatsDir, hasDeclarativeRuleFiles, ignorePatternsAIAgents, ignorePatternsBuildOutputs, ignorePatternsCaches, ignorePatternsCommon, ignorePatternsEslintDefaults, ignorePatternsGenerated, installStaticPlugins, isAcpModel, isBuiltInAgentName, listMissing, listUnresolved, loadAlintConfig, loadDeclarativeRules, loadPluginLockFile, loadSetupConfig, loadStaticConfig, mergeSetupConfigs, modelFromAcpModel, normalizeSetupConfig, parsePluginLockFile, parsePluginSpecifier, parseSetupConfigToml, parseStaticConfig, pruneProviderModels, removeProviderModels, replaceSetupProvider, setProviderEndpoint, setProviderHeader, stringifySetupConfigToml, toAlintConfig, unsetProviderHeader, writePluginLockFile, writeSetupConfig };
|
|
1810
|
+
export { addProviderModels, builtInAgentNames, createDeclarativePlugin, createEmptyPluginLockFile, createReportScope, declarativeFindingResponseSchema, declarativeFindingSchema, declarativeRuleFilePattern, emptySetupConfig, getGlobalSetupConfigPath, getProjectPluginLockPath, getProjectPluginStorePath, getProjectSetupConfigPath, getStatsDir, hasDeclarativeRuleFiles, ignorePatternsAIAgents, ignorePatternsBuildOutputs, ignorePatternsCaches, ignorePatternsCommon, ignorePatternsEslintDefaults, ignorePatternsGenerated, installStaticPlugins, isAcpModel, isBuiltInAgentName, listMissing, listUnresolved, loadAlintConfig, loadAlintConfigWithMetadata, loadDeclarativeRules, loadPluginLockFile, loadSetupConfig, loadStaticConfig, mergeSetupConfigs, modelFromAcpModel, normalizeSetupConfig, parsePluginLockFile, parsePluginSpecifier, parseSetupConfigToml, parseStaticConfig, pruneProviderModels, removeProviderModels, replaceSetupProvider, setProviderEndpoint, setProviderHeader, setStopGateConfig, stringifySetupConfigToml, toAlintConfig, unsetProviderHeader, writePluginLockFile, writeSetupConfig };
|
package/package.json
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alint-js/config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
|
+
"description": "Configuration loading and setup utilities for alint",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/moeru-ai/alint.git",
|
|
10
|
+
"directory": "packages/config"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"alint",
|
|
14
|
+
"lint",
|
|
15
|
+
"configuration",
|
|
16
|
+
"ai"
|
|
17
|
+
],
|
|
5
18
|
"exports": {
|
|
6
19
|
".": {
|
|
7
20
|
"types": "./dist/index.d.mts",
|
|
@@ -28,8 +41,9 @@
|
|
|
28
41
|
"tar-stream": "^3.2.0",
|
|
29
42
|
"valibot": "^1.4.2",
|
|
30
43
|
"xdg-basedir": "^5.1.0",
|
|
31
|
-
"@alint-js/core": "0.
|
|
32
|
-
"@alint-js/tools-fs": "0.
|
|
44
|
+
"@alint-js/core": "0.6.0",
|
|
45
|
+
"@alint-js/tools-fs": "0.6.0",
|
|
46
|
+
"@alint-js/utils": "0.6.0"
|
|
33
47
|
},
|
|
34
48
|
"devDependencies": {
|
|
35
49
|
"@types/tar-stream": "^3.1.4",
|