@cursor/july 0.1.22 → 0.1.24

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 (219) hide show
  1. package/README.md +5 -5
  2. package/dist/bin/agent-serve.d.ts +1 -0
  3. package/dist/bin/agent-serve.d.ts.map +1 -1
  4. package/dist/bin/agent-serve.js +21 -3
  5. package/dist/docs/404.html +2 -2
  6. package/dist/docs/ab.html +3 -3
  7. package/dist/docs/assets/{app.BKNKMLp4.js → app.CvSGaAxk.js} +1 -1
  8. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  9. package/dist/docs/assets/chunks/{VPLocalSearchBox.sOSfEZR6.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  10. package/dist/docs/assets/chunks/{theme.BvCHT5lj.js → theme.C7vfzr7h.js} +2 -2
  11. package/dist/docs/assets/index.md.Dfv5ic9t.js +20 -0
  12. package/dist/docs/assets/{index.md.t0TM2Qzz.lean.js → index.md.Dfv5ic9t.lean.js} +1 -1
  13. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.js → reference_cli.md.ccoKOoXt.js} +4 -3
  14. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.lean.js → reference_cli.md.ccoKOoXt.lean.js} +1 -1
  15. package/dist/docs/building-with-agents.html +3 -3
  16. package/dist/docs/concepts.html +3 -3
  17. package/dist/docs/deployment.html +3 -3
  18. package/dist/docs/evals.html +3 -3
  19. package/dist/docs/example-agents/approval-buddy.html +3 -3
  20. package/dist/docs/example-agents/benny.html +3 -3
  21. package/dist/docs/example-agents/bugbot.html +3 -3
  22. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  23. package/dist/docs/example-agents/codeowners-review.html +3 -3
  24. package/dist/docs/example-agents/concierge.html +3 -3
  25. package/dist/docs/example-agents/fsd.html +3 -3
  26. package/dist/docs/example-agents/index.html +3 -3
  27. package/dist/docs/example-agents/knowledge-base.html +3 -3
  28. package/dist/docs/example-agents/oncall.html +3 -3
  29. package/dist/docs/example-agents/security-reviewer.html +3 -3
  30. package/dist/docs/example-agents/slack-agent.html +3 -3
  31. package/dist/docs/example-agents/weather-agent.html +3 -3
  32. package/dist/docs/guides/agent-to-agent.html +3 -3
  33. package/dist/docs/guides/cloud-runtime.html +3 -3
  34. package/dist/docs/guides/github.html +3 -3
  35. package/dist/docs/guides/human-in-the-loop.html +3 -3
  36. package/dist/docs/guides/mcp-oauth.html +3 -3
  37. package/dist/docs/guides/slack.html +3 -3
  38. package/dist/docs/guides/webhooks.html +3 -3
  39. package/dist/docs/hashmap.json +1 -1
  40. package/dist/docs/hillclimbing.html +3 -3
  41. package/dist/docs/index.html +6 -6
  42. package/dist/docs/quickstart.html +3 -3
  43. package/dist/docs/reference/agent-config.html +3 -3
  44. package/dist/docs/reference/channels.html +3 -3
  45. package/dist/docs/reference/cli.html +7 -6
  46. package/dist/docs/reference/connections.html +3 -3
  47. package/dist/docs/reference/hooks.html +3 -3
  48. package/dist/docs/reference/http-api.html +3 -3
  49. package/dist/docs/reference/instructions.html +3 -3
  50. package/dist/docs/reference/playground.html +3 -3
  51. package/dist/docs/reference/project-layout.html +3 -3
  52. package/dist/docs/reference/prompt.html +3 -3
  53. package/dist/docs/reference/schedules.html +3 -3
  54. package/dist/docs/reference/sessions.html +3 -3
  55. package/dist/docs/reference/skills.html +3 -3
  56. package/dist/docs/reference/subagents.html +3 -3
  57. package/dist/docs/reference/tools.html +3 -3
  58. package/dist/docs/scaffolding-agents.html +3 -3
  59. package/dist/docs/storage.html +3 -3
  60. package/dist/docs/troubleshooting.html +3 -3
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +1 -0
  64. package/dist/internal/cli-docs.d.ts +34 -0
  65. package/dist/internal/cli-docs.d.ts.map +1 -0
  66. package/dist/internal/cli-docs.js +162 -0
  67. package/dist/internal/distribution.d.ts +2 -1
  68. package/dist/internal/distribution.d.ts.map +1 -1
  69. package/dist/internal/distribution.js +3 -1
  70. package/dist/internal/docs-site.d.ts +4 -2
  71. package/dist/internal/docs-site.d.ts.map +1 -1
  72. package/dist/internal/docs-site.js +15 -11
  73. package/dist/internal/init-project.d.ts.map +1 -1
  74. package/dist/internal/init-project.js +19 -0
  75. package/dist/internal/session-engine.d.ts.map +1 -1
  76. package/dist/internal/session-engine.js +5 -0
  77. package/dist/internal/workspace.d.ts +9 -0
  78. package/dist/internal/workspace.d.ts.map +1 -1
  79. package/dist/internal/workspace.js +52 -5
  80. package/dist/memory.d.ts +79 -0
  81. package/dist/memory.d.ts.map +1 -0
  82. package/dist/memory.js +164 -0
  83. package/dist/playground/assets/index-CidizGZv.css +1 -0
  84. package/dist/playground/assets/index-DTG9OsPV.js +85 -0
  85. package/dist/playground/index.html +2 -2
  86. package/dist/types.d.ts +11 -0
  87. package/dist/types.d.ts.map +1 -1
  88. package/docs/README.md +8 -1
  89. package/docs/reference/cli.md +20 -4
  90. package/package.json +32 -24
  91. package/src/bin/agent-serve.ts +23 -3
  92. package/src/index.ts +2 -0
  93. package/src/internal/cli-docs.ts +191 -0
  94. package/src/internal/distribution.ts +3 -1
  95. package/src/internal/docs-site.ts +19 -11
  96. package/src/internal/init-project.ts +22 -0
  97. package/src/internal/session-engine.ts +5 -0
  98. package/src/internal/workspace.ts +81 -5
  99. package/src/memory.ts +215 -0
  100. package/src/types.ts +11 -0
  101. package/dist/channels/github/instrument.d.ts +0 -20
  102. package/dist/channels/github/instrument.d.ts.map +0 -1
  103. package/dist/docs/assets/chunks/@localSearchIndexroot.YFE6WoMB.js +0 -1
  104. package/dist/docs/assets/index.md.t0TM2Qzz.js +0 -20
  105. package/dist/internal/json-dir-store.d.ts +0 -32
  106. package/dist/internal/json-dir-store.d.ts.map +0 -1
  107. package/dist/internal/json-dir-store.js +0 -100
  108. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  109. package/dist/playground/assets/index-dshZQJCp.js +0 -85
  110. package/src/bin/agent-serve.version.test.ts +0 -62
  111. package/src/channels/github/api.test.ts +0 -64
  112. package/src/channels/github/auth.test.ts +0 -105
  113. package/src/channels/github/cursor-account.test.ts +0 -204
  114. package/src/channels/github/forward.test.ts +0 -457
  115. package/src/channels/github/github.test.ts +0 -937
  116. package/src/channels/github/replay.test.ts +0 -179
  117. package/src/channels/slack/api.post-message.test.ts +0 -148
  118. package/src/channels/slack/approvals.test.ts +0 -328
  119. package/src/channels/slack/block-actions.test.ts +0 -452
  120. package/src/channels/slack/bot-mentions.test.ts +0 -267
  121. package/src/channels/slack/channel-watch.test.ts +0 -363
  122. package/src/channels/slack/cursor-account.test.ts +0 -253
  123. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  124. package/src/channels/slack/dispatch.test.ts +0 -795
  125. package/src/channels/slack/eval-directive.test.ts +0 -273
  126. package/src/channels/slack/message-body.test.ts +0 -54
  127. package/src/channels/slack/nudge-store.test.ts +0 -143
  128. package/src/channels/slack/slack.test.ts +0 -391
  129. package/src/channels/slack/stop.test.ts +0 -23
  130. package/src/channels/slack/thread-context.test.ts +0 -202
  131. package/src/evals/assertions.test.ts +0 -580
  132. package/src/evals/expect.test.ts +0 -144
  133. package/src/evals/judge.test.ts +0 -181
  134. package/src/evals/loaders.test.ts +0 -132
  135. package/src/evals/matchers.test.ts +0 -95
  136. package/src/evals/reporters.test.ts +0 -303
  137. package/src/evals/run-facts.test.ts +0 -259
  138. package/src/internal/ab-snapshot.test.ts +0 -325
  139. package/src/internal/approval-gate.test.ts +0 -49
  140. package/src/internal/approvals.integration.test.ts +0 -383
  141. package/src/internal/authored-loaders.test.ts +0 -31
  142. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  143. package/src/internal/channel-route-schema.test.ts +0 -294
  144. package/src/internal/chat-attach.test.ts +0 -262
  145. package/src/internal/cli-deploy.test.ts +0 -1991
  146. package/src/internal/cli-mcp.test.ts +0 -789
  147. package/src/internal/cli-skills.test.ts +0 -133
  148. package/src/internal/cli-slack.test.ts +0 -1647
  149. package/src/internal/cloud-merge.test.ts +0 -74
  150. package/src/internal/cron.test.ts +0 -22
  151. package/src/internal/cursor/account-mcp.test.ts +0 -807
  152. package/src/internal/cursor/backend-client.test.ts +0 -591
  153. package/src/internal/cursor/credentials.test.ts +0 -351
  154. package/src/internal/cursor/github-credentials.test.ts +0 -136
  155. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  156. package/src/internal/cursor-account.integration.test.ts +0 -441
  157. package/src/internal/cursor-event-relay.test.ts +0 -746
  158. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  159. package/src/internal/cursor-slack-relay.test.ts +0 -525
  160. package/src/internal/deploy-source.test.ts +0 -111
  161. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  162. package/src/internal/discovery.concurrency.test.ts +0 -60
  163. package/src/internal/discovery.cursor-account.test.ts +0 -133
  164. package/src/internal/discovery.cwd.test.ts +0 -83
  165. package/src/internal/discovery.hosting.test.ts +0 -80
  166. package/src/internal/discovery.identity.test.ts +0 -44
  167. package/src/internal/docs-site.test.ts +0 -66
  168. package/src/internal/duration.test.ts +0 -29
  169. package/src/internal/eval-judge-model.test.ts +0 -187
  170. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  171. package/src/internal/eval-run-store.storage.test.ts +0 -211
  172. package/src/internal/eval-runner.http.test.ts +0 -403
  173. package/src/internal/eval-runner.run.test.ts +0 -928
  174. package/src/internal/evals-client.test.ts +0 -307
  175. package/src/internal/event-mapper.test.ts +0 -243
  176. package/src/internal/github-fanout.test.ts +0 -213
  177. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  178. package/src/internal/host-kv.test.ts +0 -82
  179. package/src/internal/host-platforms.test.ts +0 -126
  180. package/src/internal/http-channel.test.ts +0 -402
  181. package/src/internal/init-project.test.ts +0 -269
  182. package/src/internal/install-cursor-skills.test.ts +0 -262
  183. package/src/internal/local-env.test.ts +0 -120
  184. package/src/internal/log-ring.test.ts +0 -31
  185. package/src/internal/logs-client.test.ts +0 -350
  186. package/src/internal/mcp-endpoint.test.ts +0 -436
  187. package/src/internal/mcp-host.test.ts +0 -298
  188. package/src/internal/mcp-oauth.test.ts +0 -148
  189. package/src/internal/net.test.ts +0 -17
  190. package/src/internal/peer-connections.test.ts +0 -128
  191. package/src/internal/peer-mcp.integration.test.ts +0 -289
  192. package/src/internal/playground/toolchain.test.ts +0 -53
  193. package/src/internal/playground-cli.test.ts +0 -187
  194. package/src/internal/playground-proxy.test.ts +0 -376
  195. package/src/internal/prompt-context.integration.test.ts +0 -232
  196. package/src/internal/prompt-context.test.ts +0 -127
  197. package/src/internal/reminder-runner.test.ts +0 -390
  198. package/src/internal/reminder-store.test.ts +0 -53
  199. package/src/internal/request-headers.test.ts +0 -27
  200. package/src/internal/resolve-prod-target.test.ts +0 -787
  201. package/src/internal/resolved-connections.test.ts +0 -295
  202. package/src/internal/router.test.ts +0 -57
  203. package/src/internal/sdk-runner.test.ts +0 -290
  204. package/src/internal/session-engine.coalesce.test.ts +0 -169
  205. package/src/internal/session-engine.concurrency.test.ts +0 -250
  206. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  207. package/src/internal/session-engine.interrupt.test.ts +0 -577
  208. package/src/internal/session-engine.storage.test.ts +0 -547
  209. package/src/internal/session-urls.test.ts +0 -28
  210. package/src/internal/sessions-client.test.ts +0 -518
  211. package/src/internal/storage-coordinator.test.ts +0 -517
  212. package/src/internal/tool-call.test.ts +0 -458
  213. package/src/internal/tool-result.test.ts +0 -52
  214. package/src/internal/trajectory.approvals.test.ts +0 -83
  215. package/src/internal/trajectory.subagents.test.ts +0 -198
  216. package/src/internal/turn-governor.test.ts +0 -137
  217. package/src/internal/update-check.test.ts +0 -485
  218. package/src/internal/workspace.test.ts +0 -81
  219. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,213 +0,0 @@
