humemory 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/.githooks/post-commit +22 -0
- package/AGENTS.md +328 -0
- package/CHANGELOG.md +198 -0
- package/LICENSE +21 -0
- package/README.md +488 -0
- package/bin/humemory.js +19 -0
- package/dist/agent/claude-hook.d.ts +15 -0
- package/dist/agent/claude-hook.js +38 -0
- package/dist/agent/commit-closer.d.ts +60 -0
- package/dist/agent/commit-closer.js +125 -0
- package/dist/agent/learning-extractor.d.ts +10 -0
- package/dist/agent/learning-extractor.js +75 -0
- package/dist/agent/session-context.d.ts +63 -0
- package/dist/agent/session-context.js +216 -0
- package/dist/agent/session-parser.d.ts +12 -0
- package/dist/agent/session-parser.js +85 -0
- package/dist/api/dream-routes.d.ts +7 -0
- package/dist/api/dream-routes.js +40 -0
- package/dist/api/intentions-routes.d.ts +23 -0
- package/dist/api/intentions-routes.js +252 -0
- package/dist/api/memory-routes.d.ts +10 -0
- package/dist/api/memory-routes.js +277 -0
- package/dist/api/scripts-routes.d.ts +13 -0
- package/dist/api/scripts-routes.js +129 -0
- package/dist/api/server.d.ts +33 -0
- package/dist/api/server.js +157 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +798 -0
- package/dist/core/clock.d.ts +38 -0
- package/dist/core/clock.js +52 -0
- package/dist/core/cue-arg.d.ts +19 -0
- package/dist/core/cue-arg.js +72 -0
- package/dist/core/cues.d.ts +138 -0
- package/dist/core/cues.js +372 -0
- package/dist/core/decay.d.ts +49 -0
- package/dist/core/decay.js +157 -0
- package/dist/core/dreamer.d.ts +114 -0
- package/dist/core/dreamer.js +427 -0
- package/dist/core/embeddings.d.ts +79 -0
- package/dist/core/embeddings.js +133 -0
- package/dist/core/event-bus.d.ts +71 -0
- package/dist/core/event-bus.js +67 -0
- package/dist/core/hybrid.d.ts +33 -0
- package/dist/core/hybrid.js +63 -0
- package/dist/core/llm-generator.d.ts +18 -0
- package/dist/core/llm-generator.js +69 -0
- package/dist/core/sanitize.d.ts +57 -0
- package/dist/core/sanitize.js +87 -0
- package/dist/core/scripts.d.ts +55 -0
- package/dist/core/scripts.js +96 -0
- package/dist/core/search.d.ts +42 -0
- package/dist/core/search.js +173 -0
- package/dist/core/trust.d.ts +48 -0
- package/dist/core/trust.js +57 -0
- package/dist/core/types.d.ts +333 -0
- package/dist/core/types.js +1 -0
- package/dist/core/vector-clusterer.d.ts +53 -0
- package/dist/core/vector-clusterer.js +113 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +18 -0
- package/dist/mcp/server.d.ts +22 -0
- package/dist/mcp/server.js +158 -0
- package/dist/store/sqlite.d.ts +240 -0
- package/dist/store/sqlite.js +1653 -0
- package/docs/TESTING.md +244 -0
- package/package.json +95 -0
- package/public/app/galaxy-f42190mq.js +10 -0
- package/public/app/index-2cf31xxn.css +1 -0
- package/public/app/index-epqg22cp.js +1 -0
- package/public/app/index-f9h80bzq.js +12 -0
- package/public/app/index-gbfwa9vq.js +2 -0
- package/public/app/index-kvhc17mz.js +2 -0
- package/public/app/index-pbd5t4dj.js +2 -0
- package/public/app/index.html +12 -0
- package/public/app/promenade-cnzzpm73.js +4111 -0
- package/public/app/river-tyawhh8w.js +13 -0
- package/public/session.html +659 -0
- package/scripts/consolidate.js +46 -0
- package/scripts/hook-post-commit.ts +80 -0
- package/scripts/hook-session-start.ts +92 -0
- package/scripts/hook-session.ts +60 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clock seam — lets tests drive time.
|
|
3
|
+
*
|
|
4
|
+
* humemory is time-driven: all decay (L0→L4) depends on the gap between
|
|
5
|
+
* `createdAt`/`lastRecalled` and "now". As long as that "now" is a `new Date()`
|
|
6
|
+
* buried in the store, a level transition can only be tested by actually waiting
|
|
7
|
+
* 24 hours. This module extracts the seam: production injects `systemClock`,
|
|
8
|
+
* tests inject a `FakeClock` they advance by hand.
|
|
9
|
+
*
|
|
10
|
+
* See docs/TESTING.md → pillar 2.
|
|
11
|
+
*/
|
|
12
|
+
export interface Clock {
|
|
13
|
+
now(): Date;
|
|
14
|
+
}
|
|
15
|
+
/** Production clock — reads the system time. */
|
|
16
|
+
export declare const systemClock: Clock;
|
|
17
|
+
/**
|
|
18
|
+
* Test clock — only moves when `advance()`/`set()` is called.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const clock = new FakeClock(new Date('2026-01-01T00:00:00Z'));
|
|
22
|
+
* const store = new SQLiteStore(':memory:', { clock });
|
|
23
|
+
* clock.advance(25 * 3600_000); // +25h, L0 → L1
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class FakeClock implements Clock {
|
|
27
|
+
private t;
|
|
28
|
+
constructor(start?: Date | string | number);
|
|
29
|
+
now(): Date;
|
|
30
|
+
/** Advances by `ms` milliseconds. */
|
|
31
|
+
advance(ms: number): this;
|
|
32
|
+
/** Advances by `h` hours — decay thresholds are expressed in hours. */
|
|
33
|
+
advanceHours(h: number): this;
|
|
34
|
+
/** Advances by `d` days. */
|
|
35
|
+
advanceDays(d: number): this;
|
|
36
|
+
/** Moves the clock to an absolute date. */
|
|
37
|
+
set(t: Date | string | number): this;
|
|
38
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clock seam — lets tests drive time.
|
|
3
|
+
*
|
|
4
|
+
* humemory is time-driven: all decay (L0→L4) depends on the gap between
|
|
5
|
+
* `createdAt`/`lastRecalled` and "now". As long as that "now" is a `new Date()`
|
|
6
|
+
* buried in the store, a level transition can only be tested by actually waiting
|
|
7
|
+
* 24 hours. This module extracts the seam: production injects `systemClock`,
|
|
8
|
+
* tests inject a `FakeClock` they advance by hand.
|
|
9
|
+
*
|
|
10
|
+
* See docs/TESTING.md → pillar 2.
|
|
11
|
+
*/
|
|
12
|
+
/** Production clock — reads the system time. */
|
|
13
|
+
export const systemClock = {
|
|
14
|
+
now: () => new Date(),
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Test clock — only moves when `advance()`/`set()` is called.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const clock = new FakeClock(new Date('2026-01-01T00:00:00Z'));
|
|
21
|
+
* const store = new SQLiteStore(':memory:', { clock });
|
|
22
|
+
* clock.advance(25 * 3600_000); // +25h, L0 → L1
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class FakeClock {
|
|
26
|
+
t;
|
|
27
|
+
constructor(start = new Date('2026-01-01T00:00:00.000Z')) {
|
|
28
|
+
this.t = new Date(start);
|
|
29
|
+
}
|
|
30
|
+
now() {
|
|
31
|
+
// Defensive copy: a caller mutating the result must not shift the clock.
|
|
32
|
+
return new Date(this.t.getTime());
|
|
33
|
+
}
|
|
34
|
+
/** Advances by `ms` milliseconds. */
|
|
35
|
+
advance(ms) {
|
|
36
|
+
this.t = new Date(this.t.getTime() + ms);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/** Advances by `h` hours — decay thresholds are expressed in hours. */
|
|
40
|
+
advanceHours(h) {
|
|
41
|
+
return this.advance(h * 3600_000);
|
|
42
|
+
}
|
|
43
|
+
/** Advances by `d` days. */
|
|
44
|
+
advanceDays(d) {
|
|
45
|
+
return this.advance(d * 24 * 3600_000);
|
|
46
|
+
}
|
|
47
|
+
/** Moves the clock to an absolute date. */
|
|
48
|
+
set(t) {
|
|
49
|
+
this.t = new Date(t);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsing of `--cue` command-line arguments.
|
|
3
|
+
*
|
|
4
|
+
* Accepted formats:
|
|
5
|
+
* time:2026-12-01 — one-shot deadline (ISO date or datetime)
|
|
6
|
+
* cron:0 9 * * 1 — recurrence
|
|
7
|
+
* event:file_open:src/auth/service.ts — file opened
|
|
8
|
+
* event:branch_switch:feature/x — branch changed
|
|
9
|
+
* event:error_pattern:SQLITE_(BUSY) — error pattern (may contain ':')
|
|
10
|
+
*
|
|
11
|
+
* It lives in core/ rather than cli/: the same format is typed on the command
|
|
12
|
+
* line and in the front-end form. One parser, tested once.
|
|
13
|
+
*/
|
|
14
|
+
import type { TriggerSpec } from '../core/types.js';
|
|
15
|
+
export declare class CueArgError extends Error {
|
|
16
|
+
}
|
|
17
|
+
export declare function parseCueArg(raw: string): TriggerSpec;
|
|
18
|
+
/** Renders a cue in its CLI form — the inverse of `parseCueArg`, for display. */
|
|
19
|
+
export declare function formatTriggerSpec(spec: TriggerSpec): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsing of `--cue` command-line arguments.
|
|
3
|
+
*
|
|
4
|
+
* Accepted formats:
|
|
5
|
+
* time:2026-12-01 — one-shot deadline (ISO date or datetime)
|
|
6
|
+
* cron:0 9 * * 1 — recurrence
|
|
7
|
+
* event:file_open:src/auth/service.ts — file opened
|
|
8
|
+
* event:branch_switch:feature/x — branch changed
|
|
9
|
+
* event:error_pattern:SQLITE_(BUSY) — error pattern (may contain ':')
|
|
10
|
+
*
|
|
11
|
+
* It lives in core/ rather than cli/: the same format is typed on the command
|
|
12
|
+
* line and in the front-end form. One parser, tested once.
|
|
13
|
+
*/
|
|
14
|
+
export class CueArgError extends Error {
|
|
15
|
+
}
|
|
16
|
+
const EVENT_TYPES = ['file_open', 'branch_switch', 'error_pattern'];
|
|
17
|
+
export function parseCueArg(raw) {
|
|
18
|
+
const input = raw.trim();
|
|
19
|
+
if (!input)
|
|
20
|
+
throw new CueArgError('empty cue');
|
|
21
|
+
const [head, ...rest] = input.split(':');
|
|
22
|
+
const tail = rest.join(':'); // error patterns and ISO times contain ':'
|
|
23
|
+
switch (head) {
|
|
24
|
+
case 'time': {
|
|
25
|
+
if (!tail)
|
|
26
|
+
throw new CueArgError('time: expects an ISO date — e.g. time:2026-12-01');
|
|
27
|
+
const date = new Date(tail);
|
|
28
|
+
if (Number.isNaN(date.getTime()))
|
|
29
|
+
throw new CueArgError(`invalid date: ${tail}`);
|
|
30
|
+
return { kind: 'time', at: date.toISOString() };
|
|
31
|
+
}
|
|
32
|
+
case 'cron': {
|
|
33
|
+
if (!tail.trim())
|
|
34
|
+
throw new CueArgError('cron: expects an expression — e.g. "cron:0 9 * * 1"');
|
|
35
|
+
return { kind: 'time', cron: tail.trim() };
|
|
36
|
+
}
|
|
37
|
+
case 'event': {
|
|
38
|
+
const sep = tail.indexOf(':');
|
|
39
|
+
const type = sep === -1 ? tail : tail.slice(0, sep);
|
|
40
|
+
const value = sep === -1 ? '' : tail.slice(sep + 1);
|
|
41
|
+
if (!EVENT_TYPES.includes(type)) {
|
|
42
|
+
throw new CueArgError(`unknown event type: "${type}" (${EVENT_TYPES.join(' | ')})`);
|
|
43
|
+
}
|
|
44
|
+
if (!value)
|
|
45
|
+
throw new CueArgError(`event:${type}: expects a value`);
|
|
46
|
+
switch (type) {
|
|
47
|
+
case 'file_open':
|
|
48
|
+
return { kind: 'event', type: 'file_open', path: value };
|
|
49
|
+
case 'branch_switch':
|
|
50
|
+
return { kind: 'event', type: 'branch_switch', branch: value };
|
|
51
|
+
default:
|
|
52
|
+
return { kind: 'event', type: 'error_pattern', pattern: value };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
throw new CueArgError(`unknown prefix: "${head}" (time | cron | event)`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Renders a cue in its CLI form — the inverse of `parseCueArg`, for display. */
|
|
60
|
+
export function formatTriggerSpec(spec) {
|
|
61
|
+
if (spec.kind === 'time') {
|
|
62
|
+
return spec.cron ? `cron:${spec.cron}` : `time:${spec.at}`;
|
|
63
|
+
}
|
|
64
|
+
switch (spec.type) {
|
|
65
|
+
case 'file_open':
|
|
66
|
+
return `event:file_open:${spec.path}`;
|
|
67
|
+
case 'branch_switch':
|
|
68
|
+
return `event:branch_switch:${spec.branch}`;
|
|
69
|
+
default:
|
|
70
|
+
return `event:error_pattern:${spec.pattern}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cue resolver — Phase 5.2.
|
|
3
|
+
*
|
|
4
|
+
* You do not search for an intention: it comes back. This module decides *when*.
|
|
5
|
+
* It reads the armed cues and answers two questions, one temporal
|
|
6
|
+
* (`resolveTimeCues`), one event-driven (`resolveEventCues`); then `fire()` marks
|
|
7
|
+
* both cue and intention as surfaced to the agent.
|
|
8
|
+
*
|
|
9
|
+
* The data layer (tables, CRUD) is Phase 5.1, in `src/store/sqlite.ts`; there is
|
|
10
|
+
* nothing but decisions here. See PHASE5_PLAN.md § 5.2.
|
|
11
|
+
*/
|
|
12
|
+
import type { Cue, Intention, IntentionStore, Script, ScriptStore, EventTriggerSpec } from './types.js';
|
|
13
|
+
import type { AppEvent, EventBus, Unsubscribe } from './event-bus.js';
|
|
14
|
+
import { type Clock } from './clock.js';
|
|
15
|
+
export interface CueResolver {
|
|
16
|
+
/** Time cues due at `now` (not yet fired, or recurring and due again). */
|
|
17
|
+
resolveTimeCues(now?: Date): Promise<Cue[]>;
|
|
18
|
+
/** Event cues matching this event. */
|
|
19
|
+
resolveEventCues(event: AppEvent): Promise<Cue[]>;
|
|
20
|
+
/** Marks cue and intention as fired. Returns the woken intention. */
|
|
21
|
+
fire(cueId: string): Promise<Intention>;
|
|
22
|
+
/** Phase 8.1 — fires a script cue: the drill is surfaced, saillance bumped. */
|
|
23
|
+
fireScript(cueId: string): Promise<Script>;
|
|
24
|
+
/** Dispatches by target kind (8.1) — what bus wiring should call. */
|
|
25
|
+
fireAny(cueId: string): Promise<{
|
|
26
|
+
kind: 'intention';
|
|
27
|
+
intention: Intention;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'script';
|
|
30
|
+
script: Script;
|
|
31
|
+
}>;
|
|
32
|
+
/** Expires intentions past their deadline. Returns how many. */
|
|
33
|
+
expireStale(now?: Date): Promise<number>;
|
|
34
|
+
}
|
|
35
|
+
interface ParsedCron {
|
|
36
|
+
minute: Set<number>;
|
|
37
|
+
hour: Set<number>;
|
|
38
|
+
dom: Set<number>;
|
|
39
|
+
month: Set<number>;
|
|
40
|
+
dow: Set<number>;
|
|
41
|
+
domRestricted: boolean;
|
|
42
|
+
dowRestricted: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Parses a 5-field cron expression. Returns null when it is invalid. */
|
|
45
|
+
export declare function parseCron(expr: string): ParsedCron | null;
|
|
46
|
+
/**
|
|
47
|
+
* True when `date` (to the minute, in UTC) lands on a cron occurrence.
|
|
48
|
+
*
|
|
49
|
+
* When day-of-month and day-of-week are both restricted, standard cron combines
|
|
50
|
+
* them with OR, not AND — `0 9 1 * 1` means "the 1st of the month **or** on a
|
|
51
|
+
* Monday". That semantics is kept so nothing surprises anyone.
|
|
52
|
+
*/
|
|
53
|
+
export declare function cronMatches(parsed: ParsedCron, date: Date): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Cron catch-up window, in minutes (7 days).
|
|
56
|
+
*
|
|
57
|
+
* The resolver is not a daemon: it runs at SessionStart, so only now and then.
|
|
58
|
+
* Without catch-up, an occurrence falling between two sessions would be lost. So
|
|
59
|
+
* time is walked backwards minute by minute from `now` to the last known
|
|
60
|
+
* reference, capped by this window — beyond it, an occurrence is considered too
|
|
61
|
+
* old to be worth a wake-up.
|
|
62
|
+
*/
|
|
63
|
+
export declare const CRON_CATCHUP_MINUTES: number;
|
|
64
|
+
/** True when a cron occurrence exists in the half-open interval (since, now]. */
|
|
65
|
+
export declare function cronDueSince(expr: string, since: Date, now: Date): boolean;
|
|
66
|
+
/** True when this event trigger matches this event. */
|
|
67
|
+
export declare function eventTriggerMatches(spec: EventTriggerSpec, event: AppEvent): boolean;
|
|
68
|
+
/** Length of the UUID prefix used as a readable loop identifier. */
|
|
69
|
+
export declare const LOOP_ID_LENGTH = 8;
|
|
70
|
+
/**
|
|
71
|
+
* Short identifier shown to the agent: `loop-a1b2c3d4`. This is what a human
|
|
72
|
+
* retypes into a commit message (`Closes loop-a1b2c3d4`) — a full UUID would
|
|
73
|
+
* never be retyped by hand.
|
|
74
|
+
*/
|
|
75
|
+
export declare function loopId(intentionId: string): string;
|
|
76
|
+
/** Extracts short loop ids mentioned in a text (a commit message). */
|
|
77
|
+
export declare function extractLoopIds(text: string): string[];
|
|
78
|
+
/** Finds the intention a short id points to, when it is unambiguous. */
|
|
79
|
+
export declare function matchIntentionByShortId(intentions: Intention[], shortId: string): Intention | null;
|
|
80
|
+
/** Salience decline of a fired intention, in points per day (the Zeigarnik pull fading). */
|
|
81
|
+
export declare const INTENTION_FADE_PER_DAY = 10;
|
|
82
|
+
/**
|
|
83
|
+
* Current salience of an intention (PHASE5_PLAN.md § 5.2):
|
|
84
|
+
* - `armed` → pinned at 100: an open loop stays salient, it does not decay
|
|
85
|
+
* - `fired` and not `closed` → declines from `firedAt`: the Zeigarnik pull fades
|
|
86
|
+
* - `closed` → 0: archived, kept for history
|
|
87
|
+
* - `expired` → 0: soft-deleted
|
|
88
|
+
*/
|
|
89
|
+
export declare function intentionSaillance(intention: Intention, now: Date): number;
|
|
90
|
+
export interface CueResolverOptions {
|
|
91
|
+
clock?: Clock;
|
|
92
|
+
}
|
|
93
|
+
export declare class SqliteCueResolver implements CueResolver {
|
|
94
|
+
private store;
|
|
95
|
+
private clock;
|
|
96
|
+
constructor(store: IntentionStore & Partial<ScriptStore>, options?: CueResolverOptions);
|
|
97
|
+
/**
|
|
98
|
+
* A cue only wakes while its target is live: an intention still `armed`, a
|
|
99
|
+
* script still `active` (8.1 — drafts never fire). Returns the target's
|
|
100
|
+
* directory for mental-place filtering, or null when the target is dead.
|
|
101
|
+
*/
|
|
102
|
+
private liveTargetDirectoryOf;
|
|
103
|
+
resolveTimeCues(now?: Date): Promise<Cue[]>;
|
|
104
|
+
resolveEventCues(event: AppEvent): Promise<Cue[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Marks cue and intention as fired. A cron cue is re-armed after firing: a
|
|
107
|
+
* recurrence that does not re-arm is a one-shot in disguise.
|
|
108
|
+
*/
|
|
109
|
+
fire(cueId: string): Promise<Intention>;
|
|
110
|
+
/** Script counterpart of fire(): same cue bookkeeping, script bumped (8.1). */
|
|
111
|
+
fireScript(cueId: string): Promise<Script>;
|
|
112
|
+
fireAny(cueId: string): Promise<{
|
|
113
|
+
kind: 'intention';
|
|
114
|
+
intention: Intention;
|
|
115
|
+
} | {
|
|
116
|
+
kind: 'script';
|
|
117
|
+
script: Script;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Expires `armed` intentions whose `expiresAt` has passed and cancels their
|
|
121
|
+
* cues — a cue outliving its intention is a ghost wake-up.
|
|
122
|
+
*/
|
|
123
|
+
expireStale(now?: Date): Promise<number>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Wires a resolver onto an event bus: every published event wakes the cues that
|
|
127
|
+
* match. Returns the unsubscribe handle.
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* const detach = attachResolverToBus(bus, resolver);
|
|
131
|
+
* await bus.publish({ type: 'branch_switch', branch: 'feature/x', directory: '/src' });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function attachResolverToBus(bus: EventBus, resolver: CueResolver, options?: {
|
|
135
|
+
onFired?: (intention: Intention, cue: Cue) => void | Promise<void>;
|
|
136
|
+
onScriptFired?: (script: Script, cue: Cue) => void | Promise<void>;
|
|
137
|
+
}): Unsubscribe;
|
|
138
|
+
export {};
|