human2ai 0.1.4 → 0.1.6

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.
Files changed (181) hide show
  1. package/README.en.md +51 -28
  2. package/README.md +51 -28
  3. package/dist/cli/main.js +33 -21
  4. package/dist/cli/main.js.map +1 -1
  5. package/dist/database/composition-session-repository.d.ts +2 -0
  6. package/dist/database/composition-session-repository.js +1 -0
  7. package/dist/database/composition-session-repository.js.map +1 -1
  8. package/dist/database/draft-version-store.d.ts +8 -1
  9. package/dist/database/draft-version-store.js +21 -4
  10. package/dist/database/draft-version-store.js.map +1 -1
  11. package/dist/database/project-session-repository.d.ts +24 -1
  12. package/dist/database/project-session-repository.js +80 -0
  13. package/dist/database/project-session-repository.js.map +1 -1
  14. package/dist/database/session-preview-validation.d.ts +3 -0
  15. package/dist/database/session-preview-validation.js +44 -0
  16. package/dist/database/session-preview-validation.js.map +1 -0
  17. package/dist/database/spatial-session-repository.d.ts +2 -0
  18. package/dist/database/spatial-session-repository.js +1 -0
  19. package/dist/database/spatial-session-repository.js.map +1 -1
  20. package/dist/database/svg-input.js +9 -1
  21. package/dist/database/svg-input.js.map +1 -1
  22. package/dist/database/ui-sketch-session-repository.d.ts +3 -0
  23. package/dist/database/ui-sketch-session-repository.js +6 -0
  24. package/dist/database/ui-sketch-session-repository.js.map +1 -1
  25. package/dist/domain/canvas-frame.d.ts +15 -0
  26. package/dist/domain/canvas-frame.js +24 -0
  27. package/dist/domain/canvas-frame.js.map +1 -0
  28. package/dist/domain/canvas-node-tone.d.ts +1 -0
  29. package/dist/domain/canvas-node-tone.js +9 -0
  30. package/dist/domain/canvas-node-tone.js.map +1 -0
  31. package/dist/domain/canvas-shape-overlap.d.ts +12 -0
  32. package/dist/domain/canvas-shape-overlap.js +79 -0
  33. package/dist/domain/canvas-shape-overlap.js.map +1 -0
  34. package/dist/domain/composition/analysis.d.ts +1 -0
  35. package/dist/domain/composition/analysis.js +6 -3
  36. package/dist/domain/composition/analysis.js.map +1 -1
  37. package/dist/domain/composition/draft.d.ts +6 -1
  38. package/dist/domain/composition/draft.js +43 -28
  39. package/dist/domain/composition/draft.js.map +1 -1
  40. package/dist/domain/composition/frame.d.ts +5 -8
  41. package/dist/domain/composition/frame.js +21 -68
  42. package/dist/domain/composition/frame.js.map +1 -1
  43. package/dist/domain/composition/index.d.ts +3 -3
  44. package/dist/domain/composition/index.js +3 -3
  45. package/dist/domain/composition/index.js.map +1 -1
  46. package/dist/domain/composition/raster.d.ts +2 -0
  47. package/dist/domain/composition/raster.js +19 -0
  48. package/dist/domain/composition/raster.js.map +1 -0
  49. package/dist/domain/composition/refinement/engine.js +1 -0
  50. package/dist/domain/composition/refinement/engine.js.map +1 -1
  51. package/dist/domain/composition/refinement/types.d.ts +1 -0
  52. package/dist/domain/composition/render.d.ts +6 -0
  53. package/dist/domain/composition/render.js +84 -20
  54. package/dist/domain/composition/render.js.map +1 -1
  55. package/dist/domain/composition/states.js +14 -8
  56. package/dist/domain/composition/states.js.map +1 -1
  57. package/dist/domain/composition/text-warp.d.ts +8 -0
  58. package/dist/domain/composition/text-warp.js +60 -0
  59. package/dist/domain/composition/text-warp.js.map +1 -0
  60. package/dist/domain/composition/types.d.ts +9 -4
  61. package/dist/domain/session/canvas-edit-history.d.ts +2 -0
  62. package/dist/domain/session/canvas-edit-history.js +2 -0
  63. package/dist/domain/session/canvas-edit-history.js.map +1 -1
  64. package/dist/domain/session/preview.d.ts +16 -0
  65. package/dist/domain/session/preview.js +48 -0
  66. package/dist/domain/session/preview.js.map +1 -0
  67. package/dist/domain/session/types.d.ts +8 -0
  68. package/dist/domain/ui-sketch/appearance.d.ts +12 -0
  69. package/dist/domain/ui-sketch/appearance.js +24 -0
  70. package/dist/domain/ui-sketch/appearance.js.map +1 -0
  71. package/dist/domain/ui-sketch/draft.js +3 -1
  72. package/dist/domain/ui-sketch/draft.js.map +1 -1
  73. package/dist/domain/ui-sketch/render.js +21 -17
  74. package/dist/domain/ui-sketch/render.js.map +1 -1
  75. package/dist/domain/ui-sketch/session-preview.d.ts +27 -0
  76. package/dist/domain/ui-sketch/session-preview.js +43 -0
  77. package/dist/domain/ui-sketch/session-preview.js.map +1 -0
  78. package/dist/domain/ui-sketch/types.d.ts +2 -0
  79. package/dist/server/app.d.ts +1 -1
  80. package/dist/server/app.js +8 -0
  81. package/dist/server/app.js.map +1 -1
  82. package/dist/server/routes/project-sessions.js +47 -3
  83. package/dist/server/routes/project-sessions.js.map +1 -1
  84. package/dist/server/routes/session-previews.d.ts +3 -0
  85. package/dist/server/routes/session-previews.js +104 -0
  86. package/dist/server/routes/session-previews.js.map +1 -0
  87. package/dist/server/session-preview-service.d.ts +55 -0
  88. package/dist/server/session-preview-service.js +255 -0
  89. package/dist/server/session-preview-service.js.map +1 -0
  90. package/locales/en/common.json +72 -8
  91. package/migrations/0011_session_groups.sql +21 -0
  92. package/package.json +1 -1
  93. package/schemas/composition-draft.schema.json +11 -2
  94. package/schemas/ui-sketch-draft.schema.json +85 -0
  95. package/skills/human2ai/SKILL.md +1 -1
  96. package/skills/human2ai/references/composition-projection.md +5 -3
  97. package/skills/human2ai/references/composition.md +51 -10
  98. package/skills/human2ai/references/ui-layout.md +7 -1
  99. package/web/out/404/index.html +1 -1
  100. package/web/out/404.html +1 -1
  101. package/web/out/__next.__PAGE__.txt +15 -14
  102. package/web/out/__next._full.txt +24 -23
  103. package/web/out/__next._tree.txt +6 -6
  104. package/web/out/_next/static/chunks/{635-611c009924b842be.js → 164-d8dd2b053f27bf62.js} +30 -30
  105. package/web/out/_next/static/chunks/348-6baeec6b3dbf02ab.js +1 -0
  106. package/web/out/_next/static/chunks/app/_not-found/page-742cf440bebb3b9b.js +1 -0
  107. package/web/out/_next/static/chunks/app/composition/page-8d037a4b99bb5546.js +1 -0
  108. package/web/out/_next/static/chunks/app/layout-ca2f61a5a618caea.js +1 -0
  109. package/web/out/_next/static/chunks/app/page-9b8bd42a93c9242c.js +1 -0
  110. package/web/out/_next/static/chunks/app/spatial/page-1d16089ca24b2eb8.js +1 -0
  111. package/web/out/_next/static/chunks/app/styles/page-e4d3c95957349351.js +1 -0
  112. package/web/out/_next/static/chunks/app/ui-sketch/page-23e5c3b12d99082c.js +1 -0
  113. package/web/out/_next/static/chunks/{main-app-cf37a257d91ce62e.js → main-app-5419a575f3ff4496.js} +1 -1
  114. package/web/out/_next/static/chunks/next/dist/client/components/builtin/global-error-15f5118ed5e001a8.js +1 -0
  115. package/web/out/_next/static/chunks/webpack-e781b4e158568ba0.js +1 -0
  116. package/web/out/_next/static/css/{3b7982b41ed8eccd.css → 210db1811016f805.css} +1 -1
  117. package/web/out/_next/static/css/2160a6bbf2cb551c.css +1 -0
  118. package/web/out/_next/static/css/28a4978acacc40b0.css +1 -0
  119. package/web/out/_next/static/css/{c739d0131cdcc891.css → 2a0db06638359895.css} +1 -1
  120. package/web/out/_next/static/css/4b1f9941c214d619.css +5 -0
  121. package/web/out/_next/static/css/9c61ee5fe683073a.css +1 -0
  122. package/web/out/_next/static/css/c39f5ecbfc8cb532.css +1 -0
  123. package/web/out/_not-found/__next._full.txt +21 -18
  124. package/web/out/_not-found/__next._not-found.__PAGE__.txt +11 -8
  125. package/web/out/_not-found/__next._tree.txt +5 -3
  126. package/web/out/_not-found/index.html +1 -1
  127. package/web/out/_not-found/index.txt +21 -18
  128. package/web/out/brand/h2a-1024.png +0 -0
  129. package/web/out/brand/h2a-128.png +0 -0
  130. package/web/out/brand/h2a-16.png +0 -0
  131. package/web/out/brand/h2a-256.png +0 -0
  132. package/web/out/brand/h2a-32.png +0 -0
  133. package/web/out/brand/h2a-48.png +0 -0
  134. package/web/out/brand/h2a-512.png +0 -0
  135. package/web/out/brand/h2a-64.png +0 -0
  136. package/web/out/brand/h2a.svg +10 -1
  137. package/web/out/composition/__next._full.txt +26 -26
  138. package/web/out/composition/__next._tree.txt +6 -7
  139. package/web/out/composition/__next.composition.__PAGE__.txt +13 -13
  140. package/web/out/composition/index.html +1 -1
  141. package/web/out/composition/index.txt +26 -26
  142. package/web/out/favicon.ico +0 -0
  143. package/web/out/icon.svg +10 -1
  144. package/web/out/index.html +1 -1
  145. package/web/out/index.txt +24 -23
  146. package/web/out/spatial/__next._full.txt +25 -24
  147. package/web/out/spatial/__next._tree.txt +5 -5
  148. package/web/out/spatial/__next.spatial.__PAGE__.txt +12 -11
  149. package/web/out/spatial/index.html +1 -1
  150. package/web/out/spatial/index.txt +25 -24
  151. package/web/out/styles/__next._full.txt +25 -24
  152. package/web/out/styles/__next._tree.txt +5 -5
  153. package/web/out/styles/__next.styles.__PAGE__.txt +12 -11
  154. package/web/out/styles/index.html +1 -1
  155. package/web/out/styles/index.txt +25 -24
  156. package/web/out/ui-sketch/__next._full.txt +26 -26
  157. package/web/out/ui-sketch/__next._tree.txt +6 -7
  158. package/web/out/ui-sketch/__next.ui-sketch.__PAGE__.txt +13 -13
  159. package/web/out/ui-sketch/index.html +1 -1
  160. package/web/out/ui-sketch/index.txt +26 -26
  161. package/web/out/_next/static/chunks/130-7e9e715a084569bb.js +0 -1
  162. package/web/out/_next/static/chunks/166-96a8c6ae1e9aed59.js +0 -1
  163. package/web/out/_next/static/chunks/20-0801fc297cda2a7a.js +0 -1
  164. package/web/out/_next/static/chunks/678-32d3aa1859450d63.js +0 -1
  165. package/web/out/_next/static/chunks/app/_not-found/page-b92817fdc4609975.js +0 -1
  166. package/web/out/_next/static/chunks/app/composition/page-6c12ee8472715448.js +0 -1
  167. package/web/out/_next/static/chunks/app/layout-1dd9196cde94389c.js +0 -1
  168. package/web/out/_next/static/chunks/app/page-741ecaf9ee8c3c07.js +0 -1
  169. package/web/out/_next/static/chunks/app/spatial/page-5ba0940650df6c7f.js +0 -1
  170. package/web/out/_next/static/chunks/app/styles/page-1ccfc2c5fbc1e646.js +0 -1
  171. package/web/out/_next/static/chunks/app/ui-sketch/page-ef4f2e531583e684.js +0 -1
  172. package/web/out/_next/static/chunks/next/dist/client/components/builtin/global-error-33b4f58f02e82215.js +0 -1
  173. package/web/out/_next/static/chunks/webpack-d16ce1f994e98178.js +0 -1
  174. package/web/out/_next/static/css/06743b5635914999.css +0 -5
  175. package/web/out/_next/static/css/1f8501a43042a5a2.css +0 -1
  176. package/web/out/_next/static/css/39e8cace36461a15.css +0 -1
  177. package/web/out/_next/static/css/81ae71f1d3e9a866.css +0 -1
  178. package/web/out/_next/static/css/ce1b4bb3ad3c6073.css +0 -1
  179. package/web/out/_next/static/css/db96ae2e88545d96.css +0 -1
  180. /package/web/out/_next/static/{n4UcxqMmr_2CBmSxBp52z → MtSBeMOcAQHxKAV1fmedM}/_buildManifest.js +0 -0
  181. /package/web/out/_next/static/{n4UcxqMmr_2CBmSxBp52z → MtSBeMOcAQHxKAV1fmedM}/_ssgManifest.js +0 -0
