hiwork-core 0.0.1

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 默认工作区:登录成功且 registry 无任何工作区时,建 ~/HiWork/Default 并注册到
3
+ * workspaceRegistry —— DSH 客户端启动/新会话时会自动连接「最近工作区」,新用户
4
+ * 无需理解工作区概念即可开始聊天。永不抛出:任何失败只 warn,不阻断登录编排。
5
+ */
6
+ import { mkdir } from 'node:fs/promises';
7
+ import { homedir } from 'node:os';
8
+ import { join } from 'node:path';
9
+ export const DEFAULT_WORKSPACE_DIR = join(homedir(), 'HiWork', 'Default');
10
+ export const DEFAULT_WORKSPACE_TITLE = '默认工作区';
11
+ export async function ensureDefaultWorkspace(registry, warn, dir = DEFAULT_WORKSPACE_DIR) {
12
+ try {
13
+ if (registry.list().length > 0)
14
+ return;
15
+ await mkdir(dir, { recursive: true });
16
+ await registry.create(dir, DEFAULT_WORKSPACE_TITLE);
17
+ }
18
+ catch (error) {
19
+ warn(`hiwork-core: ensure default workspace failed: ${error instanceof Error ? error.message : String(error)}`);
20
+ }
21
+ }