@sparkelf/dsh-knowledge-base 0.1.35 → 0.4.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.
Files changed (41) hide show
  1. package/README.md +34 -0
  2. package/lib/client.js +2516 -1378
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +17516 -7806
  5. package/lib/types/client/KnowledgeMemory.d.ts +127 -0
  6. package/lib/types/client/KnowledgePermissionOverview.d.ts +113 -0
  7. package/lib/types/client/graph/OriginBadges.d.ts +55 -0
  8. package/lib/types/client/locales.d.ts +66 -0
  9. package/lib/types/client/roleSummary.d.ts +47 -0
  10. package/lib/types/graph.d.ts +1 -0
  11. package/lib/types/graphCanvas.d.ts +1 -1
  12. package/lib/types/graphJsonProjection.d.ts +71 -0
  13. package/lib/types/graphMigration.d.ts +118 -0
  14. package/lib/types/graphModel.d.ts +194 -0
  15. package/lib/types/graphPolicy.d.ts +68 -0
  16. package/lib/types/graphTools.d.ts +23 -4
  17. package/lib/types/graphTypes.d.ts +26 -2
  18. package/lib/types/guardianSession.d.ts +135 -0
  19. package/lib/types/index.d.ts +92 -0
  20. package/lib/types/knowledgeTools.d.ts +17 -1
  21. package/lib/types/memoryBindings.d.ts +119 -0
  22. package/lib/types/memoryContext.d.ts +83 -0
  23. package/lib/types/memoryGraphBootstrap.d.ts +62 -0
  24. package/lib/types/memoryGraphWriter.d.ts +101 -0
  25. package/lib/types/memoryGuardian.d.ts +123 -0
  26. package/lib/types/memoryGuardianTool.d.ts +56 -0
  27. package/lib/types/memoryPolicy.d.ts +106 -0
  28. package/lib/types/memoryRecordTool.d.ts +39 -0
  29. package/lib/types/memoryRoutes.d.ts +85 -0
  30. package/lib/types/memorySettings.d.ts +40 -0
  31. package/lib/types/memorySkillPromotion.d.ts +62 -0
  32. package/lib/types/memoryStore.d.ts +297 -0
  33. package/lib/types/memoryTools.d.ts +71 -0
  34. package/lib/types/memoryTriggers.d.ts +65 -0
  35. package/lib/types/memoryTypes.d.ts +241 -0
  36. package/lib/types/summaryIndex.d.ts +112 -0
  37. package/lib/types/summaryWriteback.d.ts +87 -0
  38. package/package.json +2 -2
  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,113 @@