package/README.en.md CHANGED
@@ -8,6 +8,33 @@
8
8
 
9
9
  Human2AI is a local creative workspace for people and AI agents. Edit compositions, UI sketches, and 3D spaces in a desktop browser. Agents use the CLI to connect to the same sessions, read versions, make changes, and export results.
10
10
 
11
+ ## Quick install
12
+
13
+ Requires Node.js 22+. Install Human2AI globally, then install its skill in each project where you want to use it.
14
+
15
+ ### Ask an agent to install it
16
+
17
+ Open Codex in the target project and copy this instruction to the agent:
18
+
19
+ ```text
20
+ Install Human2AI globally with npm install -g human2ai, then run human2ai integration install --agent codex --mode copy from the current project root to install the Human2AI skill in this project.
21
+ Read the installed .agents/skills/human2ai/SKILL.md, start the service, check the integration and service status, and verify that it works. Then tell me the browser URL and the command to start it next time.
22
+ If this project already has .human2ai/integration.json, check and reuse its runner and service configuration first, preserving any project changes to the skill.
23
+ ```
24
+
25
+ ### Install with the CLI
26
+
27
+ Run these commands in the target project root:
28
+
29
+ ```bash
30
+ npm install -g human2ai
31
+ human2ai integration install --agent codex --mode copy
32
+ human2ai integration doctor
33
+ human2ai web
34
+ ```
35
+
36
+ Keep the service terminal running and open <http://127.0.0.1:4179> in your browser. The skill is installed in `.agents/skills/human2ai/` within the current project. See [Installation and usage](#installation-and-usage) for details.
37
+
11
38
  ## Features
