dsh-cross-memory 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +253 -2
- package/cordis.patch.yml +27 -0
- package/docs/DETAIL.md +13 -0
- package/docs/DETAIL.zh.md +17 -0
- package/icon.svg +1 -0
- package/lib/backfill.js +273 -0
- package/lib/citations.js +305 -0
- package/lib/client.js +1660 -0
- package/lib/config.js +736 -0
- package/lib/consolidate.js +1119 -0
- package/lib/extract.js +570 -0
- package/lib/gate.js +137 -0
- package/lib/git-origin.js +224 -0
- package/lib/index.js +4482 -0
- package/lib/log.js +260 -0
- package/lib/loops.js +186 -0
- package/lib/notices.js +195 -0
- package/lib/notify.js +33 -0
- package/lib/persona.js +163 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +490 -0
- package/lib/render.js +678 -0
- package/lib/retention.js +64 -0
- package/lib/schedule.js +245 -0
- package/lib/search.js +1068 -0
- package/lib/skills.js +220 -0
- package/lib/state.js +701 -0
- package/lib/storage.js +1424 -0
- package/lib/sync-runtime.js +268 -0
- package/lib/sync.js +620 -0
- package/lib/test/activity.test.js +74 -0
- package/lib/test/archive.test.js +182 -0
- package/lib/test/backfill.test.js +144 -0
- package/lib/test/citations.test.js +91 -0
- package/lib/test/client-wiring.test.js +134 -0
- package/lib/test/consolidate-job.test.js +95 -0
- package/lib/test/consolidate.test.js +430 -0
- package/lib/test/consolidation-selection.test.js +152 -0
- package/lib/test/dedupe-keys.test.js +230 -0
- package/lib/test/delta.test.js +93 -0
- package/lib/test/derived.test.js +110 -0
- package/lib/test/disputes-panel.test.js +341 -0
- package/lib/test/eval.test.js +171 -0
- package/lib/test/expand.test.js +164 -0
- package/lib/test/extract.test.js +1020 -0
- package/lib/test/git-origin.test.js +189 -0
- package/lib/test/injection.test.js +440 -0
- package/lib/test/kind-filter.test.js +49 -0
- package/lib/test/legacy-state.test.js +69 -0
- package/lib/test/log.test.js +156 -0
- package/lib/test/loops.test.js +86 -0
- package/lib/test/memory.test.js +855 -0
- package/lib/test/notices.test.js +142 -0
- package/lib/test/persona.test.js +86 -0
- package/lib/test/prefilter.test.js +73 -0
- package/lib/test/preset.test.js +77 -0
- package/lib/test/raw-recall.test.js +186 -0
- package/lib/test/recall.test.js +433 -0
- package/lib/test/reflection.test.js +64 -0
- package/lib/test/remote.test.js +238 -0
- package/lib/test/retention.test.js +117 -0
- package/lib/test/retrieval.test.js +142 -0
- package/lib/test/rotation.test.js +228 -0
- package/lib/test/schedule.test.js +112 -0
- package/lib/test/settings-card.test.js +58 -0
- package/lib/test/skills.test.js +129 -0
- package/lib/test/state.test.js +212 -0
- package/lib/test/subagent-contract.test.js +139 -0
- package/lib/test/sweep.test.js +159 -0
- package/lib/test/sync.test.js +314 -0
- package/lib/test/time.test.js +171 -0
- package/lib/time.js +303 -0
- package/lib/tool.js +330 -0
- package/lib/types/backfill.d.ts +96 -0
- package/lib/types/citations.d.ts +105 -0
- package/lib/types/config.d.ts +811 -0
- package/lib/types/consolidate.d.ts +742 -0
- package/lib/types/extract.d.ts +352 -0
- package/lib/types/gate.d.ts +83 -0
- package/lib/types/git-origin.d.ts +23 -0
- package/lib/types/index.d.ts +1316 -0
- package/lib/types/log.d.ts +144 -0
- package/lib/types/loops.d.ts +82 -0
- package/lib/types/notices.d.ts +117 -0
- package/lib/types/notify.d.ts +12 -0
- package/lib/types/persona.d.ts +76 -0
- package/lib/types/query.d.ts +45 -0
- package/lib/types/raw-recall.d.ts +84 -0
- package/lib/types/reflection.d.ts +122 -0
- package/lib/types/remote.d.ts +246 -0
- package/lib/types/render.d.ts +286 -0
- package/lib/types/retention.d.ts +66 -0
- package/lib/types/schedule.d.ts +116 -0
- package/lib/types/search.d.ts +583 -0
- package/lib/types/skills.d.ts +71 -0
- package/lib/types/state.d.ts +294 -0
- package/lib/types/storage.d.ts +458 -0
- package/lib/types/sync-runtime.d.ts +103 -0
- package/lib/types/sync.d.ts +222 -0
- package/lib/types/test/activity.test.d.ts +1 -0
- package/lib/types/test/archive.test.d.ts +1 -0
- package/lib/types/test/backfill.test.d.ts +1 -0
- package/lib/types/test/citations.test.d.ts +1 -0
- package/lib/types/test/client-wiring.test.d.ts +1 -0
- package/lib/types/test/consolidate-job.test.d.ts +1 -0
- package/lib/types/test/consolidate.test.d.ts +1 -0
- package/lib/types/test/consolidation-selection.test.d.ts +1 -0
- package/lib/types/test/dedupe-keys.test.d.ts +1 -0
- package/lib/types/test/delta.test.d.ts +1 -0
- package/lib/types/test/derived.test.d.ts +1 -0
- package/lib/types/test/disputes-panel.test.d.ts +1 -0
- package/lib/types/test/eval.test.d.ts +1 -0
- package/lib/types/test/expand.test.d.ts +1 -0
- package/lib/types/test/extract.test.d.ts +1 -0
- package/lib/types/test/git-origin.test.d.ts +1 -0
- package/lib/types/test/injection.test.d.ts +1 -0
- package/lib/types/test/kind-filter.test.d.ts +1 -0
- package/lib/types/test/legacy-state.test.d.ts +1 -0
- package/lib/types/test/log.test.d.ts +1 -0
- package/lib/types/test/loops.test.d.ts +1 -0
- package/lib/types/test/memory.test.d.ts +1 -0
- package/lib/types/test/notices.test.d.ts +1 -0
- package/lib/types/test/persona.test.d.ts +1 -0
- package/lib/types/test/prefilter.test.d.ts +1 -0
- package/lib/types/test/preset.test.d.ts +1 -0
- package/lib/types/test/raw-recall.test.d.ts +1 -0
- package/lib/types/test/recall.test.d.ts +1 -0
- package/lib/types/test/reflection.test.d.ts +1 -0
- package/lib/types/test/remote.test.d.ts +1 -0
- package/lib/types/test/retention.test.d.ts +1 -0
- package/lib/types/test/retrieval.test.d.ts +1 -0
- package/lib/types/test/rotation.test.d.ts +1 -0
- package/lib/types/test/schedule.test.d.ts +1 -0
- package/lib/types/test/settings-card.test.d.ts +1 -0
- package/lib/types/test/skills.test.d.ts +1 -0
- package/lib/types/test/state.test.d.ts +1 -0
- package/lib/types/test/subagent-contract.test.d.ts +1 -0
- package/lib/types/test/sweep.test.d.ts +1 -0
- package/lib/types/test/sync.test.d.ts +1 -0
- package/lib/types/test/time.test.d.ts +1 -0
- package/lib/types/time.d.ts +67 -0
- package/lib/types/tool.d.ts +9 -0
- package/lib/types/types.d.ts +374 -0
- package/lib/types/workspace.d.ts +20 -0
- package/lib/types.js +47 -0
- package/lib/workspace.js +65 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +126 -4
package/lib/log.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin's own log sink.
|
|
3
|
+
*
|
|
4
|
+
* This exists because the host logger drops most of what this plugin says.
|
|
5
|
+
* cordis decides per exporter with
|
|
6
|
+
* `(exporter.levels?.[name] ?? exporter.levels?.default ?? logger.level ?? 1) < level`,
|
|
7
|
+
* and the only exporter a DSH composition installs is an in-memory ring buffer
|
|
8
|
+
* that declares no levels. With no `logger:` config the threshold resolves to
|
|
9
|
+
* `1`, so `info` (1) is kept while `warn` (2) and `debug` (3) are dropped before
|
|
10
|
+
* any sink sees them — measured against a real cordis root, not assumed.
|
|
11
|
+
*
|
|
12
|
+
* Two consequences shape this module:
|
|
13
|
+
*
|
|
14
|
+
* 1. A sink that wants warnings must declare its own threshold. {@link createLogExporter}
|
|
15
|
+
* sets `levels.default = 3` and names this plugin's logger, which overrides
|
|
16
|
+
* the composition's default for our lines.
|
|
17
|
+
* 2. Nothing else in a stock profile reads the ring buffer, so "turn up the log
|
|
18
|
+
* level" alone changes nothing. The file sink is what makes the plugin's own
|
|
19
|
+
* decisions observable after the fact.
|
|
20
|
+
*
|
|
21
|
+
* Because an exporter is process-wide, "only our lines" needs stating twice: the
|
|
22
|
+
* name raises our own threshold, and `levels.default = 0` lowers every other
|
|
23
|
+
* logger's to `error`. Without that second half the host's fallback (`logger.level
|
|
24
|
+
* ?? 1`) lets another plugin's `warn` into this file, which is how a plugin log
|
|
25
|
+
* ends up full of `web-server` ECONNRESET lines.
|
|
26
|
+
*
|
|
27
|
+
* Every failure here is swallowed: a log that cannot be written must never fail
|
|
28
|
+
* an extraction, a consolidation, or a turn. Swallowed is not the same as
|
|
29
|
+
* invisible — {@link createFileSink} reports each failed write through
|
|
30
|
+
* `onWriteError`, which is the only way a user can learn that the file they are
|
|
31
|
+
* reading has stopped being written.
|
|
32
|
+
*
|
|
33
|
+
* @module dsh-cross-memory/log
|
|
34
|
+
*/
|
|
35
|
+
import { Logger } from '@deepseek-ai/cordis';
|
|
36
|
+
import { appendFileSync, mkdirSync, renameSync, rmSync, statSync } from 'node:fs';
|
|
37
|
+
import { dirname, join } from 'node:path';
|
|
38
|
+
/** Verbosity, least to most talkative. `off` records nothing. */
|
|
39
|
+
export const LOG_LEVELS = ['off', 'error', 'warn', 'info', 'debug'];
|
|
40
|
+
/** How large the log may grow before it is rotated once. */
|
|
41
|
+
export const LOG_MAX_BYTES = 2 * 1024 * 1024;
|
|
42
|
+
/** Narrow an unknown value to a log level, defaulting to `info`. */
|
|
43
|
+
export function toLogLevel(value, fallback = 'info') {
|
|
44
|
+
return typeof value === 'string' && LOG_LEVELS.includes(value)
|
|
45
|
+
? value
|
|
46
|
+
: fallback;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Importance of one severity, most important first.
|
|
50
|
+
*
|
|
51
|
+
* Deliberately not cordis's numbering, which ranks `info` above `warn`; a log
|
|
52
|
+
* level should mean "this and everything more serious", and everybody reads
|
|
53
|
+
* `warn` as more serious than `info`.
|
|
54
|
+
*/
|
|
55
|
+
const IMPORTANCE = { error: 0, warn: 1, info: 2, debug: 3 };
|
|
56
|
+
/**
|
|
57
|
+
* Whether one message is recorded at one verbosity.
|
|
58
|
+
* @param level - the configured verbosity.
|
|
59
|
+
* @param type - the message's severity.
|
|
60
|
+
* @returns true when the message belongs in the log.
|
|
61
|
+
*/
|
|
62
|
+
export function allows(level, type) {
|
|
63
|
+
if (level === 'off')
|
|
64
|
+
return false;
|
|
65
|
+
return IMPORTANCE[type] <= IMPORTANCE[level];
|
|
66
|
+
}
|
|
67
|
+
/** Where the plugin writes its log inside one harness home. */
|
|
68
|
+
export function logPath(dshHome) {
|
|
69
|
+
return join(dshHome, 'logs', 'dsh-cross-memory.log');
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create the file sink, with one rotated generation beside it.
|
|
73
|
+
*
|
|
74
|
+
* Rotation is deliberately crude — check the size before writing, move the file
|
|
75
|
+
* to `<path>.1` when it is too big, keeping exactly one generation — because the
|
|
76
|
+
* alternative (a log library, or an unbounded file) is worse for a plugin that
|
|
77
|
+
* writes at most a few lines per pass.
|
|
78
|
+
*
|
|
79
|
+
* A write failure is reported through `onWriteError` rather than thrown: the log
|
|
80
|
+
* must never fail a pass, but the caller still has to be able to tell a user that
|
|
81
|
+
* the file stopped growing. The callback fires once per failure, not per retry.
|
|
82
|
+
*
|
|
83
|
+
* @param path - absolute log path; an empty string disables the sink.
|
|
84
|
+
* @param maxBytes - size at which the file is rotated.
|
|
85
|
+
* @param onWriteError - called with the reason a write failed.
|
|
86
|
+
* @returns the sink, or `undefined` when the directory cannot be created.
|
|
87
|
+
*/
|
|
88
|
+
export function createFileSink(path, maxBytes = LOG_MAX_BYTES, onWriteError) {
|
|
89
|
+
if (path.trim().length === 0)
|
|
90
|
+
return undefined;
|
|
91
|
+
try {
|
|
92
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
onWriteError?.(describeError(error));
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
write(line) {
|
|
100
|
+
try {
|
|
101
|
+
const size = statSync(path, { throwIfNoEntry: false })?.size ?? 0;
|
|
102
|
+
if (size >= maxBytes) {
|
|
103
|
+
rmSync(`${path}.1`, { force: true });
|
|
104
|
+
renameSync(path, `${path}.1`);
|
|
105
|
+
}
|
|
106
|
+
appendFileSync(path, `${line}\n`, 'utf8');
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
// A log that cannot be written is not worth failing a pass over — but it
|
|
110
|
+
// is worth saying out loud, because the file is now silently stale.
|
|
111
|
+
onWriteError?.(describeError(error));
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** One-line description of a caught value. */
|
|
117
|
+
function describeError(error) {
|
|
118
|
+
return error instanceof Error ? error.message : String(error);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Format one host message as a single timestamped line.
|
|
122
|
+
*
|
|
123
|
+
* The argument rendering is the host's own (`Logger.format`), so `%s`/`%d`/`%o`
|
|
124
|
+
* and `Error` arguments read exactly as they would in any other DSH log; the
|
|
125
|
+
* prefix and the collapsed newlines are what make it greppable in a file.
|
|
126
|
+
*
|
|
127
|
+
* @param exporter - the sink the message is being written to, for its formatters.
|
|
128
|
+
* @param message - the structured record.
|
|
129
|
+
* @returns one line, without a trailing newline.
|
|
130
|
+
*/
|
|
131
|
+
export function formatLogMessage(exporter, message) {
|
|
132
|
+
const body = Logger.format(exporter, message);
|
|
133
|
+
return `${new Date(message.ts).toISOString()} [${message.type}] ${message.name} ${body.replace(/\s*\n\s*/gu, ' ')}`;
|
|
134
|
+
}
|
|
135
|
+
/** The logger name every line from this plugin carries, and the sink filters on. */
|
|
136
|
+
export const LOG_NAME = 'dsh-cross-memory';
|
|
137
|
+
/**
|
|
138
|
+
* Whether one host message belongs in this plugin's file.
|
|
139
|
+
*
|
|
140
|
+
* The name is the real filter, but the prefix is accepted as a fallback: a line
|
|
141
|
+
* that goes out through `ctx.logger` instead of the named logger carries the
|
|
142
|
+
* fiber's name (`memories`), not this one, and dropping the plugin's own message
|
|
143
|
+
* silently is exactly the failure mode this module exists to prevent. The host
|
|
144
|
+
* still applies its own threshold to such a line, so the fallback only rescues
|
|
145
|
+
* what was delivered — which is why every call site uses the named logger.
|
|
146
|
+
*
|
|
147
|
+
* @param message - the structured record.
|
|
148
|
+
* @param name - the logger name this file owns.
|
|
149
|
+
* @returns true when the message is ours.
|
|
150
|
+
*/
|
|
151
|
+
export function ownsMessage(message, name = LOG_NAME) {
|
|
152
|
+
if (message.name === name)
|
|
153
|
+
return true;
|
|
154
|
+
const first = message.args[0];
|
|
155
|
+
return typeof first === 'string' && first.startsWith('dsh-cross-memory:');
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build the exporter that writes to a sink.
|
|
159
|
+
*
|
|
160
|
+
* `levels` is the whole reason this object exists. cordis filters each message
|
|
161
|
+
* per exporter against `exporter.levels?.[name] ?? exporter.levels?.default ??
|
|
162
|
+
* logger.level ?? 1`, and the composition's only default exporter declares no
|
|
163
|
+
* levels, so the threshold falls back to `1` and every `warn` and `debug` line is
|
|
164
|
+
* discarded before a sink sees it. The map therefore carries both directions:
|
|
165
|
+
*
|
|
166
|
+
* - `[name]: 3` raises THIS logger's threshold, so the plugin's own `warn` and
|
|
167
|
+
* `debug` reach the file.
|
|
168
|
+
* - `default: 0` lowers every OTHER logger's threshold to `error`, so a foreign
|
|
169
|
+
* plugin's `warn` cannot land in this plugin's file. Without it the fallback
|
|
170
|
+
* threshold of `1` lets `web-server` connection noise in — measured on a real
|
|
171
|
+
* profile, not assumed.
|
|
172
|
+
*
|
|
173
|
+
* `export` still checks the name, because messages that pass the threshold arrive
|
|
174
|
+
* from every exporter and the file should be this plugin's record alone.
|
|
175
|
+
*
|
|
176
|
+
* The verbosity thunk returns a plain string because that is what the settings
|
|
177
|
+
* schema declares; an unrecognized value normalizes to `info` here exactly as it
|
|
178
|
+
* does in the runtime, so the two can never disagree about what "warn" means.
|
|
179
|
+
*
|
|
180
|
+
* @param sink - where formatted lines go.
|
|
181
|
+
* @param level - the verbosity in force right now.
|
|
182
|
+
* @param name - the logger name this file owns.
|
|
183
|
+
* @returns the exporter to hand `ctx.logger.exporter`.
|
|
184
|
+
*/
|
|
185
|
+
export function createLogExporter(sink, level, name = LOG_NAME) {
|
|
186
|
+
const exporter = {
|
|
187
|
+
colors: false,
|
|
188
|
+
levels: { [name]: 3, default: 0 },
|
|
189
|
+
export: (message) => {
|
|
190
|
+
if (!ownsMessage(message, name))
|
|
191
|
+
return;
|
|
192
|
+
if (!allows(toLogLevel(level()), message.type))
|
|
193
|
+
return;
|
|
194
|
+
sink.write(formatLogMessage(exporter, message));
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
return exporter;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Resolve the plugin's named logger.
|
|
201
|
+
*
|
|
202
|
+
* A name is what keeps this plugin's file to this plugin's lines. Deployments and
|
|
203
|
+
* test doubles that expose only the service's methods (no call signature) fall
|
|
204
|
+
* back to the service itself, which still logs — just under the fiber's name.
|
|
205
|
+
*
|
|
206
|
+
* @param logger - `ctx.logger` as the plugin sees it.
|
|
207
|
+
* @returns the object whose methods the runtime logs through.
|
|
208
|
+
*/
|
|
209
|
+
export function pluginLogger(logger) {
|
|
210
|
+
const service = logger;
|
|
211
|
+
if (typeof service === 'function') {
|
|
212
|
+
const named = service(LOG_NAME);
|
|
213
|
+
if (named !== undefined && typeof named.info === 'function')
|
|
214
|
+
return named;
|
|
215
|
+
}
|
|
216
|
+
return service;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A thin facade over `ctx.logger`.
|
|
220
|
+
*
|
|
221
|
+
* It adds exactly one thing the raw logger cannot express: a *decision* line,
|
|
222
|
+
* which is `info` while `traceMaintenance` is on and `debug` otherwise. The
|
|
223
|
+
* message always goes to the host logger, so every other sink still sees it —
|
|
224
|
+
* only this plugin's file applies `logLevel`.
|
|
225
|
+
*/
|
|
226
|
+
export class MemoryLog {
|
|
227
|
+
logger;
|
|
228
|
+
trace;
|
|
229
|
+
constructor(logger, trace) {
|
|
230
|
+
this.logger = logger;
|
|
231
|
+
this.trace = trace;
|
|
232
|
+
}
|
|
233
|
+
error(...args) {
|
|
234
|
+
this.logger.error(...args);
|
|
235
|
+
}
|
|
236
|
+
warn(...args) {
|
|
237
|
+
this.logger.warn(...args);
|
|
238
|
+
}
|
|
239
|
+
info(...args) {
|
|
240
|
+
this.logger.info(...args);
|
|
241
|
+
}
|
|
242
|
+
debug(...args) {
|
|
243
|
+
this.logger.debug(...args);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Record a maintenance decision.
|
|
247
|
+
*
|
|
248
|
+
* Quiet by default: retention, recall and selection emit several lines per
|
|
249
|
+
* pass, and a readable `logLevel: info` is worth more than a complete one.
|
|
250
|
+
* `traceMaintenance` raises them to `info`, which a stock `logLevel` keeps.
|
|
251
|
+
*
|
|
252
|
+
* @param args - the format string and its arguments.
|
|
253
|
+
*/
|
|
254
|
+
decision(...args) {
|
|
255
|
+
if (this.trace())
|
|
256
|
+
this.logger.info(...args);
|
|
257
|
+
else
|
|
258
|
+
this.logger.debug(...args);
|
|
259
|
+
}
|
|
260
|
+
}
|
package/lib/loops.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open loops: the things the user said they would do and has not done yet.
|
|
3
|
+
*
|
|
4
|
+
* This is the only input a proactive assistant can act on that is not a clock or
|
|
5
|
+
* a queue: "Friday" is a real deadline because somebody said it, not because a
|
|
6
|
+
* timestamp says so. Meta's MemoProAgent calls the same object an *open loop* and
|
|
7
|
+
* makes the point this module is built around — a reminder is only justified when
|
|
8
|
+
* there is a loop to close, otherwise a relevant memory is just noise.
|
|
9
|
+
*
|
|
10
|
+
* The lifecycle is deliberately narrow: a loop is opened by an extraction, closed
|
|
11
|
+
* by the user, or dies. Nothing here decides *whether* to speak; that is the
|
|
12
|
+
* notice gate's job. This module only keeps an honest ledger.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-cross-memory/loops
|
|
15
|
+
*/
|
|
16
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
17
|
+
import { dirname, join } from 'node:path';
|
|
18
|
+
/** File name inside the memory store. */
|
|
19
|
+
export const LOOPS_FILE = 'loops.json';
|
|
20
|
+
/** How long an untouched loop may stay open before it expires. */
|
|
21
|
+
export const LOOP_TTL_MS = 21 * 86_400_000;
|
|
22
|
+
/** How many open loops are kept; the oldest are dropped past this. */
|
|
23
|
+
export const LOOP_CAP = 50;
|
|
24
|
+
/** Reminders per loop, and the spacing between them. */
|
|
25
|
+
export const LOOP_MAX_REMINDERS = 3;
|
|
26
|
+
export const LOOP_REMIND_INTERVAL_MS = 24 * 3_600_000;
|
|
27
|
+
/** Read the ledger, tolerating a missing or corrupt file. */
|
|
28
|
+
export async function readLoops(memoriesDir) {
|
|
29
|
+
const text = await readFile(join(memoriesDir, LOOPS_FILE), 'utf8').catch(() => undefined);
|
|
30
|
+
if (text === undefined)
|
|
31
|
+
return { version: 1, loops: [] };
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(text);
|
|
34
|
+
return { version: 1, loops: Array.isArray(parsed.loops) ? parsed.loops.filter(isLoop) : [] };
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return { version: 1, loops: [] };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Write the ledger atomically. */
|
|
41
|
+
export async function writeLoops(memoriesDir, store) {
|
|
42
|
+
const target = join(memoriesDir, LOOPS_FILE);
|
|
43
|
+
await mkdir(dirname(target), { recursive: true });
|
|
44
|
+
const temp = `${target}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
45
|
+
await writeFile(temp, `${JSON.stringify({ ...store, version: 1 }, null, 2)}\n`, 'utf8');
|
|
46
|
+
await rename(temp, target);
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
/** Whether one parsed row is usable. */
|
|
50
|
+
function isLoop(value) {
|
|
51
|
+
if (typeof value !== 'object' || value === null)
|
|
52
|
+
return false;
|
|
53
|
+
const row = value;
|
|
54
|
+
return typeof row['id'] === 'string'
|
|
55
|
+
&& typeof row['text'] === 'string'
|
|
56
|
+
&& typeof row['state'] === 'string'
|
|
57
|
+
&& typeof row['openedAt'] === 'number';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Fold newly extracted promises into the ledger.
|
|
61
|
+
*
|
|
62
|
+
* Duplicates are the normal case, not the exception: a promise repeated across
|
|
63
|
+
* three sessions must be ONE loop, or the user gets reminded three times about
|
|
64
|
+
* the same thing. Matching is on normalized text and containment, which is crude
|
|
65
|
+
* but predictable — the failure mode of a cleverer match is silently merging two
|
|
66
|
+
* different promises.
|
|
67
|
+
*
|
|
68
|
+
* @param store - the current ledger.
|
|
69
|
+
* @param candidates - what an extraction just found.
|
|
70
|
+
* @param now - clock.
|
|
71
|
+
* @param sessionId - where they came from.
|
|
72
|
+
* @returns the new ledger.
|
|
73
|
+
*/
|
|
74
|
+
export function mergeLoops(store, candidates, now, sessionId) {
|
|
75
|
+
const loops = [...store.loops];
|
|
76
|
+
for (const candidate of candidates) {
|
|
77
|
+
const text = candidate.text.replace(/\s+/gu, ' ').trim().slice(0, 200);
|
|
78
|
+
if (text.length === 0)
|
|
79
|
+
continue;
|
|
80
|
+
const key = normalize(text);
|
|
81
|
+
if (key.length < 4)
|
|
82
|
+
continue;
|
|
83
|
+
const existing = loops.find((loop) => loop.state === 'open' && overlaps(normalize(loop.text), key));
|
|
84
|
+
if (existing !== undefined) {
|
|
85
|
+
// A later deadline wins: the user moved the promise, they did not make two.
|
|
86
|
+
if (candidate.dueAt !== undefined && (existing.dueAt === undefined || candidate.dueAt > existing.dueAt)) {
|
|
87
|
+
const index = loops.indexOf(existing);
|
|
88
|
+
loops[index] = { ...existing, dueAt: candidate.dueAt };
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
loops.push({
|
|
93
|
+
id: `loop-${hash(key)}`,
|
|
94
|
+
text,
|
|
95
|
+
openedAt: now,
|
|
96
|
+
...candidate.dueAt === undefined ? {} : { dueAt: candidate.dueAt },
|
|
97
|
+
state: 'open',
|
|
98
|
+
...sessionId === undefined ? {} : { sourceSession: sessionId },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Cap: an open-loop list that grows without bound becomes a second backlog.
|
|
102
|
+
const open = loops.filter((loop) => loop.state === 'open');
|
|
103
|
+
if (open.length > LOOP_CAP) {
|
|
104
|
+
const stale = open.sort((left, right) => left.openedAt - right.openedAt).slice(0, open.length - LOOP_CAP);
|
|
105
|
+
for (const loop of stale) {
|
|
106
|
+
const index = loops.indexOf(loop);
|
|
107
|
+
loops[index] = { ...loop, state: 'dropped' };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { version: 1, loops };
|
|
111
|
+
}
|
|
112
|
+
/** Expire loops nobody closed and nobody mentioned in weeks. */
|
|
113
|
+
export function pruneLoops(store, now) {
|
|
114
|
+
return {
|
|
115
|
+
version: 1,
|
|
116
|
+
loops: store.loops.map((loop) => (loop.state === 'open' && now - loop.openedAt > LOOP_TTL_MS ? { ...loop, state: 'expired' } : loop)),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Loops that may be raised right now.
|
|
121
|
+
*
|
|
122
|
+
* Only loops with a stated deadline qualify. A loop without one is a note, not a
|
|
123
|
+
* promise, and nagging somebody about a note they never dated is how a helpful
|
|
124
|
+
* assistant turns into a supervisor.
|
|
125
|
+
*
|
|
126
|
+
* @param store - the ledger.
|
|
127
|
+
* @param now - clock.
|
|
128
|
+
* @returns loops to raise, oldest deadline first.
|
|
129
|
+
*/
|
|
130
|
+
export function dueLoops(store, now) {
|
|
131
|
+
return store.loops
|
|
132
|
+
.filter((loop) => loop.state === 'open'
|
|
133
|
+
&& loop.dueAt !== undefined
|
|
134
|
+
&& loop.dueAt <= now
|
|
135
|
+
&& (loop.remindCount ?? 0) < LOOP_MAX_REMINDERS
|
|
136
|
+
&& (loop.remindedAt === undefined || now - loop.remindedAt >= LOOP_REMIND_INTERVAL_MS))
|
|
137
|
+
.sort((left, right) => (left.dueAt ?? 0) - (right.dueAt ?? 0));
|
|
138
|
+
}
|
|
139
|
+
/** Record that one loop was raised, or close it. */
|
|
140
|
+
export function withLoop(store, id, update) {
|
|
141
|
+
return { version: 1, loops: store.loops.map((loop) => (loop.id === id ? { ...loop, ...update } : loop)) };
|
|
142
|
+
}
|
|
143
|
+
/** Close one loop by the id the user typed, accepting a unique prefix. */
|
|
144
|
+
export function closeLoop(store, idOrPrefix) {
|
|
145
|
+
const needle = idOrPrefix.trim();
|
|
146
|
+
if (needle.length === 0)
|
|
147
|
+
return { store, reason: 'an id is required' };
|
|
148
|
+
const matches = store.loops.filter((loop) => loop.id.startsWith(needle) && loop.state === 'open');
|
|
149
|
+
if (matches.length === 0)
|
|
150
|
+
return { store, reason: 'no open loop matches ' + needle };
|
|
151
|
+
if (matches.length > 1)
|
|
152
|
+
return { store, reason: `${matches.length} open loops match ${needle}; be more specific` };
|
|
153
|
+
const closed = matches[0];
|
|
154
|
+
return { store: withLoop(store, closed.id, { state: 'done' }), closed };
|
|
155
|
+
}
|
|
156
|
+
/** The text a command shows: open loops, soonest deadline first. */
|
|
157
|
+
export function describeLoops(store, now) {
|
|
158
|
+
const open = store.loops.filter((loop) => loop.state === 'open');
|
|
159
|
+
if (open.length === 0)
|
|
160
|
+
return 'No open loops.';
|
|
161
|
+
return open
|
|
162
|
+
.sort((left, right) => (left.dueAt ?? Number.MAX_SAFE_INTEGER) - (right.dueAt ?? Number.MAX_SAFE_INTEGER))
|
|
163
|
+
.map((loop) => {
|
|
164
|
+
const due = loop.dueAt === undefined ? 'no date' : loop.dueAt < now ? 'overdue' : new Date(loop.dueAt).toISOString().slice(0, 10);
|
|
165
|
+
return `${loop.id} ${due.padEnd(10)} ${loop.text.slice(0, 70)}`;
|
|
166
|
+
})
|
|
167
|
+
.join('\n');
|
|
168
|
+
}
|
|
169
|
+
/** Strip punctuation and case so two spellings of one promise compare equal. */
|
|
170
|
+
function normalize(text) {
|
|
171
|
+
return text.toLowerCase().replace(/[\s\p{P}\p{S}]+/gu, '');
|
|
172
|
+
}
|
|
173
|
+
/** Whether one normalized promise contains the other. */
|
|
174
|
+
function overlaps(left, right) {
|
|
175
|
+
if (left === right)
|
|
176
|
+
return true;
|
|
177
|
+
const [shorter, longer] = left.length <= right.length ? [left, right] : [right, left];
|
|
178
|
+
return shorter.length >= 8 && longer.includes(shorter);
|
|
179
|
+
}
|
|
180
|
+
/** Stable short hash for ids. */
|
|
181
|
+
function hash(text) {
|
|
182
|
+
let value = 0;
|
|
183
|
+
for (let index = 0; index < text.length; index += 1)
|
|
184
|
+
value = (value * 31 + text.charCodeAt(index)) >>> 0;
|
|
185
|
+
return value.toString(36).slice(0, 8);
|
|
186
|
+
}
|
package/lib/notices.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notices: the only thing in this plugin that speaks without being asked.
|
|
3
|
+
*
|
|
4
|
+
* Everything else waits for a turn. A notice is deliberately NOT a message in a
|
|
5
|
+
* conversation — it is a durable record that something deserves the user's
|
|
6
|
+
* attention NOW, addressed to whichever frontend can present it (the desktop pet
|
|
7
|
+
* first, the operating system as a fallback).
|
|
8
|
+
*
|
|
9
|
+
* Design rules, all of them learned from how proactive assistants fail:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Evidence or silence.** A notice carries the ids it is about. If it cannot
|
|
12
|
+
* say what it is based on, it must not exist.
|
|
13
|
+
* 2. **A notice is an object, not a sentence.** It is queued, delivered, and then
|
|
14
|
+
* acknowledged or dismissed; the same object is never re-sent inside the
|
|
15
|
+
* spacing window, and a dismissal is a vote against that kind for a while.
|
|
16
|
+
* 3. **Silence is recorded too**, but only by the caller's log line: this module
|
|
17
|
+
* returns why it declined to enqueue.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-cross-memory/notices
|
|
20
|
+
*/
|
|
21
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
22
|
+
import { dirname, join } from 'node:path';
|
|
23
|
+
/** File name inside the memory store. */
|
|
24
|
+
export const NOTICES_FILE = 'notices.json';
|
|
25
|
+
/** How long an unacknowledged notice may sit before it is expired. */
|
|
26
|
+
export const NOTICE_TTL_MS = 7 * 86_400_000;
|
|
27
|
+
/** Read the queue, tolerating a missing or corrupt file. */
|
|
28
|
+
export async function readNotices(memoriesDir) {
|
|
29
|
+
const text = await readFile(join(memoriesDir, NOTICES_FILE), 'utf8').catch(() => undefined);
|
|
30
|
+
if (text === undefined)
|
|
31
|
+
return { version: 1, notices: [] };
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(text);
|
|
34
|
+
const notices = Array.isArray(parsed.notices) ? parsed.notices.filter(isNotice) : [];
|
|
35
|
+
return {
|
|
36
|
+
version: 1,
|
|
37
|
+
...typeof parsed.lastDigestAt === 'number' ? { lastDigestAt: parsed.lastDigestAt } : {},
|
|
38
|
+
notices,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return { version: 1, notices: [] };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Write the queue atomically. */
|
|
46
|
+
export async function writeNotices(memoriesDir, queue) {
|
|
47
|
+
const target = join(memoriesDir, NOTICES_FILE);
|
|
48
|
+
await mkdir(dirname(target), { recursive: true });
|
|
49
|
+
const temp = `${target}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
50
|
+
await writeFile(temp, `${JSON.stringify({ ...queue, version: 1 }, null, 2)}\n`, 'utf8');
|
|
51
|
+
await rename(temp, target);
|
|
52
|
+
return target;
|
|
53
|
+
}
|
|
54
|
+
/** Whether one parsed row is a usable notice. */
|
|
55
|
+
function isNotice(value) {
|
|
56
|
+
if (typeof value !== 'object' || value === null)
|
|
57
|
+
return false;
|
|
58
|
+
const row = value;
|
|
59
|
+
return typeof row['id'] === 'string'
|
|
60
|
+
&& typeof row['kind'] === 'string'
|
|
61
|
+
&& typeof row['title'] === 'string'
|
|
62
|
+
&& typeof row['body'] === 'string'
|
|
63
|
+
&& Array.isArray(row['evidence'])
|
|
64
|
+
&& typeof row['dedupeKey'] === 'string'
|
|
65
|
+
&& typeof row['state'] === 'string';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Decide whether one candidate notice may enter the queue.
|
|
69
|
+
*
|
|
70
|
+
* Runs no model and looks at no clock beyond the injected one: every rule here is
|
|
71
|
+
* explainable, which is the only way "why did it stay quiet?" can be answered
|
|
72
|
+
* later.
|
|
73
|
+
*
|
|
74
|
+
* @param queue - the current queue.
|
|
75
|
+
* @param candidate - what the trigger wants to say.
|
|
76
|
+
* @param policy - caps, spacing and quiet hours.
|
|
77
|
+
* @returns whether it was enqueued, and why not when it was not.
|
|
78
|
+
*/
|
|
79
|
+
export function admitNotice(queue, candidate, policy) {
|
|
80
|
+
if (candidate.evidence.length === 0)
|
|
81
|
+
return { ok: false, reason: 'no evidence: a notice must cite what it is about' };
|
|
82
|
+
// Same subject: never twice inside the spacing window. A dismissal doubles it.
|
|
83
|
+
const spacing = policy.minSpacingHours * 3_600_000;
|
|
84
|
+
const previous = [...queue.notices]
|
|
85
|
+
.filter((notice) => notice.dedupeKey === candidate.dedupeKey)
|
|
86
|
+
.sort((left, right) => right.createdAt - left.createdAt)[0];
|
|
87
|
+
if (previous !== undefined) {
|
|
88
|
+
const window = previous.outcome === 'dismissed' ? spacing * 2 : spacing;
|
|
89
|
+
if (policy.now - previous.createdAt < window) {
|
|
90
|
+
return { ok: false, reason: `same subject already handled ${Math.round((policy.now - previous.createdAt) / 3_600_000)}h ago` };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// The user asked for "when it matters", not for a quota: the cap is a guard rail
|
|
94
|
+
// against a runaway trigger, not an allowance to spend.
|
|
95
|
+
const since = policy.now - 86_400_000;
|
|
96
|
+
const today = queue.notices.filter((notice) => notice.createdAt >= since && notice.state !== 'expired').length;
|
|
97
|
+
if (today >= policy.dailyCap)
|
|
98
|
+
return { ok: false, reason: `daily guard rail reached (${today})` };
|
|
99
|
+
// Quiet hours defer rather than drop: the notice is due when the window opens.
|
|
100
|
+
const dueAt = quietHoursEnd(candidate.dueAt, policy.quietHours);
|
|
101
|
+
const notice = {
|
|
102
|
+
...candidate,
|
|
103
|
+
id: `${candidate.kind}-${hash(candidate.dedupeKey)}-${candidate.createdAt.toString(36)}`,
|
|
104
|
+
state: 'open',
|
|
105
|
+
};
|
|
106
|
+
return { ok: true, notice, dueAt };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Move `dueAt` to the end of the quiet window, when it falls inside one.
|
|
110
|
+
*
|
|
111
|
+
* Windows are written like `peakHours` (`22:00-08:00`, `Mon-Fri 09:00-12:00`) and
|
|
112
|
+
* parsed by the same routine, so there is one syntax for "time of day" in this
|
|
113
|
+
* plugin rather than two.
|
|
114
|
+
*
|
|
115
|
+
* @param dueAt - the moment the trigger wanted to fire.
|
|
116
|
+
* @param quietHours - the window spec; empty disables.
|
|
117
|
+
* @returns the moment it may actually fire.
|
|
118
|
+
*/
|
|
119
|
+
export function quietHoursEnd(dueAt, quietHours) {
|
|
120
|
+
const trimmed = quietHours.trim();
|
|
121
|
+
if (trimmed.length === 0)
|
|
122
|
+
return dueAt;
|
|
123
|
+
// Local-time minutes since midnight for each "HH:MM-HH:MM" window, any weekday.
|
|
124
|
+
for (const part of trimmed.split(',')) {
|
|
125
|
+
const match = /(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})/u.exec(part);
|
|
126
|
+
if (match === null)
|
|
127
|
+
continue;
|
|
128
|
+
const start = Number(match[1]) * 60 + Number(match[2]);
|
|
129
|
+
const end = Number(match[3]) * 60 + Number(match[4]);
|
|
130
|
+
const at = new Date(dueAt);
|
|
131
|
+
const minutes = at.getHours() * 60 + at.getMinutes();
|
|
132
|
+
const inside = start <= end ? minutes >= start && minutes < end : minutes >= start || minutes < end;
|
|
133
|
+
if (!inside)
|
|
134
|
+
continue;
|
|
135
|
+
const offset = ((end - minutes) + 1440) % 1440;
|
|
136
|
+
return dueAt + offset * 60_000;
|
|
137
|
+
}
|
|
138
|
+
return dueAt;
|
|
139
|
+
}
|
|
140
|
+
/** Notices that may be delivered now, oldest first. */
|
|
141
|
+
export function dueNotices(queue, now) {
|
|
142
|
+
return queue.notices
|
|
143
|
+
.filter((notice) => notice.state === 'open' && notice.dueAt <= now)
|
|
144
|
+
.sort((left, right) => right.dueAt - left.dueAt);
|
|
145
|
+
}
|
|
146
|
+
/** Replace one notice, returning a new queue. */
|
|
147
|
+
export function withNotice(queue, updated) {
|
|
148
|
+
return { ...queue, notices: queue.notices.map((notice) => (notice.id === updated.id ? updated : notice)) };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Record that a person answered one notice.
|
|
152
|
+
*
|
|
153
|
+
* This is the only feedback the plugin gets, and it is the difference between a
|
|
154
|
+
* proactive assistant that learns and one that just talks: a dismissal stretches
|
|
155
|
+
* the same subject's silence (see {@link admitNotice}), and the probe reports the
|
|
156
|
+
* acted/dismissed ratio so a week of reminders can be judged instead of guessed.
|
|
157
|
+
*
|
|
158
|
+
* @param queue - the current queue.
|
|
159
|
+
* @param idOrPrefix - full id or an unambiguous prefix, as typed by a person.
|
|
160
|
+
* @param outcome - what they did about it.
|
|
161
|
+
* @param now - clock.
|
|
162
|
+
* @returns the new queue and the answered notice, or why nothing matched.
|
|
163
|
+
*/
|
|
164
|
+
export function ackNotice(queue, idOrPrefix, outcome, now) {
|
|
165
|
+
const needle = idOrPrefix.trim();
|
|
166
|
+
if (needle.length === 0)
|
|
167
|
+
return { queue, reason: 'an id is required' };
|
|
168
|
+
const matches = queue.notices.filter((notice) => notice.id.startsWith(needle)
|
|
169
|
+
&& (notice.state === 'delivered' || notice.state === 'open'));
|
|
170
|
+
if (matches.length === 0)
|
|
171
|
+
return { queue, reason: `no unacknowledged notice matches ${needle}` };
|
|
172
|
+
if (matches.length > 1)
|
|
173
|
+
return { queue, reason: `${matches.length} notices match ${needle}; be more specific` };
|
|
174
|
+
const notice = matches[0];
|
|
175
|
+
return {
|
|
176
|
+
queue: withNotice(queue, { ...notice, state: 'acked', outcome, ackedAt: now }),
|
|
177
|
+
notice,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/** Expire notices nobody ever took, so the queue cannot grow forever. */
|
|
181
|
+
export function pruneNotices(queue, now) {
|
|
182
|
+
return {
|
|
183
|
+
...queue,
|
|
184
|
+
notices: queue.notices.map((notice) => (notice.state === 'open' && now - notice.createdAt > NOTICE_TTL_MS
|
|
185
|
+
? { ...notice, state: 'expired' }
|
|
186
|
+
: notice)),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Stable short hash for ids. */
|
|
190
|
+
function hash(text) {
|
|
191
|
+
let value = 0;
|
|
192
|
+
for (let index = 0; index < text.length; index += 1)
|
|
193
|
+
value = (value * 31 + text.charCodeAt(index)) >>> 0;
|
|
194
|
+
return value.toString(36).slice(0, 8);
|
|
195
|
+
}
|
package/lib/notify.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery channel: one operating-system notification.
|
|
3
|
+
*
|
|
4
|
+
* This plugin used to hand its notices to a desktop pet plugin over the host's
|
|
5
|
+
* loopback HTTP. That dependency was removed on 2026-10-28 together with the pet:
|
|
6
|
+
* a notice is only worth having if it arrives without a second plugin being
|
|
7
|
+
* installed, configured, authenticated, and displayed. One channel that always
|
|
8
|
+
* exists beats two where one silently fails.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-cross-memory/notify
|
|
11
|
+
*/
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
13
|
+
/**
|
|
14
|
+
* Post a macOS notification.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately the quiet kind: no sound, no focus steal. The point is that a
|
|
17
|
+
* notice is not lost, not that it interrupts. Never throws — a notification
|
|
18
|
+
* channel that can break a background pass is worse than a missed notice.
|
|
19
|
+
*
|
|
20
|
+
* @param title - notification title.
|
|
21
|
+
* @param message - notification body.
|
|
22
|
+
* @returns whether `osascript` accepted it.
|
|
23
|
+
*/
|
|
24
|
+
export function systemNotification(title, message) {
|
|
25
|
+
const script = `display notification "${message.replace(/["\\]/gu, '')}" with title "${title.replace(/["\\]/gu, '')}"`;
|
|
26
|
+
try {
|
|
27
|
+
const result = spawnSync('osascript', ['-e', script], { timeout: 3_000 });
|
|
28
|
+
return result.status === 0;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|