eve-hub 0.0.0-stage → 0.4.1

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 (122) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +100 -2
  3. package/artifacts/core.mjs +221 -0
  4. package/artifacts/state.d.ts +1 -0
  5. package/artifacts/state.js +5 -0
  6. package/artifacts/types/change-explainer.mjs +106 -0
  7. package/bash-run.mjs +300 -0
  8. package/bot-model.mjs +54 -0
  9. package/bot-token.mjs +12 -0
  10. package/channels/eve-roster-user.d.ts +2 -0
  11. package/channels/eve-roster-user.js +21 -0
  12. package/channels/eve.d.ts +1 -0
  13. package/channels/eve.js +3 -0
  14. package/connections/vercel-kit.d.ts +2 -0
  15. package/connections/vercel-kit.js +52 -0
  16. package/fork-env.mjs +41 -0
  17. package/hooks/mention-gate.d.ts +2 -0
  18. package/hooks/mention-gate.js +33 -0
  19. package/hooks/sandbox.d.ts +2 -0
  20. package/hooks/sandbox.js +17 -0
  21. package/host-browser.d.ts +59 -0
  22. package/host-browser.js +387 -0
  23. package/host-sandbox.d.ts +113 -0
  24. package/host-sandbox.js +778 -0
  25. package/hub-path.mjs +25 -0
  26. package/hub-skill.mjs +29 -0
  27. package/image-limits.mjs +59 -0
  28. package/instructions/main.d.ts +2 -0
  29. package/instructions/main.js +6 -0
  30. package/instructions/protocol.d.ts +2 -0
  31. package/instructions/protocol.js +7 -0
  32. package/main-instructions.mjs +39 -0
  33. package/memory/bot.d.ts +2 -0
  34. package/memory/bot.js +25 -0
  35. package/memory/workspace.d.ts +2 -0
  36. package/memory/workspace.js +18 -0
  37. package/memory.mjs +242 -0
  38. package/mention-gate.mjs +521 -0
  39. package/package.json +33 -4
  40. package/registry-fetch.mjs +68 -0
  41. package/roster-model.mjs +74 -0
  42. package/schedules/compact.d.ts +2 -0
  43. package/schedules/compact.js +17 -0
  44. package/schedules/dash-classify.mjs +284 -0
  45. package/schedules/dash-rules.mjs +336 -0
  46. package/schedules/dash-run.mjs +98 -0
  47. package/schedules/dash.d.ts +2 -0
  48. package/schedules/dash.js +32 -0
  49. package/schedules/hub.mjs +130 -0
  50. package/schedules/prune.d.ts +2 -0
  51. package/schedules/prune.js +26 -0
  52. package/schedules/rules.mjs +132 -0
  53. package/schedules/run-compact.mjs +25 -0
  54. package/schedules/thread-brief.mjs +108 -0
  55. package/schedules/tracks-lead.mjs +91 -0
  56. package/schedules/tracks.d.ts +2 -0
  57. package/schedules/tracks.js +14 -0
  58. package/self-restart.mjs +73 -0
  59. package/session-limits.mjs +37 -0
  60. package/skills/change-explainer.d.ts +2 -0
  61. package/skills/change-explainer.js +6 -0
  62. package/subagent-cap.mjs +69 -0
  63. package/templates/main-instructions.md +44 -0
  64. package/templates/workspace-protocol.md +87 -0
  65. package/tools/agent_send.d.ts +2 -0
  66. package/tools/agent_send.js +36 -0
  67. package/tools/apply_tags.d.ts +2 -0
  68. package/tools/apply_tags.js +40 -0
  69. package/tools/archive_thread.d.ts +2 -0
  70. package/tools/archive_thread.js +22 -0
  71. package/tools/artifact_list.d.ts +2 -0
  72. package/tools/artifact_list.js +19 -0
  73. package/tools/artifact_publish.d.ts +2 -0
  74. package/tools/artifact_publish.js +23 -0
  75. package/tools/artifact_status.d.ts +2 -0
  76. package/tools/artifact_status.js +22 -0
  77. package/tools/attach_image.d.ts +2 -0
  78. package/tools/attach_image.js +51 -0
  79. package/tools/bash.d.ts +2 -0
  80. package/tools/bash.js +33 -0
  81. package/tools/browser.d.ts +2 -0
  82. package/tools/browser.js +34 -0
  83. package/tools/create_agent.d.ts +2 -0
  84. package/tools/create_agent.js +30 -0
  85. package/tools/create_thread.d.ts +2 -0
  86. package/tools/create_thread.js +27 -0
  87. package/tools/dash_update.d.ts +2 -0
  88. package/tools/dash_update.js +33 -0
  89. package/tools/disabled.d.ts +2 -0
  90. package/tools/disabled.js +6 -0
  91. package/tools/list_agents.d.ts +2 -0
  92. package/tools/list_agents.js +11 -0
  93. package/tools/list_threads.d.ts +2 -0
  94. package/tools/list_threads.js +32 -0
  95. package/tools/move_path.d.ts +2 -0
  96. package/tools/move_path.js +24 -0
  97. package/tools/post_message.d.ts +2 -0
  98. package/tools/post_message.js +42 -0
  99. package/tools/react.d.ts +2 -0
  100. package/tools/react.js +21 -0
  101. package/tools/read_thread.d.ts +3 -0
  102. package/tools/read_thread.js +62 -0
  103. package/tools/remove_agent.d.ts +2 -0
  104. package/tools/remove_agent.js +18 -0
  105. package/tools/rename_thread.d.ts +2 -0
  106. package/tools/rename_thread.js +30 -0
  107. package/tools/restart_agent.d.ts +2 -0
  108. package/tools/restart_agent.js +21 -0
  109. package/tools/restart_hub.d.ts +2 -0
  110. package/tools/restart_hub.js +25 -0
  111. package/tools/set_summary.d.ts +2 -0
  112. package/tools/set_summary.js +25 -0
  113. package/tools/show.d.ts +2 -0
  114. package/tools/show.js +24 -0
  115. package/tools/tag_threads.d.ts +2 -0
  116. package/tools/tag_threads.js +45 -0
  117. package/tools/unarchive_thread.d.ts +2 -0
  118. package/tools/unarchive_thread.js +19 -0
  119. package/tools/view_image.d.ts +34 -0
  120. package/tools/view_image.js +132 -0
  121. package/workspace-roster.mjs +15 -0
  122. package/workspace.mjs +212 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,101 @@
