@amoree-code/ocean 1.10.1 → 1.12.0

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 CHANGED
@@ -104,6 +104,20 @@ A connected client opened in that folder starts with a bounded Ocean context lin
104
104
  and read your records over MCP, and proposes facts worth keeping. `ocean memory review`
105
105
  approves or rejects them; `ocean clients restore` undoes the last `clients apply`.
106
106
 
107
+ ## Uninstall
108
+
109
+ ```bash
110
+ ocean uninstall # shows what it would remove; changes nothing
111
+ ocean uninstall --yes # puts every client config, hook, service and shell line back
112
+ npm uninstall --global @amoree-code/ocean
113
+ ```
114
+
115
+ It removes only what Ocean wrote: the MCP entries, hooks and native-memory switches from
116
+ `clients apply`, the skills and rules Ocean copied into clients, the login service and Desktop
117
+ watcher, the shell profile block and the shims. Your workspace is kept, and running
118
+ `ocean setup` again reconnects it. `--purge` deletes the workspace too, after you type its
119
+ folder name; it refuses a workspace that is a git checkout or holds the running engine.
120
+
107
121
  ## Commands
108
122
 
109
123
  `ocean --help` lists every command; `ocean <command> --help` (or `-h`, anywhere before `--`)
@@ -115,6 +129,7 @@ prints its usage and never runs it. To hand `--help` to a wrapped client, put it
115
129
  | Command | What it does | Kind |
116
130
  | --- | --- | --- |
117
131
  | `ocean setup` | create the workspace, shims, shell line and login service | Writes (also outside: shell profile, login service) |
132
+ | `ocean uninstall` | undo `setup` and `clients apply` outside the workspace; `--purge` also deletes the workspace | Reads; `--yes` writes (also outside: client configs, shell profile, login service) |
118
133
  | `ocean onboard` | run the pending first-run steps | Writes; `--status` reads |
119
134
  | `ocean context` | the workspace context for this folder; `cost` measures each client's always-on context | Reads |
120
135
  | `ocean project` | resolve, bind, register, rename, move and index projects | Reads; `bind`, `register`, `rename`, `unbind`, `--write` write |
@@ -200,6 +215,13 @@ See [skills/index.json](packages/harness/skills/index.json) for the current cata
200
215
  `ocean skill learn <completed-session-id>` extracts a candidate skill from a finished
201
216
  session, and `ocean skill review <candidate-id> promoted` activates it.
202
217
 
218
+ Skills reach every client by themselves. At each session start Ocean copies any new or updated
219
+ skill — the engine's core skills, and the ones in the skill hub (`bridge/skills/`, where
220
+ `ocean market install` puts a skill and where you can make your own) — into Claude, Codex,
221
+ Gemini and Hermes. `ocean market install|update` copies at once, and `ocean market uninstall`
222
+ removes the copies it made. A copy you edited inside a client after Ocean's version is left as
223
+ you wrote it. `ocean skill sync` still does the core skills by hand.
224
+
203
225
  ## Public engine, private workspace, machine state
204
226
 