12
39
 
13
40
  ### Composition
@@ -44,45 +71,41 @@ Agents can also build and arrange models themselves and create complex poses for
44
71
 
45
72
  ## Installation and usage
46
73
 
47
- ### Ask an agent to install it
48
-
49
- Open Codex in the target project and give the agent this instruction:
50
-
51
- > Install human2ai in this project. Follow the npm package's README to set up the Human2AI skill, start the service, and verify that it works. Then tell me the browser URL.
74
+ ### Agent installation workflow
52
75
 
53
- Agents can read the public installation instructions with `npm view human2ai readme`, or read `node_modules/human2ai/README.en.md` after installation. The agent completes the following steps:
76
+ Agents can read the public installation instructions with `npm view human2ai readme`. After installation, they can also read `human2ai/README.md` under the directory returned by `npm root -g`. The agent completes the following steps:
54
77
 
55
- 1. Confirm the target project directory and the availability of Node.js 22+ and npm. Run `npm init -y` first if the project has no `package.json`.
56
- 2. Check for an existing `.human2ai/integration.json`. If present, use its recorded runner to check and retain the project's version and service URLs. For a new integration, follow the commands under “Install the npm package” and “Install the agent skill” below.
78
+ 1. Confirm the target project directory and the availability of Node.js 22+ and npm. The project does not need a `package.json`.
79
+ 2. Check for an existing `.human2ai/integration.json`. If present, use its recorded runner to check and retain the project's version and service URLs. For a new integration, install globally with `npm install -g human2ai`, then run the commands under “Install the agent skill” below from the target project root.
57
80
  3. Read the installed `.agents/skills/human2ai/SKILL.md`, then run `integration doctor` and `service status`. Let the CLI generate integration files, and preserve project changes if synchronization reports a conflict.
