@michengai/dsh-skills-manager 1.2.21 → 1.2.23

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/core.js CHANGED
@@ -377,9 +377,10 @@ async function nearestProjectRoot(cwd) {
377
377
  let start;
378
378
  try {
379
379
  start = await fs.realpath(resolve(cwd));
380
- if (!(await fs.stat(start)).isDirectory()) return null;
381
- } catch {
382
- return { unavailable: true, cwd };
380
+ if (!(await fs.stat(start)).isDirectory()) return { unavailable: true, cwd, code: "ENOTDIR" };
381
+ } catch (caught) {
382
+ const error = caught;
383
+ return { unavailable: true, cwd, code: (error && typeof error === "object" && typeof error.code === "string" ? error.code : void 0) || "UNAVAILABLE" };
383
384
  }
384
385
  let current = start;
385
386
  for (; ; ) {
@@ -414,10 +415,12 @@ async function projectRoots(projectCwds = [], diagnostics) {
414
415
  const found = await nearestProjectRoot(cwd);
415
416
  if (!found || !found.root) {
416
417
  if (found && found.unavailable && Array.isArray(diagnostics) && typeof cwd === "string" && isAbsolute(cwd)) {
418
+ const warningCode = found.code === "ENOENT" || found.code === "ENOTDIR" ? "warning.project.missing" : found.code === "EACCES" || found.code === "EPERM" ? "warning.project.unreadable" : "warning.project.unavailable";
419
+ const warningError = warningCode === "warning.project.missing" ? `\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u53EF\u80FD\u5DF2\u88AB\u79FB\u52A8\u6216\u5220\u9664\uFF1A${cwd}` : warningCode === "warning.project.unreadable" ? `\u65E0\u6743\u9650\u8BFB\u53D6\u5DE5\u4F5C\u533A\u76EE\u5F55\uFF1A${cwd}\uFF08${found.code}\uFF09` : `\u65E0\u6CD5\u4ECE\u5BBF\u4E3B\u8BFB\u53D6\u6D3B\u52A8\u5DE5\u4F5C\u533A\uFF0C\u9879\u76EE\u6280\u80FD\u672A\u663E\u793A\uFF1A${cwd}`;
417
420
  diagnostics.push({
418
- code: "warning.project.unavailable",
419
- params: { path: cwd },
420
- error: `\u65E0\u6CD5\u4ECE\u5BBF\u4E3B\u8BFB\u53D6\u6D3B\u52A8\u5DE5\u4F5C\u533A\uFF0C\u9879\u76EE\u6280\u80FD\u672A\u663E\u793A: ${cwd}`
421
+ code: warningCode,
422
+ params: { path: cwd, ...found.code ? { code: found.code } : {} },
423
+ error: warningError
421
424
  });
422
425
  }
423
426
  continue;
@@ -488,10 +491,10 @@ async function indexRegisteredWorkspaces(registered) {
488
491
  }
489
492
  async function projectRootForRecord(projectRoot, registered, indexed) {
490
493
  if (typeof projectRoot !== "string" || !isAbsolute(projectRoot))
491
- return { ok: false, error: "\u5B89\u88C5\u8BB0\u5F55\u4E2D\u7684\u5DE5\u4F5C\u533A\u8DEF\u5F84\u65E0\u6548", code: "error.workspace.unavailable" };
494
+ return { ok: false, error: "\u5B89\u88C5\u8BB0\u5F55\u4E2D\u7684\u5DE5\u4F5C\u533A\u8DEF\u5F84\u65E0\u6548", code: "error.workspace.unavailable", params: { path: typeof projectRoot === "string" ? projectRoot : "" } };
492
495
  const saved = await nearestProjectRoot(projectRoot);
493
496
  if (!saved?.root || !sameWorkspace(saved.root, projectRoot))
494
- return { ok: false, error: `\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u53EF\u7528: ${projectRoot}`, code: "error.workspace.unavailable", params: { path: projectRoot } };
497
+ return { ok: false, error: `\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u53EF\u7528: ${projectRoot}`, code: "error.workspace.unavailable", params: { path: projectRoot, ...saved?.code ? { code: saved.code } : {} } };
495
498
  for (const target of indexed ?? await indexRegisteredWorkspaces(registered)) {
496
499
  if ("root" in target && sameWorkspace(target.root.projectRoot, projectRoot)) return target;
497
500
  }
@@ -513,7 +516,7 @@ async function resolveWorkspaceTarget(workspace, registered) {
513
516
  ok: false,
514
517
  error: `\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u53EF\u7528: ${requested}`,
515
518
  code: "error.workspace.unavailable",
516
- params: { path: requested }
519
+ params: { path: requested, ...found?.code ? { code: found.code } : {} }
517
520
  };
518
521
  const source = PROJECT_SOURCES.find((item) => item.key === "dsh");
519
522
  const root = {
@@ -3418,7 +3421,7 @@ async function listWorkspaces(registered) {
3418
3421
  if (!found || !found.root) {
3419
3422
  const key2 = `missing:${pathIdentity(path)}`;
3420
3423
  if (!rows.has(key2))
3421
- rows.set(key2, { name: basename(path) || path, path, registeredPaths: [path], available: false, skillCount: 0, roots: [] });
3424
+ rows.set(key2, { name: basename(path) || path, path, registeredPaths: [path], available: false, errorCode: found?.code, skillCount: 0, roots: [] });
3422
3425
  continue;
3423
3426
  }
3424
3427
  const key = pathIdentity(found.root);
@@ -3453,7 +3456,7 @@ async function workspaceSkills(workspace, registered) {
3453
3456
  if (!list.some((item) => sameWorkspace(item, requested))) return unregistered;
3454
3457
  const found = await nearestProjectRoot(requested);
3455
3458
  if (!found || !found.root)
3456
- return { ok: false, error: `\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u53EF\u7528: ${requested}`, code: "error.workspace.unavailable", params: { path: requested } };
3459
+ return { ok: false, error: `\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u53EF\u7528: ${requested}`, code: "error.workspace.unavailable", params: { path: requested, ...found?.code ? { code: found.code } : {} } };
3457
3460
  const snapshot = await state({ projectCwds: [found.cwd] });
3458
3461
  const identity = pathIdentity(found.root);
3459
3462
  const roots = snapshot.roots.filter((root) => root.scope === "project" && root.projectRoot && pathIdentity(root.projectRoot) === identity);