@sparkelf/dsh-knowledge-base 0.1.36 → 0.4.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.
Files changed (41) hide show
  1. package/README.md +53 -0
  2. package/lib/client.js +2463 -1385
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +18210 -7883
  5. package/lib/types/client/KnowledgeMemory.d.ts +127 -0
  6. package/lib/types/client/graph/OriginBadges.d.ts +55 -0
  7. package/lib/types/client/locales.d.ts +64 -0
  8. package/lib/types/ftsIndex.d.ts +32 -0
  9. package/lib/types/graphCanvas.d.ts +1 -1
  10. package/lib/types/graphJsonProjection.d.ts +71 -0
  11. package/lib/types/graphMigration.d.ts +118 -0
  12. package/lib/types/graphModel.d.ts +194 -0
  13. package/lib/types/graphPolicy.d.ts +68 -0
  14. package/lib/types/graphTools.d.ts +30 -5
  15. package/lib/types/graphTypes.d.ts +24 -0
  16. package/lib/types/guardianSession.d.ts +135 -0
  17. package/lib/types/index.d.ts +135 -15
  18. package/lib/types/knowledgeTools.d.ts +50 -2
  19. package/lib/types/memoryBindings.d.ts +119 -0
  20. package/lib/types/memoryContext.d.ts +83 -0
  21. package/lib/types/memoryGraphBootstrap.d.ts +62 -0
  22. package/lib/types/memoryGraphWriter.d.ts +101 -0
  23. package/lib/types/memoryGuardian.d.ts +123 -0
  24. package/lib/types/memoryGuardianTool.d.ts +56 -0
  25. package/lib/types/memoryPolicy.d.ts +106 -0
  26. package/lib/types/memoryRecordTool.d.ts +39 -0
  27. package/lib/types/memoryRoutes.d.ts +85 -0
  28. package/lib/types/memorySettings.d.ts +40 -0
  29. package/lib/types/memorySkillPromotion.d.ts +62 -0
  30. package/lib/types/memoryStore.d.ts +297 -0
  31. package/lib/types/memoryTools.d.ts +71 -0
  32. package/lib/types/memoryTriggers.d.ts +65 -0
  33. package/lib/types/memoryTypes.d.ts +241 -0
  34. package/lib/types/summaryIndex.d.ts +112 -0
  35. package/lib/types/summaryWriteback.d.ts +87 -0
  36. package/lib/types/views.d.ts +25 -0
  37. package/package.json +1 -1
  38. package/skills/knowledge-graph/SKILL.md +37 -8
  39. package/skills/memory-extract/SKILL.md +43 -0
  40. package/skills/memory-guardian/SKILL.md +97 -0
  41. package/skills/memory-sop-evaluate/SKILL.md +43 -0