205
227
  ```text
@@ -683,6 +683,60 @@ export async function restoreClients(options = {}) {
683
683
  }
684
684
  return { batch, restored, conflicts };
685
685
  }
686
+ // `ocean uninstall`: removes every Ocean-managed MCP entry still in a client config, journaled or
687
+ // not — the `ocean` brain server (not a legacy Obsidian one, which is the owner's server under
688
+ // Ocean's old name), entries that start marketplace servers or the gateway, and dead atlas
689
+ // entries. Each removal is journaled like an apply, so `ocean clients restore` can put it back.
690
+ export async function removeOceanEntries(options = {}) {
691
+ const env = options.env ?? defaultClientEnv();
692
+ const batch = options.batch ?? newBatch();
693
+ const removed = [];
694
+ const left = [];
695
+ for (const adapter of CLIENT_ADAPTERS) {
696
+ const config = adapter.config;
697
+ if (!config)
698
+ continue;
699
+ const file = path.join(env.home, config.file);
700
+ if (!existsSync(file))
701
+ continue;
702
+ let keys = [];
703
+ try {
704
+ await edit(file, (text) => {
705
+ const servers = config.editor.servers(text);
706
+ keys = servers
707
+ ? [...servers]
708
+ .filter(([key, value]) => (key === "ocean" &&
709
+ isOceanShaped(value) &&
710
+ !runsObsidian(value)) ||
711
+ isMarketExec(value) ||
712
+ (staleAtlas(key, value) && isOceanShaped(value)))
713
+ .map(([key]) => key)
714
+ : [];
715
+ if (!servers || !keys.length)
716
+ return null;
717
+ const ops = keys.map((key) => ({ kind: "remove", key }));
718
+ return {
719
+ next: config.editor.apply(text, ops),
720
+ entries: keys.map((key) => ({
721
+ client: adapter.id,
722
+ file: config.file,
723
+ op: "remove",
724
+ key,
725
+ ...journalValue(servers.get(key)),
726
+ after: null,
727
+ })),
728
+ };
729
+ }, batch);
730
+ removed.push(...keys.map((key) => `${adapter.id}:${key}`));
731
+ }
732
+ catch (error) {
733
+ if (!(error instanceof ManualEdit))
734
+ throw error;
735
+ left.push(`${adapter.id}: ${error.message}`);
736
+ }
737
+ }
738
+ return { removed, left };
739
+ }
686
740
  // Starts the client's configured `ocean` command and checks it answers as the brain server.
687
741
  // This proves the entry launches; it does not prove the client app connects to it.
688
742
  export async function verifyClient(client, env = defaultClientEnv()) {
@@ -94,7 +94,9 @@ function parseScalar(raw) {
94
94
  const quote = (value) => JSON.stringify(value);
95
95
  // --- TOML: one `[<table>.<key>]` section per server -------------------------------------------
96
96
  export function tomlEditor(table) {
97
- const header = /^\s*\[([^\]]+)\]\s*$/;
97
+ // `[table]` and `[[array-of-tables]]` both start a section: a `[[skills.config]]` block after
98
+ // the last server (Ocean's own skill filter writes one) must end that server, not join it.
99
+ const header = /^\s*\[\[?([^\]]+)\]\]?\s*$/;
98
100
  const sections = (lines) => {
99
101
  const found = [];
100
102
  lines.forEach((line, index) => {
@@ -338,4 +338,86 @@ export async function restoreHooks(options) {
338
338
  }
339
339
  return { restored, conflicts };
340
340
  }
341
+ // `ocean uninstall`: removes every Ocean hook still in a client's settings, journaled or not —
342
+ // once the `ocean` command is gone, one left behind fails at every session start. Only Ocean's
343
+ // own hook entries go; a group that also runs the owner's hooks keeps them. An event list left
344
+ // empty is removed, and `hooks` with it once nothing else is in it.
345
+ export async function removeOceanHooks(options = {}) {
346
+ const env = options.env ?? defaultClientEnv();
347
+ const removed = [];
348
+ const left = [];
349
+ const undo = newBatch();
350
+ for (const adapter of HOOK_ADAPTERS) {
351
+ const file = path.join(env.home, adapter.file);
352
+ if (!(await readText(file)).trim())
353
+ continue;
354
+ const outcome = {
355
+ found: [],
356
+ problem: null,
357
+ };
358
+ await edit(file, (text) => {
359
+ outcome.found = [];
360
+ outcome.problem = null;
361
+ const found = outcome.found;
362
+ let document;
363
+ try {
364
+ document = canonicalJson(text);
365
+ }
366
+ catch (error) {
367
+ // Reported only when the file holds an Ocean hook it cannot be rewritten to remove.
368
+ if (hasAnyOceanHook(adapter, text))
369
+ outcome.problem =
370
+ error instanceof Error ? error.message : String(error);
371
+ return null;
372
+ }
373
+ const { parsed, render } = document;
374
+ const hooks = parsed.hooks;
375
+ if (!hooks || typeof hooks !== "object" || Array.isArray(hooks))
376
+ return null;
377
+ const table = hooks;
378
+ for (const event of adapter.events) {
379
+ const key = eventKey(adapter, event);
380
+ const groups = table[key];
381
+ if (!Array.isArray(groups) || !hasOceanHook(groups, event))
382
+ continue;
383
+ const kept = groups.flatMap((group) => {
384
+ const inner = group?.hooks;
385
+ if (!Array.isArray(inner))
386
+ return isOceanCommand(group, event) ? [] : [group];
387
+ const rest = inner.filter((hook) => !isOceanCommand(hook, event));
388
+ if (rest.length === inner.length)
389
+ return [group];
390
+ return rest.length ? [{ ...group, hooks: rest }] : [];
391
+ });
392
+ if (kept.length)
393
+ table[key] = kept;
394
+ else
395
+ delete table[key];
396
+ found.push(`${adapter.client}:${event}`);
397
+ }
398
+ if (!found.length)
399
+ return null;
400
+ if (!Object.keys(table).length)
401
+ delete parsed.hooks;
402
+ return { next: render(parsed), entries: [] };
403
+ }, undo);
404
+ removed.push(...outcome.found);
405
+ if (outcome.problem)
406
+ left.push(`${adapter.client}: ${outcome.problem} (~/${adapter.file})`);
407
+ }
408
+ return { removed, left };
409
+ }
410
+ function hasAnyOceanHook(adapter, text) {
411
+ let parsed;
412
+ try {
413
+ parsed = JSON.parse(text);
414
+ }
415
+ catch {
416
+ return /\bocean\b/.test(text);
417
+ }
418
+ return adapter.events.some((event) => {
419
+ const groups = sessionGroups(parsed, eventKey(adapter, event));
420
+ return Boolean(groups && hasOceanHook(groups, event));
421
+ });
422
+ }
341
423
  //# sourceMappingURL=hooks.js.map
@@ -73,4 +73,26 @@ export async function syncCharterCopies(home = os.homedir()) {
73
73
  }
74
74
  return results;
75
75
  }
76
+ // `ocean uninstall`: empties the generated copy between the markers. The markers and everything
77
+ // outside them are the owner's and stay.
78
+ export async function removeCharterCopies(home = os.homedir()) {
79
+ const removed = [];
80
+ for (const copy of CHARTER_COPIES) {
81
+ const file = path.join(home, copy.file);
82
+ let text;
83
+ try {
84
+ text = await readFile(file, "utf8");
85
+ }
86
+ catch {
87
+ continue;
88
+ }
89
+ const start = text.indexOf(BEGIN);
90
+ const end = text.indexOf(END, start);
91
+ if (start === -1 || end === -1 || end === start + BEGIN.length + 1)
92
+ continue;
93
+ await atomicWrite(file, `${text.slice(0, start)}${BEGIN}\n${text.slice(end)}`);
94
+ removed.push(`~/${copy.file}`);
95
+ }
96
+ return removed;
97
+ }
76
98
  //# sourceMappingURL=charter-copies.js.map
@@ -103,4 +103,38 @@ export async function configureClaudeCodeWrapper(wrapperManager, settingsPath =
103
103
  }
104
104
  return { settingsPath, wrapper, apply, changed, backup };
105
105
  }
106
+ // `ocean uninstall`: takes out the wrapper setting when it still points into Ocean's shims —
107
+ // with the shims gone, VS Code's Claude would otherwise fail to start. A wrapper of the owner's
108
+ // own stays. A JSONC file keeps its comments: only the key's own text is cut.
109
+ export async function removeClaudeCodeWrapper(shimDir, settingsPath = defaultClaudeCodeSettingsPath()) {
110
+ let source;
111
+ try {
112
+ source = await readFile(settingsPath, "utf8");
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ let parsed;
118
+ try {
119
+ parsed = parseSettings(source);
120
+ }
121
+ catch {
122
+ return null;
123
+ }
124
+ const value = parsed.settings[WRAPPER_KEY];
125
+ const relative = typeof value === "string" ? path.relative(shimDir, value) : "..";
126
+ if (relative.startsWith("..") || path.isAbsolute(relative))
127
+ return null;
128
+ let updated;
129
+ if (parsed.strict) {
130
+ const { [WRAPPER_KEY]: _removed, ...rest } = parsed.settings;
131
+ updated = `${JSON.stringify(rest, null, 2)}\n`;
132
+ }
133
+ else {
134
+ const entry = new RegExp(`\\s*"${WRAPPER_KEY.replace(".", "\\.")}"\\s*:\\s*"(?:[^"\\\\]|\\\\.)*"\\s*,?`);
135
+ updated = source.replace(entry, "");
136
+ }
137
+ await writeFile(settingsPath, updated, "utf8");
138
+ return settingsPath;
139
+ }
106
140
  //# sourceMappingURL=claude-vscode.js.map