58
81
  4. If the service is not running, execute the configured `service.start` command in a persistent terminal, wait for the service to become available, and retry the checks. Follow any existing project startup convention. A first-time npm installation defaults to port `4179` and the `~/.human2ai/` data directory.
59
- 5. Confirm that both integration and service checks return `ready`, the browser URL is accessible, and `session list` can read sessions through the configured runner. Review the installation's security audit results and report any affected dependencies and their fix status.
82
+ 5. Confirm that both integration and service checks return `ready`, the browser URL is accessible, and `session list` can read sessions through the configured runner. If installation reports warnings or vulnerabilities, explain their impact and how they were handled.
60
83
  6. Report the installed version, project path, skill path, browser URL, and command to start the service next time. The user should not need to install the skill separately.
61
84
 
62
85
  The automatic integration command currently supports Codex. Users can also perform the same installation themselves with the commands below.
63
86
 
64
87
  ### Install with commands
65
88
 
66
- #### 1. Install the npm package
89
+ #### 1. Install the npm package globally
67
90
 
68
- Run this in the root of the project where you want to use Human2AI. In an empty directory without a `package.json`, run `npm init -y` first. Keep the configuration of an existing project.
91
+ Install once globally to use the `human2ai` command across projects. Consuming projects do not need a `package.json`.
69
92
 
70
93
  ```bash
71
- npm install --save-dev human2ai
94
+ npm install -g human2ai
72
95
  ```
73
96
 
74
- The package includes prebuilt Web pages, the CLI, database migrations, schemas, and the Human2AI skill. `npm install` places these files in `node_modules/human2ai/`. Complete the next step to make the skill available to your agent.
97
+ The package includes prebuilt Web pages, the CLI, database migrations, schemas, and the Human2AI skill. Use `npm root -g` to find the installation directory. Complete the next step to make the skill available to your agent in the current project.
75
98
 
76
99
  #### 2. Install the agent skill (Codex)
77
100
 
78
- Run these commands in the same project root. If the npm package is already installed, you can start here:
101
+ Run these commands in the root of the project where you want to use Human2AI. If the npm package is already installed globally, you can start here:
79
102
 
80
103
  ```bash
81
- npx --no-install human2ai integration install --agent codex --mode copy
82
- npx --no-install human2ai integration doctor
104
+ human2ai integration install --agent codex --mode copy
105
+ human2ai integration doctor
83
106
  ```
84
107
 
85
- The integration command copies the complete skill from the project's installed npm package and creates these files:
108
+ The integration command copies the complete skill from the globally installed npm package and creates these files in the current project:
86
109
 
87
110
  | Path | Purpose |
88
111
  | --- | --- |
@@ -98,7 +121,7 @@ Open Codex in the consuming project and find Human2AI in the skill picker. In th
98
121
  #### 3. Start and verify
99
122
 
100
123
  ```bash
101
- npx --no-install human2ai web
124
+ human2ai web
102
125
  ```
103
126
 
104
127
  This command starts one service that provides both Web pages and the backend API at <http://127.0.0.1:4179>. Other consuming projects using the default configuration connect to this same service. Repeated startup commands reuse a compatible running service.
@@ -106,15 +129,15 @@ This command starts one service that provides both Web pages and the backend API
106
129
  Keep the service terminal running and open the URL in your browser. In another terminal, run these commands from the same consuming project:
107
130
 
108
131
  ```bash
109
- npx --no-install human2ai service status
110
- npx --no-install human2ai session list
132
+ human2ai service status
133
+ human2ai session list
111
134
  ```
112
135
 
113
136
  Basic installation verification is complete when the service check returns `status: "ready"` and the session list can be read. An empty list is normal for a new data directory. Agents invoke the CLI through the runner in `.human2ai/integration.json`.
114
137
 
115
138
  ### Installation notes and upgrade checks
116
139
 
117
- If npm warns that the install script for `better-sqlite3` has not been recorded in `allowScripts`, inspect the scripts first. After reviewing this database dependency's native build script, record your approval:
140
+ For an existing project-local installation, if npm warns that the install script for `better-sqlite3` has not been recorded in `allowScripts`, inspect the scripts first. After reviewing this database dependency's native build script, record your approval:
118
141
 
119
142
  ```bash
120
143
  npm install-scripts ls
@@ -128,8 +151,8 @@ If an existing integration reports `update-available` after an upgrade, synchron
128
151
  ### Connect to and use sessions
129
152
 
130
153
  ```bash