@@ -0,0 +1,127 @@
1
+ /**
2
+ * The 记忆 page: the user-facing view over their personal memory.
3
+ *
4
+ * The page is deliberately small and quiet. It answers four questions — is memory
5
+ * on, what has been remembered, where did it come from, and how do I correct or
6
+ * forget it — and it never exposes the machinery behind those answers. Rows show a
7
+ * short title, a type, a human source label and a relative time; session ids,
8
+ * tool names, paths, SOP lifecycle and JSON stay out of the surface. The switch
9
+ * never flips on click: both directions open a confirmation, and only the
10
+ * confirmation calls the Host.
11
+ *
12
+ * `KnowledgeMemory` owns the API state; `KnowledgeMemoryView` is the pure render
13
+ * used by tests. Keeping the split means the table, the confirmation copy and the
14
+ * empty state can be asserted without mounting a fetch lifecycle.
15
+ *
16
+ * @module @sparkelf/dsh-knowledge-base/client/KnowledgeMemory
17
+ */
18
+ import { type ReactNode } from 'react';
19
+ /** A source pointer attached to one memory. `sessionId` is never rendered. */
20
+ export interface MemorySourceRef {
21
+ /** Human label snapshotted when the memory was written, e.g. 驾驶舱下钻. */
22
+ label?: string;
23
+ /** ISO-8601 instant of the source. */
24
+ at?: string;
25
+ /** Internal locator used only by the host's 查看原文 action. */
26
+ sessionId?: string;
27
+ /** Evidence event positions, used only by the host action. */
28
+ eventSeqs?: number[];
29
+ /** Whether the source can still be opened; absent means derive from sessionId. */
30
+ resolvable?: boolean;
31
+ }
32
+ /** One memory as the page renders it. */
33
+ export interface MemoryEntryView {
34
+ id: string;
35
+ title: string;
36
+ content?: string;
37
+ /** preference / pitfall / fact / sop / episodic; unknown values render as Other. */
38
+ type?: string;
39
+ /** normal / private / sensitive / secret. */
40
+ privacy?: string;
41
+ updatedAt?: string;
42
+ /** Primary source pointer. */
43
+ source?: MemorySourceRef;
44
+ /** Flat source label, for callers that do not nest the source. */
45
+ sourceLabel?: string;
46
+ /** Flat source instant, for callers that do not nest the source. */
47
+ sourceAt?: string;
48
+ /** List-row source instant used by the memory route. */
49
+ sourceTime?: string;
50
+ /** More sources merged into this memory; the detail lists all of them. */
51
+ sourceRefs?: MemorySourceRef[];
52
+ /** Explicit resolvability override. */
53
+ sourceResolvable?: boolean;
54
+ }
55
+ /** List lifecycle the view renders. */
56
+ export interface MemoryListSnapshot {
57
+ status: 'loading' | 'ready' | 'error';
58
+ entries: MemoryEntryView[];
59
+ error?: string;
60
+ }
61
+ /** Props for the pure memory renderer. */
62
+ export interface KnowledgeMemoryViewProps {
63
+ t: (key: string) => string;
64
+ locale?: string;
65
+ enabled: boolean;
66
+ settingsLoading: boolean;
67
+ settingsError?: string;
68
+ list: MemoryListSnapshot;
69
+ query: string;
70
+ typeFilter: string;
71
+ onQueryChange: (value: string) => void;
72
+ onTypeFilterChange: (value: string) => void;
73
+ /** Ask to flip the switch; the container opens the confirmation. */
74
+ onToggleRequest: (enabled: boolean) => void;
75
+ /** Target state while a confirmation is open. */
76
+ pendingEnabled?: boolean;
77
+ toggleBusy: boolean;
78
+ toggleError?: string;
79
+ onCancelToggle: () => void;
80
+ onConfirmToggle: () => void;
81
+ detail?: MemoryEntryView;
82
+ detailLoading: boolean;
83
+ onOpenDetail: (entry: MemoryEntryView) => void;
84
+ onCloseDetail: () => void;
85
+ editing?: {
86
+ id: string;
87
+ content: string;
88
+ };
89
+ editBusy: boolean;
90
+ editError?: string;
91
+ onEditContent: (value: string) => void;
92
+ onStartEdit: (entry: MemoryEntryView) => void;
93
+ onCancelEdit: () => void;
94
+ onSaveEdit: () => void;
95
+ forgetTarget?: MemoryEntryView;
96
+ forgetBusy: boolean;
97
+ forgetError?: string;
98
+ onStartForget: (entry: MemoryEntryView) => void;
99
+ onCancelForget: () => void;
100
+ onConfirmForget: () => void;
101
+ onRetrySettings: () => void;
102
+ onRetryList: () => void;
103
+ /** Open the source conversation; omitted hides 查看原文. */
104
+ onOpenSource?: (entry: MemoryEntryView) => void;
105
+ }
106
+ /** Props for the stateful memory page. */
107
+ export interface KnowledgeMemoryProps {
108
+ t: (key: string) => string;
109
+ locale?: string;
110
+ /** Host hook that opens the source conversation. */
111
+ onOpenSource?: (entry: MemoryEntryView) => void;
112
+ }
113
+ /**
114
+ * Render the memory page from an explicit snapshot.
115
+ *
116
+ * @param props - locale copy, page state and the callbacks the container owns.
117
+ * @returns The header, filters, table and dialogs.
118
+ */
119
+ export declare function KnowledgeMemoryView(props: KnowledgeMemoryViewProps): ReactNode;
120
+ /**
121
+ * The stateful memory page: read settings and the list, then run the confirmed
122
+ * write actions against the Host.
123
+ *
124
+ * @param props - locale copy and the optional source opener.
125
+ * @returns The page with its live state.
126
+ */
127
+ export declare function KnowledgeMemory(props: KnowledgeMemoryProps): ReactNode;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The provenance and authority badges a graph row, topic row or document row
3
+ * shows: `[AI 生成]`, `[已审核]` and `[红线]`.
4
+ *
5
+ * The component is purely presentational. It never filters a row out and never
6
+ * decides whether the caller may act on it — the Host has already resolved graph
7
+ * visibility and the write policy; hiding a badge in the browser would not be a
8
+ * permission check, only a lie about what the data is.
9
+ *
10
+ * Fields are optional so the existing scanner and older graphs keep rendering
11
+ * exactly as before: an absent `origin` / `reviewStatus` / `authority` produces no
12
+ * badge rather than a placeholder.
13
+ *
14
+ * @module @sparkelf/dsh-knowledge-base/client/graph/OriginBadges
15
+ */
16
+ import type { KnowledgeGraphAuthority, KnowledgeGraphOrigin, KnowledgeGraphReviewStatus } from '../../graphTypes.ts';
17
+ /** Props for {@link OriginBadges}. */
18
+ export interface OriginBadgesProps {
19
+ /** How the content was produced; `ai` and `mixed` render `[AI 生成]`. */
20
+ origin?: KnowledgeGraphOrigin;
21
+ /** Review lifecycle; `reviewed` and `approved` render `[已审核]`. */
22
+ reviewStatus?: KnowledgeGraphReviewStatus;
23
+ /** Authority level; `redline` renders `[红线]`. */
24
+ authority?: KnowledgeGraphAuthority;
25
+ /** Tighter metrics for a 28px tree row. */
26
+ compact?: boolean;
27
+ /** Extra class from the row that hosts the badges. */
28
+ className?: string;
29
+ }
30
+ /** One badge before it becomes markup. */
31
+ export interface OriginBadgeItem {
32
+ /** Which field produced the badge; unique within one set. */
33
+ key: 'origin' | 'reviewStatus' | 'authority';
34
+ /** Visible text without the bracket decoration. */
35
+ label: string;
36
+ /** Answer shown by the native tooltip and used as the accessible name. */
37
+ title: string;
38
+ }
39
+ /**
40
+ * Resolve the badge list for one set of optional fields.
41
+ *
42
+ * Exported so a host surface can test "does this row have anything to show?"
43
+ * without rendering, and so the rules stay testable without a DOM.
44
+ *
45
+ * @param props - the optional provenance fields.
46
+ * @returns Badges in reading order: origin, review, authority.
47
+ */
48
+ export declare function originBadgeItems(props: Pick<OriginBadgesProps, 'origin' | 'reviewStatus' | 'authority'>): OriginBadgeItem[];
49
+ /**
50
+ * Render the badges for one row, or nothing when the row has no provenance.
51
+ *
52
+ * @param props - optional origin/review/authority fields.
53
+ * @returns A small inline group of badges, or `null`.
54
+ */
55
+ export declare function OriginBadges(props: OriginBadgesProps): import("react").JSX.Element | null;
@@ -672,6 +672,70 @@ export declare const en: {
672
672
  readonly createNameTraversal: "A name cannot be . or ..";
673
673
  readonly deployAboutRemote: "What remote deployment does";
674
674
  readonly deployAboutRemoteBody: "A remote deployment syncs documents from a shared NFS or SSHFS export. Its wizard prepares that host, installs the parsing service, and verifies the mount.";
675
+ readonly 'menu.memory': "Memory";
676
+ readonly memoryHint: "Preferences, facts, pitfalls and methods learned from your conversations.";
677
+ readonly memorySwitchLabel: "Memory";
678
+ readonly memoryEnabled: "On";
679
+ readonly memoryPaused: "Paused";
680
+ readonly memoryPausedNotice: "Memory is paused. No new memories are learned; existing memories stay visible and can still be forgotten.";
681
+ readonly memorySettingsFailed: "Could not read the memory setting.";
682
+ readonly memoryEnableTitle: "Turn on memory";
683
+ readonly memoryEnableBody: "When memory is on, the assistant learns preferences, facts, pitfalls and methods from your conversations, and they may affect later answers and actions. Existing memories are kept, and you can pause or forget any single memory at any time.";
684
+ readonly memoryPauseTitle: "Pause memory";
685
+ readonly memoryPauseBody: "When memory is paused, no new memories are learned. Existing memories are kept but no longer affect later answers.";
686
+ readonly memoryConfirmEnable: "Turn on";
687
+ readonly memoryConfirmPause: "Pause";
688
+ readonly memorySearchPlaceholder: "Search memories";
689
+ readonly memoryFilterLabel: "Filter by type";
690
+ readonly memoryFilterAll: "All types";
691
+ readonly memoryTypePreference: "Preference";
692
+ readonly memoryTypePitfall: "Pitfall";
693
+ readonly memoryTypeFact: "Fact";
694
+ readonly memoryTypeSop: "Method";
695
+ readonly memoryTypeEpisodic: "Episode";
696
+ readonly memoryTypeOther: "Other";
697
+ readonly memoryColumnMemory: "Memory";
698
+ readonly memoryColumnType: "Type";
699
+ readonly memoryColumnSource: "Source";
700
+ readonly memoryColumnUpdated: "Updated";
701
+ readonly memoryColumnPrivacy: "Privacy";
702
+ readonly memoryColumnActions: "Actions";
703
+ readonly memoryActionView: "View";
704
+ readonly memoryActionCorrect: "Correct";
705
+ readonly memoryActionForget: "Forget";
706
+ readonly memorySourceUnknown: "Earlier conversation";
707
+ readonly memoryMoreSources: "{n} more sources";
708
+ readonly memoryTimeJustNow: "Just now";
709
+ readonly memoryTimeMinutes: "{n} min ago";
710
+ readonly memoryTimeHours: "{n} h ago";
711
+ readonly memoryTimeDays: "{n} d ago";
712
+ readonly memoryPrivacyNormal: "Normal";
713
+ readonly memoryPrivacyPrivate: "Only me";
714
+ readonly memoryPrivacySensitive: "Sensitive";
715
+ readonly memoryPrivacySecret: "Credential reference";
716
+ readonly memoryPrivacyOther: "—";
717
+ readonly memoryListLoading: "Reading memories…";
718
+ readonly memoryListFailed: "Could not read memories.";
719
+ readonly memoryRetry: "Retry";
720
+ readonly memoryEmptyTitle: "No memories yet";
721
+ readonly memoryEmptyBody: "When memory is on, durable preferences, facts, pitfalls and methods from your conversations appear here.";
722
+ readonly memoryNoMatches: "No memories match this search.";
723
+ readonly memoryDetailTitle: "Memory details";
724
+ readonly memoryDetailContent: "Content";
725
+ readonly memoryDetailSource: "Source";
726
+ readonly memoryDetailEvidence: "Evidence";
727
+ readonly memoryDetailLoading: "Reading the full memory…";
728
+ readonly memoryNoContent: "No content recorded.";
729
+ readonly memoryViewSource: "View original";
730
+ readonly memoryClose: "Close";
731
+ readonly memoryEditTitle: "Correct memory";
732
+ readonly memoryEditContentLabel: "Content";
733
+ readonly memorySave: "Save";
734
+ readonly memorySaveFailed: "Could not save this correction.";
735
+ readonly memoryForgetTitle: "Forget this memory?";
736
+ readonly memoryForgetBody: "The memory will no longer appear or affect later answers. It cannot be undone from this page.";
737
+ readonly memoryForgetConfirm: "Forget";
738
+ readonly memoryForgetFailed: "Could not forget this memory.";
675
739
  };
