ai4ai 0.0.0-stage → 0.0.3

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 (302) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -2
  3. package/README.zh-CN.md +48 -0
  4. package/claude-plugin/.claude-plugin/plugin.json +5 -0
  5. package/claude-plugin/dist/adapters/claude/adapter.d.ts +21 -0
  6. package/claude-plugin/dist/adapters/claude/adapter.js +111 -0
  7. package/claude-plugin/dist/adapters/claude/journal.d.ts +51 -0
  8. package/claude-plugin/dist/adapters/claude/journal.js +81 -0
  9. package/claude-plugin/dist/adapters/claude/plugin.d.ts +3 -0
  10. package/claude-plugin/dist/adapters/claude/plugin.js +347 -0
  11. package/claude-plugin/dist/adapters/claude/status.d.ts +29 -0
  12. package/claude-plugin/dist/adapters/claude/status.js +99 -0
  13. package/claude-plugin/dist/adapters/claude/worker.d.ts +1 -0
  14. package/claude-plugin/dist/adapters/claude/worker.js +204 -0
  15. package/claude-plugin/dist/adapters/codex/adapter.d.ts +54 -0
  16. package/claude-plugin/dist/adapters/codex/adapter.js +583 -0
  17. package/claude-plugin/dist/adapters/codex/app-server.d.ts +34 -0
  18. package/claude-plugin/dist/adapters/codex/app-server.js +105 -0
  19. package/claude-plugin/dist/adapters/codex/control.d.ts +44 -0
  20. package/claude-plugin/dist/adapters/codex/control.js +263 -0
  21. package/claude-plugin/dist/adapters/codex/runner.d.ts +2 -0
  22. package/claude-plugin/dist/adapters/codex/runner.js +295 -0
  23. package/claude-plugin/dist/adapters/codex/tui-daemon-watch.d.ts +2 -0
  24. package/claude-plugin/dist/adapters/codex/tui-daemon-watch.js +106 -0
  25. package/claude-plugin/dist/adapters/codex/tui-restart-watch.d.ts +2 -0
  26. package/claude-plugin/dist/adapters/codex/tui-restart-watch.js +330 -0
  27. package/claude-plugin/dist/adapters/declarations.d.ts +36 -0
  28. package/claude-plugin/dist/adapters/declarations.js +49 -0
  29. package/claude-plugin/dist/adapters/dsh/adapter.d.ts +15 -0
  30. package/claude-plugin/dist/adapters/dsh/adapter.js +114 -0
  31. package/claude-plugin/dist/adapters/dsh/plugin.d.ts +112 -0
  32. package/claude-plugin/dist/adapters/dsh/plugin.js +276 -0
  33. package/claude-plugin/dist/adapters/dsh/status.d.ts +36 -0
  34. package/claude-plugin/dist/adapters/dsh/status.js +102 -0
  35. package/claude-plugin/dist/adapters/executors.d.ts +69 -0
  36. package/claude-plugin/dist/adapters/executors.js +184 -0
  37. package/claude-plugin/dist/adapters/external.d.ts +61 -0
  38. package/claude-plugin/dist/adapters/external.js +209 -0
  39. package/claude-plugin/dist/adapters/opencode/adapter.d.ts +14 -0
  40. package/claude-plugin/dist/adapters/opencode/adapter.js +184 -0
  41. package/claude-plugin/dist/adapters/opencode/journal.d.ts +36 -0
  42. package/claude-plugin/dist/adapters/opencode/journal.js +105 -0
  43. package/claude-plugin/dist/adapters/opencode/plugin.d.ts +9 -0
  44. package/claude-plugin/dist/adapters/opencode/plugin.js +293 -0
  45. package/claude-plugin/dist/adapters/supervisor.d.ts +2 -0
  46. package/claude-plugin/dist/adapters/supervisor.js +165 -0
  47. package/claude-plugin/dist/adapters/types.d.ts +54 -0
  48. package/claude-plugin/dist/adapters/types.js +1 -0
  49. package/claude-plugin/dist/cli.d.ts +2 -0
  50. package/claude-plugin/dist/cli.js +254 -0
  51. package/claude-plugin/dist/contract/field-state.d.ts +13 -0
  52. package/claude-plugin/dist/contract/field-state.js +43 -0
  53. package/claude-plugin/dist/contract/index.d.ts +7 -0
  54. package/claude-plugin/dist/contract/index.js +6 -0
  55. package/claude-plugin/dist/contract/schema.d.ts +2157 -0
  56. package/claude-plugin/dist/contract/schema.js +278 -0
  57. package/claude-plugin/dist/contract/states.d.ts +78 -0
  58. package/claude-plugin/dist/contract/states.js +83 -0
  59. package/claude-plugin/dist/contract/tool.d.ts +30 -0
  60. package/claude-plugin/dist/contract/tool.js +52 -0
  61. package/claude-plugin/dist/contract/types.d.ts +198 -0
  62. package/claude-plugin/dist/contract/types.js +1 -0
  63. package/claude-plugin/dist/contract/validate.d.ts +13 -0
  64. package/claude-plugin/dist/contract/validate.js +467 -0
  65. package/claude-plugin/dist/contract/version.d.ts +3 -0
  66. package/claude-plugin/dist/contract/version.js +6 -0
  67. package/claude-plugin/dist/core/config-probe.d.ts +101 -0
  68. package/claude-plugin/dist/core/config-probe.js +565 -0
  69. package/claude-plugin/dist/core/fingerprint.d.ts +8 -0
  70. package/claude-plugin/dist/core/fingerprint.js +34 -0
  71. package/claude-plugin/dist/core/index.d.ts +7 -0
  72. package/claude-plugin/dist/core/index.js +5 -0
  73. package/claude-plugin/dist/core/journal.d.ts +12 -0
  74. package/claude-plugin/dist/core/journal.js +19 -0
  75. package/claude-plugin/dist/core/ladder.d.ts +28 -0
  76. package/claude-plugin/dist/core/ladder.js +28 -0
  77. package/claude-plugin/dist/core/operations.d.ts +30 -0
  78. package/claude-plugin/dist/core/operations.js +222 -0
  79. package/claude-plugin/dist/core/policy.d.ts +19 -0
  80. package/claude-plugin/dist/core/policy.js +30 -0
  81. package/claude-plugin/dist/core/session-probe.d.ts +75 -0
  82. package/claude-plugin/dist/core/session-probe.js +469 -0
  83. package/claude-plugin/dist/core/store.d.ts +71 -0
  84. package/claude-plugin/dist/core/store.js +196 -0
  85. package/claude-plugin/dist/index.d.ts +2 -0
  86. package/claude-plugin/dist/index.js +2 -0
  87. package/claude-plugin/dist/install/binding.d.ts +33 -0
  88. package/claude-plugin/dist/install/binding.js +75 -0
  89. package/claude-plugin/dist/install/discovery.d.ts +3 -0
  90. package/claude-plugin/dist/install/discovery.js +48 -0
  91. package/claude-plugin/dist/install/dsh-installer.d.ts +73 -0
  92. package/claude-plugin/dist/install/dsh-installer.js +497 -0
  93. package/claude-plugin/dist/install/dsh-worker.d.ts +1 -0
  94. package/claude-plugin/dist/install/dsh-worker.js +108 -0
  95. package/claude-plugin/dist/install/manager.d.ts +56 -0
  96. package/claude-plugin/dist/install/manager.js +417 -0
  97. package/claude-plugin/dist/install/scope.d.ts +25 -0
  98. package/claude-plugin/dist/install/scope.js +257 -0
  99. package/claude-plugin/dist/tmux/backend.d.ts +55 -0
  100. package/claude-plugin/dist/tmux/backend.js +161 -0
  101. package/claude-plugin/hooks/hooks.json +1 -0
  102. package/claude-plugin/package.json +3 -0
  103. package/claude-plugin/request-schema.json +140 -0
  104. package/cordis.patch.yml +4 -0
  105. package/dist/adapters/claude/adapter.d.ts +21 -0
  106. package/dist/adapters/claude/adapter.js +111 -0
  107. package/dist/adapters/claude/journal.d.ts +51 -0
  108. package/dist/adapters/claude/journal.js +81 -0
  109. package/dist/adapters/claude/plugin.d.ts +3 -0
  110. package/dist/adapters/claude/plugin.js +347 -0
  111. package/dist/adapters/claude/status.d.ts +29 -0
  112. package/dist/adapters/claude/status.js +99 -0
  113. package/dist/adapters/claude/worker.d.ts +1 -0
  114. package/dist/adapters/claude/worker.js +204 -0
  115. package/dist/adapters/codex/adapter.d.ts +54 -0
  116. package/dist/adapters/codex/adapter.js +583 -0
  117. package/dist/adapters/codex/app-server.d.ts +34 -0
  118. package/dist/adapters/codex/app-server.js +105 -0
  119. package/dist/adapters/codex/control.d.ts +44 -0
  120. package/dist/adapters/codex/control.js +263 -0
  121. package/dist/adapters/codex/runner.d.ts +2 -0
  122. package/dist/adapters/codex/runner.js +295 -0
  123. package/dist/adapters/codex/tui-daemon-watch.d.ts +2 -0
  124. package/dist/adapters/codex/tui-daemon-watch.js +106 -0
  125. package/dist/adapters/codex/tui-restart-watch.d.ts +2 -0
  126. package/dist/adapters/codex/tui-restart-watch.js +330 -0
  127. package/dist/adapters/declarations.d.ts +36 -0
  128. package/dist/adapters/declarations.js +49 -0
  129. package/dist/adapters/dsh/adapter.d.ts +15 -0
  130. package/dist/adapters/dsh/adapter.js +114 -0
  131. package/dist/adapters/dsh/plugin.d.ts +112 -0
  132. package/dist/adapters/dsh/plugin.js +276 -0
  133. package/dist/adapters/dsh/status.d.ts +36 -0
  134. package/dist/adapters/dsh/status.js +102 -0
  135. package/dist/adapters/executors.d.ts +69 -0
  136. package/dist/adapters/executors.js +184 -0
  137. package/dist/adapters/external.d.ts +61 -0
  138. package/dist/adapters/external.js +209 -0
  139. package/dist/adapters/opencode/adapter.d.ts +14 -0
  140. package/dist/adapters/opencode/adapter.js +184 -0
  141. package/dist/adapters/opencode/journal.d.ts +36 -0
  142. package/dist/adapters/opencode/journal.js +105 -0
  143. package/dist/adapters/opencode/plugin.d.ts +9 -0
  144. package/dist/adapters/opencode/plugin.js +293 -0
  145. package/dist/adapters/supervisor.d.ts +2 -0
  146. package/dist/adapters/supervisor.js +165 -0
  147. package/dist/adapters/types.d.ts +54 -0
  148. package/dist/adapters/types.js +1 -0
  149. package/dist/cli.d.ts +2 -0
  150. package/dist/cli.js +254 -0
  151. package/dist/contract/field-state.d.ts +13 -0
  152. package/dist/contract/field-state.js +43 -0
  153. package/dist/contract/index.d.ts +7 -0
  154. package/dist/contract/index.js +6 -0
  155. package/dist/contract/schema.d.ts +2157 -0
  156. package/dist/contract/schema.js +278 -0
  157. package/dist/contract/states.d.ts +78 -0
  158. package/dist/contract/states.js +83 -0
  159. package/dist/contract/tool.d.ts +30 -0
  160. package/dist/contract/tool.js +52 -0
  161. package/dist/contract/types.d.ts +198 -0
  162. package/dist/contract/types.js +1 -0
  163. package/dist/contract/validate.d.ts +13 -0
  164. package/dist/contract/validate.js +467 -0
  165. package/dist/contract/version.d.ts +3 -0
  166. package/dist/contract/version.js +6 -0
  167. package/dist/core/config-probe.d.ts +101 -0
  168. package/dist/core/config-probe.js +565 -0
  169. package/dist/core/fingerprint.d.ts +8 -0
  170. package/dist/core/fingerprint.js +34 -0
  171. package/dist/core/index.d.ts +7 -0
  172. package/dist/core/index.js +5 -0
  173. package/dist/core/journal.d.ts +12 -0
  174. package/dist/core/journal.js +19 -0
  175. package/dist/core/ladder.d.ts +28 -0
  176. package/dist/core/ladder.js +28 -0
  177. package/dist/core/operations.d.ts +30 -0
  178. package/dist/core/operations.js +222 -0
  179. package/dist/core/policy.d.ts +19 -0
  180. package/dist/core/policy.js +30 -0
  181. package/dist/core/session-probe.d.ts +75 -0
  182. package/dist/core/session-probe.js +469 -0
  183. package/dist/core/store.d.ts +71 -0
  184. package/dist/core/store.js +196 -0
  185. package/dist/index.d.ts +2 -0
  186. package/dist/index.js +2 -0
  187. package/dist/install/binding.d.ts +33 -0
  188. package/dist/install/binding.js +75 -0
  189. package/dist/install/discovery.d.ts +3 -0
  190. package/dist/install/discovery.js +48 -0
  191. package/dist/install/dsh-installer.d.ts +73 -0
  192. package/dist/install/dsh-installer.js +497 -0
  193. package/dist/install/dsh-worker.d.ts +1 -0
  194. package/dist/install/dsh-worker.js +108 -0
  195. package/dist/install/manager.d.ts +56 -0
  196. package/dist/install/manager.js +417 -0
  197. package/dist/install/scope.d.ts +25 -0
  198. package/dist/install/scope.js +257 -0
  199. package/dist/tmux/backend.d.ts +55 -0
  200. package/dist/tmux/backend.js +161 -0
  201. package/docs/banner.svg +12 -0
  202. package/docs/banner.zh-CN.svg +12 -0
  203. package/docs/contract.md +1786 -0
  204. package/opencode-plugin/dist/adapters/claude/adapter.d.ts +21 -0
  205. package/opencode-plugin/dist/adapters/claude/adapter.js +111 -0
  206. package/opencode-plugin/dist/adapters/claude/journal.d.ts +51 -0
  207. package/opencode-plugin/dist/adapters/claude/journal.js +81 -0
  208. package/opencode-plugin/dist/adapters/claude/plugin.d.ts +3 -0
  209. package/opencode-plugin/dist/adapters/claude/plugin.js +347 -0
  210. package/opencode-plugin/dist/adapters/claude/status.d.ts +29 -0
  211. package/opencode-plugin/dist/adapters/claude/status.js +99 -0
  212. package/opencode-plugin/dist/adapters/claude/worker.d.ts +1 -0
  213. package/opencode-plugin/dist/adapters/claude/worker.js +204 -0
  214. package/opencode-plugin/dist/adapters/codex/adapter.d.ts +54 -0
  215. package/opencode-plugin/dist/adapters/codex/adapter.js +583 -0
  216. package/opencode-plugin/dist/adapters/codex/app-server.d.ts +34 -0
  217. package/opencode-plugin/dist/adapters/codex/app-server.js +105 -0
  218. package/opencode-plugin/dist/adapters/codex/control.d.ts +44 -0
  219. package/opencode-plugin/dist/adapters/codex/control.js +263 -0
  220. package/opencode-plugin/dist/adapters/codex/runner.d.ts +2 -0
  221. package/opencode-plugin/dist/adapters/codex/runner.js +295 -0
  222. package/opencode-plugin/dist/adapters/codex/tui-daemon-watch.d.ts +2 -0
  223. package/opencode-plugin/dist/adapters/codex/tui-daemon-watch.js +106 -0
  224. package/opencode-plugin/dist/adapters/codex/tui-restart-watch.d.ts +2 -0
  225. package/opencode-plugin/dist/adapters/codex/tui-restart-watch.js +330 -0
  226. package/opencode-plugin/dist/adapters/declarations.d.ts +36 -0
  227. package/opencode-plugin/dist/adapters/declarations.js +49 -0
  228. package/opencode-plugin/dist/adapters/dsh/adapter.d.ts +15 -0
  229. package/opencode-plugin/dist/adapters/dsh/adapter.js +114 -0
  230. package/opencode-plugin/dist/adapters/dsh/plugin.d.ts +112 -0
  231. package/opencode-plugin/dist/adapters/dsh/plugin.js +276 -0
  232. package/opencode-plugin/dist/adapters/dsh/status.d.ts +36 -0
  233. package/opencode-plugin/dist/adapters/dsh/status.js +102 -0
  234. package/opencode-plugin/dist/adapters/executors.d.ts +69 -0
  235. package/opencode-plugin/dist/adapters/executors.js +184 -0
  236. package/opencode-plugin/dist/adapters/external.d.ts +61 -0
  237. package/opencode-plugin/dist/adapters/external.js +209 -0
  238. package/opencode-plugin/dist/adapters/opencode/adapter.d.ts +14 -0
  239. package/opencode-plugin/dist/adapters/opencode/adapter.js +184 -0
  240. package/opencode-plugin/dist/adapters/opencode/journal.d.ts +36 -0
  241. package/opencode-plugin/dist/adapters/opencode/journal.js +105 -0
  242. package/opencode-plugin/dist/adapters/opencode/plugin.d.ts +9 -0
  243. package/opencode-plugin/dist/adapters/opencode/plugin.js +293 -0
  244. package/opencode-plugin/dist/adapters/supervisor.d.ts +2 -0
  245. package/opencode-plugin/dist/adapters/supervisor.js +165 -0
  246. package/opencode-plugin/dist/adapters/types.d.ts +54 -0
  247. package/opencode-plugin/dist/adapters/types.js +1 -0
  248. package/opencode-plugin/dist/cli.d.ts +2 -0
  249. package/opencode-plugin/dist/cli.js +254 -0
  250. package/opencode-plugin/dist/contract/field-state.d.ts +13 -0
  251. package/opencode-plugin/dist/contract/field-state.js +43 -0
  252. package/opencode-plugin/dist/contract/index.d.ts +7 -0
  253. package/opencode-plugin/dist/contract/index.js +6 -0
  254. package/opencode-plugin/dist/contract/schema.d.ts +2157 -0
  255. package/opencode-plugin/dist/contract/schema.js +278 -0
  256. package/opencode-plugin/dist/contract/states.d.ts +78 -0
  257. package/opencode-plugin/dist/contract/states.js +83 -0
  258. package/opencode-plugin/dist/contract/tool.d.ts +30 -0
  259. package/opencode-plugin/dist/contract/tool.js +52 -0
  260. package/opencode-plugin/dist/contract/types.d.ts +198 -0
  261. package/opencode-plugin/dist/contract/types.js +1 -0
  262. package/opencode-plugin/dist/contract/validate.d.ts +13 -0
  263. package/opencode-plugin/dist/contract/validate.js +467 -0
  264. package/opencode-plugin/dist/contract/version.d.ts +3 -0
  265. package/opencode-plugin/dist/contract/version.js +6 -0
  266. package/opencode-plugin/dist/core/config-probe.d.ts +101 -0
  267. package/opencode-plugin/dist/core/config-probe.js +565 -0
  268. package/opencode-plugin/dist/core/fingerprint.d.ts +8 -0
  269. package/opencode-plugin/dist/core/fingerprint.js +34 -0
  270. package/opencode-plugin/dist/core/index.d.ts +7 -0
  271. package/opencode-plugin/dist/core/index.js +5 -0
  272. package/opencode-plugin/dist/core/journal.d.ts +12 -0
  273. package/opencode-plugin/dist/core/journal.js +19 -0
  274. package/opencode-plugin/dist/core/ladder.d.ts +28 -0
  275. package/opencode-plugin/dist/core/ladder.js +28 -0
  276. package/opencode-plugin/dist/core/operations.d.ts +30 -0
  277. package/opencode-plugin/dist/core/operations.js +222 -0
  278. package/opencode-plugin/dist/core/policy.d.ts +19 -0
  279. package/opencode-plugin/dist/core/policy.js +30 -0
  280. package/opencode-plugin/dist/core/session-probe.d.ts +75 -0
  281. package/opencode-plugin/dist/core/session-probe.js +469 -0
  282. package/opencode-plugin/dist/core/store.d.ts +71 -0
  283. package/opencode-plugin/dist/core/store.js +196 -0
  284. package/opencode-plugin/dist/index.d.ts +2 -0
  285. package/opencode-plugin/dist/index.js +2 -0
  286. package/opencode-plugin/dist/install/binding.d.ts +33 -0
  287. package/opencode-plugin/dist/install/binding.js +75 -0
  288. package/opencode-plugin/dist/install/discovery.d.ts +3 -0
  289. package/opencode-plugin/dist/install/discovery.js +48 -0
  290. package/opencode-plugin/dist/install/dsh-installer.d.ts +73 -0
  291. package/opencode-plugin/dist/install/dsh-installer.js +497 -0
  292. package/opencode-plugin/dist/install/dsh-worker.d.ts +1 -0
  293. package/opencode-plugin/dist/install/dsh-worker.js +108 -0
  294. package/opencode-plugin/dist/install/manager.d.ts +56 -0
  295. package/opencode-plugin/dist/install/manager.js +417 -0
  296. package/opencode-plugin/dist/install/scope.d.ts +25 -0
  297. package/opencode-plugin/dist/install/scope.js +257 -0
  298. package/opencode-plugin/dist/tmux/backend.d.ts +55 -0
  299. package/opencode-plugin/dist/tmux/backend.js +161 -0
  300. package/opencode-plugin/package.json +7 -0
  301. package/opencode-plugin/plugin.js +1 -0
  302. package/package.json +91 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AI4AI contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ ![AI4AI — Let AI Manage Itself](docs/banner.svg)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [English](README.md) | [中文](README.zh-CN.md)
