mercury-agent 0.5.8 → 0.5.10

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.
Files changed (28) hide show
  1. package/README.md +29 -3
  2. package/container/Dockerfile +2 -2
  3. package/container/Dockerfile.base +2 -2
  4. package/examples/extensions/napkin/index.ts +17 -10
  5. package/examples/extensions/napkin/prompts/kb-distillation.md +6 -6
  6. package/examples/extensions/pdf/skill/SKILL.md +545 -178
  7. package/examples/extensions/pdf/skill/forms.md +273 -214
  8. package/examples/extensions/pdf/skill/reference.md +450 -480
  9. package/examples/extensions/pdf/skill/scripts/check_bounding_boxes.py +221 -58
  10. package/examples/extensions/pdf/skill/scripts/check_fillable_fields.py +90 -5
  11. package/examples/extensions/pdf/skill/scripts/convert_pdf_to_images.py +138 -22
  12. package/examples/extensions/pdf/skill/scripts/create_validation_image.py +191 -27
  13. package/examples/extensions/pdf/skill/scripts/extract_form_field_info.py +149 -104
  14. package/examples/extensions/pdf/skill/scripts/extract_form_structure.py +215 -91
  15. package/examples/extensions/pdf/skill/scripts/fill_fillable_fields.py +130 -86
  16. package/examples/extensions/pdf/skill/scripts/fill_pdf_form_with_annotations.py +204 -87
  17. package/examples/extensions/tradestation/skill/SKILL.md +2 -2
  18. package/package.json +1 -1
  19. package/src/adapters/whatsapp-media.ts +5 -2
  20. package/src/agent/container-entry.ts +1 -1
  21. package/src/agent/container-runner.ts +19 -14
  22. package/src/bridges/telegram.ts +5 -2
  23. package/src/chat-shim.ts +26 -17
  24. package/src/core/media.ts +5 -2
  25. package/src/dashboard/tokens.css +1 -1
  26. package/src/extensions/image-builder.ts +2 -2
  27. package/src/main.ts +2 -2
  28. package/examples/extensions/pdf/skill/LICENSE.txt +0 -30
package/README.md CHANGED
@@ -52,21 +52,23 @@ Configure identity and adapters in `.env`:
52
52
  MERCURY_BOT_USERNAME=Mercury
53
53
  MERCURY_TRIGGER_PATTERNS=@Mercury,Mercury
54
54
 
55
- # Enable adapters
55
+ # Enable adapters (pick one or more)
56
56
  MERCURY_ENABLE_WHATSAPP=true
57
57
  MERCURY_ENABLE_DISCORD=true
58
58
  MERCURY_DISCORD_BOT_TOKEN=your-bot-token
59
+ MERCURY_ENABLE_TELEGRAM=true
60
+ MERCURY_TELEGRAM_BOT_TOKEN=your-bot-token
59
61
  ```
60
62
 
61
63
  Start:
62
64
 
63
65
  ```bash
64
66
  mercury run
65
- # or install as a background service:
67
+ # or install as a background service (macOS/Linux only):
66
68
  mercury service install
