@hi-man/himan 0.3.1 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ The format is based on Keep a Changelog, and this project follows semver for the
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.2] - 2026-05-08
10
+
11
+ ### Added
12
+
13
+ - Added `himan install <type> <name[@version]> --global` to install a resource into the matching user-level agent directory, reusing the current project's resource agent when available and without writing the project lock file.
14
+
9
15
  ## [0.3.1] - 2026-05-07
10
16
 
11
17
  ### Added
package/README.md CHANGED
@@ -56,11 +56,16 @@ himan publish rule my-rule --patch
56
56
  - `claude-code` -> `.claude/{rules|commands|skills}/<name>`
57
57
  - `codex` -> `.agents/{rules|commands|skills}/<name>`
58
58
  - `openclaw` -> `.openclaw/{rules|commands|skills}/<name>`
59
+ - 加 `--global` 时会安装到用户级 agent 目录,并仍按当前项目生效的 agent 选择目标:
60
+ - `cursor` -> `~/.cursor/{rules|commands|skills}/<name>`
61
+ - `claude-code` -> `~/.claude/{rules|commands|skills}/<name>`
62
+ - `codex` -> `~/.agents/{rules|commands|skills}/<name>`
63
+ - `openclaw` -> `~/.openclaw/{rules|commands|skills}/<name>`
59
64
  - 开发态目录:
60
65
  - `rule` -> `.himan/dev/rule/<name>`
61
66
  - `command` -> `.himan/dev/command/<name>`
62
67
  - `skill` -> `.himan/dev/skill/<name>`
63
- - lock 文件:`install <type> <name[@version]>` 会写入 `himan.lock`,记录 source、精确版本、agent 和安装模式;`himan install`(无参数)会按 lock 记录的 source 批量恢复安装,不受当前 default source 切换影响。
68
+ - lock 文件:项目安装 `install <type> <name[@version]>` 会写入 `himan.lock`,记录 source、精确版本、agent 和安装模式;`himan install`(无参数)会按 lock 记录的 source 批量恢复安装,不受当前 default source 切换影响。`--global` 安装不写当前项目的 `himan.lock`。
64
69
  - 安装模式:默认 `--mode link` 使用软链;也可用 `--mode copy` 将资源复制到目标 agent 目录,lock 会记录并复现该模式。
65
70
  - 默认 agent:`agent use <agent>` 默认写当前项目 `.himan/config.json`;加 `--global` 写入 `~/.himan/config.json`。当前项目配置优先于全局配置。
66
71
 
@@ -136,7 +141,7 @@ your-himan-source/
136
141
 
137
142
  | 命令 | 说明 |
138
143
  | --------------------------------- | --------------------------------------------------------- |
139
- | `install [type] [name[@version]] [--agent a,b] [--mode link\|copy]` | 有参数时从当前 default source 安装指定资源;**无参数**时按 `himan.lock` 记录的 source 批量安装;可覆盖安装目标 agent 或安装模式 |
144
+ | `install [type] [name[@version]] [--global] [--agent a,b] [--mode link\|copy]` | 有参数时从当前 default source 安装指定资源;**无参数**时按 `himan.lock` 记录的 source 批量安装;加 `--global` 时安装到用户级 agent 目录且不写项目 lock;可覆盖安装目标 agent 或安装模式 |
140
145
  | `dev <type> <name>` | 切换到开发态,并按安装模式将项目目标指向或复制自 `.himan/dev/...` |
141
146
  | `uninstall <type> <name>` | 从项目移除安装目标,并同步删除 `himan.lock` 条目 |
142
147
  | `publish <type> <name>` | 默认 `--patch`;可选 `--minor` / `--major`(勿同时使用多个) |
@@ -159,7 +164,7 @@ your-himan-source/
159
164
  - `himan agent list|use|current|clear ...`
160
165
 
161
166
  说明:资源与项目相关命令统一使用 `--agent` 指定目标 Agent。
162
- 若未显式传 `--agent`,`create` / `install` 会使用当前项目默认 agent、全局默认 agent、资源 metadata 或内置默认 `cursor` 中最合适的一项;`dev` 会优先使用 lock 中记录的 agent
167
+ 若未显式传 `--agent`,`create` / `install` 会使用当前项目默认 agent、全局默认 agent、资源 metadata 或内置默认 `cursor` 中最合适的一项;`dev` 会优先使用 lock 中记录的 agent。`install --global` 会优先复用当前项目 lock 里该资源的 agent,未命中时再使用默认 install 解析顺序,但目标根目录是用户 home 下对应 agent 目录。
163
168
 
