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,122 @@
|
|
|
1
|
+
import type { LlmRuntime } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
3
|
+
import type { MemoryEntry } from './types.js';
|
|
4
|
+
/** Directory inside the memory store. */
|
|
5
|
+
export declare const REFLECTION_DIR = "reflections";
|
|
6
|
+
/** How often the pass may run. */
|
|
7
|
+
export declare const REFLECTION_INTERVAL_MS: number;
|
|
8
|
+
/** Recent entries required before a reflection is worth attempting. */
|
|
9
|
+
export declare const REFLECTION_MIN_ENTRIES = 20;
|
|
10
|
+
/** How many entries one pass reads. */
|
|
11
|
+
export declare const REFLECTION_MAX_ENTRIES = 80;
|
|
12
|
+
/** One synthesized observation, with the memories behind it. */
|
|
13
|
+
export interface ReflectionInsight {
|
|
14
|
+
/** One or two sentences, in the user's language. */
|
|
15
|
+
readonly text: string;
|
|
16
|
+
/** Ids the insight is derived from; never empty. */
|
|
17
|
+
readonly evidence: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/** The instruction. Its job is to refuse restatement. */
|
|
20
|
+
export declare const REFLECTION_SYSTEM: string;
|
|
21
|
+
/** Output contract. */
|
|
22
|
+
export declare const REFLECTION_JSON_SCHEMA: {
|
|
23
|
+
readonly type: 'object';
|
|
24
|
+
readonly additionalProperties: false;
|
|
25
|
+
readonly required: readonly ['insights'];
|
|
26
|
+
readonly properties: {
|
|
27
|
+
readonly insights: {
|
|
28
|
+
readonly type: 'array';
|
|
29
|
+
readonly items: {
|
|
30
|
+
readonly type: 'object';
|
|
31
|
+
readonly additionalProperties: false;
|
|
32
|
+
readonly required: readonly ['text', 'evidence'];
|
|
33
|
+
readonly properties: {
|
|
34
|
+
readonly text: {
|
|
35
|
+
readonly type: 'string';
|
|
36
|
+
};
|
|
37
|
+
readonly evidence: {
|
|
38
|
+
readonly type: 'array';
|
|
39
|
+
readonly items: {
|
|
40
|
+
readonly type: 'string';
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Whether a pass is due.
|
|
50
|
+
*
|
|
51
|
+
* @param lastAt - when the last reflection was written (0 when never).
|
|
52
|
+
* @param now - clock.
|
|
53
|
+
* @param entries - how many recent memories exist.
|
|
54
|
+
* @returns whether to run.
|
|
55
|
+
*/
|
|
56
|
+
export declare function reflectionDue(lastAt: number, now: number, entries: number): boolean;
|
|
57
|
+
/** Render the input document, listing only what the model may cite. */
|
|
58
|
+
export declare function renderReflectionInput(entries: readonly MemoryEntry[], persona?: string, previous?: readonly string[]): string;
|
|
59
|
+
/**
|
|
60
|
+
* Parse a reflection reply, dropping any insight whose evidence the store cannot show.
|
|
61
|
+
*
|
|
62
|
+
* @param text - the raw reply.
|
|
63
|
+
* @param knownIds - ids present in the material the model was shown.
|
|
64
|
+
* @returns the validated insights, possibly none.
|
|
65
|
+
*/
|
|
66
|
+
export declare function parseReflection(text: string, knownIds: ReadonlySet<string>): ReflectionInsight[];
|
|
67
|
+
/**
|
|
68
|
+
* Count what a reply contained, before validation dropped it.
|
|
69
|
+
*
|
|
70
|
+
* @param text - the raw reply.
|
|
71
|
+
* @param knownIds - ids the model was shown.
|
|
72
|
+
* @returns raw and evidence-bearing counts, or `undefined` when the reply is not JSON.
|
|
73
|
+
*/
|
|
74
|
+
export declare function replyStats(text: string, knownIds: ReadonlySet<string>): {
|
|
75
|
+
raw: number;
|
|
76
|
+
cited: number;
|
|
77
|
+
} | undefined;
|
|
78
|
+
/** Everything one reflection call needs. */
|
|
79
|
+
export interface ReflectionRequest {
|
|
80
|
+
readonly llm: LlmRuntime | undefined;
|
|
81
|
+
readonly session: Session | undefined;
|
|
82
|
+
readonly entries: readonly MemoryEntry[];
|
|
83
|
+
readonly persona?: string;
|
|
84
|
+
readonly previous?: readonly string[];
|
|
85
|
+
readonly provider?: string;
|
|
86
|
+
readonly model?: string;
|
|
87
|
+
readonly timeoutMs: number;
|
|
88
|
+
readonly signal: AbortSignal;
|
|
89
|
+
}
|
|
90
|
+
/** What one pass produced. */
|
|
91
|
+
export interface ReflectionOutcome {
|
|
92
|
+
readonly insights: readonly ReflectionInsight[];
|
|
93
|
+
readonly reason: string;
|
|
94
|
+
readonly skipped?: 'no-llm' | 'no-route' | 'empty' | 'failed';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Run one reflection call.
|
|
98
|
+
*
|
|
99
|
+
* @param request - material, route, budget.
|
|
100
|
+
* @returns the validated insights, or why there are none.
|
|
101
|
+
*/
|
|
102
|
+
export declare function runReflection(request: ReflectionRequest): Promise<ReflectionOutcome>;
|
|
103
|
+
/** Render one reflection as the markdown written to disk. */
|
|
104
|
+
export declare function renderReflectionFile(insights: readonly ReflectionInsight[], now: number): string;
|
|
105
|
+
/**
|
|
106
|
+
* Write one reflection file, one per day at most.
|
|
107
|
+
*
|
|
108
|
+
* @param memoriesDir - the store root.
|
|
109
|
+
* @param insights - validated observations.
|
|
110
|
+
* @param now - clock.
|
|
111
|
+
* @returns the absolute path written.
|
|
112
|
+
*/
|
|
113
|
+
export declare function writeReflection(memoriesDir: string, insights: readonly ReflectionInsight[], now: number): Promise<string>;
|
|
114
|
+
/** List the reflection files, newest first. */
|
|
115
|
+
export declare function listReflections(memoriesDir: string): Promise<{
|
|
116
|
+
name: string;
|
|
117
|
+
body: string;
|
|
118
|
+
}[]>;
|
|
119
|
+
/** The one-line observations already written, for the "do not repeat" list. */
|
|
120
|
+
export declare function previousInsights(files: readonly {
|
|
121
|
+
body: string;
|
|
122
|
+
}[]): string[];
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { MemoryStore } from './storage.js';
|
|
2
|
+
/** npm package owning the Remote methods. */
|
|
3
|
+
export declare const REMOTE_PACKAGE = "dsh-cross-memory";
|
|
4
|
+
/** Cordis service key the gateway resolves the receiver through. */
|
|
5
|
+
export declare const REMOTE_SERVICE = "memories";
|
|
6
|
+
/** Wire namespace; the browser sees it as `ctx.remote.memories`. */
|
|
7
|
+
export declare const REMOTE_NAMESPACE = "memories";
|
|
8
|
+
/** Every value that crosses the wire is one of these named shapes. */
|
|
9
|
+
export type WireShape =
|
|
10
|
+
/** A free-text parameter. */
|
|
11
|
+
'text'
|
|
12
|
+
/** A numeric parameter. */
|
|
13
|
+
| 'number'
|
|
14
|
+
/** A boolean flag parameter. */
|
|
15
|
+
| 'flag'
|
|
16
|
+
/** The persona profile plus whether it is locked against automatic rewrites. */
|
|
17
|
+
| 'persona'
|
|
18
|
+
/** Store home, per-project counts, staged skill drafts. */
|
|
19
|
+
| 'overview'
|
|
20
|
+
/** A ranked entry page plus the total before paging. */
|
|
21
|
+
| 'entries'
|
|
22
|
+
/** One stored entry. */
|
|
23
|
+
| 'entry'
|
|
24
|
+
/** Whether a delete removed a file. */
|
|
25
|
+
| 'removed'
|
|
26
|
+
/** One promoted skill and where it landed. */
|
|
27
|
+
| 'skill'
|
|
28
|
+
/** Whether a staged draft was discarded. */
|
|
29
|
+
| 'discard'
|
|
30
|
+
/** The consolidation decisions waiting for a person. */
|
|
31
|
+
| 'disputes';
|
|
32
|
+
/** One ordered business parameter, as pure data. */
|
|
33
|
+
export interface WireParameter {
|
|
34
|
+
/** Source-level parameter name. */
|
|
35
|
+
readonly name: string;
|
|
36
|
+
/** Required key in the wire `args` object. */
|
|
37
|
+
readonly wire: string;
|
|
38
|
+
/** Value shape the codec validates. */
|
|
39
|
+
readonly shape: WireShape;
|
|
40
|
+
/** Whether the caller may omit the wire field. */
|
|
41
|
+
readonly optional?: true;
|
|
42
|
+
}
|
|
43
|
+
/** One invocation, as pure data. */
|
|
44
|
+
export interface WireInvocation {
|
|
45
|
+
/** Public method name. */
|
|
46
|
+
readonly method: string;
|
|
47
|
+
/** Ordered parameters. */
|
|
48
|
+
readonly parameters: readonly WireParameter[];
|
|
49
|
+
/** Result shape. */
|
|
50
|
+
readonly result: WireShape;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The wire contract.
|
|
54
|
+
*
|
|
55
|
+
* `project` names a project scope by slug (`overview` reports the slugs on
|
|
56
|
+
* disk); the empty string means "no project", which makes the project-scoped
|
|
57
|
+
* calls return nothing rather than fail.
|
|
58
|
+
*/
|
|
59
|
+
export declare const REMOTE_INVOCATION_DATA: readonly WireInvocation[];
|
|
60
|
+
/** A schema a codec materializes: the one method the gateway calls. */
|
|
61
|
+
export interface CodecSchema {
|
|
62
|
+
/** Validate one value at the wire boundary. */
|
|
63
|
+
parse(value: unknown): unknown;
|
|
64
|
+
}
|
|
65
|
+
/** A codec the registry accepts: a type symbol plus a lazy schema factory. */
|
|
66
|
+
export interface StrictCodec {
|
|
67
|
+
readonly mode: 'strict';
|
|
68
|
+
readonly typeSymbol: string;
|
|
69
|
+
/** Materialize the shape's schema; the registry requires this factory. */
|
|
70
|
+
create(): CodecSchema;
|
|
71
|
+
}
|
|
72
|
+
/** One registry invocation descriptor. */
|
|
73
|
+
export interface RemoteDescriptor {
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly service: string;
|
|
76
|
+
readonly namespace: string;
|
|
77
|
+
readonly method: string;
|
|
78
|
+
readonly invocation: {
|
|
79
|
+
readonly kind: 'direct';
|
|
80
|
+
};
|
|
81
|
+
readonly parameters: readonly {
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly wire: string;
|
|
84
|
+
readonly source: 'json';
|
|
85
|
+
readonly codec: StrictCodec;
|
|
86
|
+
readonly acceptsUndefined?: true;
|
|
87
|
+
}[];
|
|
88
|
+
readonly result: StrictCodec;
|
|
89
|
+
}
|
|
90
|
+
/** One Typert contribution, as `ctx.typert.register()` accepts it. */
|
|
91
|
+
export interface RemoteContribution {
|
|
92
|
+
readonly package: string;
|
|
93
|
+
readonly face: 'host';
|
|
94
|
+
readonly schemas: readonly unknown[];
|
|
95
|
+
readonly invocations: readonly RemoteDescriptor[];
|
|
96
|
+
readonly model: {
|
|
97
|
+
readonly services: readonly unknown[];
|
|
98
|
+
readonly events: readonly unknown[];
|
|
99
|
+
readonly objects: readonly unknown[];
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** The slice of the Typert registry this plugin uses. */
|
|
103
|
+
export interface TypertRegistryLike {
|
|
104
|
+
/** Register one contribution; returns the disposer that withdraws it. */
|
|
105
|
+
register(contribution: RemoteContribution): () => Promise<void> | void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Expand the wire table into registry descriptors.
|
|
109
|
+
* @param data - the wire contract.
|
|
110
|
+
* @param codecOf - shape-to-codec factory (the host validates; the browser does not).
|
|
111
|
+
* @returns the invocation descriptors.
|
|
112
|
+
*/
|
|
113
|
+
export declare function expandInvocations(data: readonly WireInvocation[], codecOf?: (shape: WireShape) => StrictCodec): readonly RemoteDescriptor[];
|
|
114
|
+
/** The host contribution, ready for `ctx.typert.register()`. */
|
|
115
|
+
export declare const REMOTE_CONTRIBUTION: RemoteContribution;
|
|
116
|
+
/** One entry as the settings page renders it. */
|
|
117
|
+
export interface EntryView {
|
|
118
|
+
readonly id: string;
|
|
119
|
+
readonly scope: string;
|
|
120
|
+
readonly kind: string;
|
|
121
|
+
readonly title: string;
|
|
122
|
+
readonly body: string;
|
|
123
|
+
readonly tags: readonly string[];
|
|
124
|
+
readonly appliesTo: string;
|
|
125
|
+
/** Session this memory came from, or `''` when it has no recorded source. */
|
|
126
|
+
readonly sourceSession: string;
|
|
127
|
+
readonly createdAt: number;
|
|
128
|
+
readonly updatedAt: number;
|
|
129
|
+
readonly uses: number;
|
|
130
|
+
readonly lastUsedAt: number;
|
|
131
|
+
readonly source: string;
|
|
132
|
+
}
|
|
133
|
+
/** The store facts the settings page opens with. */
|
|
134
|
+
export interface OverviewView {
|
|
135
|
+
readonly storePath: string;
|
|
136
|
+
readonly globalCount: number;
|
|
137
|
+
readonly projects: readonly {
|
|
138
|
+
readonly slug: string;
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly root: string;
|
|
141
|
+
readonly count: number;
|
|
142
|
+
readonly updatedAt: number;
|
|
143
|
+
}[];
|
|
144
|
+
readonly drafts: readonly {
|
|
145
|
+
readonly name: string;
|
|
146
|
+
readonly description: string;
|
|
147
|
+
readonly promoted: boolean;
|
|
148
|
+
}[];
|
|
149
|
+
readonly kinds: readonly string[];
|
|
150
|
+
}
|
|
151
|
+
/** What the Remote service needs from the plugin runtime. */
|
|
152
|
+
export interface RemoteHost {
|
|
153
|
+
/** The markdown store, scopes resolved by project root. */
|
|
154
|
+
readonly store: MemoryStore;
|
|
155
|
+
/** Harness home whose `skills/` promotion writes to. */
|
|
156
|
+
readonly dshHome: string;
|
|
157
|
+
/**
|
|
158
|
+
* The consolidation decisions waiting for a person, when the runtime is wired.
|
|
159
|
+
*
|
|
160
|
+
* The browser never decides what may be applied — it only asks — so these are
|
|
161
|
+
* hooks back into the runtime rather than logic living at this seam: the
|
|
162
|
+
* runtime is the only writer, and a page without a runtime (a bare store, a
|
|
163
|
+
* test) simply has no decisions to show.
|
|
164
|
+
*/
|
|
165
|
+
readonly disputes?: () => Promise<readonly {
|
|
166
|
+
id: string;
|
|
167
|
+
scope: string;
|
|
168
|
+
action: string;
|
|
169
|
+
title: string;
|
|
170
|
+
reason: string;
|
|
171
|
+
before: string;
|
|
172
|
+
after: string;
|
|
173
|
+
}[]>;
|
|
174
|
+
/** Accept or reject one waiting decision, through the runtime that owns it. */
|
|
175
|
+
readonly resolveDispute?: (id: string, decision: 'accept' | 'reject') => Promise<string | undefined>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The Remote service surface.
|
|
179
|
+
*
|
|
180
|
+
* Signatures are POSITIONAL, one parameter per descriptor parameter in the same
|
|
181
|
+
* order: the gateway resolves each descriptor parameter and applies the service
|
|
182
|
+
* method to that argument list, so an object-shaped signature would silently
|
|
183
|
+
* receive the first string as its argument. `REMOTE_INVOCATION_DATA` is the
|
|
184
|
+
* order this interface must mirror.
|
|
185
|
+
*/
|
|
186
|
+
export interface MemoriesRemote {
|
|
187
|
+
overview(): Promise<OverviewView>;
|
|
188
|
+
list(project?: string, scope?: string, query?: string, kind?: string, limit?: number): Promise<{
|
|
189
|
+
readonly entries: readonly EntryView[];
|
|
190
|
+
readonly total: number;
|
|
191
|
+
}>;
|
|
192
|
+
add(project?: string, scope?: string, kind?: string, title?: string, body?: string, tags?: string): Promise<{
|
|
193
|
+
readonly entry: EntryView;
|
|
194
|
+
}>;
|
|
195
|
+
forget(project?: string, scope?: string, id?: string): Promise<{
|
|
196
|
+
readonly removed: boolean;
|
|
197
|
+
}>;
|
|
198
|
+
promoteSkill(name?: string): Promise<{
|
|
199
|
+
readonly name: string;
|
|
200
|
+
readonly path: string;
|
|
201
|
+
}>;
|
|
202
|
+
discardSkill(name?: string): Promise<{
|
|
203
|
+
readonly name: string;
|
|
204
|
+
readonly removed: boolean;
|
|
205
|
+
}>;
|
|
206
|
+
persona(): Promise<PersonaView>;
|
|
207
|
+
savePersona(text?: string, locked?: boolean): Promise<PersonaView>;
|
|
208
|
+
disputes(): Promise<{
|
|
209
|
+
readonly disputes: readonly DisputeView[];
|
|
210
|
+
}>;
|
|
211
|
+
resolveDispute(id?: string, decision?: string): Promise<string>;
|
|
212
|
+
}
|
|
213
|
+
/** The persona profile as the settings page edits it. */
|
|
214
|
+
export interface PersonaView {
|
|
215
|
+
/** Stored markdown, empty when no profile exists yet. */
|
|
216
|
+
readonly text: string;
|
|
217
|
+
/** Whether automatic consolidation must leave the profile alone. */
|
|
218
|
+
readonly locked: boolean;
|
|
219
|
+
}
|
|
220
|
+
/** One consolidation decision, as the settings page renders it. */
|
|
221
|
+
export interface DisputeView {
|
|
222
|
+
readonly id: string;
|
|
223
|
+
readonly scope: string;
|
|
224
|
+
/** `rewrite` or `retire`. */
|
|
225
|
+
readonly action: string;
|
|
226
|
+
readonly title: string;
|
|
227
|
+
/** Why this one is being asked about, in one sentence. */
|
|
228
|
+
readonly reason: string;
|
|
229
|
+
/** What the memory says today. */
|
|
230
|
+
readonly before: string;
|
|
231
|
+
/** What the pass wants it to say; empty for a retirement. */
|
|
232
|
+
readonly after: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Build the `memories` Remote service.
|
|
236
|
+
*
|
|
237
|
+
* Every method resolves its project root from the slug the browser passed, so a
|
|
238
|
+
* settings page can never reach a scope the store does not already know: an
|
|
239
|
+
* unknown slug is an empty result, never a path the caller supplied.
|
|
240
|
+
*
|
|
241
|
+
* @param host - store access and the harness home.
|
|
242
|
+
* @returns the service object plus its `typertRemote` binding.
|
|
243
|
+
*/
|
|
244
|
+
export declare function createRemoteService(host: RemoteHost): MemoriesRemote & {
|
|
245
|
+
readonly typertRemote: unknown;
|
|
246
|
+
};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { MemoryEntry, MemoryHit } from './types.js';
|
|
2
|
+
import type { ScopeEntries } from './search.js';
|
|
3
|
+
import type { SessionNote } from './storage.js';
|
|
4
|
+
import type { LoopItem } from './loops.js';
|
|
5
|
+
import type { RawExcerpt } from './raw-recall.js';
|
|
6
|
+
/** Opening and closing frame of the injected, once-per-conversation block. */
|
|
7
|
+
export declare const MEMORY_OPEN = "<memory-context>";
|
|
8
|
+
/** @see MEMORY_OPEN */
|
|
9
|
+
export declare const MEMORY_CLOSE = "</memory-context>";
|
|
10
|
+
/** Opening and closing frame of an on-demand recall block. */
|
|
11
|
+
export declare const RECALL_OPEN = "<memory-recall>";
|
|
12
|
+
/** @see RECALL_OPEN */
|
|
13
|
+
export declare const RECALL_CLOSE = "</memory-recall>";
|
|
14
|
+
/** Opening and closing frame of the title-only rotation block. */
|
|
15
|
+
export declare const INDEX_OPEN = "<memory-index>";
|
|
16
|
+
/** @see INDEX_OPEN */
|
|
17
|
+
export declare const INDEX_CLOSE = "</memory-index>";
|
|
18
|
+
/**
|
|
19
|
+
* Rank entries for the injected summary. Recency dominates, with a small bonus
|
|
20
|
+
* for entries the model actually used, and a smaller one for entries somebody
|
|
21
|
+
* wrote deliberately: a memory that keeps being read earns its place in a
|
|
22
|
+
* bounded summary.
|
|
23
|
+
*
|
|
24
|
+
* The weight deliberately ignores `lastSurfacedAt` (see `recencyOf`), so a
|
|
25
|
+
* listing cannot renew its own claim to the next listing. Ranking decides the
|
|
26
|
+
* order; {@link selectForSummary} decides who gets in.
|
|
27
|
+
*
|
|
28
|
+
* When a `query` is supplied (the conversation's opening turn), the ranking is
|
|
29
|
+
* **tiered** rather than merely weighted. A memory the conversation actually
|
|
30
|
+
* names is ranked above every memory it does not; inside the tier the match
|
|
31
|
+
* itself decides, and the entry's own track record only breaks ties. Below the
|
|
32
|
+
* tier nothing changes and the weight orders as it always did.
|
|
33
|
+
*
|
|
34
|
+
* It has to be a tier, not a multiplier, and it has to keep ordering inside the
|
|
35
|
+
* tier. The weight's own range is `importanceOf` (up to
|
|
36
|
+
* {@link AUTO_IMPORTANCE_CEILING} × {@link EXPLICIT_SOURCE_BONUS} = 3.5) times
|
|
37
|
+
* `decayOf` (0.25–1), so a bounded lift cannot outrank an entry that has simply
|
|
38
|
+
* been read a lot. Worse, a lift saturates: once two entries both pass the same
|
|
39
|
+
* relevance threshold they carry the same multiplier, and the order silently
|
|
40
|
+
* reverts to history. Measured on the real store, a query about how the summary
|
|
41
|
+
* is ranked left memories at relevance 62 and 51 unlisted while the global half
|
|
42
|
+
* showed entries at relevance 0 and 4.
|
|
43
|
+
*
|
|
44
|
+
* @param entries - entries to order.
|
|
45
|
+
* @param now - clock.
|
|
46
|
+
* @param query - the conversation's opening text, when the caller has it.
|
|
47
|
+
* @returns a new array, most summary-worthy first.
|
|
48
|
+
*/
|
|
49
|
+
export declare function rankForSummary(entries: readonly MemoryEntry[], now?: number, query?: string): MemoryEntry[];
|
|
50
|
+
/**
|
|
51
|
+
* Relevance floor for the summary's topical tier.
|
|
52
|
+
*
|
|
53
|
+
* Below this an entry is not "about" the conversation whatever else it shares
|
|
54
|
+
* with it. Set at the same order as the recall gate on purpose: the two decide
|
|
55
|
+
* the same question — is this turn about that memory — and they should not
|
|
56
|
+
* disagree about where the line is.
|
|
57
|
+
*/
|
|
58
|
+
export declare const TOPIC_TIER_MIN_SCORE = 9;
|
|
59
|
+
/**
|
|
60
|
+
* Strong-field terms the topical tier requires.
|
|
61
|
+
*
|
|
62
|
+
* The tier is what lets an entry outrank a well-read unrelated one, so it must
|
|
63
|
+
* not be reachable on a single common word. This is the same default the recall
|
|
64
|
+
* path uses, and for the same reason: 「该插件是否有日志」 shares an isolated 插件
|
|
65
|
+
* with memories about plugin registration order and cost meters.
|
|
66
|
+
*
|
|
67
|
+
* The tier applies the rule strictly — no "one strong term plus a decisive
|
|
68
|
+
* score" escape hatch, which recall allows so a one-keyword turn like 「端口
|
|
69
|
+
* 3080」 still finds its memory. A summary slot is not a lookup: the escape
|
|
70
|
+
* hatch admitted twelve memories at one shared term each on the real store,
|
|
71
|
+
* which made the tier stop discriminating at all.
|
|
72
|
+
*/
|
|
73
|
+
export declare const TOPIC_TIER_MIN_TERMS = 2;
|
|
74
|
+
/**
|
|
75
|
+
* Share of a scope's slots the never-surfaced reservation may take, rounded
|
|
76
|
+
* down, with a floor of one while the scope has room to spare.
|
|
77
|
+
*
|
|
78
|
+
* The reservation exists so a saturated scope eventually shows something new.
|
|
79
|
+
* It is a maintenance slot, not a ranking, and it is paid for out of the same
|
|
80
|
+
* budget as everything else — so it has to be bounded by the scope's real size
|
|
81
|
+
* or it simply becomes the scope.
|
|
82
|
+
*
|
|
83
|
+
* A third is what leaves the shipped defaults behaving: the project half
|
|
84
|
+
* renders up to 12 and the default asks for 3, unchanged. The global half
|
|
85
|
+
* renders up to 4, and there the untruncated 3 left ONE slot for the ranking —
|
|
86
|
+
* measured on the real store, three never-listed global memories took three of
|
|
87
|
+
* the four shared bullets and every topically relevant global memory was gone,
|
|
88
|
+
* including the one at relevance 62. The global half is the one every session
|
|
89
|
+
* in every workspace pays for, so spending three quarters of it on whatever
|
|
90
|
+
* happened to be written recently is the worst trade in the block.
|
|
91
|
+
*
|
|
92
|
+
* @param perScope - the slots this scope can actually render.
|
|
93
|
+
* @returns the most slots the reservation may take.
|
|
94
|
+
*/
|
|
95
|
+
export declare function maxFreshSlots(perScope: number): number;
|
|
96
|
+
/**
|
|
97
|
+
* Choose which entries one scope may list in the injected summary.
|
|
98
|
+
*
|
|
99
|
+
* Ranking alone cannot do this job. With more entries than slots, the top of the
|
|
100
|
+
* ranking is a fixed point: every listed entry carries a use count and a recent
|
|
101
|
+
* `updatedAt`, while an entry written one minute ago carries neither, so a
|
|
102
|
+
* saturated scope never shows anything new. Measured on a real store, the store
|
|
103
|
+
* had 369 entries of which 244 had never been read once — the summary was
|
|
104
|
+
* listing the same 12 per scope while the memory that corrected one of them sat
|
|
105
|
+
* invisible below the cut.
|
|
106
|
+
*
|
|
107
|
+
* So a few slots are reserved, in this order:
|
|
108
|
+
*
|
|
109
|
+
* 1. entries a person or the model wrote deliberately that have never been
|
|
110
|
+
* surfaced — an explicit statement outranks anything the extractor guessed;
|
|
111
|
+
* 2. otherwise the newest never-surfaced entries, so fresh material is seen at
|
|
112
|
+
* least once;
|
|
113
|
+
* 3. the rest by rank.
|
|
114
|
+
*
|
|
115
|
+
* `freshSlots` entries are reserved at most, and never all of them: the ranking
|
|
116
|
+
* still decides whether a scope lists anything at all, and a slot it does not
|
|
117
|
+
* use falls back to the ranking. The reservation is additionally capped at
|
|
118
|
+
* {@link maxFreshSlots} of the scope's own slots, and the caller is expected to
|
|
119
|
+
* pass the number of bullets that scope can really render rather than a shared
|
|
120
|
+
* maximum — a reservation sized against a cap the scope never reaches is a
|
|
121
|
+
* reservation that silently takes the whole section.
|
|
122
|
+
*
|
|
123
|
+
* The returned order is PROTECTION order, reserved entries first, not rank order.
|
|
124
|
+
* The renderer drops entries from the end of this array when the byte budget is
|
|
125
|
+
* tight — on a real store it renders about six per scope, not the twelve it was
|
|
126
|
+
* offered — so a reserved entry that sorted last would be the first casualty of
|
|
127
|
+
* exactly the pressure it exists to survive. That is also why the topical floor
|
|
128
|
+
* comes first: whatever the byte budget keeps is the head of this array, so an
|
|
129
|
+
* order that leads with pins and reservations hands the budget to them.
|
|
130
|
+
*
|
|
131
|
+
* @param entries - every entry in one scope.
|
|
132
|
+
* @param perScope - how many the summary may list.
|
|
133
|
+
* @param options - reserved-slot count and clock.
|
|
134
|
+
* @returns exactly the entries to list, most protected first.
|
|
135
|
+
*/
|
|
136
|
+
export declare function selectForSummary(entries: readonly MemoryEntry[], perScope: number, options?: {
|
|
137
|
+
freshSlots?: number;
|
|
138
|
+
now?: number;
|
|
139
|
+
query?: string;
|
|
140
|
+
}): MemoryEntry[];
|
|
141
|
+
/** One scope's contribution to the injected summary. */
|
|
142
|
+
export interface SummaryScope {
|
|
143
|
+
/** Model-facing scope label. */
|
|
144
|
+
readonly label: string;
|
|
145
|
+
/** Section heading, e.g. `Global memories`. */
|
|
146
|
+
readonly heading: string;
|
|
147
|
+
/** Entries to list. */
|
|
148
|
+
readonly entries: readonly MemoryEntry[];
|
|
149
|
+
/** Total entries in the scope, including ones not listed. */
|
|
150
|
+
readonly total: number;
|
|
151
|
+
/**
|
|
152
|
+
* Cap on this scope's bullets, overriding `maxEntriesPerScope`.
|
|
153
|
+
*
|
|
154
|
+
* The scopes share one byte budget, and the global section is rendered first,
|
|
155
|
+
* so an uncapped global scope expands to fill whatever the project scope does
|
|
156
|
+
* not use: measured on a real store, a two-memory project session spent 87% of
|
|
157
|
+
* the budget on global entries. A per-scope cap is what keeps a broad scope
|
|
158
|
+
* from crowding out the one scope that is about this conversation.
|
|
159
|
+
*/
|
|
160
|
+
readonly maxEntries?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Byte budget for this scope's bullets, overriding the shared one.
|
|
163
|
+
*
|
|
164
|
+
* The block's budget is shared and the global section renders first, so a
|
|
165
|
+
* count cap alone does not protect the project half: four Chinese entries cost
|
|
166
|
+
* about as much as twelve English ones, and measured on a real store the global
|
|
167
|
+
* half still took 45–81% of the block after the count cap. A byte budget is
|
|
168
|
+
* what actually reserves room for the scope that is about this conversation.
|
|
169
|
+
*/
|
|
170
|
+
readonly maxBytes?: number;
|
|
171
|
+
}
|
|
172
|
+
/** Options for {@link renderMemorySummary}. */
|
|
173
|
+
export interface SummaryOptions {
|
|
174
|
+
/** Total UTF-8 byte budget for the rendered block. */
|
|
175
|
+
readonly maxBytes: number;
|
|
176
|
+
/** Max entries listed per scope. */
|
|
177
|
+
readonly maxEntriesPerScope: number;
|
|
178
|
+
/**
|
|
179
|
+
* One line the caller wants carried in the block, when it has something the
|
|
180
|
+
* model should act on but no entry can say — today, staged skill drafts
|
|
181
|
+
* waiting for a human to promote them. Counted against `maxBytes` like every
|
|
182
|
+
* other line, so it can never push the block past its budget.
|
|
183
|
+
*/
|
|
184
|
+
readonly note?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Per-entry warning appended to a bullet, keyed by entry id.
|
|
187
|
+
*
|
|
188
|
+
* The caller checks what it is about to show (a handful of entries) rather than
|
|
189
|
+
* the whole store, so this is affordable on every injection. Today it carries
|
|
190
|
+
* "this memory cites a file that no longer exists" — the failure mode that
|
|
191
|
+
* wastes a session's turn by sending it to a path that is gone.
|
|
192
|
+
*/
|
|
193
|
+
readonly flags?: ReadonlyMap<string, string>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Render the layered memory summary injected at session start.
|
|
197
|
+
*
|
|
198
|
+
* Global entries come first, then the project's, because a project fact is
|
|
199
|
+
* allowed to override a general preference. The renderer degrades
|
|
200
|
+
* deterministically under budget pressure: entries are dropped from the end of
|
|
201
|
+
* each section, then bodies shrink, then sections are dropped, and the block is
|
|
202
|
+
* finally truncated rather than exceeding its budget.
|
|
203
|
+
*
|
|
204
|
+
* @param scopes - per-scope sections, broadest first.
|
|
205
|
+
* @param options - byte budget, per-scope cap, replacement framing, and note.
|
|
206
|
+
* @returns the complete framed block, or `undefined` when there is nothing to say.
|
|
207
|
+
*/
|
|
208
|
+
export declare function renderMemorySummary(scopes: readonly SummaryScope[], options: SummaryOptions): string | undefined;
|
|
209
|
+
/** Render the summary and return only entries whose bullets reached the output. */
|
|
210
|
+
export declare function renderMemorySummaryResult(scopes: readonly SummaryScope[], options: SummaryOptions): {
|
|
211
|
+
text: string;
|
|
212
|
+
listed: readonly MemoryEntry[];
|
|
213
|
+
} | undefined;
|
|
214
|
+
/** Limits for the open-loop section that rides with the summary block. */
|
|
215
|
+
export interface OpenLoopOptions {
|
|
216
|
+
/** Most loops to list. */
|
|
217
|
+
readonly maxEntries?: number;
|
|
218
|
+
/** UTF-8 byte budget for the section. */
|
|
219
|
+
readonly maxBytes?: number;
|
|
220
|
+
/** Clock used to label a deadline. */
|
|
221
|
+
readonly now?: number;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Render the user's open loops as a short section of the injected block.
|
|
225
|
+
*
|
|
226
|
+
* Loops were deliberately kept out of the memory store: they are obligations
|
|
227
|
+
* with a lifecycle, not facts. But leaving them out of the *injected context*
|
|
228
|
+
* was a real miss — measured in the end-to-end benchmark, the extractor filed
|
|
229
|
+
* "明天把登录页截图补齐" as a loop and the memory arm then answered "不知道"
|
|
230
|
+
* about it. A future session asked "我明天要做什么" and nothing in the context
|
|
231
|
+
* knew. The loop ledger already answers it, bounded by TTL and a cap, so it is
|
|
232
|
+
* cheap to include.
|
|
233
|
+
*
|
|
234
|
+
* Only `open` loops are listed; closed, dropped and expired ones are history.
|
|
235
|
+
* A deadline sorts first and is shown as a date, because "no date" is a note
|
|
236
|
+
* and an overdue date is a fact worth seeing.
|
|
237
|
+
*
|
|
238
|
+
* @param loops - the ledger's loops.
|
|
239
|
+
* @param options - caps and clock.
|
|
240
|
+
* @returns the section, or `undefined` when nothing is open.
|
|
241
|
+
*/
|
|
242
|
+
export declare function renderOpenLoops(loops: readonly LoopItem[], options?: OpenLoopOptions): string | undefined;
|
|
243
|
+
/** Render one search hit for the model. */
|
|
244
|
+
export declare function renderHit(hit: MemoryHit, index: number): string;
|
|
245
|
+
/** Render one entry in full. */
|
|
246
|
+
export declare function renderEntry(entry: MemoryEntry): string;
|
|
247
|
+
/**
|
|
248
|
+
* Render one on-demand recall block.
|
|
249
|
+
*
|
|
250
|
+
* Deliberately tiny and separate from the once-per-conversation summary: it
|
|
251
|
+
* answers "this turn looks like something already known", so it carries the
|
|
252
|
+
* kind, the title, and one line of body — enough to decide whether opening the
|
|
253
|
+
* memory properly is worth a tool call.
|
|
254
|
+
*
|
|
255
|
+
* Bytes, not characters, drive the budget, and the frame is never truncated
|
|
256
|
+
* away. `carriesRecall` and the pre-step hook identify our blocks by their
|
|
257
|
+
* closing frame, so a block whose tail was cut would be invisible to the dedupe
|
|
258
|
+
* that stops the summary from being injected twice.
|
|
259
|
+
*
|
|
260
|
+
* @param entries - the memories worth surfacing right now, best first.
|
|
261
|
+
* @param maxBytes - hard UTF-8 byte budget for the framed block.
|
|
262
|
+
* @param archived - retired memories that still answer the turn, offered only
|
|
263
|
+
* when nothing live did; rendered with an explicit marker so the model can
|
|
264
|
+
* tell "this is current" from "this is what we used to say".
|
|
265
|
+
* @returns the framed block, or `undefined` when nothing fits.
|
|
266
|
+
*/
|
|
267
|
+
export declare function renderRecall(entries: readonly MemoryEntry[], maxBytes: number, archived?: readonly MemoryEntry[], excerpts?: readonly RawExcerpt[]): string | undefined;
|
|
268
|
+
/**
|
|
269
|
+
* Render the title-only rotation block.
|
|
270
|
+
*
|
|
271
|
+
* The summary can name a dozen entries; on a store with hundreds, most of them
|
|
272
|
+
* are never shown and therefore never read. This block spends its budget on
|
|
273
|
+
* titles instead of bodies — roughly 60 bytes per Chinese entry — so one
|
|
274
|
+
* conversation can make a dozen more memories discoverable without repeating
|
|
275
|
+
* the summary's cost. No body is included on purpose: a title is enough to know
|
|
276
|
+
* whether to call the `memory` tool, and a body excerpt would cost 3-4x more.
|
|
277
|
+
*
|
|
278
|
+
* @param entries - entries to list, in the order the caller wants them shown.
|
|
279
|
+
* @param maxBytes - hard UTF-8 budget for the framed block.
|
|
280
|
+
* @returns the framed block, or `undefined` when nothing fits.
|
|
281
|
+
*/
|
|
282
|
+
export declare function renderMemoryIndex(entries: readonly MemoryEntry[], maxBytes?: number): string | undefined;
|
|
283
|
+
/** Render one session's evidence note for the model. */
|
|
284
|
+
export declare function renderEvidence(note: SessionNote): string;
|
|
285
|
+
/** Render a scope listing for a human-facing command. */
|
|
286
|
+
export declare function renderScopeListing(group: ScopeEntries): string;
|