131
- npx --no-install human2ai session connect --session <session-id>
132
- npx --no-install human2ai session open --session <session-id>
154
+ human2ai session connect --session <session-id>
155
+ human2ai session open --session <session-id>
133
156
  ```
134
157
 
135
158
  `session connect` returns the browser URL, the latest Capture version, and the commands supported by the current session. `capture get` reads a specific version, `capture save` saves a new version, and `capture undo` appends a restored version. Project IDs and session IDs organize work from different projects within the same local service.
@@ -194,12 +217,12 @@ Run Storybook with `npm run storybook`; its default URL is <http://localhost:600
194
217
 
195
218
  ## Upgrade an installed package
196
219
 
197
- Run these commands in the consuming project:
220
+ Update the global package, then synchronize the skill from the root of each integrated project:
198
221
 
199
222
  ```bash
200
- npm install --save-dev human2ai@latest
201
- npx --no-install human2ai integration sync --check
202
- npx --no-install human2ai integration sync
223
+ npm install -g human2ai@latest
224
+ human2ai integration sync --check
225
+ human2ai integration sync
203
226
  ```
204
227
 
205
228
  Stop the service and back up its data directory before upgrading. Run `human2ai web` again after the upgrade. Database migrations run at startup. If you roll back the software, restore a data backup compatible with that version.
@@ -223,7 +246,7 @@ mkdir -p .human2ai-data/packages
223
246
  npm pack --pack-destination .human2ai-data/packages
224
247
  ```
225
248
 
226
- In that separate project, run `npm install --save-dev /absolute/path/to/human2ai-0.1.4.tgz`, then follow the integration and startup steps above. Package checks verify required files and licenses and reject internal documentation, databases, and user-generated files.
249
+ Run `npm install -g /absolute/path/to/human2ai-0.1.6.tgz`, then follow the integration and startup steps above in a separate project. Package checks verify required files and licenses and reject internal documentation, databases, and user-generated files.
227
250
 
228
251
  ## License
229
252
 
package/README.md CHANGED
@@ -8,6 +8,33 @@
8
8
 
9
9
  Human2AI 是供人和 AI Agent 协作的本地创作工作区:用户在桌面浏览器中编辑构图、UI 草图和 3D 空间,Agent 通过 CLI 连接同一会话、读取版本、修改和导出结果。
10
10
 
11
+ ## 快速安装
12
+
13
+ 需要 Node.js 22+。将 Human2AI 安装到全局,再将专用 Skill 安装到需要使用它的项目中。
14
+
15
+ ### 交给 Agent 安装
16
+
17
+ 在目标项目中打开 Codex,复制下面的指令交给 Agent:
18
+
19
+ ```text
20
+ 请通过 npm install -g human2ai 将 Human2AI 安装到全局,再在当前项目根目录执行 human2ai integration install --agent codex --mode copy,将 Human2AI 专用 Skill 安装到当前项目。
21
+ 阅读安装后的 .agents/skills/human2ai/SKILL.md,启动服务,检查接入和服务状态并验证可用,最后告诉我访问地址和下次启动命令。
22
+ 如果当前项目已有 .human2ai/integration.json,请先检查并沿用其中的 runner 和服务配置,保留项目内已有的 Skill 修改。
23
+ ```
24
+
25
+ ### 自己用 CLI 安装
26
+
27
+ 在目标项目根目录执行:
28
+
29
+ ```bash
30
+ npm install -g human2ai
31
+ human2ai integration install --agent codex --mode copy
32
+ human2ai integration doctor
33
+ human2ai web
34
+ ```
35
+
36
+ 保持服务终端运行,在浏览器打开 <http://127.0.0.1:4179>。Skill 安装到当前项目的 `.agents/skills/human2ai/`;详细步骤见[安装与使用](#安装与使用)。
37
+
11
38
  ## 功能预览
12
39
 
13
40
  ### 构图
@@ -44,45 +71,41 @@ Agent 也可以自主建模、摆放物体和调整复杂动作,将持械、
44
71
 
45
72
  ## 安装与使用
46
73
 
47
- ### 交给 Agent 安装
48
-
49
- 在目标项目中打开 Codex,把下面这句话交给 Agent:
50
-
51
- > 帮我在当前项目安装 human2ai,按 npm 包的 README 完成 Human2AI 专用 Skill 接入、启动服务并验证可用,最后告诉我访问地址。
74
+ ### Agent 安装流程
52
75
 
53
- Agent 可以用 `npm view human2ai readme` 读取公开安装说明,安装后也可以读取 `node_modules/human2ai/README.md`。完整流程由 Agent 执行:
76
+ Agent 可以用 `npm view human2ai readme` 读取公开安装说明,安装后也可以在 `npm root -g` 返回的目录中读取 `human2ai/README.md`。完整流程由 Agent 执行:
54
77
 