4
+
5
+ **AI4AI** — Let AI manage itself more easily.
6
+
7
+ AI4AI is an extension kit for AI harnesses: it abstracts extension capabilities into a unified interface — the same tool calls work across harnesses, and skills stay portable.
8
+
9
+ - **Know Itself** — understand its own runtime state, including but not limited to context usage, model, reasoning effort and window.
10
+ - **Renew Itself** — renew itself on demand, refreshing the context, shedding the burden and traveling light.
11
+ - **Duplicate Itself** — create its own copies, making task scheduling and coordination more flexible.
12
+
13
+ ## Supported harnesses
14
+
15
+ | Harness | Linux | macOS | Windows |
16
+ |---|---|---|---|
17
+ | Claude Code | ✅ | ✅ | WSL |
18
+ | Codex | ✅ | ✅ | WSL |
19
+ | OpenCode | ✅ | ✅ | WSL |
20
+ | DeepSeek Harness | ✅ | ✅ | ✅ |
21
+
22
+ On Windows, all harnesses except DeepSeek Harness run via WSL; details and limits are in the contract docs.
23
+
24
+ ## Start
25
+
26
+ Requires Node.js 22+.
27
+
28
+ ```bash
29
+ npx ai4ai init # recommended: no global install
30
+ npm install -g ai4ai && ai4ai init # global install, command persists
31
+ npm i -D ai4ai && npx ai4ai init --scope project # project-scope install
32
+ ```
33
+
34
+ `init` detects and registers local harnesses (idempotent); `--yes` skips the prompt.
35
+
36
+ ```bash
37
+ npx ai4ai status # show state
38
+ npx ai4ai upgrade # re-register
39
+ npx ai4ai uninstall # remove registrations
40
+ ```
41
+
42
+ Claude Code / OpenCode / DSH expose the tools after registration; Codex uses the CLI:
43
+
44
+ ```bash
45
+ npx ai4ai session --operation status --harness codex
46
+ ```
47
+
48
+ Contract and details: [docs/contract.md](docs/contract.md). MIT.
@@ -0,0 +1,48 @@
1
+ ![AI4AI — 让 AI 管理自己](docs/banner.zh-CN.svg)
2
+
3
+ [English](README.md) | [中文](README.zh-CN.md)
4
+
5
+ **AI4AI** 让 AI 更方便地管理自己。
6
+
7
+ AI4AI 是面向 AI Harness 的扩展工具包:把扩展能力抽象成统一接口——工具的调用方式跨 Harness 一致,技能保持可移植。
8
+
9
+ - **认识自己** —— 了解自己的运行状态,包括但不限于上下文用量、模型、推理强度与窗口。
10
+ - **更新自己** —— 按需主动刷新自己,更新上下文,卸下负担,轻装前行。
11
+ - **复制自己** —— 创建自己的分身,让任务安排和协同更加自由。
12
+
13
+ ## 已支持的 Harness
14
+
15
+ | Harness | Linux | macOS | Windows |
16
+ |---|---|---|---|
17
+ | Claude Code | ✅ | ✅ | WSL |
18
+ | Codex | ✅ | ✅ | WSL |
19
+ | OpenCode | ✅ | ✅ | WSL |
20
+ | DeepSeek Harness | ✅ | ✅ | ✅ |
21
+
22
+ Windows 下除 DeepSeek Harness 外,均通过 WSL 运行;细节与限制见契约文档。
23
+
24
+ ## 开始
25
+
26
+ 需要 Node.js 22+。
27
+
28
+ ```bash
29
+ npx ai4ai init # 推荐:免全局安装
30
+ npm install -g ai4ai && ai4ai init # 全局安装,命令常驻
31
+ npm i -D ai4ai && npx ai4ai init --scope project # 项目内安装
32
+ ```
33
+
34
+ `init` 检测并注册本机 Harness(幂等);`--yes` 跳过选择。
35
+
36
+ ```bash
37
+ npx ai4ai status # 查看状态
38
+ npx ai4ai upgrade # 重新注册
39
+ npx ai4ai uninstall # 卸载注册
40
+ ```
41
+
42
+ Claude Code / OpenCode / DSH 注册后直接使用工具;Codex 用 CLI:
43
+
44
+ ```bash
45
+ npx ai4ai session --operation status --harness codex
46
+ ```
47
+
48
+ 契约与细节见 [docs/contract.md](docs/contract.md)。MIT。
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "ai4ai",
3
+ "version": "0.0.3",
4
+ "description": "AI Harness Extension Kit: self-handoff and detached executors for Claude Code"
5
+ }
@@ -0,0 +1,21 @@
1
+ import type { AdapterContext, CarrierCommand, StatusDetails } from '../external.js';
2
+ import { ExternalExecutorAdapter } from '../external.js';
3
+ import type { CapabilityDeclaration } from '../../contract/types.js';
4
+ import type { HarnessId, Os } from '../../contract/states.js';
5
+ import type { ExecutorRecord } from '../../core/store.js';
6
+ import type { LogLine, ExecutorStatus } from '../executors.js';
7
+ /**
8
+ * Claude Code adapter.
9
+ *
10
+ * Self-handoff is implemented by the installed in-harness plugin (`mods`); the
11
+ * external adapter owns detached executors (`claude -p` headless process).
12
+ */
13
+ /** Resolve the installed Claude plugin directory across marketplace and versioned runtimes. */
14
+ export declare function claudePluginDir(home: string): string | undefined;
15
+ export declare class ClaudeAdapter extends ExternalExecutorAdapter {
16
+ readonly harness: HarnessId;
17
+ capabilities(os: Os): CapabilityDeclaration[];
18
+ protected carrier(request: Parameters<ExternalExecutorAdapter['spawn']>[0], ctx: AdapterContext, _executorId: string, resumeSessionId?: string): Promise<CarrierCommand>;
19
+ protected statusDetails(_record: ExecutorRecord, status: ExecutorStatus, log: LogLine[], ctx: AdapterContext): Promise<StatusDetails>;
20
+ }
21
+ export declare const claudeAdapter: ClaudeAdapter;
@@ -0,0 +1,111 @@
1
+ import { existsSync, readdirSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { ExternalExecutorAdapter, lastJson } from '../external.js';
5
+ import { resolveClaudeStatus } from './status.js';
6
+ import { verifiedText, verifiedTokens, verifiedWindow } from '../../core/ladder.js';
7
+ import { declaration } from '../declarations.js';
8
+ /**
9
+ * Claude Code adapter.
10
+ *
11
+ * Self-handoff is implemented by the installed in-harness plugin (`mods`); the
12
+ * external adapter owns detached executors (`claude -p` headless process).
13
+ */
14
+ /** Resolve the installed Claude plugin directory across marketplace and versioned runtimes. */
15
+ export function claudePluginDir(home) {
16
+ const marketplace = path.join(home, 'marketplace', 'plugins', 'ai4ai');
17
+ if (existsSync(path.join(marketplace, '.claude-plugin', 'plugin.json')))
18
+ return marketplace;
19
+ const runtime = path.join(home, 'runtime');
20
+ try {
21
+ for (const entry of readdirSync(runtime)) {
22
+ const candidate = path.join(runtime, entry, 'claude-plugin');
23
+ if (existsSync(path.join(candidate, '.claude-plugin', 'plugin.json')))
24
+ return candidate;
25
+ }
26
+ }
27
+ catch { /* no runtime tree */ }
28
+ const direct = path.join(runtime, 'claude-plugin');
29
+ return existsSync(path.join(direct, '.claude-plugin', 'plugin.json')) ? direct : undefined;
30
+ }
31
+ export class ClaudeAdapter extends ExternalExecutorAdapter {
32
+ harness = 'claude-code';
33
+ capabilities(os) {
34
+ const verified = os === 'linux' || os === 'darwin';
35
+ const reason = os === 'linux'
36
+ ? 'The mods plugin loads and both native handoff modes completed in place: restart via the built-in /clear (new session, same process) and compact via the native safe point; detached carriers spawn, report status and survive the parent. Exercised on Linux.'
37
+ : os === 'darwin'
38
+ ? 'The mods plugin loads and the native in-place handoff completed on macOS; detached carriers spawn and report status with model and context. Exercised on macOS.'
39
+ : 'The mods plugin and the detached carrier are implemented; native Windows is out of scope (WSL counts as Linux) and was not exercised.';
40
+ const level = verified ? 'supported' : 'not-tested';
41
+ const common = {
42
+ handoff: { availability: level, modes: ['compact', 'restart'], tmuxFallback: 'off' },
43
+ spawn: { availability: level, maxConcurrent: 4 },
44
+ status: { availability: level, model: level, reasoningEffort: 'unsupported', context: level, percentSource: 'derived' },
45
+ ...(verified ? { evidence: `matrix:claude-code/${os}/2026-11-18` } : {}),
46
+ };
47
+ return [
48
+ declaration({ harness: 'claude-code', os, interface: 'tui', reason, ...common }),
49
+ declaration({ harness: 'claude-code', os, interface: 'headless', reason, ...common }),
50
+ ];
51
+ }
52
+ async carrier(request, ctx, _executorId, resumeSessionId) {
53
+ // A detached executor has no one to answer permission prompts: run it in the
54
+ // harness's non-interactive bypass mode, consistent with the spawn contract.
55
+ const args = ['-p', '--output-format', 'stream-json', '--verbose', '--permission-mode', 'bypassPermissions'];
56
+ // Resume selects the existing session; a new turn gets a fresh session id.
57
+ // Never pass both: the CLI rejects two session selectors.
58
+ if (resumeSessionId)
59
+ args.push('--resume', resumeSessionId);
60
+ else
61
+ args.push('--session-id', randomUUID());
62
+ const plugin = claudePluginDir(ctx.home);
63
+ if (plugin)
64
+ args.push('--plugin-dir', plugin);
65
+ if (request.model)
66
+ args.push('--model', request.model);
67
+ if (request.reasoningEffort)
68
+ args.push('--effort', request.reasoningEffort);
69
+ // A nested CLI must not inherit the parent's session markers: they bind it
70
+ // to the orchestrator's transport and can make it hang or route elsewhere.
71
+ // Only explicit overrides are persisted; the inherited environment is
72
+ // filtered at launch so credentials never land in the executor state.
73
+ const envExclude = ['CLAUDECODE', 'CLAUDE_CODE_CHILD_SESSION', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_SESSION_ID',
74
+ 'CLAUDE_CODE_MESSAGING_SOCKET', 'CLAUDE_CODE_MESSAGING_TOKEN', 'CLAUDE_CODE_ATTRIBUTION_HEADER', 'AI_AGENT'];
75
+ const env = {};
76
+ // Test/CI may point the carrier at an isolated Claude config so the user's
77
+ // personal settings (including a different provider) do not override the
78
+ // caller's intended route.
79
+ if (process.env.AI4AI_CLAUDE_CONFIG_DIR)
80
+ env.CLAUDE_CONFIG_DIR = process.env.AI4AI_CLAUDE_CONFIG_DIR;
81
+ return {
82
+ command: process.env.AI4AI_CLAUDE_BIN || 'claude',
83
+ args,
84
+ env,
85
+ envExclude,
86
+ sessionRegex: '"session_id"\\s*:\\s*"([^"]+)"',
87
+ };
88
+ }
89
+ async statusDetails(_record, status, log, ctx) {
90
+ // Layer 1: the native stream-json result of the carrier turn. The shared
91
+ // resolver then walks transcript > environment > settings per field.
92
+ const result = lastJson(log, value => value.type === 'result' && typeof value.usage === 'object');
93
+ let nativeUsed = null;
94
+ let nativeModel = null;
95
+ let nativeWindow = null;
96
+ if (result) {
97
+ const usage = (result.usage ?? {});
98
+ const used = ['input_tokens', 'cache_read_input_tokens', 'cache_creation_input_tokens']
99
+ .map(key => verifiedTokens(usage[key]) ?? 0)
100
+ .reduce((sum, value) => sum + value, 0);
101
+ nativeUsed = used > 0 ? used : null;
102
+ const modelUsage = (result.modelUsage ?? {});
103
+ nativeModel = verifiedText(Object.keys(modelUsage)[0] ?? result.model);
104
+ nativeWindow = nativeModel ? verifiedWindow(modelUsage[nativeModel]?.contextWindow) : null;
105
+ }
106
+ return resolveClaudeStatus(ctx.identity.workspace, status.sessionId, {
107
+ used: nativeUsed, model: nativeModel, window: nativeWindow,
108
+ });
109
+ }
110
+ }
111
+ export const claudeAdapter = new ClaudeAdapter();
@@ -0,0 +1,51 @@
1
+ import type { Identity, Request, Result } from '../../contract/types.js';
2
+ export type ClaudePhase = 'pending' | 'scheduled' | 'applied' | 'completed' | 'cancelled' | 'failed' | 'unknown';
3
+ export interface ClaudeRecord {
4
+ format: 2;
5
+ operationId: string;
6
+ fingerprint: string;
7
+ request: Request;
8
+ source: Identity;
9
+ marker: string;
10
+ phase: ClaudePhase;
11
+ reason: string;
12
+ /** Native context replacement strategy recorded for this handoff. */
13
+ mechanism?: 'restart' | 'compact';
14
+ successor?: Identity;
15
+ }
16
+ export interface ClaudeCommand {
17
+ action: 'binding' | 'inspect' | 'request' | 'transition' | 'recover';
18
+ caller?: Identity;
19
+ instance?: string;
20
+ request?: unknown;
21
+ operationId?: string;
22
+ phase?: ClaudePhase;
23
+ marker?: string;
24
+ reason?: string;
25
+ /** Native successor identity after a restart (new session id) or compact generation. */
26
+ successor?: Identity;
27
+ mechanism?: 'restart' | 'compact';
28
+ usage?: {
29
+ window?: number | null;
30
+ used?: number | null;
31
+ percent?: number | null;
32
+ model?: string | null;
33
+ reasoningEffort?: string | null;
34
+ };
35
+ }
36
+ declare const PHASES: readonly ClaudePhase[];
37
+ declare const sessionKey: (identity: Identity) => string;
38
+ declare function response(record: ClaudeRecord, operation?: Request['operation']): Result;
39
+ /** Durable per-session journal; revisions append and the latest row wins. */
40
+ export declare class ClaudeJournal {
41
+ private readonly home;
42
+ constructor(home: string);
43
+ private lock;
44
+ private file;
45
+ private read;
46
+ private write;
47
+ latest(records: readonly ClaudeRecord[], operationId: string): ClaudeRecord | undefined;
48
+ transaction(identity: Identity, action: (records: ClaudeRecord[], commit: (record: ClaudeRecord) => Promise<void>) => Promise<unknown>): Promise<unknown>;
49
+ rows(identity: Identity): Promise<readonly ClaudeRecord[]>;
50
+ }
51
+ export { response, PHASES, sessionKey };
@@ -0,0 +1,81 @@
1
+ import { mkdir, lstat } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { atomicJson, bytes, contained, digest, ownership, withScopeLock } from '../../install/scope.js';
4
+ import { result } from '../../contract/validate.js';
5
+ import { handoffOutcome } from '../../contract/states.js';
6
+ const PHASES = ['pending', 'scheduled', 'applied', 'completed', 'cancelled', 'failed', 'unknown'];
7
+ const sessionKey = (identity) => `${identity.workspace}\0${identity.surface}\0${identity.session}`;
8
+ function response(record, operation = 'handoff') {
9
+ const status = record.phase === 'scheduled' ? 'pending' : record.phase;
10
+ const lifecycle = handoffOutcome(record.phase);
11
+ return result({ operation, operationId: record.operationId }, status, record.reason, {
12
+ durable: true,
13
+ state: lifecycle.state,
14
+ ...(lifecycle.handoff ? { handoff: lifecycle.handoff } : {}),
15
+ ...(record.phase === 'completed' && record.successor
16
+ ? {
17
+ proof: {
18
+ source: record.source, successor: record.successor,
19
+ mechanism: (record.mechanism === 'restart' ? 'new-session' : 'surface-replacement'),
20
+ nativeEvidence: record.marker,
21
+ },
22
+ }
23
+ : {}),
24
+ });
25
+ }
26
+ /** Durable per-session journal; revisions append and the latest row wins. */
27
+ export class ClaudeJournal {
28
+ home;
29
+ constructor(home) {
30
+ this.home = home;
31
+ }
32
+ async lock(action) {
33
+ const owned = await ownership(this.home);
34
+ return withScopeLock(owned.root, owned.owner, action);
35
+ }
36
+ file(identity) {
37
+ const key = digest(sessionKey(identity));
38
+ return path.join(this.home, '.ai4ai', 'claude', `${key}.json`);
39
+ }
40
+ async read(identity, token) {
41
+ const file = this.file(identity);
42
+ const raw = await bytes(file);
43
+ if (!raw)
44
+ return { product: 'ai4ai', format: 2, ownerToken: token, session: identity.session, records: [] };
45
+ const value = JSON.parse(raw.toString());
46
+ if (value.product !== 'ai4ai' || value.format !== 2 || value.ownerToken !== token || value.session !== identity.session || !Array.isArray(value.records)) {
47
+ throw new Error('Claude journal is foreign or malformed; no transition authorized');
48
+ }
49
+ return value;
50
+ }
51
+ async write(identity, token, ledger) {
52
+ const file = this.file(identity);
53
+ await contained(this.home, file);
54
+ const directory = path.dirname(file);
55
+ await mkdir(directory, { recursive: true, mode: 0o700 });
56
+ if ((await lstat(directory)).isSymbolicLink())
57
+ throw new Error('Claude journal directory is a link');
58
+ const raw = await bytes(file);
59
+ await atomicJson(path.join(this.home, '.ai4ai'), file, ledger, raw === undefined ? undefined : digest(raw));
60
+ }
61
+ latest(records, operationId) {
62
+ return records.findLast(record => record.operationId === operationId);
63
+ }
64
+ async transaction(identity, action) {
65
+ return this.lock(async () => {
66
+ const owned = await ownership(this.home);
67
+ const ledger = await this.read(identity, owned.owner.token);
68
+ const records = ledger.records.slice();
69
+ const commit = async (record) => {
70
+ records.push(record);
71
+ await this.write(identity, owned.owner.token, { ...ledger, records });
72
+ };
73
+ return action(records, commit);
74
+ });
75
+ }
76
+ async rows(identity) {
77
+ const owned = await ownership(this.home);
78
+ return (await this.read(identity, owned.owner.token)).records;
79
+ }
80
+ }
81
+ export { response, PHASES, sessionKey };
@@ -0,0 +1,3 @@
1
+ import type { Register } from 'claude-code';
2
+ /** Native Claude Code mods: in-place handoff without a summarizer, daemon or history fork. */
3
+ export declare const register: Register;