@hi-man/himan 0.1.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/LICENSE +201 -0
- package/README.md +145 -0
- package/dist/adapters/git/repo-manager.js +70 -0
- package/dist/adapters/resource/resource-scanner.js +54 -0
- package/dist/adapters/source/git-source-adapter.js +149 -0
- package/dist/adapters/source/registry-source-adapter.js +21 -0
- package/dist/adapters/source/resource-source-adapter.js +1 -0
- package/dist/adapters/version/version-resolver.js +13 -0
- package/dist/cli/index.js +318 -0
- package/dist/domain/resource.js +1 -0
- package/dist/index.js +17 -0
- package/dist/services/index.js +331 -0
- package/dist/state/index-cache-store.js +48 -0
- package/dist/state/project-lock-store.js +72 -0
- package/dist/state/state-store.js +55 -0
- package/dist/utils/errors.js +25 -0
- package/dist/utils/path-resolver.js +16 -0
- package/dist/utils/repo-id.js +4 -0
- package/dist/version.js +10 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# himan
|
|
2
|
+
|
|
3
|
+
himan(含义为"Hey, man"),AI Coding 时代的 Prompt / Agent 资产管理系统(CLI + Git source)
|
|
4
|
+
|
|
5
|
+
## 安装与运行
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install
|
|
9
|
+
pnpm run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
之后任选其一执行命令:
|
|
13
|
+
|
|
14
|
+
- 已全局安装本包:`himan <子命令>`
|
|
15
|
+
- 本地开发:`pnpm run dev -- <子命令>`
|
|
16
|
+
- 或直接:`node dist/index.js <子命令>`
|
|
17
|
+
|
|
18
|
+
下文用 `himan` 代指上述入口。
|
|
19
|
+
|
|
20
|
+
## 一分钟上手
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
himan init https://github.com/your-org/your-himan-registry.git
|
|
24
|
+
himan list rule
|
|
25
|
+
himan install rule my-rule
|
|
26
|
+
himan dev rule my-rule
|
|
27
|
+
# 编辑项目下 .himan/dev/rule/my-rule/
|
|
28
|
+
himan publish rule my-rule --patch
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- **rule / command / skill**:都支持 `create`、`list`、`history`、`install`、`dev`、`publish`、`uninstall`。
|
|
32
|
+
- 安装后项目链接位置:
|
|
33
|
+
- `rule` -> `.cursor/rules/<name>`
|
|
34
|
+
- `command` -> `.cursor/commands/<name>`
|
|
35
|
+
- `skill` -> `.cursor/skills/<name>`
|
|
36
|
+
- 开发态目录:
|
|
37
|
+
- `rule` -> `.himan/dev/rule/<name>`
|
|
38
|
+
- `command` -> `.himan/dev/command/<name>`
|
|
39
|
+
- `skill` -> `.himan/dev/skill/<name>`
|
|
40
|
+
- lock 文件:`install <type> <name[@version]>` 会写入 `himan.lock`;`himan install`(无参数)会按 lock 批量恢复安装。
|
|
41
|
+
|
|
42
|
+
版本以 Git tag 为准,格式:`rule/my-rule@1.0.0`。更多设计见 [docs/mvp](./docs/mvp/README.md)。
|
|
43
|
+
|
|
44
|
+
## 常用命令
|
|
45
|
+
|
|
46
|
+
### 1) source(数据源)
|
|
47
|
+
|
|
48
|
+
| 命令 | 说明 |
|
|
49
|
+
| ----------------------------- | ------------------------------------------------ |
|
|
50
|
+
| `init <git_url>` | 初始化默认源(当前为 Git)并写入 `~/.himan/config.json` |
|
|
51
|
+
| `source add <name> <git_url>` | 添加命名 Git 源 |
|
|
52
|
+
| `source use <name>` | 切换默认源 |
|
|
53
|
+
| `source list [--json]` | 查看已配置源(标记当前 default) |
|
|
54
|
+
|
|
55
|
+
### 2) resource(资源)
|
|
56
|
+
|
|
57
|
+
| 命令 | 说明 |
|
|
58
|
+
| -------------------------------- | ----------------------------------------------------------------------------------- |
|
|
59
|
+
| `list [type] [--json]` | 列出当前 default source 的资源;`type` 为 `rule` / `command` / `skill`,默认 `rule` |
|
|
60
|
+
| `history <type> <name> [--json]` | 按 tag 查看版本历史 |
|
|
61
|
+
| `create <type> <name>` | 脚手架;常用选项:`--description`、`--target a,b`、`--dry-run`、`--force`、`--json` |
|
|
62
|
+
|
|
63
|
+
### 3) project(当前项目)
|
|
64
|
+
|
|
65
|
+
| 命令 | 说明 |
|
|
66
|
+
| --------------------------------- | --------------------------------------------------------- |
|
|
67
|
+
| `install [type] [name[@version]]` | 有参数时安装指定资源;**无参数**时按 `himan.lock` 批量安装 |
|
|
68
|
+
| `dev <type> <name>` | 切换到开发态并把项目链接指向 `.himan/dev/...` |
|
|
69
|
+
| `uninstall <type> <name>` | 从项目移除安装链接,并同步删除 `himan.lock` 条目 |
|
|
70
|
+
| `publish <type> <name>` | 默认 `--patch`;可选 `--minor` / `--major`(勿同时使用多个) |
|
|
71
|
+
|
|
72
|
+
`publish` 优先使用项目里 `.himan/dev` 对应目录,否则用源仓库里对应目录。需要可推送的 Git 权限。若该资源已在 lock 中,发布后会同步更新 lock 版本。
|
|
73
|
+
|
|
74
|
+
`--json` 模式下,失败时会输出机器可读错误 JSON(`stderr`)。错误码定义见 [docs/error-codes.md](./docs/error-codes.md)。
|
|
75
|
+
|
|
76
|
+
多源说明:当前是「**多来源可配置,单来源生效**」模型。业务命令(`list/install/history/dev/publish`)只作用于当前 default source;切换后再执行命令。
|
|
77
|
+
|
|
78
|
+
## 当前范围
|
|
79
|
+
|
|
80
|
+
- 源:**仅 Git**(`init`)。Registry 适配器已预留,尚未实现。
|
|
81
|
+
|
|
82
|
+
## FAQ
|
|
83
|
+
|
|
84
|
+
**Q: 为什么执行 `source add` 之后,`list` 结果没有变化?**
|
|
85
|
+
A: `source add` 只是在本地新增一个可用来源,不会自动切换当前生效来源。当前模型是“多来源可配置,单来源生效(default)”。
|
|
86
|
+
请执行:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
himan source use <name>
|
|
90
|
+
himan source list
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
确认目标来源已成为 `(default)` 后,再执行 `list/install/history/dev/publish`。
|
|
94
|
+
|
|
95
|
+
**Q: `list` 和 `source list` 有什么区别?**
|
|
96
|
+
A: `source list` 查看「我配置了哪些来源」;`list` 查看「当前 default source 里有哪些资源」。
|
|
97
|
+
|
|
98
|
+
## 开发与测试
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pnpm test
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 发布 npm 包(维护者)
|
|
105
|
+
|
|
106
|
+
### 流程概览
|
|
107
|
+
|
|
108
|
+
1. **在分支上完成开发与合并前检查**
|
|
109
|
+
本地可执行 `pnpm run verify`(类型检查、单测、`build`),确认通过后再提 PR。
|
|
110
|
+
|
|
111
|
+
2. **更新 `package.json` 中的 `version`**
|
|
112
|
+
npm 不允许重复发布同一版本号。合并进 `master` 前,在 PR 里把版本改成 registry 上尚未存在的号。
|
|
113
|
+
- 手动改 `version` 字段,或
|
|
114
|
+
- 在分支上执行其一(只改版本号,**不会**发包):`pnpm run version:patch` / `version:minor` / `version:major`(使用 `npm version … --no-git-tag-version`,需自行 `git add` / `commit` 版本变更)。
|
|
115
|
+
Git 标签约定:与 `version` 对应、带前缀 **`v`**(如 `1.2.0` → 标签 `v1.2.0`)。
|
|
116
|
+
|
|
117
|
+
3. **合并到 `master`**
|
|
118
|
+
推送合并后的 `master` 会触发 GitHub Actions 工作流 [`.github/workflows/publish-npm.yml`](.github/workflows/publish-npm.yml):安装依赖后执行 **`pnpm run release`**(即再次 `verify` + `npm publish`)。
|
|
119
|
+
需在仓库 **Settings → Secrets → Actions** 中配置 **`NPM_TOKEN`**(npm 侧「Access Tokens」,建议 Automation / 具备发包权限的 granular token)。
|
|
120
|
+
|
|
121
|
+
4. **手动从 CI 再发一次(可选)**
|
|
122
|
+
在 GitHub **Actions → Publish to npm → Run workflow** 可手动运行同一流程(例如在修复密钥后重试)。
|
|
123
|
+
|
|
124
|
+
### 本地命令(与 CI 中的 `pnpm run release` 一致)
|
|
125
|
+
|
|
126
|
+
| 命令 | 作用 |
|
|
127
|
+
|------|------|
|
|
128
|
+
| `pnpm run verify` | 仅检查(类型 / 测试 / 构建) |
|
|
129
|
+
| `pnpm run release:dry` | 检查 + `npm publish --dry-run`(演练,不上传) |
|
|
130
|
+
| `pnpm run release:test` | 检查 + 将版本打成 `*-test.*` 预发布号并发布到 **`@test` 标签** |
|
|
131
|
+
| `pnpm run release` | 检查 + 发布 **latest**(维护者本地发包时用;**请写 `pnpm run release`**,勿用裸命令 `pnpm publish`,二者不是同一套流程) |
|
|
132
|
+
| `pnpm run version:patch` / `version:minor` / `version:major` | 仅提升 `package.json` 版本号,不发包 |
|
|
133
|
+
|
|
134
|
+
发测试标签后,安装示例:`npm i @hi-man/himan@test`。
|
|
135
|
+
|
|
136
|
+
### CI:合并前校验与合并后打 Git 标签
|
|
137
|
+
|
|
138
|
+
| 工作流 | 文件 | 说明 |
|
|
139
|
+
|--------|------|------|
|
|
140
|
+
| **PR version tag check** | [`.github/workflows/pr-master-version-tag.yml`](.github/workflows/pr-master-version-tag.yml) | 目标分支为 `master` 的 PR:读取 **PR 头提交**上的 `package.json` 的 `version`,若远端已存在同名标签 **`v{version}`**,则 **检查失败**(用于在合并前拦截重复版本)。 |
|
|
141
|
+
| **Tag version on master** | [`.github/workflows/push-master-version-tag.yml`](.github/workflows/push-master-version-tag.yml) | 向 `master` **推送**后(含合并 PR):在 **当前推送提交**上创建并推送注释标签 **`v{version}`**。若标签已存在、创建或 `git push` 失败,仅输出 **告警**(`::warning::`),**工作流仍成功**,不撤销已发生的 merge;请按日志提示在本机补打标签并 `git push origin v{x.y.z}`。 |
|
|
142
|
+
|
|
143
|
+
**启用「合并前拦截」**:在 GitHub **Settings → Branches** 中为 `master` 配置分支保护,勾选 **Require status checks to pass before merging**,并勾选必选检查 **`PR version tag check / version-tag-available`**(名称以仓库里 Actions 界面为准)。
|
|
144
|
+
|
|
145
|
+
说明:来自 fork 的 PR 同样会跑上述 PR 检查;打标签工作流需要 **Actions 对仓库有写权限**(工作流内已设 `contents: write`)。若组织策略禁止 `GITHUB_TOKEN` 写标签,推送标签会失败,需按告警手动推送。
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { simpleGit } from "simple-git";
|
|
4
|
+
export class RepoManager {
|
|
5
|
+
async cloneOrFetch(repo, targetDir) {
|
|
6
|
+
const gitDir = path.join(targetDir, ".git");
|
|
7
|
+
const hasGitDir = await this.exists(gitDir);
|
|
8
|
+
if (!hasGitDir) {
|
|
9
|
+
await fs.mkdir(path.dirname(targetDir), { recursive: true });
|
|
10
|
+
await simpleGit().clone(repo, targetDir);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const git = simpleGit(targetDir);
|
|
14
|
+
await git.fetch(["--tags", "--prune"]);
|
|
15
|
+
}
|
|
16
|
+
async listTags(repoDir, pattern) {
|
|
17
|
+
const git = simpleGit(repoDir);
|
|
18
|
+
const output = await git.raw(["tag", "--list", pattern]);
|
|
19
|
+
return output
|
|
20
|
+
.split("\n")
|
|
21
|
+
.map((line) => line.trim())
|
|
22
|
+
.filter(Boolean);
|
|
23
|
+
}
|
|
24
|
+
async archiveResource(repoDir, tag, resourcePath, targetDir) {
|
|
25
|
+
await fs.rm(targetDir, { recursive: true, force: true });
|
|
26
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
27
|
+
const git = simpleGit(repoDir);
|
|
28
|
+
const output = await git.raw([
|
|
29
|
+
"ls-tree",
|
|
30
|
+
"-r",
|
|
31
|
+
"--name-only",
|
|
32
|
+
tag,
|
|
33
|
+
resourcePath,
|
|
34
|
+
]);
|
|
35
|
+
const files = output
|
|
36
|
+
.split("\n")
|
|
37
|
+
.map((line) => line.trim())
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
const content = await git.raw(["show", `${tag}:${file}`]);
|
|
41
|
+
const relative = path.relative(resourcePath, file);
|
|
42
|
+
const destination = path.join(targetDir, relative);
|
|
43
|
+
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
44
|
+
await fs.writeFile(destination, content, "utf8");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async commitTagAndPush(repoDir, message, tag, branch) {
|
|
48
|
+
const git = simpleGit(repoDir);
|
|
49
|
+
await git.add(["."]);
|
|
50
|
+
const status = await git.status();
|
|
51
|
+
if (status.isClean()) {
|
|
52
|
+
throw new Error("No changes to publish.");
|
|
53
|
+
}
|
|
54
|
+
await git.commit(message);
|
|
55
|
+
await git.addTag(tag);
|
|
56
|
+
const currentBranch = (await git.raw(["rev-parse", "--abbrev-ref", "HEAD"])).trim();
|
|
57
|
+
const targetBranch = branch ?? currentBranch;
|
|
58
|
+
await git.push("origin", targetBranch);
|
|
59
|
+
await git.pushTags("origin");
|
|
60
|
+
}
|
|
61
|
+
async exists(targetPath) {
|
|
62
|
+
try {
|
|
63
|
+
await fs.access(targetPath);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import YAML from "yaml";
|
|
4
|
+
export class ResourceScanner {
|
|
5
|
+
async scanRules(repoDir) {
|
|
6
|
+
return this.scanByType(repoDir, "rule");
|
|
7
|
+
}
|
|
8
|
+
async scanByType(repoDir, type) {
|
|
9
|
+
const baseDir = path.join(repoDir, this.getTypeDir(type));
|
|
10
|
+
const hasBaseDir = await this.exists(baseDir);
|
|
11
|
+
if (!hasBaseDir)
|
|
12
|
+
return [];
|
|
13
|
+
const entries = await fs.readdir(baseDir, { withFileTypes: true });
|
|
14
|
+
const resourceDirs = entries.filter((entry) => entry.isDirectory());
|
|
15
|
+
const result = [];
|
|
16
|
+
for (const resourceDir of resourceDirs) {
|
|
17
|
+
const yamlPath = path.join(baseDir, resourceDir.name, "himan.yaml");
|
|
18
|
+
if (!(await this.exists(yamlPath)))
|
|
19
|
+
continue;
|
|
20
|
+
const raw = await fs.readFile(yamlPath, "utf8");
|
|
21
|
+
const parsed = YAML.parse(raw);
|
|
22
|
+
if (!parsed)
|
|
23
|
+
continue;
|
|
24
|
+
if (parsed.type !== type)
|
|
25
|
+
continue;
|
|
26
|
+
if (!parsed.name || !parsed.entry)
|
|
27
|
+
continue;
|
|
28
|
+
result.push({
|
|
29
|
+
name: parsed.name,
|
|
30
|
+
type,
|
|
31
|
+
entry: parsed.entry,
|
|
32
|
+
description: parsed.description,
|
|
33
|
+
targets: parsed.targets,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
async exists(targetPath) {
|
|
39
|
+
try {
|
|
40
|
+
await fs.access(targetPath);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
getTypeDir(type) {
|
|
48
|
+
if (type === "rule")
|
|
49
|
+
return "rules";
|
|
50
|
+
if (type === "command")
|
|
51
|
+
return "commands";
|
|
52
|
+
return "skills";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { RepoManager } from "../git/repo-manager.js";
|
|
2
|
+
import { ResourceScanner } from "../resource/resource-scanner.js";
|
|
3
|
+
import semver from "semver";
|
|
4
|
+
import { HimanError, errorCodes } from "../../utils/errors.js";
|
|
5
|
+
import { promises as fs } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import YAML from "yaml";
|
|
8
|
+
import { IndexCacheStore } from "../../state/index-cache-store.js";
|
|
9
|
+
export class GitSourceAdapter {
|
|
10
|
+
repoManager = new RepoManager();
|
|
11
|
+
scanner = new ResourceScanner();
|
|
12
|
+
indexStore = new IndexCacheStore();
|
|
13
|
+
sourceConfig = null;
|
|
14
|
+
async init(sourceConfig) {
|
|
15
|
+
if (!sourceConfig.repo || !sourceConfig.repoDir) {
|
|
16
|
+
throw new HimanError(errorCodes.INVALID_INPUT, "Git source requires repo and repoDir.");
|
|
17
|
+
}
|
|
18
|
+
this.sourceConfig = sourceConfig;
|
|
19
|
+
await this.repoManager.cloneOrFetch(sourceConfig.repo, sourceConfig.repoDir);
|
|
20
|
+
}
|
|
21
|
+
async list(type) {
|
|
22
|
+
const repoDir = this.getRepoDir();
|
|
23
|
+
const repoId = this.sourceConfig?.repoId ?? "default";
|
|
24
|
+
const typeDir = this.getTypeDir(type);
|
|
25
|
+
const baseDir = path.join(repoDir, typeDir);
|
|
26
|
+
const baseDirMtimeMs = await this.getMtimeMs(baseDir);
|
|
27
|
+
const cached = await this.indexStore.get(repoId, type);
|
|
28
|
+
if (cached && cached.baseDirMtimeMs === baseDirMtimeMs) {
|
|
29
|
+
return cached.resources;
|
|
30
|
+
}
|
|
31
|
+
const scanned = await this.scanner.scanByType(repoDir, type);
|
|
32
|
+
await this.indexStore.upsert(repoId, type, baseDirMtimeMs, scanned);
|
|
33
|
+
return scanned;
|
|
34
|
+
}
|
|
35
|
+
async history(type, name) {
|
|
36
|
+
const tags = await this.repoManager.listTags(this.getRepoDir(), `${type}/${name}@*`);
|
|
37
|
+
const versions = tags
|
|
38
|
+
.map((tag) => ({ raw: tag, version: tag.split("@").at(1) ?? "" }))
|
|
39
|
+
.filter((item) => semver.valid(item.version))
|
|
40
|
+
.sort((a, b) => semver.rcompare(a.version, b.version));
|
|
41
|
+
return versions;
|
|
42
|
+
}
|
|
43
|
+
async pull(type, name, version, targetDir) {
|
|
44
|
+
const tag = `${type}/${name}@${version}`;
|
|
45
|
+
await this.repoManager.archiveResource(this.getRepoDir(), tag, `${type}s/${name}`, targetDir);
|
|
46
|
+
}
|
|
47
|
+
async publish(type, name, version, sourceDir) {
|
|
48
|
+
const repoDir = this.getRepoDir();
|
|
49
|
+
const targetDir = path.join(repoDir, `${type}s`, name);
|
|
50
|
+
const sameDir = await this.isSameDirectory(sourceDir, targetDir);
|
|
51
|
+
if (!sameDir) {
|
|
52
|
+
await fs.rm(targetDir, { recursive: true, force: true });
|
|
53
|
+
await fs.mkdir(path.dirname(targetDir), { recursive: true });
|
|
54
|
+
await fs.cp(sourceDir, targetDir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
const yamlPath = path.join(targetDir, "himan.yaml");
|
|
57
|
+
if (await this.exists(yamlPath)) {
|
|
58
|
+
const raw = await fs.readFile(yamlPath, "utf8");
|
|
59
|
+
const parsed = YAML.parse(raw);
|
|
60
|
+
parsed.version = version;
|
|
61
|
+
await fs.writeFile(yamlPath, YAML.stringify(parsed), "utf8");
|
|
62
|
+
}
|
|
63
|
+
const tag = `${type}/${name}@${version}`;
|
|
64
|
+
await this.repoManager.commitTagAndPush(repoDir, `publish ${type}/${name}@${version}`, tag);
|
|
65
|
+
return { version, tag };
|
|
66
|
+
}
|
|
67
|
+
async create(type, name, options) {
|
|
68
|
+
const repoDir = this.getRepoDir();
|
|
69
|
+
const resourceDir = path.join(repoDir, this.getTypeDir(type), name);
|
|
70
|
+
const entry = options.entry ?? this.getDefaultEntry(type);
|
|
71
|
+
const targets = options.targets?.length ? options.targets : ["cursor"];
|
|
72
|
+
if ((await this.exists(resourceDir)) && !options.force) {
|
|
73
|
+
throw new HimanError(errorCodes.RESOURCE_EXISTS, `Resource already exists: ${type}/${name}`);
|
|
74
|
+
}
|
|
75
|
+
const files = [path.join(resourceDir, "himan.yaml"), path.join(resourceDir, entry)];
|
|
76
|
+
if (!options.dryRun) {
|
|
77
|
+
await fs.rm(resourceDir, { recursive: true, force: true });
|
|
78
|
+
await fs.mkdir(resourceDir, { recursive: true });
|
|
79
|
+
await fs.writeFile(path.join(resourceDir, "himan.yaml"), YAML.stringify({
|
|
80
|
+
name,
|
|
81
|
+
type,
|
|
82
|
+
version: "0.1.0",
|
|
83
|
+
entry,
|
|
84
|
+
description: options.description ?? `${type} resource ${name}`,
|
|
85
|
+
targets,
|
|
86
|
+
}), "utf8");
|
|
87
|
+
await fs.writeFile(path.join(resourceDir, entry), this.getDefaultContent(type, name), "utf8");
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type,
|
|
91
|
+
name,
|
|
92
|
+
resourceDir,
|
|
93
|
+
files,
|
|
94
|
+
dryRun: Boolean(options.dryRun),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
getRepoDir() {
|
|
98
|
+
if (!this.sourceConfig?.repoDir) {
|
|
99
|
+
throw new HimanError(errorCodes.CONFIG_NOT_FOUND, "Git source is not initialized.");
|
|
100
|
+
}
|
|
101
|
+
return this.sourceConfig.repoDir;
|
|
102
|
+
}
|
|
103
|
+
async exists(targetPath) {
|
|
104
|
+
try {
|
|
105
|
+
await fs.access(targetPath);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async isSameDirectory(a, b) {
|
|
113
|
+
try {
|
|
114
|
+
const [ra, rb] = await Promise.all([fs.realpath(a), fs.realpath(b)]);
|
|
115
|
+
return ra === rb;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async getMtimeMs(targetPath) {
|
|
122
|
+
try {
|
|
123
|
+
const stat = await fs.stat(targetPath);
|
|
124
|
+
return stat.mtimeMs;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
getTypeDir(type) {
|
|
131
|
+
if (type === "rule")
|
|
132
|
+
return "rules";
|
|
133
|
+
if (type === "command")
|
|
134
|
+
return "commands";
|
|
135
|
+
return "skills";
|
|
136
|
+
}
|
|
137
|
+
getDefaultEntry(type) {
|
|
138
|
+
return type === "skill" ? "SKILL.md" : "content.md";
|
|
139
|
+
}
|
|
140
|
+
getDefaultContent(type, name) {
|
|
141
|
+
if (type === "rule") {
|
|
142
|
+
return `# ${name}\n\nDescribe rule instructions here.\n`;
|
|
143
|
+
}
|
|
144
|
+
if (type === "command") {
|
|
145
|
+
return `# ${name}\n\nDescribe command behavior here.\n`;
|
|
146
|
+
}
|
|
147
|
+
return `# ${name}\n\nDescribe skill workflow here.\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HimanError, errorCodes } from "../../utils/errors.js";
|
|
2
|
+
export class RegistrySourceAdapter {
|
|
3
|
+
async init(_sourceConfig) {
|
|
4
|
+
throw new HimanError(errorCodes.NOT_IMPLEMENTED, "Registry source is reserved for phase 2.");
|
|
5
|
+
}
|
|
6
|
+
async list(_type) {
|
|
7
|
+
throw new HimanError(errorCodes.NOT_IMPLEMENTED, "Registry source is reserved for phase 2.");
|
|
8
|
+
}
|
|
9
|
+
async history(_type, _name) {
|
|
10
|
+
throw new HimanError(errorCodes.NOT_IMPLEMENTED, "Registry source is reserved for phase 2.");
|
|
11
|
+
}
|
|
12
|
+
async pull(_type, _name, _version, _targetDir) {
|
|
13
|
+
throw new HimanError(errorCodes.NOT_IMPLEMENTED, "Registry source is reserved for phase 2.");
|
|
14
|
+
}
|
|
15
|
+
async publish(_type, _name, _version, _sourceDir) {
|
|
16
|
+
throw new HimanError(errorCodes.NOT_IMPLEMENTED, "Registry source is reserved for phase 2.");
|
|
17
|
+
}
|
|
18
|
+
async create(_type, _name, _options) {
|
|
19
|
+
throw new HimanError(errorCodes.NOT_IMPLEMENTED, "Registry source is reserved for phase 2.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
export class VersionResolver {
|
|
3
|
+
getLatest(versions) {
|
|
4
|
+
return semver.rsort(versions.filter((v) => semver.valid(v))).at(0);
|
|
5
|
+
}
|
|
6
|
+
nextVersion(current, releaseType) {
|
|
7
|
+
const next = semver.inc(current, releaseType);
|
|
8
|
+
if (!next) {
|
|
9
|
+
throw new Error(`Failed to bump version from ${current}`);
|
|
10
|
+
}
|
|
11
|
+
return next;
|
|
12
|
+
}
|
|
13
|
+
}
|