@mnemonik/shared 7.177.0 → 7.178.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/dist/ambientPointer.d.ts +60 -9
- package/dist/ambientPointer.d.ts.map +1 -1
- package/dist/ambientPointer.js +131 -11
- package/dist/ambientPointer.js.map +1 -1
- package/dist/contextBudget.d.ts +9 -0
- package/dist/contextBudget.d.ts.map +1 -1
- package/dist/contextBudget.js +17 -2
- package/dist/contextBudget.js.map +1 -1
- package/dist/hookTimeouts.d.ts +20 -1
- package/dist/hookTimeouts.d.ts.map +1 -1
- package/dist/hookTimeouts.js +35 -1
- package/dist/hookTimeouts.js.map +1 -1
- package/package.json +1 -1
- package/src/ambientPointer.ts +162 -12
- package/src/contextBudget.ts +28 -2
- package/src/hookTimeouts.ts +35 -1
package/dist/ambientPointer.d.ts
CHANGED
|
@@ -1,16 +1,57 @@
|
|
|
1
1
|
export declare const AMBIENT_ID_PREFIX_LENGTH = 8;
|
|
2
2
|
/**
|
|
3
3
|
* What a recalled memory's line carries when memories learned later relate to
|
|
4
|
-
* it (RETRIEVAL_LAYER §2.0.3): how many, and the closest one
|
|
5
|
-
* the line
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* it (RETRIEVAL_LAYER §2.0.3): how many, and a glimpse of the closest one,
|
|
5
|
+
* the same kind every recall line gives of its own memory: how long after the
|
|
6
|
+
* recalled memory it was learned, its opening, and its id. It follows the
|
|
7
|
+
* line's own `memory_get <id>` pointer.
|
|
8
|
+
*
|
|
9
|
+
* The glimpse is what lets an agent decide whether the later memory is worth
|
|
10
|
+
* recalling whole; a bare id gave it nothing to decide by (11 Nov 2026: 6 of
|
|
11
|
+
* 1,771 were opened). `{which}` is "closest", or "next closest" when the
|
|
12
|
+
* closest is already in the same reply. `{gap}` and `{glimpse}` are left out
|
|
13
|
+
* when they are not known, which leaves the marker as it was before the
|
|
14
|
+
* glimpse existed.
|
|
15
|
+
*
|
|
16
|
+
* The one place the wording lives: the renderer and the pattern that finds
|
|
17
|
+
* (and sheds) the marker are both built from these. A hook runtime built
|
|
18
|
+
* before a form existed cannot parse it, so the server writes the glimpse
|
|
19
|
+
* only to a runtime that says it reads it (hookTimeouts.ts HOOK_READS_HEADER).
|
|
20
|
+
* Agent-facing wording; it changes only with the owner's approval.
|
|
21
|
+
*/
|
|
22
|
+
export declare const RECALL_LATER_MARKER = " \u00B7 you learned {count} related {memories} later; {which}{gap}: {glimpse}memory_get {laterId}";
|
|
23
|
+
/** `{which}`: the later memory named is the closest one. */
|
|
24
|
+
export declare const RECALL_LATER_CLOSEST = "closest";
|
|
25
|
+
/** `{which}`: the closest one is in the same reply, so the next closest is named. */
|
|
26
|
+
export declare const RECALL_LATER_NEXT_CLOSEST = "next closest";
|
|
27
|
+
/** `{gap}`: how long after the recalled memory the later one was learned. */
|
|
28
|
+
export declare const RECALL_LATER_GAP = ", {elapsed} later";
|
|
29
|
+
/** `{glimpse}`: the later memory's opening. */
|
|
30
|
+
export declare const RECALL_LATER_GLIMPSE = "\u201C{what}\u201D ";
|
|
31
|
+
/**
|
|
32
|
+
* How long after, in words: a plain duration, so no zone and no calendar
|
|
33
|
+
* words. Null when the later memory was not memorized after the recalled one.
|
|
34
|
+
*/
|
|
35
|
+
export declare function renderLaterElapsed(learnedAfterMs: number | null | undefined): string | null;
|
|
36
|
+
/** What a marker says of the later memory beyond its id. */
|
|
37
|
+
export interface RecallLaterGlimpse {
|
|
38
|
+
/** The later memory's opening, on one line. */
|
|
39
|
+
what?: string | null;
|
|
40
|
+
/** How long after the recalled memory it was memorized, in milliseconds. */
|
|
41
|
+
learnedAfterMs?: number | null;
|
|
42
|
+
/** The closest later memory is in the same reply; this is the next closest. */
|
|
43
|
+
passedOver?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The marker for one recalled memory: `laterCount` later related memories,
|
|
47
|
+
* `laterId` the one named, with what is known of it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function renderRecallLaterMarker(laterCount: number, laterId: string, glimpse?: RecallLaterGlimpse): string;
|
|
50
|
+
/**
|
|
51
|
+
* Pattern source of one marker, derived from {@link RECALL_LATER_MARKER} and
|
|
52
|
+
* its parts; no capture groups. It finds every form the renderer writes,
|
|
53
|
+
* the one without a gap or a glimpse included.
|
|
9
54
|
*/
|
|
10
|
-
export declare const RECALL_LATER_MARKER = " \u00B7 you learned {count} related {memories} later; closest: memory_get {laterId}";
|
|
11
|
-
/** The marker for one recalled memory: `laterCount` later related memories, `laterId` the closest. */
|
|
12
|
-
export declare function renderRecallLaterMarker(laterCount: number, laterId: string): string;
|
|
13
|
-
/** Pattern source of one marker, derived from {@link RECALL_LATER_MARKER}; no capture groups. */
|
|
14
55
|
export declare const RECALL_LATER_MARKER_SOURCE: string;
|
|
15
56
|
/** The text without any later-memory marker: what the line was before one was added. */
|
|
16
57
|
export declare function stripRecallLaterMarkers(text: string): string;
|
|
@@ -21,4 +62,14 @@ export declare function stripRecallLaterMarkers(text: string): string;
|
|
|
21
62
|
*/
|
|
22
63
|
export declare const AMBIENT_ITEM_POINTER_SOURCE: string;
|
|
23
64
|
export declare function ambientItemPointerRegex(flags?: string): RegExp;
|
|
65
|
+
/**
|
|
66
|
+
* The same texts without any later-memory marker that names a memory one of
|
|
67
|
+
* them carries. A hook assembles one block from several server replies
|
|
68
|
+
* (ambient recall beside the other recall lines), and only the hook sees the
|
|
69
|
+
* whole block: a marker pointing at a memory a few lines away tells the agent
|
|
70
|
+
* nothing, so it goes. A memory is carried by the line whose own pointer names
|
|
71
|
+
* it, by a JIT line headed with its id, or by being named in `alsoCarried`.
|
|
72
|
+
* A text with no such marker is returned as the same string.
|
|
73
|
+
*/
|
|
74
|
+
export declare function withoutMarkersNamingCarried(texts: readonly string[], alsoCarried?: readonly string[]): string[];
|
|
24
75
|
//# sourceMappingURL=ambientPointer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ambientPointer.d.ts","sourceRoot":"","sources":["../src/ambientPointer.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAY1C
|
|
1
|
+
{"version":3,"file":"ambientPointer.d.ts","sourceRoot":"","sources":["../src/ambientPointer.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAY1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,mBAAmB,sGACqE,CAAC;AAEtG,4DAA4D;AAC5D,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C,qFAAqF;AACrF,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAExD,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAEpD,+CAA+C;AAC/C,eAAO,MAAM,oBAAoB,wBAAwB,CAAC;AAa1D;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAgB3F;AAED,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,+EAA+E;IAC/E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAQD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAYR;AAMD;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,QAewC,CAAC;AAEhF,wFAAwF;AACxF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,QAEe,CAAC;AAExD,wBAAgB,uBAAuB,CAAC,KAAK,SAAM,GAAG,MAAM,CAE3D;AAMD;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,WAAW,GAAE,SAAS,MAAM,EAAO,GAClC,MAAM,EAAE,CA4BV"}
|
package/dist/ambientPointer.js
CHANGED
|
@@ -9,26 +9,101 @@ const LEGACY_MEMORY_ID_SOURCE = `[0-9A-Za-z_-]{${AMBIENT_ID_PREFIX_LENGTH}}`;
|
|
|
9
9
|
const FIRST_PERSON_POINTER_LEAD_SOURCE = '(?:to recall it in full:\\s*)?';
|
|
10
10
|
/**
|
|
11
11
|
* What a recalled memory's line carries when memories learned later relate to
|
|
12
|
-
* it (RETRIEVAL_LAYER §2.0.3): how many, and the closest one
|
|
13
|
-
* the line
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* it (RETRIEVAL_LAYER §2.0.3): how many, and a glimpse of the closest one,
|
|
13
|
+
* the same kind every recall line gives of its own memory: how long after the
|
|
14
|
+
* recalled memory it was learned, its opening, and its id. It follows the
|
|
15
|
+
* line's own `memory_get <id>` pointer.
|
|
16
|
+
*
|
|
17
|
+
* The glimpse is what lets an agent decide whether the later memory is worth
|
|
18
|
+
* recalling whole; a bare id gave it nothing to decide by (11 Nov 2026: 6 of
|
|
19
|
+
* 1,771 were opened). `{which}` is "closest", or "next closest" when the
|
|
20
|
+
* closest is already in the same reply. `{gap}` and `{glimpse}` are left out
|
|
21
|
+
* when they are not known, which leaves the marker as it was before the
|
|
22
|
+
* glimpse existed.
|
|
23
|
+
*
|
|
24
|
+
* The one place the wording lives: the renderer and the pattern that finds
|
|
25
|
+
* (and sheds) the marker are both built from these. A hook runtime built
|
|
26
|
+
* before a form existed cannot parse it, so the server writes the glimpse
|
|
27
|
+
* only to a runtime that says it reads it (hookTimeouts.ts HOOK_READS_HEADER).
|
|
28
|
+
* Agent-facing wording; it changes only with the owner's approval.
|
|
17
29
|
*/
|
|
18
|
-
export const RECALL_LATER_MARKER = ' \u00b7 you learned {count} related {memories} later;
|
|
19
|
-
/**
|
|
20
|
-
export
|
|
21
|
-
|
|
30
|
+
export const RECALL_LATER_MARKER = ' \u00b7 you learned {count} related {memories} later; {which}{gap}: {glimpse}memory_get {laterId}';
|
|
31
|
+
/** `{which}`: the later memory named is the closest one. */
|
|
32
|
+
export const RECALL_LATER_CLOSEST = 'closest';
|
|
33
|
+
/** `{which}`: the closest one is in the same reply, so the next closest is named. */
|
|
34
|
+
export const RECALL_LATER_NEXT_CLOSEST = 'next closest';
|
|
35
|
+
/** `{gap}`: how long after the recalled memory the later one was learned. */
|
|
36
|
+
export const RECALL_LATER_GAP = ', {elapsed} later';
|
|
37
|
+
/** `{glimpse}`: the later memory's opening. */
|
|
38
|
+
export const RECALL_LATER_GLIMPSE = '\u201c{what}\u201d ';
|
|
39
|
+
const GLIMPSE_CLOSE = '\u201d';
|
|
40
|
+
const SECOND_MS = 1_000;
|
|
41
|
+
const MINUTE_MS = 60 * SECOND_MS;
|
|
42
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
43
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
44
|
+
function elapsedUnits(count, unit) {
|
|
45
|
+
return `${count} ${unit}${count === 1 ? '' : 's'}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* How long after, in words: a plain duration, so no zone and no calendar
|
|
49
|
+
* words. Null when the later memory was not memorized after the recalled one.
|
|
50
|
+
*/
|
|
51
|
+
export function renderLaterElapsed(learnedAfterMs) {
|
|
52
|
+
if (typeof learnedAfterMs !== 'number' || !Number.isFinite(learnedAfterMs))
|
|
53
|
+
return null;
|
|
54
|
+
if (learnedAfterMs <= 0)
|
|
55
|
+
return null;
|
|
56
|
+
if (learnedAfterMs < 90 * SECOND_MS)
|
|
57
|
+
return 'moments';
|
|
58
|
+
if (learnedAfterMs < HOUR_MS)
|
|
59
|
+
return elapsedUnits(Math.round(learnedAfterMs / MINUTE_MS), 'minute');
|
|
60
|
+
if (learnedAfterMs < 2 * DAY_MS)
|
|
61
|
+
return elapsedUnits(Math.round(learnedAfterMs / HOUR_MS), 'hour');
|
|
62
|
+
if (learnedAfterMs < 14 * DAY_MS)
|
|
63
|
+
return elapsedUnits(Math.round(learnedAfterMs / DAY_MS), 'day');
|
|
64
|
+
if (learnedAfterMs < 56 * DAY_MS) {
|
|
65
|
+
return elapsedUnits(Math.round(learnedAfterMs / (7 * DAY_MS)), 'week');
|
|
66
|
+
}
|
|
67
|
+
if (learnedAfterMs < 730 * DAY_MS) {
|
|
68
|
+
return elapsedUnits(Math.round(learnedAfterMs / (30.44 * DAY_MS)), 'month');
|
|
69
|
+
}
|
|
70
|
+
return elapsedUnits(Math.round(learnedAfterMs / (365.25 * DAY_MS)), 'year');
|
|
71
|
+
}
|
|
72
|
+
/** The opening as the marker can carry it: one line, and never its own closing quote. */
|
|
73
|
+
function glimpseText(what) {
|
|
74
|
+
if (typeof what !== 'string')
|
|
75
|
+
return '';
|
|
76
|
+
return what.replace(/\s+/gu, ' ').replaceAll(GLIMPSE_CLOSE, '"').trim();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The marker for one recalled memory: `laterCount` later related memories,
|
|
80
|
+
* `laterId` the one named, with what is known of it.
|
|
81
|
+
*/
|
|
82
|
+
export function renderRecallLaterMarker(laterCount, laterId, glimpse = {}) {
|
|
83
|
+
const elapsed = renderLaterElapsed(glimpse.learnedAfterMs);
|
|
84
|
+
const what = glimpseText(glimpse.what);
|
|
85
|
+
return (RECALL_LATER_MARKER.replace('{count}', String(laterCount))
|
|
22
86
|
.replace('{memories}', laterCount === 1 ? 'memory' : 'memories')
|
|
23
|
-
.replace('{
|
|
87
|
+
.replace('{which}', glimpse.passedOver ? RECALL_LATER_NEXT_CLOSEST : RECALL_LATER_CLOSEST)
|
|
88
|
+
.replace('{laterId}', laterId)
|
|
89
|
+
.replace('{gap}', () => (elapsed ? RECALL_LATER_GAP.replace('{elapsed}', elapsed) : ''))
|
|
90
|
+
// Last, so nothing in the opening is read as a placeholder.
|
|
91
|
+
.replace('{glimpse}', () => (what ? RECALL_LATER_GLIMPSE.replace('{what}', () => what) : '')));
|
|
24
92
|
}
|
|
25
93
|
function escapeRegExp(text) {
|
|
26
94
|
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
27
95
|
}
|
|
28
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Pattern source of one marker, derived from {@link RECALL_LATER_MARKER} and
|
|
98
|
+
* its parts; no capture groups. It finds every form the renderer writes,
|
|
99
|
+
* the one without a gap or a glimpse included.
|
|
100
|
+
*/
|
|
29
101
|
export const RECALL_LATER_MARKER_SOURCE = escapeRegExp(RECALL_LATER_MARKER)
|
|
30
102
|
.replace(escapeRegExp('{count}'), '\\d+')
|
|
31
103
|
.replace(escapeRegExp('{memories}'), 'memor(?:y|ies)')
|
|
104
|
+
.replace(escapeRegExp('{which}'), `(?:${escapeRegExp(RECALL_LATER_NEXT_CLOSEST)}|${escapeRegExp(RECALL_LATER_CLOSEST)})`)
|
|
105
|
+
.replace(escapeRegExp('{gap}'), `(?:${escapeRegExp(RECALL_LATER_GAP).replace(escapeRegExp('{elapsed}'), '[a-z0-9 ]{1,24}')})?`)
|
|
106
|
+
.replace(escapeRegExp('{glimpse}'), `(?:${escapeRegExp(RECALL_LATER_GLIMPSE).replace(escapeRegExp('{what}'), `[^${GLIMPSE_CLOSE}\\n]*`)})?`)
|
|
32
107
|
.replace(escapeRegExp('{laterId}'), `${MEMORY_UUID_SOURCE}(?![0-9A-Za-z_-])`);
|
|
33
108
|
/** The text without any later-memory marker: what the line was before one was added. */
|
|
34
109
|
export function stripRecallLaterMarkers(text) {
|
|
@@ -44,4 +119,49 @@ export const AMBIENT_ITEM_POINTER_SOURCE = `\\u2014\\s*${FIRST_PERSON_POINTER_LE
|
|
|
44
119
|
export function ambientItemPointerRegex(flags = 'g') {
|
|
45
120
|
return new RegExp(AMBIENT_ITEM_POINTER_SOURCE, flags);
|
|
46
121
|
}
|
|
122
|
+
const LATER_ID_AT_END = new RegExp(`(${MEMORY_UUID_SOURCE})$`);
|
|
123
|
+
/** A JIT line without a pointer names its memory by the first eight characters of its id. */
|
|
124
|
+
const ID_HEAD_LINE = new RegExp(`^\\[([0-9A-Fa-f]{${AMBIENT_ID_PREFIX_LENGTH}})\\] `, 'gm');
|
|
125
|
+
/**
|
|
126
|
+
* The same texts without any later-memory marker that names a memory one of
|
|
127
|
+
* them carries. A hook assembles one block from several server replies
|
|
128
|
+
* (ambient recall beside the other recall lines), and only the hook sees the
|
|
129
|
+
* whole block: a marker pointing at a memory a few lines away tells the agent
|
|
130
|
+
* nothing, so it goes. A memory is carried by the line whose own pointer names
|
|
131
|
+
* it, by a JIT line headed with its id, or by being named in `alsoCarried`.
|
|
132
|
+
* A text with no such marker is returned as the same string.
|
|
133
|
+
*/
|
|
134
|
+
export function withoutMarkersNamingCarried(texts, alsoCarried = []) {
|
|
135
|
+
const marker = new RegExp(RECALL_LATER_MARKER_SOURCE, 'g');
|
|
136
|
+
if (!texts.some((text) => new RegExp(RECALL_LATER_MARKER_SOURCE).test(text)))
|
|
137
|
+
return [...texts];
|
|
138
|
+
const carried = new Set();
|
|
139
|
+
const heads = new Set();
|
|
140
|
+
const note = (id) => {
|
|
141
|
+
const lower = id.toLowerCase();
|
|
142
|
+
if (lower.length <= AMBIENT_ID_PREFIX_LENGTH)
|
|
143
|
+
heads.add(lower);
|
|
144
|
+
else
|
|
145
|
+
carried.add(lower);
|
|
146
|
+
};
|
|
147
|
+
alsoCarried.forEach(note);
|
|
148
|
+
for (const text of texts) {
|
|
149
|
+
// Without its markers, so a later memory's own id is not taken for a line's pointer.
|
|
150
|
+
const plain = stripRecallLaterMarkers(text);
|
|
151
|
+
for (const match of plain.matchAll(ambientItemPointerRegex('g'))) {
|
|
152
|
+
if (match[1])
|
|
153
|
+
note(match[1]);
|
|
154
|
+
}
|
|
155
|
+
for (const match of plain.matchAll(ID_HEAD_LINE)) {
|
|
156
|
+
if (match[1])
|
|
157
|
+
heads.add(match[1].toLowerCase());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return texts.map((text) => text.replace(marker, (found) => {
|
|
161
|
+
const later = LATER_ID_AT_END.exec(found)?.[1]?.toLowerCase();
|
|
162
|
+
if (!later)
|
|
163
|
+
return found;
|
|
164
|
+
return carried.has(later) || heads.has(later.slice(0, AMBIENT_ID_PREFIX_LENGTH)) ? '' : found;
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
47
167
|
//# sourceMappingURL=ambientPointer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ambientPointer.js","sourceRoot":"","sources":["../src/ambientPointer.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C,MAAM,kBAAkB,GAAG,sDAAsD,CAAC;AAClF,MAAM,uBAAuB,GAAG,iBAAiB,wBAAwB,GAAG,CAAC;AAE7E;;;;GAIG;AACH,MAAM,gCAAgC,GAAG,gCAAgC,CAAC;AAE1E
|
|
1
|
+
{"version":3,"file":"ambientPointer.js","sourceRoot":"","sources":["../src/ambientPointer.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C,MAAM,kBAAkB,GAAG,sDAAsD,CAAC;AAClF,MAAM,uBAAuB,GAAG,iBAAiB,wBAAwB,GAAG,CAAC;AAE7E;;;;GAIG;AACH,MAAM,gCAAgC,GAAG,gCAAgC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,mGAAmG,CAAC;AAEtG,4DAA4D;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAE9C,qFAAqF;AACrF,MAAM,CAAC,MAAM,yBAAyB,GAAG,cAAc,CAAC;AAExD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,m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.d.ts
CHANGED
|
@@ -30,6 +30,12 @@ export interface BudgetedContextFit {
|
|
|
30
30
|
}
|
|
31
31
|
/** Measure rendered context in the host's native budget unit. */
|
|
32
32
|
export declare function measureContext(text: string, units?: ContextBudgetUnits): number;
|
|
33
|
+
/**
|
|
34
|
+
* The items as one block reads them: no later-memory marker names a memory
|
|
35
|
+
* another item of the same block carries (ambientPointer.ts
|
|
36
|
+
* withoutMarkersNamingCarried). Items it leaves alone are the same objects.
|
|
37
|
+
*/
|
|
38
|
+
export declare function withoutCarriedMarkers(items: readonly ContextBudgetItem[], alongside?: readonly ContextBudgetItem[]): ContextBudgetItem[];
|
|
33
39
|
/**
|
|
34
40
|
* Compose ordered items within a fixed budget. Full items are emitted exactly;
|
|
35
41
|
* the first item that does not fit and every later item are shed. The first
|
|
@@ -37,6 +43,9 @@ export declare function measureContext(text: string, units?: ContextBudgetUnits)
|
|
|
37
43
|
* share one trailing marker containing only their explicit retrieval routes.
|
|
38
44
|
* Items without a route leave no agent-visible stub.
|
|
39
45
|
*
|
|
46
|
+
* First, a later-memory marker that names a memory another item carries is
|
|
47
|
+
* dropped ({@link withoutCarriedMarkers}): the block is where that can be seen.
|
|
48
|
+
*
|
|
40
49
|
* Before anything is shed, the later-memory markers go (ambientPointer.ts
|
|
41
50
|
* RECALL_LATER_MARKER), the last item's first: a marker never costs a memory
|
|
42
51
|
* its place or any of its text.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextBudget.d.ts","sourceRoot":"","sources":["../src/contextBudget.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contextBudget.d.ts","sourceRoot":"","sources":["../src/contextBudget.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAElE,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,YAAY,CAAC;AAE7D,eAAO,MAAM,wBAAwB;aACnC,WAAW,EAAE,IAAK;aAClB,KAAK,EAAE,I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,GAAE,SAAS,MAAM,EAAO,GAChC,iBAAiB,EAAE,CAMrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG7E;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAClF,MAAM,CAIR;AAED,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAExD"}
|
package/dist/contextBudget.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AMBIENT_ITEM_POINTER_SOURCE, stripRecallLaterMarkers } from './ambientPointer.js';
|
|
1
|
+
import { AMBIENT_ITEM_POINTER_SOURCE, stripRecallLaterMarkers, withoutMarkersNamingCarried, } from './ambientPointer.js';
|
|
2
2
|
export { AMBIENT_ITEM_POINTER_SOURCE } from './ambientPointer.js';
|
|
3
3
|
export const REFLEX_NOTE_BUDGET_BYTES = {
|
|
4
4
|
claude_code: 6_000,
|
|
@@ -53,6 +53,18 @@ function contextHead(text, budget, units) {
|
|
|
53
53
|
export function measureContext(text, units = 'characters') {
|
|
54
54
|
return units === 'utf8-bytes' ? Buffer.byteLength(text, 'utf8') : text.length;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The items as one block reads them: no later-memory marker names a memory
|
|
58
|
+
* another item of the same block carries (ambientPointer.ts
|
|
59
|
+
* withoutMarkersNamingCarried). Items it leaves alone are the same objects.
|
|
60
|
+
*/
|
|
61
|
+
export function withoutCarriedMarkers(items, alongside = []) {
|
|
62
|
+
const texts = withoutMarkersNamingCarried(items.map((item) => item.text), [...items, ...alongside].flatMap((item) => [...itemMemoryIds(item)]));
|
|
63
|
+
return items.map((item, index) => {
|
|
64
|
+
const text = texts[index] ?? item.text;
|
|
65
|
+
return text === item.text ? item : { ...item, text };
|
|
66
|
+
});
|
|
67
|
+
}
|
|
56
68
|
/**
|
|
57
69
|
* Compose ordered items within a fixed budget. Full items are emitted exactly;
|
|
58
70
|
* the first item that does not fit and every later item are shed. The first
|
|
@@ -60,6 +72,9 @@ export function measureContext(text, units = 'characters') {
|
|
|
60
72
|
* share one trailing marker containing only their explicit retrieval routes.
|
|
61
73
|
* Items without a route leave no agent-visible stub.
|
|
62
74
|
*
|
|
75
|
+
* First, a later-memory marker that names a memory another item carries is
|
|
76
|
+
* dropped ({@link withoutCarriedMarkers}): the block is where that can be seen.
|
|
77
|
+
*
|
|
63
78
|
* Before anything is shed, the later-memory markers go (ambientPointer.ts
|
|
64
79
|
* RECALL_LATER_MARKER), the last item's first: a marker never costs a memory
|
|
65
80
|
* its place or any of its text.
|
|
@@ -68,7 +83,7 @@ export function fitContextItems(givenItems, opts) {
|
|
|
68
83
|
const units = opts.units ?? 'characters';
|
|
69
84
|
const suffix = opts.reservedSuffix ?? [];
|
|
70
85
|
const valueOf = (entries) => [...entries, ...suffix].map((item) => item.text).join(JOINER);
|
|
71
|
-
const items =
|
|
86
|
+
const items = withoutCarriedMarkers(givenItems, suffix);
|
|
72
87
|
for (let index = items.length;; index -= 1) {
|
|
73
88
|
const value = valueOf(items);
|
|
74
89
|
if (measureContext(value, units) <= opts.budget) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextBudget.js","sourceRoot":"","sources":["../src/contextBudget.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"contextBudget.js","sourceRoot":"","sources":["../src/contextBudget.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,u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C,IAAI,CAAC,IAAI,CAAC,CAAC;AACrF,CAAC"}
|
package/dist/hookTimeouts.d.ts
CHANGED
|
@@ -157,7 +157,26 @@ export declare const HOOK_BUDGET_HEADER = "x-mnemonik-hook-budget-ms";
|
|
|
157
157
|
* old runtime failing open and recall stopping silently.
|
|
158
158
|
*/
|
|
159
159
|
export declare const HOOK_VERSION_HEADER = "x-mnemonik-hook-version";
|
|
160
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* What this hook runtime can read of the server's replies, beyond what every
|
|
162
|
+
* runtime could when the header was introduced. The server writes a newer
|
|
163
|
+
* form only to a runtime that names it here; a runtime that does not send the
|
|
164
|
+
* header, or does not name the form, is sent what it was always sent. So a
|
|
165
|
+
* server may deploy ahead of the hooks that read its newest wording, which is
|
|
166
|
+
* the order every release ships in.
|
|
167
|
+
*
|
|
168
|
+
* - `later-glimpse`: the later-memory marker with the time between and the
|
|
169
|
+
* later memory's opening (ambientPointer.ts RECALL_LATER_MARKER).
|
|
170
|
+
*/
|
|
171
|
+
export declare const HOOK_READS_HEADER = "x-mnemonik-hook-reads";
|
|
172
|
+
export declare const HOOK_READS_LATER_GLIMPSE = "later-glimpse";
|
|
173
|
+
export declare const HOOK_READS: readonly string[];
|
|
174
|
+
/** Whether a request's headers say its hook runtime reads `form`. */
|
|
175
|
+
export declare function hookReads(headers: Record<string, unknown> | undefined, form: string): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* `init` with the hook-version header added, and what the runtime reads
|
|
178
|
+
* ({@link HOOK_READS_HEADER}); the caller's headers are kept.
|
|
179
|
+
*/
|
|
161
180
|
export declare function withHookVersion<T extends {
|
|
162
181
|
headers?: unknown;
|
|
163
182
|
}>(init: T, runtime: string, version: string): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookTimeouts.d.ts","sourceRoot":"","sources":["../src/hookTimeouts.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;GA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+F;AAC/F,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASjE;AA+CD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EACjF,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EACzC,KAAK,GAAE,MAAM,MAAiB,GAC7B,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAgGnB"}
|
package/dist/hookTimeouts.js
CHANGED
|
@@ -160,7 +160,35 @@ export const HOOK_BUDGET_HEADER = 'x-mnemonik-hook-budget-ms';
|
|
|
160
160
|
* old runtime failing open and recall stopping silently.
|
|
161
161
|
*/
|
|
162
162
|
export const HOOK_VERSION_HEADER = 'x-mnemonik-hook-version';
|
|
163
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* What this hook runtime can read of the server's replies, beyond what every
|
|
165
|
+
* runtime could when the header was introduced. The server writes a newer
|
|
166
|
+
* form only to a runtime that names it here; a runtime that does not send the
|
|
167
|
+
* header, or does not name the form, is sent what it was always sent. So a
|
|
168
|
+
* server may deploy ahead of the hooks that read its newest wording, which is
|
|
169
|
+
* the order every release ships in.
|
|
170
|
+
*
|
|
171
|
+
* - `later-glimpse`: the later-memory marker with the time between and the
|
|
172
|
+
* later memory's opening (ambientPointer.ts RECALL_LATER_MARKER).
|
|
173
|
+
*/
|
|
174
|
+
export const HOOK_READS_HEADER = 'x-mnemonik-hook-reads';
|
|
175
|
+
export const HOOK_READS_LATER_GLIMPSE = 'later-glimpse';
|
|
176
|
+
export const HOOK_READS = [HOOK_READS_LATER_GLIMPSE];
|
|
177
|
+
/** Whether a request's headers say its hook runtime reads `form`. */
|
|
178
|
+
export function hookReads(headers, form) {
|
|
179
|
+
const raw = headers?.[HOOK_READS_HEADER];
|
|
180
|
+
const value = Array.isArray(raw) ? raw.join(',') : raw;
|
|
181
|
+
if (typeof value !== 'string')
|
|
182
|
+
return false;
|
|
183
|
+
return value
|
|
184
|
+
.split(',')
|
|
185
|
+
.map((part) => part.trim().toLowerCase())
|
|
186
|
+
.includes(form);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* `init` with the hook-version header added, and what the runtime reads
|
|
190
|
+
* ({@link HOOK_READS_HEADER}); the caller's headers are kept.
|
|
191
|
+
*/
|
|
164
192
|
export function withHookVersion(init, runtime, version) {
|
|
165
193
|
const raw = init.headers;
|
|
166
194
|
if (raw && typeof raw === 'object' && !(raw instanceof Headers) && !Array.isArray(raw)) {
|
|
@@ -172,11 +200,17 @@ export function withHookVersion(init, runtime, version) {
|
|
|
172
200
|
if (name.toLowerCase() === HOOK_VERSION_HEADER)
|
|
173
201
|
delete headers[name];
|
|
174
202
|
}
|
|
203
|
+
for (const name of Object.keys(headers)) {
|
|
204
|
+
if (name.toLowerCase() === HOOK_READS_HEADER)
|
|
205
|
+
delete headers[name];
|
|
206
|
+
}
|
|
175
207
|
headers[HOOK_VERSION_HEADER] = `${runtime}/${version}`;
|
|
208
|
+
headers[HOOK_READS_HEADER] = HOOK_READS.join(',');
|
|
176
209
|
return { ...init, headers };
|
|
177
210
|
}
|
|
178
211
|
const headers = new Headers(raw);
|
|
179
212
|
headers.set(HOOK_VERSION_HEADER, `${runtime}/${version}`);
|
|
213
|
+
headers.set(HOOK_READS_HEADER, HOOK_READS.join(','));
|
|
180
214
|
return { ...init, headers: Object.fromEntries(headers.entries()) };
|
|
181
215
|
}
|
|
182
216
|
/**
|
package/dist/hookTimeouts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookTimeouts.js","sourceRoot":"","sources":["../src/hookTimeouts.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;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BACD,IAAI,OAAO,KAAK,CAAC;oBAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,CAAC;QAEF,MAAM,CAAC,CAAC,CAAC,CAAC;QACV,UAAU,GAAG,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/ambientPointer.ts
CHANGED
|
@@ -12,30 +12,134 @@ const FIRST_PERSON_POINTER_LEAD_SOURCE = '(?:to recall it in full:\\s*)?';
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* What a recalled memory's line carries when memories learned later relate to
|
|
15
|
-
* it (RETRIEVAL_LAYER §2.0.3): how many, and the closest one
|
|
16
|
-
* the line
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* it (RETRIEVAL_LAYER §2.0.3): how many, and a glimpse of the closest one,
|
|
16
|
+
* the same kind every recall line gives of its own memory: how long after the
|
|
17
|
+
* recalled memory it was learned, its opening, and its id. It follows the
|
|
18
|
+
* line's own `memory_get <id>` pointer.
|
|
19
|
+
*
|
|
20
|
+
* The glimpse is what lets an agent decide whether the later memory is worth
|
|
21
|
+
* recalling whole; a bare id gave it nothing to decide by (11 Nov 2026: 6 of
|
|
22
|
+
* 1,771 were opened). `{which}` is "closest", or "next closest" when the
|
|
23
|
+
* closest is already in the same reply. `{gap}` and `{glimpse}` are left out
|
|
24
|
+
* when they are not known, which leaves the marker as it was before the
|
|
25
|
+
* glimpse existed.
|
|
26
|
+
*
|
|
27
|
+
* The one place the wording lives: the renderer and the pattern that finds
|
|
28
|
+
* (and sheds) the marker are both built from these. A hook runtime built
|
|
29
|
+
* before a form existed cannot parse it, so the server writes the glimpse
|
|
30
|
+
* only to a runtime that says it reads it (hookTimeouts.ts HOOK_READS_HEADER).
|
|
31
|
+
* Agent-facing wording; it changes only with the owner's approval.
|
|
20
32
|
*/
|
|
21
33
|
export const RECALL_LATER_MARKER =
|
|
22
|
-
' \u00b7 you learned {count} related {memories} later;
|
|
34
|
+
' \u00b7 you learned {count} related {memories} later; {which}{gap}: {glimpse}memory_get {laterId}';
|
|
23
35
|
|
|
24
|
-
/**
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
/** `{which}`: the later memory named is the closest one. */
|
|
37
|
+
export const RECALL_LATER_CLOSEST = 'closest';
|
|
38
|
+
|
|
39
|
+
/** `{which}`: the closest one is in the same reply, so the next closest is named. */
|
|
40
|
+
export const RECALL_LATER_NEXT_CLOSEST = 'next closest';
|
|
41
|
+
|
|
42
|
+
/** `{gap}`: how long after the recalled memory the later one was learned. */
|
|
43
|
+
export const RECALL_LATER_GAP = ', {elapsed} later';
|
|
44
|
+
|
|
45
|
+
/** `{glimpse}`: the later memory's opening. */
|
|
46
|
+
export const RECALL_LATER_GLIMPSE = '\u201c{what}\u201d ';
|
|
47
|
+
|
|
48
|
+
const GLIMPSE_CLOSE = '\u201d';
|
|
49
|
+
|
|
50
|
+
const SECOND_MS = 1_000;
|
|
51
|
+
const MINUTE_MS = 60 * SECOND_MS;
|
|
52
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
53
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
54
|
+
|
|
55
|
+
function elapsedUnits(count: number, unit: string): string {
|
|
56
|
+
return `${count} ${unit}${count === 1 ? '' : 's'}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* How long after, in words: a plain duration, so no zone and no calendar
|
|
61
|
+
* words. Null when the later memory was not memorized after the recalled one.
|
|
62
|
+
*/
|
|
63
|
+
export function renderLaterElapsed(learnedAfterMs: number | null | undefined): string | null {
|
|
64
|
+
if (typeof learnedAfterMs !== 'number' || !Number.isFinite(learnedAfterMs)) return null;
|
|
65
|
+
if (learnedAfterMs <= 0) return null;
|
|
66
|
+
if (learnedAfterMs < 90 * SECOND_MS) return 'moments';
|
|
67
|
+
if (learnedAfterMs < HOUR_MS)
|
|
68
|
+
return elapsedUnits(Math.round(learnedAfterMs / MINUTE_MS), 'minute');
|
|
69
|
+
if (learnedAfterMs < 2 * DAY_MS)
|
|
70
|
+
return elapsedUnits(Math.round(learnedAfterMs / HOUR_MS), 'hour');
|
|
71
|
+
if (learnedAfterMs < 14 * DAY_MS) return elapsedUnits(Math.round(learnedAfterMs / DAY_MS), 'day');
|
|
72
|
+
if (learnedAfterMs < 56 * DAY_MS) {
|
|
73
|
+
return elapsedUnits(Math.round(learnedAfterMs / (7 * DAY_MS)), 'week');
|
|
74
|
+
}
|
|
75
|
+
if (learnedAfterMs < 730 * DAY_MS) {
|
|
76
|
+
return elapsedUnits(Math.round(learnedAfterMs / (30.44 * DAY_MS)), 'month');
|
|
77
|
+
}
|
|
78
|
+
return elapsedUnits(Math.round(learnedAfterMs / (365.25 * DAY_MS)), 'year');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** What a marker says of the later memory beyond its id. */
|
|
82
|
+
export interface RecallLaterGlimpse {
|
|
83
|
+
/** The later memory's opening, on one line. */
|
|
84
|
+
what?: string | null;
|
|
85
|
+
/** How long after the recalled memory it was memorized, in milliseconds. */
|
|
86
|
+
learnedAfterMs?: number | null;
|
|
87
|
+
/** The closest later memory is in the same reply; this is the next closest. */
|
|
88
|
+
passedOver?: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The opening as the marker can carry it: one line, and never its own closing quote. */
|
|
92
|
+
function glimpseText(what: string | null | undefined): string {
|
|
93
|
+
if (typeof what !== 'string') return '';
|
|
94
|
+
return what.replace(/\s+/gu, ' ').replaceAll(GLIMPSE_CLOSE, '"').trim();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The marker for one recalled memory: `laterCount` later related memories,
|
|
99
|
+
* `laterId` the one named, with what is known of it.
|
|
100
|
+
*/
|
|
101
|
+
export function renderRecallLaterMarker(
|
|
102
|
+
laterCount: number,
|
|
103
|
+
laterId: string,
|
|
104
|
+
glimpse: RecallLaterGlimpse = {}
|
|
105
|
+
): string {
|
|
106
|
+
const elapsed = renderLaterElapsed(glimpse.learnedAfterMs);
|
|
107
|
+
const what = glimpseText(glimpse.what);
|
|
108
|
+
return (
|
|
109
|
+
RECALL_LATER_MARKER.replace('{count}', String(laterCount))
|
|
110
|
+
.replace('{memories}', laterCount === 1 ? 'memory' : 'memories')
|
|
111
|
+
.replace('{which}', glimpse.passedOver ? RECALL_LATER_NEXT_CLOSEST : RECALL_LATER_CLOSEST)
|
|
112
|
+
.replace('{laterId}', laterId)
|
|
113
|
+
.replace('{gap}', () => (elapsed ? RECALL_LATER_GAP.replace('{elapsed}', elapsed) : ''))
|
|
114
|
+
// Last, so nothing in the opening is read as a placeholder.
|
|
115
|
+
.replace('{glimpse}', () => (what ? RECALL_LATER_GLIMPSE.replace('{what}', () => what) : ''))
|
|
116
|
+
);
|
|
29
117
|
}
|
|
30
118
|
|
|
31
119
|
function escapeRegExp(text: string): string {
|
|
32
120
|
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
33
121
|
}
|
|
34
122
|
|
|
35
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Pattern source of one marker, derived from {@link RECALL_LATER_MARKER} and
|
|
125
|
+
* its parts; no capture groups. It finds every form the renderer writes,
|
|
126
|
+
* the one without a gap or a glimpse included.
|
|
127
|
+
*/
|
|
36
128
|
export const RECALL_LATER_MARKER_SOURCE = escapeRegExp(RECALL_LATER_MARKER)
|
|
37
129
|
.replace(escapeRegExp('{count}'), '\\d+')
|
|
38
130
|
.replace(escapeRegExp('{memories}'), 'memor(?:y|ies)')
|
|
131
|
+
.replace(
|
|
132
|
+
escapeRegExp('{which}'),
|
|
133
|
+
`(?:${escapeRegExp(RECALL_LATER_NEXT_CLOSEST)}|${escapeRegExp(RECALL_LATER_CLOSEST)})`
|
|
134
|
+
)
|
|
135
|
+
.replace(
|
|
136
|
+
escapeRegExp('{gap}'),
|
|
137
|
+
`(?:${escapeRegExp(RECALL_LATER_GAP).replace(escapeRegExp('{elapsed}'), '[a-z0-9 ]{1,24}')})?`
|
|
138
|
+
)
|
|
139
|
+
.replace(
|
|
140
|
+
escapeRegExp('{glimpse}'),
|
|
141
|
+
`(?:${escapeRegExp(RECALL_LATER_GLIMPSE).replace(escapeRegExp('{what}'), `[^${GLIMPSE_CLOSE}\\n]*`)})?`
|
|
142
|
+
)
|
|
39
143
|
.replace(escapeRegExp('{laterId}'), `${MEMORY_UUID_SOURCE}(?![0-9A-Za-z_-])`);
|
|
40
144
|
|
|
41
145
|
/** The text without any later-memory marker: what the line was before one was added. */
|
|
@@ -55,3 +159,49 @@ export const AMBIENT_ITEM_POINTER_SOURCE =
|
|
|
55
159
|
export function ambientItemPointerRegex(flags = 'g'): RegExp {
|
|
56
160
|
return new RegExp(AMBIENT_ITEM_POINTER_SOURCE, flags);
|
|
57
161
|
}
|
|
162
|
+
|
|
163
|
+
const LATER_ID_AT_END = new RegExp(`(${MEMORY_UUID_SOURCE})$`);
|
|
164
|
+
/** A JIT line without a pointer names its memory by the first eight characters of its id. */
|
|
165
|
+
const ID_HEAD_LINE = new RegExp(`^\\[([0-9A-Fa-f]{${AMBIENT_ID_PREFIX_LENGTH}})\\] `, 'gm');
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The same texts without any later-memory marker that names a memory one of
|
|
169
|
+
* them carries. A hook assembles one block from several server replies
|
|
170
|
+
* (ambient recall beside the other recall lines), and only the hook sees the
|
|
171
|
+
* whole block: a marker pointing at a memory a few lines away tells the agent
|
|
172
|
+
* nothing, so it goes. A memory is carried by the line whose own pointer names
|
|
173
|
+
* it, by a JIT line headed with its id, or by being named in `alsoCarried`.
|
|
174
|
+
* A text with no such marker is returned as the same string.
|
|
175
|
+
*/
|
|
176
|
+
export function withoutMarkersNamingCarried(
|
|
177
|
+
texts: readonly string[],
|
|
178
|
+
alsoCarried: readonly string[] = []
|
|
179
|
+
): string[] {
|
|
180
|
+
const marker = new RegExp(RECALL_LATER_MARKER_SOURCE, 'g');
|
|
181
|
+
if (!texts.some((text) => new RegExp(RECALL_LATER_MARKER_SOURCE).test(text))) return [...texts];
|
|
182
|
+
const carried = new Set<string>();
|
|
183
|
+
const heads = new Set<string>();
|
|
184
|
+
const note = (id: string): void => {
|
|
185
|
+
const lower = id.toLowerCase();
|
|
186
|
+
if (lower.length <= AMBIENT_ID_PREFIX_LENGTH) heads.add(lower);
|
|
187
|
+
else carried.add(lower);
|
|
188
|
+
};
|
|
189
|
+
alsoCarried.forEach(note);
|
|
190
|
+
for (const text of texts) {
|
|
191
|
+
// Without its markers, so a later memory's own id is not taken for a line's pointer.
|
|
192
|
+
const plain = stripRecallLaterMarkers(text);
|
|
193
|
+
for (const match of plain.matchAll(ambientItemPointerRegex('g'))) {
|
|
194
|
+
if (match[1]) note(match[1]);
|
|
195
|
+
}
|
|
196
|
+
for (const match of plain.matchAll(ID_HEAD_LINE)) {
|
|
197
|
+
if (match[1]) heads.add(match[1].toLowerCase());
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return texts.map((text) =>
|
|
201
|
+
text.replace(marker, (found: string) => {
|
|
202
|
+
const later = LATER_ID_AT_END.exec(found)?.[1]?.toLowerCase();
|
|
203
|
+
if (!later) return found;
|
|
204
|
+
return carried.has(later) || heads.has(later.slice(0, AMBIENT_ID_PREFIX_LENGTH)) ? '' : found;
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
}
|
package/src/contextBudget.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AMBIENT_ITEM_POINTER_SOURCE,
|
|
3
|
+
stripRecallLaterMarkers,
|
|
4
|
+
withoutMarkersNamingCarried,
|
|
5
|
+
} from './ambientPointer.js';
|
|
2
6
|
|
|
3
7
|
export { AMBIENT_ITEM_POINTER_SOURCE } from './ambientPointer.js';
|
|
4
8
|
|
|
@@ -85,6 +89,25 @@ export function measureContext(text: string, units: ContextBudgetUnits = 'charac
|
|
|
85
89
|
return units === 'utf8-bytes' ? Buffer.byteLength(text, 'utf8') : text.length;
|
|
86
90
|
}
|
|
87
91
|
|
|
92
|
+
/**
|
|
93
|
+
* The items as one block reads them: no later-memory marker names a memory
|
|
94
|
+
* another item of the same block carries (ambientPointer.ts
|
|
95
|
+
* withoutMarkersNamingCarried). Items it leaves alone are the same objects.
|
|
96
|
+
*/
|
|
97
|
+
export function withoutCarriedMarkers(
|
|
98
|
+
items: readonly ContextBudgetItem[],
|
|
99
|
+
alongside: readonly ContextBudgetItem[] = []
|
|
100
|
+
): ContextBudgetItem[] {
|
|
101
|
+
const texts = withoutMarkersNamingCarried(
|
|
102
|
+
items.map((item) => item.text),
|
|
103
|
+
[...items, ...alongside].flatMap((item) => [...itemMemoryIds(item)])
|
|
104
|
+
);
|
|
105
|
+
return items.map((item, index) => {
|
|
106
|
+
const text = texts[index] ?? item.text;
|
|
107
|
+
return text === item.text ? item : { ...item, text };
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
88
111
|
/**
|
|
89
112
|
* Compose ordered items within a fixed budget. Full items are emitted exactly;
|
|
90
113
|
* the first item that does not fit and every later item are shed. The first
|
|
@@ -92,6 +115,9 @@ export function measureContext(text: string, units: ContextBudgetUnits = 'charac
|
|
|
92
115
|
* share one trailing marker containing only their explicit retrieval routes.
|
|
93
116
|
* Items without a route leave no agent-visible stub.
|
|
94
117
|
*
|
|
118
|
+
* First, a later-memory marker that names a memory another item carries is
|
|
119
|
+
* dropped ({@link withoutCarriedMarkers}): the block is where that can be seen.
|
|
120
|
+
*
|
|
95
121
|
* Before anything is shed, the later-memory markers go (ambientPointer.ts
|
|
96
122
|
* RECALL_LATER_MARKER), the last item's first: a marker never costs a memory
|
|
97
123
|
* its place or any of its text.
|
|
@@ -108,7 +134,7 @@ export function fitContextItems(
|
|
|
108
134
|
const suffix = opts.reservedSuffix ?? [];
|
|
109
135
|
const valueOf = (entries: readonly ContextBudgetItem[]): string =>
|
|
110
136
|
[...entries, ...suffix].map((item) => item.text).join(JOINER);
|
|
111
|
-
const items =
|
|
137
|
+
const items = withoutCarriedMarkers(givenItems, suffix);
|
|
112
138
|
for (let index = items.length; ; index -= 1) {
|
|
113
139
|
const value = valueOf(items);
|
|
114
140
|
if (measureContext(value, units) <= opts.budget) {
|
package/src/hookTimeouts.ts
CHANGED
|
@@ -179,7 +179,36 @@ export const HOOK_BUDGET_HEADER = 'x-mnemonik-hook-budget-ms';
|
|
|
179
179
|
*/
|
|
180
180
|
export const HOOK_VERSION_HEADER = 'x-mnemonik-hook-version';
|
|
181
181
|
|
|
182
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* What this hook runtime can read of the server's replies, beyond what every
|
|
184
|
+
* runtime could when the header was introduced. The server writes a newer
|
|
185
|
+
* form only to a runtime that names it here; a runtime that does not send the
|
|
186
|
+
* header, or does not name the form, is sent what it was always sent. So a
|
|
187
|
+
* server may deploy ahead of the hooks that read its newest wording, which is
|
|
188
|
+
* the order every release ships in.
|
|
189
|
+
*
|
|
190
|
+
* - `later-glimpse`: the later-memory marker with the time between and the
|
|
191
|
+
* later memory's opening (ambientPointer.ts RECALL_LATER_MARKER).
|
|
192
|
+
*/
|
|
193
|
+
export const HOOK_READS_HEADER = 'x-mnemonik-hook-reads';
|
|
194
|
+
export const HOOK_READS_LATER_GLIMPSE = 'later-glimpse';
|
|
195
|
+
export const HOOK_READS: readonly string[] = [HOOK_READS_LATER_GLIMPSE];
|
|
196
|
+
|
|
197
|
+
/** Whether a request's headers say its hook runtime reads `form`. */
|
|
198
|
+
export function hookReads(headers: Record<string, unknown> | undefined, form: string): boolean {
|
|
199
|
+
const raw = headers?.[HOOK_READS_HEADER];
|
|
200
|
+
const value = Array.isArray(raw) ? raw.join(',') : raw;
|
|
201
|
+
if (typeof value !== 'string') return false;
|
|
202
|
+
return value
|
|
203
|
+
.split(',')
|
|
204
|
+
.map((part) => part.trim().toLowerCase())
|
|
205
|
+
.includes(form);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* `init` with the hook-version header added, and what the runtime reads
|
|
210
|
+
* ({@link HOOK_READS_HEADER}); the caller's headers are kept.
|
|
211
|
+
*/
|
|
183
212
|
export function withHookVersion<T extends { headers?: unknown }>(
|
|
184
213
|
init: T,
|
|
185
214
|
runtime: string,
|
|
@@ -197,11 +226,16 @@ export function withHookVersion<T extends { headers?: unknown }>(
|
|
|
197
226
|
for (const name of Object.keys(headers)) {
|
|
198
227
|
if (name.toLowerCase() === HOOK_VERSION_HEADER) delete headers[name];
|
|
199
228
|
}
|
|
229
|
+
for (const name of Object.keys(headers)) {
|
|
230
|
+
if (name.toLowerCase() === HOOK_READS_HEADER) delete headers[name];
|
|
231
|
+
}
|
|
200
232
|
headers[HOOK_VERSION_HEADER] = `${runtime}/${version}`;
|
|
233
|
+
headers[HOOK_READS_HEADER] = HOOK_READS.join(',');
|
|
201
234
|
return { ...init, headers };
|
|
202
235
|
}
|
|
203
236
|
const headers = new Headers(raw as ConstructorParameters<typeof Headers>[0]);
|
|
204
237
|
headers.set(HOOK_VERSION_HEADER, `${runtime}/${version}`);
|
|
238
|
+
headers.set(HOOK_READS_HEADER, HOOK_READS.join(','));
|
|
205
239
|
return { ...init, headers: Object.fromEntries(headers.entries()) };
|
|
206
240
|
}
|
|
207
241
|
|