@@ -0,0 +1,44 @@
1
+ import { syncCoreSkills } from "@ocean/market/skills/core-skill-sync.js";
2
+ import { copyClientSkills, retireCoreFromHub, } from "@ocean/market/skills/skill-hub.js";
3
+ // Keeps every client's skills current with no command run: the session-start sync and
4
+ // `ocean market install|update` call it. Hub skills (installed from the market or made there)
5
+ // first, then the engine's core skills, so the engine's version of a core skill wins. A copy the
6
+ // owner changed inside a client after Ocean's version is kept, never overwritten.
7
+ export async function autoSyncSkills(home) {
8
+ const summary = {
9
+ retired: [],
10
+ copied: [],
11
+ kept: [],
12
+ failed: [],
13
+ };
14
+ try {
15
+ summary.retired = await retireCoreFromHub();
16
+ }
17
+ catch (error) {
18
+ summary.failed.push(`retire: ${error instanceof Error ? error.message : String(error)}`);
19
+ }
20
+ try {
21
+ const hub = await copyClientSkills({ apply: true, auto: true, home });
22
+ for (const action of hub.actions) {
23
+ const label = `${action.client}:${action.skill}`;
24
+ if (action.action === "kept")
25
+ summary.kept.push(label);
26
+ else if (action.action === "failed")
27
+ summary.failed.push(`${label}: ${action.error}`);
28
+ else if (action.action !== "synchronized")
29
+ summary.copied.push(label);
30
+ }
31
+ }
32
+ catch (error) {
33
+ summary.failed.push(`hub: ${error instanceof Error ? error.message : String(error)}`);
34
+ }
35
+ try {
36
+ for (const result of await syncCoreSkills(home, { keepNewer: true }))
37
+ summary.copied.push(...result.copied.map((skill) => `${result.client}:${skill}`));
38
+ }
39
+ catch (error) {
40
+ summary.failed.push(`core: ${error instanceof Error ? error.message : String(error)}`);
41
+ }
42
+ return summary;
43
+ }
44
+ //# sourceMappingURL=skill-auto-sync.js.map
@@ -182,8 +182,10 @@ async function syncGemini(home, hidden) {
182
182
  disabled: wanted.length,
183
183
  };
