@venizia/vulcan 0.3.4 → 0.3.6
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 +2 -2
- package/base/agents.json +232 -0
- package/base/claude/settings.json +12 -0
- package/base/hooks/guard-package.ts +29 -0
- package/base/rules.md +2 -0
- package/base/templates/AGENTS.md +4 -3
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +54 -0
- package/src/agents/common/constants.ts +38 -0
- package/src/agents/common/index.ts +3 -0
- package/src/agents/common/schema.ts +42 -0
- package/src/agents/common/types.ts +30 -0
- package/src/agents/detect.ts +36 -0
- package/src/agents/exclude.ts +87 -0
- package/src/agents/index.ts +9 -0
- package/src/agents/local.ts +65 -0
- package/src/agents/prompt.ts +22 -0
- package/src/agents/render.ts +229 -0
- package/src/agents/resolve.ts +145 -0
- package/src/agents/table.ts +35 -0
- package/src/commands/agents.command.ts +154 -0
- package/src/commands/doctor.command.ts +5 -1
- package/src/commands/help.command.ts +5 -1
- package/src/commands/index.ts +2 -0
- package/src/commands/sync.command.ts +112 -3
- package/src/common/constants.ts +9 -1
- package/src/config/common/constants.ts +12 -1
- package/src/config/packages.ts +2 -0
- package/src/config/schema.ts +16 -1
- package/src/create/add-app.ts +110 -4
- package/src/create/add-lib.ts +317 -0
- package/src/create/common/constants.ts +3 -0
- package/src/create/common/types.ts +18 -2
- package/src/create/dockerignore.ts +36 -0
- package/src/create/init-monorepo.ts +22 -4
- package/src/create/lib-preset.ts +154 -0
- package/src/create/preset.ts +22 -3
- package/src/create/workspace.ts +94 -3
- package/src/doctor/checks.ts +183 -12
- package/src/doctor/common/constants.ts +26 -0
- package/src/doctor/runner.ts +22 -0
- package/src/hooks/guard-package.ts +211 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/session-digest.ts +27 -1
- package/src/init/scaffold.ts +8 -5
- package/src/manifest/render.ts +4 -0
- package/src/router.ts +10 -1
- package/src/sync/agent-files.ts +112 -0
- package/src/sync/agent-removal.ts +241 -0
- package/src/sync/atlas-block.ts +55 -0
- package/src/sync/common/constants.ts +2 -0
- package/src/sync/exclude.ts +89 -0
- package/src/sync/index.ts +5 -0
- package/src/sync/local-choice.ts +55 -0
- package/src/sync/planner.ts +55 -19
- package/src/sync/settings.ts +26 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
3
|
import { BASE_DIRECTORY, ProjectLayout } from '../common/index.ts';
|
|
4
4
|
import { ConfigConstants, loadConfig } from '../config/index.ts';
|
|
5
5
|
import { extractRuleRows, parseRuleIds, readSlots, RuleConstants } from '../rules/index.ts';
|
|
@@ -22,6 +22,25 @@ const selectRows = (opts: { rows: string[]; ids: string[] }): string[] =>
|
|
|
22
22
|
const readText = (opts: { file: string }): string =>
|
|
23
23
|
existsSync(opts.file) ? readFileSync(opts.file, 'utf8') : '';
|
|
24
24
|
|
|
25
|
+
/** The Atlas block: only for a project whose `.mcp.json` runs the atlas server. */
|
|
26
|
+
const buildAtlasBlock = (opts: {
|
|
27
|
+
projectRoot: string;
|
|
28
|
+
project: string;
|
|
29
|
+
sources: string[];
|
|
30
|
+
}): string[] => {
|
|
31
|
+
if (!/\batlas\b/.test(readText({ file: join(opts.projectRoot, '.mcp.json') }))) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return [
|
|
36
|
+
'## Atlas',
|
|
37
|
+
'',
|
|
38
|
+
`The \`atlas\` MCP server holds the real code and docs of: ${[`${opts.project} (this repository)`, ...opts.sources].join(', ')}.`,
|
|
39
|
+
'Look facts up there before you answer or write from memory: `symbol` for an export you import, `search` for how something works, `version` or `changes` for a release (V-P-07).',
|
|
40
|
+
'',
|
|
41
|
+
];
|
|
42
|
+
};
|
|
43
|
+
|
|
25
44
|
/** The SessionStart context: base write boundaries, this project's slot choices and own rules, the often-dropped rules. */
|
|
26
45
|
export const buildSessionDigest = async (opts: { projectRoot: string }): Promise<string> => {
|
|
27
46
|
const baseRows = extractRuleRows({
|
|
@@ -53,6 +72,13 @@ export const buildSessionDigest = async (opts: { projectRoot: string }): Promise
|
|
|
53
72
|
'',
|
|
54
73
|
'Base rules: `node_modules/@venizia/vulcan/base/rules.md`. This project: `.agents/rules.md`.',
|
|
55
74
|
'',
|
|
75
|
+
...buildAtlasBlock({
|
|
76
|
+
projectRoot: opts.projectRoot,
|
|
77
|
+
project: loaded.ok
|
|
78
|
+
? (loaded.config.name ?? basename(opts.projectRoot))
|
|
79
|
+
: basename(opts.projectRoot),
|
|
80
|
+
sources: loaded.ok ? loaded.config.atlas.sources.map(source => source.name) : [],
|
|
81
|
+
}),
|
|
56
82
|
'## Write boundaries',
|
|
57
83
|
'',
|
|
58
84
|
...TABLE_HEADER,
|
package/src/init/scaffold.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { BASE_DIRECTORY, ProjectLayout, readProperty } from '../common/index.ts'
|
|
|
4
4
|
import { ConfigConstants, findConfigFiles } from '../config/index.ts';
|
|
5
5
|
import type { TConfigExtension } from '../config/index.ts';
|
|
6
6
|
import { InitConstants, InitStatuses } from './common/index.ts';
|
|
7
|
+
import { renderDockerignore } from '../create/dockerignore.ts';
|
|
7
8
|
import type { IInitEntry, IScaffoldFile } from './common/index.ts';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Whether a `.mcp.json` already serves atlas: a server named `atlas`, or any server whose arguments run
|
|
11
12
|
* `atlas mcp` under another name, as separate arguments or inside a `sh -c` string. A file that is not JSON falls back to looking for the name.
|
|
12
13
|
*/
|
|
13
|
-
const runsAtlas = (opts: { text: string }): boolean => {
|
|
14
|
+
export const runsAtlas = (opts: { text: string }): boolean => {
|
|
14
15
|
try {
|
|
15
16
|
const parsed: { mcpServers?: Record<string, { args?: unknown }> } = JSON.parse(opts.text);
|
|
16
17
|
const servers = parsed.mcpServers ?? {};
|
|
@@ -45,9 +46,9 @@ const SCAFFOLD_FILES: IScaffoldFile[] = [
|
|
|
45
46
|
|
|
46
47
|
/** The lint configs of a single-package project. A workspaces project keeps them in each app. */
|
|
47
48
|
const LINT_CONFIG_FILES: IScaffoldFile[] = [
|
|
48
|
-
{ path: '.configs/oxlint.config.mts', template: 'oxlint.config.mts' },
|
|
49
|
-
{ path: '.configs/eslint.config.mjs', template: 'eslint.config.mjs' },
|
|
50
|
-
{ path: '.configs/oxfmt.config.mts', template: 'oxfmt.config.mts' },
|
|
49
|
+
{ path: '.configs/lints/oxlint.config.mts', template: 'oxlint.config.mts' },
|
|
50
|
+
{ path: '.configs/lints/eslint.config.mjs', template: 'eslint.config.mjs' },
|
|
51
|
+
{ path: '.configs/formatters/oxfmt.config.mts', template: 'oxfmt.config.mts' },
|
|
51
52
|
];
|
|
52
53
|
|
|
53
54
|
export interface IScaffoldResult {
|
|
@@ -163,7 +164,7 @@ export const scaffoldProject = (opts: {
|
|
|
163
164
|
if (isWorkspaces) {
|
|
164
165
|
entries.push({
|
|
165
166
|
status: InitStatuses.SKIPPED,
|
|
166
|
-
subject: `.configs/{
|
|
167
|
+
subject: `.configs/{lints,formatters}: a workspaces project keeps them per app (apps/<name>/.configs/lints/, apps/<name>/.configs/formatters/); the templates are in node_modules/@venizia/vulcan/base/templates/`,
|
|
167
168
|
});
|
|
168
169
|
}
|
|
169
170
|
|
|
@@ -188,6 +189,8 @@ export const scaffoldProject = (opts: {
|
|
|
188
189
|
);
|
|
189
190
|
}
|
|
190
191
|
|
|
192
|
+
entries.push(writeIfAbsent({ root, path: '.dockerignore', content: renderDockerignore() }));
|
|
193
|
+
|
|
191
194
|
const makefile = join(root, 'Makefile');
|
|
192
195
|
|
|
193
196
|
if (!existsSync(makefile)) {
|
package/src/manifest/render.ts
CHANGED
|
@@ -63,7 +63,11 @@ export const renderManifest = (opts: { root: string; config: TResolvedConfig }):
|
|
|
63
63
|
path: entry.path,
|
|
64
64
|
aliases: entry.aliases,
|
|
65
65
|
retired: entry.retired,
|
|
66
|
+
...(entry.kind === undefined ? {} : { kind: entry.kind }),
|
|
66
67
|
})),
|
|
68
|
+
// Where each kind of app goes and the presets that make one: what an agent asked for a new app needs.
|
|
69
|
+
...(config.layout === undefined ? {} : { layout: config.layout }),
|
|
70
|
+
...(config.presets === undefined ? {} : { presets: config.presets }),
|
|
67
71
|
knowledge: {
|
|
68
72
|
bundle: config.knowledge.bundle,
|
|
69
73
|
...(wiki === undefined ? {} : { wiki }),
|
package/src/router.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AgentConstants } from './agents/index.ts';
|
|
1
2
|
import { COMMAND_HANDLERS } from './commands/index.ts';
|
|
2
3
|
import { runHelpCommand } from './commands/help.command.ts';
|
|
3
4
|
import { ExitCodes, UpgradeFlags, VulcanCommands } from './common/index.ts';
|
|
@@ -37,10 +38,18 @@ const ACCEPTED_ARGS: Record<string, IAcceptedArgs> = {
|
|
|
37
38
|
CreateFlags.FRONTEND_DIR,
|
|
38
39
|
CreateFlags.APP,
|
|
39
40
|
CreateFlags.API,
|
|
41
|
+
CreateFlags.LIB,
|
|
42
|
+
CreateFlags.DIR,
|
|
43
|
+
CreateFlags.SCOPE,
|
|
40
44
|
],
|
|
41
45
|
positionals: 0,
|
|
42
46
|
},
|
|
43
|
-
[VulcanCommands.SYNC]: {
|
|
47
|
+
[VulcanCommands.SYNC]: {
|
|
48
|
+
flags: ['--dry-run', '--prune'],
|
|
49
|
+
values: [AgentConstants.FLAG],
|
|
50
|
+
positionals: 0,
|
|
51
|
+
},
|
|
52
|
+
[VulcanCommands.AGENTS]: { flags: ['--dry-run'], values: [], positionals: 2 },
|
|
44
53
|
[VulcanCommands.DOCTOR]: { flags: [], values: [], positionals: 0 },
|
|
45
54
|
[VulcanCommands.UPGRADE]: {
|
|
46
55
|
flags: [UpgradeFlags.STABLE, UpgradeFlags.NIGHTLY],
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import {
|
|
4
|
+
AgentRenderers,
|
|
5
|
+
AgentScopes,
|
|
6
|
+
atlasServerEntry,
|
|
7
|
+
mergeCodexToml,
|
|
8
|
+
mergeMcpServers,
|
|
9
|
+
readAgentTable,
|
|
10
|
+
} from '../agents/index.ts';
|
|
11
|
+
import type { TAgentEntry } from '../agents/index.ts';
|
|
12
|
+
import { SyncStatuses } from './common/index.ts';
|
|
13
|
+
import type { ISyncAction } from './common/index.ts';
|
|
14
|
+
|
|
15
|
+
const NO_CHANGE = (): void => {};
|
|
16
|
+
|
|
17
|
+
/** A file git tracks cannot be hidden by an exclude entry, and a per-developer edit would show as a diff. */
|
|
18
|
+
const isTracked = (opts: { root: string; path: string }): boolean => {
|
|
19
|
+
try {
|
|
20
|
+
return (
|
|
21
|
+
Bun.spawnSync(['git', 'ls-files', '--error-unmatch', opts.path], {
|
|
22
|
+
cwd: opts.root,
|
|
23
|
+
stdout: 'ignore',
|
|
24
|
+
stderr: 'ignore',
|
|
25
|
+
}).exitCode === 0
|
|
26
|
+
);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const merge = (opts: { entry: TAgentEntry; root: string; text: string | undefined }) => {
|
|
33
|
+
const server = atlasServerEntry({ root: opts.root });
|
|
34
|
+
|
|
35
|
+
switch (opts.entry.mcp.renderer) {
|
|
36
|
+
case AgentRenderers.CODEX_TOML: {
|
|
37
|
+
return mergeCodexToml({ text: opts.text, root: opts.root });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
case AgentRenderers.SERVERS: {
|
|
41
|
+
return mergeMcpServers({
|
|
42
|
+
text: opts.text,
|
|
43
|
+
key: 'servers',
|
|
44
|
+
entry: { type: 'stdio', ...server },
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
default: {
|
|
49
|
+
return mergeMcpServers({ text: opts.text, key: 'mcpServers', entry: server });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** The atlas entry in the agent's own MCP file; an agent on the shared `.mcp.json` needs no file. */
|
|
55
|
+
const planAgentMcp = (opts: { root: string; entry: TAgentEntry }): ISyncAction[] => {
|
|
56
|
+
if (opts.entry.mcp.scope !== AgentScopes.PROJECT) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const path = join(opts.root, opts.entry.mcp.path);
|
|
61
|
+
const text = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
|
|
62
|
+
const merged = merge({ entry: opts.entry, root: opts.root, text });
|
|
63
|
+
|
|
64
|
+
if (!merged.ok) {
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
path,
|
|
68
|
+
status: SyncStatuses.SKIPPED,
|
|
69
|
+
note: `${merged.reason} - left untouched; fix it, then re-run sync`,
|
|
70
|
+
apply: NO_CHANGE,
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!merged.changed) {
|
|
76
|
+
return [{ path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE }];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (text !== undefined && isTracked({ root: opts.root, path: opts.entry.mcp.path })) {
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
path,
|
|
83
|
+
status: SyncStatuses.SKIPPED,
|
|
84
|
+
note: `tracked by git - left alone; add the atlas server by hand: bun ${join(opts.root, 'node_modules', '.bin', 'vulcan')} x atlas mcp --root ${opts.root}`,
|
|
85
|
+
apply: NO_CHANGE,
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
path,
|
|
93
|
+
status: text === undefined ? SyncStatuses.CREATED : SyncStatuses.REPLACED,
|
|
94
|
+
apply: () => {
|
|
95
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
96
|
+
writeFileSync(path, merged.text);
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** The MCP files of every chosen agent, in table order. */
|
|
103
|
+
export const planAgentFiles = (opts: { root: string; agents: string[] }): ISyncAction[] =>
|
|
104
|
+
readAgentTable()
|
|
105
|
+
.filter(entry => opts.agents.includes(entry.id))
|
|
106
|
+
.flatMap(entry => planAgentMcp({ root: opts.root, entry }));
|
|
107
|
+
|
|
108
|
+
/** One line per note of a chosen agent (a trust prompt only the user can answer). */
|
|
109
|
+
export const agentNotes = (opts: { agents: string[] }): { agent: string; note: string }[] =>
|
|
110
|
+
readAgentTable()
|
|
111
|
+
.filter(entry => opts.agents.includes(entry.id))
|
|
112
|
+
.flatMap(entry => entry.notes.map(note => ({ agent: entry.id, note })));
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
lstatSync,
|
|
4
|
+
readdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
readlinkSync,
|
|
7
|
+
rmdirSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
import {
|
|
13
|
+
AgentConstants,
|
|
14
|
+
AgentRenderers,
|
|
15
|
+
AgentScopes,
|
|
16
|
+
readAgentTable,
|
|
17
|
+
removeCodexBlock,
|
|
18
|
+
removeMcpEntry,
|
|
19
|
+
} from '../agents/index.ts';
|
|
20
|
+
import type { TAgentEntry } from '../agents/index.ts';
|
|
21
|
+
import { BASE_DIRECTORY, stableBaseDirectoryOf } from '../common/index.ts';
|
|
22
|
+
import { SyncConstants, SyncStatuses } from './common/index.ts';
|
|
23
|
+
import type { ISyncAction, TSettings } from './common/index.ts';
|
|
24
|
+
import { isSettingsObject, removeManagedSettings } from './settings.ts';
|
|
25
|
+
|
|
26
|
+
const NO_CHANGE = (): void => {};
|
|
27
|
+
const CLAUDE_SKILLS = join(SyncConstants.CLAUDE_DIRECTORY, SyncConstants.SKILLS_DIRECTORY);
|
|
28
|
+
/** Parents sync may delete once empty: its own agent folders, never `.agents` or the project. */
|
|
29
|
+
const OWN_FOLDERS = new Set(['.cursor', '.codex', '.pi', '.vscode', '.claude']);
|
|
30
|
+
|
|
31
|
+
const isSymlink = (opts: { path: string }): boolean =>
|
|
32
|
+
lstatSync(opts.path, { throwIfNoEntry: false })?.isSymbolicLink() ?? false;
|
|
33
|
+
|
|
34
|
+
const removeIfEmpty = (opts: { path: string }): void => {
|
|
35
|
+
try {
|
|
36
|
+
if (existsSync(opts.path) && readdirSync(opts.path).length === 0) {
|
|
37
|
+
rmdirSync(opts.path);
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// A folder that cannot be removed stays; it is the user's to clean.
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const readJsonObject = (opts: { path: string }): TSettings | undefined => {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = { value: JSON.parse(readFileSync(opts.path, 'utf8')) };
|
|
47
|
+
|
|
48
|
+
return isSettingsObject(parsed) ? parsed.value : undefined;
|
|
49
|
+
} catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** A skill link sync made: a symlink into the shipped skills, stable or in the package, or into `.agents/skills`. */
|
|
55
|
+
const isSkillLink = (opts: { root: string; path: string }): boolean => {
|
|
56
|
+
if (!isSymlink({ path: opts.path })) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const target = readlinkSync(opts.path);
|
|
61
|
+
const shipped = [
|
|
62
|
+
join(stableBaseDirectoryOf(opts), SyncConstants.SKILLS_DIRECTORY),
|
|
63
|
+
join(BASE_DIRECTORY, SyncConstants.SKILLS_DIRECTORY),
|
|
64
|
+
join(opts.root, '.agents', SyncConstants.SKILLS_DIRECTORY),
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
return shipped.some(directory => target === directory || target.startsWith(`${directory}/`));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const removeFile = (opts: { path: string; note?: string; parent?: string }): ISyncAction => ({
|
|
71
|
+
path: opts.path,
|
|
72
|
+
status: SyncStatuses.REMOVED,
|
|
73
|
+
note: opts.note,
|
|
74
|
+
apply: () => {
|
|
75
|
+
rmSync(opts.path, { force: true });
|
|
76
|
+
|
|
77
|
+
if (opts.parent !== undefined) {
|
|
78
|
+
removeIfEmpty({ path: opts.parent });
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const planMcpRemoval = (opts: { root: string; entry: TAgentEntry }): ISyncAction[] => {
|
|
84
|
+
if (opts.entry.mcp.scope !== AgentScopes.PROJECT) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const path = join(opts.root, opts.entry.mcp.path);
|
|
89
|
+
|
|
90
|
+
if (!existsSync(path)) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const text = readFileSync(path, 'utf8');
|
|
95
|
+
const folder = dirname(opts.entry.mcp.path);
|
|
96
|
+
const parent = OWN_FOLDERS.has(folder) ? join(opts.root, folder) : undefined;
|
|
97
|
+
|
|
98
|
+
if (opts.entry.mcp.renderer === AgentRenderers.CODEX_TOML) {
|
|
99
|
+
const removed = removeCodexBlock({ text });
|
|
100
|
+
|
|
101
|
+
if (!removed.changed) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return removed.text === undefined
|
|
106
|
+
? [removeFile({ path, parent })]
|
|
107
|
+
: [
|
|
108
|
+
{
|
|
109
|
+
path,
|
|
110
|
+
status: SyncStatuses.REPLACED,
|
|
111
|
+
note: 'the atlas block taken out',
|
|
112
|
+
apply: () => writeFileSync(path, removed.text ?? ''),
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const key = opts.entry.mcp.renderer === AgentRenderers.SERVERS ? 'servers' : 'mcpServers';
|
|
118
|
+
const removed = removeMcpEntry({ text, key });
|
|
119
|
+
|
|
120
|
+
if (!removed.ok) {
|
|
121
|
+
return [{ path, status: SyncStatuses.SKIPPED, note: removed.reason, apply: NO_CHANGE }];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (removed.outcome === 'absent') {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return removed.text === undefined
|
|
129
|
+
? [removeFile({ path, parent })]
|
|
130
|
+
: [
|
|
131
|
+
{
|
|
132
|
+
path,
|
|
133
|
+
status: SyncStatuses.REPLACED,
|
|
134
|
+
note: 'the atlas entry taken out',
|
|
135
|
+
apply: () => writeFileSync(path, removed.text ?? ''),
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const planSkillLinkRemoval = (opts: { root: string; directory: string }): ISyncAction[] => {
|
|
141
|
+
const target = join(opts.root, opts.directory);
|
|
142
|
+
|
|
143
|
+
if (!existsSync(target) || isSymlink({ path: target })) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const links = readdirSync(target)
|
|
148
|
+
.map(name => join(target, name))
|
|
149
|
+
.filter(path => isSkillLink({ root: opts.root, path }));
|
|
150
|
+
|
|
151
|
+
return links.map((path, index) => ({
|
|
152
|
+
path,
|
|
153
|
+
status: SyncStatuses.REMOVED,
|
|
154
|
+
apply: () => {
|
|
155
|
+
rmSync(path, { force: true });
|
|
156
|
+
|
|
157
|
+
if (index === links.length - 1) {
|
|
158
|
+
removeIfEmpty({ path: target });
|
|
159
|
+
removeIfEmpty({
|
|
160
|
+
path: dirname(target) === join(opts.root, '.agents') ? '' : dirname(target),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const planClaudeRemoval = (opts: { root: string }): ISyncAction[] => {
|
|
168
|
+
const actions: ISyncAction[] = [];
|
|
169
|
+
const shim = join(opts.root, SyncConstants.CLAUDE_TOOL_FILE);
|
|
170
|
+
|
|
171
|
+
if (existsSync(shim) && readFileSync(shim, 'utf8').trim() === SyncConstants.CLAUDE_IMPORT_LINE) {
|
|
172
|
+
actions.push(removeFile({ path: shim }));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const directory = join(opts.root, SyncConstants.CLAUDE_DIRECTORY);
|
|
176
|
+
const settingsPath = join(directory, SyncConstants.SETTINGS_FILE);
|
|
177
|
+
const managedPath = join(directory, SyncConstants.MANAGED_FILE);
|
|
178
|
+
const settings = readJsonObject({ path: settingsPath });
|
|
179
|
+
const managed = readJsonObject({ path: managedPath });
|
|
180
|
+
|
|
181
|
+
if (settings !== undefined && managed !== undefined) {
|
|
182
|
+
const remaining = removeManagedSettings({ settings, managed });
|
|
183
|
+
|
|
184
|
+
actions.push(
|
|
185
|
+
Object.keys(remaining).length === 0
|
|
186
|
+
? removeFile({ path: settingsPath, note: 'only what sync wrote was in it' })
|
|
187
|
+
: {
|
|
188
|
+
path: settingsPath,
|
|
189
|
+
status: SyncStatuses.REPLACED,
|
|
190
|
+
note: 'the settings sync wrote taken out, yours kept',
|
|
191
|
+
apply: () => writeFileSync(settingsPath, `${JSON.stringify(remaining, null, 2)}\n`),
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (existsSync(managedPath)) {
|
|
197
|
+
actions.push(removeFile({ path: managedPath }));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
actions.push(...planSkillLinkRemoval({ root: opts.root, directory: CLAUDE_SKILLS }));
|
|
201
|
+
|
|
202
|
+
return actions;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* What sync created for the agents that are no longer chosen, taken back: the Claude shim and managed
|
|
207
|
+
* settings, a file sync wrote whole, the atlas key it merged into a file that holds more, the Codex
|
|
208
|
+
* block, and the skill links no remaining agent still reads. A file the user changed so the entry is
|
|
209
|
+
* no longer sync's is left and reported.
|
|
210
|
+
*/
|
|
211
|
+
export const planAgentRemoval = (opts: {
|
|
212
|
+
root: string;
|
|
213
|
+
removed: string[];
|
|
214
|
+
remaining: string[];
|
|
215
|
+
}): ISyncAction[] => {
|
|
216
|
+
const table = readAgentTable();
|
|
217
|
+
const kept = new Set(
|
|
218
|
+
table.filter(entry => opts.remaining.includes(entry.id)).map(entry => entry.skills.dir),
|
|
219
|
+
);
|
|
220
|
+
const cleaned = new Set<string>();
|
|
221
|
+
const actions: ISyncAction[] = [];
|
|
222
|
+
|
|
223
|
+
for (const entry of table.filter(item => opts.removed.includes(item.id))) {
|
|
224
|
+
if (entry.id === AgentConstants.DEFAULT_AGENT) {
|
|
225
|
+
actions.push(...planClaudeRemoval({ root: opts.root }));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
actions.push(...planMcpRemoval({ root: opts.root, entry }));
|
|
229
|
+
|
|
230
|
+
if (
|
|
231
|
+
entry.skills.dir !== CLAUDE_SKILLS &&
|
|
232
|
+
!kept.has(entry.skills.dir) &&
|
|
233
|
+
!cleaned.has(entry.skills.dir)
|
|
234
|
+
) {
|
|
235
|
+
cleaned.add(entry.skills.dir);
|
|
236
|
+
actions.push(...planSkillLinkRemoval({ root: opts.root, directory: entry.skills.dir }));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return actions;
|
|
241
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { mergeAtlasBlock, renderAtlasBlock } from '../agents/index.ts';
|
|
4
|
+
import type { TResolvedConfig } from '../config/index.ts';
|
|
5
|
+
import { runsAtlas } from '../init/scaffold.ts';
|
|
6
|
+
import { projectNameOf } from '../manifest/index.ts';
|
|
7
|
+
import { SyncStatuses } from './common/index.ts';
|
|
8
|
+
import type { ISyncAction } from './common/index.ts';
|
|
9
|
+
|
|
10
|
+
const NO_CHANGE = (): void => {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The block's text for this project, or undefined when AGENTS.md is absent or the project does not
|
|
14
|
+
* run the atlas server (a block that points at a server nobody started is noise).
|
|
15
|
+
*/
|
|
16
|
+
export const mergedAtlasBlock = (opts: {
|
|
17
|
+
root: string;
|
|
18
|
+
config: TResolvedConfig;
|
|
19
|
+
}): { path: string; changed: boolean; text: string } | undefined => {
|
|
20
|
+
const path = join(opts.root, 'AGENTS.md');
|
|
21
|
+
const mcp = join(opts.root, '.mcp.json');
|
|
22
|
+
|
|
23
|
+
if (!existsSync(path) || !existsSync(mcp) || !runsAtlas({ text: readFileSync(mcp, 'utf8') })) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const block = renderAtlasBlock({
|
|
28
|
+
project: projectNameOf(opts),
|
|
29
|
+
sources: opts.config.atlas.sources.map(source => source.name),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return { path, ...mergeAtlasBlock({ text: readFileSync(path, 'utf8'), block }) };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** The committed AGENTS.md carries the block for every agent, Claude included. */
|
|
36
|
+
export const planAtlasBlock = (opts: { root: string; config: TResolvedConfig }): ISyncAction[] => {
|
|
37
|
+
const merged = mergedAtlasBlock(opts);
|
|
38
|
+
|
|
39
|
+
if (merged === undefined) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!merged.changed) {
|
|
44
|
+
return [{ path: merged.path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE }];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
path: merged.path,
|
|
50
|
+
status: SyncStatuses.REPLACED,
|
|
51
|
+
note: 'Atlas block',
|
|
52
|
+
apply: () => writeFileSync(merged.path, merged.text),
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
};
|
|
@@ -36,6 +36,8 @@ export class SyncConstants {
|
|
|
36
36
|
static readonly HOOKS_KEY = 'hooks';
|
|
37
37
|
/** Objects of independent entries: merged one level deep, so personal entries survive shared ones. */
|
|
38
38
|
static readonly MERGE_ONE_LEVEL = new Set(['permissions', 'hooks', 'enabledPlugins', 'env']);
|
|
39
|
+
/** Top-level lists that merge as a union, so the user's own entries survive the shared ones. */
|
|
40
|
+
static readonly UNION_ARRAYS = new Set(['enabledMcpjsonServers']);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/** How a base rule moved between the manifest's last sync and the installed base. */
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { excludePathsOf, mergeExcludeBlock, renderExcludeBlock } from '../agents/index.ts';
|
|
4
|
+
import { BASE_DIRECTORY } from '../common/index.ts';
|
|
5
|
+
import { SyncConstants, SyncStatuses } from './common/index.ts';
|
|
6
|
+
import type { ISyncAction } from './common/index.ts';
|
|
7
|
+
|
|
8
|
+
const NO_CHANGE = (): void => {};
|
|
9
|
+
|
|
10
|
+
const git = (opts: { root: string; args: string[] }): string | undefined => {
|
|
11
|
+
try {
|
|
12
|
+
const result = Bun.spawnSync(['git', ...opts.args], {
|
|
13
|
+
cwd: opts.root,
|
|
14
|
+
stdout: 'pipe',
|
|
15
|
+
stderr: 'ignore',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return result.exitCode === 0 ? result.stdout.toString().trim() : undefined;
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const shippedSkillNames = (): string[] => {
|
|
25
|
+
const directory = join(BASE_DIRECTORY, SyncConstants.SKILLS_DIRECTORY);
|
|
26
|
+
|
|
27
|
+
return existsSync(directory)
|
|
28
|
+
? readdirSync(directory, { withFileTypes: true })
|
|
29
|
+
.filter(
|
|
30
|
+
entry =>
|
|
31
|
+
entry.isDirectory() &&
|
|
32
|
+
existsSync(join(directory, entry.name, SyncConstants.SKILL_FILE)),
|
|
33
|
+
)
|
|
34
|
+
.map(entry => entry.name)
|
|
35
|
+
.sort()
|
|
36
|
+
: [];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The files sync creates for the chosen agents, listed in this clone's `.git/info/exclude` (D1): the
|
|
41
|
+
* choice is per developer, so a committed `.gitignore` would flip-flop. A re-run replaces the block, so
|
|
42
|
+
* an agent that is no longer chosen drops out. Paths git tracks are not listed; outside a git
|
|
43
|
+
* repository nothing is written.
|
|
44
|
+
*/
|
|
45
|
+
export const planExclude = (opts: { root: string; agents: string[] }): ISyncAction[] => {
|
|
46
|
+
const location = git({ root: opts.root, args: ['rev-parse', '--git-path', 'info/exclude'] });
|
|
47
|
+
|
|
48
|
+
if (location === undefined || location === '') {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const path = resolve(opts.root, location);
|
|
53
|
+
const prefix = git({ root: opts.root, args: ['rev-parse', '--show-prefix'] }) ?? '';
|
|
54
|
+
const anchored = excludePathsOf({ agents: opts.agents, skillNames: shippedSkillNames() }).map(
|
|
55
|
+
group => ({ ...group, paths: group.paths.map(item => `/${prefix}${item.slice(1)}`) }),
|
|
56
|
+
);
|
|
57
|
+
const candidates = anchored.flatMap(group => group.paths).filter(item => !item.endsWith('/'));
|
|
58
|
+
const tracked = new Set(
|
|
59
|
+
(
|
|
60
|
+
git({
|
|
61
|
+
root: opts.root,
|
|
62
|
+
args: ['ls-files', '--', ...candidates.map(item => item.slice(`/${prefix}`.length))],
|
|
63
|
+
}) ?? ''
|
|
64
|
+
)
|
|
65
|
+
.split('\n')
|
|
66
|
+
.filter(line => line !== '')
|
|
67
|
+
.map(line => `/${prefix}${line}`),
|
|
68
|
+
);
|
|
69
|
+
const groups = anchored
|
|
70
|
+
.map(group => ({ ...group, paths: group.paths.filter(item => !tracked.has(item)) }))
|
|
71
|
+
.filter(group => group.paths.length > 0);
|
|
72
|
+
const before = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
|
|
73
|
+
const merged = mergeExcludeBlock({ text: before, block: renderExcludeBlock({ groups }) });
|
|
74
|
+
|
|
75
|
+
if (!merged.changed) {
|
|
76
|
+
return [{ path, status: SyncStatuses.UNCHANGED, apply: NO_CHANGE }];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
path,
|
|
82
|
+
status: before === undefined ? SyncStatuses.CREATED : SyncStatuses.REPLACED,
|
|
83
|
+
apply: () => {
|
|
84
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
85
|
+
writeFileSync(path, merged.text);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
};
|
package/src/sync/index.ts
CHANGED
|
@@ -3,3 +3,8 @@ export * from './base-rules.ts';
|
|
|
3
3
|
export * from './planner.ts';
|
|
4
4
|
export * from './prune.ts';
|
|
5
5
|
export * from './settings.ts';
|
|
6
|
+
export * from './local-choice.ts';
|
|
7
|
+
export * from './agent-files.ts';
|
|
8
|
+
export * from './atlas-block.ts';
|
|
9
|
+
export * from './exclude.ts';
|
|
10
|
+
export * from './agent-removal.ts';
|