1
- # Temporary Holding Version
1
+ # eve-hub
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
+ The bot-side code every hub agent shares (milestone M3 in [`docs/architecture`](../../docs/architecture/README.md#milestones); D0, D12). Bots live in a workspace (their own repo, [`docs/workspace.md`](../../docs/workspace.md)); each keeps a one-line stub per file and the code lives here once.
4
+
5
+ | Module | What it is | Bots use it as |
6
+ |---|---|---|
7
+ | `tools/rename_thread.ts`, `list_threads.ts`, `read_thread.ts`, `react.ts`, `show.ts`, `attach_image.ts`, `browser.ts` | Registry and workspace tools (`defineTool`) | `agent/tools/<same name>.ts` |
8
+ | `tools/create_thread.ts`, `post_message.ts`, `archive_thread.ts`, `unarchive_thread.ts`, `list_agents.ts`, `create_agent.ts`, `remove_agent.ts`, `restart_agent.ts`, `agent_send.ts`, `tag_threads.ts`, `apply_tags.ts` | The orchestrator's tools | `main`'s `agent/tools/<same name>.ts` |
9
+ | `hooks/sandbox.ts` | Migrates legacy Docker sessions to the host sandbox (`defineHook`) | `agent/hooks/sandbox.ts` |
10
+ | `instructions/main.ts`, `main-instructions.mjs` | main's instructions (`defineInstructions`), rendered at build time from the kit's `templates/main-instructions.md` + `workspace-protocol.md`, so no workspace carries a copy | `main`'s `agent/instructions.ts`; workspace-only additions in `agent/instructions/*.md` |
11
+ | `instructions/protocol.ts` | The shared protocol alone, rendered from `templates/workspace-protocol.md` | every other bot's `agent/instructions/protocol.ts`, appended after its own `instructions.md` (who the bot is) |
12
+ | `memory/workspace.ts`, `memory.mjs` | an eve memory slot (default export, constant `workspace` scope) whose provider recalls the workspace's `memory/<id>.md` entries, one message each, at every turn start and after compaction, only the ones whose text changed since the session last saw them, as new messages after the history; `validateMemory(root)` for a workspace's tests | every bot's (main too) `agent/memory/workspace.ts`: `export { default } from "eve-hub/memory/workspace"` |
13
+ | `memory/bot.ts` | the same for the bot's own `agents/<bot>/memory/<id>.md` entries; the bot is found from its directory (`findBotDir`), scope is its name | every bot's `agent/memory/bot.ts`: `export { default } from "eve-hub/memory/bot"` |
14
+ | `channels/eve-roster-user.ts` | `eveChannel({ auth: [rosterUser, localDev()], turnPolicy: "queue" })`: queued mentions, and the registry's `x-roster-user` human as a user principal | every bot's `agent/channels/eve.ts` |
15
+ | `channels/eve.ts` | Re-exports `eve-roster-user.ts`, for stubs written before every bot shared one channel | older `agent/channels/eve.ts` stubs |
16
+ | `tools/disabled.ts` | `disableTool()`: removes an eve default tool | the read-only preset's `agent/tools/write_file.ts` |
17
+ | `host-sandbox.ts`, `host-browser.ts` | `HostSandbox` (the host machine is the sandbox) and each session's headless Chromium | `agent/sandbox.ts` imports `HostSandbox` |
18
+ | `roster-model.mjs` | `bindRoster(workspace)`: `rosterModel(name, …)` (the dynamic `model` for agent.ts), `rosterLimits`, `agents` and `subagentCap`, for the `hub.workspace.json` the bot imports; `rosterModel` / `rosterLimits` read from disk for bots scaffolded before it; `createRosterModel({ agents, subagentCap })`: the same for a given roster | `bindRoster(workspace)` in agent.ts |
19
+ | `session-limits.mjs` | `sessionLimits(roster, name)`: a bot's eve `limits` (no session timeout, per-session usage limits from `hub.workspace.json` over the default backstop) | `limits: rosterLimits("<name>")` from `eve-hub/roster-model` |
20
+ | `workspace.mjs` | Reads and validates `hub.workspace.json`, assigns ports, finds a bot's workspace (`HUB_WORKSPACE`, else up from cwd) | the daemon (`lib/workspace-root.mjs`) and `roster-model.mjs` |
21
+ | `workspace-roster.mjs` | `agents`, `humans`, `SUBAGENT_CAP` of the bot's workspace, read from disk | older subagents that resolve their capped model |
22
+ | `bot-model.mjs`, `subagent-cap.mjs` | Model parsing/selection and the subagent cap | via `roster-model.mjs`; subagents import `subagent-cap.mjs` |
23
+
24
+ The `hubChannel` from D0 isn't here yet. Turn lifecycle and replies are owned by the registry's eve stream consumer; agents do not report them through hooks.
25
+
26
+ ## How a bot uses it
27
+
28
+ eve discovers tools, hooks, and channels by file under `agent/tools`, `agent/hooks`, and `agent/channels`. A tool's name is its file name, so the file has to exist in the bot. The stub just re-exports the kit's default:
29
+
30
+ ```ts
31
+ // agents/<bot>/agent/tools/rename_thread.ts
32
+ export { default } from "eve-hub/tools/rename_thread";
33
+ ```
34
+
35
+ `sandbox.ts` stays a small module of its own, because each agent and subagent declares its own `environment`:
36
+
37
+ ```ts
38
+ import { defineSandbox } from "eve/sandbox";
39
+ import { HostSandbox } from "eve-hub/host-sandbox";
40
+ export const environment = HostSandbox.environment();
41
+ export default defineSandbox(() => environment.open());
42
+ ```
43
+
44
+ `lib/agent-template.mjs` (`KIT_FILES`, `MAIN_KIT_FILES`, `PRESETS`, `kitStub`, `hostSandboxFile`) writes these files: `scaffoldMain` for `hub workspace init`, `scaffoldAgent` for `create_agent`. `test/agent-kit.test.mjs` checks that they match.
45
+
46
+ A bot's role is enforced by its files as well as its prose. `create_agent`'s `preset` picks them: `builder` (the default) has every tool; `read-only` (planners, reviewers) adds `agent/tools/write_file.ts` → `tools/disabled.ts`, so it reads code, runs tests and delegates `agent` copies (which share its tool set) but can't edit files by tool. Its bash is the kit's regular bash, with no approval step.
47
+
48
+ ## The package import (D12)
49
+
50
+ 1. Before spawning the bots, the daemon links the kit (`lib/workspace-link.mjs`): `<workspace>/.hub/eve-hub` and `<workspace>/node_modules/eve-hub` → `<hub>/packages/agent-kit`. If the workspace has no `eve`/`zod` of its own, they are linked to hub's install too. The daemon only replaces links it created, never a real install.
51
+ 2. The workspace's `package.json` depends on `"eve-hub": "link:.hub/eve-hub"` (`workspace init` writes it), so a later `pnpm install` keeps resolving the kit the same way.
52
+ 3. The stubs use the specifiers the `exports` map serves (`eve-hub/tools/x`, `eve-hub/host-sandbox`, `eve-hub/roster-model`, …).
53
+ 4. `eve` and `zod` are peer dependencies. eve's bundler resolves the kit to its realpath, so the kit's own `eve` imports come from hub's install. When the workspace's eve is linked to hub's, that's one eve (verified with eve 0.69).
54
+
55
+ Bump `version` when a tool's name, schema, or description, the hook's events, or the channel config changes. Hub records each agent's kit version and accepts N and N−1 (D0/D12).
56
+
57
+ ## Published package (deployed workspaces)
58
+
59
+ A deployed workspace (`node scripts/workspace-template.mjs <dir>`, lib/workspace-template.mjs) has no hub checkout to link, so it installs the kit from npm, published as [`eve-hub`](https://www.npmjs.com/package/eve-hub): `"eve-hub": "<version>"`. `node packages/agent-kit/scripts/pack.mjs <outDir>` builds the package: every `.ts` module compiled to `.js` + `.d.ts` in place (node won't strip types under `node_modules`), the `exports` map pointed at them, and `templates/` included.
60
+
61
+ `.github/workflows/publish-eve-hub.yml` publishes it on every push to main whose kit `version` npm doesn't have yet, authenticated by the repo's `NPM_TOKEN` secret (an npm automation token). Bump `version` to ship a kit change to deployed workspaces; the template pins the version this checkout carries.
62
+
63
+ The template's main gets a Vercel Sandbox and only the kit stubs that run without the hub's machine (lib/workspace-template.mjs `DEPLOYED_KIT_FILES`; eve's own bash replaces the kit's). The published tarball (`scripts/pack.mjs`) leaves out the kit__worker extension, which mounts only on the hub's machine. The hub reaches each bot's eve channel with `Authorization: Bearer $BOT_TOKEN` (`bot-token.mjs`); the kit's calls to the hub (`registry-fetch.mjs`, at `ROSTER_REGISTRY_URL`) carry `Authorization: Bearer $HUB_TOKEN` and, since the hosted hub keeps Vercel Authentication on, `x-vercel-protection-bypass: $HUB_PROTECTION_BYPASS` (the hub project's automation bypass secret), each when set.
64
+
65
+ ## Vercel Kit connection
66
+
67
+ An agent opts into the app's Kit connector with `agent/connections/vercel-kit.ts`:
68
+
69
+ ```ts
70
+ export { default } from "eve-hub/connections/vercel-kit";
71
+ ```
72
+
73
+ Set `KIT_CONNECTOR` to the returned Vercel Connect connector UID in Hub's
74
+ `.env.local` (or its process environment). Hub's daemon loads that file before
75
+ starting agents. This app uses `kit.vercel.sh/hub`, attached to
76
+ `vercel-internal-playground/06-agents-only-one-project`.
77
+ All agents importing this connection share the connector; Connect authorizes
78
+ each authenticated roster user separately. Missing or blank configuration
79
+ returns no connection. Connector configuration is re-read at each turn.
80
+
81
+ Hub's local channel derives a user principal from the registry's `x-roster-user`
82
+ header only during local development. Callers without an authenticated user
83
+ cannot use this user-scoped connection. Each user completes Eve's sign-in
84
+ challenge when first using Kit. Kit action approvals are separate from sign-in:
85
+ when Kit returns `consent_required`, present its approval link and resume its
86
+ saved run only after the user decides.
87
+
88
+ For another Hub app, create and attach its own connector from its linked project:
89
+
90
+ ```sh
91
+ vercel connect create kit.vercel.sh/api/mcp --name my-hub --yes
92
+ vercel connect attach <returned-connector-uid> --yes
93
+ ```
94
+
95
+ Use `vercel env pull` to refresh local project credentials when needed; preserve
96
+ local settings before pulling because it replaces the destination file. Restart
97
+ an idle agent after adding its connection stub or updating its environment.
98
+ Validate by completing sign-in and asking for one read from a connected service.
99
+ Compilation and mocked authorization tests do not prove a live service read.
100
+
101
+ Reference: [Kit integration guide](https://app.notion.com/p/3dfe06b059c480778efaf967196764a8).
@@ -0,0 +1,221 @@
1
+ // Artifacts: a versioned static site a bot publishes and keeps current, such
2
+ // as a change explainer. The core is type-agnostic. A type (artifacts/types/)
3
+ // builds the site and its card from a source, and says whether a published
4
+ // version is still current.
5
+ //
6
+ // The session that publishes an artifact owns it. Its record lives in that
7
+ // session's state (the tools keep it in defineState("hub.artifacts")), and
8
+ // every deployment also carries its own artifact.json with the full history.
9
+ // The tool result carries the record, so the registry folds it into its
10
+ // read-only index (GET /api/artifacts) and the thread's card.
11
+ //
12
+ // Publishing a version:
13
+ // 1. the type builds the site, its card fields, and a thumbnail
14
+ // 2. artifact.json (record + history) is written into the site
15
+ // 3. `vercel deploy --prebuilt` to the hub-artifacts project, tagged with
16
+ // --meta artifact=<slug> --meta version=<n>
17
+ // 4. the stable alias <slug>.<domain> moves to it, unless another session
18
+ // published a newer version meanwhile
19
+ // 5. the site goes to the registry, which serves it at /artifacts/<id>/v<n>/
20
+ // for the hub's inline preview (no Vercel sign-in)
21
+ // 6. deployments older than the last KEEP versions are removed
22
+ import { execFile } from "node:child_process";
23
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
24
+ import { homedir, tmpdir } from "node:os";
25
+ import { join } from "node:path";
26
+ import changeExplainer from "./types/change-explainer.mjs";
27
+
28
+ import { registryFetch } from "../registry-fetch.mjs";
29
+ const SCOPE = process.env.HUB_ARTIFACTS_SCOPE ?? "vercel-internal-playground";
30
+ const PROJECT = process.env.HUB_ARTIFACTS_PROJECT ?? "hub-artifacts";
31
+ const DOMAIN = process.env.HUB_ARTIFACTS_DOMAIN ?? "playground-vercel.tools";
32
+ const WORK = process.env.HUB_ARTIFACTS_WORK ?? join(process.env.HUB_HOME ?? join(homedir(), ".hub"), "artifacts");
33
+ export const KEEP = 5;
34
+
35
+ export const TYPES = { "change-explainer": changeExplainer };
36
+ export const STATE_NAME = "hub.artifacts";
37
+
38
+ export const artifactId = (type, key) => `${type}:${key}`;
39
+ // A DNS label (at most 63 characters): the alias host and the --meta tag.
40
+ export function slugOf(id) {
41
+ const slug = id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
42
+ return slug.length <= 63 ? slug : slug.slice(0, 63).replace(/-+$/, "");
43
+ }
44
+ export const aliasOf = (id) => `${slugOf(id)}.${DOMAIN}`;
45
+ export const previewPath = (id, version) => `/artifacts/${encodeURIComponent(id)}/v${version}/`;
46
+
47
+ export function typeOf(name) {
48
+ const type = TYPES[name];
49
+ if (!type) throw new Error(`unknown artifact type ${JSON.stringify(name)} (known: ${Object.keys(TYPES).join(", ")})`);
50
+ return type;
51
+ }
52
+
53
+ export function run(cmd, args, { cwd, input, timeoutMs = 600_000 } = {}) {
54
+ return new Promise((resolve, reject) => {
55
+ const child = execFile(cmd, args, { cwd, maxBuffer: 64 << 20, timeout: timeoutMs, env: { ...process.env, FORCE_COLOR: "0" } }, (error, stdout, stderr) => {
56
+ if (error) {
57
+ const tail = String(stderr || stdout || "").trim().split("\n").slice(-6).join("\n");
58
+ reject(new Error(`${cmd} ${args[0] ?? ""} failed: ${tail || error.message}`));
59
+ } else resolve(String(stdout));
60
+ });
61
+ if (input !== undefined) child.stdin.end(input);
62
+ else child.stdin.end();
63
+ });
64
+ }
65
+
66
+ // The registry's copy of an artifact (owner, latest version), or null.
67
+ export async function registryRecord(id, fetchImpl = fetch) {
68
+ const res = await registryFetch(`/api/artifacts/${encodeURIComponent(id)}`, {}, { fetchImpl }).catch(() => null);
69
+ if (!res?.ok) return null;
70
+ return res.json().catch(() => null);
71
+ }
72
+
73
+ // The newest record this session can see: its own state or, for a fork or
74
+ // another session picking an artifact up, the registry's index.
75
+ export async function latestRecord(id, stateRecords, fetchImpl = fetch) {
76
+ const mine = stateRecords?.[id] ?? null;
77
+ const hub = await registryRecord(id, fetchImpl);
78
+ if (!hub) return mine;
79
+ if (!mine) return stripOwner(hub);
80
+ return (hub.version ?? 0) > (mine.version ?? 0) ? stripOwner(hub) : mine;
81
+ }
82
+ const stripOwner = ({ owner, ...record }) => record;
83
+
84
+ function projectLink() {
85
+ const dir = join(WORK, "vercel-link");
86
+ const file = join(dir, ".vercel", "project.json");
87
+ return { dir, file };
88
+ }
89
+
90
+ async function ensureProject() {
91
+ const { dir, file } = projectLink();
92
+ if (existsSync(file)) return file;
93
+ mkdirSync(dir, { recursive: true });
94
+ await run("vercel", ["link", "--yes", "--project", PROJECT, "--scope", SCOPE], { cwd: dir });
95
+ if (!existsSync(file)) throw new Error(`vercel link didn't write ${file}`);
96
+ return file;
97
+ }
98
+
99
+ // A Build Output API v3 tree around the site: static files, no SPA fallback
100
+ // (artifact sites route with the hash), the target pinned to preview.
101
+ function stage(site, slug, version) {
102
+ const dir = mkdtempSync(join(tmpdir(), `artifact-${slug}-v${version}-`));
103
+ const output = join(dir, ".vercel", "output");
104
+ cpSync(site, join(output, "static"), { recursive: true });
105
+ writeFileSync(
106
+ join(output, "config.json"),
107
+ JSON.stringify({
108
+ version: 3,
109
+ routes: [{ src: "/(.*)", headers: { "x-robots-tag": "noindex", "referrer-policy": "no-referrer" }, continue: true }, { handle: "filesystem" }],
110
+ }),
111
+ );
112
+ writeFileSync(join(output, "builds.json"), JSON.stringify({ target: "preview", builds: [] }));
113
+ return dir;
114
+ }
115
+
116
+ async function deploy(site, slug, version) {
117
+ const link = await ensureProject();
118
+ const dir = stage(site, slug, version);
119
+ try {
120
+ cpSync(link, join(dir, ".vercel", "project.json"));
121
+ const out = await run("vercel", ["deploy", "--prebuilt", "--target", "preview", "--scope", SCOPE, "--yes", "--meta", `artifact=${slug}`, "--meta", `version=${version}`], { cwd: dir });
122
+ const url = out.trim().split(/\s+/).reverse().find((w) => /^https:\/\/\S+$/.test(w));
123
+ if (!url) throw new Error(`vercel deploy printed no URL: ${out.slice(-300)}`);
124
+ return url;
125
+ } finally {
126
+ rmSync(dir, { recursive: true, force: true });
127
+ }
128
+ }
129
+
130
+ async function uploadBundle(site, id, version, fetchImpl) {
131
+ const tar = await new Promise((resolve, reject) =>
132
+ execFile("tar", ["-czf", "-", "-C", site, "."], { encoding: "buffer", maxBuffer: 1 << 30 }, (error, stdout) => (error ? reject(error) : resolve(stdout))),
133
+ );
134
+ const res = await registryFetch(`/api/artifacts/${encodeURIComponent(id)}/v/${version}/bundle`, {
135
+ method: "POST",
136
+ headers: { "content-type": "application/gzip" },
137
+ body: tar,
138
+ signal: AbortSignal.timeout(120_000),
139
+ }, { fetchImpl });
140
+ if (!res.ok) throw new Error(`preview upload failed: ${(await res.json().catch(() => ({}))).error ?? res.status}`);
141
+ return previewPath(id, version);
142
+ }
143
+
144
+ async function uploadThumbnail(path, fetchImpl) {
145
+ if (!path || !existsSync(path)) return undefined;
146
+ const res = await registryFetch(`/api/uploads`, {
147
+ method: "POST",
148
+ headers: { "content-type": "application/octet-stream", "x-filename": "thumbnail.png" },
149
+ body: readFileSync(path),
150
+ signal: AbortSignal.timeout(30_000),
151
+ }, { fetchImpl }).catch(() => null);
152
+ if (!res?.ok) return undefined;
153
+ return (await res.json()).id;
154
+ }
155
+
156
+ // Removes deployments older than the last KEEP versions; best effort.
157
+ async function prune(history) {
158
+ const old = history.slice(0, Math.max(0, history.length - KEEP)).filter((h) => h.url && !h.removed);
159
+ for (const h of old) {
160
+ await run("vercel", ["rm", h.url, "--yes", "--scope", SCOPE], { timeoutMs: 60_000 }).then(
161
+ () => (h.removed = true),
162
+ () => {},
163
+ );
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Publishes the next version of `type:key` from `source`. `prior` is the
169
+ * newest record this session knows (latestRecord). Returns the new record.
170
+ * `deps` swaps the side effects out in tests.
171
+ */
172
+ export async function publish({ type: typeName, key, source }, prior, deps = {}) {
173
+ const type = typeOf(typeName);
174
+ const id = artifactId(typeName, key);
175
+ const slug = slugOf(id);
176
+ const fetchImpl = deps.fetch ?? fetch;
177
+ const version = (prior?.version ?? 0) + 1;
178
+ const work = mkdtempSync(join(tmpdir(), `artifact-build-${slug}-`));
179
+ try {
180
+ const built = await (deps.build ?? type.build)(source, { work, id, version });
181
+ const now = new Date().toISOString();
182
+ const history = [...(prior?.history ?? []), { version, at: now, ...(built.meta?.head ? { head: built.meta.head } : {}) }];
183
+ const record = {
184
+ id,
185
+ type: typeName,
186
+ key,
187
+ version,
188
+ status: "fresh",
189
+ card: { ...built.card, updatedAt: now },
190
+ source,
191
+ meta: built.meta ?? {},
192
+ history,
193
+ updatedAt: now,
194
+ };
195
+ writeFileSync(join(built.site, "artifact.json"), JSON.stringify(record, null, 2));
196
+ const url = await (deps.deploy ?? deploy)(built.site, slug, version);
197
+ history.at(-1).url = url;
198
+ record.url = url;
199
+ // Another session may have moved the alias on while this one built.
200
+ const current = await registryRecord(id, fetchImpl);
201
+ if ((current?.version ?? 0) >= version) {
202
+ throw new Error(`${id} v${current.version} was published by ${current.owner?.bot ?? "another session"} while this one built v${version}; run artifact_status and publish again`);
203
+ }
204
+ const alias = aliasOf(id);
205
+ await (deps.alias ?? ((u, a) => run("vercel", ["alias", "set", u, a, "--scope", SCOPE])))(url, alias);
206
+ record.alias = `https://${alias}`;
207
+ record.preview = await (deps.uploadBundle ?? uploadBundle)(built.site, id, version, fetchImpl);
208
+ const thumbnail = await (deps.uploadThumbnail ?? uploadThumbnail)(built.thumbnail, fetchImpl);
209
+ if (thumbnail) record.card.thumbnail = thumbnail;
210
+ await (deps.prune ?? prune)(history);
211
+ return record;
212
+ } finally {
213
+ rmSync(work, { recursive: true, force: true });
214
+ }
215
+ }
216
+
217
+ /** What the type says about a published record: { status, reasons[] }. */
218
+ export async function status(record) {
219
+ const type = typeOf(record.type);
220
+ return type.status ? type.status(record) : { status: record.status ?? "fresh", reasons: [] };
221
+ }
@@ -0,0 +1 @@
1
+ export declare const artifacts: any;
@@ -0,0 +1,5 @@
1
+ // The owning session's artifact records, id -> latest record. Durable eve
2
+ // session state: it survives restarts like the rest of the session.
3
+ import { defineState } from "eve/context";
4
+ import { STATE_NAME } from "./core.mjs";
5
+ export const artifacts = defineState(STATE_NAME, () => ({}));
@@ -0,0 +1,106 @@
1
+ // The change-explainer artifact type: a narrated walkthrough of a PR or a
2
+ // stack (packages/explainer), built from a fixture (fixture.json,
3
+ // overview.json, sequence.json) and a read-only checkout of the repo.
4
+ //
5
+ // source: { fixture: <fixture dir>, repo: <git checkout>, scip?: <index.scip>, branch?: <ref the change lives on> }
6
+ import { execFile } from "node:child_process";
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { hubPath } from "../../hub-path.mjs";
10
+
11
+ // packages/explainer, resolved per call: eve bundles this module into the
12
+ // workspace's module cache, so import.meta.dirname isn't in the hub checkout.
13
+ const explainerDir = () => hubPath(join("packages", "explainer"), { probe: join("scripts", "build-data.mjs") });
14
+
15
+ // packages/explainer has its own lockfile, outside the hub's pnpm workspace,
16
+ // so the hub's install doesn't cover it. Say so up front rather than failing
17
+ // halfway through build-data on a missing import.
18
+ function explainerReady() {
19
+ const dir = explainerDir();
20
+ if (!existsSync(join(dir, "node_modules", "@sourcegraph", "scip-typescript"))) {
21
+ throw new Error(`the explainer's dependencies aren't installed: run \`pnpm install --ignore-workspace --frozen-lockfile\` in ${dir}`);
22
+ }
23
+ return dir;
24
+ }
25
+
26
+ const node = (script, args, dir = explainerDir()) => {
27
+ return new Promise((ok, fail) =>
28
+ execFile(process.execPath, [join(dir, "scripts", script), ...args], { cwd: dir, maxBuffer: 64 << 20, timeout: 900_000 }, (error, stdout, stderr) =>
29
+ error ? fail(new Error(`${script} failed: ${String(stderr || error.message).trim().split("\n").slice(-6).join("\n")}`)) : ok(String(stdout)),
30
+ ),
31
+ );
32
+ };
33
+
34
+ const git = (repo, ...args) =>
35
+ new Promise((ok, fail) => execFile("git", ["-C", repo, ...args], (error, stdout) => (error ? fail(error) : ok(String(stdout).trim()))));
36
+
37
+ const readJson = (path) => JSON.parse(readFileSync(path, "utf8"));
38
+
39
+ export function firstSentence(text = "") {
40
+ const sentence = String(text).trim().split(/(?<=[.!?])\s+(?=[A-Z"'`(])/, 1)[0] ?? "";
41
+ return sentence.length > 220 ? `${sentence.slice(0, 219).replace(/\s+\S*$/, "")}…` : sentence;
42
+ }
43
+
44
+ function checkSource(source) {
45
+ if (!source || typeof source !== "object") throw new Error("change-explainer source must be { fixture, repo, scip?, branch? }");
46
+ for (const key of ["fixture", "repo"]) if (typeof source[key] !== "string" || !existsSync(source[key])) throw new Error(`change-explainer source.${key}: no such path ${JSON.stringify(source[key])}`);
47
+ if (!existsSync(join(source.fixture, "fixture.json"))) throw new Error(`no fixture.json in ${source.fixture}`);
48
+ if (source.scip && !existsSync(source.scip)) throw new Error(`change-explainer source.scip: no such file ${source.scip}`);
49
+ }
50
+
51
+ // Card fields from the fixture: what the change is, and which commits.
52
+ export function cardOf(fixture, overview) {
53
+ const short = (sha) => String(sha ?? "").slice(0, 9);
54
+ const prs = (fixture.prs ?? []).map((p) => `#${p.number}`);
55
+ return {
56
+ title: fixture.title ?? fixture.id,
57
+ gist: firstSentence(overview?.thesis),
58
+ subtitle: [fixture.repo, prs.join(" ")].filter(Boolean).join(" "),
59
+ ref: `${short(fixture.base)}..${short(fixture.head)}`,
60
+ };
61
+ }
62
+
63
+ async function build(source, { work }) {
64
+ checkSource(source);
65
+ const fixture = readJson(join(source.fixture, "fixture.json"));
66
+ const overviewPath = join(source.fixture, "overview.json");
67
+ const overview = existsSync(overviewPath) ? readJson(overviewPath) : null;
68
+ const data = join(work, "data");
69
+ const site = join(work, "site");
70
+ const dir = explainerReady();
71
+ await node("build-data.mjs", ["--fixture", source.fixture, "--repo", source.repo, ...(source.scip ? ["--scip", source.scip] : []), "--out", data], dir);
72
+ await node("build.mjs", ["--out", site, "--data", data, "--fixture", fixture.id], dir);
73
+ const thumbnail = join(work, "thumbnail.png");
74
+ await node("thumbnail.mjs", [site, thumbnail], dir).catch(() => {});
75
+ const [base, head] = await Promise.all([git(source.repo, "rev-parse", `${fixture.base}^{commit}`), git(source.repo, "rev-parse", `${fixture.head}^{commit}`)]);
76
+ return {
77
+ site,
78
+ thumbnail: existsSync(thumbnail) ? thumbnail : undefined,
79
+ card: cardOf(fixture, overview),
80
+ meta: { repo: fixture.repo, base, head, prs: (fixture.prs ?? []).map((p) => p.number) },
81
+ };
82
+ }
83
+
84
+ // Whether the published version still describes the change. This checks the
85
+ // pinned range against the fixture and, with source.branch, the branch head;
86
+ // which parts went stale (snippet hashes, re-anchoring) is the next step.
87
+ async function status(record) {
88
+ const { source = {}, meta = {} } = record;
89
+ const reasons = [];
90
+ if (record.status === "merged" || record.status === "closed") return { status: record.status, reasons };
91
+ try {
92
+ const fixture = readJson(join(source.fixture, "fixture.json"));
93
+ const [base, head] = await Promise.all([git(source.repo, "rev-parse", `${fixture.base}^{commit}`), git(source.repo, "rev-parse", `${fixture.head}^{commit}`)]);
94
+ if (base !== meta.base) reasons.push(`the fixture's base is now ${base.slice(0, 9)} (published at ${String(meta.base).slice(0, 9)})`);
95
+ if (head !== meta.head) reasons.push(`the fixture's head is now ${head.slice(0, 9)} (published at ${String(meta.head).slice(0, 9)})`);
96
+ if (source.branch) {
97
+ const tip = await git(source.repo, "rev-parse", `${source.branch}^{commit}`);
98
+ if (tip !== meta.head) reasons.push(`${source.branch} is at ${tip.slice(0, 9)}, ahead of the published head ${String(meta.head).slice(0, 9)}`);
99
+ }
100
+ } catch (error) {
101
+ reasons.push(`couldn't read the source: ${error.message}`);
102
+ }
103
+ return { status: reasons.length ? "stale" : "fresh", reasons };
104
+ }
105
+
106
+ export default { name: "change-explainer", build, status };