164
169
  `publish` 优先使用项目里 `.himan/dev` 对应目录,否则用源仓库里对应目录。若资源目录包含 `himan.yaml`,发布前会校验元数据与入口文件;若没有 `himan.yaml`,则按默认入口推断最小元数据并发布,不会强制创建 `himan.yaml`。发布需要可推送的 Git 权限。发布 commit 会包含资源目录以及自动维护的 source 根目录 `README.md` / `CHANGELOG.md`。发布成功后会从新版本 store 以 `copy` 模式重新安装到项目目标、更新 lock,并删除对应 `.himan/dev/<type>/<name>` 开发目录。
165
170
 
@@ -63,7 +63,7 @@ Command groups:
63
63
  init, source init, source add, source use, source list, source init-docs
64
64
  resource Source resource discovery and metadata
65
65
  list, history, create, resource list, resource history, resource create
66
- project Resource usage lifecycle in current project
66
+ project Resource usage lifecycle in current project or user-level agent dirs
67
67
  install, dev, uninstall, publish,
68
68
  project install, project dev, project uninstall, project publish
69
69
  agent Default agent configuration
@@ -8,12 +8,17 @@ export function registerProjectCommands(command, services) {
8
8
  .argument("[name[@version]]", "resource name with optional @version")
9
9
  .option("--agent <list>", "install target agents, comma separated")
10
10
  .option("--mode <mode>", "install mode: link or copy")
11
+ .option("--global", "install into user-level agent directories")
11
12
  .description("Install resource, or install from himan.lock")
12
13
  .action(async (type, nameVersion, options) => {
13
14
  await runAction(async () => {
14
15
  const agents = parseAgents(options.agent);
15
16
  const mode = parseInstallMode(options.mode);
16
17
  if (!type && !nameVersion) {
18
+ if (options.global) {
19
+ throw new HimanError(errorCodes.CLI_USAGE, "Global install requires a resource:\n"
20
+ + " - himan install <type> <name[@version]> --global [--mode link|copy]");
21
+ }
17
22
  const results = await services.installFromLock(process.cwd(), agents, mode);
18
23
  if (results.length === 0) {
19
24
  process.stdout.write("No resources in lock file.\n");
@@ -27,12 +32,15 @@ export function registerProjectCommands(command, services) {
27
32
  if (!type || !nameVersion) {
28
33
  throw new HimanError(errorCodes.CLI_USAGE, "Install usage:\n"
29
34
  + " - himan install # install from himan.lock\n"
30
- + " - himan install <type> <name[@version]> [--mode link|copy] # install single resource");
35
+ + " - himan install <type> <name[@version]> [--mode link|copy] # install single resource\n"
36
+ + " - himan install <type> <name[@version]> --global [--mode link|copy] # install single resource globally");
31
37
  }
32
38
  const resourceType = ensureResourceType(type);
33
39
  const { name, version } = parseNameVersion(nameVersion);
34
- const result = await services.install(resourceType, name, version, process.cwd(), agents, mode);
35
- process.stdout.write(`Installed ${result.type}/${result.name}@${result.version}\n`);
40
+ const result = options.global
41
+ ? await services.installGlobal(resourceType, name, version, process.cwd(), agents, mode)
42
+ : await services.install(resourceType, name, version, process.cwd(), agents, mode);
43
+ process.stdout.write(`Installed ${options.global ? "global " : ""}${result.type}/${result.name}@${result.version}\n`);
36
44
  });
37
45
  });
38
46
  command
@@ -6,7 +6,7 @@ import { ProjectLockStore, } from "../state/project-lock-store.js";
6
6
  import { PathResolver } from "../utils/path-resolver.js";
7
7
  import { toRepoId } from "../utils/repo-id.js";
8
8
  import { HimanError, errorCodes } from "../utils/errors.js";
9
- import { getProjectResourcePaths, getSupportedAgentNames, normalizeAgents, } from "../utils/agent-configs.js";
9
+ import { getGlobalResourcePaths, getProjectResourcePaths, getSupportedAgentNames, normalizeAgents, } from "../utils/agent-configs.js";
10
10
  import path from "node:path";
11
11
  import { promises as fs } from "node:fs";
12
12
  import { VersionResolver } from "../adapters/version/version-resolver.js";
@@ -165,6 +165,10 @@ export class ServiceFactory {
165
165
  const { source, sourceInfo } = await this.loadSourceWithInfoFromConfig();
166
166
  return this.installWithSource(source, sourceInfo, type, name, version, projectDir, agents, mode);
167
167
  }
168
+ async installGlobal(type, name, version, projectDir, agents, mode = "link") {
169
+ const source = await this.loadSourceFromConfig();
170
+ return this.installWithSource(source, undefined, type, name, version, projectDir, agents, mode, "global");
171
+ }
168
172
  async dev(type, name, projectDir) {
169
173
  const installInfo = await this.resolveInstalledResource(projectDir, type, name);
170
174
  const installedPath = installInfo.installedPath;
@@ -263,12 +267,12 @@ export class ServiceFactory {
263
267
  const lockSourceInfo = this.normalizeLockSourceInfo(lock.source);
264
268
  const lockedSource = await this.loadSourceFromLock(lockSourceInfo);
265
269
  for (const item of lock.resources) {
266
- const result = await this.installWithSource(lockedSource, lockSourceInfo, item.type, item.name, item.version, projectDir, agents ?? item.agents, mode ?? this.resolveInstallMode(item.mode));
270
+ const result = await this.installWithSource(lockedSource, lockSourceInfo, item.type, item.name, item.version, projectDir, agents ?? item.agents, mode ?? this.resolveInstallMode(item.mode), "project");
267
271
  results.push(result);
268
272
  }
269
273
  return results;
270
274
  }
271
- async installWithSource(source, sourceInfo, type, name, version, projectDir, agents, mode) {
275
+ async installWithSource(source, sourceInfo, type, name, version, projectDir, agents, mode, scope = "project") {
272
276
  const history = await source.history(type, name);
273
277
  if (history.length === 0) {
274
278
  throw new HimanError(errorCodes.RESOURCE_NOT_FOUND, `Resource not found: ${type}/${name}`);
@@ -279,18 +283,27 @@ export class ServiceFactory {
279
283
  await source.pull(type, name, resolvedVersion, storePath);
280
284
  }
281
285
  const resourceMeta = await this.readResourceMetaFromDir(storePath, type);
282
- const effectiveTargets = await this.resolveEffectiveAgents(projectDir, agents, resourceMeta?.agents);
283
- const linkPaths = getProjectResourcePaths(projectDir, type, name, effectiveTargets);
286
+ const effectiveTargets = scope === "global"
287
+ ? await this.resolveGlobalInstallAgents(projectDir, type, name, agents, resourceMeta?.agents)
288
+ : await this.resolveEffectiveAgents(projectDir, agents, resourceMeta?.agents);
289
+ const linkPaths = scope === "global"
290
+ ? getGlobalResourcePaths(this.paths.getHomeDir(), type, name, effectiveTargets)
291
+ : getProjectResourcePaths(projectDir, type, name, effectiveTargets);
284
292
  for (const linkPath of linkPaths) {
285
293
  await this.materializeResource(storePath, linkPath, mode);
286
294
  }
287
- await this.lockStore.upsertResource(projectDir, sourceInfo, {
288
- type,
289
- name,
290
- version: resolvedVersion,
291
- agents: effectiveTargets,
292
- mode,
293
- });
295
+ if (scope === "project") {
296
+ if (!sourceInfo) {
297
+ throw new Error("Project install requires source lock information.");
298
+ }
299
+ await this.lockStore.upsertResource(projectDir, sourceInfo, {
300
+ type,
301
+ name,
302
+ version: resolvedVersion,
303
+ agents: effectiveTargets,
304
+ mode,
305
+ });
306
+ }
294
307
  return { type, name, version: resolvedVersion, linkPath: linkPaths[0], mode };
295
308
  }
296
309
  async loadSourceFromConfig() {
@@ -467,6 +480,16 @@ export class ServiceFactory {
467
480
  }
468
481
  return normalizeAgents(fallbackAgents);
469
482
  }
483
+ async resolveGlobalInstallAgents(projectDir, type, name, explicitAgents, fallbackAgents) {
484
+ if (explicitAgents?.length) {
485
+ return normalizeAgents(explicitAgents);
486
+ }
487
+ const locked = await this.getLockedResource(projectDir, type, name);
488
+ if (locked?.agents?.length) {
489
+ return normalizeAgents(locked.agents);
490
+ }
491
+ return this.resolveEffectiveAgents(projectDir, undefined, fallbackAgents);
492
+ }
470
493
  async getConfiguredAgents(projectDir) {
471
494
  const [globalConfig, projectConfig] = await Promise.all([
472
495
  this.stateStore.loadConfig(),
@@ -46,8 +46,14 @@ export function normalizeAgent(input) {
46
46
  return AGENT_ALIASES.get(input.trim().toLowerCase());
47
47
  }
48
48
  export function getProjectResourcePaths(projectDir, type, name, agents) {
49
+ return getResourcePaths(projectDir, type, name, agents);
50
+ }
51
+ export function getGlobalResourcePaths(homeDir, type, name, agents) {
52
+ return getResourcePaths(homeDir, type, name, agents);
53
+ }
54
+ function getResourcePaths(rootDir, type, name, agents) {
49
55
  const typeDir = getTypeDir(type);
50
- return normalizeAgents(agents).map((agent) => path.join(projectDir, getAgentBaseDir(agent), typeDir, name));
56
+ return normalizeAgents(agents).map((agent) => path.join(rootDir, getAgentBaseDir(agent), typeDir, name));
51
57
  }
52
58
  export function getSupportedAgentNames() {
53
59
  return AGENT_CONFIGS.map((config) => config.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-man/himan",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Prompt and agent asset management CLI",
5
5
  "keywords": [
6
6
  "ai",