55
- 1. 确认目标项目目录、Node.js 22+ 和 npm 可用;项目没有 `package.json` 时先执行 `npm init -y`。
56
- 2. 检查已有 `.human2ai/integration.json`。已有接入时,按记录的 runner 检查并沿用项目的版本和服务地址;首次接入时执行下方“安装 npm 包”和“安装 Agent Skill”中的命令。
78
+ 1. 确认目标项目目录、Node.js 22+ 和 npm 可用;项目无需创建 `package.json`。
79
+ 2. 检查已有 `.human2ai/integration.json`。已有接入时,按记录的 runner 检查并沿用项目的版本和服务地址;首次接入时,执行 `npm install -g human2ai` 全局安装,再在目标项目根目录执行下方“安装 Agent Skill”中的命令。
57
80
  3. 阅读安装后的 `.agents/skills/human2ai/SKILL.md`,运行 `integration doctor` 和 `service status`。接入文件由 CLI 生成;出现同步冲突时保留项目内已有修改。
58
81
  4. 服务未运行时,在持久终端执行配置中的 `service.start`,等待服务就绪后重试。项目已有明确启动约定时沿用该约定;首次 npm 安装默认使用 `4179` 和 `~/.human2ai/` 数据目录。
59
- 5. 确认接入检查与服务检查均返回 `ready`,浏览器地址可访问,按 runner 执行 `session list` 可以读取会话;同时查看安装的安全审计结果,遇到漏洞时报告受影响依赖与修复情况。
82
+ 5. 确认接入检查与服务检查均返回 `ready`,浏览器地址可访问,按 runner 执行 `session list` 可以读取会话;安装过程若报告警告或漏洞,说明其影响与处理结果。
60
83
  6. 向用户报告安装版本、项目路径、Skill 路径、浏览器地址和下次启动命令。用户无需再手动补装 Skill。
61
84
 
62
85
  当前自动接入命令支持 Codex。用户也可以自行执行下面的相同安装流程。
63
86
 
64
87
  ### 自己按命令安装
65
88
 
66
- #### 1. 安装 npm 包
89
+ #### 1. 全局安装 npm 包
67
90
 
68
- 在需要接入 Human2AI 的消费项目根目录执行。空白目录尚无 `package.json` 时,先运行 `npm init -y`;已有项目保留原配置。
91
+ 全局安装一次,即可在不同项目中使用 `human2ai` 命令;消费项目无需创建 `package.json`。
69
92
 
70
93
  ```bash
71
- npm install --save-dev human2ai
94
+ npm install -g human2ai
72
95
  ```
73
96
 
74
- 安装包包含预构建的 Web 页面、CLI、数据库迁移、Schema 和 Human2AI 专用 Skill。`npm install` 将这些文件安装到 `node_modules/human2ai/`;要让 Agent 发现并使用 Skill,还需要执行下一步接入命令。
97
+ 安装包包含预构建的 Web 页面、CLI、数据库迁移、Schema 和 Human2AI 专用 Skill,安装位置可通过 `npm root -g` 查看。要让 Agent 在当前项目中发现并使用 Skill,还需要执行下一步接入命令。
75
98
 
76
99
  #### 2. 安装 Agent Skill(Codex)
77
100
 
78
- 在同一个消费项目根目录执行;已经安装 npm 包的项目可以直接从这里开始:
101
+ 在需要接入 Human2AI 的消费项目根目录执行;已经全局安装 npm 包时可以直接从这里开始:
79
102
 
80
103
  ```bash
81
- npx --no-install human2ai integration install --agent codex --mode copy
82
- npx --no-install human2ai integration doctor
104
+ human2ai integration install --agent codex --mode copy
105
+ human2ai integration doctor
83
106
  ```
84
107
 
85
- 接入命令从当前项目安装的 npm 包复制完整 Skill,并生成以下文件:
108
+ 接入命令从全局安装的 npm 包复制完整 Skill,在当前项目中生成以下文件:
86
109
 
87
110
  | 路径 | 用途 |
88
111
  | --- | --- |
@@ -98,7 +121,7 @@ npx --no-install human2ai integration doctor
98
121
  #### 3. 启动与验证
99
122
 
100
123
  ```bash
101
- npx --no-install human2ai web
124
+ human2ai web
102
125
  ```
103
126
 
104
127
  这个命令启动一个同时提供 Web 页面和后端 API 的服务,两者共用 <http://127.0.0.1:4179>。其他消费项目使用默认配置时也连接这一个服务;重复启动会复用已运行的兼容服务。
@@ -106,15 +129,15 @@ npx --no-install human2ai web
106
129
  保持服务终端运行,在浏览器打开上述地址。另开终端,在同一个消费项目中执行:
107
130
 
108
131
  ```bash
109
- npx --no-install human2ai service status
110
- npx --no-install human2ai session list
132
+ human2ai service status
133
+ human2ai session list
111
134
  ```
112
135
 
113
136
  服务检查返回 `status: "ready"`,且会话列表可以读取,即完成基本安装验证;新数据目录返回空列表也是正常结果。Agent 按 `.human2ai/integration.json` 中的 runner 调用 CLI。
114
137
 
115
138
  ### 安装提示与升级检查
116
139
 
117
- 如果 npm 提示 `better-sqlite3` 的安装脚本尚未记录到 `allowScripts`,可先查看脚本列表;审核该数据库依赖的原生构建脚本后,记录授权:
140
+ 对于已有的项目内安装,如果 npm 提示 `better-sqlite3` 的安装脚本尚未记录到 `allowScripts`,可先查看脚本列表;审核该数据库依赖的原生构建脚本后,记录授权:
118
141
 
119
142
  ```bash
120
143
  npm install-scripts ls
@@ -128,8 +151,8 @@ npm install-scripts approve better-sqlite3
128
151
  ### 连接与使用会话
129
152
 
130
153
  ```bash
