@sparkelf/dsh-knowledge-base 0.6.0 → 0.6.2
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.md +30 -8
- package/lib/client.js +1101 -643
- package/lib/client.js.map +1 -1
- package/lib/index.js +3657 -2701
- package/lib/types/client/KnowledgeMemory.d.ts +63 -0
- package/lib/types/client/locales.d.ts +27 -0
- package/lib/types/memoryContext.d.ts +30 -6
- package/lib/types/memoryDisplay.d.ts +38 -0
- package/lib/types/memoryPromotion.d.ts +180 -0
- package/lib/types/memoryPromotionRoutes.d.ts +80 -0
- package/lib/types/memoryTools.d.ts +9 -2
- package/package.json +1 -1
|
@@ -58,6 +58,65 @@ export interface MemoryListSnapshot {
|
|
|
58
58
|
entries: MemoryEntryView[];
|
|
59
59
|
error?: string;
|
|
60
60
|
}
|
|
61
|
+
/** One promotion as the page shows it. */
|
|
62
|
+
export interface MemoryPromotionView {
|
|
63
|
+
id: string;
|
|
64
|
+
memoryId: string;
|
|
65
|
+
title?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
/** Promoted body; the review row shows a bounded preview. */
|
|
68
|
+
content?: string;
|
|
69
|
+
status: 'pending' | 'approved' | 'rejected';
|
|
70
|
+
targetScope: 'department' | 'global';
|
|
71
|
+
departmentCode?: string;
|
|
72
|
+
requestedAt?: string;
|
|
73
|
+
reviewedAt?: string;
|
|
74
|
+
reviewNote?: string;
|
|
75
|
+
selfApproval?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** One queued promotion plus whether this reviewer submitted it. */
|
|
78
|
+
export interface MemoryReviewItem {
|
|
79
|
+
promotion: MemoryPromotionView;
|
|
80
|
+
selfApproval: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** One read-only department/global memory row. */
|
|
83
|
+
export interface SharedMemoryView {
|
|
84
|
+
id: string;
|
|
85
|
+
title: string;
|
|
86
|
+
type?: string;
|
|
87
|
+
content?: string;
|
|
88
|
+
scope: 'department' | 'global';
|
|
89
|
+
departmentCode?: string;
|
|
90
|
+
promotedAt?: string;
|
|
91
|
+
promotedBy?: string;
|
|
92
|
+
}
|
|
93
|
+
/** The promotion state the page renders; absent on a caller without review access. */
|
|
94
|
+
export interface MemoryPromotionUiState {
|
|
95
|
+
promotions: MemoryPromotionView[];
|
|
96
|
+
reviewQueue: MemoryReviewItem[];
|
|
97
|
+
shared: SharedMemoryView[];
|
|
98
|
+
canPromoteGlobal: boolean;
|
|
99
|
+
canPromoteDepartments: string[];
|
|
100
|
+
canReview: boolean;
|
|
101
|
+
busy: boolean;
|
|
102
|
+
error?: string;
|
|
103
|
+
notice?: string;
|
|
104
|
+
/** Open target picker, when the user asked to promote one memory. */
|
|
105
|
+
target?: {
|
|
106
|
+
entry: MemoryEntryView;
|
|
107
|
+
scope: 'department' | 'global';
|
|
108
|
+
confirm: boolean;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** Callbacks the container owns for the promotion surface. */
|
|
112
|
+
export interface MemoryPromotionActions {
|
|
113
|
+
onStart: (entry: MemoryEntryView) => void;
|
|
114
|
+
onCancel: () => void;
|
|
115
|
+
onScopeChange: (scope: 'department' | 'global') => void;
|
|
116
|
+
onConfirmChange: (confirm: boolean) => void;
|
|
117
|
+
onSubmit: () => void;
|
|
118
|
+
onReview: (id: string, decision: 'approve' | 'reject') => void;
|
|
119
|
+
}
|
|
61
120
|
/** Props for the pure memory renderer. */
|
|
62
121
|
export interface KnowledgeMemoryViewProps {
|
|
63
122
|
t: (key: string) => string;
|
|
@@ -115,6 +174,10 @@ export interface KnowledgeMemoryViewProps {
|
|
|
115
174
|
onRetryList: () => void;
|
|
116
175
|
/** Open the source conversation; omitted hides 查看原文. */
|
|
117
176
|
onOpenSource?: (entry: MemoryEntryView) => void;
|
|
177
|
+
/** Promotion state; omitted hides the promotion surface entirely. */
|
|
178
|
+
promotion?: MemoryPromotionUiState;
|
|
179
|
+
/** Promotion handlers; required only when `promotion` is supplied. */
|
|
180
|
+
promotionActions?: MemoryPromotionActions;
|
|
118
181
|
}
|
|
119
182
|
/** Props for the stateful memory page. */
|
|
120
183
|
export interface KnowledgeMemoryProps {
|
|
@@ -743,6 +743,33 @@ export declare const en: {
|
|
|
743
743
|
readonly memoryForgetBody: "The memory will no longer appear or affect later answers. It cannot be undone from this page.";
|
|
744
744
|
readonly memoryForgetConfirm: "Forget";
|
|
745
745
|
readonly memoryForgetFailed: "Could not forget this memory.";
|
|
746
|
+
readonly memoryActionPromote: "Promote";
|
|
747
|
+
readonly memoryPromotionPending: "Pending review";
|
|
748
|
+
readonly memoryPromotionApproved: "Promoted";
|
|
749
|
+
readonly memoryPromotionRejected: "Rejected";
|
|
750
|
+
readonly memoryPromotionNone: "—";
|
|
751
|
+
readonly memoryPromotionTargetGlobal: "Global";
|
|
752
|
+
readonly memoryPromotionTargetDepartment: "Department";
|
|
753
|
+
readonly memoryPromotionTarget: "Target";
|
|
754
|
+
readonly memoryPromotionRequested: "Requested";
|
|
755
|
+
readonly memoryReviewTitle: "Promotion requests";
|
|
756
|
+
readonly memoryReviewHint: "Approving copies the memory into the department or global shared memory. You cannot approve your own request.";
|
|
757
|
+
readonly memoryReviewApprove: "Approve";
|
|
758
|
+
readonly memoryReviewReject: "Reject";
|
|
759
|
+
readonly memoryReviewSelfApproval: "Another administrator must approve your own request.";
|
|
760
|
+
readonly memoryReviewApproved: "Approved and promoted.";
|
|
761
|
+
readonly memoryReviewRejected: "Rejected.";
|
|
762
|
+
readonly memorySharedTitle: "Department and global memory";
|
|
763
|
+
readonly memorySharedHint: "Read-only memory promoted by an administrator; personal memories are never listed here.";
|
|
764
|
+
readonly memoryPromoteTitle: "Promote memory";
|
|
765
|
+
readonly memoryPromoteTarget: "Target";
|
|
766
|
+
readonly memoryPromoteSubmit: "Submit for review";
|
|
767
|
+
readonly memoryPromoteConfirmNow: "Promote now";
|
|
768
|
+
readonly memoryPromoteConfirmLabel: "Promote immediately (administrator confirmation)";
|
|
769
|
+
readonly memoryPromoteConfirmHint: "The memory is copied to the target scope now and the action is recorded in the audit trail.";
|
|
770
|
+
readonly memoryPromoteReviewHint: "The request waits for another administrator to review it.";
|
|
771
|
+
readonly memoryPromoteApplied: "Promoted.";
|
|
772
|
+
readonly memoryPromotePending: "Submitted for review.";
|
|
746
773
|
};
|
|
747
774
|
/** Stable key set shared by every knowledge-base locale. */
|
|
748
775
|
export type KnowledgeKey = keyof typeof en;
|
|
@@ -1,20 +1,29 @@
|
|
|
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
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
export type MemoryContextMode = 'subscribe' | 'internalize' | 'personal';
|
|
17
|
+
/** Where one resolved context entry came from. */
|
|
18
|
+
export type MemoryContextSourceType = BindingSourceType | 'entry';
|
|
19
|
+
/** One resolved node/edge/memory the runtime may inject. */
|
|
11
20
|
export interface MemoryContextEntry {
|
|
12
21
|
mode: MemoryContextMode;
|
|
13
22
|
graphId: string;
|
|
14
|
-
sourceType:
|
|
23
|
+
sourceType: MemoryContextSourceType;
|
|
15
24
|
sourceId: string;
|
|
16
25
|
title: string;
|
|
17
|
-
/** Node type or
|
|
26
|
+
/** Node type, relation type, or memory type. */
|
|
18
27
|
type: string;
|
|
19
28
|
authority: MemoryAuthority;
|
|
20
29
|
origin: MemoryOrigin;
|
|
@@ -31,6 +40,10 @@ export interface MemoryContextEntry {
|
|
|
31
40
|
/** Relation endpoints, when the source is an edge. */
|
|
32
41
|
from?: string;
|
|
33
42
|
to?: string;
|
|
43
|
+
/** Personal-memory privacy label; absent on graph bindings. */
|
|
44
|
+
privacy?: Privacy;
|
|
45
|
+
/** Last update of a personal entry; absent on graph bindings. */
|
|
46
|
+
updatedAt?: string;
|
|
34
47
|
body: string;
|
|
35
48
|
/** Budget cost used by this resolver (title + body + fixed metadata overhead). */
|
|
36
49
|
chars: number;
|
|
@@ -38,7 +51,7 @@ export interface MemoryContextEntry {
|
|
|
38
51
|
/** One entry omitted only because the character budget ran out. */
|
|
39
52
|
export interface MemoryContextDrop {
|
|
40
53
|
graphId: string;
|
|
41
|
-
sourceType:
|
|
54
|
+
sourceType: MemoryContextSourceType;
|
|
42
55
|
sourceId: string;
|
|
43
56
|
mode: MemoryContextMode;
|
|
44
57
|
chars: number;
|
|
@@ -52,6 +65,8 @@ export interface MemoryContextResult {
|
|
|
52
65
|
charCount: number;
|
|
53
66
|
maxChars: number;
|
|
54
67
|
redlineCount: number;
|
|
68
|
+
/** Number of selected entries that came from the caller's own `MemoryStore`. */
|
|
69
|
+
personalCount: number;
|
|
55
70
|
/** Non-empty when at least one redline is present. */
|
|
56
71
|
systemPolicy: string;
|
|
57
72
|
}
|
|
@@ -63,6 +78,15 @@ export interface MemoryContextInput {
|
|
|
63
78
|
graphs: LoadedGraph[];
|
|
64
79
|
/** Pre-read bindings, for callers that already listed them. Omit to rebuild from disk. */
|
|
65
80
|
bindings?: PersonalBinding[];
|
|
81
|
+
/**
|
|
82
|
+
* Absolute root of the caller's own personal memory tree
|
|
83
|
+
* (`<actualRoot>/personal/<userId>/个人记忆图谱`).
|
|
84
|
+
*
|
|
85
|
+
* The Host builds this from the authenticated user id; this resolver never
|
|
86
|
+
* searches sibling user roots. Omit to keep bindings-only behavior (for
|
|
87
|
+
* example a paused memory setting).
|
|
88
|
+
*/
|
|
89
|
+
personalMemoryRoot?: string;
|
|
66
90
|
/** Prompt budget; defaults to {@link DEFAULT_MEMORY_CONTEXT_MAX_CHARS}. */
|
|
67
91
|
maxChars?: number;
|
|
68
92
|
}
|
|
@@ -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,180 @@
|
|
|
1
|
+
import type { AnyMemoryEntry, MemoryType, Privacy } from './memoryTypes.ts';
|
|
2
|
+
import type { ListedMemoryEntry } from './memoryStore.ts';
|
|
3
|
+
/** The two scopes a personal memory may be promoted into. */
|
|
4
|
+
export declare const PROMOTION_TARGET_SCOPES: readonly ["department", "global"];
|
|
5
|
+
export type PromotionTargetScope = typeof PROMOTION_TARGET_SCOPES[number];
|
|
6
|
+
/** Review lifecycle. `approved` and `rejected` are terminal. */
|
|
7
|
+
export declare const PROMOTION_STATUSES: readonly ["pending", "approved", "rejected"];
|
|
8
|
+
export type PromotionStatus = typeof PROMOTION_STATUSES[number];
|
|
9
|
+
/** Graph id that owns promoted department/global memory inside one scope. */
|
|
10
|
+
export declare const SHARED_MEMORY_GRAPH_ID = "shared-memory";
|
|
11
|
+
/** Folder (relative to the scope root) that holds one document per promotion. */
|
|
12
|
+
export declare const SHARED_MEMORY_FOLDER = "\u8BB0\u5FC6\u5171\u4EAB";
|
|
13
|
+
/** Display name per graph scope. */
|
|
14
|
+
export declare function sharedMemoryGraphName(scope: PromotionTargetScope): string;
|
|
15
|
+
/** A structured refusal the route maps to a status code. */
|
|
16
|
+
export declare class MemoryPromotionError extends Error {
|
|
17
|
+
readonly code: 'invalid' | 'forbidden' | 'not-found' | 'conflict' | 'privacy' | 'invalid-graph' | 'io';
|
|
18
|
+
readonly name = "MemoryPromotionError";
|
|
19
|
+
constructor(code: 'invalid' | 'forbidden' | 'not-found' | 'conflict' | 'privacy' | 'invalid-graph' | 'io', message: string);
|
|
20
|
+
}
|
|
21
|
+
/** One actor in the promotion audit trail. */
|
|
22
|
+
export interface PromotionActor {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
}
|
|
26
|
+
/** One durable step in a promotion's history. */
|
|
27
|
+
export interface PromotionAuditEntry {
|
|
28
|
+
readonly at: string;
|
|
29
|
+
readonly actorId: string;
|
|
30
|
+
readonly actorName: string;
|
|
31
|
+
readonly action: 'requested' | 'confirmed' | 'approved' | 'rejected';
|
|
32
|
+
readonly detail?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/** The personal entry a promotion was made from. */
|
|
35
|
+
export interface PromotionSource {
|
|
36
|
+
readonly userId: string;
|
|
37
|
+
readonly userName?: string;
|
|
38
|
+
readonly memoryId: string;
|
|
39
|
+
readonly memoryType: MemoryType;
|
|
40
|
+
readonly title: string;
|
|
41
|
+
readonly content: string;
|
|
42
|
+
readonly privacy: Privacy;
|
|
43
|
+
readonly sourceLabel?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Where the promotion lands. `departmentPath` is snapshotted at request time. */
|
|
46
|
+
export interface PromotionTarget {
|
|
47
|
+
readonly scope: PromotionTargetScope;
|
|
48
|
+
readonly departmentCode?: string;
|
|
49
|
+
readonly departmentName?: string;
|
|
50
|
+
readonly departmentPath?: readonly string[];
|
|
51
|
+
readonly graphId: typeof SHARED_MEMORY_GRAPH_ID;
|
|
52
|
+
readonly graphName: string;
|
|
53
|
+
/** Scope-relative document path (`记忆共享/<id>.md`). */
|
|
54
|
+
readonly docPath: string;
|
|
55
|
+
}
|
|
56
|
+
/** One promotion as stored. */
|
|
57
|
+
export interface MemoryPromotionRecord {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly status: PromotionStatus;
|
|
60
|
+
readonly source: PromotionSource;
|
|
61
|
+
readonly target: PromotionTarget;
|
|
62
|
+
readonly requestedBy: PromotionActor;
|
|
63
|
+
readonly requestedAt: string;
|
|
64
|
+
readonly reviewedBy?: PromotionActor;
|
|
65
|
+
readonly reviewedAt?: string;
|
|
66
|
+
readonly reviewNote?: string;
|
|
67
|
+
/** True when an administrator applied it directly instead of the review queue. */
|
|
68
|
+
readonly confirmed: boolean;
|
|
69
|
+
readonly appliedAt?: string;
|
|
70
|
+
readonly audit: readonly PromotionAuditEntry[];
|
|
71
|
+
}
|
|
72
|
+
/** The whole store file. */
|
|
73
|
+
export interface MemoryPromotionStore {
|
|
74
|
+
readonly version: 1;
|
|
75
|
+
readonly promotions: readonly MemoryPromotionRecord[];
|
|
76
|
+
}
|
|
77
|
+
/** The caller projection a promotion decision needs. */
|
|
78
|
+
export interface PromotionReviewer {
|
|
79
|
+
readonly userId: string;
|
|
80
|
+
readonly name: string;
|
|
81
|
+
/** Administrator/super administrator: sees and manages every scope. */
|
|
82
|
+
readonly isGlobalAdmin: boolean;
|
|
83
|
+
/** Holds the DataOps `kb:config:manage` permission. */
|
|
84
|
+
readonly canManageConfig: boolean;
|
|
85
|
+
readonly departmentCode?: string;
|
|
86
|
+
readonly departmentName?: string;
|
|
87
|
+
readonly departmentPathCodes?: readonly string[];
|
|
88
|
+
/** Departments whose review queue this caller may decide. */
|
|
89
|
+
readonly reviewDepartments: readonly string[];
|
|
90
|
+
/** Extra departments the backend's data scope grants. */
|
|
91
|
+
readonly visibleDepartmentCodes?: readonly string[];
|
|
92
|
+
}
|
|
93
|
+
/** A scope decision, with the department path the write will use. */
|
|
94
|
+
export type PromotionScopeDecision = {
|
|
95
|
+
readonly ok: true;
|
|
96
|
+
readonly departmentCode?: string;
|
|
97
|
+
readonly departmentPath?: readonly string[];
|
|
98
|
+
} | {
|
|
99
|
+
readonly ok: false;
|
|
100
|
+
readonly code: 'forbidden' | 'invalid';
|
|
101
|
+
readonly message: string;
|
|
102
|
+
};
|
|
103
|
+
/** The submitter may request a promotion only inside a scope they can review. */
|
|
104
|
+
export declare function decidePromotionScope(reviewer: PromotionReviewer, scope: PromotionTargetScope, departmentCode?: string): PromotionScopeDecision;
|
|
105
|
+
/** Whether one reviewer may decide a promotion aimed at its target scope. */
|
|
106
|
+
export declare function canReviewPromotion(reviewer: PromotionReviewer, target: PromotionTarget): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Whether one approved promotion is visible to a viewer.
|
|
109
|
+
*
|
|
110
|
+
* A department promotion is visible to the viewer whose organization path contains
|
|
111
|
+
* that department (own department and its ancestors) or whose data scope names it.
|
|
112
|
+
* The source owner always keeps seeing their own approved memory.
|
|
113
|
+
*/
|
|
114
|
+
export declare function isPromotionVisibleTo(record: MemoryPromotionRecord, viewer: PromotionReviewer): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The scope root one target writes under, WITHOUT a trailing slash.
|
|
117
|
+
*
|
|
118
|
+
* DataOps grants are matched against this exact resource id (a trailing slash is a
|
|
119
|
+
* different id and matches nothing), so every permission question must use this
|
|
120
|
+
* spelling. Directory joining adds the slash separately.
|
|
121
|
+
*/
|
|
122
|
+
export declare function targetScopeRoot(target: PromotionTarget): string;
|
|
123
|
+
/** The scope-relative prefix one target writes under (`global/`, `department/A/B/`). */
|
|
124
|
+
export declare function targetScopePrefix(target: PromotionTarget): string;
|
|
125
|
+
/** Where the review queue lives for one deployment's per-user memory root. */
|
|
126
|
+
export declare function promotionStorePath(memoryUsersRoot: string): string;
|
|
127
|
+
/** Map a stored memory type onto the graph's smaller node vocabulary. */
|
|
128
|
+
export declare function sharedNodeTypeOf(type: MemoryType): 'policy' | 'fact' | 'procedure' | 'case' | 'skill' | 'topic';
|
|
129
|
+
/** The text a promotion copies into the shared document. */
|
|
130
|
+
export declare function promotionContentOf(entry: AnyMemoryEntry): string;
|
|
131
|
+
/** The short title a shared row shows; mirrors the personal page's rules. */
|
|
132
|
+
export declare function promotionTitleOf(entry: ListedMemoryEntry): string;
|
|
133
|
+
/** Read the queue, treating absence as empty and quarantining corrupt JSON. */
|
|
134
|
+
export declare function readPromotionStore(path: string): Promise<MemoryPromotionStore>;
|
|
135
|
+
/** Commit the queue atomically. */
|
|
136
|
+
export declare function writePromotionStore(path: string, store: MemoryPromotionStore): Promise<void>;
|
|
137
|
+
/** Read every promotion, oldest first. */
|
|
138
|
+
export declare function listPromotionRecords(path: string): Promise<readonly MemoryPromotionRecord[]>;
|
|
139
|
+
/** The validated pieces of a new request, before an id or timestamps are assigned. */
|
|
140
|
+
export interface PromotionDraft {
|
|
141
|
+
readonly source: PromotionSource;
|
|
142
|
+
readonly target: PromotionTarget;
|
|
143
|
+
}
|
|
144
|
+
/** Reject a request that cannot be shared safely or written to a graph. */
|
|
145
|
+
export declare function normalizePromotionDraft(draft: PromotionDraft): PromotionDraft;
|
|
146
|
+
/** Create one pending request, or return the identical pending one. */
|
|
147
|
+
export declare function createPromotionRequest(path: string, draft: PromotionDraft, actor: PromotionActor, now?: () => Date): Promise<{
|
|
148
|
+
record: MemoryPromotionRecord;
|
|
149
|
+
duplicate: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
/** Load one promotion by id. */
|
|
152
|
+
export declare function getPromotionRecord(path: string, id: string): Promise<MemoryPromotionRecord | undefined>;
|
|
153
|
+
/** Mark one pending promotion approved after its shared document is on disk. */
|
|
154
|
+
export declare function markPromotionApproved(path: string, id: string, reviewer: PromotionActor, appliedPath: string, options: {
|
|
155
|
+
confirmed: boolean;
|
|
156
|
+
note?: string;
|
|
157
|
+
}, now?: () => Date): Promise<MemoryPromotionRecord>;
|
|
158
|
+
/** Mark one pending promotion rejected, keeping the reason. */
|
|
159
|
+
export declare function markPromotionRejected(path: string, id: string, reviewer: PromotionActor, note: string | undefined, now?: () => Date): Promise<MemoryPromotionRecord>;
|
|
160
|
+
/** Compose the shared document: front matter for the graph loader, then the body. */
|
|
161
|
+
export declare function renderSharedMemoryDocument(record: MemoryPromotionRecord, now: string): string;
|
|
162
|
+
/** The result of materializing one approved promotion. */
|
|
163
|
+
export interface AppliedPromotion {
|
|
164
|
+
readonly docPath: string;
|
|
165
|
+
readonly graphPath: string;
|
|
166
|
+
readonly graphId: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Write an approved promotion into the target scope and register it in the shared
|
|
170
|
+
* memory graph.
|
|
171
|
+
*
|
|
172
|
+
* The document is written first and the manifest second: if the manifest write
|
|
173
|
+
* fails, the next approval retries both and the orphan document is harmless (it is
|
|
174
|
+
* not referenced). The reverse order would publish a broken node.
|
|
175
|
+
*/
|
|
176
|
+
export declare function applyPromotionToSharedMemory(input: {
|
|
177
|
+
record: MemoryPromotionRecord;
|
|
178
|
+
scopeRoot: string;
|
|
179
|
+
now?: string;
|
|
180
|
+
}): Promise<AppliedPromotion>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP seam for memory promotion and shared (department/global) memory.
|
|
3
|
+
*
|
|
4
|
+
* `memoryRoutes.ts` owns the caller's personal page. This module owns the one
|
|
5
|
+
* operation that crosses a scope boundary — promoting a personal memory into a
|
|
6
|
+
* department or global memory — plus the review queue and the read-only shared
|
|
7
|
+
* list. It is separate because the trust question is different: the personal page
|
|
8
|
+
* acts on the caller's own tree, while every promotion decision needs a reviewer
|
|
9
|
+
* projection and a DataOps write/read decision for the TARGET path.
|
|
10
|
+
*
|
|
11
|
+
* Authorization has two layers, on purpose:
|
|
12
|
+
*
|
|
13
|
+
* 1. the product layer ({@link decidePromotionScope}, {@link canReviewPromotion})
|
|
14
|
+
* answers "is this reviewer's product scope the one this record targets", which
|
|
15
|
+
* is what makes the queue and the 403 messages understandable;
|
|
16
|
+
* 2. DataOps stays authoritative for the write and the read through the injected
|
|
17
|
+
* `canWrite` / `canRead` seams. A projection that disagrees with the backend
|
|
18
|
+
* therefore narrows access, never widens it.
|
|
19
|
+
*
|
|
20
|
+
* The submitter is never allowed to approve their own pending request. An
|
|
21
|
+
* administrator who wants to share their own memory uses `confirm: true`, which is
|
|
22
|
+
* recorded as a distinct `confirmed` audit action.
|
|
23
|
+
*
|
|
24
|
+
* @module @sparkelf/dsh-knowledge-base/memory-promotion-routes
|
|
25
|
+
*/
|
|
26
|
+
import type { MemoryStore } from './memoryStore.ts';
|
|
27
|
+
import { SHARED_MEMORY_FOLDER, SHARED_MEMORY_GRAPH_ID, type MemoryPromotionRecord, type PromotionActor, type PromotionReviewer, type PromotionTargetScope } from './memoryPromotion.ts';
|
|
28
|
+
/** The methods this handler answers. */
|
|
29
|
+
export type MemoryPromotionMethod = 'memory.promote' | 'memory.promotions' | 'memory.review-promotion' | 'memory.shared';
|
|
30
|
+
/** Injected filesystem/permission seams; tests use plain functions. */
|
|
31
|
+
export interface MemoryPromotionRouteInput {
|
|
32
|
+
readonly method: MemoryPromotionMethod;
|
|
33
|
+
/** Parsed JSON body; methods without one may omit it. */
|
|
34
|
+
readonly body?: unknown;
|
|
35
|
+
readonly actor: PromotionActor;
|
|
36
|
+
readonly reviewer: PromotionReviewer;
|
|
37
|
+
/** The caller's personal memory store; the source entry is read from here. */
|
|
38
|
+
readonly store: Pick<MemoryStore, 'getEntry'>;
|
|
39
|
+
/** Absolute path of the promotion queue JSON file. */
|
|
40
|
+
readonly queuePath: string;
|
|
41
|
+
/** Authoritative knowledge root (`/nas/kb/actual`). */
|
|
42
|
+
readonly actualRoot: string;
|
|
43
|
+
/** DataOps write decision for one scope-relative path. */
|
|
44
|
+
readonly canWrite?: (relPath: string) => Promise<boolean>;
|
|
45
|
+
/** DataOps read decision for one scope-relative path. */
|
|
46
|
+
readonly canRead?: (relPath: string) => Promise<boolean>;
|
|
47
|
+
/** Injectable clock for deterministic tests. */
|
|
48
|
+
readonly now?: () => Date;
|
|
49
|
+
}
|
|
50
|
+
/** One response the route switch can pass straight to `writeJson`. */
|
|
51
|
+
export interface MemoryPromotionRouteResponse {
|
|
52
|
+
readonly status: number;
|
|
53
|
+
readonly body: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
/** The externally visible shape of one promotion; never the source user id. */
|
|
56
|
+
export declare function publicPromotion(record: MemoryPromotionRecord, viewerId: string): Record<string, unknown>;
|
|
57
|
+
/** One read-only row of the department/global shared list. */
|
|
58
|
+
export interface SharedMemoryRow {
|
|
59
|
+
id: string;
|
|
60
|
+
title: string;
|
|
61
|
+
type: string;
|
|
62
|
+
content: string;
|
|
63
|
+
scope: PromotionTargetScope;
|
|
64
|
+
departmentCode?: string;
|
|
65
|
+
departmentName?: string;
|
|
66
|
+
promotedAt: string;
|
|
67
|
+
promotedBy?: string;
|
|
68
|
+
}
|
|
69
|
+
/** Build the row without any personal identifier or source session. */
|
|
70
|
+
export declare function sharedRowOf(record: MemoryPromotionRecord): SharedMemoryRow;
|
|
71
|
+
/**
|
|
72
|
+
* Handle one promotion/shared-memory method.
|
|
73
|
+
*
|
|
74
|
+
* Expected failures are returned as status/body pairs. Unexpected errors are
|
|
75
|
+
* rethrown so the route's outer handler reports a real 500 rather than a
|
|
76
|
+
* misleading 400.
|
|
77
|
+
*/
|
|
78
|
+
export declare function handleMemoryPromotionRoute(input: MemoryPromotionRouteInput): Promise<MemoryPromotionRouteResponse>;
|
|
79
|
+
/** Re-exported so the host can build the same target shape in its tests. */
|
|
80
|
+
export { SHARED_MEMORY_GRAPH_ID, SHARED_MEMORY_FOLDER, type PromotionTargetScope };
|
|
@@ -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,
|
|
7
|
-
* non-overridable, and a
|
|
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,6 +34,12 @@ 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[]>;
|
|
38
45
|
/** Whether the caller holds the memory-management capability (`kb:config:manage`). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkelf/dsh-knowledge-base",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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",
|