1
+ /**
2
+ * Two ways to read the same grant table: by person, and by resource.
3
+ *
4
+ * A grant says "this principal may do this to this path". That is the right shape
5
+ * to STORE and the wrong shape to AUDIT: an administrator asked "what does 张三
6
+ * have" and "who can see 制度.md" is asking two questions that one row-per-grant
7
+ * layout cannot answer without being read line by line.
8
+ *
9
+ * Both views are derived on the client from the same payload. No second endpoint
10
+ * exists because there is no second truth: deriving them here means the overview
11
+ * cannot disagree with the table it summarizes.
12
+ *
13
+ * @module @sparkelf/dsh-knowledge-base/client/KnowledgePermissionOverview
14
+ */
15
+ import type { GrantView, KnowledgeGrantSubjectType } from '../api.ts';
16
+ import { type RoleSummary } from './roleSummary.ts';
17
+ /** One person's holdings, as the person view renders them. */
18
+ export interface PersonHoldings {
19
+ /** Principal id the grants name. */
20
+ principalId: string;
21
+ /** Display name when a directory entry resolved one, else the id. */
22
+ label: string;
23
+ /** Distinct paths this person may touch. */
24
+ paths: string[];
25
+ /** Which actions the person holds, collapsed so a full house reads `all`. */
26
+ actions: string[];
27
+ /**
28
+ * Roles the person reaches through a `role` grant they belong to.
29
+ *
30
+ * Empty when the directory does not know the membership: a role grant names the
31
+ * ROLE, not the people in it, so this is only populated when a directory entry
32
+ * declared the membership.
33
+ */
34
+ roles: string[];
35
+ }
36
+ /** One resource and everyone who may reach it. */
37
+ export interface ResourceHoldings {
38
+ /** Path, relative to the mount point. */
39
+ relPath: string;
40
+ /** Whether it is a file or a directory. */
41
+ kind: 'file' | 'directory';
42
+ /** Everyone holding any action on it, grouped by principal kind. */
43
+ principals: Array<{
44
+ principalType: KnowledgeGrantSubjectType;
45
+ principalId: string;
46
+ label: string;
47
+ actions: string[];
48
+ }>;
49
+ }
50
+ /**
51
+ * Collapse a set of action strings into the shortest describing list.
52
+ *
53
+ * Mirrors the server's collapse rule without importing it: this file is bundled
54
+ * for the browser and must not pull the server module in. Keeping the rule in
55
+ * two places is a real cost, so it is stated once here and covered by the same
56
+ * expectations as the server's own test.
57
+ *
58
+ * @param actions - raw action strings from grants.
59
+ * @returns `['all']` when everything is held, else the concrete subset in order.
60
+ */
61
+ export declare function summarizeActions(actions: readonly string[]): string[];
62
+ /**
63
+ * Group grants by the principal they name.
64
+ *
65
+ * A principal appearing in several grants is one row: "what does 张三 have" is a
66
+ * question about a person, and splitting them across rows because they hold two
67
+ * paths would answer it wrong.
68
+ *
69
+ * @param grants - the grant table.
70
+ * @param labels - display names by `principalType:principalId`, optional.
71
+ * @returns one entry per principal, ordered by label then id.
72
+ */
73
+ export declare function groupHoldingsByPrincipal(grants: readonly GrantView[], labels?: Readonly<Record<string, string>>): PersonHoldings[];
74
+ /**
75
+ * Group grants by the resource they cover.
76
+ *
77
+ * @param grants - the grant table.
78
+ * @param labels - display names by `principalType:principalId`, optional.
79
+ * @returns one entry per path, ordered by path.
80
+ */
81
+ export declare function groupHoldingsByResource(grants: readonly GrantView[], labels?: Readonly<Record<string, string>>): ResourceHoldings[];
82
+ /** Copy for the overview, supplied by the caller's locale record. */
83
+ export interface OverviewCopy {
84
+ tabByPerson: string;
85
+ tabByResource: string;
86
+ empty: string;
87
+ pathsHeld: (count: number) => string;
88
+ rolesHeld: string;
89
+ actionsHeld: string;
90
+ builtInRoles: string;
91
+ noActions: string;
92
+ }
93
+ /** Props the parent panel supplies. */
94
+ export interface KnowledgePermissionOverviewProps {
95
+ /** The grant table already loaded by the permissions page. */
96
+ grants: readonly GrantView[];
97
+ /** Display names by `principalType:principalId`. */
98
+ labels?: Readonly<Record<string, string>>;
99
+ /** Built-in role summaries, so the person view can explain what a role means. */
100
+ roles?: readonly RoleSummary[];
101
+ /** Locale copy. */
102
+ copy: OverviewCopy;
103
+ }
104
+ /**
105
+ * Render both readings of the grant table under one tab strip.
106
+ *
107
+ * The two tabs share the loaded grants rather than fetching twice: they are two
108
+ * renderings of one answer, and a refresh between them would let the screen show
109
+ * a person and a resource that disagree.
110
+ *
111
+ * @param props - grants, labels, role summaries and copy.
112
+ */
113
+ export declare function KnowledgePermissionOverview(props: KnowledgePermissionOverviewProps): import("react").JSX.Element;
@@ -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;
@@ -262,6 +262,8 @@ export declare const en: {
262
262
  readonly previewTruncated: "This file is large; only the start is shown.";
263
263
  readonly modifiedAt: "Modified";
264
264
  readonly openedInSidebar: "Opened in the file window on the right.";
265
+ readonly openFailureTitle: "Could not open the file window on the right";
266
+ readonly openFailureBody: "The document is shown in this page instead. The file window is unavailable here, or no conversation surface is mounted.";
265
267
  readonly previewClose: "Close preview";
266
268
  readonly previewLoading: "Loading document…";
267
269
  readonly copyCode: "Copy";
@@ -670,6 +672,70 @@ export declare const en: {
670
672
  readonly createNameTraversal: "A name cannot be . or ..";
671
673
  readonly deployAboutRemote: "What remote deployment does";
672
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.";
673
739
  };
674
740
  /** Stable key set shared by every knowledge-base locale. */
675
741
  export type KnowledgeKey = keyof typeof en;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * What each role in the grant table actually amounts to.
3
+ *
4
+ * A role is not stored anywhere: it exists because grants name it. That is a good
5
+ * property to inherit — a role cannot outlive its resources or appear with none —
6
+ * but it means "list the roles" is a question about the grants, answered by
7
+ * reading them. This module is that reading, kept out of the component so it can
8
+ * be tested without a DOM.
9
+ *
10
+ * @module @sparkelf/dsh-knowledge-base/client/roleSummary
11
+ */
12
+ import type { GrantView } from '../api.ts';
13
+ /** One role as the overview shows it. */
14
+ export interface RoleSummary {
15
+ /** Role id, which is the `principalId` its grants carry. */
16
+ id: string;
17
+ /** Display name, falling back to the id when no locale entry matches. */
18
+ label: string;
19
+ /** Actions granted anywhere by this role, collapsed so a full house reads `all`. */
20
+ actions: string[];
21
+ /** Distinct paths it reaches. */
22
+ paths: string[];
23
+ /** Whether this is one of the two the product ships with. */
24
+ builtIn: boolean;
25
+ }
26
+ /**
27
+ * Collapse raw action strings into the shortest describing list.
28
+ *
29
+ * The client needs this independently of the server: the overview renders grants
30
+ * the server already wrote, so it summarizes what is there rather than what a
31
+ * request asked for.
32
+ *
33
+ * @param actions - raw action strings.
34
+ * @returns `['all']` when all four concrete actions are held, else the subset.
35
+ */
36
+ export declare function summarizeRoleActions(actions: readonly string[]): string[];
37
+ /**
38
+ * Read the roles out of a grant table.
39
+ *
40
+ * Only `role` grants contribute: a user grant is not a role, and inventing one
41
+ * per user would flood the list with rows that mean nothing.
42
+ *
43
+ * @param grants - the grant table.
44
+ * @param locale - `zh` or `en`, for the built-in role names.
45
+ * @returns one entry per role named by a grant, built-ins first then alphabetical.
46
+ */
47
+ export declare function buildRoleSummaries(grants: readonly GrantView[], locale?: 'zh' | 'en'): RoleSummary[];
@@ -8,6 +8,7 @@
8
8
  * <scope>/知识图谱/<graph>/
9
9
  * <topic>/index.md # the topic card, visible
10
10
  * <topic>/<document>.md # documents, visible
11
+ * <topic>/<folder>/<doc>.md # documents grouped below the topic, visible
11
12
  * .kg/links/<a>--<b>.md # relations, hidden from the file tree and search
12
13
  * ```
13
14
  *