dsh-cross-memory 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +247 -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 +1550 -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 +4475 -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 +112 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +455 -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 +314 -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 +140 -0
- package/lib/test/persona.test.js +73 -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 +227 -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 +43 -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 +233 -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,222 @@
|
|
|
1
|
+
/** Minimal logging seam, satisfied by the plugin's own logger. */
|
|
2
|
+
export interface SyncLog {
|
|
3
|
+
info(message: string, ...args: unknown[]): void;
|
|
4
|
+
warn(message: string, ...args: unknown[]): void;
|
|
5
|
+
decision(message: string, ...args: unknown[]): void;
|
|
6
|
+
}
|
|
7
|
+
/** The two versions of one entry that git could not merge. */
|
|
8
|
+
export interface EntryConflict {
|
|
9
|
+
/** Repository-relative path, e.g. \`entries/<id>.md\`. */
|
|
10
|
+
readonly path: string;
|
|
11
|
+
/** This machine's revision. */
|
|
12
|
+
readonly ours: string;
|
|
13
|
+
/** The incoming revision. */
|
|
14
|
+
readonly theirs: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decide what one conflicting entry should become.
|
|
18
|
+
*
|
|
19
|
+
* Returns the merged entry file (frontmatter and body), or \`undefined\` to fall
|
|
20
|
+
* back to the newer-\`updated\` rule. Throwing is treated the same as returning
|
|
21
|
+
* \`undefined\`: a model that is down must not block the store.
|
|
22
|
+
*/
|
|
23
|
+
export type ConflictResolver = (conflict: EntryConflict) => Promise<string | undefined>;
|
|
24
|
+
/** What one sync run did. */
|
|
25
|
+
export interface SyncOutcome {
|
|
26
|
+
/** Files committed locally by this run. */
|
|
27
|
+
readonly committed: number;
|
|
28
|
+
/** Commits rebased in from the remote. */
|
|
29
|
+
readonly pulled: number;
|
|
30
|
+
/** Whether this run pushed. */
|
|
31
|
+
readonly pushed: boolean;
|
|
32
|
+
/** Entry files that required conflict resolution. */
|
|
33
|
+
readonly conflicts: number;
|
|
34
|
+
/** Conflicts the injected resolver decided. */
|
|
35
|
+
readonly resolvedByResolver: number;
|
|
36
|
+
/** Conflicts the newer-updated rule decided. */
|
|
37
|
+
readonly resolvedByTime: number;
|
|
38
|
+
/** Conflicts a structural merge decided without a model, e.g. the loop ledger. */
|
|
39
|
+
readonly mergedByStructure: number;
|
|
40
|
+
/** Path the rebase gave up on, when it gave up on one. */
|
|
41
|
+
readonly stoppedBy: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Options for {@link MemorySync}. */
|
|
44
|
+
export interface MemorySyncOptions {
|
|
45
|
+
/** The memory store directory; it becomes the git working copy. */
|
|
46
|
+
readonly memoriesDir: string;
|
|
47
|
+
/** Git remote to pull from and push to. Empty keeps the repository local. */
|
|
48
|
+
readonly remote: string;
|
|
49
|
+
/** Background interval in milliseconds; 0 disables the interval timer. */
|
|
50
|
+
readonly intervalMs: number;
|
|
51
|
+
/** Local clock times to sync at ("HH:MM"); takes precedence over `intervalMs`. */
|
|
52
|
+
readonly clock?: readonly string[];
|
|
53
|
+
/** Debounce before a queued write is committed, in milliseconds. */
|
|
54
|
+
readonly debounceMs: number;
|
|
55
|
+
/** Timeout for one non-network git command. */
|
|
56
|
+
readonly gitTimeoutMs: number;
|
|
57
|
+
/** Timeout for a fetch or push. */
|
|
58
|
+
readonly networkTimeoutMs: number;
|
|
59
|
+
/** Logger. */
|
|
60
|
+
readonly log: SyncLog;
|
|
61
|
+
/** Machine name recorded in commit messages. */
|
|
62
|
+
readonly host: string;
|
|
63
|
+
/** Conflict resolver; absent means the timestamp rule decides everything. */
|
|
64
|
+
readonly resolveConflict?: ConflictResolver;
|
|
65
|
+
}
|
|
66
|
+
/** Files that are per-machine state, never content. */
|
|
67
|
+
export declare const STORE_GITIGNORE: string;
|
|
68
|
+
/**
|
|
69
|
+
* Whether a repository-relative path is one memory this module can merge.
|
|
70
|
+
*
|
|
71
|
+
* One memory is one file, in the live tree or in the archive: both carry the same
|
|
72
|
+
* frontmatter, so the same arbitration applies. Persona, session notes and staged
|
|
73
|
+
* skills are prose with a different shape — a conflict there aborts the rebase
|
|
74
|
+
* instead of being guessed at.
|
|
75
|
+
*/
|
|
76
|
+
export declare function isEntryPath(path: string): boolean;
|
|
77
|
+
/** The updated stamp of one entry text, or 0 when it cannot be parsed. */
|
|
78
|
+
export declare function entryStamp(text: string): number;
|
|
79
|
+
/**
|
|
80
|
+
* Resolve one conflicting entry by keeping the newer revision.
|
|
81
|
+
*
|
|
82
|
+
* Exported because it is the documented fallback: a caller that wants the model
|
|
83
|
+
* decision first reads this only when the model declined or failed.
|
|
84
|
+
*/
|
|
85
|
+
export declare function newerEntry(ours: string, theirs: string): {
|
|
86
|
+
text: string;
|
|
87
|
+
oursWon: boolean;
|
|
88
|
+
};
|
|
89
|
+
/** Whether one repository path is a session note: prose, but stamped with `at:`. */
|
|
90
|
+
export declare function isSessionNotePath(path: string): boolean;
|
|
91
|
+
/** The `at` stamp of one session note, or 0 when it cannot be parsed. */
|
|
92
|
+
export declare function sessionNoteStamp(text: string): number;
|
|
93
|
+
/**
|
|
94
|
+
* Resolve one conflicting session note by keeping the later `at:` stamp.
|
|
95
|
+
*
|
|
96
|
+
* A session note is the extractor's prose summary of one session. The same
|
|
97
|
+
* session can be summarised twice — once on each machine, or again after the
|
|
98
|
+
* conversation grew — and then the two notes conflict on every later sync. The
|
|
99
|
+
* `at:` frontmatter says which summary is the later reading, so the newer one
|
|
100
|
+
* wins the way an entry's `updated` stamp does; the older text stays in git.
|
|
101
|
+
*
|
|
102
|
+
* @returns the winning text, or undefined when neither side carries a stamp.
|
|
103
|
+
*/
|
|
104
|
+
/** Whether one repository path is a per-host descriptor: `projects/<slug>/hosts/<host>.json`. */
|
|
105
|
+
export declare function isHostDescriptorPath(path: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Resolve one conflicting host descriptor by keeping the newer reading.
|
|
108
|
+
*
|
|
109
|
+
* A host descriptor is the machine's own note about one project checkout: where
|
|
110
|
+
* it is, when it was seen last, and its git origin. Only the machine named in
|
|
111
|
+
* the file writes it, but every other machine carries a copy — so a rebase
|
|
112
|
+
* between two machines stops here with an older and a newer reading of the same
|
|
113
|
+
* machine. `lastSeen` says which is newer; when both agree, the side that knows
|
|
114
|
+
* the origin wins because a descriptor written before the origin field existed
|
|
115
|
+
* lacks it.
|
|
116
|
+
*
|
|
117
|
+
* @returns the winning text, or undefined when neither side is a descriptor.
|
|
118
|
+
*/
|
|
119
|
+
export declare function newerHostDescriptor(ours: string, theirs: string): string | undefined;
|
|
120
|
+
export declare function newerSessionNote(ours: string, theirs: string): string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Merge two versions of the open-loop ledger.
|
|
123
|
+
*
|
|
124
|
+
* The ledger is one JSON file both machines append to, so it conflicts as soon
|
|
125
|
+
* as either side opens a loop — and unlike an entry it is not one memory with
|
|
126
|
+
* two edits but many independent rows. The merge is therefore a union by id: a
|
|
127
|
+
* loop only one side knows is kept, and a loop both sides changed takes its most
|
|
128
|
+
* final copy. A side whose file was committed with conflict markers contributes
|
|
129
|
+
* the loops from both branches (see {@link ledgersIn}).
|
|
130
|
+
*
|
|
131
|
+
* @param ours - one side of the conflict, as `git show :2:` returned it.
|
|
132
|
+
* @param theirs - the other side, as `git show :3:` returned it.
|
|
133
|
+
* @returns the merged ledger text, or undefined when neither side is a ledger.
|
|
134
|
+
*/
|
|
135
|
+
export declare function mergeLoopLedgers(ours: string, theirs: string): string | undefined;
|
|
136
|
+
/** Parse one "HH:MM" clock entry into minutes past midnight, or undefined. */
|
|
137
|
+
export declare function parseClockTime(value: string): number | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Milliseconds from `now` until the next configured clock time.
|
|
140
|
+
*
|
|
141
|
+
* The schedule is local time, so a machine in another timezone syncs at its own
|
|
142
|
+
* 12:05 — which is the point: off-peak pricing and "when nobody is working" are
|
|
143
|
+
* local facts, not UTC ones.
|
|
144
|
+
*
|
|
145
|
+
* @param clock - "HH:MM" entries; unparsable ones are ignored.
|
|
146
|
+
* @param now - clock.
|
|
147
|
+
* @returns the delay, or undefined when no entry parses.
|
|
148
|
+
*/
|
|
149
|
+
export declare function nextClockDelay(clock: readonly string[], now: number): number | undefined;
|
|
150
|
+
/** The memory store's git transport. */
|
|
151
|
+
export declare class MemorySync {
|
|
152
|
+
private readonly options;
|
|
153
|
+
private readonly dir;
|
|
154
|
+
private timer;
|
|
155
|
+
private debounce;
|
|
156
|
+
private pushing;
|
|
157
|
+
private inflight;
|
|
158
|
+
private lastOutcome;
|
|
159
|
+
constructor(options: MemorySyncOptions);
|
|
160
|
+
/** The outcome of the last completed run, when there was one. */
|
|
161
|
+
get last(): SyncOutcome | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Make the store a git repository and remember the remote.
|
|
164
|
+
*
|
|
165
|
+
* Idempotent: an existing repository is adopted, never reinitialised, and the
|
|
166
|
+
* remote is only added when it is missing. .gitignore is written only when
|
|
167
|
+
* absent so a hand-edited one is not overwritten.
|
|
168
|
+
*/
|
|
169
|
+
init(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Start the background timer.
|
|
172
|
+
*
|
|
173
|
+
* A clock schedule wins over an interval: two fixed local times are what the
|
|
174
|
+
* owner asked for (sync right after off-peak pricing starts, when a conflict
|
|
175
|
+
* merge costs least), while an interval is the fallback for anyone who wants
|
|
176
|
+
* continuous convergence.
|
|
177
|
+
*/
|
|
178
|
+
start(): void;
|
|
179
|
+
/** Arms the next clock run; each run arms the following one. */
|
|
180
|
+
private armClock;
|
|
181
|
+
/** Stop the background timer and any queued commit. */
|
|
182
|
+
stop(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Note that the store changed.
|
|
185
|
+
*
|
|
186
|
+
* Deliberately synchronous and cheap: this runs inside a memory write. The
|
|
187
|
+
* commit and the network happen later, on the debounce timer.
|
|
188
|
+
*/
|
|
189
|
+
queueCommit(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Commit, pull and push once.
|
|
192
|
+
*
|
|
193
|
+
* Concurrent calls share one run: two flushes over one directory would index
|
|
194
|
+
* each other's half-written rebase.
|
|
195
|
+
*
|
|
196
|
+
* @param reason - who asked, for the log.
|
|
197
|
+
* @returns what the run did.
|
|
198
|
+
*/
|
|
199
|
+
run(reason: string): Promise<SyncOutcome>;
|
|
200
|
+
/** The body of one run; see {@link run}. */
|
|
201
|
+
private flush;
|
|
202
|
+
/** Stage and commit everything the store changed. */
|
|
203
|
+
private commit;
|
|
204
|
+
/** Whether a rebase was interrupted and still owns the index and worktree. */
|
|
205
|
+
private rebaseInProgress;
|
|
206
|
+
/** Fetch, then rebase onto the remote branch, resolving entry conflicts. */
|
|
207
|
+
private pull;
|
|
208
|
+
/**
|
|
209
|
+
* Resolve whatever the rebase stopped on, then finish it.
|
|
210
|
+
*
|
|
211
|
+
* Entry files are resolved automatically (the resolver, then the newer
|
|
212
|
+
* `updated` stamp). The loop ledger is a JSON file of independent rows rather
|
|
213
|
+
* than one memory with two edits, so it gets a structural union merge. Anything
|
|
214
|
+
* else aborts the rebase: a store left mid-rebase is far worse than a sync that
|
|
215
|
+
* skipped a cycle.
|
|
216
|
+
*/
|
|
217
|
+
private resolveRebase;
|
|
218
|
+
/** Push the current branch, pulling once and retrying when the remote moved. */
|
|
219
|
+
private push;
|
|
220
|
+
}
|
|
221
|
+
/** The memory id of one entry text, for messages about a conflict. */
|
|
222
|
+
export declare function entryIdOf(text: string): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolving the stretch of time a turn is talking about.
|
|
3
|
+
*
|
|
4
|
+
* The store has always *carried* time — `createdAt` says when a fact was
|
|
5
|
+
* learned, `asOf` says when a `snapshot` reading was measured — but nothing ever
|
|
6
|
+
* *asked* about it. A turn like 「上个月那个发票接口的问题是怎么解决的」 shares
|
|
7
|
+
* 发票/接口 with every invoice memory ever written, so the ranking falls back to
|
|
8
|
+
* importance and recency and hands back the same three entries it hands back for
|
|
9
|
+
* every other invoice question. The date the user actually said, which is the
|
|
10
|
+
* one thing that would cut the list down to the right week, was ignored.
|
|
11
|
+
*
|
|
12
|
+
* This module is the missing half: turn free text into a half-open epoch range,
|
|
13
|
+
* deterministically and without a model call. It is deliberately narrow. It
|
|
14
|
+
* recognises the shapes people really type — 今天/昨天/前天, 上周/上个月/去年,
|
|
15
|
+
* 去年春天, 最近三天, 3 天前, 2026-09-20, 9 月 20 日 — and returns `undefined`
|
|
16
|
+
* for everything else. A false positive is worse than a miss: it silently
|
|
17
|
+
* reorders results for a turn that was not about time at all, and the reader has
|
|
18
|
+
* no way to see why.
|
|
19
|
+
*
|
|
20
|
+
* Two design choices worth keeping:
|
|
21
|
+
*
|
|
22
|
+
* - **Local time.** Windows are computed with the host's local calendar, the
|
|
23
|
+
* same way `peakHours` is, because the user's "昨天" means their wall clock,
|
|
24
|
+
* not UTC. A memory system that answered 今天 with yesterday's date between
|
|
25
|
+
* 00:00 and 08:00 in Shanghai would be worse than one that ignored dates.
|
|
26
|
+
* - **Half-open ranges.** `[start, end)` so an entry measured exactly at
|
|
27
|
+
* midnight belongs to one day, not two.
|
|
28
|
+
*
|
|
29
|
+
* @module dsh-cross-memory/time
|
|
30
|
+
*/
|
|
31
|
+
/** A resolved half-open window `[start, end)` in epoch milliseconds. */
|
|
32
|
+
export interface TimeRange {
|
|
33
|
+
/** Inclusive lower bound. */
|
|
34
|
+
readonly start: number;
|
|
35
|
+
/** Exclusive upper bound. */
|
|
36
|
+
readonly end: number;
|
|
37
|
+
/** The text that produced it, for logs and tests. */
|
|
38
|
+
readonly label: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read a number written as Arabic digits or Chinese numerals.
|
|
42
|
+
*
|
|
43
|
+
* Only the shapes dates use: 3, 三, 十, 十一, 二十, 三十一.
|
|
44
|
+
*
|
|
45
|
+
* @param text - the matched text.
|
|
46
|
+
* @returns the number, or `undefined` when it is neither form.
|
|
47
|
+
*/
|
|
48
|
+
export declare function cnNumber(text: string): number | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The window a turn refers to, or `undefined` when it names no time.
|
|
51
|
+
*
|
|
52
|
+
* Rules are tried most-specific first, so "2026 年 3 月" resolves as a month
|
|
53
|
+
* rather than falling through to the bare "3 月" rule, and "去年春天" resolves
|
|
54
|
+
* as last year's spring rather than this year's.
|
|
55
|
+
*
|
|
56
|
+
* @param text - the raw turn or query.
|
|
57
|
+
* @param now - clock the relative expressions are resolved against.
|
|
58
|
+
* @returns the half-open window, or `undefined` when the text names no time.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseTimeRange(text: string, now?: number): TimeRange | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Whether one instant falls inside a window.
|
|
63
|
+
* @param at - epoch milliseconds, or `undefined` when the entry carries no time.
|
|
64
|
+
* @param range - the window, or `undefined` when the turn named no time.
|
|
65
|
+
* @returns true when `at` is inside `[start, end)`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function within(at: number | undefined, range: TimeRange | undefined): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { MemoriesRuntime } from './index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Register the `memory` tool.
|
|
5
|
+
* @param ctx - context carrying the tool registry.
|
|
6
|
+
* @param runtime - the memory runtime the tool operates on.
|
|
7
|
+
* @returns the exact disposer that unregisters the tool.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerMemoryTool(ctx: Context, runtime: MemoriesRuntime): () => void;
|