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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic retention: which memories no longer earn their place.
|
|
3
|
+
*
|
|
4
|
+
* This is the cheap half of maintenance. It costs no model call, so it can run
|
|
5
|
+
* on a schedule instead of only when new material happens to arrive, and it is
|
|
6
|
+
* the only thing in the plugin that ever retires a memory for being unused.
|
|
7
|
+
*
|
|
8
|
+
* The rule is deliberately one rule: a memory that has not been read, surfaced,
|
|
9
|
+
* or written for `maxUnusedDays` is archived. Archived, not deleted — see
|
|
10
|
+
* `MemoryStore.archive` — because a judgement made without a model's help must
|
|
11
|
+
* be reversible.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-cross-memory/retention
|
|
14
|
+
*/
|
|
15
|
+
import type { MemoryEntry, MemoryScope, RetentionRow } from './types.js';
|
|
16
|
+
/** Everything one retention pass needs. */
|
|
17
|
+
export interface RetentionOptions {
|
|
18
|
+
/** Days an unused memory survives. `0` disables retention entirely. */
|
|
19
|
+
readonly maxUnusedDays: number;
|
|
20
|
+
/**
|
|
21
|
+
* Days a `snapshot` survives regardless of use. `0` or absent disables
|
|
22
|
+
* snapshot expiry, which is how the rule behaved before the field existed.
|
|
23
|
+
*/
|
|
24
|
+
readonly snapshotMaxAgeDays?: number;
|
|
25
|
+
/** Clock, injected for deterministic tests. */
|
|
26
|
+
readonly now: number;
|
|
27
|
+
}
|
|
28
|
+
/** One entry selected for archival. */
|
|
29
|
+
export interface RetentionDecision {
|
|
30
|
+
/** Owning scope. */
|
|
31
|
+
readonly scope: MemoryScope;
|
|
32
|
+
/** Entry id. */
|
|
33
|
+
readonly id: string;
|
|
34
|
+
/** Days since the entry was last read, surfaced, or written. */
|
|
35
|
+
readonly ageDays: number;
|
|
36
|
+
}
|
|
37
|
+
/** Key one entry or usage row the same way, so the two lists can be joined. */
|
|
38
|
+
export declare function retentionKey(scope: string, id: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* The moment an entry last earned attention.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately not `updatedAt` alone: consolidation rewrites entries without
|
|
43
|
+
* anyone using them, and counting that as attention would let a memory be
|
|
44
|
+
* rewritten every sweep and never expire. Reading and being surfaced are the
|
|
45
|
+
* signals that count, and the state database is the authority for both, because
|
|
46
|
+
* a concurrent session may hold a newer counter than the entry file does.
|
|
47
|
+
*
|
|
48
|
+
* @param entry - the entry file's view.
|
|
49
|
+
* @param row - the state database's view, when one exists.
|
|
50
|
+
* @returns Unix epoch milliseconds.
|
|
51
|
+
*/
|
|
52
|
+
export declare function lastAttention(entry: MemoryEntry, row: RetentionRow | undefined): number;
|
|
53
|
+
/**
|
|
54
|
+
* Choose the entries to archive.
|
|
55
|
+
*
|
|
56
|
+
* A `user`-sourced entry is never chosen: somebody typed it, and a schedule is
|
|
57
|
+
* not entitled to overrule a person. Everything else is judged purely by age,
|
|
58
|
+
* so the outcome is explainable — "unused for N days" — rather than a score
|
|
59
|
+
* nobody can reconstruct.
|
|
60
|
+
*
|
|
61
|
+
* @param entries - every entry in one scope.
|
|
62
|
+
* @param rows - usage rows from the state database.
|
|
63
|
+
* @param options - the age limit and the clock.
|
|
64
|
+
* @returns the entries to archive, longest-unused first.
|
|
65
|
+
*/
|
|
66
|
+
export declare function planRetention(entries: readonly MemoryEntry[], rows: readonly RetentionRow[], options: RetentionOptions): RetentionDecision[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timing for the background passes: how long to wait for a session to settle,
|
|
3
|
+
* and which hours the plugin is allowed to spend tokens in.
|
|
4
|
+
*
|
|
5
|
+
* Both exist for the same reason. Stage 1 (extraction) and stage 2
|
|
6
|
+
* (consolidation) are the only parts of this plugin that call a model, so they
|
|
7
|
+
* are the only parts that cost anything, and providers price by time of day:
|
|
8
|
+
* DeepSeek, for one, charges double on weekday mornings and afternoons (Beijing
|
|
9
|
+
* time) and half everywhere else. Deferring those two calls into the cheap
|
|
10
|
+
* window is a straight discount on everything this plugin spends.
|
|
11
|
+
*
|
|
12
|
+
* The window is expressed as the *peak* hours to avoid, not as the hours to run,
|
|
13
|
+
* because that is how providers publish it and how a person reasons about it:
|
|
14
|
+
* "don't spend between 9 and 12". Everything else is implicitly allowed, so
|
|
15
|
+
* weekends need no entry at all.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-cross-memory/schedule
|
|
18
|
+
*/
|
|
19
|
+
/** One parsed peak window: local time, minutes since midnight, wrap allowed. */
|
|
20
|
+
export interface PeakWindow {
|
|
21
|
+
/** Weekdays the window starts on (`Date.getDay()` numbering). */
|
|
22
|
+
readonly days: ReadonlySet<number>;
|
|
23
|
+
/** Start, in minutes since local midnight. */
|
|
24
|
+
readonly from: number;
|
|
25
|
+
/** End, in minutes since local midnight; `1440` means midnight tonight. */
|
|
26
|
+
readonly to: number;
|
|
27
|
+
}
|
|
28
|
+
/** The result of parsing one `peakHours` spec. */
|
|
29
|
+
export interface PeakSpec {
|
|
30
|
+
/** The windows that parsed. */
|
|
31
|
+
readonly windows: readonly PeakWindow[];
|
|
32
|
+
/** Entries that did not parse, verbatim, so a typo can be reported. */
|
|
33
|
+
readonly invalid: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse a `peakHours` spec.
|
|
37
|
+
*
|
|
38
|
+
* Grammar, all optional and local time:
|
|
39
|
+
*
|
|
40
|
+
* ```text
|
|
41
|
+
* <days> <HH:MM>-<HH:MM> Mon-Fri 09:00-12:00
|
|
42
|
+
* <HH:MM>-<HH:MM> every day
|
|
43
|
+
* <a>+<b> <HH:MM>-<HH:MM> Mon+Wed+Fri 14:00-18:00
|
|
44
|
+
* `*` for days * 09:00-12:00
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Entries are separated by `,` or `;`. A window whose end is not after its start
|
|
48
|
+
* crosses midnight (`Sat 22:00-02:00`). An empty spec means "never peak".
|
|
49
|
+
*
|
|
50
|
+
* @param spec - the configured spec.
|
|
51
|
+
* @returns the windows that parsed, plus any entries that did not.
|
|
52
|
+
*/
|
|
53
|
+
export declare function parsePeakHours(spec: string): PeakSpec;
|
|
54
|
+
/**
|
|
55
|
+
* Whether a moment falls inside a window.
|
|
56
|
+
*
|
|
57
|
+
* A window that crosses midnight is matched on the day it *starts*: `Sat
|
|
58
|
+
* 22:00-02:00` covers Saturday night and Sunday's small hours, because that is
|
|
59
|
+
* what somebody writing it means.
|
|
60
|
+
*
|
|
61
|
+
* @param window - the parsed window.
|
|
62
|
+
* @param now - the moment to test.
|
|
63
|
+
* @returns true when the moment is inside.
|
|
64
|
+
*/
|
|
65
|
+
export declare function withinWindow(window: PeakWindow, now: Date): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Milliseconds until the current peak window ends, or `0` when not in one.
|
|
68
|
+
*
|
|
69
|
+
* The delay is floored one second past the boundary: firing exactly on it would
|
|
70
|
+
* re-enter the same check and defer again.
|
|
71
|
+
*
|
|
72
|
+
* @param spec - the configured `peakHours` spec.
|
|
73
|
+
* @param now - the moment to measure from.
|
|
74
|
+
* @returns milliseconds to wait, or 0 when spending is allowed right now.
|
|
75
|
+
*/
|
|
76
|
+
export declare function peakDelayMs(spec: string, now?: Date): number;
|
|
77
|
+
/**
|
|
78
|
+
* How long to wait after a session settles before mining it.
|
|
79
|
+
*
|
|
80
|
+
* The delay is the *larger* of the two configured waits, and that is the whole
|
|
81
|
+
* point: scheduling for the idle delay alone produced a pass that always failed
|
|
82
|
+
* the quiet-window gate. The timer fires once and is never re-armed, so a 5
|
|
83
|
+
* minute timer guarding a 6 hour window meant stage 1 never ran at all — the
|
|
84
|
+
* plugin's own store showed dozens of tracked sessions and not one watermark.
|
|
85
|
+
*
|
|
86
|
+
* @param settings - the tunables in force.
|
|
87
|
+
* @returns milliseconds to wait after the session settles.
|
|
88
|
+
*/
|
|
89
|
+
export declare function extractionDelayMs(settings: {
|
|
90
|
+
autoExtractIdleMs: number;
|
|
91
|
+
minIdleHours: number;
|
|
92
|
+
}): number;
|
|
93
|
+
/**
|
|
94
|
+
* How long to wait before the next pass, counting both gates.
|
|
95
|
+
*
|
|
96
|
+
* @param settings - the tunables in force.
|
|
97
|
+
* @param now - the moment to measure from.
|
|
98
|
+
* @returns milliseconds to wait.
|
|
99
|
+
*/
|
|
100
|
+
export declare function backgroundDelayMs(settings: {
|
|
101
|
+
autoExtractIdleMs: number;
|
|
102
|
+
minIdleHours: number;
|
|
103
|
+
peakHours: string;
|
|
104
|
+
}, now?: Date): number;
|
|
105
|
+
/** Render a delay as `45s`, `5m`, or `6h30m`, for one diagnostic line. */
|
|
106
|
+
export declare function formatDelay(ms: number): string;
|
|
107
|
+
/**
|
|
108
|
+
* How long to wait before retrying a window whose reply hit the output cap.
|
|
109
|
+
*
|
|
110
|
+
* @param hits - consecutive capped replies for this session, counting this one.
|
|
111
|
+
* @param intervalMs - the configured pass interval. The wait is never shorter
|
|
112
|
+
* than it, so the ladder's first rung cannot undercut a slower cadence the
|
|
113
|
+
* user chose deliberately; `0` (periodic checks off) leaves the ladder alone.
|
|
114
|
+
* @returns milliseconds to wait before the next attempt.
|
|
115
|
+
*/
|
|
116
|
+
export declare function cappedBackoffMs(hits: number, intervalMs: number): number;
|