@venizia/vulcan 0.4.8 → 0.4.9-1
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/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +4 -3
- package/base/hooks/codex-guards.ts +17 -6
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +5 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +6 -6
- package/base/hooks/guard-remote-hosts.ts +14 -9
- package/base/hooks/guard-scripting.ts +6 -6
- package/base/hooks/guard-writes.ts +20 -11
- package/base/hooks/post-tool.ts +4 -3
- package/base/hooks/prompt-submit.ts +4 -3
- package/base/hooks/session-start.ts +5 -3
- package/base/hooks/stop.ts +4 -3
- package/base/hooks/subagent-start.ts +2 -2
- package/base/make/vulcan.mk +1 -4
- package/base/skills/build-a-feature/SKILL.md +1 -1
- package/base/skills/docs-update/SKILL.md +11 -5
- package/base/skills/docs-update/evals/evals.json +1 -1
- package/base/skills/docs-writing/SKILL.md +1 -1
- package/base/skills/plan-a-change/references/spec-card.md +1 -1
- package/base/skills/ship/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +29 -6
- package/base/skills/visualize-work/references/spec.md +16 -5
- package/package.json +5 -6
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +55 -52
- package/src/agents/common/types.ts +1 -1
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +97 -98
- package/src/agents/hooks-json.ts +41 -43
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +203 -201
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/cli.ts +3 -1
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +6 -4
- package/src/commands/help.command.ts +11 -9
- package/src/commands/init.command.ts +14 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +43 -50
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +85 -78
- package/src/commands/visualize.command.ts +20 -5
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/index.ts +2 -0
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +96 -111
- package/src/common/paths.ts +14 -12
- package/src/common/record.ts +7 -0
- package/src/common/text.ts +7 -0
- package/src/config/common/constants.ts +13 -1
- package/src/config/common/types.ts +8 -1
- package/src/config/loader.ts +53 -48
- package/src/config/packages.ts +17 -11
- package/src/config/schema.ts +54 -7
- package/src/create/add-app.ts +604 -493
- package/src/create/add-lib.ts +249 -242
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/common/constants.ts +1 -0
- package/src/create/common/failure.ts +10 -0
- package/src/create/common/index.ts +2 -0
- package/src/create/common/preset-path.ts +11 -0
- package/src/create/common/types.ts +7 -2
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +78 -80
- package/src/create/lib-preset.ts +62 -61
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +27 -24
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +415 -240
- package/src/create/preset-menu.ts +40 -34
- package/src/create/preset.ts +207 -194
- package/src/create/process.ts +80 -71
- package/src/create/scratch.ts +49 -48
- package/src/create/workspace.ts +423 -398
- package/src/doctor/checks.ts +1069 -998
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -116
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +44 -41
- package/src/hooks/codex-patch.ts +27 -24
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/common/constants.ts +0 -3
- package/src/hooks/common/types.ts +15 -1
- package/src/hooks/decision.ts +38 -42
- package/src/hooks/guard-git.ts +52 -50
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +109 -88
- package/src/hooks/guard-package.ts +86 -77
- package/src/hooks/guard-scripting.ts +20 -15
- package/src/hooks/guard-writes.ts +169 -111
- package/src/hooks/owner-reply.ts +128 -128
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +93 -55
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +157 -149
- package/src/hooks/session-digest.ts +99 -95
- package/src/hooks/shell.ts +519 -500
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +158 -80
- package/src/init/common/types.ts +1 -1
- package/src/init/scaffold.ts +137 -134
- package/src/local/clean.ts +39 -37
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +146 -140
- package/src/manifest/render.ts +127 -112
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +100 -96
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +72 -70
- package/src/owner/survey.ts +175 -164
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/router.ts +4 -1
- package/src/rules/base.ts +15 -11
- package/src/rules/common/types.ts +1 -1
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +36 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +80 -85
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +62 -68
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +74 -37
- package/src/sync/common/constants.ts +4 -0
- package/src/sync/common/index.ts +1 -0
- package/src/sync/common/symlink.ts +9 -0
- package/src/sync/common/types.ts +2 -2
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +64 -68
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +167 -168
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +35 -33
- package/src/ui/prompt.ts +81 -77
- package/src/visualize/assets.ts +379 -195
- package/src/visualize/charts.ts +188 -176
- package/src/visualize/compare-css.ts +31 -0
- package/src/visualize/compare-render.ts +196 -0
- package/src/visualize/compare-schema.ts +81 -0
- package/src/visualize/compare-validate.ts +126 -0
- package/src/visualize/constants.ts +29 -3
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/gate.ts +136 -0
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +9 -4
- package/src/visualize/index.ts +2 -0
- package/src/visualize/kinds-css.ts +54 -0
- package/src/visualize/kinds-render.ts +698 -0
- package/src/visualize/kinds-schema.ts +148 -0
- package/src/visualize/kinds-validate.ts +186 -0
- package/src/visualize/labels-vi.ts +109 -0
- package/src/visualize/labels.ts +53 -0
- package/src/visualize/layout.ts +112 -92
- package/src/visualize/page.ts +140 -114
- package/src/visualize/render.ts +158 -114
- package/src/visualize/schema.ts +21 -1
- package/src/visualize/sections.ts +401 -309
- package/src/visualize/sources.ts +270 -0
- package/src/visualize/theme.ts +474 -0
- package/src/visualize/validate.ts +15 -5
- package/src/wiki/anchors.ts +39 -37
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +49 -49
package/src/agents/render.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
import { RecordValue } from '../common/record.ts';
|
|
2
3
|
import { RemoveOutcomes } from './common/index.ts';
|
|
3
4
|
|
|
4
5
|
export const CODEX_BLOCK_START = '# vulcan:atlas:start';
|
|
@@ -6,239 +7,240 @@ export const CODEX_BLOCK_END = '# vulcan:atlas:end';
|
|
|
6
7
|
const CODEX_TABLE = '[mcp_servers.atlas]';
|
|
7
8
|
const SERVER_NAME = 'atlas';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
type TMergeResult = { ok: true; changed: boolean; text: string } | { ok: false; reason: string };
|
|
11
|
+
|
|
12
|
+
export class McpConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Whether an `atlas` entry is the one sync writes, for whatever place: `bun <root>/node_modules/.bin/vulcan
|
|
15
|
+
* x atlas mcp --root <root>` (plus `type: stdio` for VS Code) with the two paths agreeing, or the relative
|
|
16
|
+
* entry of the root `.mcp.json`. Anything else is the user's. A project that moved is recognised this way
|
|
17
|
+
* and rewritten.
|
|
18
|
+
*/
|
|
19
|
+
private static isOwnEntry(opts: { entry: unknown }): boolean {
|
|
20
|
+
const { entry } = opts;
|
|
21
|
+
|
|
22
|
+
if (!RecordValue.isRecord(entry) || entry.command !== 'bun' || !Array.isArray(entry.args)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The atlas server as the root `.mcp.json` starts it: the same for every developer, so it is relative.
|
|
31
|
-
* Claude Code, omp and Copilot CLI launch a project server from the project root.
|
|
32
|
-
*/
|
|
33
|
-
export const canonicalAtlasEntry = (): { command: string; args: string[] } => ({
|
|
34
|
-
command: 'bun',
|
|
35
|
-
args: ['x', '--no-install', 'vulcan', 'x', 'atlas', 'mcp', '--root', '.'],
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
39
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Whether an `atlas` entry is the one sync writes, for whatever place: `bun <root>/node_modules/.bin/vulcan
|
|
43
|
-
* x atlas mcp --root <root>` (plus `type: stdio` for VS Code) with the two paths agreeing, or the relative
|
|
44
|
-
* entry of the root `.mcp.json`. Anything else is the user's. A project that moved is recognised this way
|
|
45
|
-
* and rewritten.
|
|
46
|
-
*/
|
|
47
|
-
const isOwnEntry = (opts: { entry: unknown }): boolean => {
|
|
48
|
-
const { entry } = opts;
|
|
49
|
-
|
|
50
|
-
if (!isRecord(entry) || entry.command !== 'bun' || !Array.isArray(entry.args)) {
|
|
51
|
-
return false;
|
|
26
|
+
if (JSON.stringify(entry) === JSON.stringify(McpConfig.canonicalAtlasEntry())) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const keys = Object.keys(entry).filter((key) => key !== 'type');
|
|
31
|
+
const [bin, ...rest] = entry.args;
|
|
32
|
+
const root = rest[4];
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
keys.length === 2 &&
|
|
36
|
+
(entry.type === undefined || entry.type === 'stdio') &&
|
|
37
|
+
entry.args.length === 6 &&
|
|
38
|
+
rest.slice(0, 4).join(' ') === 'x atlas mcp --root' &&
|
|
39
|
+
typeof root === 'string' &&
|
|
40
|
+
bin === join(root, 'node_modules', '.bin', 'vulcan')
|
|
41
|
+
);
|
|
52
42
|
}
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
private static codexBlock(opts: { root: string }): string {
|
|
45
|
+
const { command, args } = McpConfig.atlasServerEntry({ root: opts.root });
|
|
46
|
+
|
|
47
|
+
return [
|
|
48
|
+
CODEX_BLOCK_START,
|
|
49
|
+
CODEX_TABLE,
|
|
50
|
+
`command = ${JSON.stringify(command)}`,
|
|
51
|
+
`args = [${args.map((arg) => JSON.stringify(arg)).join(', ')}]`,
|
|
52
|
+
CODEX_BLOCK_END,
|
|
53
|
+
'',
|
|
54
|
+
].join('\n');
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* `atlas` entry is the user's and is left as it is.
|
|
76
|
-
*/
|
|
77
|
-
export const mergeMcpServers = (opts: {
|
|
78
|
-
text: string | undefined;
|
|
79
|
-
key: string;
|
|
80
|
-
entry: Record<string, unknown>;
|
|
81
|
-
}): TMergeResult => {
|
|
82
|
-
let document: Record<string, unknown> = {};
|
|
83
|
-
|
|
84
|
-
if (opts.text !== undefined) {
|
|
85
|
-
let parsed: unknown;
|
|
57
|
+
/**
|
|
58
|
+
* The atlas server as a per-machine file starts it: the project's own `vulcan` by absolute path with
|
|
59
|
+
* an absolute `--root`, so it does not matter which directory the agent launches the server from.
|
|
60
|
+
*/
|
|
61
|
+
static atlasServerEntry(opts: { root: string }): { command: string; args: string[] } {
|
|
62
|
+
return {
|
|
63
|
+
command: 'bun',
|
|
64
|
+
args: [
|
|
65
|
+
join(opts.root, 'node_modules', '.bin', 'vulcan'),
|
|
66
|
+
'x',
|
|
67
|
+
'atlas',
|
|
68
|
+
'mcp',
|
|
69
|
+
'--root',
|
|
70
|
+
opts.root,
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
86
74
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The atlas server as the root `.mcp.json` starts it: the same for every developer, so it is relative.
|
|
77
|
+
* Claude Code, omp and Copilot CLI launch a project server from the project root.
|
|
78
|
+
*/
|
|
79
|
+
static canonicalAtlasEntry(): { command: string; args: string[] } {
|
|
80
|
+
return {
|
|
81
|
+
command: 'bun',
|
|
82
|
+
args: ['x', '--no-install', 'vulcan', 'x', 'atlas', 'mcp', '--root', '.'],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sets the `atlas` server in a JSON file's server map and nothing else: the user's keys, servers and
|
|
88
|
+
* order stay, an `atlas` entry sync wrote for another place is rewritten for this one, and any other
|
|
89
|
+
* `atlas` entry is the user's and is left as it is.
|
|
90
|
+
*/
|
|
91
|
+
static mergeServers(opts: {
|
|
92
|
+
text: string | undefined;
|
|
93
|
+
key: string;
|
|
94
|
+
entry: Record<string, unknown>;
|
|
95
|
+
}): TMergeResult {
|
|
96
|
+
let document: Record<string, unknown> = {};
|
|
97
|
+
|
|
98
|
+
if (opts.text !== undefined) {
|
|
99
|
+
let parsed: unknown;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
parsed = JSON.parse(opts.text);
|
|
103
|
+
} catch {
|
|
104
|
+
return { ok: false, reason: 'not valid JSON' };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!RecordValue.isRecord(parsed)) {
|
|
108
|
+
return { ok: false, reason: 'not a JSON object' };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
document = parsed;
|
|
91
112
|
}
|
|
92
113
|
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
const servers = document[opts.key] ?? {};
|
|
115
|
+
|
|
116
|
+
if (!RecordValue.isRecord(servers)) {
|
|
117
|
+
return { ok: false, reason: `${opts.key} is not an object` };
|
|
95
118
|
}
|
|
96
119
|
|
|
97
|
-
|
|
98
|
-
}
|
|
120
|
+
const existing = servers[SERVER_NAME];
|
|
99
121
|
|
|
100
|
-
|
|
122
|
+
if (Object.hasOwn(servers, SERVER_NAME) && !McpConfig.isOwnEntry({ entry: existing })) {
|
|
123
|
+
return { ok: true, changed: false, text: opts.text ?? '' };
|
|
124
|
+
}
|
|
101
125
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
if (
|
|
127
|
+
Object.hasOwn(servers, SERVER_NAME) &&
|
|
128
|
+
JSON.stringify(existing) === JSON.stringify(opts.entry)
|
|
129
|
+
) {
|
|
130
|
+
return { ok: true, changed: false, text: opts.text ?? '' };
|
|
131
|
+
}
|
|
105
132
|
|
|
106
|
-
|
|
133
|
+
const text = `${JSON.stringify(
|
|
134
|
+
{ ...document, [opts.key]: { ...servers, [SERVER_NAME]: opts.entry } },
|
|
135
|
+
null,
|
|
136
|
+
2,
|
|
137
|
+
)}\n`;
|
|
107
138
|
|
|
108
|
-
|
|
109
|
-
return { ok: true, changed: false, text: opts.text ?? '' };
|
|
139
|
+
return { ok: true, changed: true, text };
|
|
110
140
|
}
|
|
111
141
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
142
|
+
/**
|
|
143
|
+
* The atlas entry as a marker-delimited block of `.codex/config.toml`: no TOML writer is needed, and
|
|
144
|
+
* a later sync replaces only what sits between the markers.
|
|
145
|
+
*/
|
|
146
|
+
static mergeCodexToml(opts: { text: string | undefined; root: string }): TMergeResult {
|
|
147
|
+
const block = McpConfig.codexBlock({ root: opts.root });
|
|
118
148
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
2,
|
|
123
|
-
)}\n`;
|
|
124
|
-
|
|
125
|
-
return { ok: true, changed: true, text };
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const codexBlock = (opts: { root: string }): string => {
|
|
129
|
-
const { command, args } = atlasServerEntry({ root: opts.root });
|
|
130
|
-
|
|
131
|
-
return [
|
|
132
|
-
CODEX_BLOCK_START,
|
|
133
|
-
CODEX_TABLE,
|
|
134
|
-
`command = ${JSON.stringify(command)}`,
|
|
135
|
-
`args = [${args.map((arg) => JSON.stringify(arg)).join(', ')}]`,
|
|
136
|
-
CODEX_BLOCK_END,
|
|
137
|
-
'',
|
|
138
|
-
].join('\n');
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The atlas entry as a marker-delimited block of `.codex/config.toml`: no TOML writer is needed, and
|
|
143
|
-
* a later sync replaces only what sits between the markers.
|
|
144
|
-
*/
|
|
145
|
-
export const mergeCodexToml = (opts: { text: string | undefined; root: string }): TMergeResult => {
|
|
146
|
-
const block = codexBlock({ root: opts.root });
|
|
147
|
-
|
|
148
|
-
if (opts.text === undefined || opts.text === '') {
|
|
149
|
-
return { ok: true, changed: true, text: block };
|
|
150
|
-
}
|
|
149
|
+
if (opts.text === undefined || opts.text === '') {
|
|
150
|
+
return { ok: true, changed: true, text: block };
|
|
151
|
+
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
const start = opts.text.indexOf(CODEX_BLOCK_START);
|
|
154
|
+
const end = opts.text.indexOf(CODEX_BLOCK_END);
|
|
154
155
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
if (start !== -1 && end > start) {
|
|
157
|
+
const after = end + CODEX_BLOCK_END.length;
|
|
158
|
+
const rest = opts.text.slice(after).replace(/^\n/, '');
|
|
159
|
+
const text = `${opts.text.slice(0, start)}${block}${rest}`;
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
return { ok: true, changed: text !== opts.text, text };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (opts.text.includes(CODEX_TABLE)) {
|
|
165
|
+
return {
|
|
166
|
+
ok: false,
|
|
167
|
+
reason: 'a [mcp_servers.atlas] table is already there outside the vulcan markers',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
162
170
|
|
|
163
|
-
if (opts.text.includes(CODEX_TABLE)) {
|
|
164
171
|
return {
|
|
165
|
-
ok:
|
|
166
|
-
|
|
172
|
+
ok: true,
|
|
173
|
+
changed: true,
|
|
174
|
+
text: `${opts.text}${opts.text.endsWith('\n') ? '' : '\n'}\n${block}`,
|
|
167
175
|
};
|
|
168
176
|
}
|
|
169
177
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Takes sync's own atlas entry out of a JSON server map. The file is deleted (`text` undefined) when
|
|
180
|
+
* nothing else is left in it; an entry of another shape is the user's and is reported, not removed.
|
|
181
|
+
*/
|
|
182
|
+
static removeEntry(opts: { text: string; key: string }): TRemoveResult {
|
|
183
|
+
let document: unknown;
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
try {
|
|
186
|
+
document = JSON.parse(opts.text);
|
|
187
|
+
} catch {
|
|
188
|
+
return { ok: false, reason: 'not valid JSON - left untouched' };
|
|
189
|
+
}
|
|
181
190
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
*/
|
|
186
|
-
export const removeMcpEntry = (opts: { text: string; key: string }): TRemoveResult => {
|
|
187
|
-
let document: unknown;
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
document = JSON.parse(opts.text);
|
|
191
|
-
} catch {
|
|
192
|
-
return { ok: false, reason: 'not valid JSON - left untouched' };
|
|
193
|
-
}
|
|
191
|
+
if (!RecordValue.isRecord(document)) {
|
|
192
|
+
return { ok: false, reason: 'not a JSON object - left untouched' };
|
|
193
|
+
}
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
return { ok: false, reason: 'not a JSON object - left untouched' };
|
|
197
|
-
}
|
|
195
|
+
const servers = document[opts.key];
|
|
198
196
|
|
|
199
|
-
|
|
197
|
+
if (!RecordValue.isRecord(servers) || !Object.hasOwn(servers, SERVER_NAME)) {
|
|
198
|
+
return { ok: true, outcome: RemoveOutcomes.ABSENT };
|
|
199
|
+
}
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
if (!McpConfig.isOwnEntry({ entry: servers[SERVER_NAME] })) {
|
|
202
|
+
return { ok: false, reason: 'the atlas entry is not the one sync wrote - left alone' };
|
|
203
|
+
}
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
const otherServers = Object.fromEntries(
|
|
206
|
+
Object.entries(servers).filter(([name]) => name !== SERVER_NAME),
|
|
207
|
+
);
|
|
208
|
+
const otherKeys = Object.fromEntries(
|
|
209
|
+
Object.entries(document).filter(([key]) => key !== opts.key),
|
|
210
|
+
);
|
|
211
|
+
const remaining =
|
|
212
|
+
Object.keys(otherServers).length === 0
|
|
213
|
+
? otherKeys
|
|
214
|
+
: { ...document, [opts.key]: otherServers };
|
|
215
|
+
const onlyEmptyInputs = Object.entries(remaining).every(
|
|
216
|
+
([key, value]) => key === 'inputs' && Array.isArray(value) && value.length === 0,
|
|
217
|
+
);
|
|
208
218
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
);
|
|
215
|
-
const remaining =
|
|
216
|
-
Object.keys(otherServers).length === 0 ? otherKeys : { ...document, [opts.key]: otherServers };
|
|
217
|
-
const onlyEmptyInputs = Object.entries(remaining).every(
|
|
218
|
-
([key, value]) => key === 'inputs' && Array.isArray(value) && value.length === 0,
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
ok: true,
|
|
223
|
-
outcome: RemoveOutcomes.REMOVED,
|
|
224
|
-
text: onlyEmptyInputs ? undefined : `${JSON.stringify(remaining, null, 2)}\n`,
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
/** Takes the marker block out of `.codex/config.toml`; `text` is undefined when nothing else is left. */
|
|
229
|
-
export const removeCodexBlock = (opts: {
|
|
230
|
-
text: string;
|
|
231
|
-
}): { changed: boolean; text: string | undefined } => {
|
|
232
|
-
const start = opts.text.indexOf(CODEX_BLOCK_START);
|
|
233
|
-
const end = opts.text.indexOf(CODEX_BLOCK_END);
|
|
234
|
-
|
|
235
|
-
if (start === -1 || end < start) {
|
|
236
|
-
return { changed: false, text: opts.text };
|
|
219
|
+
return {
|
|
220
|
+
ok: true,
|
|
221
|
+
outcome: RemoveOutcomes.REMOVED,
|
|
222
|
+
text: onlyEmptyInputs ? undefined : `${JSON.stringify(remaining, null, 2)}\n`,
|
|
223
|
+
};
|
|
237
224
|
}
|
|
238
225
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
226
|
+
/** Takes the marker block out of `.codex/config.toml`; `text` is undefined when nothing else is left. */
|
|
227
|
+
static removeCodexBlock(opts: { text: string }): { changed: boolean; text: string | undefined } {
|
|
228
|
+
const start = opts.text.indexOf(CODEX_BLOCK_START);
|
|
229
|
+
const end = opts.text.indexOf(CODEX_BLOCK_END);
|
|
230
|
+
|
|
231
|
+
if (start === -1 || end < start) {
|
|
232
|
+
return { changed: false, text: opts.text };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const before = opts.text.slice(0, start).replace(/\n+$/, '\n');
|
|
236
|
+
const after = opts.text.slice(end + CODEX_BLOCK_END.length).replace(/^\n+/, '');
|
|
237
|
+
const text = `${before}${before !== '' && after !== '' ? '\n' : ''}${after}`;
|
|
238
|
+
|
|
239
|
+
return { changed: true, text: text.trim() === '' ? undefined : text };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
242
|
|
|
243
|
-
|
|
244
|
-
}
|
|
243
|
+
type TRemoveResult =
|
|
244
|
+
| { ok: true; outcome: typeof RemoveOutcomes.ABSENT }
|
|
245
|
+
| { ok: true; outcome: typeof RemoveOutcomes.REMOVED; text: string | undefined }
|
|
246
|
+
| { ok: false; reason: string };
|