@jossuealcala/madre 1.0.5 → 1.1.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/ADDITIONAL-TERMS.md +7 -2
- package/CHANGELOG.en.md +47 -1
- package/CHANGELOG.md +47 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +111 -661
- package/NOTICE +28 -23
- package/README.en.md +30 -101
- package/README.md +30 -103
- package/SECURITY.md +1 -0
- package/TRADEMARKS.en.md +13 -14
- package/TRADEMARKS.md +24 -26
- package/bin/madre.cjs +2 -2
- package/bin/madre.mjs +112 -40
- package/docs/REFERENCE.md +52 -5
- package/docs/SDK.md +21 -3
- package/docs/en/REFERENCE.md +52 -5
- package/docs/en/SDK.md +22 -3
- package/docs/sdk/hello-module.mjs +3 -0
- package/package.json +3 -2
- package/public/abduction.js +6 -6
- package/public/activity.js +425 -0
- package/public/app.js +2468 -435
- package/public/assets/abduction-cat-blink.webp +0 -0
- package/public/assets/abduction-cat-control-left.webp +0 -0
- package/public/assets/abduction-cat-control-right.webp +0 -0
- package/public/assets/abduction-cat.webp +0 -0
- package/public/assets/manual/shots/en-agents.webp +0 -0
- package/public/assets/manual/shots/en-chats.webp +0 -0
- package/public/assets/manual/shots/en-code.webp +0 -0
- package/public/assets/manual/shots/en-composer.webp +0 -0
- package/public/assets/manual/shots/en-connectors.webp +0 -0
- package/public/assets/manual/shots/en-continuity.webp +0 -0
- package/public/assets/manual/shots/en-coordinator.webp +0 -0
- package/public/assets/manual/shots/en-copilot.webp +0 -0
- package/public/assets/manual/shots/en-diagnostics.webp +0 -0
- package/public/assets/manual/shots/en-home.webp +0 -0
- package/public/assets/manual/shots/en-local.webp +0 -0
- package/public/assets/manual/shots/en-market.webp +0 -0
- package/public/assets/manual/shots/en-memory.webp +0 -0
- package/public/assets/manual/shots/en-modes.webp +0 -0
- package/public/assets/manual/shots/en-notes.webp +0 -0
- package/public/assets/manual/shots/en-settings.webp +0 -0
- package/public/assets/manual/shots/en-welcome.webp +0 -0
- package/public/assets/manual/shots/en-windows.webp +0 -0
- package/public/assets/manual/shots/es-agents.webp +0 -0
- package/public/assets/manual/shots/es-chats.webp +0 -0
- package/public/assets/manual/shots/es-code.webp +0 -0
- package/public/assets/manual/shots/es-composer.webp +0 -0
- package/public/assets/manual/shots/es-connectors.webp +0 -0
- package/public/assets/manual/shots/es-continuity.webp +0 -0
- package/public/assets/manual/shots/es-coordinator.webp +0 -0
- package/public/assets/manual/shots/es-copilot.webp +0 -0
- package/public/assets/manual/shots/es-diagnostics.webp +0 -0
- package/public/assets/manual/shots/es-home.webp +0 -0
- package/public/assets/manual/shots/es-local.webp +0 -0
- package/public/assets/manual/shots/es-market.webp +0 -0
- package/public/assets/manual/shots/es-memory.webp +0 -0
- package/public/assets/manual/shots/es-modes.webp +0 -0
- package/public/assets/manual/shots/es-notes.webp +0 -0
- package/public/assets/manual/shots/es-settings.webp +0 -0
- package/public/assets/manual/shots/es-welcome.webp +0 -0
- package/public/assets/manual/shots/es-windows.webp +0 -0
- package/public/assets/news/1.1/en/chats.webp +0 -0
- package/public/assets/news/1.1/en/home.webp +0 -0
- package/public/assets/news/1.1/en/maps.webp +0 -0
- package/public/assets/news/1.1/en/market.webp +0 -0
- package/public/assets/news/1.1/en/permissions.webp +0 -0
- package/public/assets/news/1.1/en/privacy.webp +0 -0
- package/public/assets/news/1.1/en/welcome.webp +0 -0
- package/public/assets/news/1.1/es/chats.webp +0 -0
- package/public/assets/news/1.1/es/home.webp +0 -0
- package/public/assets/news/1.1/es/maps.webp +0 -0
- package/public/assets/news/1.1/es/market.webp +0 -0
- package/public/assets/news/1.1/es/permissions.webp +0 -0
- package/public/assets/news/1.1/es/privacy.webp +0 -0
- package/public/assets/news/1.1/es/welcome.webp +0 -0
- package/public/attribution.js +15 -16
- package/public/brands.js +2 -2
- package/public/code-tools.js +2 -2
- package/public/editor.js +13 -13
- package/public/en.js +413 -4
- package/public/es.js +1345 -483
- package/public/hardware.js +2 -2
- package/public/i18n.js +2 -2
- package/public/icons.js +158 -0
- package/public/index.html +66 -48
- package/public/inquiry.js +2 -2
- package/public/loader.js +271 -2
- package/public/macroverso.js +60 -21
- package/public/manual-content.js +412 -169
- package/public/manual-shots.js +38 -34
- package/public/manual.css +20 -2
- package/public/manual.html +1 -1
- package/public/manual.js +54 -25
- package/public/market-art.js +47 -45
- package/public/market-view.js +111 -33
- package/public/market.js +132 -30
- package/public/mcp-catalog.js +2 -2
- package/public/neural.js +64 -8
- package/public/nostromo-engine.js +709 -40
- package/public/page-errors.js +29 -0
- package/public/power.js +350 -11
- package/public/remedy.js +89 -0
- package/public/resay.js +3 -2
- package/public/review-ask.js +12 -7
- package/public/routing.js +3 -3
- package/public/salas-mac.css +703 -24
- package/public/salas-mac.html +26 -14
- package/public/salas-mac.js +1254 -289
- package/public/salas.css +2 -2
- package/public/salas.html +3 -3
- package/public/salas.js +3 -3
- package/public/styles.css +2404 -291
- package/public/syntax.js +2 -2
- package/public/terms.js +152 -0
- package/public/touch.js +2 -2
- package/public/tour-chapters.js +10 -10
- package/public/tour.js +56 -8
- package/public/troubleshooting.js +182 -11
- package/public/wallpaper.js +4 -3
- package/public/welcome.js +923 -0
- package/src/activity.mjs +85 -0
- package/src/adapters/claude.mjs +61 -35
- package/src/adapters/codex.mjs +18 -5
- package/src/adapters/cursor.mjs +5 -3
- package/src/adapters/gemini.mjs +5 -3
- package/src/adapters/madre.mjs +3 -3
- package/src/adapters/opencode.mjs +73 -10
- package/src/adapters/process.mjs +14 -13
- package/src/adapters/subagents.mjs +159 -0
- package/src/asking.mjs +8 -2
- package/src/auth-probe.mjs +27 -10
- package/src/bridge/devices.mjs +2 -2
- package/src/bridge/handoff.mjs +2 -2
- package/src/bridge/host.mjs +2 -2
- package/src/bridge/network.mjs +2 -2
- package/src/bridge/policy.mjs +3 -3
- package/src/bridge/qr.mjs +2 -2
- package/src/bridge/server.mjs +2 -2
- package/src/builtin-updates.mjs +87 -0
- package/src/capabilities.mjs +2 -2
- package/src/chats.mjs +51 -2
- package/src/checkpoint.mjs +67 -9
- package/src/choices.mjs +2 -2
- package/src/cli-args.mjs +2 -2
- package/src/cold.mjs +2 -2
- package/src/commands.mjs +2 -2
- package/src/config.mjs +2 -2
- package/src/conversation-context.mjs +2 -2
- package/src/credentials.mjs +56 -16
- package/src/dataset.mjs +2 -2
- package/src/directives.mjs +2 -2
- package/src/distiller.mjs +2 -2
- package/src/embeddings.mjs +2 -2
- package/src/enlaces.mjs +2 -2
- package/src/environment.mjs +147 -0
- package/src/event-store.mjs +2 -2
- package/src/exam.mjs +2 -2
- package/src/extensions.mjs +2 -2
- package/src/eyecat-watch.mjs +2 -2
- package/src/eyecat.mjs +2 -2
- package/src/file-ops.mjs +2 -2
- package/src/files.mjs +2 -2
- package/src/github.mjs +2 -2
- package/src/heartbeat.mjs +2 -2
- package/src/history.mjs +2 -2
- package/src/i18n.mjs +9 -2
- package/src/image-studio.mjs +2 -2
- package/src/install-metrics.mjs +109 -0
- package/src/json-file.mjs +2 -2
- package/src/launch.mjs +2 -2
- package/src/lease.mjs +15 -4
- package/src/lobby-work.mjs +11 -4
- package/src/local-ai.mjs +2 -2
- package/src/looks.mjs +2 -2
- package/src/market-check.mjs +165 -0
- package/src/market-key.mjs +10 -2
- package/src/market-license.mjs +4 -4
- package/src/market-remote.mjs +54 -12
- package/src/maturity.mjs +2 -2
- package/src/mcp/connect.mjs +2 -2
- package/src/mcp/github-server.mjs +2 -2
- package/src/mcp/image-server.mjs +2 -2
- package/src/mcp/memory-server.mjs +2 -2
- package/src/mcp/proxy.mjs +2 -2
- package/src/mcp/smtp-server.mjs +2 -2
- package/src/memory-dashboard.mjs +2 -2
- package/src/memory-tools.mjs +2 -2
- package/src/memory.mjs +2 -2
- package/src/models.mjs +33 -3
- package/src/module-scope.mjs +2 -2
- package/src/modules/ahp.mjs +2 -2
- package/src/modules/ash-policy.mjs +2 -2
- package/src/modules/ash.mjs +2 -2
- package/src/modules/bishop-exam.mjs +2 -2
- package/src/modules/bishop-plan.mjs +2 -2
- package/src/modules/bishop.mjs +9 -3
- package/src/modules/choices.mjs +2 -2
- package/src/modules/correo.mjs +2 -2
- package/src/modules/enlaces.mjs +2 -2
- package/src/modules/git-pulse.mjs +2 -2
- package/src/modules/github.mjs +2 -2
- package/src/modules/helpers.mjs +2 -2
- package/src/modules/image-studio.mjs +2 -2
- package/src/modules/index.mjs +90 -5
- package/src/modules/intents-calibration.mjs +2 -2
- package/src/modules/intents-desk.mjs +4 -3
- package/src/modules/intents-observe.mjs +2 -2
- package/src/modules/intents-policy.mjs +2 -2
- package/src/modules/intents-try.mjs +2 -2
- package/src/modules/intents.mjs +2 -2
- package/src/modules/local-models.mjs +14 -11
- package/src/modules/mcp-connect.mjs +2 -2
- package/src/modules/notes.mjs +159 -20
- package/src/modules/ollama.mjs +9 -3
- package/src/modules/playwright.mjs +2 -2
- package/src/modules/reminders.mjs +356 -37
- package/src/modules/ripley.mjs +3 -3
- package/src/modules/runs.mjs +2 -2
- package/src/modules/sdk.mjs +38 -6
- package/src/modules/updates.mjs +2 -2
- package/src/mother.mjs +2 -2
- package/src/npm-launch.mjs +2 -2
- package/src/ollama.mjs +6 -4
- package/src/opencode-health.mjs +26 -6
- package/src/outbound.mjs +10 -2
- package/src/override.mjs +27 -22
- package/src/ports.mjs +2 -2
- package/src/prices.mjs +2 -2
- package/src/privacy.mjs +2 -2
- package/src/quota-monitor.mjs +2 -2
- package/src/quota-sources.mjs +2 -2
- package/src/request-guard.mjs +2 -2
- package/src/review-ask.mjs +4 -3
- package/src/room/archivist.mjs +2 -2
- package/src/room/attachments.mjs +2 -2
- package/src/room/budget.mjs +2 -2
- package/src/room/context.mjs +2 -2
- package/src/room/control.mjs +2 -2
- package/src/room/copilot.mjs +2 -2
- package/src/room/economy.mjs +2 -2
- package/src/room/escalation.mjs +2 -2
- package/src/room/ghost.mjs +2 -2
- package/src/room/guard.mjs +6 -4
- package/src/room/prompt.mjs +3 -3
- package/src/room/returns.mjs +2 -2
- package/src/room/runs.mjs +6 -4
- package/src/room/vectors.mjs +2 -2
- package/src/room.mjs +127 -31
- package/src/router.mjs +2 -2
- package/src/runs.mjs +2 -2
- package/src/runtime-detection.mjs +31 -5
- package/src/salas.mjs +31 -6
- package/src/sentinel-errors.mjs +13 -4
- package/src/server-sentinel.mjs +2 -2
- package/src/server.mjs +689 -80
- package/src/setup-trouble.mjs +33 -0
- package/src/setup.mjs +4 -4
- package/src/smtp.mjs +2 -2
- package/src/telemetry.mjs +266 -0
- package/src/terms.mjs +43 -0
- package/src/tour.mjs +39 -5
- package/src/uninstall.mjs +225 -0
- package/src/updates.mjs +2 -2
- package/src/usage-sentinel.mjs +2 -2
- package/src/vault.mjs +2 -2
- package/src/verdict.mjs +13 -10
- package/src/whats-new.mjs +97 -3
- package/public/assets/abduction-cat-blink.png +0 -0
- package/public/assets/abduction-cat-control-left.png +0 -0
- package/public/assets/abduction-cat-control-right.png +0 -0
- package/public/assets/abduction-cat.png +0 -0
- package/public/assets/manual/madre-manual-en.pdf +0 -0
- package/public/assets/manual/madre-manual-es.pdf +0 -0
- package/public/assets/manual/shots/en-modules.webp +0 -0
- package/public/assets/manual/shots/es-modules.webp +0 -0
- package/src/mcp/notes-server.mjs +0 -120
- package/src/reminder-time.mjs +0 -127
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// Reminders (0.1, 2026-10-20). An idea by Daniel Castillo.
|
|
4
4
|
//
|
|
5
5
|
// What a person says they still have to do gets lost in a conversation: «mañana reviso el PR»,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// Nothing is set without that press.
|
|
10
10
|
//
|
|
11
11
|
// Two ways to notice, the cheap one first:
|
|
12
|
-
// · pending words that mean «later» or «remember» (
|
|
12
|
+
// · pending words that mean «later» or «remember» (WHEN, below, reads the when);
|
|
13
13
|
// · frequent the same request on three different days: offered as a daily reminder.
|
|
14
14
|
// When the project has the local AI, @madre's model reads a candidate before it is offered: it
|
|
15
15
|
// drops what is not a task and writes the task short, in the person's language. Without it the
|
|
@@ -19,18 +19,220 @@
|
|
|
19
19
|
// Reminders are kept for the whole computer, in ~/.pulse/reminders.json, each with the project and
|
|
20
20
|
// the conversation it came from: when it is due, Home shows it in «Needs you», and the project it
|
|
21
21
|
// came from shows it the moment it opens. A repeating one, marked done, comes back at its next time.
|
|
22
|
+
//
|
|
23
|
+
// ONE FILE (SDK 2, 2026-10-25). Everything Reminders is lives here: reading the when, its files,
|
|
24
|
+
// the cards, and the tool server an agent uses. It imports nothing from MADRE — the room's words
|
|
25
|
+
// come through ctx.t and the local AI through ctx.services.ollama — so a newer Reminders can come
|
|
26
|
+
// from the Market, signed, without waiting for a new MADRE (src/builtin-updates.mjs). When an
|
|
27
|
+
// agent runs it with node, the same file is the tool server (at the bottom).
|
|
22
28
|
|
|
23
|
-
import { readFile } from 'node:fs/promises';
|
|
24
|
-
import { basename, join } from 'node:path';
|
|
29
|
+
import { mkdir, open, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
30
|
+
import { basename, dirname, join } from 'node:path';
|
|
25
31
|
import { randomUUID } from 'node:crypto';
|
|
26
|
-
import { defineModule } from './sdk.mjs';
|
|
27
|
-
import { oneAtATime, writeWhole } from '../json-file.mjs';
|
|
28
|
-
import { ollamaGenerate } from '../ollama.mjs';
|
|
29
|
-
import { REPEATS, nextOccurrence, parseWhen, tomorrowMorning } from '../reminder-time.mjs';
|
|
30
32
|
import { fileURLToPath } from 'node:url';
|
|
31
|
-
import { language, t } from '../i18n.mjs';
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
+
const SELF = fileURLToPath(import.meta.url);
|
|
35
|
+
|
|
36
|
+
// FILES THAT MORE THAN ONE THING CHANGES (the same rules as MADRE's src/json-file.mjs): written
|
|
37
|
+
// whole, through a draft renamed over the file, and one change at a time — in this process by a
|
|
38
|
+
// queue, and between the rooms of this computer and the tool server by a lock file beside it.
|
|
39
|
+
async function writeWhole(file, text, { mode } = {}) {
|
|
40
|
+
await mkdir(dirname(file), { recursive: true });
|
|
41
|
+
const draft = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
42
|
+
try {
|
|
43
|
+
await writeFile(draft, text, mode ? { mode } : undefined);
|
|
44
|
+
await rename(draft, file);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
await rm(draft, { force: true }).catch(() => {});
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const STALE_MS = 5000;
|
|
52
|
+
async function lockBeside(file) {
|
|
53
|
+
const lock = `${file}.lock`;
|
|
54
|
+
await mkdir(dirname(lock), { recursive: true });
|
|
55
|
+
for (let attempt = 0; attempt < 250; attempt += 1) {
|
|
56
|
+
try {
|
|
57
|
+
await (await open(lock, 'wx')).close();
|
|
58
|
+
return () => rm(lock, { force: true });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error.code !== 'EEXIST') throw error;
|
|
61
|
+
const since = await stat(lock).catch(() => null);
|
|
62
|
+
if (since && Date.now() - since.mtimeMs > STALE_MS) { await rm(lock, { force: true }); continue; }
|
|
63
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`${file} is being changed by another room; try again.`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const queues = new Map();
|
|
70
|
+
function oneAtATime(file, work) {
|
|
71
|
+
const run = async () => {
|
|
72
|
+
const release = await lockBeside(file);
|
|
73
|
+
try {
|
|
74
|
+
return await work();
|
|
75
|
+
} finally {
|
|
76
|
+
await release();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const before = queues.get(file) ?? Promise.resolve();
|
|
80
|
+
const turn = before.then(run, run);
|
|
81
|
+
const settled = turn.catch(() => {});
|
|
82
|
+
queues.set(file, settled);
|
|
83
|
+
void settled.then(() => { if (queues.get(file) === settled) queues.delete(file); });
|
|
84
|
+
return turn;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// WHEN, read from a person's own words.
|
|
88
|
+
// When a reminder is due, read from a person's own words (Reminders, 2026-10-20).
|
|
89
|
+
//
|
|
90
|
+
// «mañana a las 5», «el lunes», «en 2 horas», «cada día», «tomorrow at 9am», «every monday»: what
|
|
91
|
+
// people write when they say when, in Spanish or in English. Read here, without a model, so the
|
|
92
|
+
// same words always give the same hour and a reminder never depends on a model being awake. What
|
|
93
|
+
// is not said is filled the way a person would: a day without an hour is at 9:00, an hour without
|
|
94
|
+
// a day is the next time that hour comes, and «a las 5» with nothing else is in the afternoon.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
const fold = (text) => String(text ?? '').normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();
|
|
98
|
+
export const REPEATS = ['daily', 'weekdays', 'weekly'];
|
|
99
|
+
const DAYS = [
|
|
100
|
+
['domingo', 'sunday'], ['lunes', 'monday'], ['martes', 'tuesday'], ['miercoles', 'wednesday'],
|
|
101
|
+
['jueves', 'thursday'], ['viernes', 'friday'], ['sabado', 'saturday'],
|
|
102
|
+
];
|
|
103
|
+
const dayIndex = (word) => DAYS.findIndex((names) => names.includes(word));
|
|
104
|
+
const DAY_WORDS = DAYS.flat().join('|');
|
|
105
|
+
const NUMBERS = { un: 1, una: 1, uno: 1, a: 1, an: 1, one: 1, dos: 2, two: 2, tres: 3, three: 3, cuatro: 4, four: 4, cinco: 5, five: 5, diez: 10, ten: 10, quince: 15, fifteen: 15, veinte: 20, twenty: 20, treinta: 30, thirty: 30 };
|
|
106
|
+
const UNIT_MS = { min: 60000, hor: 3600000, hou: 3600000, dia: 86400000, day: 86400000, sem: 7 * 86400000, wee: 7 * 86400000 };
|
|
107
|
+
export const DEFAULT_HOUR = 9;
|
|
108
|
+
|
|
109
|
+
const at = (base, hour, minute = 0) => { const next = new Date(base); next.setHours(hour, minute, 0, 0); return next; };
|
|
110
|
+
const plusDays = (base, days) => { const next = new Date(base); next.setDate(next.getDate() + days); return next; };
|
|
111
|
+
|
|
112
|
+
// The hour said, if any: «a las 5», «a las 17:30», «at 9am», «5 pm», «10:15». `tagged`: whether it
|
|
113
|
+
// said which half of the day (am, pm, «de la tarde»…), so the part of the day may still decide it.
|
|
114
|
+
// In English «at 3» is an hour only when nothing but the time follows it: «look at 3 files» is not.
|
|
115
|
+
const AT_FOLLOWS = /^\s*($|[,.;:!?)]|(?:tomorrow|today|tonight|to|on|in|every|and|then|sharp|o'?clock)\b)/;
|
|
116
|
+
function hourSaid(text) {
|
|
117
|
+
let match = null;
|
|
118
|
+
for (const one of text.matchAll(/\b(a las|a la|at)\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm|a\.m\.|p\.m\.|de la manana|de la tarde|de la noche|hrs|h)?\b/g)) {
|
|
119
|
+
if (one[1] === 'at' && !one[3] && !one[4] && !AT_FOLLOWS.test(text.slice(one.index + one[0].length))) continue;
|
|
120
|
+
match = one.slice(1);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
match ??= text.match(/\b()(\d{1,2}):(\d{2})\s*(am|pm|a\.m\.|p\.m\.)?/)?.slice(1)
|
|
124
|
+
?? text.match(/\b()(\d{1,2})()\s*(am|pm|a\.m\.|p\.m\.)(?![a-z])/)?.slice(1);
|
|
125
|
+
if (!match) return null;
|
|
126
|
+
let hour = Number(match[1]);
|
|
127
|
+
const minute = Number(match[2] || 0);
|
|
128
|
+
const tag = match[3] ?? '';
|
|
129
|
+
if (hour > 23 || minute > 59) return null;
|
|
130
|
+
if (/pm|p\.m\.|tarde|noche/.test(tag) && hour < 12) hour += 12;
|
|
131
|
+
else if (/am|a\.m\.|manana/.test(tag) && hour === 12) hour = 0;
|
|
132
|
+
// «a las 5» with nothing else: a person at work means the afternoon, not dawn.
|
|
133
|
+
else if (!tag && hour >= 1 && hour <= 7) hour += 12;
|
|
134
|
+
// A 24-hour clock («a las 17», «9 hrs») or a half said (pm, «de la tarde») is not the part of the day's to change.
|
|
135
|
+
return { hour, minute, tagged: Number(match[1]) > 12 || Boolean(tag) };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// The part of the day said in words, when no hour was.
|
|
139
|
+
function partOfDay(text) {
|
|
140
|
+
if (/\b(esta noche|en la noche|por la noche|tonight|in the evening)\b/.test(text)) return { hour: 20, minute: 0 };
|
|
141
|
+
if (/\b(esta tarde|en la tarde|por la tarde|this afternoon|in the afternoon)\b/.test(text)) return { hour: 17, minute: 0 };
|
|
142
|
+
if (/\b(en la manana|por la manana|in the morning)\b/.test(text)) return { hour: 9, minute: 0 };
|
|
143
|
+
if (/\b(al mediodia|a mediodia|at noon|noon)\b/.test(text)) return { hour: 12, minute: 0 };
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// What repeats, and on which day for a weekly one.
|
|
148
|
+
function repeatOf(text) {
|
|
149
|
+
const weekly = text.match(new RegExp(`\\b(?:cada|todos los|every)\\s+(${DAY_WORDS})s?\\b`));
|
|
150
|
+
if (weekly) return { repeat: 'weekly', day: dayIndex(weekly[1]) };
|
|
151
|
+
if (/\b(entre semana|de lunes a viernes|every weekday|weekdays)\b/.test(text)) return { repeat: 'weekdays' };
|
|
152
|
+
if (/\b(cada dia|todos los dias|diario|diariamente|cada manana|todas las mananas|every day|everyday|daily|each day|every morning)\b/.test(text)) return { repeat: 'daily' };
|
|
153
|
+
if (/\b(cada semana|semanal(mente)?|every week|weekly)\b/.test(text)) return { repeat: 'weekly' };
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// The next time a repeating reminder comes after `after`.
|
|
158
|
+
export function nextOccurrence(due, repeat, after = new Date()) {
|
|
159
|
+
let next = new Date(due);
|
|
160
|
+
if (!REPEATS.includes(repeat)) return next;
|
|
161
|
+
const step = () => {
|
|
162
|
+
if (repeat === 'weekly') next = plusDays(next, 7);
|
|
163
|
+
else {
|
|
164
|
+
next = plusDays(next, 1);
|
|
165
|
+
if (repeat === 'weekdays') while (next.getDay() === 0 || next.getDay() === 6) next = plusDays(next, 1);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
for (let guard = 0; next <= after && guard < 4000; guard += 1) step();
|
|
169
|
+
return next;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// { due, repeat, said } for the words, or null when they say no time at all.
|
|
173
|
+
export function parseWhen(words, now = new Date(), { hour: dayHour = DEFAULT_HOUR } = {}) {
|
|
174
|
+
const text = fold(words);
|
|
175
|
+
const base = new Date(now);
|
|
176
|
+
const repeated = repeatOf(text);
|
|
177
|
+
// The part of the day decides an hour that did not say its half: «esta noche a las 9» is 21:00,
|
|
178
|
+
// «en la mañana a las 5» is 5:00.
|
|
179
|
+
const clock = hourSaid(text);
|
|
180
|
+
const part = partOfDay(text);
|
|
181
|
+
let hour = clock ?? part;
|
|
182
|
+
if (clock && !clock.tagged && part) {
|
|
183
|
+
if (part.hour >= 17 && clock.hour < 12) hour = { ...clock, hour: clock.hour + 12 };
|
|
184
|
+
else if (part.hour === 9 && clock.hour > 12) hour = { ...clock, hour: clock.hour - 12 };
|
|
185
|
+
}
|
|
186
|
+
const said = [];
|
|
187
|
+
|
|
188
|
+
// «en 2 horas», «en media hora», «in 20 minutes»: a moment from now, the hour does not apply.
|
|
189
|
+
const relative = text.match(/\b(?:en|in|dentro de)\s+(\d+|media|half an?|un|una|uno|a|an|one|dos|two|tres|three|cuatro|four|cinco|five|diez|ten|quince|fifteen|veinte|twenty|treinta|thirty)\s+(min\w*|hor\w*|hou\w*|dia\w*|day\w*|sem\w*|wee\w*)/);
|
|
190
|
+
if (relative && !repeated) {
|
|
191
|
+
const amount = /^(media|half)/.test(relative[1]) ? 0.5 : Number(relative[1]) || NUMBERS[relative[1]] || 1;
|
|
192
|
+
const unit = UNIT_MS[relative[2].slice(0, 3)] ?? 3600000;
|
|
193
|
+
return { due: new Date(base.getTime() + amount * unit), repeat: null, said: relative[0] };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let day = null;
|
|
197
|
+
if (/\bpasado manana\b|\bday after tomorrow\b/.test(text)) { day = plusDays(base, 2); said.push('pasado mañana'); }
|
|
198
|
+
// «mañana» is tomorrow unless it is the morning: «la mañana», «de la mañana», «por la mañana».
|
|
199
|
+
else if (/(^|[^a-z])(manana)(?![a-z])/.test(text.replace(/\b(la|las|en la|por la|de la|cada|todas las)\s+manana(s)?\b/g, ' ')) || /\btomorrow\b/.test(text)) { day = plusDays(base, 1); said.push('mañana'); }
|
|
200
|
+
else if (/\b(hoy|today|tonight|esta tarde|esta noche|this afternoon)\b/.test(text)) { day = new Date(base); said.push('hoy'); }
|
|
201
|
+
else if (/\b(la proxima semana|la semana que viene|next week)\b/.test(text)) {
|
|
202
|
+
day = plusDays(base, ((8 - base.getDay()) % 7) || 7);
|
|
203
|
+
said.push('la próxima semana');
|
|
204
|
+
} else {
|
|
205
|
+
const named = text.match(new RegExp(`\\b(?:el|este|el proximo|on|next|this)?\\s*(${DAY_WORDS})\\b`));
|
|
206
|
+
if (named && !repeated) {
|
|
207
|
+
const target = dayIndex(named[1]);
|
|
208
|
+
const ahead = (target - base.getDay() + 7) % 7;
|
|
209
|
+
day = plusDays(base, ahead || 7);
|
|
210
|
+
said.push(named[1]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (repeated) {
|
|
215
|
+
let first = at(base, hour?.hour ?? dayHour, hour?.minute ?? 0);
|
|
216
|
+
if (repeated.repeat === 'weekly' && Number.isInteger(repeated.day)) first = plusDays(first, (repeated.day - base.getDay() + 7) % 7);
|
|
217
|
+
if (repeated.repeat === 'weekdays') while (first.getDay() === 0 || first.getDay() === 6) first = plusDays(first, 1);
|
|
218
|
+
const due = first > base ? first : nextOccurrence(first, repeated.repeat, base);
|
|
219
|
+
return { due, repeat: repeated.repeat, said: 'repeat' };
|
|
220
|
+
}
|
|
221
|
+
if (day) {
|
|
222
|
+
const due = at(day, hour?.hour ?? dayHour, hour?.minute ?? 0);
|
|
223
|
+
// «hoy a las 8» written at 23:00: never born overdue — the same hour, tomorrow.
|
|
224
|
+
return { due: due > base ? due : plusDays(due, 1), repeat: null, said: said.join(' ') };
|
|
225
|
+
}
|
|
226
|
+
if (hour) {
|
|
227
|
+
const today = at(base, hour.hour, hour.minute);
|
|
228
|
+
return { due: today > base ? today : plusDays(today, 1), repeat: null, said: 'hour' };
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// When nothing was said: tomorrow, at the start of the day (the person's own start, from Reminders' settings).
|
|
234
|
+
export const tomorrowMorning = (now = new Date(), hour = DEFAULT_HOUR) => at(plusDays(now, 1), hour);
|
|
235
|
+
|
|
34
236
|
// A message that asks for a reminder (2026-10-20): «/recordatorios …», «/reminders …», «recuérdame».
|
|
35
237
|
export const ASKS_FOR_REMINDER = /(^|\s)\/(recordatorios?|reminders?|remind)\b|recu[eé]rd(ame|anos|ale)|\brecordatorios?\b|\bremind(er|ers)?\b/i;
|
|
36
238
|
|
|
@@ -40,7 +242,6 @@ const ID = /^[a-z0-9-]{6,64}$/i;
|
|
|
40
242
|
const remindersFile = (stateRoot) => join(stateRoot, 'reminders.json');
|
|
41
243
|
const habitsFile = (roomDir) => join(roomDir, 'reminder-habits.json');
|
|
42
244
|
const iso = (value) => (typeof value === 'string' && !Number.isNaN(Date.parse(value)) ? new Date(value).toISOString() : null);
|
|
43
|
-
const fold = (text) => String(text ?? '').normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();
|
|
44
245
|
|
|
45
246
|
function reminderOf(raw) {
|
|
46
247
|
if (!raw || typeof raw !== 'object' || !ID.test(String(raw.id ?? '')) || !iso(raw.due)) return null;
|
|
@@ -56,6 +257,8 @@ function reminderOf(raw) {
|
|
|
56
257
|
chat: typeof raw.chat === 'string' && raw.chat.length <= 120 ? raw.chat : null,
|
|
57
258
|
why: ['pending', 'frequent', 'asked', 'manual'].includes(raw.why) ? raw.why : 'manual',
|
|
58
259
|
done: iso(raw.done),
|
|
260
|
+
// A repeating one put off: the time of its series, which «Done» goes on from.
|
|
261
|
+
series: REPEATS.includes(raw.repeat) ? iso(raw.series) : null,
|
|
59
262
|
at: iso(raw.at) ?? new Date(0).toISOString(),
|
|
60
263
|
};
|
|
61
264
|
}
|
|
@@ -84,20 +287,27 @@ export function addReminder(stateRoot, { text, due, repeat = null, room = null,
|
|
|
84
287
|
return { reminder: made };
|
|
85
288
|
});
|
|
86
289
|
}
|
|
87
|
-
// Done: a repeating one moves to its next time
|
|
290
|
+
// Done: a repeating one moves to its next time — also when it is marked before its hour today, which
|
|
291
|
+
// counts for today — from the hour of its series, not from where a snooze had moved it; any other is
|
|
292
|
+
// kept as done.
|
|
88
293
|
export function doneReminder(stateRoot, id, now = new Date()) {
|
|
89
294
|
return change(stateRoot, (reminders) => {
|
|
90
295
|
const one = reminders.find((item) => item.id === id);
|
|
91
296
|
if (!one) return { error: 'unknown', write: false };
|
|
92
|
-
if (one.repeat)
|
|
93
|
-
|
|
297
|
+
if (one.repeat) {
|
|
298
|
+
const after = new Date(Math.max(new Date(now).getTime(), new Date(one.due).getTime()));
|
|
299
|
+
one.due = nextOccurrence(one.series ?? one.due, one.repeat, after).toISOString();
|
|
300
|
+
one.series = null;
|
|
301
|
+
} else one.done = new Date(now).toISOString();
|
|
94
302
|
return { reminder: one };
|
|
95
303
|
});
|
|
96
304
|
}
|
|
305
|
+
// Later: this time only. A repeating one keeps the hour of its series (`series`) to come back to.
|
|
97
306
|
export function snoozeReminder(stateRoot, id, until) {
|
|
98
307
|
return change(stateRoot, (reminders) => {
|
|
99
308
|
const one = reminders.find((item) => item.id === id);
|
|
100
309
|
if (!one || !iso(until)) return { error: 'unknown', write: false };
|
|
310
|
+
if (one.repeat) one.series ??= one.due;
|
|
101
311
|
one.due = iso(until);
|
|
102
312
|
one.done = null;
|
|
103
313
|
return { reminder: one };
|
|
@@ -176,9 +386,9 @@ export function noteHabit(roomDir, text, now = new Date()) {
|
|
|
176
386
|
|
|
177
387
|
// The local model's reading of a candidate: is it a task, and how would a reminder say it.
|
|
178
388
|
const LOCAL_SYSTEM = 'You read one message a person wrote to their AI agents about their project. Decide whether it holds something the PERSON must do or remember later: a pending task, a deadline, a follow-up, or something they asked to be reminded of. Questions, instructions for the agents to do now, and plans already done are not. Answer with JSON only: {"remind": true|false, "what": "the task as a short reminder, imperative, in the same language as the message, at most 80 characters", "when": "when it is due, in the words of the message, or empty"}.';
|
|
179
|
-
export async function readWithLocal({
|
|
389
|
+
export async function readWithLocal({ generate, model = null, text, timeoutMs = 45000 }) {
|
|
180
390
|
try {
|
|
181
|
-
const answer = await
|
|
391
|
+
const answer = await generate({ model, system: LOCAL_SYSTEM, prompt: String(text).slice(0, 2000), json: true, timeoutMs, temperature: 0 });
|
|
182
392
|
const parsed = JSON.parse(answer.text);
|
|
183
393
|
if (typeof parsed?.remind !== 'boolean') return null;
|
|
184
394
|
return { remind: parsed.remind, what: typeof parsed.what === 'string' ? parsed.what.trim().replace(/[.!¡]+$/, '').slice(0, REMINDER_TEXT_MAX) : '', when: typeof parsed.when === 'string' ? parsed.when.slice(0, 120) : '' };
|
|
@@ -188,7 +398,7 @@ export async function readWithLocal({ host, model, text, fetchImpl = globalThis.
|
|
|
188
398
|
// One offer per conversation every few minutes, unless the person asked for it in words.
|
|
189
399
|
const lastOffer = new Map();
|
|
190
400
|
const OFFER_GAP_MS = 10 * 60 * 1000;
|
|
191
|
-
export async function offerFor(ctx, event, { now = new Date()
|
|
401
|
+
export async function offerFor(ctx, event, { now = new Date() } = {}) {
|
|
192
402
|
const said = event?.payload ?? {};
|
|
193
403
|
if (event?.type !== 'message.created' || said.role !== 'user' || said.via || said.synthetic) return null;
|
|
194
404
|
const text = String(said.text ?? '');
|
|
@@ -208,8 +418,9 @@ export async function offerFor(ctx, event, { now = new Date(), fetchImpl = globa
|
|
|
208
418
|
const local = ctx.services?.ollama?.state?.() ?? null;
|
|
209
419
|
const project = await Promise.resolve(ctx.services?.ollama?.project?.()).catch(() => null);
|
|
210
420
|
const model = local?.madreModel ?? local?.chatModel ?? null;
|
|
211
|
-
|
|
212
|
-
|
|
421
|
+
const generate = ctx.services?.ollama?.generate;
|
|
422
|
+
if (prefs.local !== false && typeof generate === 'function' && local?.running && model && project?.on !== false && found.why !== 'frequent') {
|
|
423
|
+
const read = await readWithLocal({ generate, model, text });
|
|
213
424
|
if (read && !read.remind && found.why !== 'asked') return null;
|
|
214
425
|
if (read?.what) { what = read.what; by = 'local'; }
|
|
215
426
|
if (read?.when) whenWords = `${read.when} ${text}`;
|
|
@@ -228,9 +439,9 @@ export const HOURS = ['7', '8', '9', '10', '11', '12'];
|
|
|
228
439
|
export const SNOOZES = ['15', '30', '60', '180'];
|
|
229
440
|
const hourOf = (prefs) => (HOURS.includes(String(prefs?.hour)) ? Number(prefs.hour) : 9);
|
|
230
441
|
const snoozeOf = (prefs) => (SNOOZES.includes(String(prefs?.snooze)) ? Number(prefs.snooze) : 60);
|
|
231
|
-
const prefsOf = (ctx) =>
|
|
442
|
+
const prefsOf = (ctx) => ctx.settings ?? {};
|
|
232
443
|
// A due time said as a person reads it, in the room's language.
|
|
233
|
-
export const whenWords = (due) => new Intl.DateTimeFormat(language
|
|
444
|
+
export const whenWords = (due, language = 'es') => new Intl.DateTimeFormat(language === 'en' ? 'en-US' : 'es-MX', { weekday: 'long', day: 'numeric', month: 'long', hour: 'numeric', minute: '2-digit' }).format(new Date(due));
|
|
234
445
|
const projectOf = (ctx) => (ctx.roomId ? basename(ctx.projectRoot ?? '') || null : null);
|
|
235
446
|
// The quick times a card offers beside the one it chose, said as data the page puts in words.
|
|
236
447
|
export function quickTimes(now = new Date()) {
|
|
@@ -245,7 +456,11 @@ export function quickTimes(now = new Date()) {
|
|
|
245
456
|
];
|
|
246
457
|
}
|
|
247
458
|
|
|
248
|
-
|
|
459
|
+
// The room's words (ctx.t, SDK 2); outside a room — a test, the tool server — the English as written.
|
|
460
|
+
const say = (ctx, text, vars = null) => (typeof ctx?.t === 'function' ? ctx.t(text, vars) : String(text).replace(/\{(\w+)\}/g, (whole, name) => (vars && Object.hasOwn(vars, name) ? String(vars[name]) : whole)));
|
|
461
|
+
|
|
462
|
+
export default {
|
|
463
|
+
sdk: 2,
|
|
249
464
|
id: 'reminders',
|
|
250
465
|
name: 'Reminders',
|
|
251
466
|
vendor: 'MADRE',
|
|
@@ -264,8 +479,12 @@ const reminders = defineModule({
|
|
|
264
479
|
async status(ctx) {
|
|
265
480
|
const enabled = Boolean(ctx.settings.enabled);
|
|
266
481
|
const list = (await readReminders(ctx.stateRoot)).filter((one) => !one.done && (!ctx.roomId || one.room === ctx.roomId));
|
|
482
|
+
// What is still to come, and what already fell due, said apart (QA 1.1.0, ACT-10).
|
|
483
|
+
const due = list.filter((one) => Date.parse(one.due) <= Date.now()).length;
|
|
484
|
+
const ahead = list.length - due;
|
|
485
|
+
const words = [ahead === 1 ? say(ctx, '1 reminder ahead') : say(ctx, '{n} reminders ahead', { n: ahead }), due ? (due === 1 ? say(ctx, '1 due') : say(ctx, '{n} due', { n: due })) : null].filter(Boolean).join(' · ');
|
|
267
486
|
return {
|
|
268
|
-
status: { installed: enabled, detail: enabled ?
|
|
487
|
+
status: { installed: enabled, detail: enabled ? words : say(ctx, 'off') },
|
|
269
488
|
install: { display: enabled ? 'turn off Reminders' : 'turn on Reminders', platforms: [] },
|
|
270
489
|
};
|
|
271
490
|
},
|
|
@@ -273,13 +492,14 @@ const reminders = defineModule({
|
|
|
273
492
|
const offer = await offerFor(ctx, event);
|
|
274
493
|
if (offer) await ctx.record('reminder.offered', offer);
|
|
275
494
|
},
|
|
276
|
-
// An agent sets a reminder when the person asks for one (
|
|
495
|
+
// An agent sets a reminder when the person asks for one (this same file, run as its tool server):
|
|
496
|
+
// it can only add.
|
|
277
497
|
async toolsForTurn(ctx, turn) {
|
|
278
498
|
if (turn?.text !== undefined && !ASKS_FOR_REMINDER.test(turn.text)) return [];
|
|
279
499
|
return [{
|
|
280
500
|
name: 'madre-reminders',
|
|
281
501
|
command: process.execPath,
|
|
282
|
-
args: [
|
|
502
|
+
args: [SELF],
|
|
283
503
|
env: { PULSE_REMINDERS_STATE: ctx.stateRoot, PULSE_ROOM_ID: ctx.roomId ?? '', PULSE_PROJECT: projectOf(ctx) ?? '', PULSE_REMINDER_HOUR: String(hourOf(ctx.settings)) },
|
|
284
504
|
tools: ['create_reminder'],
|
|
285
505
|
brief: 'When the person asks to be reminded of something (they may write /recordatorios or /reminders), set it with the create_reminder tool of server madre-reminders: what to remember, short, in their language, and when, in their own words. Then tell them when it is due.',
|
|
@@ -298,23 +518,23 @@ const reminders = defineModule({
|
|
|
298
518
|
} },
|
|
299
519
|
{ method: 'POST', path: '/api/reminders', handler: async (ctx, { payload }) => {
|
|
300
520
|
const text = String(payload?.text ?? '').trim();
|
|
301
|
-
if (!text) return reply(400, { error:
|
|
521
|
+
if (!text) return reply(400, { error: say(ctx, 'Write what to remember.') });
|
|
302
522
|
const dayHour = hourOf(prefsOf(ctx));
|
|
303
523
|
const when = iso(payload?.due) ? { due: new Date(payload.due), repeat: REPEATS.includes(payload?.repeat) ? payload.repeat : null } : parseWhen(`${payload?.when ?? ''} ${text}`, new Date(), { hour: dayHour }) ?? { due: tomorrowMorning(new Date(), dayHour), repeat: null };
|
|
304
524
|
const made = await addReminder(ctx.stateRoot, { text: taskFromWords(text), due: when.due.toISOString(), repeat: when.repeat, room: ctx.roomId ?? null, project: projectOf(ctx), why: 'manual' });
|
|
305
|
-
return made.error ? reply(409, { error:
|
|
525
|
+
return made.error ? reply(409, { error: say(ctx, 'The reminder was not set.') }) : reply(200, made);
|
|
306
526
|
} },
|
|
307
527
|
// The answer to a card: yes with the time it offered or one of the quick ones, or no.
|
|
308
528
|
{ method: 'POST', path: '/api/reminders/answer', handler: async (ctx, { payload }) => {
|
|
309
529
|
const offer = String(payload?.offer ?? '');
|
|
310
|
-
if (!ID.test(offer)) return reply(400, { error:
|
|
530
|
+
if (!ID.test(offer)) return reply(400, { error: say(ctx, 'That offer is not known.') });
|
|
311
531
|
const chat = typeof payload?.chat === 'string' ? payload.chat : null;
|
|
312
532
|
let made = null;
|
|
313
533
|
if (payload?.accept === true) {
|
|
314
534
|
const due = iso(payload?.due);
|
|
315
|
-
if (!due) return reply(400, { error:
|
|
535
|
+
if (!due) return reply(400, { error: say(ctx, 'Say when.') });
|
|
316
536
|
made = await addReminder(ctx.stateRoot, { text: String(payload?.text ?? ''), due, repeat: REPEATS.includes(payload?.repeat) ? payload.repeat : null, room: ctx.roomId ?? null, project: projectOf(ctx), chat, why: ['pending', 'frequent', 'asked'].includes(payload?.why) ? payload.why : 'pending' });
|
|
317
|
-
if (made.error) return reply(409, { error:
|
|
537
|
+
if (made.error) return reply(409, { error: say(ctx, 'The reminder was not set.') });
|
|
318
538
|
}
|
|
319
539
|
const settled = { offer, accepted: Boolean(made), id: made?.reminder.id ?? null, due: made?.reminder.due ?? null, repeat: made?.reminder.repeat ?? null };
|
|
320
540
|
await ctx.services.recordIn(chat, 'reminder.answered', settled).catch(() => null);
|
|
@@ -322,14 +542,14 @@ const reminders = defineModule({
|
|
|
322
542
|
} },
|
|
323
543
|
{ method: 'POST', path: '/api/reminders/done', handler: async (ctx, { payload }) => {
|
|
324
544
|
const done = await doneReminder(ctx.stateRoot, String(payload?.id ?? ''));
|
|
325
|
-
return done.error ? reply(404, { error:
|
|
545
|
+
return done.error ? reply(404, { error: say(ctx, 'That reminder is no longer here.') }) : reply(200, done);
|
|
326
546
|
} },
|
|
327
547
|
{ method: 'POST', path: '/api/reminders/snooze', handler: async (ctx, { payload }) => {
|
|
328
548
|
const minutes = Number(payload?.minutes);
|
|
329
549
|
const until = iso(payload?.until) ?? (Number.isFinite(minutes) && minutes > 0 && minutes <= 60 * 24 * 30 ? new Date(Date.now() + minutes * 60000).toISOString() : null);
|
|
330
|
-
if (!until) return reply(400, { error:
|
|
550
|
+
if (!until) return reply(400, { error: say(ctx, 'Say when.') });
|
|
331
551
|
const moved = await snoozeReminder(ctx.stateRoot, String(payload?.id ?? ''), until);
|
|
332
|
-
return moved.error ? reply(404, { error:
|
|
552
|
+
return moved.error ? reply(404, { error: say(ctx, 'That reminder is no longer here.') }) : reply(200, moved);
|
|
333
553
|
} },
|
|
334
554
|
// The history emptied: the done ones of this project, or of every project in Home.
|
|
335
555
|
{ method: 'POST', path: '/api/reminders/clear-done', handler: async (ctx) => {
|
|
@@ -338,8 +558,107 @@ const reminders = defineModule({
|
|
|
338
558
|
} },
|
|
339
559
|
{ method: 'POST', path: '/api/reminders/delete', handler: async (ctx, { payload }) => {
|
|
340
560
|
const gone = await deleteReminder(ctx.stateRoot, String(payload?.id ?? ''));
|
|
341
|
-
return gone.error ? reply(404, { error:
|
|
561
|
+
return gone.error ? reply(404, { error: say(ctx, 'That reminder is no longer here.') }) : reply(200, gone);
|
|
342
562
|
} },
|
|
343
563
|
],
|
|
344
|
-
}
|
|
345
|
-
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// THE TOOL SERVER (MCP over stdio, JSON-RPC 2.0), when an agent's turn runs this file with node:
|
|
567
|
+
// one tool, create_reminder. It only adds — it cannot read, change or delete the person's
|
|
568
|
+
// reminders, which stay theirs — and it writes the same file the page reads.
|
|
569
|
+
//
|
|
570
|
+
// Environment:
|
|
571
|
+
// PULSE_REMINDERS_STATE ~/.pulse, where reminders.json is kept
|
|
572
|
+
// PULSE_ROOM_ID the project's room id, kept on each reminder
|
|
573
|
+
// PULSE_PROJECT the project's name, for Home
|
|
574
|
+
// PULSE_REMINDER_HOUR the hour a day starts at for a reminder with no hour (Reminders' setting)
|
|
575
|
+
const SERVER_NAME = 'madre-reminders';
|
|
576
|
+
const SERVER_VERSION = '2.0.0';
|
|
577
|
+
const REMINDER_TOOL = {
|
|
578
|
+
name: 'create_reminder',
|
|
579
|
+
description: 'Set a reminder for the person. Use it when they ask to be reminded of something (they may write /recordatorios or /reminders). MADRE tells them when it is due, in Home and in this project.',
|
|
580
|
+
inputSchema: { type: 'object', properties: { what: { type: 'string', description: 'What to remember, short, in the person\'s language.' }, when: { type: 'string', description: 'When, in the person\'s own words: «mañana a las 5», «el lunes», «every day at 9», «in 2 hours». Empty for tomorrow morning.' } }, required: ['what'] },
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// This file imports nothing of MADRE: the hour is written in the language the computer runs in.
|
|
584
|
+
export function localWhen(iso, language = undefined) {
|
|
585
|
+
const when = new Date(iso);
|
|
586
|
+
if (Number.isNaN(when.getTime())) return String(iso);
|
|
587
|
+
const locale = language === 'en' ? 'en-US' : language === 'es' ? 'es-MX' : undefined;
|
|
588
|
+
try {
|
|
589
|
+
return when.toLocaleString(locale, { weekday: 'long', day: 'numeric', month: 'long', hour: 'numeric', minute: '2-digit' });
|
|
590
|
+
} catch { return when.toString(); }
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async function createReminder(args, env) {
|
|
594
|
+
const what = taskFromWords(String(args.what ?? '').trim());
|
|
595
|
+
if (!what) throw new Error('The reminder needs what to remember.');
|
|
596
|
+
const hour = Number(env.PULSE_REMINDER_HOUR) || 9;
|
|
597
|
+
const when = parseWhen(String(args.when ?? ''), new Date(), { hour }) ?? { due: tomorrowMorning(new Date(), hour), repeat: null };
|
|
598
|
+
const made = await addReminder(env.PULSE_REMINDERS_STATE, { text: what, due: when.due.toISOString(), repeat: when.repeat, room: env.PULSE_ROOM_ID || null, project: env.PULSE_PROJECT || null, why: 'asked' });
|
|
599
|
+
if (made.error) throw new Error('The reminder was not set.');
|
|
600
|
+
// The hour as this computer reads it (QA 1.1.0, NUE-29): handed only the ISO time, an agent told
|
|
601
|
+
// a person in Mexico City «a las 03:09 UTC» for a reminder due at 21:09 where they are.
|
|
602
|
+
const local = localWhen(made.reminder.due);
|
|
603
|
+
return `Reminder set: «${made.reminder.text}», due ${local} (this computer's local time; ${made.reminder.due} in UTC)${made.reminder.repeat ? `, repeating ${made.reminder.repeat}` : ''}. Tell the person when, in their words and in that local time, never in UTC.`;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function handleRequest(message, { env = process.env } = {}) {
|
|
607
|
+
const reply = (result) => ({ jsonrpc: '2.0', id: message.id, result });
|
|
608
|
+
const fail = (code, text) => ({ jsonrpc: '2.0', id: message.id, error: { code, message: text } });
|
|
609
|
+
const tools = env.PULSE_REMINDERS_STATE ? [REMINDER_TOOL] : [];
|
|
610
|
+
switch (message.method) {
|
|
611
|
+
case 'initialize':
|
|
612
|
+
return Promise.resolve(reply({ protocolVersion: message.params?.protocolVersion ?? '2025-06-18', capabilities: { tools: {} }, serverInfo: { name: SERVER_NAME, version: SERVER_VERSION } }));
|
|
613
|
+
case 'notifications/initialized':
|
|
614
|
+
case 'initialized':
|
|
615
|
+
return Promise.resolve(null);
|
|
616
|
+
case 'ping':
|
|
617
|
+
return Promise.resolve(reply({}));
|
|
618
|
+
case 'tools/list':
|
|
619
|
+
return Promise.resolve(reply({ tools }));
|
|
620
|
+
case 'tools/call': {
|
|
621
|
+
const { name, arguments: args = {} } = message.params ?? {};
|
|
622
|
+
if (!tools.some((tool) => tool.name === name)) return Promise.resolve(fail(-32602, `Unknown tool: ${name}`));
|
|
623
|
+
return createReminder(args, env)
|
|
624
|
+
.then((text) => reply({ content: [{ type: 'text', text }], isError: false }))
|
|
625
|
+
.catch((error) => reply({ content: [{ type: 'text', text: `Nothing was saved: ${error.message}` }], isError: true }));
|
|
626
|
+
}
|
|
627
|
+
default:
|
|
628
|
+
return Promise.resolve(message.id === undefined ? null : fail(-32601, `Method not found: ${message.method}`));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export function serve({ input = process.stdin, output = process.stdout, env = process.env } = {}) {
|
|
633
|
+
let buffer = '';
|
|
634
|
+
let pending = 0;
|
|
635
|
+
let ended = false;
|
|
636
|
+
const finish = () => { if (ended && pending === 0) process.exit(0); };
|
|
637
|
+
input.setEncoding('utf8');
|
|
638
|
+
input.on('data', (chunk) => {
|
|
639
|
+
buffer += chunk;
|
|
640
|
+
let index;
|
|
641
|
+
while ((index = buffer.indexOf('\n')) >= 0) {
|
|
642
|
+
const line = buffer.slice(0, index).trim();
|
|
643
|
+
buffer = buffer.slice(index + 1);
|
|
644
|
+
if (!line) continue;
|
|
645
|
+
let message;
|
|
646
|
+
try { message = JSON.parse(line); } catch { output.write(`${JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } })}\n`); continue; }
|
|
647
|
+
pending += 1;
|
|
648
|
+
void handleRequest(message, { env })
|
|
649
|
+
.then((response) => { if (response) output.write(`${JSON.stringify(response)}\n`); })
|
|
650
|
+
.finally(() => { pending -= 1; finish(); });
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
input.on('end', () => { ended = true; finish(); });
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Both paths resolved before they are compared (WIN-004), as the other servers do.
|
|
657
|
+
const real = async (path) => (path ? realpath(path).catch(() => path) : null);
|
|
658
|
+
if (process.argv[1] && (await real(process.argv[1])) === (await real(SELF))) {
|
|
659
|
+
if (!process.env.PULSE_REMINDERS_STATE) {
|
|
660
|
+
process.stderr.write('PULSE_REMINDERS_STATE is required.\n');
|
|
661
|
+
process.exit(2);
|
|
662
|
+
}
|
|
663
|
+
serve();
|
|
664
|
+
}
|
package/src/modules/ripley.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// RIPLEY: the file viewer renders HTML, SVG and Markdown inside a sealed frame.
|
|
4
4
|
// A switch in config.json, read live by the preview route.
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ import { t } from '../i18n.mjs';
|
|
|
9
9
|
export default defineModule({
|
|
10
10
|
id: 'ripley',
|
|
11
11
|
name: 'Preview',
|
|
12
|
-
vendor: 'MADRE ·
|
|
12
|
+
vendor: 'MADRE · Preview',
|
|
13
13
|
version: '1.0.0',
|
|
14
14
|
summary: 'Renders HTML, SVG and Markdown from the project in the file viewer, inside a sealed frame, and opens a browser on the servers answering on this computer.',
|
|
15
15
|
creates: ['nothing in the project', 'a switch in ~/.pulse/config.json', 'scripts run in the frame \u00b7 nothing leaves, nothing is stored, nothing reaches MADRE'],
|
package/src/modules/runs.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// Runs: letting an agent ask the human to run a command instead of asking them to copy it.
|
|
4
4
|
//
|
|
5
5
|
// Below #4 AIRLOCK an agent cannot run anything, and some answers turn on a command anyway: the
|