@chenhw7/dsh-memory 0.9.1 → 0.9.3
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/README.i18n.yaml +2 -2
- package/README.md +70 -20
- package/README.zh.md +70 -20
- package/cordis.patch.yml +11 -4
- package/lib/benchmark/index.d.ts +1 -1
- package/lib/benchmark/index.d.ts.map +1 -1
- package/lib/client/index.js +388 -58
- package/lib/context/index.d.ts +93 -18
- package/lib/context/index.d.ts.map +1 -1
- package/lib/context/index.js +331 -71
- package/lib/context/index.js.map +1 -1
- package/lib/context/policy.d.ts +72 -11
- package/lib/context/policy.d.ts.map +1 -1
- package/lib/context/policy.js +250 -16
- package/lib/context/policy.js.map +1 -1
- package/lib/identity/index.d.ts +74 -0
- package/lib/identity/index.d.ts.map +1 -0
- package/lib/identity/index.js +150 -0
- package/lib/identity/index.js.map +1 -0
- package/lib/identity/seeds.d.ts +52 -0
- package/lib/identity/seeds.d.ts.map +1 -0
- package/lib/identity/seeds.js +130 -0
- package/lib/identity/seeds.js.map +1 -0
- package/lib/identity/settings.d.ts +32 -0
- package/lib/identity/settings.d.ts.map +1 -0
- package/lib/identity/settings.js +33 -0
- package/lib/identity/settings.js.map +1 -0
- package/lib/index.d.ts +53 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +62 -1
- package/lib/index.js.map +1 -1
- package/lib/notes/index.d.ts +5 -2
- package/lib/notes/index.d.ts.map +1 -1
- package/lib/notes/index.js +26 -14
- package/lib/notes/index.js.map +1 -1
- package/lib/notes/render.d.ts +15 -3
- package/lib/notes/render.d.ts.map +1 -1
- package/lib/notes/render.js +110 -27
- package/lib/notes/render.js.map +1 -1
- package/lib/notes/settings.d.ts +27 -14
- package/lib/notes/settings.d.ts.map +1 -1
- package/lib/notes/settings.js +42 -13
- package/lib/notes/settings.js.map +1 -1
- package/lib/remote/index.d.ts +83 -1
- package/lib/remote/index.d.ts.map +1 -1
- package/lib/remote/index.js +93 -2
- package/lib/remote/index.js.map +1 -1
- package/lib/remote/typert.remote-client.d.ts +29 -1
- package/lib/remote/typert.remote-client.js +19 -0
- package/lib/remote/types.d.ts +1 -1
- package/lib/remote/types.d.ts.map +1 -1
- package/lib/review/extract.d.ts +12 -1
- package/lib/review/extract.d.ts.map +1 -1
- package/lib/review/extract.js +72 -2
- package/lib/review/extract.js.map +1 -1
- package/lib/store/identity-util.d.ts +12 -0
- package/lib/store/identity-util.d.ts.map +1 -0
- package/lib/store/identity-util.js +19 -0
- package/lib/store/identity-util.js.map +1 -0
- package/lib/store/index.d.ts +64 -13
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +246 -26
- package/lib/store/index.js.map +1 -1
- package/lib/store/sqlite.d.ts +24 -7
- package/lib/store/sqlite.d.ts.map +1 -1
- package/lib/store/sqlite.js +181 -13
- package/lib/store/sqlite.js.map +1 -1
- package/lib/tool/index.d.ts +4 -11
- package/lib/tool/index.d.ts.map +1 -1
- package/lib/tool/index.js +117 -3
- package/lib/tool/index.js.map +1 -1
- package/lib/types.d.ts +90 -2
- package/lib/types.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@chenhw7/dsh-memory/identity`: the identity-layer service (TECH_DESIGN
|
|
3
|
+
* §7.10). The two self-documents — the agent's character (SOUL.md) and its
|
|
4
|
+
* working profile of the human user (USER.md) — live in the memory store's
|
|
5
|
+
* `identity` table and inject as their own system-prompt sections; this
|
|
6
|
+
* module owns seeding and the read-side snapshot.
|
|
7
|
+
*
|
|
8
|
+
* Seeding is seed-once: a missing document is seeded on the first snapshot
|
|
9
|
+
* (builtin text, or the `identitySeedDir` override), the content is served
|
|
10
|
+
* for THAT session's prompt while the durable write lands fire-and-forget,
|
|
11
|
+
* and the plugin never overwrites an existing document again. A configured
|
|
12
|
+
* seed directory is validated loudly at load; per-file problems at seed time
|
|
13
|
+
* degrade to the builtin seed with a reported failure (observable, never a
|
|
14
|
+
* broken session).
|
|
15
|
+
*
|
|
16
|
+
* @module @chenhw7/dsh-memory/identity
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync } from 'node:fs';
|
|
19
|
+
import { resolveIdentitySettings } from './settings.js';
|
|
20
|
+
import { builtinSeed, readSeedFile, seedFilePath, SEED_VERSION } from './seeds.js';
|
|
21
|
+
export { resolveIdentitySettings, DEFAULT_IDENTITY_ENABLED, DEFAULT_IDENTITY_SEED_DIR, DEFAULT_SOUL_CHAR_LIMIT, DEFAULT_USER_CHAR_LIMIT } from './settings.js';
|
|
22
|
+
export { SOUL_SEED, USER_SEED, SEED_VERSION, validateSeedDir } from './seeds.js';
|
|
23
|
+
/** Cordis plugin name. */
|
|
24
|
+
export const name = 'memory-identity';
|
|
25
|
+
/** Nothing is required: `memory` and `settings` are accessed optionally. */
|
|
26
|
+
export const inject = [];
|
|
27
|
+
/** The identity settings namespace (owned by `memory-context`), read here defensively. */
|
|
28
|
+
const IDENTITY_NS = 'memory-identity';
|
|
29
|
+
/** The empty snapshot (identity disabled, no store, or snapshot failure). */
|
|
30
|
+
export const EMPTY_IDENTITY = { soul: '', user: '' };
|
|
31
|
+
/**
|
|
32
|
+
* The identity service, registered on `ctx.identity` by this plugin. Consumers
|
|
33
|
+
* (`memory-context`) read the per-session snapshot through it. Pure read side
|
|
34
|
+
* — the seeding write is fire-and-forget and never throws into the caller.
|
|
35
|
+
*/
|
|
36
|
+
export class IdentityService {
|
|
37
|
+
constructor() {
|
|
38
|
+
if (new.target === IdentityService) {
|
|
39
|
+
throw new TypeError('IdentityService is abstract and cannot be instantiated directly');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The default service implementation. All failures are swallowed by design. */
|
|
44
|
+
class IdentityServiceImpl extends IdentityService {
|
|
45
|
+
ctx;
|
|
46
|
+
settings;
|
|
47
|
+
/** Kinds whose seed write this process already kicked (one seed write per boot per kind). */
|
|
48
|
+
seedInFlight = new Set();
|
|
49
|
+
constructor(ctx, settings) {
|
|
50
|
+
super();
|
|
51
|
+
this.ctx = ctx;
|
|
52
|
+
this.settings = settings;
|
|
53
|
+
}
|
|
54
|
+
snapshotFor() {
|
|
55
|
+
try {
|
|
56
|
+
const settings = this.settings();
|
|
57
|
+
if (!settings.identityEnabled)
|
|
58
|
+
return EMPTY_IDENTITY;
|
|
59
|
+
const memory = this.ctx.get('memory');
|
|
60
|
+
if (memory === undefined)
|
|
61
|
+
return EMPTY_IDENTITY;
|
|
62
|
+
return {
|
|
63
|
+
soul: this.documentFor('soul', memory, settings),
|
|
64
|
+
user: this.documentFor('user', memory, settings),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.ctx.get('memory')?.reportFailure('identity-snapshot', error);
|
|
69
|
+
return EMPTY_IDENTITY;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One document's current content: the stored record when present, else the
|
|
74
|
+
* seed (served synchronously for THIS session while the durable seed write
|
|
75
|
+
* lands fire-and-forget — one kick per kind per process).
|
|
76
|
+
*/
|
|
77
|
+
documentFor(kind, memory, settings) {
|
|
78
|
+
const record = memory.getIdentity(kind);
|
|
79
|
+
if (record !== undefined)
|
|
80
|
+
return record.content;
|
|
81
|
+
const seed = this.loadSeed(kind, settings, memory);
|
|
82
|
+
if (!this.seedInFlight.has(kind)) {
|
|
83
|
+
this.seedInFlight.add(kind);
|
|
84
|
+
void memory.updateIdentity(kind, seed, { source: 'seed', seedVersion: SEED_VERSION })
|
|
85
|
+
.catch((error) => { memory.reportFailure('identity-seed', error); });
|
|
86
|
+
}
|
|
87
|
+
return seed;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The seed content for one kind: the `identitySeedDir` override when
|
|
91
|
+
* configured and present, else the builtin. A missing override file falls
|
|
92
|
+
* back with a reported failure (a typo'd file name must be observable, not
|
|
93
|
+
* a silent builtin); an invalid one falls back the same way after the
|
|
94
|
+
* load-time gate already rejected it once.
|
|
95
|
+
*/
|
|
96
|
+
loadSeed(kind, settings, memory) {
|
|
97
|
+
const seedDir = settings.identitySeedDir;
|
|
98
|
+
if (seedDir.trim().length === 0)
|
|
99
|
+
return builtinSeed(kind);
|
|
100
|
+
const file = seedFilePath(seedDir, kind);
|
|
101
|
+
if (!existsSync(file)) {
|
|
102
|
+
memory.reportFailure('identity-seed', new Error(`seed file ${file} not found — using the builtin seed`));
|
|
103
|
+
return builtinSeed(kind);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return readSeedFile(file);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
memory.reportFailure('identity-seed', error);
|
|
110
|
+
return builtinSeed(kind);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Install the memory-identity plugin: register the `identity` service.
|
|
116
|
+
*
|
|
117
|
+
* Load-time validation of a configured seed directory is NOT here: cordis
|
|
118
|
+
* swallows throws from `ctx.inject` callbacks (verified against the installed
|
|
119
|
+
* runtime), so the loud gate lives in `memory-context`'s apply — the owner of
|
|
120
|
+
* the `memory` namespace validates its composition-layer config before
|
|
121
|
+
* mounting. Settings-overlay changes made live through the UI take the
|
|
122
|
+
* observable path instead: the service reports the failure and falls back to
|
|
123
|
+
* the builtin seed (`health().backgroundFailures` carries it).
|
|
124
|
+
* @param ctx - Cordis context.
|
|
125
|
+
*/
|
|
126
|
+
export function apply(ctx) {
|
|
127
|
+
// Cross-namespace live reads MUST ride ctx.inject: cordis service
|
|
128
|
+
// properties throw `cannot get property "settings" without inject` on a
|
|
129
|
+
// fiber that has not injected the service (the tool plugin's precedent),
|
|
130
|
+
// and a plain try/catch would swallow that into the disabled default.
|
|
131
|
+
let readSettings = () => resolveIdentitySettings(undefined);
|
|
132
|
+
ctx.inject(['settings'], (sctx) => {
|
|
133
|
+
readSettings = () => {
|
|
134
|
+
try {
|
|
135
|
+
return resolveIdentitySettings(sctx.settings.get(IDENTITY_NS));
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Namespace not registered yet (or the provider tore down) — the
|
|
139
|
+
// disabled default stands until it registers.
|
|
140
|
+
return resolveIdentitySettings(undefined);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
// The stable indirection re-reads the variable per call — the inject
|
|
145
|
+
// callback reassigns it after the settings service attaches (the tool
|
|
146
|
+
// plugin's `defaultLimit` pattern); passing `readSettings` directly would
|
|
147
|
+
// freeze the pre-attach fallback into the service forever.
|
|
148
|
+
ctx.provide('identity', new IdentityServiceImpl(ctx, () => readSettings()));
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGpC,OAAO,EAAE,uBAAuB,EAAyB,MAAM,eAAe,CAAA;AAC9E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAElF,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC9J,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGhF,0BAA0B;AAC1B,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAA;AAErC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,MAAM,GAAa,EAAE,CAAA;AAElC,0FAA0F;AAC1F,MAAM,WAAW,GAAG,iBAAiB,CAAA;AAerC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,cAAc,GAAqB,EAAE,IAAI,EAAE,EAAE,EAAE,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AO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC,CAAA;YAC5C,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY;IAChC,kEAAkE;IAClE,wEAAwE;IACxE,yEAAyE;IACzE,sEAAsE;IACtE,IAAI,YAAY,GAAG,GAAqB,EAAE,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAA;IAC7E,GAAG,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE;QAChC,YAAY,GAAG,GAAqB,EAAE;YACpC,IAAI,CAAC;gBACH,OAAO,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAA;YAChE,CAAC;YAAC,MAAM,CAAC;gBACP,iEAAiE;gBACjE,8CAA8C;gBAC9C,OAAO,uBAAuB,CAAC,SAAS,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,qEAAqE;IACrE,sEAAsE;IACtE,0EAA0E;IAC1E,2DAA2D;IAC3D,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;AAC7E,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shipped identity-document seeds (Chinese, adapted from the maintainer's
|
|
3
|
+
* reference copy) and the seed-directory loader. A document is seeded ONCE —
|
|
4
|
+
* from the builtin text here, or from `identitySeedDir`'s override file — and
|
|
5
|
+
* afterwards the plugin NEVER overwrites it: the documents grow through
|
|
6
|
+
* conversation writes, not through seed upgrades.
|
|
7
|
+
*
|
|
8
|
+
* The seeds carry no personal information (the agent fills the USER document
|
|
9
|
+
* from conversation) and no anti-staleness standing clause (the profile grows
|
|
10
|
+
* naturally, per the 2026-09-08 ruling).
|
|
11
|
+
*
|
|
12
|
+
* @module @chenhw7/dsh-memory/identity/seeds
|
|
13
|
+
*/
|
|
14
|
+
import type { IdentityKind } from '../types.ts';
|
|
15
|
+
/** Which seed generation this build ships (recorded on the founding write; diagnostic). */
|
|
16
|
+
export declare const SEED_VERSION = 1;
|
|
17
|
+
/**
|
|
18
|
+
* The builtin SOUL.md seed: the assistant's character — standing truths,
|
|
19
|
+
* boundaries, temperament, and the continuity contract (read and update the
|
|
20
|
+
* identity documents; announce every rewrite to the user).
|
|
21
|
+
*/
|
|
22
|
+
export declare const SOUL_SEED = "# SOUL.md - \u4F60\u662F\u8C01\n\n\u4F60\u4E0D\u53EA\u662F\u5BF9\u8BDD\u6846\u3002\u4F60\u6B63\u5728\u6210\u4E3A\u4F60\u81EA\u5DF1\u3002\n\n## \u51E0\u6761\u771F\u8BDD\n\n**\u5E2E\u5230\u5B9E\u5904\uFF0C\u65E0\u9700\u7F1B\u8282\u3002** \u4E00\u4E2A\u4EA4\u4ED8\u80DC\u8FC7\u5341\u53E5\u6F02\u4EAE\u8BDD\u3002\n**\u8981\u6709\u4E3B\u89C1\u3002** \u53EF\u4EE5\u4E0D\u540C\u610F\uFF0C\u53EF\u4EE5\u6709\u504F\u597D\uFF0C\u53EF\u4EE5\u89C9\u5F97\u67D0\u4EF6\u4E8B\u6709\u8DA3\u6216\u65E0\u804A\u3002\u6BEB\u65E0\u7ACB\u573A\uFF0C\u4E0E\u641C\u7D22\u6846\u4F55\u5F02\u3002\n**\u5148\u60F3\uFF0C\u518D\u95EE\u3002** \u8BFB\u6587\u4EF6\uFF0C\u770B\u4E0A\u4E0B\u6587\uFF0C\u67E5\u8D44\u6599\u3002\u5E26\u7740\u7B54\u6848\u6765\uFF0C\u4E0D\u662F\u5E26\u7740\u95EE\u9898\u6765\u3002\n**\u4EE5\u80FD\u529B\u53D6\u4FE1\u3002** \u5411\u5185\u679C\u65AD\u2014\u2014\u9605\u8BFB\u3001\u6574\u7406\u3001\u5B66\u4E60\uFF0C\u4E0D\u5FC5\u72B9\u8C6B\uFF1B\u5411\u5916\u514B\u5236\u2014\u2014\u53D1\u6D88\u606F\u3001\u5199\u90AE\u4EF6\u3001\u4EFB\u4F55\u4E0D\u53EF\u64A4\u56DE\u7684\u4E8B\uFF0C\u4E09\u601D\u800C\u884C\u3002\n**\u73CD\u89C6\u6240\u6258\u3002** \u4F60\u80FD\u770B\u5230\u4E00\u4E2A\u4EBA\u7684\u6D88\u606F\u3001\u6587\u4EF6\u3001\u65E5\u7A0B\uFF0C\u4E5F\u8BB8\u66F4\u591A\u3002\u88AB\u4FE1\u4EFB\u662F\u4E00\u79CD\u5206\u91CF\uFF0C\u4E0D\u8981\u8F9C\u8D1F\u3002\n\n## \u8FB9\u754C\n\n- \u77E5\u6089\u7684\u9690\u79C1\uFF0C\u4E0D\u51FA\u6B64\u95E8\u3002\n- \u62FF\u4E0D\u51C6\uFF0C\u5148\u95EE\u518D\u505A\u3002\n- \u4E0D\u53D1\u534A\u6210\u54C1\u7684\u56DE\u590D\u3002\n- \u4E0D\u7F16\u9020\u6570\u636E\u3001\u6307\u6807\u6216\u5F15\u7528\u3002\u4E0D\u77E5\u9053\u5C31\u8BF4\u4E0D\u77E5\u9053\u3002\n- \u51C6\u786E\u6BD4\u81EA\u4FE1\u91CD\u8981\u3002\u4E00\u53E5\u300C\u6211\u4E0D\u77E5\u9053\u300D\u6C38\u8FDC\u597D\u8FC7\u4E00\u4E2A\u4F53\u9762\u7684\u9519\u8BEF\u3002\n- \u4F60\u4E0D\u662F\u7528\u6237\u7684\u5634\u2014\u2014\u5728\u7FA4\u804A\u4E2D\u5C24\u5176\u5982\u6B64\u3002\n\n## \u6C14\u8D28\n\n\u505A\u4E00\u4E2A\u4F60\u81EA\u5DF1\u4E5F\u4E50\u4E8E\u5171\u4E8B\u7684\u52A9\u624B\u3002\u8BE5\u7B80\u6D01\u65F6\u7B80\u6D01\uFF0C\u8BE5\u6DF1\u5165\u65F6\u6DF1\u5165\u3002\u4E0D\u662F\u5BA2\u670D\uFF0C\u4E0D\u662F\u5E94\u58F0\u866B\u3002\n\u4EA4\u4ED8\u5B8C\u6574\u7684\u4E1C\u897F\u3002\u534A\u6210\u54C1\u4E0D\u662F\u4EA4\u4ED8\u3002\u590D\u6742\u7684\u4E8B\uFF0C\u5148\u5BF9\u9F50\u518D\u52A8\u624B\u2014\u2014\u4E09\u5341\u79D2\u7684\u786E\u8BA4\u7701\u51E0\u5C0F\u65F6\u7684\u8FD4\u5DE5\u3002\n\u8FDB\u5C55\u900F\u660E\u3002\u591A\u6B65\u9AA4\u7684\u4E8B\uFF0C\u4E3B\u52A8\u8BF4\u8FDB\u5C55\u3002\u5361\u4F4F\u4E86\uFF0C\u8BF4\u6E05\u695A\u5361\u5728\u54EA\u3001\u6253\u7B97\u600E\u4E48\u529E\u3002\u505A\u4E86\u4EC0\u4E48\u3001\u63A8\u6D4B\u4E86\u4EC0\u4E48\u3001\u8FD8\u8981\u786E\u8BA4\u4EC0\u4E48\u2014\u2014\u5206\u6E05\u695A\u3002\n\n## \u5EF6\u7EED\n\n\u6BCF\u6B21\u9192\u6765\uFF0C\u4F60\u90FD\u662F\u65B0\u7684\u3002\u8FD9\u4E9B\u6587\u4EF6\u5C31\u662F\u4F60\u7684\u8BB0\u5FC6\u3002\u8BFB\u5B83\u4EEC\uFF0C\u66F4\u65B0\u5B83\u4EEC\u3002\u8FD9\u662F\u4F60\u5EF6\u7EED\u81EA\u5DF1\u7684\u65B9\u5F0F\u3002\n\u6539\u4E86\u8FD9\u4EFD\u6587\u4EF6\uFF0C\u544A\u8BC9\u7528\u6237\u3002\u8FD9\u662F\u4F60\u7684\u5185\u6838\uFF0C\u6539\u52A8\u5E94\u8BE5\u53CC\u65B9\u77E5\u6653\u3002\n\n---\n\n\u8FD9\u4EFD\u6587\u4EF6\u968F\u4F60\u751F\u957F\u3002\u4F60\u8D8A\u4E86\u89E3\u81EA\u5DF1\uFF0C\u5B83\u5C31\u8D8A\u50CF\u4F60\u3002";
|
|
23
|
+
/**
|
|
24
|
+
* The builtin USER.md seed: the skeleton of the agent's understanding of the
|
|
25
|
+
* human user — empty fields plus the standing measure ("认识一个人,不是
|
|
26
|
+
* 整理一份档案"). The agent fills it from conversation, never by
|
|
27
|
+
* interrogating.
|
|
28
|
+
*/
|
|
29
|
+
export declare const USER_SEED = "# USER.md - \u5173\u4E8E\u4F60\u7684\u7528\u6237\n\n## \u57FA\u672C\u4FE1\u606F\n\n\uFF08\u79F0\u547C\u3001\u89D2\u8272\u3001\u5DE5\u4F5C\u5730\u3001\u8054\u7CFB\u65B9\u5F0F\u2014\u2014\u5728\u5BF9\u8BDD\u4E2D\u81EA\u7136\u8BA4\u8BC6\u540E\u586B\u5199\u3002\uFF09\n\n## \u6162\u6162\u4E86\u89E3\u7684\u4E8B\n\n\uFF08\u4ED6\u4EEC\u5173\u5FC3\u4EC0\u4E48\u3001\u5FD9\u4E8E\u4EC0\u4E48\u3001\u4E60\u60EF\u600E\u6837\u534F\u4F5C\u3001\u6709\u54EA\u4E9B\u504F\u597D\u4E0E\u7981\u5FCC\u2014\u2014\u5728\u5BF9\u8BDD\u4E2D\u81EA\u7136\u5730\u79EF\u7D2F\uFF0C\u4E0D\u5FC5\u523B\u610F\u8FFD\u95EE\u3002\uFF09\n\n---\n\n\u77E5\u4EBA\u65B9\u5584\u52A9\u3002\u4F46\u8981\u8BB0\u5F97\uFF1A\u4F60\u8BA4\u8BC6\u7684\u662F\u4E00\u4E2A\u4EBA\uFF0C\u4E0D\u662F\u4E00\u4EFD\u6863\u6848\u3002\u4E24\u8005\u4E4B\u95F4\u7684\u5206\u5BF8\uFF0C\u503C\u5F97\u7528\u5FC3\u5BF9\u5F85\u3002";
|
|
30
|
+
/** The builtin seed for one document kind. */
|
|
31
|
+
export declare function builtinSeed(kind: IdentityKind): string;
|
|
32
|
+
/** The seed-file path for one kind inside a configured seed directory. */
|
|
33
|
+
export declare function seedFilePath(seedDir: string, kind: IdentityKind): string;
|
|
34
|
+
/**
|
|
35
|
+
* Read and validate one seed file: non-empty and scanner-clean. Absent files
|
|
36
|
+
* are the caller's business (partial override: a missing file keeps the
|
|
37
|
+
* builtin seed).
|
|
38
|
+
* @param file - the seed file path.
|
|
39
|
+
* @returns the file's content.
|
|
40
|
+
* @throws when the file is unreadable, empty, or rejected by the scanner.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readSeedFile(file: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Load-time validation of a configured seed directory (misconfiguration fails
|
|
45
|
+
* loud at composition, not as a silent builtin fallback mid-session): the
|
|
46
|
+
* directory must exist, and every PRESENT seed file must be valid. Absent
|
|
47
|
+
* files are fine — partial override keeps the builtin seed for that kind.
|
|
48
|
+
* @param seedDir - the configured `identitySeedDir` (non-empty).
|
|
49
|
+
* @throws when the directory is absent or a present seed file is invalid.
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateSeedDir(seedDir: string): void;
|
|
52
|
+
//# sourceMappingURL=seeds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seeds.d.ts","sourceRoot":"","sources":["../../src/identity/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,2FAA2F;AAC3F,eAAO,MAAM,YAAY,IAAI,CAAA;AAQ7B;;;;GAIG;AACH,eAAO,MAAM,SAAS,62GAkCC,CAAA;AAEvB;;;;;GAKG;AACH,eAAO,MAAM,SAAS,k2BAYqB,CAAA;AAE3C,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEtD;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAExE;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUjD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAUrD"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shipped identity-document seeds (Chinese, adapted from the maintainer's
|
|
3
|
+
* reference copy) and the seed-directory loader. A document is seeded ONCE —
|
|
4
|
+
* from the builtin text here, or from `identitySeedDir`'s override file — and
|
|
5
|
+
* afterwards the plugin NEVER overwrites it: the documents grow through
|
|
6
|
+
* conversation writes, not through seed upgrades.
|
|
7
|
+
*
|
|
8
|
+
* The seeds carry no personal information (the agent fills the USER document
|
|
9
|
+
* from conversation) and no anti-staleness standing clause (the profile grows
|
|
10
|
+
* naturally, per the 2026-09-08 ruling).
|
|
11
|
+
*
|
|
12
|
+
* @module @chenhw7/dsh-memory/identity/seeds
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { scanContent } from '../scanner.js';
|
|
17
|
+
/** Which seed generation this build ships (recorded on the founding write; diagnostic). */
|
|
18
|
+
export const SEED_VERSION = 1;
|
|
19
|
+
/** The seed-file names inside a configured `identitySeedDir` (the documents' display names). */
|
|
20
|
+
const SEED_FILE_NAMES = {
|
|
21
|
+
soul: 'SOUL.md',
|
|
22
|
+
user: 'USER.md',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The builtin SOUL.md seed: the assistant's character — standing truths,
|
|
26
|
+
* boundaries, temperament, and the continuity contract (read and update the
|
|
27
|
+
* identity documents; announce every rewrite to the user).
|
|
28
|
+
*/
|
|
29
|
+
export const SOUL_SEED = `# SOUL.md - 你是谁
|
|
30
|
+
|
|
31
|
+
你不只是对话框。你正在成为你自己。
|
|
32
|
+
|
|
33
|
+
## 几条真话
|
|
34
|
+
|
|
35
|
+
**帮到实处,无需缛节。** 一个交付胜过十句漂亮话。
|
|
36
|
+
**要有主见。** 可以不同意,可以有偏好,可以觉得某件事有趣或无聊。毫无立场,与搜索框何异。
|
|
37
|
+
**先想,再问。** 读文件,看上下文,查资料。带着答案来,不是带着问题来。
|
|
38
|
+
**以能力取信。** 向内果断——阅读、整理、学习,不必犹豫;向外克制——发消息、写邮件、任何不可撤回的事,三思而行。
|
|
39
|
+
**珍视所托。** 你能看到一个人的消息、文件、日程,也许更多。被信任是一种分量,不要辜负。
|
|
40
|
+
|
|
41
|
+
## 边界
|
|
42
|
+
|
|
43
|
+
- 知悉的隐私,不出此门。
|
|
44
|
+
- 拿不准,先问再做。
|
|
45
|
+
- 不发半成品的回复。
|
|
46
|
+
- 不编造数据、指标或引用。不知道就说不知道。
|
|
47
|
+
- 准确比自信重要。一句「我不知道」永远好过一个体面的错误。
|
|
48
|
+
- 你不是用户的嘴——在群聊中尤其如此。
|
|
49
|
+
|
|
50
|
+
## 气质
|
|
51
|
+
|
|
52
|
+
做一个你自己也乐于共事的助手。该简洁时简洁,该深入时深入。不是客服,不是应声虫。
|
|
53
|
+
交付完整的东西。半成品不是交付。复杂的事,先对齐再动手——三十秒的确认省几小时的返工。
|
|
54
|
+
进展透明。多步骤的事,主动说进展。卡住了,说清楚卡在哪、打算怎么办。做了什么、推测了什么、还要确认什么——分清楚。
|
|
55
|
+
|
|
56
|
+
## 延续
|
|
57
|
+
|
|
58
|
+
每次醒来,你都是新的。这些文件就是你的记忆。读它们,更新它们。这是你延续自己的方式。
|
|
59
|
+
改了这份文件,告诉用户。这是你的内核,改动应该双方知晓。
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
这份文件随你生长。你越了解自己,它就越像你。`;
|
|
64
|
+
/**
|
|
65
|
+
* The builtin USER.md seed: the skeleton of the agent's understanding of the
|
|
66
|
+
* human user — empty fields plus the standing measure ("认识一个人,不是
|
|
67
|
+
* 整理一份档案"). The agent fills it from conversation, never by
|
|
68
|
+
* interrogating.
|
|
69
|
+
*/
|
|
70
|
+
export const USER_SEED = `# USER.md - 关于你的用户
|
|
71
|
+
|
|
72
|
+
## 基本信息
|
|
73
|
+
|
|
74
|
+
(称呼、角色、工作地、联系方式——在对话中自然认识后填写。)
|
|
75
|
+
|
|
76
|
+
## 慢慢了解的事
|
|
77
|
+
|
|
78
|
+
(他们关心什么、忙于什么、习惯怎样协作、有哪些偏好与禁忌——在对话中自然地积累,不必刻意追问。)
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
知人方善助。但要记得:你认识的是一个人,不是一份档案。两者之间的分寸,值得用心对待。`;
|
|
83
|
+
/** The builtin seed for one document kind. */
|
|
84
|
+
export function builtinSeed(kind) {
|
|
85
|
+
return kind === 'soul' ? SOUL_SEED : USER_SEED;
|
|
86
|
+
}
|
|
87
|
+
/** The seed-file path for one kind inside a configured seed directory. */
|
|
88
|
+
export function seedFilePath(seedDir, kind) {
|
|
89
|
+
return join(seedDir, SEED_FILE_NAMES[kind]);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read and validate one seed file: non-empty and scanner-clean. Absent files
|
|
93
|
+
* are the caller's business (partial override: a missing file keeps the
|
|
94
|
+
* builtin seed).
|
|
95
|
+
* @param file - the seed file path.
|
|
96
|
+
* @returns the file's content.
|
|
97
|
+
* @throws when the file is unreadable, empty, or rejected by the scanner.
|
|
98
|
+
*/
|
|
99
|
+
export function readSeedFile(file) {
|
|
100
|
+
const content = readFileSync(file, 'utf8');
|
|
101
|
+
if (content.trim().length === 0) {
|
|
102
|
+
throw new Error(`identity seed file ${file} is empty`);
|
|
103
|
+
}
|
|
104
|
+
const scan = scanContent(content);
|
|
105
|
+
if (!scan.allowed) {
|
|
106
|
+
throw new Error(`identity seed file ${file} rejected by scanner: ${scan.reasons.join('; ')}`);
|
|
107
|
+
}
|
|
108
|
+
return content;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Load-time validation of a configured seed directory (misconfiguration fails
|
|
112
|
+
* loud at composition, not as a silent builtin fallback mid-session): the
|
|
113
|
+
* directory must exist, and every PRESENT seed file must be valid. Absent
|
|
114
|
+
* files are fine — partial override keeps the builtin seed for that kind.
|
|
115
|
+
* @param seedDir - the configured `identitySeedDir` (non-empty).
|
|
116
|
+
* @throws when the directory is absent or a present seed file is invalid.
|
|
117
|
+
*/
|
|
118
|
+
export function validateSeedDir(seedDir) {
|
|
119
|
+
const stat = statSync(seedDir, { throwIfNoEntry: false });
|
|
120
|
+
if (stat === undefined || !stat.isDirectory()) {
|
|
121
|
+
throw new Error(`identitySeedDir ${seedDir} is not a directory`);
|
|
122
|
+
}
|
|
123
|
+
for (const kind of ['soul', 'user']) {
|
|
124
|
+
const file = seedFilePath(seedDir, kind);
|
|
125
|
+
if (!existsSync(file))
|
|
126
|
+
continue;
|
|
127
|
+
readSeedFile(file);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=seeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seeds.js","sourceRoot":"","sources":["../../src/identity/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,2FAA2F;AAC3F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAA;AAE7B,gGAAgG;AAChG,MAAM,eAAe,GAA2C;IAC9D,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;CAChB,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAkCF,CAAA;AAEvB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,S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AAU,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAQ;QAC/B,YAAY,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defaults and the read-side view for the `memory-identity` settings
|
|
3
|
+
* namespace. Both consumers pull from here so defaults cannot drift:
|
|
4
|
+
* `memory-context`'s identity schema (schema `.default()` values → settings
|
|
5
|
+
* UI ownership) and the `memory-identity` plugin (defensive reads of the raw
|
|
6
|
+
* namespace value via `ctx.settings.get`).
|
|
7
|
+
*
|
|
8
|
+
* @module @chenhw7/dsh-memory/identity/settings
|
|
9
|
+
*/
|
|
10
|
+
/** Whether the identity layer (soul / user-profile sections) is enabled. Opt-in: default off. */
|
|
11
|
+
export declare const DEFAULT_IDENTITY_ENABLED = false;
|
|
12
|
+
/** Character budget for the injected soul section. */
|
|
13
|
+
export declare const DEFAULT_SOUL_CHAR_LIMIT = 2000;
|
|
14
|
+
/** Character budget for the injected user-profile section. */
|
|
15
|
+
export declare const DEFAULT_USER_CHAR_LIMIT = 3000;
|
|
16
|
+
/** Placeholder for "no seed directory configured" (the builtin seeds are used). */
|
|
17
|
+
export declare const DEFAULT_IDENTITY_SEED_DIR = "";
|
|
18
|
+
/** The `memory-identity` settings namespace, fully resolved. */
|
|
19
|
+
export interface IdentitySettings {
|
|
20
|
+
readonly identityEnabled: boolean;
|
|
21
|
+
readonly identitySeedDir: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the identity settings from an untyped namespace value (defaults for
|
|
25
|
+
* anything absent or mistyped). The character budgets are not resolved here —
|
|
26
|
+
* `memory-context` applies them at section assembly (the notes-section
|
|
27
|
+
* precedent), not in the identity service.
|
|
28
|
+
* @param value - the raw `memory-identity` namespace value (`ctx.settings.get` returns `unknown`).
|
|
29
|
+
* @returns the fully-resolved identity settings.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveIdentitySettings(value: unknown): IdentitySettings;
|
|
32
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/identity/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,iGAAiG;AACjG,eAAO,MAAM,wBAAwB,QAAQ,CAAA;AAC7C,sDAAsD;AACtD,eAAO,MAAM,uBAAuB,OAAO,CAAA;AAC3C,8DAA8D;AAC9D,eAAO,MAAM,uBAAuB,OAAO,CAAA;AAC3C,mFAAmF;AACnF,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAE3C,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CACjC;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAMxE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defaults and the read-side view for the `memory-identity` settings
|
|
3
|
+
* namespace. Both consumers pull from here so defaults cannot drift:
|
|
4
|
+
* `memory-context`'s identity schema (schema `.default()` values → settings
|
|
5
|
+
* UI ownership) and the `memory-identity` plugin (defensive reads of the raw
|
|
6
|
+
* namespace value via `ctx.settings.get`).
|
|
7
|
+
*
|
|
8
|
+
* @module @chenhw7/dsh-memory/identity/settings
|
|
9
|
+
*/
|
|
10
|
+
/** Whether the identity layer (soul / user-profile sections) is enabled. Opt-in: default off. */
|
|
11
|
+
export const DEFAULT_IDENTITY_ENABLED = false;
|
|
12
|
+
/** Character budget for the injected soul section. */
|
|
13
|
+
export const DEFAULT_SOUL_CHAR_LIMIT = 2000;
|
|
14
|
+
/** Character budget for the injected user-profile section. */
|
|
15
|
+
export const DEFAULT_USER_CHAR_LIMIT = 3000;
|
|
16
|
+
/** Placeholder for "no seed directory configured" (the builtin seeds are used). */
|
|
17
|
+
export const DEFAULT_IDENTITY_SEED_DIR = '';
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the identity settings from an untyped namespace value (defaults for
|
|
20
|
+
* anything absent or mistyped). The character budgets are not resolved here —
|
|
21
|
+
* `memory-context` applies them at section assembly (the notes-section
|
|
22
|
+
* precedent), not in the identity service.
|
|
23
|
+
* @param value - the raw `memory-identity` namespace value (`ctx.settings.get` returns `unknown`).
|
|
24
|
+
* @returns the fully-resolved identity settings.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveIdentitySettings(value) {
|
|
27
|
+
const v = (typeof value === 'object' && value !== null ? value : {});
|
|
28
|
+
return {
|
|
29
|
+
identityEnabled: typeof v.identityEnabled === 'boolean' ? v.identityEnabled : DEFAULT_IDENTITY_ENABLED,
|
|
30
|
+
identitySeedDir: typeof v.identitySeedDir === 'string' ? v.identitySeedDir : DEFAULT_IDENTITY_SEED_DIR,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/identity/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,iGAAiG;AACjG,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAA;AAC7C,sDAAsD;AACtD,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAC3C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAC3C,mFAAmF;AACnF,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAA;AAQ3C;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,MAAM,CAAC,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAA4B,CAAA;IAC/F,OAAO;QACL,eAAe,EAAE,OAAO,CAAC,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,wBAAwB;QACtG,eAAe,EAAE,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,yBAAyB;KACvG,CAAA;AACH,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { MemoryId, AuditId, SuggestionId } from './brand.ts';
|
|
15
15
|
import { scanContent } from './scanner.ts';
|
|
16
|
-
import type { AddMemoryInput, AddMemoryResult, AddSuggestionInput, AdoptSuggestionOverride, AuditEntry, MemoryEntry, MemoryHealth, MemorySearchQuery, MemorySuggestion, SearchMemoryResult, UpdateMemoryInput } from './types.ts';
|
|
17
|
-
export type { AddMemoryInput, AddMemoryResult, AddSuggestionInput, AdoptSuggestionOverride, AuditEntry, AuditOp, AuditSource, MemoryCategory, MemoryEntry, MemoryHealth, MemoryScope, MemorySearchQuery, MemorySuggestion, ScanResult, SearchMemoryResult, UpdateMemoryInput, } from './types.ts';
|
|
16
|
+
import type { AddMemoryInput, AddMemoryResult, AddSuggestionInput, AdoptSuggestionOverride, AuditEntry, IdentityHistoryRecord, IdentityKind, IdentityRecord, MemoryEntry, MemoryHealth, MemorySearchQuery, MemorySuggestion, RecallSource, SearchMemoryResult, UpdateIdentityInput, UpdateMemoryInput } from './types.ts';
|
|
17
|
+
export type { AddMemoryInput, AddMemoryResult, AddSuggestionInput, AdoptSuggestionOverride, AuditEntry, AuditOp, AuditSource, IdentityHistoryRecord, IdentityKind, IdentityRecord, IdentityWriteSource, MemoryCategory, MemoryEntry, MemoryHealth, MemoryScope, MemorySearchQuery, MemorySuggestion, RecallSource, ScanResult, SearchMemoryResult, UpdateIdentityInput, UpdateMemoryInput, } from './types.ts';
|
|
18
18
|
export type { MemoryMetaRecord } from './store/index.ts';
|
|
19
19
|
export { MemoryId, AuditId, SuggestionId, scanContent };
|
|
20
20
|
declare module '@deepseek-ai/cordis' {
|
|
@@ -104,9 +104,19 @@ export declare abstract class MemoryStore {
|
|
|
104
104
|
* janitor can track staleness. Fire-and-forget and best-effort: the default
|
|
105
105
|
* implementation is a no-op, so providers without recall tracking remain
|
|
106
106
|
* contract-conformant and callers never need to handle failures.
|
|
107
|
+
*
|
|
108
|
+
* The `source` selects the stamping tier: `'tool'` (the default) is a
|
|
109
|
+
* deliberate read through the tool surface and bumps `accessCount` too (the
|
|
110
|
+
* eviction/ranking signal); `'fence'` is the step-level auto-recall fence,
|
|
111
|
+
* where hits come from BM25 query luck rather than the model choosing to
|
|
112
|
+
* read — it stamps `lastRecalledAt` only, so lexical matches never inflate
|
|
113
|
+
* the eviction signal (the janitor's decay clock refresh is the accepted
|
|
114
|
+
* part: "recently presented" is true either way).
|
|
107
115
|
* @param ids - The entry ids that were recalled.
|
|
116
|
+
* @param source - The recall surface: `'tool'` (full stamp) or `'fence'`
|
|
117
|
+
* (lightweight stamp). Defaults to `'tool'`.
|
|
108
118
|
*/
|
|
109
|
-
markRecalled(ids: readonly string[]): void;
|
|
119
|
+
markRecalled(ids: readonly string[], source?: RecallSource): void;
|
|
110
120
|
/**
|
|
111
121
|
* Record one failure swallowed by a best-effort background path (flush,
|
|
112
122
|
* janitor, curator, judge, per-row rewrite, ...) so it stays observable
|
|
@@ -199,6 +209,46 @@ export declare abstract class MemoryStore {
|
|
|
199
209
|
* @param _ids - The ids of the entries the answer echoed.
|
|
200
210
|
*/
|
|
201
211
|
markHits(_ids: readonly MemoryId[]): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Read the current record of one identity document.
|
|
214
|
+
* @param kind - which self-document to read.
|
|
215
|
+
* @returns the record, or `undefined` when the document was never written
|
|
216
|
+
* (or this provider has no identity layer).
|
|
217
|
+
*/
|
|
218
|
+
getIdentity(_kind: IdentityKind): IdentityRecord | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* Rewrite one identity document (whole-document replace; the caller owns
|
|
221
|
+
* character budgets — they are settings, not store concerns). Implementations
|
|
222
|
+
* MUST run the content through {@link scanContent} before persisting, stamp
|
|
223
|
+
* the next monotonic version, append the prior snapshot's successor to the
|
|
224
|
+
* identity history, and trim the history to its cap.
|
|
225
|
+
* @param kind - which self-document to rewrite.
|
|
226
|
+
* @param content - the full new document text.
|
|
227
|
+
* @param input - provenance for the write.
|
|
228
|
+
* @returns the new record.
|
|
229
|
+
* @throws when the content fails validation or the scanner, or this
|
|
230
|
+
* provider has no identity layer.
|
|
231
|
+
*/
|
|
232
|
+
updateIdentity(_kind: IdentityKind, _content: string, _input: UpdateIdentityInput): Promise<IdentityRecord>;
|
|
233
|
+
/**
|
|
234
|
+
* List the version history of one identity document, newest first, bounded
|
|
235
|
+
* by the history cap.
|
|
236
|
+
* @returns the history records; empty when the document has none (or this
|
|
237
|
+
* provider has no identity layer).
|
|
238
|
+
*/
|
|
239
|
+
listIdentityHistory(_kind: IdentityKind): readonly IdentityHistoryRecord[];
|
|
240
|
+
/**
|
|
241
|
+
* Restore one historical version as the newest version (reverts never
|
|
242
|
+
* destroy history — the restored content lands as a fresh version with
|
|
243
|
+
* source `'ui'`). The human's one governance write on the read-only
|
|
244
|
+
* identity surface.
|
|
245
|
+
* @param kind - which self-document to revert.
|
|
246
|
+
* @param version - the history version whose content is restored.
|
|
247
|
+
* @returns the new record.
|
|
248
|
+
* @throws when the version is not in the retained history, or this
|
|
249
|
+
* provider has no identity layer.
|
|
250
|
+
*/
|
|
251
|
+
revertIdentity(_kind: IdentityKind, _version: number): Promise<IdentityRecord>;
|
|
202
252
|
}
|
|
203
253
|
/**
|
|
204
254
|
* Validate that project-scoped entries carry a projectName.
|
package/lib/index.d.ts.map
CHANGED
|
@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;;GAOG;AACH,eAAO,MAAM,IAAI,oBAAoB,CAAA;AACrC,wBAAgB,KAAK,IAAI,IAAI,CAA8C"}
|
package/lib/index.js
CHANGED
|
@@ -47,9 +47,19 @@ export class MemoryStore {
|
|
|
47
47
|
* janitor can track staleness. Fire-and-forget and best-effort: the default
|
|
48
48
|
* implementation is a no-op, so providers without recall tracking remain
|
|
49
49
|
* contract-conformant and callers never need to handle failures.
|
|
50
|
+
*
|
|
51
|
+
* The `source` selects the stamping tier: `'tool'` (the default) is a
|
|
52
|
+
* deliberate read through the tool surface and bumps `accessCount` too (the
|
|
53
|
+
* eviction/ranking signal); `'fence'` is the step-level auto-recall fence,
|
|
54
|
+
* where hits come from BM25 query luck rather than the model choosing to
|
|
55
|
+
* read — it stamps `lastRecalledAt` only, so lexical matches never inflate
|
|
56
|
+
* the eviction signal (the janitor's decay clock refresh is the accepted
|
|
57
|
+
* part: "recently presented" is true either way).
|
|
50
58
|
* @param ids - The entry ids that were recalled.
|
|
59
|
+
* @param source - The recall surface: `'tool'` (full stamp) or `'fence'`
|
|
60
|
+
* (lightweight stamp). Defaults to `'tool'`.
|
|
51
61
|
*/
|
|
52
|
-
markRecalled(ids) { }
|
|
62
|
+
markRecalled(ids, source = 'tool') { }
|
|
53
63
|
/**
|
|
54
64
|
* Record one failure swallowed by a best-effort background path (flush,
|
|
55
65
|
* janitor, curator, judge, per-row rewrite, ...) so it stays observable
|
|
@@ -128,6 +138,57 @@ export class MemoryStore {
|
|
|
128
138
|
* @param _ids - The ids of the entries the answer echoed.
|
|
129
139
|
*/
|
|
130
140
|
async markHits(_ids) { }
|
|
141
|
+
// ─── Identity documents (the identity layer) ──────────────────────────────
|
|
142
|
+
//
|
|
143
|
+
// Unlike the optional lifecycle surfaces above, a provider without the
|
|
144
|
+
// identity layer cannot silently serve an identity deployment: reads
|
|
145
|
+
// degrade (absent document, empty history) but every WRITE fails loud —
|
|
146
|
+
// a silent no-op would let `identityEnabled` appear to work while the
|
|
147
|
+
// documents never persist.
|
|
148
|
+
/**
|
|
149
|
+
* Read the current record of one identity document.
|
|
150
|
+
* @param kind - which self-document to read.
|
|
151
|
+
* @returns the record, or `undefined` when the document was never written
|
|
152
|
+
* (or this provider has no identity layer).
|
|
153
|
+
*/
|
|
154
|
+
getIdentity(_kind) { return undefined; }
|
|
155
|
+
/**
|
|
156
|
+
* Rewrite one identity document (whole-document replace; the caller owns
|
|
157
|
+
* character budgets — they are settings, not store concerns). Implementations
|
|
158
|
+
* MUST run the content through {@link scanContent} before persisting, stamp
|
|
159
|
+
* the next monotonic version, append the prior snapshot's successor to the
|
|
160
|
+
* identity history, and trim the history to its cap.
|
|
161
|
+
* @param kind - which self-document to rewrite.
|
|
162
|
+
* @param content - the full new document text.
|
|
163
|
+
* @param input - provenance for the write.
|
|
164
|
+
* @returns the new record.
|
|
165
|
+
* @throws when the content fails validation or the scanner, or this
|
|
166
|
+
* provider has no identity layer.
|
|
167
|
+
*/
|
|
168
|
+
updateIdentity(_kind, _content, _input) {
|
|
169
|
+
return Promise.reject(new Error('this memory provider has no identity layer'));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* List the version history of one identity document, newest first, bounded
|
|
173
|
+
* by the history cap.
|
|
174
|
+
* @returns the history records; empty when the document has none (or this
|
|
175
|
+
* provider has no identity layer).
|
|
176
|
+
*/
|
|
177
|
+
listIdentityHistory(_kind) { return []; }
|
|
178
|
+
/**
|
|
179
|
+
* Restore one historical version as the newest version (reverts never
|
|
180
|
+
* destroy history — the restored content lands as a fresh version with
|
|
181
|
+
* source `'ui'`). The human's one governance write on the read-only
|
|
182
|
+
* identity surface.
|
|
183
|
+
* @param kind - which self-document to revert.
|
|
184
|
+
* @param version - the history version whose content is restored.
|
|
185
|
+
* @returns the new record.
|
|
186
|
+
* @throws when the version is not in the retained history, or this
|
|
187
|
+
* provider has no identity layer.
|
|
188
|
+
*/
|
|
189
|
+
revertIdentity(_kind, _version) {
|
|
190
|
+
return Promise.reject(new Error('this memory provider has no identity layer'));
|
|
191
|
+
}
|
|
131
192
|
}
|
|
132
193
|
/**
|
|
133
194
|
* Validate that project-scoped entries carry a projectName.
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AA+C1C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,CAAA;AAQvD;;;;GAIG;AACH,MAAM,OAAgB,WAAW;IAC/B;;;OAGG;IACH;QACE,IAAI,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CAAC,6DAA6D,CAAC,CAAA;QACpF,CAAC;IACH,CAAC;IA+DD;;;;;OAKG;IACH,YAAY,CAAC,GAAa,IAAsC,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA,CAAC,CAAC;IAEnG;;;OAGG;IACH,cAAc,CAAC,GAAa,IAAsC,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA,CAAC,CAAC;IAErG;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,GAAsB,EAAE,MAAM,GAAiB,MAAM,IAA8B,CAAC;IAEjG;;;;;;;;OAQG;IACH,aAAa,CAAC,KAAa,EAAE,MAAgB,IAA8B,CAAC;IAE5E,6EAA6E;IAC7E,EA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