@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,383 +0,0 @@
1
- /**
2
- * Integration: mock AgentRunner parks on needsApproval; resolve unblocks.
3
- */
4
-
5
- import { mkdtemp, rm } from "node:fs/promises";
6
- import { tmpdir } from "node:os";
7
- import { join } from "node:path";
8
- import { afterEach, describe, expect, it } from "vitest";
9
- import { httpChannel } from "../channels.js";
10
- import { defineTool } from "../tools.js";
11
- import type { AgentProject, RunnerTurnRequest, ToolContext } from "../types.js";
12
- import type { AgentRunner } from "./sdk-runner.js";
13
- import { SessionAuthError, SessionEngine } from "./session-engine.js";
14
-
15
- function makeHitlProject(executeFlag: { called: boolean }): AgentProject {
16
- const definition = defineTool({
17
- description: "A risky tool that needs approval",
18
- needsApproval: true,
19
- async execute(input: { note?: string }, _ctx: ToolContext) {
20
- executeFlag.called = true;
21
- return { ok: true, note: input.note ?? "" };
22
- },
23
- });
24
-
25
- return {
26
- rootDir: "/tmp/hitl-fixture",
27
- agentDir: "/tmp/hitl-fixture/agent",
28
- name: "hitl-fixture",
29
- agent: {
30
- name: "hitl-fixture",
31
- runtime: "local",
32
- tools: [
33
- {
34
- name: "risky_action",
35
- description: definition.description,
36
- execution: "server",
37
- needsApproval: true,
38
- inputSchema: {
39
- type: "object",
40
- properties: { note: { type: "string" } },
41
- additionalProperties: false,
42
- },
43
- definition,
44
- },
45
- ],
46
- skills: [],
47
- connections: [],
48
- subagents: [],
49
- seedFiles: [],
50
- },
51
- httpChannel: httpChannel(),
52
- channels: [],
53
- schedules: [],
54
- hooks: [],
55
- abs: [],
56
- diagnostics: [],
57
- };
58
- }
59
-
60
- describe("human-in-the-loop approvals (integration)", () => {
61
- let stateRoot: string | undefined;
62
-
63
- afterEach(async () => {
64
- if (stateRoot !== undefined) {
65
- await rm(stateRoot, { recursive: true, force: true });
66
- stateRoot = undefined;
67
- }
68
- });
69
-
70
- it("parks risky_action until approve, then finishes the turn", async () => {
71
- stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-hitl-"));
72
- const executeFlag = { called: false };
73
- const project = makeHitlProject(executeFlag);
74
-
75
- const runner: AgentRunner = {
76
- async runTurn(request: RunnerTurnRequest) {
77
- const tool = request.customTools.risky_action;
78
- if (tool === undefined) {
79
- throw new Error("risky_action not registered");
80
- }
81
- const result = await tool.execute(
82
- { note: "ship it" },
83
- { toolCallId: "call_alert_1" }
84
- );
85
- expect(result).toMatchObject({ ok: true, note: "ship it" });
86
- return {
87
- status: "finished",
88
- result: "done",
89
- };
90
- },
91
- };
92
-
93
- const engine = new SessionEngine({
94
- project,
95
- stateRoot,
96
- runner,
97
- });
98
-
99
- const auth = {
100
- authenticator: "local-dev",
101
- principalId: "loopback",
102
- principalType: "user" as const,
103
- };
104
-
105
- const sessionPromise = engine.send("http", "please run risky action", {
106
- auth,
107
- });
108
-
109
- let callId: string | undefined;
110
- let sessionId: string | undefined;
111
- for (let i = 0; i < 100; i++) {
112
- const sessions = await engine.sessions.list();
113
- if (sessions.length > 0) {
114
- sessionId = sessions[0]!.sessionId;
115
- const pending = await engine.listPendingApprovals(sessionId);
116
- if (pending.length > 0) {
117
- callId = pending[0]!.callId;
118
- break;
119
- }
120
- }
121
- await new Promise((r) => setTimeout(r, 20));
122
- }
123
-
124
- expect(sessionId).toBeDefined();
125
- expect(callId).toBe("call_alert_1");
126
- expect(executeFlag.called).toBe(false);
127
-
128
- await engine.resolveApproval(sessionId!, callId!, "approve", auth);
129
-
130
- const session = await sessionPromise;
131
- await session.waitForCompletion();
132
-
133
- expect(executeFlag.called).toBe(true);
134
-
135
- const events = await engine.listEvents(session.id);
136
- const types = events.map((e) => e.type);
137
- expect(types).toContain("action.approval_requested");
138
- expect(types).toContain("action.approval_resolved");
139
- expect(types).toContain("session.waiting");
140
-
141
- await engine.close();
142
- });
143
-
144
- it("rejects approval resolution from a different principal", async () => {
145
- stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-hitl-"));
146
- const executeFlag = { called: false };
147
- const project = makeHitlProject(executeFlag);
148
-
149
- const runner: AgentRunner = {
150
- async runTurn(request: RunnerTurnRequest) {
151
- const tool = request.customTools.risky_action;
152
- if (tool === undefined) {
153
- throw new Error("risky_action not registered");
154
- }
155
- await tool.execute({ note: "ship it" }, { toolCallId: "call_alert_2" });
156
- return { status: "finished", result: "done" };
157
- },
158
- };
159
-
160
- const engine = new SessionEngine({
161
- project,
162
- stateRoot,
163
- runner,
164
- });
165
-
166
- const ownerAuth = {
167
- authenticator: "local-dev",
168
- principalId: "owner",
169
- principalType: "user" as const,
170
- };
171
- const otherAuth = {
172
- authenticator: "local-dev",
173
- principalId: "other",
174
- principalType: "user" as const,
175
- };
176
-
177
- void engine.send("http", "please run risky action", { auth: ownerAuth });
178
-
179
- let callId: string | undefined;
180
- let sessionId: string | undefined;
181
- for (let i = 0; i < 100; i++) {
182
- const sessions = await engine.sessions.list();
183
- if (sessions.length > 0) {
184
- sessionId = sessions[0]!.sessionId;
185
- const pending = await engine.listPendingApprovals(sessionId);
186
- if (pending.length > 0) {
187
- callId = pending[0]!.callId;
188
- break;
189
- }
190
- }
191
- await new Promise((r) => setTimeout(r, 20));
192
- }
193
-
194
- expect(sessionId).toBeDefined();
195
- expect(callId).toBeDefined();
196
-
197
- await expect(
198
- engine.resolveApproval(sessionId!, callId!, "approve", otherAuth)
199
- ).rejects.toThrow(SessionAuthError);
200
-
201
- // Deny as owner so the parked turn can finish before close().
202
- await engine.resolveApproval(sessionId!, callId!, "deny", ownerAuth);
203
- await engine.close();
204
- });
205
-
206
- it("asSessionOwner bridge lets a non-owner resolve Slack-owned approvals", async () => {
207
- stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-hitl-"));
208
- const executeFlag = { called: false };
209
- const project = makeHitlProject(executeFlag);
210
-
211
- const runner: AgentRunner = {
212
- async runTurn(request: RunnerTurnRequest) {
213
- const tool = request.customTools.risky_action;
214
- if (tool === undefined) {
215
- throw new Error("risky_action not registered");
216
- }
217
- await tool.execute({ note: "bridge" }, { toolCallId: "call_bridge_1" });
218
- return { status: "finished", result: "done" };
219
- },
220
- };
221
-
222
- const engine = new SessionEngine({
223
- project,
224
- stateRoot,
225
- runner,
226
- });
227
-
228
- const slackAuth = {
229
- authenticator: "slack",
230
- principalId: "slack:T:C:123.456",
231
- principalType: "user" as const,
232
- attributes: {
233
- channel_id: "C",
234
- thread_ts: "123.456",
235
- user_id: "U_OWNER",
236
- },
237
- };
238
- const playgroundAuth = {
239
- authenticator: "allow-all",
240
- principalId: "anonymous",
241
- principalType: "user" as const,
242
- };
243
-
244
- const sessionPromise = engine.send("http", "please run risky action", {
245
- auth: slackAuth,
246
- });
247
-
248
- let callId: string | undefined;
249
- let sessionId: string | undefined;
250
- for (let i = 0; i < 100; i++) {
251
- const sessions = await engine.sessions.list();
252
- if (sessions.length > 0) {
253
- sessionId = sessions[0]!.sessionId;
254
- const pending = await engine.listPendingApprovals(sessionId);
255
- if (pending.length > 0) {
256
- callId = pending[0]!.callId;
257
- break;
258
- }
259
- }
260
- await new Promise((r) => setTimeout(r, 20));
261
- }
262
-
263
- expect(sessionId).toBeDefined();
264
- expect(callId).toBeDefined();
265
-
266
- await expect(
267
- engine.resolveApproval(sessionId!, callId!, "approve", playgroundAuth)
268
- ).rejects.toThrow(SessionAuthError);
269
-
270
- await engine.resolveApproval(
271
- sessionId!,
272
- callId!,
273
- "approve",
274
- playgroundAuth,
275
- { asSessionOwner: true }
276
- );
277
-
278
- const session = await sessionPromise;
279
- await session.waitForCompletion();
280
-
281
- expect(executeFlag.called).toBe(true);
282
-
283
- const events = await engine.listEvents(session.id);
284
- const resolved = events.find((e) => e.type === "action.approval_resolved");
285
- expect(resolved?.type).toBe("action.approval_resolved");
286
- if (resolved?.type === "action.approval_resolved") {
287
- expect(resolved.data.by).toBe("anonymous");
288
- expect(resolved.data.decision).toBe("approve");
289
- }
290
-
291
- await engine.close();
292
- });
293
-
294
- it("parks when needsApproval predicate returns true (input-only)", async () => {
295
- stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-hitl-"));
296
- const executeFlag = { called: false };
297
- const definition = defineTool({
298
- description: "Conditional risky tool",
299
- needsApproval: (input: { urgent?: boolean }) => input.urgent === true,
300
- async execute(_input: { urgent?: boolean }, _ctx: ToolContext) {
301
- executeFlag.called = true;
302
- return { ok: true };
303
- },
304
- });
305
- const project: AgentProject = {
306
- rootDir: "/tmp/hitl-fixture",
307
- agentDir: "/tmp/hitl-fixture/agent",
308
- name: "hitl-fixture",
309
- agent: {
310
- name: "hitl-fixture",
311
- runtime: "local",
312
- tools: [
313
- {
314
- name: "conditional_risky",
315
- description: definition.description,
316
- execution: "server",
317
- needsApproval: true,
318
- inputSchema: {
319
- type: "object",
320
- properties: { urgent: { type: "boolean" } },
321
- additionalProperties: false,
322
- },
323
- definition,
324
- },
325
- ],
326
- skills: [],
327
- connections: [],
328
- subagents: [],
329
- seedFiles: [],
330
- },
331
- httpChannel: httpChannel(),
332
- channels: [],
333
- schedules: [],
334
- hooks: [],
335
- abs: [],
336
- diagnostics: [],
337
- };
338
-
339
- const runner: AgentRunner = {
340
- async runTurn(request: RunnerTurnRequest) {
341
- const tool = request.customTools.conditional_risky;
342
- if (tool === undefined) {
343
- throw new Error("conditional_risky not registered");
344
- }
345
- await tool.execute({ urgent: true }, { toolCallId: "call_pred_1" });
346
- return { status: "finished", result: "done" };
347
- },
348
- };
349
-
350
- const engine = new SessionEngine({ project, stateRoot, runner });
351
- const auth = {
352
- authenticator: "local-dev",
353
- principalId: "loopback",
354
- principalType: "user" as const,
355
- };
356
-
357
- const sessionPromise = engine.send("http", "urgent action", { auth });
358
-
359
- let callId: string | undefined;
360
- let sessionId: string | undefined;
361
- for (let i = 0; i < 100; i++) {
362
- const sessions = await engine.sessions.list();
363
- if (sessions.length > 0) {
364
- sessionId = sessions[0]!.sessionId;
365
- const pending = await engine.listPendingApprovals(sessionId);
366
- if (pending.length > 0) {
367
- callId = pending[0]!.callId;
368
- break;
369
- }
370
- }
371
- await new Promise((r) => setTimeout(r, 20));
372
- }
373
-
374
- expect(callId).toBe("call_pred_1");
375
- expect(executeFlag.called).toBe(false);
376
-
377
- await engine.resolveApproval(sessionId!, callId!, "approve", auth);
378
- const session = await sessionPromise;
379
- await session.waitForCompletion();
380
- expect(executeFlag.called).toBe(true);
381
- await engine.close();
382
- });
383
- });
@@ -1,31 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { describe, expect, it } from "vitest";
3
- import { AUTHORING_ENTRY_FILES } from "./distribution.js";
4
-
5
- describe("AUTHORING_ENTRY_FILES", () => {
6
- it("mirrors the package exports map (the runtime alias hooks derive their targets from it)", () => {
7
- const pkg = JSON.parse(
8
- readFileSync(new URL("../../package.json", import.meta.url), "utf8")
9
- ) as {
10
- exports: Record<string, string | { import?: string }>;
11
- };
12
- const fromExports = Object.entries(pkg.exports)
13
- .filter(
14
- ([exportPath, conditions]) =>
15
- typeof conditions !== "string" && exportPath !== "./package.json"
16
- )
17
- .map(([exportPath, conditions]) => {
18
- const subpath =
19
- exportPath === "." ? "" : exportPath.replace(/^\.\//, "");
20
- const importTarget = (conditions as { import?: string }).import;
21
- expect(
22
- importTarget,
23
- `exports["${exportPath}"] must have an import condition`
24
- ).toBeDefined();
25
- return [subpath, importTarget?.replace(/^\.\/dist\//, "")];
26
- });
27
- expect(AUTHORING_ENTRY_FILES.map((entry) => [...entry])).toEqual(
28
- fromExports
29
- );
30
- });
31
- });
@@ -1,201 +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 { httpChannel } from "../../channels.js";
6
- import type { AgentProject, ReminderInfo, SessionRecord } from "../../types.js";
7
- import { ReminderRunner } from "../reminder-runner.js";
8
- import { SessionEngine } from "../session-engine.js";
9
- import { builtinTools } from "./index.js";
10
-
11
- function testProject(rootDir: string): AgentProject {
12
- return {
13
- rootDir,
14
- agentDir: join(rootDir, "agent"),
15
- name: "builtin-reminders-test",
16
- agent: {
17
- name: "builtin-reminders-test",
18
- runtime: "local",
19
- instructions: "Test agent instructions.",
20
- tools: builtinTools({ reminders: true }),
21
- skills: [],
22
- connections: [],
23
- subagents: [],
24
- seedFiles: [],
25
- },
26
- httpChannel: httpChannel(),
27
- channels: [],
28
- schedules: [],
29
- hooks: [],
30
- abs: [],
31
- diagnostics: [],
32
- };
33
- }
34
-
35
- const cleanups: Array<() => Promise<void>> = [];
36
-
37
- afterEach(async () => {
38
- while (cleanups.length > 0) {
39
- await cleanups.pop()?.();
40
- }
41
- });
42
-
43
- async function makeEngine(): Promise<SessionEngine> {
44
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-builtin-rem-"));
45
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
46
- const engine = new SessionEngine({
47
- project: testProject(stateRoot),
48
- stateRoot,
49
- runner: {
50
- runTurn: () => {
51
- throw new Error("no model turns in this test");
52
- },
53
- },
54
- });
55
- engine.setReminders(new ReminderRunner(engine));
56
- return engine;
57
- }
58
-
59
- async function saveSession(
60
- engine: SessionEngine,
61
- sessionId: string,
62
- continuationKey: string | null
63
- ): Promise<void> {
64
- const record: SessionRecord = {
65
- sessionId,
66
- channelId: "http",
67
- mode: "chat",
68
- continuationKey,
69
- auth: null,
70
- turnCount: 0,
71
- createdAt: new Date().toISOString(),
72
- updatedAt: new Date().toISOString(),
73
- };
74
- await engine.sessions.save(record);
75
- }
76
-
77
- describe("built-in reminder tools", () => {
78
- it("creates, lists, and cancels a reminder bound to the conversation", async () => {
79
- const engine = await makeEngine();
80
- await saveSession(engine, "ses_a", "conv:a");
81
-
82
- const created = await engine.callTool(
83
- "reminders_create",
84
- {
85
- prompt: "Re-check CI.",
86
- every: "30m",
87
- until: "Cancel once CI is green.",
88
- },
89
- { sessionId: "ses_a" }
90
- );
91
- expect(created.isError).toBe(false);
92
- const reminder = created.result as { reminderId: string; until: string };
93
- expect(reminder.reminderId).toMatch(/^rem_/);
94
- expect(reminder.until).toBe("Cancel once CI is green.");
95
-
96
- const listed = await engine.callTool(
97
- "reminders_list",
98
- {},
99
- { sessionId: "ses_a" }
100
- );
101
- const list = listed.result as { reminders: Array<{ reminderId: string }> };
102
- expect(list.reminders.map((r) => r.reminderId)).toEqual([
103
- reminder.reminderId,
104
- ]);
105
-
106
- const cancelled = await engine.callTool(
107
- "reminders_cancel",
108
- { id: reminder.reminderId },
109
- { sessionId: "ses_a" }
110
- );
111
- expect(cancelled.isError).toBe(false);
112
- expect(cancelled.result).toEqual({
113
- reminderId: reminder.reminderId,
114
- status: "cancelled",
115
- });
116
-
117
- const after = await engine.callTool(
118
- "reminders_list",
119
- {},
120
- { sessionId: "ses_a" }
121
- );
122
- expect((after.result as { reminders: unknown[] }).reminders).toEqual([]);
123
- });
124
-
125
- it("refuses to cancel another conversation's reminder", async () => {
126
- const engine = await makeEngine();
127
- await saveSession(engine, "ses_a", "conv:a");
128
- await saveSession(engine, "ses_b", "conv:b");
129
-
130
- const created = await engine.callTool(
131
- "reminders_create",
132
- { prompt: "wake", delay: "5m" },
133
- { sessionId: "ses_a" }
134
- );
135
- const { reminderId } = created.result as { reminderId: string };
136
-
137
- const foreign = await engine.callTool(
138
- "reminders_cancel",
139
- { id: reminderId },
140
- { sessionId: "ses_b" }
141
- );
142
- expect(foreign.isError).toBe(true);
143
- expect(foreign.errorMessage).toContain("in this conversation");
144
-
145
- const mine = await engine.host.reminders?.list({ status: "armed" });
146
- expect((mine as ReminderInfo[]).map((r) => r.id)).toEqual([reminderId]);
147
- });
148
-
149
- it("keeps reminders addressed across HTTP continuation rotation", async () => {
150
- const engine = await makeEngine();
151
- await saveSession(engine, "ses_a", "conv:a");
152
-
153
- const created = await engine.callTool(
154
- "reminders_create",
155
- { prompt: "wake", delay: "5m" },
156
- { sessionId: "ses_a" }
157
- );
158
- const { reminderId } = created.result as { reminderId: string };
159
-
160
- // The built-in HTTP channel rotates the token after every follow-up.
161
- await engine.setContinuationToken("ses_a", "conv:rotated");
162
-
163
- const listed = await engine.callTool(
164
- "reminders_list",
165
- {},
166
- { sessionId: "ses_a" }
167
- );
168
- const list = listed.result as { reminders: Array<{ reminderId: string }> };
169
- expect(list.reminders.map((r) => r.reminderId)).toEqual([reminderId]);
170
-
171
- // Fire path must still resolve the session (no session_gone disarm).
172
- const dispatched = await engine.host.reminders?.dispatch(reminderId);
173
- expect(dispatched).toMatchObject({ outcome: "fired", reason: "delivered" });
174
- });
175
-
176
- it("rejects sub-minute recurring reminders", async () => {
177
- const engine = await makeEngine();
178
- await saveSession(engine, "ses_a", "conv:a");
179
-
180
- const outcome = await engine.callTool(
181
- "reminders_create",
182
- { prompt: "wake", every: "5s" },
183
- { sessionId: "ses_a" }
184
- );
185
- expect(outcome.isError).toBe(true);
186
- expect(outcome.errorMessage).toContain('every >= "1m"');
187
- });
188
-
189
- it("rejects creates from sessions without a continuation key", async () => {
190
- const engine = await makeEngine();
191
- await saveSession(engine, "ses_nokey", null);
192
-
193
- const outcome = await engine.callTool(
194
- "reminders_create",
195
- { prompt: "wake", delay: "5m" },
196
- { sessionId: "ses_nokey" }
197
- );
198
- expect(outcome.isError).toBe(true);
199
- expect(outcome.errorMessage).toContain("followable");
200
- });
201
- });