131
- npx --no-install human2ai session connect --session <session-id>
132
- npx --no-install human2ai session open --session <session-id>
154
+ human2ai session connect --session <session-id>
155
+ human2ai session open --session <session-id>
133
156
  ```
134
157
 
135
158
  `session connect` 返回浏览器地址、最新 Capture 版本和当前会话支持的命令。`capture get` 读取指定版本,`capture save` 保存新版本,`capture undo` 追加恢复版本。不同项目通过项目 ID 和会话 ID 组织在同一本地服务中。
@@ -202,12 +225,12 @@ Storybook 使用 `npm run storybook`,默认地址为 <http://localhost:6006>
202
225
 
203
226
  ## 升级安装版
204
227
 
205
- 在消费项目执行:
228
+ 更新全局安装包,再在每个已接入的消费项目根目录同步 Skill:
206
229
 
207
230
  ```bash
208
- npm install --save-dev human2ai@latest
209
- npx --no-install human2ai integration sync --check
210
- npx --no-install human2ai integration sync
231
+ npm install -g human2ai@latest
232
+ human2ai integration sync --check
233
+ human2ai integration sync
211
234
  ```
212
235
 
213
236
  升级前停止服务并备份数据目录,升级后重新运行 `human2ai web`。数据库迁移在启动时执行;软件版本回退时应使用对应版本的数据备份。
@@ -231,7 +254,7 @@ mkdir -p .human2ai-data/packages
231
254
  npm pack --pack-destination .human2ai-data/packages
232
255
  ```
233
256
 
234
- 在独立项目中执行 `npm install --save-dev /absolute/path/to/human2ai-0.1.4.tgz`,再按安装步骤接入并启动。安装包检查会验证必需文件和许可证,并拒绝内部文档、数据库及用户产物。
257
+ 执行 `npm install -g /absolute/path/to/human2ai-0.1.6.tgz`,再在独立项目中按安装步骤接入并启动。安装包检查会验证必需文件和许可证,并拒绝内部文档、数据库及用户产物。
235
258
 
236
259
  ## 许可证
237
260
 
package/dist/cli/main.js CHANGED
@@ -6,6 +6,7 @@ import path from "node:path";
6
6
  import process from "node:process";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import sharp from "sharp";
9
+ import { compositionSvgForRaster } from "../domain/composition/raster.js";
9
10
  import { CliIntegrationError, executeIntegrationCommand, integrationStartDirectory, integrationUsage, readIntegrationManifestSync, } from "./integration.js";
10
11
  import { isDevelopmentSource, resolveRuntimeDefaults } from "../runtime-defaults.js";
11
12
  import { RefinementConstraintError, applyRefinementPlan, inspectComposition, refinementMethods, refinementPlanSchema, renderCompositionReferenceSvg, renderCompositionSvg, validateDraft, } from "../domain/composition/index.js";
@@ -793,17 +794,26 @@ function parseStyleProcessing(input) {
793
794
  }
794
795
  return value;
795
796
  }
797
+ async function writeCompositionPreview(previewPath, svg) {
798
+ if (path.extname(previewPath).toLowerCase() === ".png") {
799
+ await sharp(Buffer.from(await compositionSvgForRaster(svg))).png().toFile(previewPath);
800
+ return { previewSvg: null, previewPng: previewPath };
801
+ }
802
+ await writeFile(previewPath, svg, "utf8");
803
+ return { previewSvg: previewPath };
804
+ }
796
805
  async function inspectLocalDraft(options) {
797
806
  assertOnlyOptions(options, ["draft", "preview"], "inspect with --draft");
798
807
  const draftPath = path.resolve(requireOption(options, "draft"));
799
808
  const draft = validateDraft(await readJson(draftPath));
800
809
  const previewPath = options.preview ? path.resolve(options.preview) : null;
801
810
  assertArtifactTargets([{ label: "preview", filename: previewPath }], [{ label: "draft", filename: draftPath }]);
802
- if (previewPath)
803
- await writeFile(previewPath, renderCompositionSvg(draft), "utf8");
811
+ const artifacts = previewPath
812
+ ? await writeCompositionPreview(previewPath, renderCompositionSvg(draft))
813
+ : { previewSvg: null };
804
814
  return {
805
815
  ...inspectComposition(draft),
806
- artifacts: { previewSvg: previewPath },
816
+ artifacts,
807
817
  };
808
818
  }
