uncamp 0.0.0 → 0.1.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/LICENSE +21 -0
- package/README.md +65 -2
- package/agent-rules/project-rule.md +1 -0
- package/dist/approvals.js +47 -0
- package/dist/cli.js +52 -0
- package/dist/core.js +373 -0
- package/dist/guidance.js +399 -0
- package/dist/install/config.js +34 -0
- package/dist/install/hosts.js +7 -0
- package/dist/install/manifest.js +16 -0
- package/dist/mcp/server.js +248 -0
- package/dist/memory.js +199 -0
- package/dist/memoryTools.js +1 -0
- package/dist/preferences.js +97 -0
- package/dist/projectRoot.js +201 -0
- package/dist/scripts/sync.js +107 -0
- package/dist/session.js +158 -0
- package/dist/setup.js +502 -0
- package/dist/trash.js +208 -0
- package/dist/workloads.js +162 -0
- package/package.json +50 -5
- package/plugins/README.md +14 -0
- package/plugins/uncamp/hosts/rules-src/agents-plugin.md +3 -0
- package/plugins/uncamp/hosts/rules-src/project-cursor.mdc +8 -0
- package/plugins/uncamp/uncamp-install.json +191 -0
- package/skills/uncamp/SKILL.md +49 -0
- package/skills/uncamp-hygienic-setup/SKILL.md +17 -0
- package/skills/uncamp-memory-writer/SKILL.md +16 -0
- package/skills/uncamp-session-end/SKILL.md +33 -0
package/dist/setup.js
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { cp, mkdir, readFile, writeFile, copyFile, access } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { writePreferences } from "./preferences.js";
|
|
8
|
+
import { syncPlugins } from "./scripts/sync.js";
|
|
9
|
+
import { defaultIndexPath, removeProject } from "./projectRoot.js";
|
|
10
|
+
import { moveOwnedPathToTrash } from "./trash.js";
|
|
11
|
+
import { backupBeforeEdit } from "./install/config.js";
|
|
12
|
+
import { readManifest, writeManifest } from "./install/manifest.js";
|
|
13
|
+
import { validateHosts } from "./install/hosts.js";
|
|
14
|
+
const hosts = ["codex", "claude", "cursor"];
|
|
15
|
+
const skills = ["uncamp", "uncamp-session-end", "uncamp-memory-writer", "uncamp-hygienic-setup"];
|
|
16
|
+
const home = () => process.env.HOME || os.homedir();
|
|
17
|
+
const root = () => path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
18
|
+
const exists = async (file) => {
|
|
19
|
+
try {
|
|
20
|
+
await access(file);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
async function readJson(file) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(await readFile(file, "utf8"));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function writeJson(file, data) {
|
|
36
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
37
|
+
await writeFile(file, JSON.stringify(data, null, 2) + "\n");
|
|
38
|
+
}
|
|
39
|
+
async function trash(file) {
|
|
40
|
+
if (!(await exists(file)))
|
|
41
|
+
return undefined;
|
|
42
|
+
return moveOwnedPathToTrash(file);
|
|
43
|
+
}
|
|
44
|
+
function ruleBlock(canonical) {
|
|
45
|
+
return `<!-- uncamp-rule:start v=2.0 -->\n${canonical.trim()}\n<!-- uncamp-rule:end -->`;
|
|
46
|
+
}
|
|
47
|
+
const RULE_RE = /<!-- uncamp-rule:start(?: v=[^>]*)? -->[\s\S]*?<!-- uncamp-rule:end -->/;
|
|
48
|
+
/** Cursor applies a `.mdc` rule on every request only with `alwaysApply: true` frontmatter (from the template). */
|
|
49
|
+
async function cursorFrontmatter() {
|
|
50
|
+
const template = await readFile(path.join(root(), "plugins/uncamp/hosts/rules-src/project-cursor.mdc"), "utf8");
|
|
51
|
+
const match = template.match(/^---\n[\s\S]*?\n---\n/);
|
|
52
|
+
return match ? match[0] : "---\nalwaysApply: true\n---\n";
|
|
53
|
+
}
|
|
54
|
+
/** True when a rule file holds nothing but optional frontmatter. */
|
|
55
|
+
function onlyFrontmatter(text) {
|
|
56
|
+
return !text.replace(/^---\n[\s\S]*?\n---\n?/, "").trim();
|
|
57
|
+
}
|
|
58
|
+
async function editRule(file, remove = false) {
|
|
59
|
+
let old = "";
|
|
60
|
+
try {
|
|
61
|
+
old = await readFile(file, "utf8");
|
|
62
|
+
}
|
|
63
|
+
catch { }
|
|
64
|
+
const canonical = await readFile(path.join(root(), "agent-rules/project-rule.md"), "utf8");
|
|
65
|
+
const block = ruleBlock(canonical);
|
|
66
|
+
let next = remove
|
|
67
|
+
? old.replace(new RegExp(RULE_RE.source + "\\n?", "g"), "").trimEnd() + "\n"
|
|
68
|
+
: RULE_RE.test(old)
|
|
69
|
+
? old.replace(RULE_RE, block)
|
|
70
|
+
: `${old.trimEnd()}${old.trim() ? "\n\n" : ""}${block}\n`;
|
|
71
|
+
if (!remove && file.endsWith(".mdc") && !old.trim())
|
|
72
|
+
next = `${await cursorFrontmatter()}\n${block}\n`;
|
|
73
|
+
if (!old && remove)
|
|
74
|
+
next = old;
|
|
75
|
+
if (next !== old) {
|
|
76
|
+
const backup = await backupBeforeEdit(file);
|
|
77
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
78
|
+
await writeFile(file, next);
|
|
79
|
+
return { changed: true, backup };
|
|
80
|
+
}
|
|
81
|
+
return { changed: false, backup: undefined };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The node binary for MCP entries. A Homebrew Cellar path names one node version and breaks on upgrade,
|
|
85
|
+
* so prefer the stable `opt` link for the same formula when it exists.
|
|
86
|
+
*/
|
|
87
|
+
export function stableNodePath(execPath = process.execPath) {
|
|
88
|
+
const match = execPath.match(/^(.*)\/Cellar\/([^/]+)\/[^/]+\/bin\/node$/);
|
|
89
|
+
if (match) {
|
|
90
|
+
const stable = path.join(match[1], "opt", match[2], "bin", "node");
|
|
91
|
+
if (existsSync(stable))
|
|
92
|
+
return stable;
|
|
93
|
+
}
|
|
94
|
+
return execPath;
|
|
95
|
+
}
|
|
96
|
+
const mcpConfig = (cli) => ({ command: stableNodePath(), args: [cli, "mcp"] });
|
|
97
|
+
function removeTomlSection(text, header) {
|
|
98
|
+
let skip = false;
|
|
99
|
+
const kept = text.split(/\r?\n/).filter((line) => {
|
|
100
|
+
const section = line.match(/^\[([^\]]+)\]$/)?.[1];
|
|
101
|
+
if (section)
|
|
102
|
+
skip = section === header || section.startsWith(`${header}.`);
|
|
103
|
+
return !skip;
|
|
104
|
+
});
|
|
105
|
+
return (kept
|
|
106
|
+
.join("\n")
|
|
107
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
108
|
+
.trimEnd() + "\n");
|
|
109
|
+
}
|
|
110
|
+
function tomlSection(text, header) {
|
|
111
|
+
let active = false;
|
|
112
|
+
const selected = [];
|
|
113
|
+
for (const line of text.split(/\r?\n/)) {
|
|
114
|
+
const section = line.match(/^\[([^\]]+)\]$/)?.[1];
|
|
115
|
+
if (section)
|
|
116
|
+
active = section === header || section.startsWith(`${header}.`);
|
|
117
|
+
if (active)
|
|
118
|
+
selected.push(line);
|
|
119
|
+
}
|
|
120
|
+
return selected.join("\n");
|
|
121
|
+
}
|
|
122
|
+
function isLegacyMcp(entry) {
|
|
123
|
+
return (Array.isArray(entry?.args) &&
|
|
124
|
+
entry.args.some((arg) => typeof arg === "string" && arg.includes("trace_runtime.mcp_server")));
|
|
125
|
+
}
|
|
126
|
+
function skillRoot(base, host) {
|
|
127
|
+
return path.join(base, host === "codex" ? ".agents/skills" : host === "claude" ? ".claude/skills" : ".cursor/skills");
|
|
128
|
+
}
|
|
129
|
+
async function copySkills(source, destinationRoot, created, previouslyCreated, actions, host) {
|
|
130
|
+
await mkdir(destinationRoot, { recursive: true });
|
|
131
|
+
for (const skill of skills) {
|
|
132
|
+
const destination = path.join(destinationRoot, skill);
|
|
133
|
+
const existed = await exists(destination);
|
|
134
|
+
const relative = path.relative(home(), destination);
|
|
135
|
+
if (existed && !previouslyCreated.has(relative)) {
|
|
136
|
+
actions.push(`left pre-existing skill unchanged: ${destination}`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
await cp(path.join(source, "skills", skill), destination, { recursive: true, force: true });
|
|
140
|
+
if (!existed)
|
|
141
|
+
created.add(relative);
|
|
142
|
+
actions.push(`copied ${host} skill ${skill} -> ${destination}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function configEdit(file, next, actions) {
|
|
146
|
+
let before = "";
|
|
147
|
+
try {
|
|
148
|
+
before = await readFile(file, "utf8");
|
|
149
|
+
}
|
|
150
|
+
catch { }
|
|
151
|
+
if (next === before)
|
|
152
|
+
return false;
|
|
153
|
+
const backup = await backupBeforeEdit(file);
|
|
154
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
155
|
+
await writeFile(file, next);
|
|
156
|
+
actions.push(`edited ${file}${backup ? `; backup: ${backup}` : ""}`);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
// Dependencies sit in the package's own node_modules in a checkout or a global install, and beside the package
|
|
160
|
+
// (hoisted into the parent node_modules) when it runs from npx or a local install.
|
|
161
|
+
async function copyDependencies(source, destination) {
|
|
162
|
+
const own = path.join(source, "node_modules");
|
|
163
|
+
if (await exists(own)) {
|
|
164
|
+
await cp(own, destination, { recursive: true });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const parent = path.dirname(source);
|
|
168
|
+
if (path.basename(parent) !== "node_modules")
|
|
169
|
+
throw new Error(`uncamp dependencies not found near ${source}`);
|
|
170
|
+
const self = path.basename(source);
|
|
171
|
+
await cp(parent, destination, {
|
|
172
|
+
recursive: true,
|
|
173
|
+
filter: (item) => {
|
|
174
|
+
const first = path.relative(parent, item).split(path.sep)[0];
|
|
175
|
+
return first !== self && first !== ".bin" && first !== ".package-lock.json";
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async function installRuntime(source, runtime, actions) {
|
|
180
|
+
if (await exists(runtime)) {
|
|
181
|
+
const moved = await trash(runtime);
|
|
182
|
+
actions.push(`moved previous runtime to Trash: ${runtime} -> ${moved}`);
|
|
183
|
+
}
|
|
184
|
+
await mkdir(path.dirname(runtime), { recursive: true });
|
|
185
|
+
for (const folder of ["dist", "skills", "agent-rules", "plugins"]) {
|
|
186
|
+
await cp(path.join(source, folder), path.join(runtime, folder), { recursive: true });
|
|
187
|
+
}
|
|
188
|
+
await copyFile(path.join(source, "package.json"), path.join(runtime, "package.json"));
|
|
189
|
+
await copyDependencies(source, path.join(runtime, "node_modules"));
|
|
190
|
+
await syncPlugins(path.join(runtime, "plugins-build"));
|
|
191
|
+
actions.push(`refreshed runtime -> ${runtime}`);
|
|
192
|
+
}
|
|
193
|
+
async function runClaude(args) {
|
|
194
|
+
const command = process.env.UNCAMP_CLAUDE_CLI || "claude";
|
|
195
|
+
const result = spawnSync(command, args, { encoding: "utf8" });
|
|
196
|
+
if (result.error || result.status !== 0) {
|
|
197
|
+
return `Claude CLI unavailable or failed; run manually: ${[command, ...args].join(" ")}`;
|
|
198
|
+
}
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
export async function runInstall(requested, dry = false) {
|
|
202
|
+
const base = home();
|
|
203
|
+
const selectedHosts = validateHosts(requested ?? hosts.filter((host) => existsSync(path.join(base, `.${host}`))));
|
|
204
|
+
const stateRoot = process.env.UNCAMP_HOME || path.join(base, ".uncamp");
|
|
205
|
+
const optOutFile = path.join(stateRoot, "host-opt-outs.json");
|
|
206
|
+
const optOuts = new Set();
|
|
207
|
+
try {
|
|
208
|
+
const data = JSON.parse(await readFile(optOutFile, "utf8"));
|
|
209
|
+
for (const host of Array.isArray(data.hosts) ? data.hosts : [])
|
|
210
|
+
if (typeof host === "string" && host.trim())
|
|
211
|
+
optOuts.add(host.trim().toLowerCase());
|
|
212
|
+
}
|
|
213
|
+
catch { }
|
|
214
|
+
for (const host of (process.env.UNCAMP_DISABLED_HOSTS ?? "").split(","))
|
|
215
|
+
if (host.trim())
|
|
216
|
+
optOuts.add(host.trim().toLowerCase());
|
|
217
|
+
const selected = selectedHosts.filter((host) => !optOuts.has(host));
|
|
218
|
+
const source = root();
|
|
219
|
+
const runtime = path.join(base, ".uncamp/runtime");
|
|
220
|
+
const cli = path.join(runtime, "dist/cli.js");
|
|
221
|
+
const manifestFile = path.join(base, ".uncamp/install-manifest.json");
|
|
222
|
+
const actions = selectedHosts
|
|
223
|
+
.filter((host) => optOuts.has(host))
|
|
224
|
+
.map((host) => `skipped ${host}: ~/.uncamp/host-opt-outs.json disables this host`);
|
|
225
|
+
const created = new Set();
|
|
226
|
+
if (!selected.length)
|
|
227
|
+
return actions;
|
|
228
|
+
if (dry) {
|
|
229
|
+
actions.push(`would refresh runtime -> ${runtime}`);
|
|
230
|
+
for (const host of selected) {
|
|
231
|
+
actions.push(`would install ${host}`);
|
|
232
|
+
for (const skill of skills) {
|
|
233
|
+
actions.push(`would copy ${host} skill ${skill} -> ${path.join(skillRoot(base, host), skill)}`);
|
|
234
|
+
}
|
|
235
|
+
const rules = host === "codex"
|
|
236
|
+
? [".codex/AGENTS.md"]
|
|
237
|
+
: host === "cursor"
|
|
238
|
+
? [".cursor/rules/uncamp.mdc"]
|
|
239
|
+
: [".claude/CLAUDE.md"];
|
|
240
|
+
for (const rel of rules)
|
|
241
|
+
actions.push(`would configure rule -> ${path.join(base, rel)}`);
|
|
242
|
+
if (host === "claude") {
|
|
243
|
+
const marketplace = path.join(base, ".uncamp-plugins/marketplace");
|
|
244
|
+
actions.push(`would run claude plugin marketplace add and plugin install for ${marketplace}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return actions;
|
|
248
|
+
}
|
|
249
|
+
const previous = await readManifest(base);
|
|
250
|
+
const previouslyCreated = new Set(Array.isArray(previous.created) ? previous.created : []);
|
|
251
|
+
const mcpHosts = new Set(Array.isArray(previous.mcp_hosts) ? previous.mcp_hosts : []);
|
|
252
|
+
await installRuntime(source, runtime, actions);
|
|
253
|
+
for (const host of selected) {
|
|
254
|
+
if (host === "codex") {
|
|
255
|
+
const file = path.join(base, ".codex/config.toml");
|
|
256
|
+
let text = "";
|
|
257
|
+
try {
|
|
258
|
+
text = await readFile(file, "utf8");
|
|
259
|
+
}
|
|
260
|
+
catch { }
|
|
261
|
+
const expected = mcpConfig(cli);
|
|
262
|
+
const old = tomlSection(text, "mcp_servers.uncamp");
|
|
263
|
+
if (old &&
|
|
264
|
+
!old.includes("trace_runtime.mcp_server") &&
|
|
265
|
+
!old.includes(JSON.stringify(cli)) &&
|
|
266
|
+
!mcpHosts.has(host) &&
|
|
267
|
+
!(old.includes(`command = ${JSON.stringify(expected.command)}`) &&
|
|
268
|
+
old.includes(`args = [${JSON.stringify(cli)}, "mcp"]`))) {
|
|
269
|
+
throw new Error("uncamp MCP server is already in use by another configuration");
|
|
270
|
+
}
|
|
271
|
+
const mcpMatches = old.includes(`command = ${JSON.stringify(expected.command)}`) &&
|
|
272
|
+
old.includes(`args = [${JSON.stringify(cli)}, "mcp"]`);
|
|
273
|
+
text = removeTomlSection(text, "mcp_servers.uncamp");
|
|
274
|
+
text += `\n[mcp_servers.uncamp]\ncommand = ${JSON.stringify(expected.command)}\n`;
|
|
275
|
+
text += `args = [${JSON.stringify(cli)}, "mcp"]\n`;
|
|
276
|
+
text = removeTomlSection(text, "marketplaces.uncamp-local");
|
|
277
|
+
text = removeTomlSection(text, 'plugins."uncamp@uncamp-local"');
|
|
278
|
+
const marketplace = path.join(runtime, "plugins-build/marketplaces/uncamp");
|
|
279
|
+
text += `\n[marketplaces.uncamp-local]\nsource_type = "local"\n`;
|
|
280
|
+
text += `source = ${JSON.stringify(marketplace)}\n\n`;
|
|
281
|
+
text += '[plugins."uncamp@uncamp-local"]\nenabled = true\n';
|
|
282
|
+
await configEdit(file, text, actions);
|
|
283
|
+
if (!mcpMatches || mcpHosts.has(host) || old.includes("trace_runtime.mcp_server"))
|
|
284
|
+
mcpHosts.add(host);
|
|
285
|
+
for (const rel of [".codex/AGENTS.md"]) {
|
|
286
|
+
const result = await editRule(path.join(base, rel));
|
|
287
|
+
if (result.changed) {
|
|
288
|
+
actions.push(`edited ${path.join(base, rel)}${result.backup ? `; backup: ${result.backup}` : ""}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
await copySkills(source, skillRoot(base, host), created, previouslyCreated, actions, host);
|
|
292
|
+
}
|
|
293
|
+
else if (host === "cursor") {
|
|
294
|
+
const file = path.join(base, ".cursor/mcp.json");
|
|
295
|
+
const data = await readJson(file);
|
|
296
|
+
const before = JSON.stringify(data);
|
|
297
|
+
data.mcpServers ??= {};
|
|
298
|
+
const old = data.mcpServers.uncamp;
|
|
299
|
+
const expected = mcpConfig(cli);
|
|
300
|
+
if (old && old.command !== expected.command && !isLegacyMcp(old) && !(old.args ?? []).includes(cli)) {
|
|
301
|
+
throw new Error("uncamp MCP server is already in use by another configuration");
|
|
302
|
+
}
|
|
303
|
+
const matches = old?.command === expected.command && JSON.stringify(old.args) === JSON.stringify(expected.args);
|
|
304
|
+
data.mcpServers.uncamp = expected;
|
|
305
|
+
if (JSON.stringify(data) !== before) {
|
|
306
|
+
const backup = await backupBeforeEdit(file);
|
|
307
|
+
await writeJson(file, data);
|
|
308
|
+
actions.push(`edited ${file}${backup ? `; backup: ${backup}` : ""}`);
|
|
309
|
+
}
|
|
310
|
+
if (!matches || mcpHosts.has(host) || isLegacyMcp(old))
|
|
311
|
+
mcpHosts.add(host);
|
|
312
|
+
const plugin = path.join(base, ".cursor/plugins/local/uncamp");
|
|
313
|
+
await mkdir(path.dirname(plugin), { recursive: true });
|
|
314
|
+
await cp(path.join(runtime, "plugins-build/cursor"), plugin, { recursive: true, force: true });
|
|
315
|
+
created.add(path.relative(base, plugin));
|
|
316
|
+
actions.push(`copied Cursor plugin -> ${plugin}`);
|
|
317
|
+
const result = await editRule(path.join(base, ".cursor/rules/uncamp.mdc"));
|
|
318
|
+
if (result.changed) {
|
|
319
|
+
const file = path.join(base, ".cursor/rules/uncamp.mdc");
|
|
320
|
+
actions.push(`edited ${file}${result.backup ? `; backup: ${result.backup}` : ""}`);
|
|
321
|
+
}
|
|
322
|
+
await copySkills(source, skillRoot(base, host), created, previouslyCreated, actions, host);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
const legacyFile = path.join(base, ".claude.json");
|
|
326
|
+
const legacy = await readJson(legacyFile);
|
|
327
|
+
if (isLegacyMcp(legacy.mcpServers?.uncamp)) {
|
|
328
|
+
delete legacy.mcpServers.uncamp;
|
|
329
|
+
if (!Object.keys(legacy.mcpServers).length)
|
|
330
|
+
delete legacy.mcpServers;
|
|
331
|
+
const backup = await backupBeforeEdit(legacyFile);
|
|
332
|
+
await writeJson(legacyFile, legacy);
|
|
333
|
+
actions.push(`edited ${legacyFile}${backup ? `; backup: ${backup}` : ""}`);
|
|
334
|
+
}
|
|
335
|
+
const market = path.join(base, ".uncamp-plugins/marketplace");
|
|
336
|
+
await mkdir(path.dirname(market), { recursive: true });
|
|
337
|
+
await cp(path.join(runtime, "plugins-build/marketplaces/uncamp"), market, { recursive: true, force: true });
|
|
338
|
+
await writeJson(path.join(market, ".mcp.json"), { mcpServers: { uncamp: mcpConfig(cli) } });
|
|
339
|
+
created.add(path.relative(base, market));
|
|
340
|
+
actions.push(`copied Claude marketplace -> ${market}`);
|
|
341
|
+
const marketplaceFailure = await runClaude(["plugin", "marketplace", "add", market, "--scope", "user"]);
|
|
342
|
+
if (marketplaceFailure)
|
|
343
|
+
actions.push(marketplaceFailure);
|
|
344
|
+
const pluginFailure = await runClaude(["plugin", "install", "uncamp@uncamp-local", "--scope", "user"]);
|
|
345
|
+
if (pluginFailure)
|
|
346
|
+
actions.push(pluginFailure);
|
|
347
|
+
const result = await editRule(path.join(base, ".claude/CLAUDE.md"));
|
|
348
|
+
if (result.changed) {
|
|
349
|
+
const file = path.join(base, ".claude/CLAUDE.md");
|
|
350
|
+
actions.push(`edited ${file}${result.backup ? `; backup: ${result.backup}` : ""}`);
|
|
351
|
+
}
|
|
352
|
+
await copySkills(source, skillRoot(base, host), created, previouslyCreated, actions, host);
|
|
353
|
+
}
|
|
354
|
+
actions.push(`installed ${host}`);
|
|
355
|
+
}
|
|
356
|
+
created.add(".uncamp/runtime");
|
|
357
|
+
const exactCreated = [...created];
|
|
358
|
+
const previousCreated = Array.isArray(previous.created) ? previous.created : [];
|
|
359
|
+
const manifest = {
|
|
360
|
+
hosts: [...new Set([...(Array.isArray(previous.hosts) ? previous.hosts : []), ...selected])].sort(),
|
|
361
|
+
mcp_hosts: [...mcpHosts],
|
|
362
|
+
created: [...new Set([...previousCreated, ...exactCreated])],
|
|
363
|
+
installed_at: new Date().toISOString(),
|
|
364
|
+
};
|
|
365
|
+
const manifestPath = await writeManifest(base, manifest);
|
|
366
|
+
actions.push(`wrote install manifest -> ${manifestPath}`);
|
|
367
|
+
return actions;
|
|
368
|
+
}
|
|
369
|
+
export async function runUninstall(requested, dry = false) {
|
|
370
|
+
const base = home();
|
|
371
|
+
const manifest = await readManifest(base);
|
|
372
|
+
const selected = validateHosts(requested ?? manifest.hosts ?? []);
|
|
373
|
+
const mcpHosts = new Set(Array.isArray(manifest.mcp_hosts) ? manifest.mcp_hosts : []);
|
|
374
|
+
const actions = [];
|
|
375
|
+
if (dry) {
|
|
376
|
+
for (const host of selected) {
|
|
377
|
+
actions.push(`would uninstall ${host}`);
|
|
378
|
+
actions.push(`would remove ${host} rule block`);
|
|
379
|
+
for (const skill of skills)
|
|
380
|
+
actions.push(`would move ${path.join(skillRoot(base, host), skill)} to Trash`);
|
|
381
|
+
}
|
|
382
|
+
for (const rel of manifest.created ?? [])
|
|
383
|
+
actions.push(`would move ${path.join(base, rel)} to Trash`);
|
|
384
|
+
return actions;
|
|
385
|
+
}
|
|
386
|
+
for (const host of selected) {
|
|
387
|
+
if (host === "codex") {
|
|
388
|
+
const file = path.join(base, ".codex/config.toml");
|
|
389
|
+
let text = "";
|
|
390
|
+
try {
|
|
391
|
+
text = await readFile(file, "utf8");
|
|
392
|
+
}
|
|
393
|
+
catch { }
|
|
394
|
+
const before = text;
|
|
395
|
+
if (await exists(file)) {
|
|
396
|
+
if (mcpHosts.has(host))
|
|
397
|
+
text = removeTomlSection(text, "mcp_servers.uncamp");
|
|
398
|
+
text = removeTomlSection(text, "marketplaces.uncamp-local");
|
|
399
|
+
text = removeTomlSection(text, 'plugins."uncamp@uncamp-local"');
|
|
400
|
+
await configEdit(file, text, actions);
|
|
401
|
+
}
|
|
402
|
+
for (const rel of [".codex/AGENTS.md"]) {
|
|
403
|
+
const result = await editRule(path.join(base, rel), true);
|
|
404
|
+
if (result.changed) {
|
|
405
|
+
actions.push(`edited ${path.join(base, rel)}${result.backup ? `; backup: ${result.backup}` : ""}`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else if (host === "cursor") {
|
|
410
|
+
const file = path.join(base, ".cursor/mcp.json");
|
|
411
|
+
if (await exists(file)) {
|
|
412
|
+
const data = await readJson(file);
|
|
413
|
+
const before = JSON.stringify(data);
|
|
414
|
+
if (mcpHosts.has(host) && data.mcpServers)
|
|
415
|
+
delete data.mcpServers.uncamp;
|
|
416
|
+
if (JSON.stringify(data) !== before) {
|
|
417
|
+
const backup = await backupBeforeEdit(file);
|
|
418
|
+
await writeJson(file, data);
|
|
419
|
+
actions.push(`edited ${file}${backup ? `; backup: ${backup}` : ""}`);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const ruleFile = path.join(base, ".cursor/rules/uncamp.mdc");
|
|
423
|
+
const result = await editRule(ruleFile, true);
|
|
424
|
+
if (result.changed)
|
|
425
|
+
actions.push(`edited ${ruleFile}${result.backup ? `; backup: ${result.backup}` : ""}`);
|
|
426
|
+
if ((await exists(ruleFile)) && onlyFrontmatter(await readFile(ruleFile, "utf8"))) {
|
|
427
|
+
const moved = await trash(ruleFile);
|
|
428
|
+
if (moved)
|
|
429
|
+
actions.push(`moved empty Cursor rule to Trash: ${ruleFile} -> ${moved}`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
const failed = await runClaude(["plugin", "uninstall", "uncamp@uncamp-local", "--scope", "user"]);
|
|
434
|
+
if (failed)
|
|
435
|
+
actions.push(failed);
|
|
436
|
+
const marketFailed = await runClaude(["plugin", "marketplace", "remove", "uncamp-local", "--scope", "user"]);
|
|
437
|
+
if (marketFailed)
|
|
438
|
+
actions.push(marketFailed);
|
|
439
|
+
const result = await editRule(path.join(base, ".claude/CLAUDE.md"), true);
|
|
440
|
+
if (result.changed) {
|
|
441
|
+
const ruleFile = path.join(base, ".claude/CLAUDE.md");
|
|
442
|
+
actions.push(`edited ${ruleFile}${result.backup ? `; backup: ${result.backup}` : ""}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
actions.push(`uninstalled ${host}`);
|
|
446
|
+
}
|
|
447
|
+
const skillPaths = new Set(selected.flatMap((host) => skills.map((skill) => path.join(skillRoot(base, host), skill))));
|
|
448
|
+
const owned = new Set((manifest.created ?? []).map((rel) => path.resolve(base, rel)));
|
|
449
|
+
const remainingHosts = (manifest.hosts ?? []).filter((host) => !selected.includes(host));
|
|
450
|
+
const targets = [...owned].filter((target) => (target === path.join(base, ".uncamp/runtime") && !remainingHosts.length) ||
|
|
451
|
+
(target === path.join(base, ".uncamp-plugins/marketplace") && selected.includes("claude")) ||
|
|
452
|
+
(target === path.join(base, ".cursor/plugins/local/uncamp") && selected.includes("cursor")) ||
|
|
453
|
+
skillPaths.has(target));
|
|
454
|
+
for (const target of targets) {
|
|
455
|
+
const moved = await trash(target);
|
|
456
|
+
if (moved)
|
|
457
|
+
actions.push(`moved uncamp-created path to Trash: ${target} -> ${moved}`);
|
|
458
|
+
}
|
|
459
|
+
const remaining = (manifest.created ?? []).filter((rel) => !targets.includes(path.resolve(base, rel)));
|
|
460
|
+
if (!remainingHosts.length && !remaining.length) {
|
|
461
|
+
const manifestFile = path.join(base, ".uncamp/install-manifest.json");
|
|
462
|
+
const moved = await trash(manifestFile);
|
|
463
|
+
if (moved)
|
|
464
|
+
actions.push(`moved install manifest to Trash: ${manifestFile} -> ${moved}`);
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
const file = await writeManifest(base, { ...manifest, hosts: remainingHosts, created: remaining });
|
|
468
|
+
actions.push(`updated install manifest -> ${file}`);
|
|
469
|
+
}
|
|
470
|
+
return actions;
|
|
471
|
+
}
|
|
472
|
+
export async function configureProject(project, agents) {
|
|
473
|
+
const root = path.resolve(project);
|
|
474
|
+
if (!hosts.includes(agents[0] ?? ""))
|
|
475
|
+
throw new Error("unknown host");
|
|
476
|
+
if (existsSync(path.join(root, ".uncamp", "opt-out")))
|
|
477
|
+
throw new Error(`uncamp is opted out for this project: ${root}`);
|
|
478
|
+
const prefs = await import("./preferences.js");
|
|
479
|
+
const old = await prefs.loadPreferences(root);
|
|
480
|
+
const merged = [...new Set([...(old.agents ?? []), ...agents])].sort();
|
|
481
|
+
await writePreferences(root, { configured: true, agents: merged });
|
|
482
|
+
const rulePath = agents.includes("cursor")
|
|
483
|
+
? ".cursor/rules/uncamp.mdc"
|
|
484
|
+
: agents.includes("claude")
|
|
485
|
+
? "CLAUDE.local.md"
|
|
486
|
+
: "AGENTS.local.md";
|
|
487
|
+
const rule = path.join(root, rulePath);
|
|
488
|
+
await editRule(rule);
|
|
489
|
+
return [`configured ${agents.join(", ")}`];
|
|
490
|
+
}
|
|
491
|
+
export async function unconfigureProject(project) {
|
|
492
|
+
const root = path.resolve(project);
|
|
493
|
+
await writePreferences(root, { configured: false, agents: [] });
|
|
494
|
+
for (const rel of ["AGENTS.local.md", "CLAUDE.local.md", ".cursor/rules/uncamp.mdc"]) {
|
|
495
|
+
const file = path.join(root, rel);
|
|
496
|
+
const result = await editRule(file, true);
|
|
497
|
+
if (result.changed && onlyFrontmatter(await readFile(file, "utf8")))
|
|
498
|
+
await trash(file);
|
|
499
|
+
}
|
|
500
|
+
await removeProject(defaultIndexPath(), root);
|
|
501
|
+
return ["removed uncamp project wiring"];
|
|
502
|
+
}
|