@sparkelf/dsh-knowledge-base 0.5.2 → 0.5.4

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/lib/index.js CHANGED
@@ -4462,9 +4462,9 @@ function assertIndexOutsideTrees(indexPath, trees) {
4462
4462
  /** Derive the scope columns from a view-relative path. */
4463
4463
  function scopeForPath(relPath) {
4464
4464
  const parts = relPath.split("/").filter((part) => part !== "");
4465
- if (parts[0] === "personal" && parts.length >= 3) return {
4465
+ if (parts[0] === "personal" && parts.length >= 2) return {
4466
4466
  scope: "personal",
4467
- ownerId: parts[1] ?? null,
4467
+ ownerId: parts.length >= 3 ? parts[1] ?? null : null,
4468
4468
  departmentCode: null
4469
4469
  };
4470
4470
  if (parts[0] === "department" && parts.length >= 3) return {
@@ -21387,6 +21387,32 @@ function personalPathRefusal(config, relPath) {
21387
21387
  return isTeamDeployment(config) ? void 0 : checkLocalPath(relPath);
21388
21388
  }
21389
21389
  /**
21390
+ * Normalize a PERSONAL write path to the caller's own subtree.
21391
+ *
21392
+ * The page's upload destination is the virtual bucket `personal`, so a file dropped
21393
+ * there arrives as `personal/<file>`. That spelling has no owner segment; writing it
21394
+ * literally would put the document beside the owners and force the permission layer
21395
+ * to grant the whole `personal` bucket, which resolves as shared across users.
21396
+ * Rewriting it to `personal/<callerId>/<file>` keeps the owner in the path, makes the
21397
+ * existing `personal/<userId>` grants sufficient, and keeps every user's personal
21398
+ * bucket disjoint. An explicit `personal/<uuid>/…` is left untouched so a cross-user
21399
+ * write still reaches the permission layer and is refused rather than silently
21400
+ * redirected.
21401
+ *
21402
+ * @param relPath - the path as the caller sent it.
21403
+ * @param callerId - the authenticated caller's user id.
21404
+ * @returns the caller-scoped personal path, or the input when it is not personal.
21405
+ */
21406
+ function normalizePersonalWritePath(relPath, callerId) {
21407
+ const normalized = resolveScopeAlias(relPath);
21408
+ if (!normalized.startsWith("personal/")) return normalized;
21409
+ if (normalized === `personal/${callerId}` || normalized.startsWith(`personal/${callerId}/`)) return normalized;
21410
+ const rest = normalized.slice(9);
21411
+ const head = rest.split("/")[0] ?? "";
21412
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(head)) return normalized;
21413
+ return `personal/${callerId}/${rest}`;
21414
+ }
21415
+ /**
21390
21416
  * The resolved layout, derived on the Host.
21391
21417
  *
21392
21418
  * There is no backend counterpart to ask: DataOps serves no knowledge config
@@ -22302,12 +22328,17 @@ async function canReadPath(ctx, config, relPath) {
22302
22328
  relPath = resolveScopeAlias(relPath);
22303
22329
  if (!isTeamDeployment(config)) return checkLocalPath(relPath) === void 0;
22304
22330
  try {
22331
+ let permissionPath = relPath;
22332
+ if (relPath.startsWith("personal/")) {
22333
+ const who = await fetchCaller(ctx, config).catch(() => void 0);
22334
+ if (who !== void 0 && isSafeUserId(who.userId)) permissionPath = normalizePersonalWritePath(relPath, who.userId);
22335
+ }
22305
22336
  return (await request(ctx, config, ENDPOINTS.resolve, {
22306
22337
  method: "POST",
22307
22338
  body: {
22308
22339
  resourceType: KB_RESOURCE_TYPE,
22309
- resourceId: relPath,
22310
- ancestors: knowledgeAncestorsFor(relPath)
22340
+ resourceId: permissionPath,
22341
+ ancestors: knowledgeAncestorsFor(permissionPath)
22311
22342
  }
22312
22343
  })).canRead === true;
22313
22344
  } catch {
@@ -22335,12 +22366,17 @@ async function canWritePath(ctx, config, relPath) {
22335
22366
  relPath = resolveScopeAlias(relPath);
22336
22367
  if (!isTeamDeployment(config)) return checkLocalPath(relPath) === void 0;
22337
22368
  try {
22369
+ let permissionPath = relPath;
22370
+ if (relPath.startsWith("personal/")) {
22371
+ const who = await fetchCaller(ctx, config).catch(() => void 0);
22372
+ if (who !== void 0 && isSafeUserId(who.userId)) permissionPath = normalizePersonalWritePath(relPath, who.userId);
22373
+ }
22338
22374
  return (await request(ctx, config, ENDPOINTS.resolve, {
22339
22375
  method: "POST",
22340
22376
  body: {
22341
22377
  resourceType: KB_RESOURCE_TYPE,
22342
- resourceId: relPath,
22343
- ancestors: knowledgeAncestorsFor(relPath)
22378
+ resourceId: permissionPath,
22379
+ ancestors: knowledgeAncestorsFor(permissionPath)
22344
22380
  }
22345
22381
  })).canWrite === true;
22346
22382
  } catch {
@@ -24417,7 +24453,7 @@ function apply(ctx, deploymentConfig) {
24417
24453
  }
24418
24454
  case "create": {
24419
24455
  const body = await readJsonBody(req);
24420
- const relPath = String(body.relPath ?? "");
24456
+ let relPath = String(body.relPath ?? "");
24421
24457
  const directory = body.kind === "directory";
24422
24458
  const refusal = personalPathRefusal(config, relPath);
24423
24459
  if (refusal !== void 0) return writeJson(res, 400, {
@@ -24432,6 +24468,11 @@ function apply(ctx, deploymentConfig) {
24432
24468
  });
24433
24469
  const caller = await fetchCaller(host, config).catch(() => void 0);
24434
24470
  if (caller === void 0 || !isSafeUserId(caller.userId)) return writeJson(res, 400, { error: "unsafe or unreadable caller id" });
24471
+ relPath = normalizePersonalWritePath(relPath, caller.userId);
24472
+ if (!isContainedRelPath(relPath)) return writeJson(res, 400, {
24473
+ error: "path escapes the knowledge root",
24474
+ refused: [relPath]
24475
+ });
24435
24476
  if (!await canWritePath(host, config, relPath)) return writeJson(res, 403, {
24436
24477
  error: "write access is required to create this path",
24437
24478
  refused: [relPath]
@@ -24600,7 +24641,7 @@ function apply(ctx, deploymentConfig) {
24600
24641
  }
24601
24642
  case "upload": {
24602
24643
  const body = await readJsonBody(req);
24603
- const relPath = String(body.relPath ?? "");
24644
+ let relPath = String(body.relPath ?? "");
24604
24645
  const encoding = body.encoding === "base64" ? "base64" : "utf8";
24605
24646
  const content = typeof body.content === "string" ? body.content : "";
24606
24647
  const refusal = personalPathRefusal(config, relPath);
@@ -24622,6 +24663,11 @@ function apply(ctx, deploymentConfig) {
24622
24663
  });
24623
24664
  const caller = await fetchCaller(host, config).catch(() => void 0);
24624
24665
  if (caller === void 0 || !isSafeUserId(caller.userId)) return writeJson(res, 400, { error: "unsafe or unreadable caller id" });
24666
+ relPath = normalizePersonalWritePath(relPath, caller.userId);
24667
+ if (!isContainedRelPath(relPath)) return writeJson(res, 400, {
24668
+ error: "path escapes the knowledge root",
24669
+ refused: [relPath]
24670
+ });
24625
24671
  if (!await canWritePath(host, config, relPath)) return writeJson(res, 403, {
24626
24672
  error: "write access is required to upload here",
24627
24673
  refused: [relPath]
@@ -27171,4 +27217,4 @@ async function executeStep(runner, step, hostId, record) {
27171
27217
  }
27172
27218
  }
27173
27219
  //#endregion
27174
- export { BindingStore, Config, FACT_KINDS, GUARDIAN_SESSION_TITLE, GUARDIAN_SKILL_NAME, GraphLoadError, GuardianSessionStore, IDLE_DEBOUNCE_MS, KB_ROOT_RESOURCE_ID, KB_SUMMARIZE_SKILL_DESCRIPTION, KB_SUMMARIZE_SKILL_NAME, KB_SUMMARIZE_SKILL_RANK, KB_VECTORIZE_SKILL_DESCRIPTION, KB_VECTORIZE_SKILL_NAME, KB_VECTORIZE_SKILL_RANK, KNOWLEDGE_GRAPH_SKILL_DESCRIPTION, KNOWLEDGE_GRAPH_SKILL_NAME, KNOWLEDGE_SKILL_DESCRIPTION, KNOWLEDGE_SKILL_INVOCATION, KNOWLEDGE_SKILL_NAME, KNOWLEDGE_SKILL_PROVIDER, KNOWLEDGE_SKILL_RANK, KnowledgeError, KnowledgeWriteError, LOCAL_USER_ID, MAX_KNOWLEDGE_WRITE_BYTES, MEMORY_ENTRY_MARKER, MEMORY_EXTRACT_SKILL_NAME, MEMORY_FACT_FILE, MEMORY_GUARDIAN_SKILL_NAME, MEMORY_LOG_DIR, MEMORY_PITFALL_FILE, MEMORY_PREFERENCE_FILE, MEMORY_SOP_DIR, MEMORY_SOP_EVALUATE_SKILL_NAME, MEMORY_TYPES, MemoryGraphWriter, MemoryGraphWriterError, MemoryStore, MemoryStoreError, PERSONAL_MEMORY_FOLDER, PERSONAL_MEMORY_GRAPH_ID, PRIVACY_VALUES, SOP_STATUSES, TEMPLATE_READ_TIMEOUT_MS, actualRelPathForView, adoptViewFile, apply, applyMigration, applySummaryWriteback, assertValidMemoryEntry, bindingKey, canManageGrants, canManageGraph, canReadPath, canReviewWorkflows, canViewGraph, canWritePath, checkLocalPath, classifyMount, createGrant, createKnowledgeEntry, createMemoryGuardianTools, createMemoryRecordTools, createMemoryTools, decideMemoryAction, deleteSopAfterPromotion, diffSnapshots, extractBeside, extractionOutcomeOf, fetchCaller, fetchGrants, fetchPrincipals, filterVisibleGraphs, inject, installMemoryTriggers, isFactKind, isMemoryType, isPrivacy, isSafeMemorySlug, isSopStatus, isTeamDeployment, kbSummarizeSkillPath, kbVectorizeSkillPath, knowledgeAncestorsFor, knowledgeBaseSkillProvider, knowledgeBaseToolDisclosure, knowledgeGraphScopeRoots, knowledgeGraphSkillPath, knowledgeSkillPath, listDirectory, listDirectoryShapes, listDirectoryWithPermissions, listGraphs, listRelativeFiles, loadGraph, localConfig, localManagementContext, localStatus, localStorageRoot, markUpstreamUpdates, memoryExtractSkillPath, memoryGuardianSkillPath, memorySopEvaluateSkillPath, mineruUrlFor, name, newMemoryId, parentChain, parseMemoryEntries, parseNodeFrontMatter, permissionForKbRoute, planContext, planMigration, promoteSopToSkill, readAuthorized, readDepartmentOf, readKnowledgeFile, readKnowledgeFileForDownload, readSharedMineruUrl, refreshDirtySummaries, renderMemoryContextMarkdown, renderMigrationReport, resolveMemoryContext, resolveMineruUrl, resolveOrCreateGuardian, resolveWorkflowActor, revokeGrant, runGuardianPass, runtimeInjectionTags, scanKnowledgeTree, searchKnowledge, sendToGuardian, serializeMemoryEntry, summarySnapshotPathFor, syncCallerView, syncPersonalMemoryGraph, toolScopedActualPath, toolScopedViewPath, tutorialTemplatePath, validateGraph, validateMemoryEntry, withLocalStorageRoot, withStoredStorage };
27220
+ export { BindingStore, Config, FACT_KINDS, GUARDIAN_SESSION_TITLE, GUARDIAN_SKILL_NAME, GraphLoadError, GuardianSessionStore, IDLE_DEBOUNCE_MS, KB_ROOT_RESOURCE_ID, KB_SUMMARIZE_SKILL_DESCRIPTION, KB_SUMMARIZE_SKILL_NAME, KB_SUMMARIZE_SKILL_RANK, KB_VECTORIZE_SKILL_DESCRIPTION, KB_VECTORIZE_SKILL_NAME, KB_VECTORIZE_SKILL_RANK, KNOWLEDGE_GRAPH_SKILL_DESCRIPTION, KNOWLEDGE_GRAPH_SKILL_NAME, KNOWLEDGE_SKILL_DESCRIPTION, KNOWLEDGE_SKILL_INVOCATION, KNOWLEDGE_SKILL_NAME, KNOWLEDGE_SKILL_PROVIDER, KNOWLEDGE_SKILL_RANK, KnowledgeError, KnowledgeWriteError, LOCAL_USER_ID, MAX_KNOWLEDGE_WRITE_BYTES, MEMORY_ENTRY_MARKER, MEMORY_EXTRACT_SKILL_NAME, MEMORY_FACT_FILE, MEMORY_GUARDIAN_SKILL_NAME, MEMORY_LOG_DIR, MEMORY_PITFALL_FILE, MEMORY_PREFERENCE_FILE, MEMORY_SOP_DIR, MEMORY_SOP_EVALUATE_SKILL_NAME, MEMORY_TYPES, MemoryGraphWriter, MemoryGraphWriterError, MemoryStore, MemoryStoreError, PERSONAL_MEMORY_FOLDER, PERSONAL_MEMORY_GRAPH_ID, PRIVACY_VALUES, SOP_STATUSES, TEMPLATE_READ_TIMEOUT_MS, actualRelPathForView, adoptViewFile, apply, applyMigration, applySummaryWriteback, assertValidMemoryEntry, bindingKey, canManageGrants, canManageGraph, canReadPath, canReviewWorkflows, canViewGraph, canWritePath, checkLocalPath, classifyMount, createGrant, createKnowledgeEntry, createMemoryGuardianTools, createMemoryRecordTools, createMemoryTools, decideMemoryAction, deleteSopAfterPromotion, diffSnapshots, extractBeside, extractionOutcomeOf, fetchCaller, fetchGrants, fetchPrincipals, filterVisibleGraphs, inject, installMemoryTriggers, isFactKind, isMemoryType, isPrivacy, isSafeMemorySlug, isSopStatus, isTeamDeployment, kbSummarizeSkillPath, kbVectorizeSkillPath, knowledgeAncestorsFor, knowledgeBaseSkillProvider, knowledgeBaseToolDisclosure, knowledgeGraphScopeRoots, knowledgeGraphSkillPath, knowledgeSkillPath, listDirectory, listDirectoryShapes, listDirectoryWithPermissions, listGraphs, listRelativeFiles, loadGraph, localConfig, localManagementContext, localStatus, localStorageRoot, markUpstreamUpdates, memoryExtractSkillPath, memoryGuardianSkillPath, memorySopEvaluateSkillPath, mineruUrlFor, name, newMemoryId, normalizePersonalWritePath, parentChain, parseMemoryEntries, parseNodeFrontMatter, permissionForKbRoute, planContext, planMigration, promoteSopToSkill, readAuthorized, readDepartmentOf, readKnowledgeFile, readKnowledgeFileForDownload, readSharedMineruUrl, refreshDirtySummaries, renderMemoryContextMarkdown, renderMigrationReport, resolveMemoryContext, resolveMineruUrl, resolveOrCreateGuardian, resolveWorkflowActor, revokeGrant, runGuardianPass, runtimeInjectionTags, scanKnowledgeTree, searchKnowledge, sendToGuardian, serializeMemoryEntry, summarySnapshotPathFor, syncCallerView, syncPersonalMemoryGraph, toolScopedActualPath, toolScopedViewPath, tutorialTemplatePath, validateGraph, validateMemoryEntry, withLocalStorageRoot, withStoredStorage };
@@ -76,8 +76,26 @@ export interface KnowledgeContextMenuProps {
76
76
  shareCopy: ShareDialogCopy;
77
77
  /** Close the menu. */
78
78
  onClose: () => void;
79
+ /** Open one file for preview. Absent on a surface with no preview. */
80
+ onOpen?: (path: string) => void;
81
+ /**
82
+ * Move one row into a destination directory, both tree-relative.
83
+ *
84
+ * The destination is typed by the reader and resolved by the caller, because only the
85
+ * page knows the caller's authoritative `personal/<id>/...` path. Absent means this
86
+ * surface has no move route and the entry is not offered.
87
+ */
88
+ onMove?: (row: ContextTarget, destination: string) => Promise<void> | void;
79
89
  /** Open the permission surface for this path. */
80
- onGrant: (path: string) => void;
90
+ onGrant?: (path: string) => void;
91
+ /**
92
+ * Whether the caller may manage grants.
93
+ *
94
+ * The permission entry is hidden unless this is exactly true AND `onGrant` is present:
95
+ * a row that opens a surface the backend will refuse is worse than no row, and the
96
+ * answer comes from the Host rather than being derived here.
97
+ */
98
+ canManageGrants?: boolean;
81
99
  /** Toggle the pin state for this path. */
82
100
  onPin: (path: string, pinned: boolean) => void;
83
101
  /** Whether this path is currently pinned. */
@@ -177,6 +177,29 @@ export interface KnowledgeFileTreeProps {
177
177
  * reports where the click landed.
178
178
  */
179
179
  onPasteInto?: (directory: string) => void;
180
+ /**
181
+ * Open the page's own row menu at the pointer.
182
+ *
183
+ * This is how the KNOWLEDGE menu reaches a tree row. The explorer builds a workspace
184
+ * file menu inside itself (copy path, new folder, upload here), which is the wrong
185
+ * vocabulary for a curated knowledge export and cannot carry knowledge actions such
186
+ * as preview, permissions, or trash. When this hook is present the wrapper suppresses
187
+ * that menu for a row and hands the gesture to the page, which renders the same
188
+ * `KnowledgeContextMenu` the table uses. Omitted (the upload destination picker), the
189
+ * explorer menu is left untouched.
190
+ */
191
+ onRowContextMenu?: (target: {
192
+ relPath: string;
193
+ name: string;
194
+ isDir: boolean;
195
+ }, at: {
196
+ x: number;
197
+ y: number;
198
+ }, selection?: readonly {
199
+ relPath: string;
200
+ name: string;
201
+ isDir: boolean;
202
+ }[]) => void;
180
203
  /**
181
204
  * Called the moment an extraction is REQUESTED for one document, before it settles.
182
205
  *
@@ -45,6 +45,7 @@ export declare const en: {
45
45
  readonly grantsManaged: "Authorization is managed in DataOps.";
46
46
  readonly menu: "Sections";
47
47
  readonly 'menu.search': "Search";
48
+ readonly actionOpen: "Open preview";
48
49
  readonly actionDownload: "Download";
49
50
  readonly actionRename: "Rename…";
50
51
  readonly actionPin: "Pin";
@@ -263,6 +263,24 @@ export interface LocalPathRefusal {
263
263
  * @returns undefined when the path is allowed, else why it is not.
264
264
  */
265
265
  export declare function checkLocalPath(relPath: string): LocalPathRefusal | undefined;
266
+ /**
267
+ * Normalize a PERSONAL write path to the caller's own subtree.
268
+ *
269
+ * The page's upload destination is the virtual bucket `personal`, so a file dropped
270
+ * there arrives as `personal/<file>`. That spelling has no owner segment; writing it
271
+ * literally would put the document beside the owners and force the permission layer
272
+ * to grant the whole `personal` bucket, which resolves as shared across users.
273
+ * Rewriting it to `personal/<callerId>/<file>` keeps the owner in the path, makes the
274
+ * existing `personal/<userId>` grants sufficient, and keeps every user's personal
275
+ * bucket disjoint. An explicit `personal/<uuid>/…` is left untouched so a cross-user
276
+ * write still reaches the permission layer and is refused rather than silently
277
+ * redirected.
278
+ *
279
+ * @param relPath - the path as the caller sent it.
280
+ * @param callerId - the authenticated caller's user id.
281
+ * @returns the caller-scoped personal path, or the input when it is not personal.
282
+ */
283
+ export declare function normalizePersonalWritePath(relPath: string, callerId: string): string;
266
284
  /**
267
285
  * The resolved layout, derived on the Host.
268
286
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-knowledge-base",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
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",