67
69
  ```
68
70
 
69
- > `mercury run` runs in the foreground (good for a first smoke test). For anything long-running, prefer `mercury service install` — it runs in the background and auto-restarts.
71
+ > `mercury run` runs in the foreground — on Windows (WSL2) this is the only option. On macOS/Linux, prefer `mercury service install` for long-running use — it runs in the background and auto-restarts.
70
72
 
71
73
  ### Set up spaces and conversations
72
74
 
@@ -86,6 +88,26 @@ mercury link <id> main # Link a conversation to a space
86
88
 
87
89
  Multiple conversations can point at the same space — they share memory, session, and vault.
88
90
 
91
+ ### Updating Mercury
92
+
93
+ ```bash
94
+ # 1. Stop Mercury
95
+ # macOS/Linux: mercury service uninstall
96
+ # Windows/WSL2: Ctrl+C in the terminal running mercury run
97
+
98
+ # 2. Update the package
99
+ npm update -g mercury-agent
100
+
101
+ # 3. Rebuild the agent container image
102
+ mercury build
103
+
104
+ # 4. Start again
105
+ # macOS/Linux: mercury service install
106
+ # Windows/WSL2: mercury run
107
+ ```
108
+
109
+ `mercury build` rebuilds the base agent image from the installed package source. The derived image (base + your extensions) rebuilds automatically on startup when the base changes.
110
+
89
111
  ---
90
112
 
91
113
  ## How It Works
@@ -445,6 +467,10 @@ This fork is maintained by [Avishai Tsabari](https://github.com/Avishai-Tsabari)
445
467
 
446
468
  MIT — see [LICENSE](LICENSE)
447
469
 
470
+ ### Third-party licenses
471
+
472
+ The WhatsApp adapter depends on [@whiskeysockets/baileys](https://github.com/WhiskeySockets/Baileys), which transitively includes [libsignal](https://github.com/nicktrav/libsignal) (GPL-3.0) for Signal Protocol encryption. This component runs inside an isolated Docker container and is loaded as a runtime dependency, not statically linked into Mercury's codebase. If your use case has strict copyleft concerns, consult legal counsel or omit the WhatsApp adapter.
473
+
448
474
  ---
449
475
 
450
476
  <p align="center">
@@ -60,7 +60,7 @@ RUN echo '{"args":["--no-sandbox"]}' > /home/mercury/.puppeteerrc.json
60
60
  ENV CHROMIUM_FLAGS="--no-sandbox"
61
61
 
62
62
  # Install CLIs
63
- RUN bun add -g @mariozechner/pi-coding-agent@^0.67.2
63
+ RUN bun add -g @earendil-works/pi-coding-agent@~0.79.6
64
64
 
65
65
  WORKDIR /app
66
66
 
@@ -77,7 +77,7 @@ function patch(dir) {
77
77
  const p = path.join(dir, f);
78
78
  try {
79
79
  if (fs.statSync(p).isDirectory()) patch(p);
80
- else if (f === 'google.js' && p.includes('@mariozechner/pi-ai')) {
80
+ else if (f === 'google.js' && p.includes('@earendil-works/pi-ai')) {
81
81
  let c = fs.readFileSync(p, 'utf8');
82
82
  const noThinking = '&& !model.id.startsWith("gemma")';
83
83
  const p1 = 'if (options.thinking?.enabled && model.reasoning) {';
@@ -42,7 +42,7 @@ RUN echo '{"args":["--no-sandbox"]}' > /home/mercury/.puppeteerrc.json
42
42
  ENV CHROMIUM_FLAGS="--no-sandbox"
43
43
 
44
44
  # Install CLIs
45
- RUN bun add -g @mariozechner/pi-coding-agent@^0.67.2
45
+ RUN bun add -g @earendil-works/pi-coding-agent@~0.79.6
46
46
 
47
47
  WORKDIR /app
48
48
 
@@ -59,7 +59,7 @@ function patch(dir) {
59
59
  const p = path.join(dir, f);
60
60
  try {
61
61
  if (fs.statSync(p).isDirectory()) patch(p);
62
- else if (f === 'google.js' && p.includes('@mariozechner/pi-ai')) {
62
+ else if (f === 'google.js' && p.includes('@earendil-works/pi-ai')) {
63
63
  let c = fs.readFileSync(p, 'utf8');
64
64
  const noThinking = '&& !model.id.startsWith("gemma")';
65
65
  const p1 = 'if (options.thinking?.enabled && model.reasoning) {';
@@ -8,8 +8,9 @@ import {
8
8
  unlinkSync,
9
9
  writeFileSync,
10
10
  } from "node:fs";
11
+ import { createRequire } from "node:module";
11
12
  import { homedir, tmpdir } from "node:os";
12
- import { delimiter, join } from "node:path";
13
+ import { delimiter, dirname, join } from "node:path";
13
14
 
14
15
  const KNOWLEDGE_DIR = "knowledge";
15
16
  const VAULT_DIRS = ["people", "projects", "references", "daily", "episodes", "weekly", "monthly", "templates"];
@@ -135,25 +136,31 @@ function exportMessages(
135
136
  }
136
137
 
137
138
  /**
138
- * Build a child env whose PATH also contains the standard global-bin
139
- * directories where the `pi` CLI is installed. The distill job runs in the
140
- * Mercury HOST process, whichunlike the cloud Docker image, where `pi` is
141
- * always on PATH may have been launched with an incomplete PATH (e.g.
142
- * `bun <abs>/mercury.ts run` from an IDE or a scheduled task resolves
143
- * `.bun/bin` but not the npm global bin). A bare `spawn("pi")` then fails with
144
- * ENOENT before pi ever starts. Appending the well-known global-bin dirs makes
145
- * resolution robust on local installs and is a no-op in the cloud.
139
+ * Build a child env whose PATH also contains directories where the `pi` CLI
140
+ * may live. A global npm install only links the top-level package's bins
141
+ * (mercury, mercury-ctl)dependency bins like `pi` stay in node_modules/.bin.
142
+ * We resolve that .bin dir from the package graph first, then fall back to
143
+ * well-known global-bin dirs (~/.bun/bin, /usr/local/bin).
146
144
  */
147
145
  function envWithPiOnPath(): NodeJS.ProcessEnv {
148
146
  const isWindows = process.platform === "win32";
149
147
  const base = process.env.PATH ?? process.env.Path ?? "";
150
148
  const home = homedir();
149
+
150
+ let piNodeModulesBin: string | undefined;
151
+ try {
152
+ const req = createRequire(import.meta.url);
153
+ const pkgJson = req.resolve("@earendil-works/pi-coding-agent/package.json");
154
+ piNodeModulesBin = join(dirname(dirname(dirname(pkgJson))), ".bin");
155
+ } catch {}
156
+
151
157
  const candidates = [
158
+ piNodeModulesBin,
152
159
  join(home, ".bun", "bin"),
153
160
  isWindows
154
161
  ? join(process.env.APPDATA ?? join(home, "AppData", "Roaming"), "npm")
155
162
  : "/usr/local/bin",
156
- ];
163
+ ].filter(Boolean) as string[];
157
164
  // PATH entries are case-insensitive on Windows, case-sensitive on POSIX.
158
165
  const normalize = (p: string) => (isWindows ? p.toLowerCase() : p);
159
166
  const existing = new Set(base.split(delimiter).map(normalize).filter(Boolean));
@@ -45,20 +45,20 @@ Every entity file follows this shape. The **current** value of a fact lives in B
45
45
 
46
46
  ```markdown
47
47
  ---
48
- name: Ronny Cohen
48
+ name: Alex Carter
49
49
  type: person
50
50
  updated: 2026-05-10
51
- summary: Biotech investor in the tagula group; bullish on SLS.
51
+ summary: Biotech investor in the research group; bullish on ACME.
52
52
  # Structured "current value" fields for facts that are known to change:
53
- sls_price_target: "$15"
53
+ acme_price_target: "$15"
54
54
  ---
55
55
 
56
- # Ronny Cohen
56
+ # Alex Carter
57
57
 
58
- Member of the [[tagula-space]] investing group.
58
+ Member of the [[research-space]] investing group.
59
59
 
60
60
  ## Current View
61
- - SLS price target: **$15** (as of 2026-05-10)
61
+ - ACME price target: **$15** (as of 2026-05-10)
62
62
  - Thesis: bullish, waiting for the Phase 3 readout
63
63
 
64
64
  ## History