184
184
  }
185
- export async function syncSkillFilter(home = os.homedir()) {
186
- const hidden = await claudeHiddenSkills(home);
185
+ // `hidden` empty (`ocean uninstall`) re-enables every skill Ocean disabled: the Codex block goes
186
+ // and the names Ocean added to the Gemini and Hermes lists come out; the owner's own stay.
187
+ export async function syncSkillFilter(home = os.homedir(), hidden) {
188
+ hidden ??= await claudeHiddenSkills(home);
187
189
  return [
188
190
  await syncCodex(home, hidden),
189
191
  await syncGemini(home, hidden),
@@ -1,6 +1,7 @@
1
1
  import { writeFile } from "node:fs/promises";
2
2
  import { oceanPath, PERSONAL_DIR } from "@ocean/core/shared/paths.js";
3
- import { copyClientSkills, populateSkillHub, } from "@ocean/market/skills/skill-hub.js";
3
+ import { syncCoreSkills } from "@ocean/market/skills/core-skill-sync.js";
4
+ import { copyClientSkills } from "@ocean/market/skills/skill-hub.js";
4
5
  import { connectObsidianVault } from "@ocean/services/obsidian/vault-discovery.js";
5
6
  import { ONBOARDING_QUESTIONS, onboard, } from "@ocean/services/onboarding/onboarding.js";
6
7
  // Bump when a step is added; completed steps stay completed, only new ids run.
@@ -182,8 +183,8 @@ export function buildSteps(deps) {
182
183
  title: "Skills (one store in Ocean, clients hold copies)",
183
184
  optional: false,
184
185
  async run(io) {
185
- const hub = await populateSkillHub();
186
- io.say(` Hub: ${hub.added.length} added, ${hub.kept.length} already there.`);
186
+ const core = await syncCoreSkills(undefined, { keepNewer: true });
187
+ io.say(` Core skills: ${core.flatMap((item) => item.copied).length} copied to clients.`);
187
188
  const plan = await copyClientSkills({});
188
189
  const pending = plan.actions.filter((a) => a.action !== "synchronized");
189
190
  if (pending.length === 0) {
@@ -0,0 +1,247 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { readFile, rm } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { promisify } from "node:util";
6
+ import { atomicWrite } from "@ocean/core/shared/fs-utils.js";
7
+ import { liveEngineEntry, oceanRoot } from "@ocean/core/shared/paths.js";
8
+ import { removeCoreSkills } from "@ocean/market/skills/core-skill-sync.js";
9
+ import { defaultClientEnv, newBatch, readJournal, removeOceanEntries, restoreClients, } from "../clients/clients.js";
10
+ import { DESKTOP_WATCHER_FILE, DESKTOP_WATCHER_LABEL, restoreDesktopWatcher, } from "../clients/desktop-watcher.js";
11
+ import { removeOceanHooks, restoreHooks } from "../clients/hooks.js";
12
+ import { restoreNative } from "../clients/native.js";
13
+ import { restoreOpencodePlugin } from "../clients/opencode-plugin.js";
14
+ import { removeCharterCopies } from "../integrations/charter-copies.js";
15
+ import { removeClaudeCodeWrapper } from "../integrations/claude-vscode.js";
16
+ import { syncSkillFilter } from "../integrations/skill-filter.js";
17
+ const runCommand = (command, args) => promisify(execFile)(command, args);
18
+ // Shell files a profile block may be in: the shell can have changed since setup ran.
19
+ const SHELL_PROFILES = [
20
+ ".zshrc",
21
+ ".zprofile",
22
+ ".bashrc",
23
+ ".bash_profile",
24
+ ".profile",
25
+ ".config/fish/config.fish",
26
+ "Documents/PowerShell/Microsoft.PowerShell_profile.ps1",
27
+ ];
28
+ const PROFILE_MARKER = "# >>> ocean interception >>>";
29
+ const RUNTIME_LABEL = "com.ocean.runtime";
30
+ const BRIDGE_LABEL = "com.ocean.browser-bridge";
31
+ function context(options) {
32
+ const env = options.env ?? defaultClientEnv();
33
+ const home = env.home;
34
+ const platform = options.platform ?? process.platform;
35
+ return {
36
+ env,
37
+ home,
38
+ platform,
39
+ run: options.run ?? runCommand,
40
+ root: options.root ?? oceanRoot(),
41
+ shimDir: options.shimDir,
42
+ domain: `gui/${process.getuid?.() ?? ""}`,
43
+ launchAgent: (label) => path.join(home, "Library", "LaunchAgents", `${label}.plist`),
44
+ systemdUnit: path.join(home, ".config", "systemd", "user", "ocean.service"),
45
+ windowsStartup: path.join(process.env.APPDATA ?? path.join(home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "ocean.cmd"),
46
+ };
47
+ }
48
+ // Apply batches not yet fully undone, newest first. An entry counts as undone once a restore
49
+ // note names its batch, client, file, op and key.
50
+ export function pendingBatches(journal) {
51
+ const id = (entry, batch) => [batch, entry.client, entry.file, entry.op, entry.key].join("\u0000");
52
+ const undone = new Set(journal
53
+ .filter((entry) => entry.restoreOf)
54
+ .map((entry) => id(entry, entry.restoreOf)));
55
+ const order = [];
56
+ const open = new Set();
57
+ for (const entry of journal) {
58
+ if (entry.restoreOf)
59
+ continue;
60
+ if (!order.includes(entry.batch))
61
+ order.push(entry.batch);
62
+ if (!undone.has(id(entry, entry.batch)))
63
+ open.add(entry.batch);
64
+ }
65
+ return order.filter((batch) => open.has(batch)).reverse();
66
+ }
67
+ async function profileFiles(home) {
68
+ const found = [];
69
+ for (const relative of SHELL_PROFILES) {
70
+ const file = path.join(home, relative);
71
+ const text = await readFile(file, "utf8").catch(() => null);
72
+ if (text?.includes(PROFILE_MARKER))
73
+ found.push(file);
74
+ }
75
+ return found;
76
+ }
77
+ function serviceFiles(ctx) {
78
+ const files = ctx.platform === "darwin"
79
+ ? [
80
+ ctx.launchAgent(RUNTIME_LABEL),
81
+ ctx.launchAgent(BRIDGE_LABEL),
82
+ path.join(ctx.home, DESKTOP_WATCHER_FILE),
83
+ ]
84
+ : ctx.platform === "linux"
85
+ ? [ctx.systemdUnit]
86
+ : ctx.platform === "win32"
87
+ ? [ctx.windowsStartup]
88
+ : [];
89
+ return files
90
+ .filter((file) => existsSync(file))
91
+ .map((target) => ({ area: "service", target }));
92
+ }
93
+ // Why the workspace must not be deleted by a command, or null when it may be.
94
+ export function purgeRefusal(root, home) {
95
+ const resolved = path.resolve(root);
96
+ if (resolved === path.resolve(home) || resolved === path.parse(resolved).root)
97
+ return `${resolved} is not a workspace folder`;
98
+ if (existsSync(path.join(resolved, ".git")))
99
+ return `${resolved} is a git checkout; delete it by hand if you mean to`;
100
+ const engine = path.relative(resolved, liveEngineEntry());
101
+ if (!engine.startsWith("..") && !path.isAbsolute(engine))
102
+ return `the running Ocean engine is inside ${resolved}; delete it by hand if you mean to`;
103
+ return null;
104
+ }
105
+ // What `ocean uninstall` would change, read-only.
106
+ export async function planUninstall(options) {
107
+ const ctx = context(options);
108
+ const items = [];
109
+ const batches = pendingBatches(await readJournal());
110
+ if (batches.length)
111
+ items.push({
112
+ area: "clients",
113
+ target: `undo ${batches.length} \`ocean clients apply\` change set(s), then remove any Ocean MCP entry and hook still there`,
114
+ });
115
+ else
116
+ items.push({
117
+ area: "clients",
118
+ target: "remove any Ocean MCP entry and hook still in a client config",
119
+ });
120
+ items.push({
121
+ area: "skills",
122
+ target: "Ocean's core skill copies, the charter copy in Codex and Gemini rules, the skills Ocean disabled",
123
+ });
124
+ items.push(...serviceFiles(ctx));
125
+ for (const file of await profileFiles(ctx.home))
126
+ items.push({
127
+ area: "shell",
128
+ target: `${file} (the ocean interception block)`,
129
+ });
130
+ if (existsSync(ctx.shimDir))
131
+ items.push({ area: "shims", target: ctx.shimDir });
132
+ if (!options.purge)
133
+ return { items, purge: null };
134
+ const refusal = purgeRefusal(ctx.root, ctx.home);
135
+ return refusal ? { items, purge: null, refusal } : { items, purge: ctx.root };
136
+ }
137
+ async function stopServices(ctx, report) {
138
+ if (ctx.platform === "darwin") {
139
+ for (const label of [DESKTOP_WATCHER_LABEL, BRIDGE_LABEL, RUNTIME_LABEL]) {
140
+ const file = ctx.launchAgent(label);
141
+ if (!existsSync(file))
142
+ continue;
143
+ await ctx
144
+ .run("launchctl", ["bootout", `${ctx.domain}/${label}`])
145
+ .catch(() => { });
146
+ await rm(file, { force: true });
147
+ report.removed.push({ area: "service", target: file });
148
+ }
149
+ }
150
+ else if (ctx.platform === "linux" && existsSync(ctx.systemdUnit)) {
151
+ await ctx
152
+ .run("systemctl", ["--user", "disable", "--now", "ocean.service"])
153
+ .catch(() => { });
154
+ await rm(ctx.systemdUnit, { force: true });
155
+ await ctx.run("systemctl", ["--user", "daemon-reload"]).catch(() => { });
156
+ report.removed.push({ area: "service", target: ctx.systemdUnit });
157
+ }
158
+ else if (ctx.platform === "win32" && existsSync(ctx.windowsStartup)) {
159
+ await rm(ctx.windowsStartup, { force: true });
160
+ report.removed.push({ area: "service", target: ctx.windowsStartup });
161
+ report.next.push("the Ocean runtime started at this login keeps running until you sign out");
162
+ }
163
+ }
164
+ export async function runUninstall(options) {
165
+ const ctx = context(options);
166
+ const report = {
167
+ removed: [],
168
+ left: [],
169
+ purged: null,
170
+ next: [],
171
+ };
172
+ const removed = (area, targets) => report.removed.push(...targets.map((target) => ({ area, target })));
173
+ const left = (area, targets) => report.left.push(...targets.map((target) => ({ area, target })));
174
+ // 1. Launch services first — the runtime, the Desktop watcher, the retired browser bridge — so
175
+ // nothing re-wires a client while its config is being put back.
176
+ await stopServices(ctx, report);
177
+ // 2. Client configs: every journaled apply undone, newest first, then whatever Ocean wrote
178
+ // that the journal does not cover (or that a conflict kept).
179
+ const conflicts = new Set();
180
+ for (const batch of pendingBatches(await readJournal())) {
181
+ const env = ctx.env;
182
+ const results = [
183
+ await restoreClients({ batch, env }),
184
+ await restoreHooks({ batch, env }),
185
+ await restoreOpencodePlugin({ batch, env }),
186
+ await restoreNative({ batch, env }),
187
+ await restoreDesktopWatcher({ batch, env, run: ctx.run }),
188
+ ];
189
+ for (const result of results) {
190
+ removed("clients", result.restored);
191
+ for (const conflict of result.conflicts)
192
+ conflicts.add(conflict);
193
+ }
194
+ }
195
+ const sweep = newBatch();
196
+ const entries = await removeOceanEntries({ env: ctx.env, batch: sweep });
197
+ const hooks = await removeOceanHooks({ env: ctx.env });
198
+ removed("clients", [...entries.removed, ...hooks.removed]);
199
+ left("clients", [...entries.left, ...hooks.left]);
200
+ // MCP entries, hooks and the Desktop watcher are swept regardless of the journal, so their
201
+ // conflicts are settled; a native switch or plugin the owner changed since is named instead.
202
+ for (const conflict of conflicts)
203
+ if (conflict.endsWith(":native") || conflict.endsWith(":plugin"))
204
+ left("clients", [
205
+ `${conflict} (changed since Ocean wrote it; check by hand)`,
206
+ ]);
207
+ // 3. Skills and rules Ocean copied into clients.
208
+ const skills = await removeCoreSkills(ctx.home);
209
+ removed("skills", skills.removed);
210
+ left("skills", skills.kept.map((item) => `${item} (edited since Ocean copied it)`));
211
+ removed("rules", await removeCharterCopies(ctx.home));
212
+ const filter = await syncSkillFilter(ctx.home, new Set());
213
+ removed("skills", filter
214
+ .filter((result) => result.status === "updated")
215
+ .map((result) => `${result.file} (skills Ocean disabled)`));
216
+ const vscode = await removeClaudeCodeWrapper(ctx.shimDir, options.vscodeSettings);
217
+ if (vscode)
218
+ removed("clients", [`${vscode} (claudeCode.claudeProcessWrapper)`]);
219
+ // 4. Shell profile blocks and the shims they put on PATH.
220
+ for (const file of await profileFiles(ctx.home)) {
221
+ const text = await readFile(file, "utf8");
222
+ const next = options.stripProfile(text);
223
+ if (next === text)
224
+ continue;
225
+ await atomicWrite(file, next);
226
+ removed("shell", [file]);
227
+ }
228
+ if (existsSync(ctx.shimDir)) {
229
+ await rm(ctx.shimDir, { recursive: true, force: true });
230
+ removed("shims", [ctx.shimDir]);
231
+ }
232
+ // 5. The workspace, only on --purge, and never one that is a checkout or holds the engine.
233
+ if (options.purge) {
234
+ const refusal = purgeRefusal(ctx.root, ctx.home);
235
+ if (refusal)
236
+ left("workspace", [refusal]);
237
+ else {
238
+ await rm(ctx.root, { recursive: true, force: true });
239
+ report.purged = ctx.root;
240
+ }
241
+ }
242
+ report.next.push("open a new terminal (the current one still has the old PATH)", "npm uninstall --global @amoree-code/ocean");
243
+ if (!report.purged && !options.purge)
244
+ report.next.push(`your workspace is kept at ${ctx.root}; delete it by hand, or run \`ocean uninstall --yes --purge\``);
245
+ return report;
246
+ }
247
+ //# sourceMappingURL=uninstall.js.map
@@ -235,7 +235,7 @@ function withoutEol(line) {
235
235
  // all other lines keep their exact bytes and line endings. Only the single blank separator the
236
236
  // installer puts above its block goes with it. A begin marker without a matching end marker is
237
237
  // left alone rather than guessed at.
238
- function stripInterceptionBlocks(text) {
238
+ export function stripInterceptionBlocks(text) {
239
239
  const lines = text.split(/(?<=\n)/);
240
240
  const kept = [];
241
241
  // Once a name has no end marker after some position it has none after any later one, so
@@ -35,6 +35,7 @@ import { findInstallSpec, installPlan, installProvider, listInstallSpecs, remove
35
35
  import { syncCharterCopies } from "../../application/integrations/charter-copies.js";
36
36
  import { configureClaudeCodeWrapper } from "../../application/integrations/claude-vscode.js";
37
37
  import { repairEngineEntries } from "../../application/integrations/engine-entry-repair.js";
38
+ import { autoSyncSkills } from "../../application/integrations/skill-auto-sync.js";
38
39
  import { syncSkillFilter } from "../../application/integrations/skill-filter.js";
39
40
  import { selectProfileForTask } from "../../application/profiles/profile-suggestion.js";
40
41
  import { listSchedules, runDueSchedules, runSchedule, runSchedulerWorker, runSchedulerWorkerOnce, saveSchedule, setScheduleEnabled, } from "../../application/scheduler/local-scheduler.js";
@@ -82,6 +83,7 @@ import { insideFactsCall, runSessionFactsCommand, startSessionFacts, } from "./s
82
83
  import { parseSetupArgs, SETUP_USAGE, setup } from "./setup-command.js";
83
84
  import { runTasksCommand } from "./tasks-command.js";
84
85
  import { runTelemetryCommand } from "./telemetry-command.js";
86
+ import { runUninstallCommand } from "./uninstall-command.js";
85
87
  // brain_search over MCP uses vectors when the local embedder answers (T-307), and full text when
86
88
  // it does not; a working embedder is kept, a failure is retried on the next search.
87
89
  function mcpEmbedder() {
@@ -184,6 +186,8 @@ async function commandClient() {
184
186
  // to core.md reaches the clients that carry a copy without a manual step.
185
187
  const charter = await syncCharterCopies();
186
188
  const skillFilter = await syncSkillFilter();
189
+ // A skill made or installed reaches every client at the next session start.
190
+ const skills = await autoSyncSkills();
187
191
  const engineEntries = await repairEngineEntries();
188
192
  // T-305: a repointed service start file only takes effect once the service restarts.
189
193
  const service = engineEntries.some((repair) => repair.kind === "service" && repair.status === "updated")
@@ -199,6 +203,7 @@ async function commandClient() {
199
203
  providers: result.providers,
200
204
  charter,
201
205
  skillFilter,
206
+ skills,
202
207
  engineEntries,
203
208
  service,
204
209
  clients,
@@ -1215,6 +1220,7 @@ async function commandSession() {
1215
1220
  }
1216
1221
  export const commandRegistry = {
1217
1222
  setup: commandSetup,
1223
+ uninstall: () => runUninstallCommand(process.argv.slice(3)),
1218
1224
  onboard: () => runOnboardCommand(process.argv.slice(3)),
1219
1225
  service: commandService,
1220
1226
  intercept: commandIntercept,
@@ -1,7 +1,7 @@
1
1
  const commandGroups = [
2
2
  [
3
3
  "Workspace",
4
- "setup, onboard, context, project, tasks, loop, policy, lifecycle, doctor, repair",
4
+ "setup, uninstall, onboard, context, project, tasks, loop, policy, lifecycle, doctor, repair",
5
5
  ],
6
6
  [
7
7
  "Execution",
@@ -30,6 +30,10 @@ export const commandHelp = {
30
30
  "Create the private workspace, the AI CLI shims, the shell profile entry and the login service.",
31
31
  "ocean setup [--obsidian <vault-path>] [--read-write]",
32
32
  ],
33
+ uninstall: [
34
+ "Undo setup and clients apply outside the workspace; shows the plan until --yes, --purge also deletes the workspace.",
35
+ "ocean uninstall [--yes] [--purge] [--json]",
36
+ ],
33
37
  onboard: [
34
38
  "Run the pending first-run steps; --status only shows them.",
35
39
  "ocean onboard [--yes] [--status] [--reset <step>]",