@fabersep/memory 0.5.1 → 0.5.2
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/CHANGELOG.md +7 -0
- package/README.md +3 -3
- package/dist/src/cli.js +38 -16
- package/dist/src/init.d.ts +12 -0
- package/dist/src/init.js +155 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@fabersep/memory`. Versions follow [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## [0.5.2](https://github.com/fabersep/memory/compare/v0.5.1...v0.5.2) (2026-12-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* connect Codex in init and print a plain summary instead of Before/After ([#25](https://github.com/fabersep/memory/issues/25)) ([72245ad](https://github.com/fabersep/memory/commit/72245addb45fcd2ab5729f961f6eab7b9275998b))
|
|
11
|
+
|
|
5
12
|
## [0.5.1](https://github.com/fabersep/memory/compare/v0.5.0...v0.5.1) (2026-12-03)
|
|
6
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ FaberSEP Memory started from a common setup: several AI tools on a workstation,
|
|
|
22
22
|
|
|
23
23
|
| | Built-in agent memory | FaberSEP Memory |
|
|
24
24
|
| :--- | :--- | :--- |
|
|
25
|
-
| **Who can read it** | The one tool that wrote it | Claude Code, Antigravity, Cursor, Claude Desktop
|
|
25
|
+
| **Who can read it** | The one tool that wrote it | Claude Code, Antigravity, Codex, Cursor, Claude Desktop |
|
|
26
26
|
| **Where it lives** | One machine | A Git repo you can clone to any machine, a server included (read-only there) |
|
|
27
27
|
| **Who writes it** | The agent, silently | What you tell it to remember is saved at once; what the agent decides on its own waits for your approval |
|
|
28
28
|
| **History and undo** | Usually none | Every change is a Git commit |
|
|
@@ -56,9 +56,9 @@ There is **no background service and no account**. `faber-memory` is a CLI plus
|
|
|
56
56
|
| Antigravity | `~/.gemini/GEMINI.md` | `~/.gemini/config/mcp_config.json` |
|
|
57
57
|
| Cursor | none | `~/.cursor/mcp.json` |
|
|
58
58
|
| Claude Desktop | none | `claude_desktop_config.json` (`--engine claude-desktop`) |
|
|
59
|
-
| Codex
|
|
59
|
+
| Codex (CLI and app) | `~/.codex/AGENTS.md` | `~/.codex/config.toml` |
|
|
60
60
|
|
|
61
|
-
Every touched file gets a `.bak` backup. `init --preview` shows
|
|
61
|
+
Every touched file gets a `.bak` backup. `init` prints one line per tool; `init --details` shows each file change, `init --preview` shows what would change first, and `init --undo` removes the block and the MCP entry and leaves your notes alone. Details: [Connecting engines](docs/guide.md#connecting-engines-init).
|
|
62
62
|
|
|
63
63
|
## Get started
|
|
64
64
|
|
package/dist/src/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import { countRecentDirectSaves, DIRECT_SAVE_RECENT_DAYS, isDirectUserSaveOn, un
|
|
|
8
8
|
import { formatDoctorReport, runDoctor } from './doctor.js';
|
|
9
9
|
import { getDefaultBranch, getHeadSha, gitCloneTeamRepo, gitInitSoloRepo, gitSync, isGitRepo, } from './git.js';
|
|
10
10
|
import { runImport } from './importer.js';
|
|
11
|
-
import { formatPlanBeforeAfter, planOrApplyInit } from './init.js';
|
|
11
|
+
import { formatInitSummary, formatPlanBeforeAfter, planOrApplyInit, } from './init.js';
|
|
12
12
|
import { FaberMemoryMcpServer } from './mcp.js';
|
|
13
13
|
import { approveProposalsBatch, findProposalById, reconcileAwaitingCommitProposals, rejectProposal, saveProposal, } from './proposals.js';
|
|
14
14
|
import { buildShareableBenchmark, computeStats, formatShareableMarkdown, formatStatsReport, validateDaysArg, } from './stats.js';
|
|
@@ -20,7 +20,7 @@ import { c, hr, inferErrorAnchor, normalizeTeamUrl, troubleshootingLink, } from
|
|
|
20
20
|
import { openBrowserBestEffort, startWebServer, validateIdleTimeoutArg, validatePortArg, } from './web.js';
|
|
21
21
|
// Flags that never take a value, so `init --preview ~/notes` keeps ~/notes as a positional.
|
|
22
22
|
const BOOLEAN_FLAGS = new Set([
|
|
23
|
-
'apply', 'undo', 'preview', 'dry-run', 'check', 'json', 'strict', 'cache', 'share', 'yes',
|
|
23
|
+
'apply', 'undo', 'preview', 'dry-run', 'details', 'check', 'json', 'strict', 'cache', 'share', 'yes',
|
|
24
24
|
'all', 'approve', 'approve-all', 'split-headings', 'normalize-paths', 'project-hint',
|
|
25
25
|
'include-personal-repo', 'help', 'allow-public', 'web', 'no-open',
|
|
26
26
|
]);
|
|
@@ -908,26 +908,48 @@ async function main() {
|
|
|
908
908
|
projectHint,
|
|
909
909
|
homeDir,
|
|
910
910
|
});
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
911
|
+
// Default output is one plain line per assistant; --details adds the
|
|
912
|
+
// file-by-file Before/After view for those who want it.
|
|
913
|
+
const details = Boolean(flags.details);
|
|
914
|
+
const mode = undo ? 'undo' : preview ? 'preview' : 'apply';
|
|
915
|
+
const heading = mode === 'undo'
|
|
916
|
+
? 'Disconnecting memory from your assistants:'
|
|
917
|
+
: mode === 'preview'
|
|
918
|
+
? 'Preview: nothing was written.'
|
|
919
|
+
: 'Memory is connected to your assistants:';
|
|
920
|
+
console.log(c.bold(heading));
|
|
921
|
+
console.log(formatInitSummary(res.plans, mode));
|
|
922
|
+
if (details) {
|
|
923
|
+
for (const n of res.notes)
|
|
924
|
+
console.log(c.yellow(n));
|
|
925
|
+
for (const p of res.plans)
|
|
926
|
+
console.log(formatPlanBeforeAfter(p));
|
|
927
|
+
}
|
|
928
|
+
if (res.projectHint) {
|
|
929
|
+
console.log(`\nProject hint: ${res.projectHint}`);
|
|
915
930
|
}
|
|
931
|
+
console.log('');
|
|
916
932
|
if (undo) {
|
|
917
|
-
console.log(
|
|
933
|
+
console.log('Your memories and pending proposals were kept. (Use "faber-memory reset" to wipe local state.)');
|
|
918
934
|
if (res.backups.length > 0) {
|
|
919
|
-
console.log(c.dim(`
|
|
935
|
+
console.log(c.dim(`Backups kept, not restored: ${res.backups.join(', ')}`));
|
|
920
936
|
}
|
|
921
937
|
}
|
|
922
|
-
if (
|
|
923
|
-
console.log(`
|
|
938
|
+
else if (preview) {
|
|
939
|
+
console.log(`Run ${c.cyan('faber-memory init')} to apply.`);
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
const changed = res.plans.some((p) => p.changed);
|
|
943
|
+
console.log(changed
|
|
944
|
+
? 'Start a new chat in your assistant to use memory.'
|
|
945
|
+
: 'Everything was already set up.');
|
|
924
946
|
}
|
|
925
|
-
if (
|
|
926
|
-
|
|
947
|
+
if (!details) {
|
|
948
|
+
const again = undo ? 'faber-memory init --undo --details' : preview ? 'faber-memory init --preview --details' : 'faber-memory init --details';
|
|
949
|
+
console.log(c.dim(`See which files are touched and how: ${again}`));
|
|
927
950
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
console.log(c.green(`\nConnected: ${wired.join(', ') || 'nothing to change'}. Backups are saved as .bak; undo any time with "faber-memory init --undo". Start a new chat in your assistant to use memory.`));
|
|
951
|
+
if (!undo && !preview) {
|
|
952
|
+
console.log(c.dim('Undo any time: faber-memory init --undo'));
|
|
931
953
|
}
|
|
932
954
|
return 0;
|
|
933
955
|
}
|
|
@@ -994,7 +1016,7 @@ Commands:
|
|
|
994
1016
|
remote add <git-url> [--allow-public] | remote remove
|
|
995
1017
|
push
|
|
996
1018
|
config [set-path <personal|team> <new-path> | set-submit-mode <auto|pr> | set-push-mode <ask|auto|never> | set-direct-save <on|off> | unset <personal|team>]
|
|
997
|
-
init [folder] [--remote <git-url>] [--preview | --undo] [--engine claude-code,antigravity,claude-desktop,cursor,codex] [--project-hint]
|
|
1019
|
+
init [folder] [--remote <git-url>] [--preview | --undo] [--details] [--engine claude-code,antigravity,claude-desktop,cursor,codex] [--project-hint]
|
|
998
1020
|
compile [--check] [--repo <dir>]
|
|
999
1021
|
sync [--timeout <ms>]
|
|
1000
1022
|
status
|
package/dist/src/init.d.ts
CHANGED
|
@@ -6,13 +6,16 @@ export declare const PROJECT_HINT_LINE = "Project memory: run npx @fabersep/memo
|
|
|
6
6
|
export type EngineName = 'claude-code' | 'claude-desktop' | 'antigravity' | 'cursor' | 'codex';
|
|
7
7
|
export interface EngineSpec {
|
|
8
8
|
name: EngineName;
|
|
9
|
+
label: string;
|
|
9
10
|
verifiedImport: boolean;
|
|
10
11
|
gap: boolean;
|
|
11
12
|
instructionFile?: (userHome: string) => string;
|
|
12
13
|
mcpConfigFile?: (userHome: string) => string;
|
|
14
|
+
mcpFormat?: 'json' | 'toml';
|
|
13
15
|
renderBlock?: (compiledL0Path: string) => string;
|
|
14
16
|
}
|
|
15
17
|
export declare function getEngineSpecs(): Record<EngineName, EngineSpec>;
|
|
18
|
+
export type PlanAction = 'added' | 'updated' | 'unchanged' | 'removed';
|
|
16
19
|
export interface FilePlan {
|
|
17
20
|
filePath: string;
|
|
18
21
|
kind: 'instruction' | 'mcp-config';
|
|
@@ -20,6 +23,8 @@ export interface FilePlan {
|
|
|
20
23
|
before: string | null;
|
|
21
24
|
after: string;
|
|
22
25
|
changed: boolean;
|
|
26
|
+
/** What init does to faber-memory's part of the file; omitted plans count as added/updated by `changed`. */
|
|
27
|
+
action?: PlanAction;
|
|
23
28
|
backupPath?: string;
|
|
24
29
|
}
|
|
25
30
|
export interface InitPlanResult {
|
|
@@ -31,6 +36,10 @@ export interface InitPlanResult {
|
|
|
31
36
|
export declare function getUserHome(): string;
|
|
32
37
|
export declare function upsertManagedBlock(existing: string, block: string): string;
|
|
33
38
|
export declare function removeManagedBlock(existing: string): string;
|
|
39
|
+
export declare function renderCodexTomlTable(): string;
|
|
40
|
+
export declare function hasCodexTomlEntry(raw: string | null): boolean;
|
|
41
|
+
export declare function upsertMcpToml(existingRaw: string | null): string;
|
|
42
|
+
export declare function removeMcpToml(existingRaw: string): string;
|
|
34
43
|
export declare function detectTargetEngines(userHome: string, requested?: EngineName[]): EngineName[];
|
|
35
44
|
export declare function planOrApplyInit(config: UserConfig, options?: {
|
|
36
45
|
apply?: boolean;
|
|
@@ -42,3 +51,6 @@ export declare function planOrApplyInit(config: UserConfig, options?: {
|
|
|
42
51
|
}): InitPlanResult;
|
|
43
52
|
export declare function formatUnifiedDiff(plan: FilePlan): string;
|
|
44
53
|
export declare function formatPlanBeforeAfter(plan: FilePlan, useColor?: boolean): string;
|
|
54
|
+
export type InitMode = 'apply' | 'preview' | 'undo';
|
|
55
|
+
/** One plain line per assistant: what init did (or would do) there. */
|
|
56
|
+
export declare function formatInitSummary(plans: FilePlan[], mode: InitMode, useColor?: boolean): string;
|
package/dist/src/init.js
CHANGED
|
@@ -8,10 +8,14 @@ export const BLOCK_START = '<!-- faber-memory:start -->';
|
|
|
8
8
|
export const BLOCK_END = '<!-- faber-memory:end -->';
|
|
9
9
|
export const TOOL_GUIDANCE_LINE = 'Use the faber-memory MCP tools: memory_search and memory_get for the details behind these lines; when you learn a durable rule, decision, lesson or preference, call memory_propose (the user approves it later; never edit memory files directly). When the user explicitly asks you to remember something, call memory_propose with source "user" and their exact words in user_quote; it is saved at once.';
|
|
10
10
|
export const PROJECT_HINT_LINE = 'Project memory: run npx @fabersep/memory init';
|
|
11
|
+
function renderReadInstructionBlock(l0Path) {
|
|
12
|
+
return `${BLOCK_START}\nAt session start, read ${l0Path} (global L0 memory).\n${TOOL_GUIDANCE_LINE}\n${BLOCK_END}`;
|
|
13
|
+
}
|
|
11
14
|
export function getEngineSpecs() {
|
|
12
15
|
return {
|
|
13
16
|
'claude-code': {
|
|
14
17
|
name: 'claude-code',
|
|
18
|
+
label: 'Claude Code',
|
|
15
19
|
verifiedImport: true,
|
|
16
20
|
gap: false,
|
|
17
21
|
instructionFile: (home) => path.join(home, '.claude', 'CLAUDE.md'),
|
|
@@ -20,6 +24,7 @@ export function getEngineSpecs() {
|
|
|
20
24
|
},
|
|
21
25
|
'claude-desktop': {
|
|
22
26
|
name: 'claude-desktop',
|
|
27
|
+
label: 'Claude Desktop',
|
|
23
28
|
verifiedImport: false,
|
|
24
29
|
gap: false,
|
|
25
30
|
mcpConfigFile: (home) => process.platform === 'darwin'
|
|
@@ -28,22 +33,32 @@ export function getEngineSpecs() {
|
|
|
28
33
|
},
|
|
29
34
|
antigravity: {
|
|
30
35
|
name: 'antigravity',
|
|
36
|
+
label: 'Antigravity',
|
|
31
37
|
verifiedImport: true,
|
|
32
38
|
gap: false,
|
|
33
39
|
instructionFile: (home) => path.join(home, '.gemini', 'GEMINI.md'),
|
|
34
40
|
mcpConfigFile: (home) => path.join(home, '.gemini', 'config', 'mcp_config.json'),
|
|
35
|
-
renderBlock:
|
|
41
|
+
renderBlock: renderReadInstructionBlock,
|
|
36
42
|
},
|
|
37
43
|
cursor: {
|
|
38
44
|
name: 'cursor',
|
|
45
|
+
label: 'Cursor',
|
|
39
46
|
verifiedImport: false,
|
|
40
47
|
gap: true,
|
|
41
48
|
mcpConfigFile: (home) => path.join(home, '.cursor', 'mcp.json'),
|
|
42
49
|
},
|
|
50
|
+
// Codex CLI and the Codex desktop app share ~/.codex: global AGENTS.md
|
|
51
|
+
// (no @-import, so an explicit read instruction like Antigravity) and
|
|
52
|
+
// MCP servers in config.toml.
|
|
43
53
|
codex: {
|
|
44
54
|
name: 'codex',
|
|
55
|
+
label: 'Codex',
|
|
45
56
|
verifiedImport: false,
|
|
46
|
-
gap:
|
|
57
|
+
gap: false,
|
|
58
|
+
instructionFile: (home) => path.join(home, '.codex', 'AGENTS.md'),
|
|
59
|
+
mcpConfigFile: (home) => path.join(home, '.codex', 'config.toml'),
|
|
60
|
+
mcpFormat: 'toml',
|
|
61
|
+
renderBlock: renderReadInstructionBlock,
|
|
47
62
|
},
|
|
48
63
|
};
|
|
49
64
|
}
|
|
@@ -78,27 +93,56 @@ export function removeManagedBlock(existing) {
|
|
|
78
93
|
function escapeRegex(s) {
|
|
79
94
|
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
80
95
|
}
|
|
96
|
+
const MCP_COMMAND = 'npx';
|
|
97
|
+
const MCP_ARGS = ['-y', '@fabersep/memory', 'serve'];
|
|
98
|
+
function parseJsonObject(raw) {
|
|
99
|
+
if (!raw || !raw.trim())
|
|
100
|
+
return null;
|
|
101
|
+
try {
|
|
102
|
+
const parsed = JSON.parse(raw);
|
|
103
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
104
|
+
? parsed
|
|
105
|
+
: null;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function getJsonMcpEntry(raw) {
|
|
112
|
+
const obj = parseJsonObject(raw);
|
|
113
|
+
const servers = obj?.mcpServers;
|
|
114
|
+
if (!servers || typeof servers !== 'object')
|
|
115
|
+
return undefined;
|
|
116
|
+
return servers['faber-memory'];
|
|
117
|
+
}
|
|
118
|
+
function isWantedMcpEntry(entry) {
|
|
119
|
+
if (!entry || typeof entry !== 'object')
|
|
120
|
+
return false;
|
|
121
|
+
const e = entry;
|
|
122
|
+
return (e.command === MCP_COMMAND &&
|
|
123
|
+
Array.isArray(e.args) &&
|
|
124
|
+
JSON.stringify(e.args) === JSON.stringify(MCP_ARGS));
|
|
125
|
+
}
|
|
81
126
|
function upsertMcpJson(existingRaw) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
obj = {};
|
|
89
|
-
}
|
|
127
|
+
// Leave the file byte-for-byte alone when the entry is already right, so a
|
|
128
|
+
// second init never rewrites (and reformats) a file the assistant owns.
|
|
129
|
+
if (existingRaw !== null && isWantedMcpEntry(getJsonMcpEntry(existingRaw))) {
|
|
130
|
+
return existingRaw;
|
|
90
131
|
}
|
|
132
|
+
const obj = parseJsonObject(existingRaw) ?? {};
|
|
91
133
|
const servers = obj.mcpServers && typeof obj.mcpServers === 'object'
|
|
92
134
|
? { ...obj.mcpServers }
|
|
93
135
|
: {};
|
|
94
136
|
servers['faber-memory'] = {
|
|
95
|
-
command:
|
|
96
|
-
args: [
|
|
137
|
+
command: MCP_COMMAND,
|
|
138
|
+
args: [...MCP_ARGS],
|
|
97
139
|
};
|
|
98
140
|
obj.mcpServers = servers;
|
|
99
141
|
return JSON.stringify(obj, null, 2) + '\n';
|
|
100
142
|
}
|
|
101
143
|
function removeMcpJson(existingRaw) {
|
|
144
|
+
if (getJsonMcpEntry(existingRaw) === undefined)
|
|
145
|
+
return existingRaw;
|
|
102
146
|
let obj = {};
|
|
103
147
|
try {
|
|
104
148
|
obj = JSON.parse(existingRaw);
|
|
@@ -113,6 +157,46 @@ function removeMcpJson(existingRaw) {
|
|
|
113
157
|
}
|
|
114
158
|
return JSON.stringify(obj, null, 2) + '\n';
|
|
115
159
|
}
|
|
160
|
+
// Codex keeps MCP servers in TOML (`[mcp_servers.<name>]`). The Codex app
|
|
161
|
+
// rewrites config.toml itself and drops comments, so the table header is the
|
|
162
|
+
// only marker init relies on; zero-dependency line handling, no TOML parser.
|
|
163
|
+
const TOML_FABER_TABLE = /^\s*\[\s*mcp_servers\s*\.\s*(?:faber-memory|"faber-memory"|'faber-memory')\s*(\]|\.)/;
|
|
164
|
+
const TOML_ANY_TABLE = /^\s*\[/;
|
|
165
|
+
export function renderCodexTomlTable() {
|
|
166
|
+
return [
|
|
167
|
+
'[mcp_servers.faber-memory]',
|
|
168
|
+
`command = ${JSON.stringify(MCP_COMMAND)}`,
|
|
169
|
+
`args = [${MCP_ARGS.map((a) => JSON.stringify(a)).join(', ')}]`,
|
|
170
|
+
].join('\n');
|
|
171
|
+
}
|
|
172
|
+
export function hasCodexTomlEntry(raw) {
|
|
173
|
+
return Boolean(raw) && raw.split('\n').some((l) => TOML_FABER_TABLE.test(l));
|
|
174
|
+
}
|
|
175
|
+
export function upsertMcpToml(existingRaw) {
|
|
176
|
+
// An existing faber-memory table (ours, or edited by the user or the app) is kept as-is.
|
|
177
|
+
if (existingRaw !== null && hasCodexTomlEntry(existingRaw))
|
|
178
|
+
return existingRaw;
|
|
179
|
+
const trimmed = (existingRaw ?? '').trimEnd();
|
|
180
|
+
return trimmed ? `${trimmed}\n\n${renderCodexTomlTable()}\n` : `${renderCodexTomlTable()}\n`;
|
|
181
|
+
}
|
|
182
|
+
export function removeMcpToml(existingRaw) {
|
|
183
|
+
if (!hasCodexTomlEntry(existingRaw))
|
|
184
|
+
return existingRaw;
|
|
185
|
+
const out = [];
|
|
186
|
+
let skipping = false;
|
|
187
|
+
for (const line of existingRaw.split('\n')) {
|
|
188
|
+
if (TOML_FABER_TABLE.test(line)) {
|
|
189
|
+
skipping = true;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (skipping && TOML_ANY_TABLE.test(line))
|
|
193
|
+
skipping = false;
|
|
194
|
+
if (!skipping)
|
|
195
|
+
out.push(line);
|
|
196
|
+
}
|
|
197
|
+
const next = out.join('\n').replace(/\n{3,}/g, '\n\n').trimEnd();
|
|
198
|
+
return next ? `${next}\n` : '';
|
|
199
|
+
}
|
|
116
200
|
export function detectTargetEngines(userHome, requested) {
|
|
117
201
|
if (requested && requested.length > 0)
|
|
118
202
|
return requested;
|
|
@@ -123,6 +207,8 @@ export function detectTargetEngines(userHome, requested) {
|
|
|
123
207
|
detected.push('antigravity');
|
|
124
208
|
if (fs.existsSync(path.join(userHome, '.cursor')))
|
|
125
209
|
detected.push('cursor');
|
|
210
|
+
if (fs.existsSync(path.join(userHome, '.codex')))
|
|
211
|
+
detected.push('codex');
|
|
126
212
|
if (detected.length === 0)
|
|
127
213
|
detected.push('claude-code');
|
|
128
214
|
return detected;
|
|
@@ -167,6 +253,7 @@ export function planOrApplyInit(config, options = {}) {
|
|
|
167
253
|
before,
|
|
168
254
|
after,
|
|
169
255
|
changed,
|
|
256
|
+
action: planAction(changed, Boolean(options.undo), (before ?? '').includes(BLOCK_START)),
|
|
170
257
|
};
|
|
171
258
|
if (options.undo && fs.existsSync(`${filePath}.bak`)) {
|
|
172
259
|
plan.backupPath = `${filePath}.bak`;
|
|
@@ -178,12 +265,18 @@ export function planOrApplyInit(config, options = {}) {
|
|
|
178
265
|
const filePath = spec.mcpConfigFile(userHome);
|
|
179
266
|
const exists = fs.existsSync(filePath);
|
|
180
267
|
const before = exists ? fs.readFileSync(filePath, 'utf8') : null;
|
|
268
|
+
const toml = spec.mcpFormat === 'toml';
|
|
181
269
|
const after = options.undo
|
|
182
270
|
? before !== null
|
|
183
|
-
?
|
|
271
|
+
? toml
|
|
272
|
+
? removeMcpToml(before)
|
|
273
|
+
: removeMcpJson(before)
|
|
184
274
|
: ''
|
|
185
|
-
:
|
|
275
|
+
: toml
|
|
276
|
+
? upsertMcpToml(before)
|
|
277
|
+
: upsertMcpJson(before);
|
|
186
278
|
const changed = (before ?? '') !== after;
|
|
279
|
+
const hadEntry = toml ? hasCodexTomlEntry(before) : getJsonMcpEntry(before) !== undefined;
|
|
187
280
|
const plan = {
|
|
188
281
|
filePath,
|
|
189
282
|
kind: 'mcp-config',
|
|
@@ -191,6 +284,7 @@ export function planOrApplyInit(config, options = {}) {
|
|
|
191
284
|
before,
|
|
192
285
|
after,
|
|
193
286
|
changed,
|
|
287
|
+
action: planAction(changed, Boolean(options.undo), hadEntry),
|
|
194
288
|
};
|
|
195
289
|
if (options.undo && fs.existsSync(`${filePath}.bak`)) {
|
|
196
290
|
plan.backupPath = `${filePath}.bak`;
|
|
@@ -224,6 +318,13 @@ export function planOrApplyInit(config, options = {}) {
|
|
|
224
318
|
projectHint: options.projectHint ? PROJECT_HINT_LINE : undefined,
|
|
225
319
|
};
|
|
226
320
|
}
|
|
321
|
+
function planAction(changed, undo, hadEntry) {
|
|
322
|
+
if (!changed)
|
|
323
|
+
return 'unchanged';
|
|
324
|
+
if (undo)
|
|
325
|
+
return 'removed';
|
|
326
|
+
return hadEntry ? 'updated' : 'added';
|
|
327
|
+
}
|
|
227
328
|
export function formatUnifiedDiff(plan) {
|
|
228
329
|
const beforeLines = (plan.before ?? '').split('\n');
|
|
229
330
|
const afterLines = plan.after.split('\n');
|
|
@@ -248,7 +349,8 @@ export function formatPlanBeforeAfter(plan, useColor = shouldUseColor()) {
|
|
|
248
349
|
lines.push(`${c.bold(c.cyan(`[${plan.engine}]`, useColor), useColor)} ${c.bold(plan.kind, useColor)} — ${plan.filePath}`);
|
|
249
350
|
lines.push(c.dim(hr('─', 64), useColor));
|
|
250
351
|
if (!plan.changed) {
|
|
251
|
-
|
|
352
|
+
const present = (plan.before ?? '').includes(plan.kind === 'instruction' ? BLOCK_START : 'faber-memory');
|
|
353
|
+
lines.push(c.dim(present ? ' (no changes: the faber-memory part is already in place)' : ' (no changes)', useColor));
|
|
252
354
|
return lines.join('\n');
|
|
253
355
|
}
|
|
254
356
|
const beforeLines = (plan.before ?? '').split('\n');
|
|
@@ -260,7 +362,7 @@ export function formatPlanBeforeAfter(plan, useColor = shouldUseColor()) {
|
|
|
260
362
|
lines.push(c.dim(' (file does not exist yet)', useColor));
|
|
261
363
|
}
|
|
262
364
|
else if (removed.length === 0) {
|
|
263
|
-
lines.push(c.dim(' (
|
|
365
|
+
lines.push(c.dim(' (no lines removed)', useColor));
|
|
264
366
|
}
|
|
265
367
|
else {
|
|
266
368
|
for (const l of removed) {
|
|
@@ -270,12 +372,48 @@ export function formatPlanBeforeAfter(plan, useColor = shouldUseColor()) {
|
|
|
270
372
|
lines.push('');
|
|
271
373
|
lines.push(c.bold(c.green('After:', useColor), useColor));
|
|
272
374
|
if (added.length === 0) {
|
|
273
|
-
lines.push(c.dim(' (
|
|
375
|
+
lines.push(c.dim(' (no lines added)', useColor));
|
|
274
376
|
}
|
|
275
377
|
else {
|
|
276
378
|
for (const l of added) {
|
|
277
379
|
lines.push(c.green(` + ${l}`, useColor));
|
|
278
380
|
}
|
|
279
381
|
}
|
|
382
|
+
if (plan.backupPath) {
|
|
383
|
+
lines.push('');
|
|
384
|
+
lines.push(c.dim(`Backup: ${plan.backupPath}`, useColor));
|
|
385
|
+
}
|
|
280
386
|
return lines.join('\n');
|
|
281
387
|
}
|
|
388
|
+
const SUMMARY_TEXT = {
|
|
389
|
+
apply: { connect: 'connected', update: 'updated', same: 'already connected, nothing changed' },
|
|
390
|
+
preview: {
|
|
391
|
+
connect: 'would be connected',
|
|
392
|
+
update: 'would be updated',
|
|
393
|
+
same: 'already connected, nothing to change',
|
|
394
|
+
},
|
|
395
|
+
undo: { connect: 'disconnected', update: 'disconnected', same: 'was not connected' },
|
|
396
|
+
};
|
|
397
|
+
/** One plain line per assistant: what init did (or would do) there. */
|
|
398
|
+
export function formatInitSummary(plans, mode, useColor = shouldUseColor()) {
|
|
399
|
+
const specs = getEngineSpecs();
|
|
400
|
+
const engines = [...new Set(plans.map((p) => p.engine))];
|
|
401
|
+
if (engines.length === 0)
|
|
402
|
+
return c.dim(' No assistants found to connect.', useColor);
|
|
403
|
+
const width = Math.max(...engines.map((e) => (specs[e]?.label ?? e).length)) + 2;
|
|
404
|
+
return engines
|
|
405
|
+
.map((engine) => {
|
|
406
|
+
const mine = plans.filter((p) => p.engine === engine);
|
|
407
|
+
const actions = mine.map((p) => p.action ?? (p.changed ? 'updated' : 'unchanged'));
|
|
408
|
+
const key = actions.every((a) => a === 'unchanged')
|
|
409
|
+
? 'same'
|
|
410
|
+
: actions.some((a) => a === 'added')
|
|
411
|
+
? 'connect'
|
|
412
|
+
: 'update';
|
|
413
|
+
const label = (specs[engine]?.label ?? engine).padEnd(width);
|
|
414
|
+
const toolsOnly = specs[engine]?.gap && mode !== 'undo' ? ' (memory tools only)' : '';
|
|
415
|
+
const mark = key === 'same' ? c.dim('·', useColor) : c.green('✓', useColor);
|
|
416
|
+
return ` ${mark} ${c.bold(label, useColor)}${SUMMARY_TEXT[mode][key]}${toolsOnly}`;
|
|
417
|
+
})
|
|
418
|
+
.join('\n');
|
|
419
|
+
}
|
package/package.json
CHANGED