mercury-agent 0.24.4-beta.0 → 0.24.4-beta.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.
@@ -2528,3 +2528,7 @@ zap extractor reads one-store cards labelled `למפרט טכני` (restart-depl
2528
2528
  - [ ] MANUAL-VERIFY(2026-10-19): Click **Sign out** at the top right. You should land on the login form, and reloading `/dashboard` should bring you back to it.
2529
2529
  - [ ] MANUAL-VERIFY(2026-10-19): From a laptop, run `for i in $(seq 11); do curl -s -o /dev/null -w "%{http_code} " -H "Authorization: Bearer wrong" https://<box>/api/spaces; done`. You should see ten `401` then `429`. The journal should show `Secret check refused` lines with your real IP as `clientAddress` (not 127.0.0.1) and one `Failed-secret throttle engaged`. Wait 10 minutes before using the secret from that IP again.
2530
2530
  - [ ] MANUAL-VERIFY(2026-10-19): In the Tagula console, open this box's embedded dashboard. It should load and update live, with no "Assistant login did not return a session" error (the console's `init` login still uses `?token=` and looks for a `mercury_token` cookie).
2531
+
2532
+ ## Issue #143 / F14 — deleting a space removes all of it (added 2026-10-19, deploy-gated: new release + restart)
2533
+
2534
+ - [ ] MANUAL-VERIFY(2026-10-19): Create a throwaway space, link a test group to it, send a message, then delete it from chat with `/spaces delete <id>` and answer `yes`. The reply should say it removed its files. On the box, `ls ~/whatsapp-bot/.mercury/spaces/<id>` should say "No such file", and `sqlite3 ~/whatsapp-bot/.mercury/state.db "SELECT COUNT(*) FROM conversations WHERE observed_title LIKE '%<group name>%'"` should print 0. Adjust the paths if the project lives elsewhere.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mercury-agent",
3
- "version": "0.24.4-beta.0",
3
+ "version": "0.24.4-beta.1",
4
4
  "description": "Personal AI assistant for chat platforms (WhatsApp, Slack, Discord, Telegram)",
5
5
  "license": "MIT",
6
6
  "author": "Avishai Tsabari",
@@ -66,3 +66,11 @@ Cross-space deletion is a **chat** action for a seeded admin only:
66
66
  If a user asks you to delete a space other than this one, do not reach for
67
67
  `mrctl`. Tell them to run that chat command themselves, and that it asks for a
68
68
  `yes` confirmation before anything is destroyed.
