clavarium-docket 0.1.2-next.2 → 0.1.2-next.3
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/package.json +1 -1
- package/server/docket.mjs +32 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium-docket",
|
|
3
|
-
"version": "0.1.2-next.
|
|
3
|
+
"version": "0.1.2-next.3",
|
|
4
4
|
"description": "Clavarium Docket: events an AI agent or a script sees and acknowledges, and reminders it sets itself (a command and an MCP server, and a library for the application). No dependency.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/clavarium/clavarium-docket#readme",
|
package/server/docket.mjs
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
* plans.jsonl the worker's: the reminders it set, and took back
|
|
19
19
|
* plans-off.jsonl the application's: the reminders the person took back
|
|
20
20
|
*/
|
|
21
|
-
import { appendFileSync, readFileSync, mkdirSync, statSync, lstatSync, realpathSync } from 'node:fs';
|
|
21
|
+
import { appendFileSync, readFileSync, mkdirSync, statSync, lstatSync, realpathSync, openSync, readSync, closeSync, constants } from 'node:fs';
|
|
22
22
|
import { dirname, join, resolve } from 'node:path';
|
|
23
23
|
import { fileURLToPath } from 'node:url';
|
|
24
24
|
import { randomUUID, createHash } from 'node:crypto';
|
|
25
25
|
import { createInterface } from 'node:readline';
|
|
26
26
|
import { zoneOf, isZone, parseWhen, parseIn, parseCron, nextCron, lastCron, wall } from './time.mjs';
|
|
27
27
|
|
|
28
|
-
export const VERSION = '0.1.2-next.
|
|
28
|
+
export const VERSION = '0.1.2-next.3';
|
|
29
29
|
export const FOLDER = '.docket';
|
|
30
30
|
export const TEXT_MAX = 500;
|
|
31
31
|
export const NOTE_MAX = 1000;
|
|
@@ -41,8 +41,37 @@ const NOT_SHOWN = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F---
|
|
|
41
41
|
export const oneLine = (text, max) => String(text ?? '').replace(/\r/g, '').replace(NOT_SHOWN, '').replace(/\s+/g, ' ').trim().slice(0, max);
|
|
42
42
|
const parsed = (line) => { try { const j = JSON.parse(line); return j && typeof j === 'object' && !Array.isArray(j) ? j : null; } catch { return null; } };
|
|
43
43
|
/* The lines of one file of the folder: never through a link; one that does not parse is skipped. */
|
|
44
|
+
/* READ ONCE, THEN ONLY WHAT WAS ADDED (18-11: the server read every awake conversation's events and acks whole
|
|
45
|
+
every 5 s; they only grow): per file, where it was read up to; grown, only its new bytes; replaced or shrunk,
|
|
46
|
+
read again whole. The list given is the one kept: read it, never change it. */
|
|
47
|
+
export const LINES_KEPT = 512;
|
|
48
|
+
const kept = new Map();
|
|
44
49
|
export function lines(file) {
|
|
45
|
-
|
|
50
|
+
let info;
|
|
51
|
+
try { info = lstatSync(file); } catch { kept.delete(file); return []; }
|
|
52
|
+
if (info.isSymbolicLink() || !info.isFile()) { kept.delete(file); return []; }
|
|
53
|
+
let k = kept.get(file);
|
|
54
|
+
if (k && (k.ino !== info.ino || k.dev !== info.dev || info.size < k.offset)) k = undefined;
|
|
55
|
+
if (k && info.size === k.size && info.mtimeMs === k.mtimeMs) return k.rows;
|
|
56
|
+
if (!k) k = { ino: info.ino, dev: info.dev, offset: 0, rows: [], size: 0, mtimeMs: 0 };
|
|
57
|
+
try {
|
|
58
|
+
const fd = openSync(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
59
|
+
try {
|
|
60
|
+
const want = info.size - k.offset;
|
|
61
|
+
const buf = Buffer.alloc(Math.max(0, want));
|
|
62
|
+
let got = 0;
|
|
63
|
+
while (got < want) { const n = readSync(fd, buf, got, want - got, k.offset + got); if (n <= 0) break; got += n; }
|
|
64
|
+
const end = buf.subarray(0, got).lastIndexOf(0x0a);
|
|
65
|
+
if (end >= 0) {
|
|
66
|
+
for (const line of buf.subarray(0, end).toString('utf8').split('\n')) { if (!line) continue; const j = parsed(line); if (j) k.rows.push(j); }
|
|
67
|
+
k.offset += end + 1;
|
|
68
|
+
}
|
|
69
|
+
k.size = k.offset + (end >= 0 ? got - end - 1 : got); k.mtimeMs = info.mtimeMs;
|
|
70
|
+
} finally { closeSync(fd); }
|
|
71
|
+
} catch { kept.delete(file); return []; }
|
|
72
|
+
kept.delete(file); kept.set(file, k);
|
|
73
|
+
if (kept.size > LINES_KEPT) kept.delete(kept.keys().next().value);
|
|
74
|
+
return k.rows;
|
|
46
75
|
}
|
|
47
76
|
const isFolder = (path) => { try { return statSync(path).isDirectory(); } catch { return false; } };
|
|
48
77
|
|