@hi-man/himan 0.1.0 → 0.2.0
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/README.md +54 -11
- package/dist/adapters/resource/resource-scanner.js +3 -1
- package/dist/adapters/source/git-source-adapter.js +2 -2
- package/dist/bin/himan-project.js +7 -0
- package/dist/bin/himan-resource.js +7 -0
- package/dist/bin/himan-source.js +7 -0
- package/dist/bin/himan.js +7 -0
- package/dist/{index.js → bin/shared.js} +3 -5
- package/dist/cli/agent-commands.js +93 -0
- package/dist/cli/builders.js +72 -0
- package/dist/cli/index.js +3 -318
- package/dist/cli/project-commands.js +127 -0
- package/dist/cli/resource-commands.js +104 -0
- package/dist/cli/shared.js +69 -0
- package/dist/cli/source-commands.js +58 -0
- package/dist/services/index.js +200 -44
- package/dist/state/project-config-store.js +43 -0
- package/dist/state/project-lock-store.js +4 -0
- package/dist/state/state-store.js +5 -1
- package/dist/utils/agent-configs.js +71 -0
- package/dist/{version.js → utils/version.js} +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -13,7 +13,13 @@ pnpm run build
|
|
|
13
13
|
|
|
14
14
|
- 已全局安装本包:`himan <子命令>`
|
|
15
15
|
- 本地开发:`pnpm run dev -- <子命令>`
|
|
16
|
-
- 或直接:`node dist/
|
|
16
|
+
- 或直接:`node dist/bin/himan.js <子命令>`
|
|
17
|
+
|
|
18
|
+
也支持两个独立入口:
|
|
19
|
+
|
|
20
|
+
- `himan-source <子命令>`(source 相关)
|
|
21
|
+
- `himan-resource <子命令>`(resource/project 相关)
|
|
22
|
+
- `himan-project <子命令>`(project 相关)
|
|
17
23
|
|
|
18
24
|
下文用 `himan` 代指上述入口。
|
|
19
25
|
|
|
@@ -22,6 +28,7 @@ pnpm run build
|
|
|
22
28
|
```bash
|
|
23
29
|
himan init https://github.com/your-org/your-himan-registry.git
|
|
24
30
|
himan list rule
|
|
31
|
+
himan agent use codex
|
|
25
32
|
himan install rule my-rule
|
|
26
33
|
himan dev rule my-rule
|
|
27
34
|
# 编辑项目下 .himan/dev/rule/my-rule/
|
|
@@ -29,15 +36,18 @@ himan publish rule my-rule --patch
|
|
|
29
36
|
```
|
|
30
37
|
|
|
31
38
|
- **rule / command / skill**:都支持 `create`、`list`、`history`、`install`、`dev`、`publish`、`uninstall`。
|
|
32
|
-
-
|
|
33
|
-
- `
|
|
34
|
-
- `
|
|
35
|
-
- `
|
|
39
|
+
- 安装后项目目标位置(按 `agents`,默认 `cursor`):
|
|
40
|
+
- `cursor` -> `.cursor/{rules|commands|skills}/<name>`
|
|
41
|
+
- `claude-code` -> `.claude/{rules|commands|skills}/<name>`
|
|
42
|
+
- `codex` -> `.agents/{rules|commands|skills}/<name>`
|
|
43
|
+
- `openclaw` -> `.openclaw/{rules|commands|skills}/<name>`
|
|
36
44
|
- 开发态目录:
|
|
37
45
|
- `rule` -> `.himan/dev/rule/<name>`
|
|
38
46
|
- `command` -> `.himan/dev/command/<name>`
|
|
39
47
|
- `skill` -> `.himan/dev/skill/<name>`
|
|
40
48
|
- lock 文件:`install <type> <name[@version]>` 会写入 `himan.lock`;`himan install`(无参数)会按 lock 批量恢复安装。
|
|
49
|
+
- 安装模式:默认 `--mode link` 使用软链;也可用 `--mode copy` 将资源复制到目标 agent 目录,lock 会记录并复现该模式。
|
|
50
|
+
- 默认 agent:`agent use <agent>` 默认写当前项目 `.himan/config.json`;加 `--global` 写入 `~/.himan/config.json`。当前项目配置优先于全局配置。
|
|
41
51
|
|
|
42
52
|
版本以 Git tag 为准,格式:`rule/my-rule@1.0.0`。更多设计见 [docs/mvp](./docs/mvp/README.md)。
|
|
43
53
|
|
|
@@ -51,24 +61,52 @@ himan publish rule my-rule --patch
|
|
|
51
61
|
| `source add <name> <git_url>` | 添加命名 Git 源 |
|
|
52
62
|
| `source use <name>` | 切换默认源 |
|
|
53
63
|
| `source list [--json]` | 查看已配置源(标记当前 default) |
|
|
64
|
+
| `source init <git_url>` | 与 `init` 等价,便于统一走 `himan source ...` 入口 |
|
|
65
|
+
|
|
66
|
+
等价独立命令:
|
|
67
|
+
|
|
68
|
+
- `himan-source init <git_url>`
|
|
69
|
+
- `himan-source add <name> <git_url>`
|
|
70
|
+
- `himan-source use <name>`
|
|
71
|
+
- `himan-source list [--json]`
|
|
54
72
|
|
|
55
73
|
### 2) resource(资源)
|
|
56
74
|
|
|
57
75
|
| 命令 | 说明 |
|
|
58
76
|
| -------------------------------- | ----------------------------------------------------------------------------------- |
|
|
59
|
-
| `list [type] [--json]`
|
|
77
|
+
| `list [type] [--agent a,b] [--json]` | 列出当前 default source 的资源;可按 agent 过滤;`type` 默认 `rule` |
|
|
60
78
|
| `history <type> <name> [--json]` | 按 tag 查看版本历史 |
|
|
61
|
-
| `create <type> <name>` | 脚手架;常用选项:`--description`、`--
|
|
79
|
+
| `create <type> <name>` | 脚手架;常用选项:`--description`、`--agent a,b`、`--dry-run`、`--force`、`--json` |
|
|
62
80
|
|
|
63
81
|
### 3) project(当前项目)
|
|
64
82
|
|
|
65
83
|
| 命令 | 说明 |
|
|
66
84
|
| --------------------------------- | --------------------------------------------------------- |
|
|
67
|
-
| `install [type] [name[@version]]` | 有参数时安装指定资源;**无参数**时按 `himan.lock`
|
|
68
|
-
| `dev <type> <name>` |
|
|
69
|
-
| `uninstall <type> <name>` |
|
|
85
|
+
| `install [type] [name[@version]] [--agent a,b] [--mode link\|copy]` | 有参数时安装指定资源;**无参数**时按 `himan.lock` 批量安装;可覆盖安装目标 agent 或安装模式 |
|
|
86
|
+
| `dev <type> <name>` | 切换到开发态,并按安装模式将项目目标指向或复制自 `.himan/dev/...` |
|
|
87
|
+
| `uninstall <type> <name>` | 从项目移除安装目标,并同步删除 `himan.lock` 条目 |
|
|
70
88
|
| `publish <type> <name>` | 默认 `--patch`;可选 `--minor` / `--major`(勿同时使用多个) |
|
|
71
89
|
|
|
90
|
+
### 4) agent(默认 Agent)
|
|
91
|
+
|
|
92
|
+
| 命令 | 说明 |
|
|
93
|
+
|------|------|
|
|
94
|
+
| `agent list [--json]` | 查看支持的 agent |
|
|
95
|
+
| `agent use <agent[,agent]> [--project\|--global] [--json]` | 设置当前项目或全局默认 agent;默认 `--project` |
|
|
96
|
+
| `agent current [--json]` | 查看当前项目、全局和最终生效的默认 agent |
|
|
97
|
+
| `agent clear [--project\|--global] [--json]` | 清除当前项目或全局默认 agent;默认 `--project` |
|
|
98
|
+
|
|
99
|
+
也可使用分组命令(与上面等价):
|
|
100
|
+
|
|
101
|
+
- `himan resource list|history|create ...`
|
|
102
|
+
- `himan-resource list|history|create ...`(兼容保留:也可执行 install/dev/uninstall/publish)
|
|
103
|
+
- `himan project install|dev|uninstall|publish ...`
|
|
104
|
+
- `himan-project install|dev|uninstall|publish ...`
|
|
105
|
+
- `himan agent list|use|current|clear ...`
|
|
106
|
+
|
|
107
|
+
说明:资源与项目相关命令统一使用 `--agent` 指定目标 Agent。
|
|
108
|
+
若未显式传 `--agent`,`create` / `install` 会使用当前项目默认 agent、全局默认 agent、资源 metadata 或内置默认 `cursor` 中最合适的一项;`dev` 会优先使用 lock 中记录的 agent。
|
|
109
|
+
|
|
72
110
|
`publish` 优先使用项目里 `.himan/dev` 对应目录,否则用源仓库里对应目录。需要可推送的 Git 权限。若该资源已在 lock 中,发布后会同步更新 lock 版本。
|
|
73
111
|
|
|
74
112
|
`--json` 模式下,失败时会输出机器可读错误 JSON(`stderr`)。错误码定义见 [docs/error-codes.md](./docs/error-codes.md)。
|
|
@@ -116,7 +154,12 @@ pnpm test
|
|
|
116
154
|
|
|
117
155
|
3. **合并到 `master`**
|
|
118
156
|
推送合并后的 `master` 会触发 GitHub Actions 工作流 [`.github/workflows/publish-npm.yml`](.github/workflows/publish-npm.yml):安装依赖后执行 **`pnpm run release`**(即再次 `verify` + `npm publish`)。
|
|
119
|
-
|
|
157
|
+
npm 发布认证使用 **Trusted Publishing**,不使用长期 `NPM_TOKEN`。需在 npmjs.com 的 `@hi-man/himan` 包设置中添加 Trusted Publisher:
|
|
158
|
+
- Provider: GitHub Actions
|
|
159
|
+
- Organization or user: `lidetao`
|
|
160
|
+
- Repository: `himan`
|
|
161
|
+
- Workflow filename: `publish-npm.yml`
|
|
162
|
+
workflow 已授予 OIDC 所需的 `id-token: write` 权限,并在发布前升级 npm CLI 到支持 Trusted Publishing 的版本。
|
|
120
163
|
|
|
121
164
|
4. **手动从 CI 再发一次(可选)**
|
|
122
165
|
在 GitHub **Actions → Publish to npm → Run workflow** 可手动运行同一流程(例如在修复密钥后重试)。
|
|
@@ -68,7 +68,7 @@ export class GitSourceAdapter {
|
|
|
68
68
|
const repoDir = this.getRepoDir();
|
|
69
69
|
const resourceDir = path.join(repoDir, this.getTypeDir(type), name);
|
|
70
70
|
const entry = options.entry ?? this.getDefaultEntry(type);
|
|
71
|
-
const
|
|
71
|
+
const agents = options.agents?.length ? options.agents : ["cursor"];
|
|
72
72
|
if ((await this.exists(resourceDir)) && !options.force) {
|
|
73
73
|
throw new HimanError(errorCodes.RESOURCE_EXISTS, `Resource already exists: ${type}/${name}`);
|
|
74
74
|
}
|
|
@@ -82,7 +82,7 @@ export class GitSourceAdapter {
|
|
|
82
82
|
version: "0.1.0",
|
|
83
83
|
entry,
|
|
84
84
|
description: options.description ?? `${type} resource ${name}`,
|
|
85
|
-
|
|
85
|
+
agents,
|
|
86
86
|
}), "utf8");
|
|
87
87
|
await fs.writeFile(path.join(resourceDir, entry), this.getDefaultContent(type, name), "utf8");
|
|
88
88
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import { CommanderError } from "commander";
|
|
3
|
-
import {
|
|
4
|
-
async function
|
|
5
|
-
const program =
|
|
2
|
+
import { writeCliError } from "../cli/index.js";
|
|
3
|
+
export async function runCliMain(buildProgram) {
|
|
4
|
+
const program = buildProgram();
|
|
6
5
|
try {
|
|
7
6
|
await program.parseAsync(process.argv);
|
|
8
7
|
}
|
|
@@ -14,4 +13,3 @@ async function main() {
|
|
|
14
13
|
process.exitCode = error instanceof CommanderError ? error.exitCode : 1;
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
void main();
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { HimanError, errorCodes } from "../utils/errors.js";
|
|
2
|
+
import { getSupportedAgentNames, normalizeAgent } from "../utils/agent-configs.js";
|
|
3
|
+
import { runAction } from "./shared.js";
|
|
4
|
+
export function registerAgentCommands(command, services) {
|
|
5
|
+
command
|
|
6
|
+
.command("list")
|
|
7
|
+
.option("--json", "output json format")
|
|
8
|
+
.description("List supported agents")
|
|
9
|
+
.action(async (options) => {
|
|
10
|
+
await runAction(async () => {
|
|
11
|
+
const agents = getSupportedAgentNames();
|
|
12
|
+
if (options.json) {
|
|
13
|
+
process.stdout.write(`${JSON.stringify(agents, null, 2)}\n`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
for (const agent of agents) {
|
|
17
|
+
process.stdout.write(`- ${agent}\n`);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
command
|
|
22
|
+
.command("use")
|
|
23
|
+
.argument("<agent_list>", "agent list, comma separated")
|
|
24
|
+
.option("--global", "save as global default")
|
|
25
|
+
.option("--project", "save as current project default")
|
|
26
|
+
.option("--json", "output json format")
|
|
27
|
+
.description("Set default agents globally or for current project")
|
|
28
|
+
.action(async (agentList, options) => {
|
|
29
|
+
await runAction(async () => {
|
|
30
|
+
const scope = parseScope(options);
|
|
31
|
+
const result = await services.setAgents(parseAgents(agentList), scope, process.cwd());
|
|
32
|
+
if (options.json) {
|
|
33
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
process.stdout.write(`Using agents (${result.scope}): ${result.agents.join(", ")}\n`);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
command
|
|
40
|
+
.command("current")
|
|
41
|
+
.option("--json", "output json format")
|
|
42
|
+
.description("Show configured and effective default agents")
|
|
43
|
+
.action(async (options) => {
|
|
44
|
+
await runAction(async () => {
|
|
45
|
+
const settings = await services.getAgentSettings(process.cwd());
|
|
46
|
+
if (options.json) {
|
|
47
|
+
process.stdout.write(`${JSON.stringify(settings, null, 2)}\n`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
process.stdout.write(`effective: ${settings.effective.join(", ")}\n`);
|
|
51
|
+
process.stdout.write(`project: ${(settings.project ?? []).join(", ") || "-"}\n`);
|
|
52
|
+
process.stdout.write(`global: ${(settings.global ?? []).join(", ") || "-"}\n`);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
command
|
|
56
|
+
.command("clear")
|
|
57
|
+
.option("--global", "clear global default agents")
|
|
58
|
+
.option("--project", "clear current project default agents")
|
|
59
|
+
.option("--json", "output json format")
|
|
60
|
+
.description("Clear configured default agents")
|
|
61
|
+
.action(async (options) => {
|
|
62
|
+
await runAction(async () => {
|
|
63
|
+
const result = await services.clearAgents(parseScope(options), process.cwd());
|
|
64
|
+
if (options.json) {
|
|
65
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
process.stdout.write(`Cleared agents (${result.scope}).\n`);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function parseScope(options) {
|
|
73
|
+
if (options.global && options.project) {
|
|
74
|
+
throw new HimanError(errorCodes.CLI_USAGE, "Use only one of --global or --project.");
|
|
75
|
+
}
|
|
76
|
+
return options.global ? "global" : "project";
|
|
77
|
+
}
|
|
78
|
+
function parseAgents(input) {
|
|
79
|
+
const agents = input
|
|
80
|
+
.split(",")
|
|
81
|
+
.map((item) => item.trim())
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
if (agents.length === 0) {
|
|
84
|
+
throw new HimanError(errorCodes.INVALID_INPUT, "Agent list cannot be empty.");
|
|
85
|
+
}
|
|
86
|
+
const supported = getSupportedAgentNames();
|
|
87
|
+
for (const agent of agents) {
|
|
88
|
+
if (!normalizeAgent(agent)) {
|
|
89
|
+
throw new HimanError(errorCodes.INVALID_INPUT, `Unsupported agent: ${agent}. Supported agents: ${supported.join(", ")}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return agents;
|
|
93
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ServiceFactory } from "../services/index.js";
|
|
2
|
+
import { registerAgentCommands } from "./agent-commands.js";
|
|
3
|
+
import { registerProjectCommands } from "./project-commands.js";
|
|
4
|
+
import { registerResourceCommands } from "./resource-commands.js";
|
|
5
|
+
import { registerInitCommand, registerSourceCommands } from "./source-commands.js";
|
|
6
|
+
import { createBaseProgram } from "./shared.js";
|
|
7
|
+
export function buildCli() {
|
|
8
|
+
const program = createBaseProgram("himan", "Prompt and agent asset management CLI");
|
|
9
|
+
const services = new ServiceFactory();
|
|
10
|
+
appendCommandGroupsHelp(program);
|
|
11
|
+
registerInitCommand(program, services);
|
|
12
|
+
const sourceCmd = program.command("source").description("Manage source repositories");
|
|
13
|
+
registerSourceCommands(sourceCmd, services, { includeInit: true });
|
|
14
|
+
const resourceCmd = program
|
|
15
|
+
.command("resource")
|
|
16
|
+
.description("Manage resources from current default source");
|
|
17
|
+
registerResourceCommands(resourceCmd, services);
|
|
18
|
+
const projectCmd = program
|
|
19
|
+
.command("project")
|
|
20
|
+
.description("Manage installed resources in current project");
|
|
21
|
+
registerProjectCommands(projectCmd, services);
|
|
22
|
+
const agentCmd = program
|
|
23
|
+
.command("agent")
|
|
24
|
+
.description("Manage default agent configuration");
|
|
25
|
+
registerAgentCommands(agentCmd, services);
|
|
26
|
+
// Backward compatible top-level resource lifecycle commands.
|
|
27
|
+
registerResourceCommands(program, services);
|
|
28
|
+
registerProjectCommands(program, services);
|
|
29
|
+
return program;
|
|
30
|
+
}
|
|
31
|
+
export function buildSourceCli() {
|
|
32
|
+
const program = createBaseProgram("himan-source", "Source repository management CLI");
|
|
33
|
+
const services = new ServiceFactory();
|
|
34
|
+
registerSourceCommands(program, services, { includeInit: true });
|
|
35
|
+
return program;
|
|
36
|
+
}
|
|
37
|
+
export function buildResourceCli() {
|
|
38
|
+
const program = createBaseProgram("himan-resource", "Resource lifecycle management CLI");
|
|
39
|
+
const services = new ServiceFactory();
|
|
40
|
+
registerResourceCommands(program, services);
|
|
41
|
+
const agentCmd = program
|
|
42
|
+
.command("agent")
|
|
43
|
+
.description("Manage default agent configuration");
|
|
44
|
+
registerAgentCommands(agentCmd, services);
|
|
45
|
+
// Backward compatible: keep project lifecycle commands in himan-resource.
|
|
46
|
+
registerProjectCommands(program, services);
|
|
47
|
+
return program;
|
|
48
|
+
}
|
|
49
|
+
export function buildProjectCli() {
|
|
50
|
+
const program = createBaseProgram("himan-project", "Project lifecycle management CLI");
|
|
51
|
+
const services = new ServiceFactory();
|
|
52
|
+
const agentCmd = program
|
|
53
|
+
.command("agent")
|
|
54
|
+
.description("Manage default agent configuration");
|
|
55
|
+
registerAgentCommands(agentCmd, services);
|
|
56
|
+
registerProjectCommands(program, services);
|
|
57
|
+
return program;
|
|
58
|
+
}
|
|
59
|
+
function appendCommandGroupsHelp(program) {
|
|
60
|
+
program.addHelpText("after", `
|
|
61
|
+
Command groups:
|
|
62
|
+
source Data source management (git now, registry reserved)
|
|
63
|
+
init, source init, source add, source use, source list
|
|
64
|
+
resource Source resource discovery and metadata
|
|
65
|
+
list, history, create, resource list, resource history, resource create
|
|
66
|
+
project Resource usage lifecycle in current project
|
|
67
|
+
install, dev, uninstall, publish,
|
|
68
|
+
project install, project dev, project uninstall, project publish
|
|
69
|
+
agent Default agent configuration
|
|
70
|
+
agent list, agent use, agent current, agent clear
|
|
71
|
+
`);
|
|
72
|
+
}
|