@sparkelf/dsh-knowledge-base 0.6.1 → 0.6.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.
@@ -1,20 +1,34 @@
1
1
  import type { GraphManifest, LoadedGraph, MemoryAuthority, MemoryOrigin, MemoryReviewStatus } from './graphModel.ts';
2
2
  import { type GraphScopeDescriptor, type GraphViewer } from './graphPolicy.ts';
3
3
  import { type BindingSourceType, type BindingStatus, type PersonalBinding } from './memoryBindings.ts';
4
+ import type { Privacy } from './memoryTypes.ts';
4
5
  /** Default prompt budget for the resolved context. */
5
6
  export declare const DEFAULT_MEMORY_CONTEXT_MAX_CHARS = 8000;
6
7
  /** Marker the runtime must treat as above personal memory and preferences. */
7
8
  export declare const SYSTEM_POLICY_MARKER = "system policy overrides personal memory";
8
- /** How a memory entry reaches the personal graph. */
9
- export type MemoryContextMode = 'subscribe' | 'internalize';
10
- /** One resolved node/edge the runtime may inject. */
9
+ /**
10
+ * How a memory entry reaches the personal graph.
11
+ *
12
+ * `personal` is the user's own `MemoryStore` snapshot (`偏好.md`, `踩坑.md`,
13
+ * `事实.md`, `SOP/`, daily logs). It has no binding and no graph-side authority:
14
+ * it is always advisory, so it can never outrank a department/global redline.
15
+ *
16
+ * `shared` is an approved department/global promotion read from the scope's
17
+ * `记忆共享/` graph. It needs no binding either, but unlike personal memory it is
18
+ * published policy-shaped content: still advisory, still below redline/canonical,
19
+ * yet kept when the user pauses personal memory.
20
+ */
21
+ export type MemoryContextMode = 'subscribe' | 'internalize' | 'personal' | 'shared';
22
+ /** Where one resolved context entry came from. */
23
+ export type MemoryContextSourceType = BindingSourceType | 'entry';
24
+ /** One resolved node/edge/memory the runtime may inject. */
11
25
  export interface MemoryContextEntry {
12
26
  mode: MemoryContextMode;
13
27
  graphId: string;
14
- sourceType: BindingSourceType;
28
+ sourceType: MemoryContextSourceType;
15
29
  sourceId: string;
16
30
  title: string;
17
- /** Node type or relation type. */
31
+ /** Node type, relation type, or memory type. */
18
32
  type: string;
19
33
  authority: MemoryAuthority;
20
34
  origin: MemoryOrigin;
@@ -31,6 +45,12 @@ export interface MemoryContextEntry {
31
45
  /** Relation endpoints, when the source is an edge. */
32
46
  from?: string;
33
47
  to?: string;
48
+ /** Personal-memory privacy label; absent on graph bindings. */
49
+ privacy?: Privacy;
50
+ /** `global` or `department:<code>` for a shared-memory document. */
51
+ scope?: string;
52
+ /** Last update of a personal entry; absent on graph bindings. */
53
+ updatedAt?: string;
34
54
  body: string;
35
55
  /** Budget cost used by this resolver (title + body + fixed metadata overhead). */
36
56
  chars: number;
@@ -38,7 +58,7 @@ export interface MemoryContextEntry {
38
58
  /** One entry omitted only because the character budget ran out. */
39
59
  export interface MemoryContextDrop {
40
60
  graphId: string;
41
- sourceType: BindingSourceType;
61
+ sourceType: MemoryContextSourceType;
42
62
  sourceId: string;
43
63
  mode: MemoryContextMode;
44
64
  chars: number;
@@ -52,6 +72,10 @@ export interface MemoryContextResult {
52
72
  charCount: number;
53
73
  maxChars: number;
54
74
  redlineCount: number;
75
+ /** Number of selected entries that came from the caller's own `MemoryStore`. */
76
+ personalCount: number;
77
+ /** Number of selected entries read from a department/global `记忆共享/` graph. */
78
+ sharedCount: number;
55
79
  /** Non-empty when at least one redline is present. */
56
80
  systemPolicy: string;
57
81
  }
@@ -63,6 +87,24 @@ export interface MemoryContextInput {
63
87
  graphs: LoadedGraph[];
64
88
  /** Pre-read bindings, for callers that already listed them. Omit to rebuild from disk. */
65
89
  bindings?: PersonalBinding[];
90
+ /**
91
+ * Absolute root of the caller's own personal memory tree
92
+ * (`<actualRoot>/personal/<userId>/个人记忆图谱`).
93
+ *
94
+ * The Host builds this from the authenticated user id; this resolver never
95
+ * searches sibling user roots. Omit to keep bindings-only behavior (for
96
+ * example a paused memory setting).
97
+ */
98
+ personalMemoryRoot?: string;
99
+ /**
100
+ * Personal memory is paused for this caller.
101
+ *
102
+ * Design §22.2: pausing stops personal memory from influencing answers, but
103
+ * department/global policy — and every redline — still applies. The resolver
104
+ * therefore skips the caller's internalized branches and personal store while
105
+ * keeping department/global subscriptions and shared memory.
106
+ */
107
+ paused?: boolean;
66
108
  /** Prompt budget; defaults to {@link DEFAULT_MEMORY_CONTEXT_MAX_CHARS}. */
67
109
  maxChars?: number;
68
110
  }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Display projection shared by the memory page and the model-facing context.
3
+ *
4
+ * The memory page caps a row title at 24 characters and hides internal words
5
+ * (tool names, paths, session ids) behind neutral fallbacks. `memory_context`
6
+ * must show the same title for the same entry, otherwise a user comparing the
7
+ * page with the model's answer sees two names for one memory. Keeping the
8
+ * heuristics here is what makes "the list and the context agree" a property of
9
+ * the data rather than of two copies that happen to match today.
10
+ *
11
+ * Nothing in this module reads or writes the filesystem; it is a pure
12
+ * projection over one parsed entry.
13
+ *
14
+ * @module @sparkelf/dsh-knowledge-base/memory-display
15
+ */
16
+ import type { AnyMemoryEntry } from './memoryTypes.ts';
17
+ /** Title budget for one memory row (design §22.3: short, ≤20 characters). */
18
+ export declare const MEMORY_TITLE_MAX_CHARS = 24;
19
+ /** Collapse whitespace and cap one display line. */
20
+ export declare function clipMemoryLine(value: string, max?: number): string;
21
+ /** A technical token that should never be the first thing a reader sees in a row. */
22
+ export declare function looksTechnicalMemoryValue(value: string): boolean;
23
+ /** Short, non-technical fallback for entries written before displayTitle existed. */
24
+ export declare function memoryEntryFallbackTitle(entry: AnyMemoryEntry): string;
25
+ /** The table's 「记忆」 column: a short user-facing title, never an internal id. */
26
+ export declare function memoryEntryTitle(entry: AnyMemoryEntry): string;
27
+ /** The detail drawer's editable content, in a type-appropriate shape. */
28
+ export declare function memoryEntryContent(entry: AnyMemoryEntry): string;
29
+ /**
30
+ * Display source label. The snapshot written at record time wins; then the
31
+ * scenario/app the guardian knew; only then the neutral label. A raw session id
32
+ * is never used as the label.
33
+ */
34
+ export declare function memoryEntrySourceLabel(entry: AnyMemoryEntry): string;
35
+ /** When the remembered thing happened; falls back to `createdAt`. */
36
+ export declare function memoryEntrySourceTime(entry: AnyMemoryEntry): string;
37
+ /** Last update, used for deterministic ordering. */
38
+ export declare function memoryEntryUpdatedAt(entry: AnyMemoryEntry): string;
@@ -0,0 +1,57 @@
1
+ import type { LoadedGraph, MemoryAuthority, MemoryOrigin, MemoryReviewStatus } from './graphModel.ts';
2
+ import { type Privacy } from './memoryTypes.ts';
3
+ /** The caller fields the shared scope roots are derived from. */
4
+ export interface SharedMemoryCaller {
5
+ departmentCode?: string;
6
+ departmentPathCodes?: readonly string[];
7
+ }
8
+ /** One scope root that may hold a shared-memory graph. */
9
+ export interface SharedMemoryScopeRoot {
10
+ scope: 'global' | 'department';
11
+ /** Scope-relative root without a trailing slash (`global`, `department/A/B`). */
12
+ relPath: string;
13
+ /** Leaf department code for a department root. */
14
+ departmentCode?: string;
15
+ }
16
+ /**
17
+ * The shared-memory scope roots a caller may own content under.
18
+ *
19
+ * `global` is always a candidate (subject to `canRead`); the department root is
20
+ * the caller's own organization chain, never a sibling. Order is global first,
21
+ * then department, so the rendered context is deterministic.
22
+ *
23
+ * @param caller - the authenticated caller's department projection.
24
+ * @returns Scope roots in a stable order.
25
+ */
26
+ export declare function sharedMemoryScopeRoots(caller: SharedMemoryCaller): SharedMemoryScopeRoot[];
27
+ /** One shared document a caller may inject, before context-level dedupe/sort. */
28
+ export interface SharedMemoryCandidate {
29
+ /** Node id (`mem-mp-…`); also the dedupe key against a subscription binding. */
30
+ id: string;
31
+ title: string;
32
+ /** Graph node type (`topic`, `fact`, `case`, `procedure`, `policy`, `skill`). */
33
+ type: string;
34
+ authority: MemoryAuthority;
35
+ origin: MemoryOrigin;
36
+ reviewStatus: MemoryReviewStatus;
37
+ privacy: Privacy;
38
+ /** Scope-relative document path (`记忆共享/<id>.md`). */
39
+ path: string;
40
+ /** `global` or `department:<code>` from the manifest. */
41
+ scope: string;
42
+ status: 'active';
43
+ version: number;
44
+ body: string;
45
+ }
46
+ /**
47
+ * Read every injectable node of one shared-memory graph.
48
+ *
49
+ * A missing or unreadable document is skipped (fail soft): one broken promotion
50
+ * must not hide a redline or fail the whole context. A graph that is not the
51
+ * shared-memory graph, or whose manifest scope is neither `global` nor
52
+ * `department:<code>`, contributes nothing.
53
+ *
54
+ * @param graph - the loaded graph; its `root` must be the scope root.
55
+ * @returns Candidates in manifest node order, already privacy-filtered.
56
+ */
57
+ export declare function readSharedMemoryCandidates(graph: LoadedGraph): Promise<SharedMemoryCandidate[]>;
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * `memory_context` is read-only. It resolves the caller's personal binding
5
5
  * projection through {@link resolveMemoryContext}: live proxies for subscribed
6
- * sources, the user's own branch for internalized sources, redlines marked
7
- * non-overridable, and a deterministic budget. It never writes.
6
+ * sources, the user's own branch for internalized sources, the current entries
7
+ * of the user's own `MemoryStore`, redlines marked non-overridable, and a
8
+ * deterministic budget. It never writes.
8
9
  *
9
10
  * `memory_guardian_run` is the manual trigger for the guardian pass. It is a
10
11
  * maintenance action, not a read: it refreshes `sourceVersion`/`sourceCommit`,
@@ -33,8 +34,22 @@ export interface MemoryToolHost {
33
34
  resolveCaller(): Promise<GraphViewer>;
34
35
  /** Root of `<usersRoot>/<userId>/bindings`; supplied by plugin configuration. */
35
36
  usersRoot: string;
37
+ /**
38
+ * Absolute root of the caller's own personal `MemoryStore`
39
+ * (`<actualRoot>/personal/<userId>/个人记忆图谱`). The Host builds it from the
40
+ * authenticated user id; omitting it keeps a bindings-only context.
41
+ */
42
+ personalMemoryRoot?(viewer: GraphViewer): string;
36
43
  /** Every graph the caller may read. Implementations must not return a denied graph. */
37
44
  loadGraphs(viewer: GraphViewer): Promise<LoadedGraph[]>;
45
+ /**
46
+ * Department/global shared-memory graphs the caller may read (`shared-memory`
47
+ * under the caller's own department chain and the global scope).
48
+ *
49
+ * This is a separate seam from {@link loadGraphs} so the guardian pass keeps its
50
+ * existing graph scope: shared memory is runtime context, not a graph to bind.
51
+ */
52
+ loadSharedGraphs?(viewer: GraphViewer): Promise<LoadedGraph[]>;
38
53
  /** Whether the caller holds the memory-management capability (`kb:config:manage`). */
39
54
  canManage(viewer: GraphViewer): Promise<boolean> | boolean;
40
55
  /** Whether personal memory is enabled for this caller; a paused user gets no personal entries. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-knowledge-base",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "DataOps-backed knowledge base for DeepSeek Harness: a left-sidebar destination, Settings configuration, and index tooling over a mounted NAS view.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",