809
819
  async function sessionImageSources(draft, sessionId, dependencies) {
@@ -852,9 +862,9 @@ async function inspectSessionDraft(options, dependencies) {
852
862
  const revision = requireInteger(options, "revision", 1);
853
863
  const version = parseDraftVersion(await requestService(dependencies, `${compositionDraftsPath(sessionId)}/${revision}`));
854
864
  const previewPath = options.preview ? path.resolve(options.preview) : null;
855
- if (previewPath) {
856
- await writeFile(previewPath, renderCompositionSvg(version.draft, await sessionImageSources(version.draft, sessionId, dependencies)), "utf8");
857
- }
865
+ const artifacts = previewPath
866
+ ? await writeCompositionPreview(previewPath, renderCompositionSvg(version.draft, await sessionImageSources(version.draft, sessionId, dependencies)))
867
+ : { previewSvg: null };
858
868
  return {
859
869
  ...inspectComposition(version.draft),
860
870
  source: {
@@ -863,7 +873,7 @@ async function inspectSessionDraft(options, dependencies) {
863
873
  draftVersionId: version.id,
864
874
  draftRevision: version.revision,
865
875
  },
866
- artifacts: { previewSvg: previewPath },
876
+ artifacts,
867
877
  };
868
878
  }
869
879
  async function applyLocalRefinement(options) {
@@ -882,18 +892,18 @@ async function applyLocalRefinement(options) {
882
892
  const draft = validateDraft(await readJson(draftPath));
883
893
  const plan = await readJson(planPath);
884
894
  const result = applyRefinementPlan(draft, plan);
895
+ const preview = previewPath
896
+ ? await writeCompositionPreview(previewPath, renderCompositionSvg(result.refinedDraft))
897
+ : { previewSvg: null };
885
898
  const payload = {
886
899
  ...result,
887
900
  artifacts: {
888
901
  result: outputPath,
889
- previewSvg: previewPath,
902
+ ...preview,
890
903
  },
891
904
  };
892
905
  if (outputPath)
893
906
  await writeJson(outputPath, payload);
894
- if (previewPath) {
895
- await writeFile(previewPath, renderCompositionSvg(result.refinedDraft), "utf8");
896
- }
897
907
  return payload;
898
908
  }
899
909
  async function applySessionRefinement(options, dependencies) {
@@ -923,18 +933,18 @@ async function writeSessionRefinementArtifacts(run, options, dependencies) {
923
933
  { label: "output", filename: outputPath },
924
934
  { label: "preview", filename: previewPath },
925
935
  ], []);
936
+ const preview = previewPath
937
+ ? await writeCompositionPreview(previewPath, renderCompositionSvg(run.result.refinedDraft, await sessionImageSources(run.result.refinedDraft, run.sessionId, dependencies)))
938
+ : { previewSvg: null };
926
939
  const payload = {
927
940
  ...run,
928
941
  artifacts: {
929
942
  result: outputPath,
930
- previewSvg: previewPath,
943
+ ...preview,
931
944
  },
932
945
  };
933
946
  if (outputPath)
934
947
  await writeJson(outputPath, payload);
935
- if (previewPath) {
936
- await writeFile(previewPath, renderCompositionSvg(run.result.refinedDraft, await sessionImageSources(run.result.refinedDraft, run.sessionId, dependencies)), "utf8");
937
- }
938
948
  return payload;
939
949
  }
940
950
  async function writeSessionReference(options, dependencies) {
@@ -944,10 +954,12 @@ async function writeSessionReference(options, dependencies) {
944
954
  const outputPath = path.resolve(requireOption(options, "output"));
945
955
  const run = parseRefinementRun(await requestService(dependencies, `${compositionRefinementsPath(sessionId)}/${encodeURIComponent(runId)}`));
946
956
  const draft = run.result.refinedDraft;
947
- await sharp(Buffer.from(renderCompositionReferenceSvg(draft, await sessionImageSources(draft, sessionId, dependencies)))).png().toFile(outputPath);
957
+ const svg = renderCompositionReferenceSvg(draft, await sessionImageSources(draft, sessionId, dependencies));
958
+ await sharp(Buffer.from(await compositionSvgForRaster(svg))).png().toFile(outputPath);
948
959
  return {
949
960
  version: 1,
950
961
  kind: "composition-reference",
962
+ previewMode: draft.previewMode ?? "precise",
951
963
  sessionId: run.sessionId,
952
964
  refinementRunId: run.id,
953
965
  sourceDraftRevision: run.sourceDraftRevision,
@@ -1327,12 +1339,12 @@ function usage() {
1327
1339
  " human2ai composition methods",
1328
1340
  " human2ai composition save --session <id> --draft <draft.json> --expected-revision <n>",
1329
1341
  " human2ai composition drafts --session <id>",
1330
- " human2ai composition inspect --draft <draft.json> [--preview <preview.svg>]",
1331
- " human2ai composition inspect --session <id> --revision <n> [--preview <preview.svg>]",
1332
- " human2ai composition apply --draft <draft.json> --plan <plan.json> [--output <result.json>] [--preview <preview.svg>]",
1333
- " human2ai composition apply --session <id> --revision <n> --plan <plan.json> [--output <run.json>] [--preview <preview.svg>]",
1342
+ " human2ai composition inspect --draft <draft.json> [--preview <preview.png|preview.svg>]",
1343
+ " human2ai composition inspect --session <id> --revision <n> [--preview <preview.png|preview.svg>]",
1344
+ " human2ai composition apply --draft <draft.json> --plan <plan.json> [--output <result.json>] [--preview <preview.png|preview.svg>]",
1345
+ " human2ai composition apply --session <id> --revision <n> --plan <plan.json> [--output <run.json>] [--preview <preview.png|preview.svg>]",
1334
1346
  " human2ai composition refinements --session <id>",
1335
- " human2ai composition refinement --session <id> --run <id> [--output <run.json>] [--preview <preview.svg>]",
1347
+ " human2ai composition refinement --session <id> --run <id> [--output <run.json>] [--preview <preview.png|preview.svg>]",
1336
1348
  " human2ai composition reference --session <id> --run <id> --output <reference.png>",
1337
1349
  ].join("\n");
1338
1350
  }