69
+
70
+ ## What a delete removes
71
+
72
+ When asked, say it plainly: deleting a space removes its messages, tasks,
73
+ settings, roles, the link to its chats (with the group's name), and its files
74
+ (memory, received media). It cannot be undone. Backups made before the delete
75
+ still hold a copy until they age out under the instance's backup retention.
76
+ Do not promise more than that.
@@ -67,7 +67,7 @@ mrctl model reset # Clear the pin and restore the fallback chain
67
67
  mrctl spaces list # List all spaces with names (admin-only)
68
68
  mrctl spaces name # Get current space's display name
69
69
  mrctl spaces name "My Space" # Set current space's display name
70
- mrctl spaces delete # Delete current space + tasks/messages/roles/config
70
+ mrctl spaces delete # Delete current space: all its data and files
71
71
  mrctl conversations list # List known conversations
72
72
  mrctl conversations list --unlinked # Show only unlinked conversations
73
73
  ```
@@ -36,8 +36,12 @@ import {
36
36
  loadConfig,
37
37
  resolveProjectPath,
38
38
  } from "../config.js";
39
- import { mergeRawMercuryConfig } from "../config-file.js";
39
+ import {
40
+ mergeRawMercuryConfig,
41
+ mergeRawMercuryConfigWithSources,
42
+ } from "../config-file.js";
40
43
  import { reapProcessTree } from "../core/process-tree.js";
44
+ import { deleteSpaceEverywhere } from "../core/space-delete.js";
41
45
  import {
42
46
  installWatchdogAbortHandler,
43
47
  raiseWatchdogForStartup,
@@ -145,7 +149,6 @@ import {
145
149
  } from "../storage/backup.js";
146
150
  import { Db } from "../storage/db.js";
147
151
  import { DbIntegrityError } from "../storage/integrity.js";
148
- import { removeSpaceWorkspace } from "../storage/memory.js";
149
152
  import {
150
153
  copyDirRecursive,
151
154
  DOCKERFILE_SOURCE,
@@ -162,11 +165,14 @@ import {
162
165
  unitPathIncludes,
163
166
  } from "./service-unit.js";
164
167
  import {
168
+ configuredImageSource,
165
169
  lockedLibvipsDlls,
166
170
  NPM_BIN,
167
171
  npmGlobalRoot,
172
+ parseUnitWorkingDirectory,
168
173
  runUpgrade,
169
174
  type UpgradeDeps,
175
+ writeEnvFileAtomically,
170
176
  } from "./upgrade.js";
171
177
  import {
172
178
  DEFAULT_LIMIT as DEFAULT_WEB_FAILURES_LIMIT,
@@ -2482,16 +2488,24 @@ async function upgradeAction(
2482
2488
  };
2483
2489
  };
2484
2490
 
2491
+ const envPath = join(CWD, ".env");
2485
2492
  const readConfiguredImage: UpgradeDeps["readConfiguredImage"] = () => {
2486
2493
  // Best effort, the shape `mercury build` uses: this command runs from
2487
2494
  // anywhere, and no project directory is the normal case, not an error.
2488
2495
  try {
2489
- const envPath = join(CWD, ".env");
2490
- if (existsSync(envPath)) Object.assign(process.env, loadEnvFile(envPath));
2491
- return { image: loadConfig().agentContainerImage, problem: null };
2496
+ const fromEnvFile = existsSync(envPath) ? loadEnvFile(envPath) : {};
2497
+ Object.assign(process.env, fromEnvFile);
2498
+ // Who set it, from the merge that decides it: the loader returns the
2499
+ // derived default whether or not anybody pinned that same string.
2500
+ const source = configuredImageSource(
2501
+ fromEnvFile,
2502
+ mergeRawMercuryConfigWithSources(process.env, CWD, () => {}).sources
2503
+ .agentContainerImage,
2504
+ );
2505
+ return { image: loadConfig().agentContainerImage, problem: null, source };
2492
2506
  } catch (err) {
2493
2507
  const msg = err instanceof Error ? err.message : String(err);
2494
- return { image: null, problem: msg.split("\n")[0] ?? msg };
2508
+ return { image: null, problem: msg.split("\n")[0] ?? msg, source: null };
2495
2509
  }
2496
2510
  };
2497
2511
 
@@ -2523,6 +2537,35 @@ async function upgradeAction(
2523
2537
  };
2524
2538
  },
2525
2539
  readConfiguredImage,
2540
+ readEnvFile: () =>
2541
+ existsSync(envPath)
2542
+ ? { path: envPath, text: readFileSync(envPath, "utf-8") }
2543
+ : null,
2544
+ writeEnvFile: (path, text, backupBase) =>
2545
+ writeEnvFileAtomically(path, text, backupBase),
2546
+ cwd: canonicalPath(CWD),
2547
+ serviceWorkingDirectory: (kind) => {
2548
+ // The unit file `service install` wrote, read back: its
2549
+ // WorkingDirectory is the project the restarted host boots in.
2550
+ const paths = getServicePaths();
2551
+ const unitFile =
2552
+ kind === "launchd"
2553
+ ? paths.launchdPlist
2554
+ : kind === "systemd-user"
2555
+ ? paths.systemdUser
2556
+ : paths.systemdSystem;
2557
+ try {
2558
+ const dir = parseUnitWorkingDirectory(
2559
+ kind,
2560
+ readFileSync(unitFile, "utf-8"),
2561
+ );
2562
+ return dir === null ? null : canonicalPath(dir);
2563
+ } catch (err) {
2564
+ const msg = err instanceof Error ? err.message : String(err);
2565
+ console.error(`upgrade: could not read ${unitFile}: ${msg}`);
2566
+ return null;
2567
+ }
2568
+ },
2526
2569
  hostVersion: readHostVersion(PACKAGE_ROOT),
2527
2570
  log: {
2528
2571
  info: (line) => console.log(line),
@@ -3329,39 +3372,30 @@ spacesCommand
3329
3372
  console.log("Aborted.");
3330
3373
  return;
3331
3374
  }
3332
- const result = withProjectDb((db) => db.deleteSpace(id));
3333
- const spacesDir = join(CWD, getProjectDataDir(CWD), "spaces");
3334
- try {
3335
- removeSpaceWorkspace(spacesDir, id);
3336
- } catch (err) {
3337
- console.warn(
3338
- `Warning: could not remove workspace directory for space '${id}':`,
3339
- err instanceof Error ? err.message : err,
3340
- );
3341
- }
3342
- console.log(
3343
- `Deleted space '${id}' — removed ${result.removed.messages} messages, ${result.removed.tasks} tasks`,
3344
- );
3375
+ deleteSpaceFromCli(id);
3345
3376
  },
3346
3377
  );
3347
3378
  return;
3348
3379
  }
3349
3380
 
3350
- const result = withProjectDb((db) => db.deleteSpace(id));
3351
- const spacesDir = join(CWD, getProjectDataDir(CWD), "spaces");
3352
- try {
3353
- removeSpaceWorkspace(spacesDir, id);
3354
- } catch (err) {
3355
- console.warn(
3356
- `Warning: could not remove workspace directory for space '${id}':`,
3357
- err instanceof Error ? err.message : err,
3358
- );
3359
- }
3360
- console.log(
3361
- `Deleted space '${id}' — removed ${result.removed.messages} messages, ${result.removed.tasks} tasks`,
3362
- );
3381
+ deleteSpaceFromCli(id);
3363
3382
  });
3364
3383
 
3384
+ function deleteSpaceFromCli(id: string): void {
3385
+ const spacesDir = join(CWD, getProjectDataDir(CWD), "spaces");
3386
+ const result = withProjectDb((db) =>
3387
+ deleteSpaceEverywhere(db, spacesDir, id),
3388
+ );
3389
+ if (result.workspaceError) {
3390
+ console.warn(
3391
+ `Warning: could not remove workspace directory for space '${id}': ${result.workspaceError}`,
3392
+ );
3393
+ }
3394
+ console.log(
3395
+ `Deleted space '${id}' — removed ${result.removed.messages} messages, ${result.removed.tasks} tasks, ${result.removed.conversations} conversations`,
3396
+ );
3397
+ }
3398
+
3365
3399
  // ─── Backup & restore ───────────────────────────────────────────────────
3366
3400
  //
3367
3401
  // Thin shells over src/storage/backup.ts — the same functions the storage