1
- import { createHmac } from "node:crypto";
2
- import { createServer, type IncomingMessage, type Server } from "node:http";
3
- import type { AddressInfo } from "node:net";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import type { GitHubForwardTarget } from "../channels/github/forward.js";
6
- import { fanoutDelivery, startFanoutServer } from "./github-fanout.js";
7
-
8
- interface Captured {
9
- method: string;
10
- headers: IncomingMessage["headers"];
11
- body: string;
12
- }
13
-
14
- /** A stand-in GitHub channel that records the requests it receives. */
15
- function recordingServer(): Promise<{
16
- url: string;
17
- received: Captured[];
18
- close: () => void;
19
- }> {
20
- const received: Captured[] = [];
21
- const server: Server = createServer((req, res) => {
22
- const chunks: Buffer[] = [];
23
- req.on("data", (chunk: Buffer) => chunks.push(chunk));
24
- req.on("end", () => {
25
- received.push({
26
- method: req.method ?? "",
27
- headers: req.headers,
28
- body: Buffer.concat(chunks).toString("utf8"),
29
- });
30
- res.writeHead(200, { "content-type": "application/json" });
31
- res.end(JSON.stringify({ ok: true }));
32
- });
33
- });
34
- return new Promise((resolve) => {
35
- server.listen(0, "127.0.0.1", () => {
36
- const { port } = server.address() as AddressInfo;
37
- resolve({
38
- url: `http://127.0.0.1:${port}`,
39
- received,
40
- close: () => server.close(),
41
- });
42
- });
43
- });
44
- }
45
-
46
- const cleanups: Array<() => void> = [];
47
- afterEach(() => {
48
- for (const cleanup of cleanups.splice(0)) {
49
- cleanup();
50
- }
51
- });
52
-
53
- describe("fanoutDelivery", () => {
54
- it("re-posts the raw body + signature to every matching channel", async () => {
55
- const a = await recordingServer();
56
- const b = await recordingServer();
57
- cleanups.push(a.close, b.close);
58
-
59
- const targets: GitHubForwardTarget[] = [
60
- {
61
- slug: "fsd",
62
- channelId: "github",
63
- url: a.url,
64
- events: ["pull_request"],
65
- },
66
- {
67
- slug: "reviewer",
68
- channelId: "github",
69
- url: b.url,
70
- events: ["pull_request"],
71
- },
72
- ];
73
-
74
- const body = Buffer.from(JSON.stringify({ action: "opened" }));
75
- const signature = `sha256=${createHmac("sha256", "s3cr3t").update(body).digest("hex")}`;
76
- const delivered = await fanoutDelivery(
77
- body,
78
- {
79
- "content-type": "application/json",
80
- "x-github-event": "pull_request",
81
- "x-hub-signature-256": signature,
82
- },
83
- targets,
84
- { logger: () => {} }
85
- );
86
-
87
- expect(delivered.sort()).toEqual(["fsd/github", "reviewer/github"]);
88
- for (const server of [a, b]) {
89
- expect(server.received).toHaveLength(1);
90
- expect(server.received[0]?.body).toBe(body.toString("utf8"));
91
- expect(server.received[0]?.headers["x-hub-signature-256"]).toBe(
92
- signature
93
- );
94
- expect(server.received[0]?.headers["x-github-event"]).toBe(
95
- "pull_request"
96
- );
97
- }
98
- });
99
-
100
- it("delivers only to channels whose event set matches", async () => {
101
- const fsd = await recordingServer();
102
- const reviewer = await recordingServer();
103
- cleanups.push(fsd.close, reviewer.close);
104
-
105
- const targets: GitHubForwardTarget[] = [
106
- {
107
- slug: "fsd",
108
- channelId: "github",
109
- url: fsd.url,
110
- events: ["pull_request", "check_run"],
111
- },
112
- {
113
- slug: "reviewer",
114
- channelId: "github",
115
- url: reviewer.url,
116
- events: ["pull_request"],
117
- },
118
- ];
119
-
120
- const delivered = await fanoutDelivery(
121
- Buffer.from("{}"),
122
- { "x-github-event": "check_run" },
123
- targets,
124
- { logger: () => {} }
125
- );
126
-
127
- expect(delivered).toEqual(["fsd/github"]);
128
- expect(fsd.received).toHaveLength(1);
129
- expect(reviewer.received).toHaveLength(0);
130
- });
131
-
132
- it("does not count HTTP error responses as delivered", async () => {
133
- const ok = await recordingServer();
134
- const failing = createServer((req, res) => {
135
- const chunks: Buffer[] = [];
136
- req.on("data", (chunk: Buffer) => chunks.push(chunk));
137
- req.on("end", () => {
138
- res.writeHead(500);
139
- res.end("error");
140
- });
141
- });
142
- await new Promise<void>((resolve) => {
143
- failing.listen(0, "127.0.0.1", () => resolve());
144
- });
145
- const failingPort = (failing.address() as AddressInfo).port;
146
- cleanups.push(ok.close, () => failing.close());
147
-
148
- const targets: GitHubForwardTarget[] = [
149
- {
150
- slug: "ok",
151
- channelId: "github",
152
- url: ok.url,
153
- events: ["pull_request"],
154
- },
155
- {
156
- slug: "bad",
157
- channelId: "github",
158
- url: `http://127.0.0.1:${failingPort}`,
159
- events: ["pull_request"],
160
- },
161
- ];
162
-
163
- const delivered = await fanoutDelivery(
164
- Buffer.from("{}"),
165
- { "x-github-event": "pull_request" },
166
- targets,
167
- { logger: () => {} }
168
- );
169
-
170
- expect(delivered).toEqual(["ok/github"]);
171
- expect(ok.received).toHaveLength(1);
172
- });
173
- });
174
-
175
- describe("startFanoutServer", () => {
176
- it("proxies a POST through to matching channels", async () => {
177
- const channel = await recordingServer();
178
- cleanups.push(channel.close);
179
-
180
- const proxy = await startFanoutServer(
181
- [
182
- {
183
- slug: "fsd",
184
- channelId: "github",
185
- url: channel.url,
186
- events: ["pull_request"],
187
- },
188
- ],
189
- { logger: () => {} }
190
- );
191
- cleanups.push(proxy.close);
192
-
193
- const response = await fetch(proxy.url, {
194
- method: "POST",
195
- headers: {
196
- "content-type": "application/json",
197
- "x-github-event": "pull_request",
198
- },
199
- body: JSON.stringify({ action: "synchronize" }),
200
- });
201
- const result = (await response.json()) as {
202
- ok: boolean;
203
- delivered: string[];
204
- };
205
-
206
- expect(response.status).toBe(200);
207
- expect(result).toEqual({ ok: true, delivered: ["fsd/github"] });
208
- expect(channel.received).toHaveLength(1);
209
- expect(channel.received[0]?.body).toBe(
210
- JSON.stringify({ action: "synchronize" })
211
- );
212
- });
213
- });
@@ -1,179 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { githubChannel } from "../channels/github/github-channel.js";
3
- import type {
4
- ChannelHandlerArgs,
5
- ChannelSession,
6
- SendMessageFn,
7
- } from "../types.js";
8
- import {
9
- collectGitHubTriggerTargets,
10
- handleAgentServeTrigger,
11
- } from "./handleAgentServeTrigger.js";
12
-
13
- describe("handleAgentServeTrigger", () => {
14
- it("fans out a pull_request delivery to every github channel target", async () => {
15
- const sendA = vi.fn<SendMessageFn>(async () => fakeSession("a"));
16
- const sendB = vi.fn<SendMessageFn>(async () => fakeSession("b"));
17
-
18
- const channelA = githubChannel({
19
- auth: [],
20
- onPullRequest: (ctx) => ({
21
- auth: {
22
- authenticator: "github-webhook",
23
- principalId: ctx.senderLogin ?? "github",
24
- principalType: "user",
25
- },
26
- }),
27
- });
28
- const channelB = githubChannel({
29
- auth: [],
30
- onPullRequest: () => null,
31
- });
32
- const buildSecurityReviewerArgs = vi.fn(() => handlerArgs(sendA));
33
-
34
- const targets = collectGitHubTriggerTargets({
35
- mounts: [
36
- {
37
- slug: "security-reviewer",
38
- channels: [{ id: "reviewer", definition: channelA }],
39
- buildHandlerArgs: buildSecurityReviewerArgs,
40
- },
41
- {
42
- slug: "fsd",
43
- channels: [{ id: "github", definition: channelB }],
44
- buildHandlerArgs: () => handlerArgs(sendB),
45
- },
46
- {
47
- slug: "weather-agent",
48
- channels: [],
49
- buildHandlerArgs: () => handlerArgs(vi.fn()),
50
- },
51
- ],
52
- });
53
-
54
- expect(targets.map((t) => t.slug)).toEqual(["security-reviewer", "fsd"]);
55
- expect(buildSecurityReviewerArgs).toHaveBeenCalledWith("reviewer");
56
-
57
- const result = await handleAgentServeTrigger({
58
- type: "github",
59
- bodyText: JSON.stringify(pullRequestPayload()),
60
- eventName: "pull_request",
61
- deliveryId: "delivery-1",
62
- targets,
63
- });
64
-
65
- expect(result.ok).toBe(true);
66
- expect(result.targets).toHaveLength(2);
67
- expect(result.targets[0]?.slug).toBe("security-reviewer");
68
- expect(result.targets[0]?.status).toBe(200);
69
- expect(result.targets[1]?.slug).toBe("fsd");
70
- expect(result.targets[1]?.body).toMatchObject({
71
- ok: true,
72
- skipped: true,
73
- reason: "not_dispatched",
74
- });
75
- expect(sendA).toHaveBeenCalledOnce();
76
- expect(sendB).not.toHaveBeenCalled();
77
- });
78
-
79
- it("rejects invalid JSON without dispatching", async () => {
80
- const result = await handleAgentServeTrigger({
81
- type: "github",
82
- bodyText: "not-json",
83
- eventName: "pull_request",
84
- targets: [],
85
- });
86
- expect(result.ok).toBe(false);
87
- expect(result.targets[0]?.status).toBe(400);
88
- });
89
- });
90
-
91
- function handlerArgs(send: SendMessageFn): ChannelHandlerArgs {
92
- return {
93
- params: {},
94
- requestIp: "127.0.0.1",
95
- auth: null,
96
- host: {
97
- mcp: {
98
- names: () => [],
99
- listTools: async () => [],
100
- callTool: async () => ({ content: [] }),
101
- },
102
- github: {
103
- getOctokit: async () => {
104
- throw new Error("github client not configured in test");
105
- },
106
- },
107
- slack: {
108
- getClient: async () => {
109
- throw new Error("slack client not configured in test");
110
- },
111
- },
112
- kv: {
113
- get: async () => undefined,
114
- put: async () => {},
115
- delete: async () => {},
116
- },
117
- },
118
- send,
119
- getSession: async () => null,
120
- receive: async () => fakeSession("recv"),
121
- callTool: async (toolName) => ({
122
- toolName,
123
- callId: "call-1",
124
- isError: false,
125
- result: null,
126
- durationMs: 0,
127
- }),
128
- waitUntil: () => {},
129
- sessionUrls: () => ({
130
- playgroundUrl: "http://127.0.0.1:3000/playground",
131
- traceUrl: "http://127.0.0.1:3000/v1/session/x/events",
132
- }),
133
- };
134
- }
135
-
136
- function fakeSession(id: string): ChannelSession {
137
- return {
138
- id,
139
- isNew: true,
140
- continuationToken: `github-pr:acme/widgets#42:${id}`,
141
- info: {
142
- id,
143
- channelId: "github",
144
- mode: "chat",
145
- auth: null,
146
- sdkAgentId: undefined,
147
- title: "GitHub acme/widgets#42",
148
- },
149
- getEventStream: async () => new ReadableStream<Uint8Array>(),
150
- waitForCompletion: async () => ({ status: "finished", result: "done" }),
151
- setContinuationToken: async () => {},
152
- };
153
- }
154
-
155
- function pullRequestPayload(): Record<string, unknown> {
156
- return {
157
- action: "opened",
158
- repository: {
159
- full_name: "acme/widgets",
160
- html_url: "https://github.com/acme/widgets",
161
- },
162
- pull_request: {
163
- number: 42,
164
- html_url: "https://github.com/acme/widgets/pull/42",
165
- title: "Add widgets",
166
- body: "PR body",
167
- draft: false,
168
- user: { login: "octocat" },
169
- head: {
170
- ref: "feature/widgets",
171
- sha: "abc123",
172
- },
173
- base: {
174
- ref: "main",
175
- },
176
- },
177
- sender: { login: "sender" },
178
- };
179
- }
@@ -1,82 +0,0 @@
1
- import { mkdtemp, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import { defineStorage, storageKeys } from "../storage.js";
6
- import { createHostKvApi } from "./host-kv.js";
7
- import { StorageCoordinator } from "./storage-coordinator.js";
8
-
9
- describe("createHostKvApi", () => {
10
- const dirs: string[] = [];
11
-
12
- afterEach(async () => {
13
- await Promise.all(
14
- dirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true }))
15
- );
16
- });
17
-
18
- async function tempDir(): Promise<string> {
19
- const dir = await mkdtemp(join(tmpdir(), "agentkit-host-kv-"));
20
- dirs.push(dir);
21
- return dir;
22
- }
23
-
24
- it("falls back to state-root files when defineStorage is absent", async () => {
25
- const stateRoot = await tempDir();
26
- const kv = createHostKvApi({ agentName: "jenny", stateRoot });
27
-
28
- expect(await kv.get("alert-memory/a")).toBeUndefined();
29
- await kv.put("alert-memory/a", { class: "monitor:1", updated: "t" });
30
- expect(await kv.get("alert-memory/a")).toEqual({
31
- class: "monitor:1",
32
- updated: "t",
33
- });
34
- await kv.delete("alert-memory/a");
35
- expect(await kv.get("alert-memory/a")).toBeUndefined();
36
- });
37
-
38
- it("uses defineStorage under storageKeys.kv when get is present", async () => {
39
- const stateRoot = await tempDir();
40
- const store = new Map<string, unknown>();
41
- const coordinator = new StorageCoordinator({
42
- definition: defineStorage({
43
- put: (key, value) => {
44
- store.set(key, value);
45
- },
46
- get: (key) => store.get(key) as never,
47
- delete: (key) => {
48
- store.delete(key);
49
- },
50
- list: (prefix) =>
51
- [...store.entries()]
52
- .filter(([key]) => key.startsWith(prefix))
53
- .map(([key, value]) => ({ key, value: value as never }))
54
- .sort((a, b) => a.key.localeCompare(b.key)),
55
- }),
56
- agentName: "jenny",
57
- projectRoot: stateRoot,
58
- logger: () => {},
59
- });
60
- const kv = createHostKvApi({
61
- agentName: "jenny",
62
- stateRoot,
63
- storage: coordinator,
64
- });
65
-
66
- await kv.put("alert-memory/x", { ok: true });
67
- expect(store.get(storageKeys.kv("jenny", "alert-memory/x"))).toEqual({
68
- ok: true,
69
- });
70
- expect(await kv.get("alert-memory/x")).toEqual({ ok: true });
71
- await kv.delete("alert-memory/x");
72
- expect(store.has(storageKeys.kv("jenny", "alert-memory/x"))).toBe(false);
73
- });
74
-
75
- it("rejects empty keys", async () => {
76
- const kv = createHostKvApi({
77
- agentName: "jenny",
78
- stateRoot: await tempDir(),
79
- });
80
- await expect(kv.get(" ")).rejects.toThrow(/non-empty/);
81
- });
82
- });
@@ -1,126 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const tryResolveGhAuthToken = vi.hoisted(() => vi.fn());
4
- const hasGitHubAppCredentials = vi.hoisted(() => vi.fn());
5
- const resolveGitHubInstallationId = vi.hoisted(() => vi.fn());
6
- const ensureGhCliTokenEnv = vi.hoisted(() => vi.fn());
7
-
8
- vi.mock("../channels/github/auth.js", async (importOriginal) => {
9
- const actual =
10
- await importOriginal<typeof import("../channels/github/auth.js")>();
11
- return {
12
- ...actual,
13
- tryResolveGhAuthToken,
14
- hasGitHubAppCredentials,
15
- resolveGitHubInstallationId,
16
- ensureGhCliTokenEnv,
17
- };
18
- });
19
-
20
- import { clearGitHubAuthCaches } from "../channels/github/auth.js";
21
- import {
22
- resolveHostGitHubAuthSource,
23
- warmupHostGitHubAuth,
24
- } from "./host-platforms.js";
25
-
26
- describe("host GitHub auth warmup", () => {
27
- beforeEach(() => {
28
- clearGitHubAuthCaches();
29
- tryResolveGhAuthToken.mockReset();
30
- hasGitHubAppCredentials.mockReset();
31
- resolveGitHubInstallationId.mockReset();
32
- ensureGhCliTokenEnv.mockReset();
33
- hasGitHubAppCredentials.mockResolvedValue(false);
34
- resolveGitHubInstallationId.mockResolvedValue(undefined);
35
- ensureGhCliTokenEnv.mockResolvedValue(false);
36
- delete process.env.GITHUB_TOKEN;
37
- delete process.env.GH_TOKEN;
38
- });
39
-
40
- afterEach(() => {
41
- clearGitHubAuthCaches();
42
- tryResolveGhAuthToken.mockReset();
43
- hasGitHubAppCredentials.mockReset();
44
- resolveGitHubInstallationId.mockReset();
45
- ensureGhCliTokenEnv.mockReset();
46
- delete process.env.GITHUB_TOKEN;
47
- delete process.env.GH_TOKEN;
48
- });
49
-
50
- it("prefers App installation auth over env PAT", async () => {
51
- process.env.GITHUB_TOKEN = "env-token";
52
- hasGitHubAppCredentials.mockResolvedValue(true);
53
- resolveGitHubInstallationId.mockResolvedValue(42);
54
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("app");
55
- expect(tryResolveGhAuthToken).not.toHaveBeenCalled();
56
- });
57
-
58
- it("prefers env over gh when App creds are unset", async () => {
59
- process.env.GITHUB_TOKEN = "env-token";
60
- tryResolveGhAuthToken.mockResolvedValue("gh-token");
61
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("env");
62
- expect(tryResolveGhAuthToken).not.toHaveBeenCalled();
63
- });
64
-
65
- it("falls back to gh auth token", async () => {
66
- tryResolveGhAuthToken.mockResolvedValue("gh-token");
67
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("gh");
68
- expect(tryResolveGhAuthToken).toHaveBeenCalledOnce();
69
- });
70
-
71
- it("reports unavailable when neither App, env, nor gh works", async () => {
72
- tryResolveGhAuthToken.mockResolvedValue(undefined);
73
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("unavailable");
74
- });
75
-
76
- it("logs and primes Octokit on successful warmup", async () => {
77
- process.env.GITHUB_TOKEN = "env-token";
78
- const lines: string[] = [];
79
- const getOctokit = vi.fn(async () => ({ ok: true }) as never);
80
- await expect(
81
- warmupHostGitHubAuth({
82
- logger: (line) => lines.push(line),
83
- github: { getOctokit },
84
- })
85
- ).resolves.toBe("env");
86
- expect(getOctokit).toHaveBeenCalledOnce();
87
- expect(lines.some((line) => line.includes("GITHUB_TOKEN/GH_TOKEN"))).toBe(
88
- true
89
- );
90
- });
91
-
92
- it("warns without failing when auth is unavailable", async () => {
93
- tryResolveGhAuthToken.mockResolvedValue(undefined);
94
- const lines: string[] = [];
95
- const getOctokit = vi.fn(async () => {
96
- throw new Error("should not be called");
97
- });
98
- await expect(
99
- warmupHostGitHubAuth({
100
- logger: (line) => lines.push(line),
101
- github: { getOctokit },
102
- })
103
- ).resolves.toBe("unavailable");
104
- expect(getOctokit).not.toHaveBeenCalled();
105
- expect(ensureGhCliTokenEnv).not.toHaveBeenCalled();
106
- expect(lines.some((line) => line.includes("unavailable"))).toBe(true);
107
- });
108
-
109
- it("exports GH_TOKEN for gh CLI when App auth is configured", async () => {
110
- hasGitHubAppCredentials.mockResolvedValue(true);
111
- resolveGitHubInstallationId.mockResolvedValue(42);
112
- ensureGhCliTokenEnv.mockResolvedValue(true);
113
- const lines: string[] = [];
114
- const getOctokit = vi.fn(async () => ({ ok: true }) as never);
115
- await expect(
116
- warmupHostGitHubAuth({
117
- logger: (line) => lines.push(line),
118
- github: { getOctokit },
119
- })
120
- ).resolves.toBe("app");
121
- expect(ensureGhCliTokenEnv).toHaveBeenCalledOnce();
122
- expect(
123
- lines.some((line) => line.includes("exported as GH_TOKEN for gh CLI"))
124
- ).toBe(true);
125
- });
126
- });