@intra-mart/accel 0.5.0-dev.202608030656 → 0.5.0-dev.202608180918
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 +103 -32
- package/dist/asset/deployer.d.ts +2 -0
- package/dist/asset/deployer.js +11 -9
- package/dist/asset/git-provider.d.ts +1 -0
- package/dist/asset/git-provider.js +20 -9
- package/dist/asset/updater.d.ts +9 -2
- package/dist/asset/updater.js +12 -6
- package/dist/asset/walker.d.ts +2 -1
- package/dist/asset/walker.js +36 -0
- package/dist/commands/asset-provider.d.ts +1 -1
- package/dist/commands/asset-provider.js +2 -2
- package/dist/commands/attach.d.ts +116 -82
- package/dist/commands/attach.js +176 -145
- package/dist/commands/cache.js +11 -19
- package/dist/commands/deploy.d.ts +53 -32
- package/dist/commands/deploy.js +112 -75
- package/dist/commands/detach.d.ts +18 -0
- package/dist/commands/detach.js +69 -54
- package/dist/commands/init.d.ts +117 -83
- package/dist/commands/init.js +119 -98
- package/dist/commands/login.d.ts +12 -10
- package/dist/commands/login.js +14 -10
- package/dist/commands/preset.d.ts +31 -0
- package/dist/commands/preset.js +389 -0
- package/dist/commands/run-wrapper.d.ts +15 -0
- package/dist/commands/run-wrapper.js +62 -0
- package/dist/commands/switch.d.ts +49 -17
- package/dist/commands/switch.js +206 -122
- package/dist/commands/update.d.ts +142 -83
- package/dist/commands/update.js +359 -261
- package/dist/core/color-env.d.ts +1 -0
- package/dist/core/color-env.js +6 -0
- package/dist/core/constants.d.ts +0 -1
- package/dist/core/constants.js +0 -3
- package/dist/core/errors.d.ts +6 -0
- package/dist/core/errors.js +16 -0
- package/dist/core/logger.d.ts +15 -0
- package/dist/core/logger.js +1 -0
- package/dist/core/paths.d.ts +6 -0
- package/dist/core/paths.js +22 -0
- package/dist/core/types.d.ts +14 -1
- package/dist/core/validation.d.ts +34 -0
- package/dist/core/validation.js +87 -0
- package/dist/core/validators.d.ts +2 -0
- package/dist/core/validators.js +7 -0
- package/dist/deploy/api-client.d.ts +1 -0
- package/dist/deploy/api-client.js +7 -1
- package/dist/git/config-file.d.ts +3 -0
- package/dist/git/config-file.js +178 -0
- package/dist/git/errors.d.ts +5 -0
- package/dist/git/errors.js +21 -2
- package/dist/git/git-objects.d.ts +11 -0
- package/dist/git/git-objects.js +49 -0
- package/dist/git/http.d.ts +2 -2
- package/dist/git/http.js +22 -10
- package/dist/git/index-file.d.ts +17 -0
- package/dist/git/index-file.js +111 -0
- package/dist/git/object-cache.d.ts +1 -0
- package/dist/git/object-cache.js +11 -15
- package/dist/git/object-store.d.ts +4 -0
- package/dist/git/object-store.js +82 -107
- package/dist/git/pack-parse.d.ts +19 -0
- package/dist/git/pack-parse.js +261 -0
- package/dist/git/pack-store.d.ts +20 -0
- package/dist/git/pack-store.js +144 -0
- package/dist/git/read-capped.d.ts +1 -0
- package/dist/git/read-capped.js +26 -0
- package/dist/git/redact-url.d.ts +1 -0
- package/dist/git/redact-url.js +14 -0
- package/dist/git/repo-layout.d.ts +5 -0
- package/dist/git/repo-layout.js +44 -0
- package/dist/git/smart-http.d.ts +3 -2
- package/dist/git/smart-http.js +5 -5
- package/dist/git/untracked.d.ts +11 -0
- package/dist/git/untracked.js +93 -0
- package/dist/git/worktree-status.d.ts +4 -0
- package/dist/git/worktree-status.js +140 -0
- package/dist/git/zlib-inflate.d.ts +7 -0
- package/dist/git/zlib-inflate.js +78 -0
- package/dist/i18n/en.js +47 -0
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/ja.js +47 -0
- package/dist/i18n/zh_CN.js +47 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -2
- package/dist/interactive/asset-messages.d.ts +2 -1
- package/dist/interactive/asset-messages.js +4 -4
- package/dist/interactive/clack-logger.d.ts +2 -0
- package/dist/interactive/clack-logger.js +11 -0
- package/dist/interactive/credential-auth.d.ts +2 -0
- package/dist/interactive/credential-auth.js +7 -6
- package/dist/interactive/credentials-prompts.js +10 -6
- package/dist/interactive/next-steps.d.ts +2 -1
- package/dist/interactive/next-steps.js +3 -3
- package/dist/interactive/progress.d.ts +8 -1
- package/dist/interactive/progress.js +0 -0
- package/dist/interactive/prompts.d.ts +3 -33
- package/dist/interactive/prompts.js +23 -111
- package/dist/interactive/summary.d.ts +2 -1
- package/dist/interactive/summary.js +3 -3
- package/dist/juggling/resolve.d.ts +7 -0
- package/dist/juggling/resolve.js +18 -0
- package/dist/lib.d.ts +34 -0
- package/dist/lib.js +29 -0
- package/dist/utils/args.d.ts +4 -1
- package/dist/utils/args.js +26 -3
- package/dist/utils/githooks-sync.d.ts +3 -1
- package/dist/utils/githooks-sync.js +37 -37
- package/dist/utils/mcp-generate.d.ts +26 -0
- package/dist/utils/mcp-generate.js +313 -0
- package/dist/utils/preset-io.d.ts +24 -0
- package/dist/utils/preset-io.js +167 -0
- package/dist/utils/settings-io.d.ts +2 -0
- package/dist/utils/settings-io.js +2 -2
- package/package.json +20 -13
- package/dist/utils/mcp-sync.d.ts +0 -4
- package/dist/utils/mcp-sync.js +0 -103
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import * as p from "@clack/prompts";
|
|
1
|
+
import { chmod, lstat, mkdir, readdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
3
|
+
import { readConfigValue, writeConfigValue } from "../git/config-file.js";
|
|
4
|
+
import { readTextFileCapped } from "../git/read-capped.js";
|
|
5
|
+
import { resolveRepoLayout } from "../git/repo-layout.js";
|
|
7
6
|
import { createFsAssetTree } from "../asset/asset-tree.js";
|
|
8
7
|
import { walkAssetDir } from "../asset/walker.js";
|
|
9
8
|
import { emptyEvalContext } from "../core/eval-context.js";
|
|
9
|
+
import { getAssetsGithooksRoot } from "../core/paths.js";
|
|
10
10
|
import { getMessage } from "../i18n/index.js";
|
|
11
11
|
import { detectLocale } from "./locale-detect.js";
|
|
12
12
|
import { readSettingsSafe } from "./settings-io.js";
|
|
13
13
|
const MANAGED_MARKER = "@accel-cli-managed";
|
|
14
14
|
const HOOKS_PATH = ".githooks";
|
|
15
15
|
const HOOK_FILE_REL = ".githooks/pre-commit";
|
|
16
|
-
const
|
|
17
|
-
const readFileSafe =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
16
|
+
const MAX_HOOK_FILE_BYTES = 1024 * 1024;
|
|
17
|
+
const readFileSafe = (filePath) => readTextFileCapped(filePath, MAX_HOOK_FILE_BYTES);
|
|
18
|
+
const isInside = (parent, child) => {
|
|
19
|
+
const rel = relative(parent, child);
|
|
20
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
24
21
|
};
|
|
25
22
|
const listForeignFiles = async (hooksDir) => {
|
|
26
23
|
const foreign = [];
|
|
@@ -36,24 +33,29 @@ const listForeignFiles = async (hooksDir) => {
|
|
|
36
33
|
}
|
|
37
34
|
return foreign;
|
|
38
35
|
};
|
|
39
|
-
export const syncGitHooks = async (projectDir) => {
|
|
36
|
+
export const syncGitHooks = async (projectDir, opts) => {
|
|
40
37
|
const settings = await readSettingsSafe(projectDir);
|
|
41
38
|
if (settings?.gitHooks === false)
|
|
42
39
|
return;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
40
|
+
const layout = await resolveRepoLayout(projectDir);
|
|
41
|
+
if (layout === null)
|
|
47
42
|
return;
|
|
48
|
-
|
|
43
|
+
const configPath = join(layout.commonDir, "config");
|
|
49
44
|
const locale = settings?.locale ?? detectLocale();
|
|
50
|
-
const tree = createFsAssetTree(
|
|
45
|
+
const tree = createFsAssetTree(getAssetsGithooksRoot());
|
|
51
46
|
const entries = await walkAssetDir(tree, emptyEvalContext({ locale }));
|
|
52
47
|
for (const entry of entries) {
|
|
53
48
|
const destPath = join(projectDir, entry.relativePath);
|
|
54
|
-
const
|
|
49
|
+
const destStats = await lstat(destPath).catch(() => null);
|
|
50
|
+
if (destStats !== null && !destStats.isFile()) {
|
|
51
|
+
opts.warn(getMessage("warning.gitHooksUserFile", locale, {
|
|
52
|
+
path: entry.relativePath,
|
|
53
|
+
}));
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const existing = destStats === null ? null : await readFileSafe(destPath);
|
|
55
57
|
if (existing !== null && !existing.includes(MANAGED_MARKER)) {
|
|
56
|
-
|
|
58
|
+
opts.warn(getMessage("warning.gitHooksUserFile", locale, {
|
|
57
59
|
path: entry.relativePath,
|
|
58
60
|
}));
|
|
59
61
|
continue;
|
|
@@ -65,27 +67,25 @@ export const syncGitHooks = async (projectDir) => {
|
|
|
65
67
|
await chmod(destPath, 0o755);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const genuineWorktree = isInside(join(layout.commonDir, "worktrees"), layout.gitDir);
|
|
71
|
+
if (!isInside(projectDir, layout.commonDir) && !genuineWorktree) {
|
|
72
|
+
opts.warn(getMessage("warning.gitHooksLayoutSuspicious", locale, {
|
|
73
|
+
path: layout.commonDir,
|
|
74
|
+
}));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const current = await readConfigValue(configPath, "core", "hooksPath");
|
|
78
|
+
if (current === undefined || current === "") {
|
|
74
79
|
const foreign = await listForeignFiles(join(projectDir, HOOKS_PATH));
|
|
75
80
|
if (foreign.length > 0) {
|
|
76
|
-
|
|
81
|
+
opts.warn(getMessage("warning.gitHooksForeignFiles", locale, {
|
|
77
82
|
files: foreign.join(", "),
|
|
78
83
|
}));
|
|
79
84
|
return;
|
|
80
85
|
}
|
|
81
|
-
await
|
|
82
|
-
fs,
|
|
83
|
-
dir: projectDir,
|
|
84
|
-
path: "core.hooksPath",
|
|
85
|
-
value: HOOKS_PATH,
|
|
86
|
-
});
|
|
86
|
+
await writeConfigValue(configPath, "core", "hooksPath", HOOKS_PATH);
|
|
87
87
|
}
|
|
88
88
|
else if (current !== HOOKS_PATH) {
|
|
89
|
-
|
|
89
|
+
opts.warn(getMessage("warning.gitHooksPathConflict", locale, { current }));
|
|
90
90
|
}
|
|
91
91
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AccelCredentials } from "../core/types.js";
|
|
2
|
+
export type McpState = Record<string, string[]>;
|
|
3
|
+
type McpLogSink = {
|
|
4
|
+
info: (msg: string) => void;
|
|
5
|
+
warn: (msg: string) => void;
|
|
6
|
+
};
|
|
7
|
+
export type McpGenerateOpts = {
|
|
8
|
+
info?: (msg: string) => void;
|
|
9
|
+
warn?: (msg: string) => void;
|
|
10
|
+
credentialsConfirmed?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const readMcpState: (projectDir: string) => Promise<McpState>;
|
|
13
|
+
export declare const writeMcpState: (projectDir: string, state: McpState) => Promise<void>;
|
|
14
|
+
export declare const generateMcpConfigs: (projectDir: string, opts?: McpGenerateOpts) => Promise<void>;
|
|
15
|
+
export declare const removeManagedMcpEntries: (projectDir: string, opts?: {
|
|
16
|
+
info?: (msg: string) => void;
|
|
17
|
+
warn?: (msg: string) => void;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
export declare const persistCredentialsAndGenerateMcp: (projectDir: string, creds: AccelCredentials, opts?: {
|
|
20
|
+
info?: (msg: string) => void;
|
|
21
|
+
warn?: (msg: string) => void;
|
|
22
|
+
}) => Promise<void>;
|
|
23
|
+
export declare const generateMcpConfigsBestEffort: (projectDir: string, logger: McpLogSink, impl?: typeof generateMcpConfigs) => Promise<void>;
|
|
24
|
+
export declare const removeManagedMcpEntriesBestEffort: (projectDir: string, logger: McpLogSink, impl?: typeof removeManagedMcpEntries) => Promise<void>;
|
|
25
|
+
export declare const createPersistCredentialsWithMcp: (logger: McpLogSink) => (projectDir: string, creds: AccelCredentials) => Promise<void>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
4
|
+
import { buildEvalContext, emptyEvalContext } from "../core/eval-context.js";
|
|
5
|
+
import { interpolateVariables } from "../core/variable-interpolator.js";
|
|
6
|
+
import { getMessage } from "../i18n/index.js";
|
|
7
|
+
import { persistCredentials, readCredentials } from "./credentials.js";
|
|
8
|
+
import { ensureGitignoreEntry } from "./gitignore.js";
|
|
9
|
+
import { syncGitHooks } from "./githooks-sync.js";
|
|
10
|
+
import { detectLocale } from "./locale-detect.js";
|
|
11
|
+
import { sanitizeDisplayText } from "./sanitize-text.js";
|
|
12
|
+
import { ACCEL_DIR, ensureAccelDir, readSettingsSafe } from "./settings-io.js";
|
|
13
|
+
const MCP_DIR = "mcp";
|
|
14
|
+
const MCP_STATE_FILE = "mcp-state.json";
|
|
15
|
+
const MCP_STATE_GITIGNORE_ENTRY = `${ACCEL_DIR}/${MCP_STATE_FILE}`;
|
|
16
|
+
const OUTPUT_TARGETS = new Map([
|
|
17
|
+
[".mcp.json", { format: "json", containerKey: "mcpServers" }],
|
|
18
|
+
[".vscode/mcp.json", { format: "json", containerKey: "servers" }],
|
|
19
|
+
[".codex/config.toml", { format: "toml", containerKey: "mcp_servers" }],
|
|
20
|
+
]);
|
|
21
|
+
const CREDENTIAL_PLACEHOLDERS = ["{{$endpoint}}", "{{$apiKey}}"];
|
|
22
|
+
const noop = () => { };
|
|
23
|
+
const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
const escapeStringValue = (value) => JSON.stringify(value).slice(1, -1);
|
|
25
|
+
const parseDoc = (format, text) => {
|
|
26
|
+
const doc = format === "json" ? JSON.parse(text) : parseToml(text);
|
|
27
|
+
if (!isPlainObject(doc)) {
|
|
28
|
+
throw new Error("top-level value is not an object");
|
|
29
|
+
}
|
|
30
|
+
return doc;
|
|
31
|
+
};
|
|
32
|
+
const serializeDoc = (format, doc) => {
|
|
33
|
+
if (format === "json")
|
|
34
|
+
return JSON.stringify(doc, null, 2) + "\n";
|
|
35
|
+
const out = stringifyToml(doc);
|
|
36
|
+
return out.endsWith("\n") ? out : out + "\n";
|
|
37
|
+
};
|
|
38
|
+
const resolveOutputFile = (projectDir, outputPath) => join(projectDir, ...outputPath.split("/"));
|
|
39
|
+
export const readMcpState = async (projectDir) => {
|
|
40
|
+
try {
|
|
41
|
+
const raw = await readFile(join(projectDir, ACCEL_DIR, MCP_STATE_FILE), "utf-8");
|
|
42
|
+
const parsed = JSON.parse(raw);
|
|
43
|
+
if (!isPlainObject(parsed))
|
|
44
|
+
return {};
|
|
45
|
+
const state = {};
|
|
46
|
+
for (const [outputPath, names] of Object.entries(parsed)) {
|
|
47
|
+
if (outputPath === "__proto__")
|
|
48
|
+
continue;
|
|
49
|
+
if (!Array.isArray(names))
|
|
50
|
+
continue;
|
|
51
|
+
const valid = names.filter((n) => typeof n === "string");
|
|
52
|
+
if (valid.length > 0)
|
|
53
|
+
state[outputPath] = valid;
|
|
54
|
+
}
|
|
55
|
+
return state;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const writeMcpState = async (projectDir, state) => {
|
|
62
|
+
const accelDir = await ensureAccelDir(projectDir);
|
|
63
|
+
await writeFile(join(accelDir, MCP_STATE_FILE), JSON.stringify(state, null, 2) + "\n", "utf-8");
|
|
64
|
+
await ensureGitignoreEntry(projectDir, MCP_STATE_GITIGNORE_ENTRY);
|
|
65
|
+
};
|
|
66
|
+
const listFragmentTargets = async (projectDir) => {
|
|
67
|
+
const targets = new Map();
|
|
68
|
+
const walk = async (dir, rel) => {
|
|
69
|
+
let dirents;
|
|
70
|
+
try {
|
|
71
|
+
dirents = await readdir(dir, { withFileTypes: true });
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const files = [];
|
|
77
|
+
for (const entry of dirents) {
|
|
78
|
+
if (entry.isDirectory()) {
|
|
79
|
+
await walk(join(dir, entry.name), rel === "" ? entry.name : `${rel}/${entry.name}`);
|
|
80
|
+
}
|
|
81
|
+
else if (entry.isFile()) {
|
|
82
|
+
files.push(entry.name);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (rel !== "" && files.length > 0) {
|
|
86
|
+
targets.set(rel, files.sort());
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
await walk(join(projectDir, ACCEL_DIR, MCP_DIR), "");
|
|
90
|
+
return targets;
|
|
91
|
+
};
|
|
92
|
+
const fileExists = async (path) => {
|
|
93
|
+
try {
|
|
94
|
+
await stat(path);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const resolveProjectLocale = async (projectDir) => {
|
|
102
|
+
const settings = await readSettingsSafe(projectDir);
|
|
103
|
+
return { settings, locale: settings?.locale ?? detectLocale() };
|
|
104
|
+
};
|
|
105
|
+
const readOutputDoc = async (projectDir, outputPath, format, locale, warn) => {
|
|
106
|
+
let raw;
|
|
107
|
+
try {
|
|
108
|
+
raw = await readFile(resolveOutputFile(projectDir, outputPath), "utf-8");
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
raw = null;
|
|
112
|
+
}
|
|
113
|
+
if (raw === null)
|
|
114
|
+
return { raw, doc: {} };
|
|
115
|
+
try {
|
|
116
|
+
return { raw, doc: parseDoc(format, raw) };
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
warn(getMessage("mcp.warning.outputParse", locale, {
|
|
120
|
+
path: sanitizeDisplayText(outputPath),
|
|
121
|
+
}));
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
126
|
+
const info = opts.info ?? noop;
|
|
127
|
+
const warn = opts.warn ?? noop;
|
|
128
|
+
const { settings, locale } = await resolveProjectLocale(projectDir);
|
|
129
|
+
const context = settings
|
|
130
|
+
? buildEvalContext(settings)
|
|
131
|
+
: emptyEvalContext({ locale });
|
|
132
|
+
const creds = await readCredentials(projectDir);
|
|
133
|
+
const extra = new Map();
|
|
134
|
+
if (typeof creds.endpoint === "string" && creds.endpoint.trim() !== "") {
|
|
135
|
+
extra.set("endpoint", escapeStringValue(creds.endpoint));
|
|
136
|
+
}
|
|
137
|
+
if (typeof creds.apiKey === "string" && creds.apiKey.trim() !== "") {
|
|
138
|
+
extra.set("apiKey", escapeStringValue(creds.apiKey));
|
|
139
|
+
}
|
|
140
|
+
const prevState = await readMcpState(projectDir);
|
|
141
|
+
const fragmentTargets = await listFragmentTargets(projectDir);
|
|
142
|
+
const targetPaths = [
|
|
143
|
+
...new Set([...fragmentTargets.keys(), ...Object.keys(prevState)]),
|
|
144
|
+
].sort();
|
|
145
|
+
const nextState = {};
|
|
146
|
+
let deferredTotal = 0;
|
|
147
|
+
for (const outputPath of targetPaths) {
|
|
148
|
+
const target = OUTPUT_TARGETS.get(outputPath);
|
|
149
|
+
if (!target) {
|
|
150
|
+
if (fragmentTargets.has(outputPath)) {
|
|
151
|
+
warn(getMessage("mcp.warning.unknownOutput", locale, {
|
|
152
|
+
path: sanitizeDisplayText(outputPath),
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const entries = new Map();
|
|
158
|
+
for (const name of fragmentTargets.get(outputPath) ?? []) {
|
|
159
|
+
const fragRel = `${ACCEL_DIR}/${MCP_DIR}/${outputPath}/${name}`;
|
|
160
|
+
let raw;
|
|
161
|
+
try {
|
|
162
|
+
raw = await readFile(join(projectDir, ...fragRel.split("/")), "utf-8");
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
warn(getMessage("mcp.warning.fragmentParse", locale, {
|
|
166
|
+
path: sanitizeDisplayText(fragRel),
|
|
167
|
+
}));
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const expanded = interpolateVariables(raw, context, extra);
|
|
171
|
+
let doc;
|
|
172
|
+
try {
|
|
173
|
+
doc = parseDoc(target.format, expanded);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
warn(getMessage("mcp.warning.fragmentParse", locale, {
|
|
177
|
+
path: sanitizeDisplayText(fragRel),
|
|
178
|
+
}));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const container = doc[target.containerKey];
|
|
182
|
+
if (!isPlainObject(container))
|
|
183
|
+
continue;
|
|
184
|
+
for (const [serverName, value] of Object.entries(container)) {
|
|
185
|
+
entries.set(serverName, value);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const deferred = [];
|
|
189
|
+
for (const [serverName, value] of [...entries]) {
|
|
190
|
+
const text = JSON.stringify(value) ?? "";
|
|
191
|
+
if (CREDENTIAL_PLACEHOLDERS.some((p) => text.includes(p))) {
|
|
192
|
+
deferred.push(serverName);
|
|
193
|
+
entries.delete(serverName);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
deferredTotal += deferred.length;
|
|
197
|
+
if (opts.credentialsConfirmed && deferred.length > 0) {
|
|
198
|
+
warn(getMessage("mcp.warning.credentialEntryExcluded", locale, {
|
|
199
|
+
path: sanitizeDisplayText(outputPath),
|
|
200
|
+
names: sanitizeDisplayText(deferred.join(", ")),
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
const existing = await readOutputDoc(projectDir, outputPath, target.format, locale, warn);
|
|
204
|
+
if (existing === null) {
|
|
205
|
+
const prev = prevState[outputPath];
|
|
206
|
+
if (prev && prev.length > 0)
|
|
207
|
+
nextState[outputPath] = prev;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const { raw: existingRaw, doc } = existing;
|
|
211
|
+
const deferredSet = new Set(deferred);
|
|
212
|
+
const removeNames = [
|
|
213
|
+
...new Set([...(prevState[outputPath] ?? []), ...entries.keys()]),
|
|
214
|
+
].filter((n) => !deferredSet.has(n));
|
|
215
|
+
const existingContainer = doc[target.containerKey];
|
|
216
|
+
const container = isPlainObject(existingContainer) ? existingContainer : {};
|
|
217
|
+
const removedCount = removeNames.filter((n) => Object.hasOwn(container, n)).length;
|
|
218
|
+
if (entries.size > 0 || removedCount > 0) {
|
|
219
|
+
for (const n of removeNames)
|
|
220
|
+
delete container[n];
|
|
221
|
+
for (const [n, v] of entries)
|
|
222
|
+
container[n] = v;
|
|
223
|
+
doc[target.containerKey] = container;
|
|
224
|
+
const out = serializeDoc(target.format, doc);
|
|
225
|
+
if (out !== existingRaw) {
|
|
226
|
+
const outFile = resolveOutputFile(projectDir, outputPath);
|
|
227
|
+
await mkdir(dirname(outFile), { recursive: true });
|
|
228
|
+
await writeFile(outFile, out, "utf-8");
|
|
229
|
+
info(getMessage("mcp.generated", locale, {
|
|
230
|
+
path: sanitizeDisplayText(outputPath),
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const managed = [...new Set([...entries.keys(), ...deferred])].sort();
|
|
235
|
+
if (managed.length > 0)
|
|
236
|
+
nextState[outputPath] = managed;
|
|
237
|
+
}
|
|
238
|
+
if (deferredTotal > 0 && !opts.credentialsConfirmed) {
|
|
239
|
+
info(getMessage("mcp.hint.loginRequired", locale));
|
|
240
|
+
}
|
|
241
|
+
const statePath = join(projectDir, ACCEL_DIR, MCP_STATE_FILE);
|
|
242
|
+
if (Object.keys(nextState).length > 0 || (await fileExists(statePath))) {
|
|
243
|
+
await writeMcpState(projectDir, nextState);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
export const removeManagedMcpEntries = async (projectDir, opts = {}) => {
|
|
247
|
+
const info = opts.info ?? noop;
|
|
248
|
+
const warn = opts.warn ?? noop;
|
|
249
|
+
const { locale } = await resolveProjectLocale(projectDir);
|
|
250
|
+
const state = await readMcpState(projectDir);
|
|
251
|
+
for (const [outputPath, names] of Object.entries(state)) {
|
|
252
|
+
const target = OUTPUT_TARGETS.get(outputPath);
|
|
253
|
+
if (!target)
|
|
254
|
+
continue;
|
|
255
|
+
const existing = await readOutputDoc(projectDir, outputPath, target.format, locale, warn);
|
|
256
|
+
if (existing === null || existing.raw === null)
|
|
257
|
+
continue;
|
|
258
|
+
const { doc } = existing;
|
|
259
|
+
const container = doc[target.containerKey];
|
|
260
|
+
if (!isPlainObject(container))
|
|
261
|
+
continue;
|
|
262
|
+
const removed = names.filter((n) => Object.hasOwn(container, n));
|
|
263
|
+
if (removed.length === 0)
|
|
264
|
+
continue;
|
|
265
|
+
for (const n of removed)
|
|
266
|
+
delete container[n];
|
|
267
|
+
await writeFile(resolveOutputFile(projectDir, outputPath), serializeDoc(target.format, doc), "utf-8");
|
|
268
|
+
info(getMessage("mcp.detach.removed", locale, {
|
|
269
|
+
path: sanitizeDisplayText(outputPath),
|
|
270
|
+
count: String(removed.length),
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
export const persistCredentialsAndGenerateMcp = async (projectDir, creds, opts = {}) => {
|
|
275
|
+
await persistCredentials(projectDir, creds);
|
|
276
|
+
try {
|
|
277
|
+
await generateMcpConfigs(projectDir, {
|
|
278
|
+
...opts,
|
|
279
|
+
credentialsConfirmed: true,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
await syncGitHooks(projectDir, { warn: opts.warn ?? noop });
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
export const generateMcpConfigsBestEffort = async (projectDir, logger, impl = generateMcpConfigs) => {
|
|
291
|
+
try {
|
|
292
|
+
await impl(projectDir, {
|
|
293
|
+
info: (msg) => logger.info(msg),
|
|
294
|
+
warn: (msg) => logger.warn(msg),
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
export const removeManagedMcpEntriesBestEffort = async (projectDir, logger, impl = removeManagedMcpEntries) => {
|
|
301
|
+
try {
|
|
302
|
+
await impl(projectDir, {
|
|
303
|
+
info: (msg) => logger.info(msg),
|
|
304
|
+
warn: (msg) => logger.warn(msg),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
export const createPersistCredentialsWithMcp = (logger) => (projectDir, creds) => persistCredentialsAndGenerateMcp(projectDir, creds, {
|
|
311
|
+
info: (msg) => logger.info(msg),
|
|
312
|
+
warn: (msg) => logger.warn(msg),
|
|
313
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AccelPreset } from "../core/types.js";
|
|
2
|
+
import { type Release } from "../core/catalog.js";
|
|
3
|
+
export declare const presetsDir: (projectDir: string) => string;
|
|
4
|
+
export declare const presetPath: (projectDir: string, name: string) => string;
|
|
5
|
+
export declare const writePreset: (projectDir: string, preset: AccelPreset) => Promise<void>;
|
|
6
|
+
export declare const presetExists: (projectDir: string, name: string) => Promise<boolean>;
|
|
7
|
+
export declare const deletePreset: (projectDir: string, name: string) => Promise<void>;
|
|
8
|
+
export type PresetSummary = {
|
|
9
|
+
name: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const listPresetSummaries: (projectDir: string) => Promise<PresetSummary[]>;
|
|
14
|
+
export declare const formatPresetDisplayName: (summary: PresetSummary) => string;
|
|
15
|
+
export declare const buildPresetSelectOptions: (presets: PresetSummary[], locale: string) => Array<{
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
hint?: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const parsePresetChoice: (choice: string) => string | undefined;
|
|
21
|
+
export declare const validatePresetSchema: (raw: unknown, expectedName: string, locale: string) => string[];
|
|
22
|
+
export declare const collectPresetCatalogErrors: (preset: AccelPreset, release: Release, locale: string) => string[];
|
|
23
|
+
export declare const readPreset: (projectDir: string, name: string, locale: string) => Promise<AccelPreset>;
|
|
24
|
+
export declare const loadAndValidatePreset: (projectDir: string, name: string, releaseId: string, locale: string) => Promise<AccelPreset>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir, readdir, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { PRESET_NAME_PATTERN, createPresetNameValidator, createReleaseValidators, createValidators, } from "../core/validators.js";
|
|
4
|
+
import { findReleaseById } from "../core/catalog.js";
|
|
5
|
+
import { getMessage } from "../i18n/index.js";
|
|
6
|
+
import { ACCEL_DIR } from "./settings-io.js";
|
|
7
|
+
import { sanitizeDisplayText } from "./sanitize-text.js";
|
|
8
|
+
import { mapWithConcurrency, FS_CONCURRENCY } from "./concurrency.js";
|
|
9
|
+
const PRESETS_DIR = "presets";
|
|
10
|
+
const PRESET_EXT = ".json";
|
|
11
|
+
export const presetsDir = (projectDir) => join(projectDir, ACCEL_DIR, PRESETS_DIR);
|
|
12
|
+
export const presetPath = (projectDir, name) => {
|
|
13
|
+
if (!PRESET_NAME_PATTERN.test(name)) {
|
|
14
|
+
throw new Error(`Invalid preset name: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
return join(presetsDir(projectDir), `${name}${PRESET_EXT}`);
|
|
17
|
+
};
|
|
18
|
+
export const writePreset = async (projectDir, preset) => {
|
|
19
|
+
const filePath = presetPath(projectDir, preset.name);
|
|
20
|
+
await mkdir(presetsDir(projectDir), { recursive: true });
|
|
21
|
+
await writeFile(filePath, JSON.stringify(preset, null, 2) + "\n", "utf-8");
|
|
22
|
+
};
|
|
23
|
+
export const presetExists = async (projectDir, name) => {
|
|
24
|
+
try {
|
|
25
|
+
await stat(presetPath(projectDir, name));
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const deletePreset = async (projectDir, name) => {
|
|
33
|
+
await rm(presetPath(projectDir, name));
|
|
34
|
+
};
|
|
35
|
+
export const listPresetSummaries = async (projectDir) => {
|
|
36
|
+
let entries;
|
|
37
|
+
try {
|
|
38
|
+
entries = await readdir(presetsDir(projectDir));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const names = entries
|
|
44
|
+
.filter((f) => f.endsWith(PRESET_EXT))
|
|
45
|
+
.map((f) => f.slice(0, -PRESET_EXT.length))
|
|
46
|
+
.filter((n) => PRESET_NAME_PATTERN.test(n))
|
|
47
|
+
.sort((a, b) => a.localeCompare(b));
|
|
48
|
+
return mapWithConcurrency(names, FS_CONCURRENCY, async (name) => {
|
|
49
|
+
const summary = { name };
|
|
50
|
+
try {
|
|
51
|
+
const raw = JSON.parse(await readFile(presetPath(projectDir, name), "utf-8"));
|
|
52
|
+
if (typeof raw.label === "string" && raw.label.length > 0) {
|
|
53
|
+
summary.label = raw.label;
|
|
54
|
+
}
|
|
55
|
+
if (typeof raw.description === "string" && raw.description.length > 0) {
|
|
56
|
+
summary.description = raw.description;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
}
|
|
61
|
+
return summary;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const formatPresetDisplayName = (summary) => summary.label
|
|
65
|
+
? `${sanitizeDisplayText(summary.label)} (${summary.name})`
|
|
66
|
+
: summary.name;
|
|
67
|
+
const PRESET_CHOICE_PREFIX = "preset:";
|
|
68
|
+
export const buildPresetSelectOptions = (presets, locale) => presets.map((summary) => ({
|
|
69
|
+
value: `${PRESET_CHOICE_PREFIX}${summary.name}`,
|
|
70
|
+
label: getMessage("preset.prompt.select.usePreset", locale, {
|
|
71
|
+
name: formatPresetDisplayName(summary),
|
|
72
|
+
}),
|
|
73
|
+
...(summary.description
|
|
74
|
+
? { hint: sanitizeDisplayText(summary.description) }
|
|
75
|
+
: {}),
|
|
76
|
+
}));
|
|
77
|
+
export const parsePresetChoice = (choice) => choice.startsWith(PRESET_CHOICE_PREFIX)
|
|
78
|
+
? choice.slice(PRESET_CHOICE_PREFIX.length)
|
|
79
|
+
: undefined;
|
|
80
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
81
|
+
export const validatePresetSchema = (raw, expectedName, locale) => {
|
|
82
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
83
|
+
return [
|
|
84
|
+
getMessage("preset.error.parse", locale, { message: "not an object" }),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
const obj = raw;
|
|
88
|
+
const errors = [];
|
|
89
|
+
for (const field of ["modules", "features", "agents"]) {
|
|
90
|
+
if (!isStringArray(obj[field])) {
|
|
91
|
+
errors.push(getMessage("preset.error.field", locale, { field }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (obj.name !== expectedName) {
|
|
95
|
+
errors.push(getMessage("preset.error.nameMismatch", locale, {
|
|
96
|
+
value: sanitizeDisplayText(typeof obj.name === "string" ? obj.name : String(obj.name)),
|
|
97
|
+
name: expectedName,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return errors;
|
|
101
|
+
};
|
|
102
|
+
export const collectPresetCatalogErrors = (preset, release, locale) => {
|
|
103
|
+
const releaseValidators = createReleaseValidators(locale, release);
|
|
104
|
+
const agentValidator = createValidators(locale).agent;
|
|
105
|
+
const errors = [];
|
|
106
|
+
for (const module of preset.modules) {
|
|
107
|
+
const error = releaseValidators.module(module);
|
|
108
|
+
if (error)
|
|
109
|
+
errors.push(error);
|
|
110
|
+
}
|
|
111
|
+
for (const feature of preset.features) {
|
|
112
|
+
const error = releaseValidators.feature(feature);
|
|
113
|
+
if (error)
|
|
114
|
+
errors.push(error);
|
|
115
|
+
}
|
|
116
|
+
for (const agent of preset.agents) {
|
|
117
|
+
const error = agentValidator(agent);
|
|
118
|
+
if (error)
|
|
119
|
+
errors.push(error);
|
|
120
|
+
}
|
|
121
|
+
return errors.map((error) => sanitizeDisplayText(error));
|
|
122
|
+
};
|
|
123
|
+
const invalidPresetError = (name, errors, locale) => new Error(getMessage("preset.error.invalid", locale, {
|
|
124
|
+
name,
|
|
125
|
+
errors: errors.map((e) => ` - ${e}`).join("\n"),
|
|
126
|
+
}));
|
|
127
|
+
export const readPreset = async (projectDir, name, locale) => {
|
|
128
|
+
const nameError = createPresetNameValidator(locale)(name);
|
|
129
|
+
if (nameError) {
|
|
130
|
+
throw new Error(nameError);
|
|
131
|
+
}
|
|
132
|
+
let content;
|
|
133
|
+
try {
|
|
134
|
+
content = await readFile(presetPath(projectDir, name), "utf-8");
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
throw new Error(getMessage("preset.error.notFound", locale, { name }));
|
|
138
|
+
}
|
|
139
|
+
let raw;
|
|
140
|
+
try {
|
|
141
|
+
raw = JSON.parse(content);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
throw invalidPresetError(name, [
|
|
145
|
+
getMessage("preset.error.parse", locale, {
|
|
146
|
+
message: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
|
|
147
|
+
}),
|
|
148
|
+
], locale);
|
|
149
|
+
}
|
|
150
|
+
const schemaErrors = validatePresetSchema(raw, name, locale);
|
|
151
|
+
if (schemaErrors.length > 0) {
|
|
152
|
+
throw invalidPresetError(name, schemaErrors, locale);
|
|
153
|
+
}
|
|
154
|
+
return raw;
|
|
155
|
+
};
|
|
156
|
+
export const loadAndValidatePreset = async (projectDir, name, releaseId, locale) => {
|
|
157
|
+
const preset = await readPreset(projectDir, name, locale);
|
|
158
|
+
const release = findReleaseById(releaseId);
|
|
159
|
+
if (!release) {
|
|
160
|
+
throw new Error(getMessage("error.invalidVersion", locale, { version: releaseId }));
|
|
161
|
+
}
|
|
162
|
+
const catalogErrors = collectPresetCatalogErrors(preset, release, locale);
|
|
163
|
+
if (catalogErrors.length > 0) {
|
|
164
|
+
throw invalidPresetError(name, catalogErrors, locale);
|
|
165
|
+
}
|
|
166
|
+
return preset;
|
|
167
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { AccelSettings, HashsumEntry } from "../core/types.js";
|
|
2
|
+
export declare const ACCEL_DIR = ".accel";
|
|
3
|
+
export declare const ensureAccelDir: (projectDir: string) => Promise<string>;
|
|
2
4
|
export declare const writeSettings: (projectDir: string, settings: AccelSettings) => Promise<void>;
|
|
3
5
|
export declare const readSettings: (projectDir: string) => Promise<AccelSettings>;
|
|
4
6
|
export declare const readSettingsSafe: (projectDir: string) => Promise<AccelSettings | null>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { isSafeRelPath } from "./safe-rel-path.js";
|
|
4
|
-
const ACCEL_DIR = ".accel";
|
|
4
|
+
export const ACCEL_DIR = ".accel";
|
|
5
5
|
const SETTINGS_FILE = "settings.json";
|
|
6
6
|
const HASHSUM_FILE = "hashsum.txt";
|
|
7
|
-
const ensureAccelDir = async (projectDir) => {
|
|
7
|
+
export const ensureAccelDir = async (projectDir) => {
|
|
8
8
|
const accelDir = join(projectDir, ACCEL_DIR);
|
|
9
9
|
await mkdir(accelDir, { recursive: true });
|
|
10
10
|
return accelDir;
|