676
740
  /** Stable key set shared by every knowledge-base locale. */
677
741
  export type KnowledgeKey = keyof typeof en;
@@ -17,6 +17,15 @@ import { type OutlineSection, type OutlineTocEntry } from './outlineText.ts';
17
17
  import { type OutlineSaveRejection, type OutlineSectionSubmission, type OutlineSummaryKind } from './outlineGuard.ts';
18
18
  /** Prefix used for the sidecar directory when no explicit index dir is configured. */
19
19
  export declare const DEFAULT_INDEX_DIR = "/nas/kb/index";
20
+ /**
21
+ * Whether a path's bytes are plain text the index can read directly.
22
+ *
23
+ * Shared with the write paths so "index this after the write" and "the index walk
24
+ * will find this file" cannot disagree: both answer from the same extension set.
25
+ * @param relPath - the document's path.
26
+ * @returns true when {@link syncIndex} would read this file as text.
27
+ */
28
+ export declare function isIndexableTextPath(relPath: string): boolean;
20
29
  /** One search hit returned to the model. */
21
30
  /** Result of one kb_search call, including whether it had to relax. */
22
31
  export interface FtsSearchResult {
@@ -175,6 +184,29 @@ export interface FtsCallerScope {
175
184
  }
176
185
  /** The index path for one deployment. */
177
186
  export declare function indexPathFor(indexDir: string | undefined): string;
187
+ /** What the sidecar index knows about one document. */
188
+ export interface DocumentIndexStatus {
189
+ found: boolean;
190
+ docId?: number;
191
+ path?: string;
192
+ scope?: string;
193
+ chunks?: number;
194
+ indexedAt?: number;
195
+ }
196
+ /**
197
+ * Read one document's row from the sidecar index.
198
+ *
199
+ * Used by the write paths to report whether the document they just wrote is really
200
+ * searchable, and by the `index.status` route. The lookup accepts the view spelling
201
+ * too (`global/…` may be stored as the actual path, or a personal view path drops the
202
+ * owner segment), so an exact miss falls back to a suffix match before reporting
203
+ * `found: false`.
204
+ *
205
+ * @param indexPath - the deployment's SQLite index file.
206
+ * @param relPath - the document's authoritative or view-relative path.
207
+ * @returns the row, or `found: false` when nothing matches or the index is absent.
208
+ */
209
+ export declare function documentIndexStatus(indexPath: string, relPath: string): DocumentIndexStatus;
178
210
  /**
179
211
  * Refuse an index path inside the browsable/authoritative trees.
180
212
  *