@vercel/factory 0.0.0 → 0.0.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.
@@ -1,16 +1,424 @@
1
+ import * as eve_hooks from 'eve/hooks';
1
2
  import * as eve_tools from 'eve/tools';
2
- import { F as FactoryStores } from '../engine-BXVTLiXU.js';
3
+ import { z } from 'zod';
4
+ import { F as FactoryStores, A as ApprovalPolicy, a as Finding } from '../approval-Z7iaWibT.js';
3
5
  import '../common-CaHaEOAS.js';
4
- import 'zod';
5
6
  import '../driver-tRNggCCJ.js';
6
7
 
8
+ /** The subset of the eve sandbox handle a credentialed git operation needs. */
9
+ interface CommandSandbox {
10
+ run(options: {
11
+ command: string;
12
+ }): PromiseLike<{
13
+ stdout: string;
14
+ stderr?: string;
15
+ exitCode?: number;
16
+ }>;
17
+ }
18
+ interface FetchPullRequestOptions<S extends CommandSandbox = CommandSandbox> {
19
+ /**
20
+ * Runs one git command against `slug` with a credential the sandbox does not
21
+ * otherwise have, and removes it again before resolving. Supplied by the
22
+ * app, which owns how credentials are minted and where they are injected;
23
+ * the library only decides what is fetched.
24
+ */
25
+ withCredential: (sandbox: S, slug: string, command: string) => Promise<{
26
+ stdout: string;
27
+ stderr?: string;
28
+ exitCode?: number;
29
+ }>;
30
+ /** Path of the checkout inside the sandbox. Defaults to `repo`. */
31
+ repoPath?: string;
32
+ /** Fetch depth for the pull request head. Defaults to 50. */
33
+ depth?: number;
34
+ }
35
+ type FetchPullRequestResult = {
36
+ fetched: false;
37
+ reason: string;
38
+ } | {
39
+ fetched: true;
40
+ prNumber: number;
41
+ prUrl: string;
42
+ branch: string;
43
+ headSha: string;
44
+ };
45
+ /**
46
+ * The verifier's way in to the change under review. The sandbox has no
47
+ * GitHub credential while the agent runs, so trusted code does the one fetch
48
+ * the agent cannot: the pull request number and repository come from the
49
+ * change record, never from the agent, and the credential is gone again
50
+ * before control returns. Mirrors how publication reads commits out of the
51
+ * sandbox instead of letting the agent push.
52
+ */
53
+ declare function fetchPullRequestTool<S extends CommandSandbox>(stores: FactoryStores, options: FetchPullRequestOptions<S>): eve_tools.ToolDefinition<{
54
+ changeId: string;
55
+ }, FetchPullRequestResult> & {
56
+ execute(input: {
57
+ changeId: string;
58
+ }, ctx: eve_tools.ToolContext): Promise<FetchPullRequestResult>;
59
+ };
60
+
61
+ interface RecordFindingOptions {
62
+ /** Signal source the findings are recorded under. Defaults to security_scan. */
63
+ source?: string;
64
+ /** Which resulting tasks wait for a human. Defaults to the standard policy. */
65
+ approval?: ApprovalPolicy;
66
+ }
67
+ type RecordFindingResult = {
68
+ recorded: false;
69
+ reason: string;
70
+ duplicate?: true;
71
+ signalId?: string;
72
+ } | {
73
+ recorded: true;
74
+ signalId: string;
75
+ taskId: string;
76
+ approval: "required" | "not_required";
77
+ };
78
+ /**
79
+ * Turn one finding into a signal and a fix task. The fingerprint is the
80
+ * signal's delivery id, so the same problem reported twice is a no-op. The
81
+ * signal is accepted on the reporter's own verification (a human gate follows
82
+ * when the approval policy says so), and the task carries the approval
83
+ * decision from the moment it exists. Shared by record_finding and scanner
84
+ * tools that record on the agent's behalf.
85
+ */
86
+ declare function recordFinding(stores: FactoryStores, repositoryId: string, finding: Finding, options?: RecordFindingOptions): Promise<RecordFindingResult>;
87
+ /**
88
+ * The scanner's outcome tool: turns one finding into a signal and a fix task
89
+ * in a single deterministic step. The finding's fingerprint is the signal's
90
+ * delivery id, so reporting the same problem twice is a no-op. The signal is
91
+ * accepted on the reporter's own verification (a human gate follows when the
92
+ * approval policy says so), and the task carries the approval decision from
93
+ * the moment it exists.
94
+ */
95
+ declare function recordFindingTool(stores: FactoryStores, options?: RecordFindingOptions): eve_tools.ToolDefinition<{
96
+ repositoryId: string;
97
+ finding: {
98
+ title: string;
99
+ body: string;
100
+ priority: "P0" | "P1" | "P2" | "P3";
101
+ category: "security" | "correctness" | "reliability" | "performance" | "compatibility" | "accessibility" | "documentation" | "maintainability" | "testing" | "usability";
102
+ verification: {
103
+ level: "unverified" | "supported" | "confirmed";
104
+ method: "documentation" | "code_inspection" | "static_analysis" | "manual_reproduction" | "unit_test" | "integration_test" | "e2e_test" | "runtime_observation";
105
+ summary: string;
106
+ limitations?: string | undefined;
107
+ };
108
+ path?: string | undefined;
109
+ line?: number | undefined;
110
+ endLine?: number | undefined;
111
+ tool?: string | undefined;
112
+ ruleId?: string | undefined;
113
+ };
114
+ }, RecordFindingResult> & {
115
+ execute(input: {
116
+ repositoryId: string;
117
+ finding: {
118
+ title: string;
119
+ body: string;
120
+ priority: "P0" | "P1" | "P2" | "P3";
121
+ category: "security" | "correctness" | "reliability" | "performance" | "compatibility" | "accessibility" | "documentation" | "maintainability" | "testing" | "usability";
122
+ verification: {
123
+ level: "unverified" | "supported" | "confirmed";
124
+ method: "documentation" | "code_inspection" | "static_analysis" | "manual_reproduction" | "unit_test" | "integration_test" | "e2e_test" | "runtime_observation";
125
+ summary: string;
126
+ limitations?: string | undefined;
127
+ };
128
+ path?: string | undefined;
129
+ line?: number | undefined;
130
+ endLine?: number | undefined;
131
+ tool?: string | undefined;
132
+ ruleId?: string | undefined;
133
+ };
134
+ }, ctx: eve_tools.ToolContext): Promise<RecordFindingResult>;
135
+ };
136
+
137
+ interface DeepsecScanOptions<S extends CommandSandbox = CommandSandbox> extends RecordFindingOptions {
138
+ /**
139
+ * Runs one shell command with the model credential deepsec's gateway route
140
+ * expects, and removes it again before resolving. Supplied by the app, which
141
+ * owns where the credential comes from: on Vercel it is the deployment's own
142
+ * OIDC identity (VERCEL_OIDC_TOKEN), so nothing has to be configured.
143
+ */
144
+ withModelCredential: (sandbox: S, command: string) => Promise<{
145
+ stdout: string;
146
+ stderr?: string;
147
+ exitCode?: number;
148
+ }>;
149
+ /** deepsec agent backend: claude, codex, or pi. */
150
+ agent?: "claude" | "codex" | "pi";
151
+ /** Model deepsec's investigation agent uses, through the AI Gateway (e.g. claude-sonnet-4-6). */
152
+ model?: string;
153
+ /** Reasoning effort for the investigation: minimal, low, medium, high, or xhigh. */
154
+ thinkingLevel?: "minimal" | "low" | "medium" | "high" | "xhigh";
155
+ /** Parallel investigation batches. */
156
+ concurrency?: number;
157
+ /** deepsec version to install. */
158
+ version?: string;
159
+ /** Repository checkout inside the sandbox. Defaults to `repo`. */
160
+ repoPath?: string;
161
+ /** deepsec workspace inside the sandbox. Defaults to `deepsec`. */
162
+ workspacePath?: string;
163
+ /** Shell run before every deepsec command, e.g. to put a Node 24 on PATH. */
164
+ commandPrefix?: string;
165
+ /**
166
+ * Candidate files investigated per run. deepsec keeps state, so successive
167
+ * scans continue where the last one stopped; the cap keeps one run inside
168
+ * the deployment's time limit on large repositories. Defaults to 40.
169
+ */
170
+ filesPerRun?: number;
171
+ }
172
+ /** deepsec's exported finding shape, as far as we depend on it. */
173
+ declare const deepsecFindingSchema: z.ZodObject<{
174
+ title: z.ZodString;
175
+ description: z.ZodString;
176
+ severity: z.ZodString;
177
+ metadata: z.ZodOptional<z.ZodObject<{
178
+ filePath: z.ZodOptional<z.ZodString>;
179
+ lineNumbers: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
180
+ vulnSlug: z.ZodOptional<z.ZodString>;
181
+ confidence: z.ZodOptional<z.ZodString>;
182
+ runId: z.ZodOptional<z.ZodString>;
183
+ }, z.core.$loose>>;
184
+ }, z.core.$loose>;
185
+ /** Convert one deepsec finding into the factory's Finding. Pure; exported for tests. */
186
+ declare function findingFromDeepsec(raw: z.infer<typeof deepsecFindingSchema>): Finding;
187
+ /**
188
+ * Runs deepsec (vercel-labs/deepsec) against the sandbox checkout and records
189
+ * what it finds through the same path as record_finding, so every deepsec
190
+ * finding becomes a fix task subject to the approval policy. Trusted code
191
+ * owns the command sequence and the credential; the agent chooses when to
192
+ * scan and reports the outcome.
193
+ */
194
+ declare function deepsecScanTool<S extends CommandSandbox>(stores: FactoryStores, options: DeepsecScanOptions<S>): eve_tools.ToolDefinition<{
195
+ repositoryId: string;
196
+ limit?: number | undefined;
197
+ }, {
198
+ scanned: false;
199
+ reason: string;
200
+ tool?: undefined;
201
+ found?: undefined;
202
+ recorded?: undefined;
203
+ duplicates?: undefined;
204
+ awaitingApproval?: undefined;
205
+ findings?: undefined;
206
+ } | {
207
+ scanned: true;
208
+ tool: string;
209
+ found: number;
210
+ recorded: number;
211
+ duplicates: number;
212
+ awaitingApproval: number;
213
+ findings: ({
214
+ taskId: string;
215
+ approval: "required" | "not_required";
216
+ title: string;
217
+ priority: "P0" | "P1" | "P2" | "P3";
218
+ path: string | undefined;
219
+ line: number | undefined;
220
+ } | {
221
+ duplicate: boolean;
222
+ title: string;
223
+ priority: "P0" | "P1" | "P2" | "P3";
224
+ path: string | undefined;
225
+ line: number | undefined;
226
+ })[];
227
+ reason?: undefined;
228
+ }> & {
229
+ execute(input: {
230
+ repositoryId: string;
231
+ limit?: number | undefined;
232
+ }, ctx: eve_tools.ToolContext): Promise<{
233
+ scanned: false;
234
+ reason: string;
235
+ tool?: undefined;
236
+ found?: undefined;
237
+ recorded?: undefined;
238
+ duplicates?: undefined;
239
+ awaitingApproval?: undefined;
240
+ findings?: undefined;
241
+ } | {
242
+ scanned: true;
243
+ tool: string;
244
+ found: number;
245
+ recorded: number;
246
+ duplicates: number;
247
+ awaitingApproval: number;
248
+ findings: ({
249
+ taskId: string;
250
+ approval: "required" | "not_required";
251
+ title: string;
252
+ priority: "P0" | "P1" | "P2" | "P3";
253
+ path: string | undefined;
254
+ line: number | undefined;
255
+ } | {
256
+ duplicate: boolean;
257
+ title: string;
258
+ priority: "P0" | "P1" | "P2" | "P3";
259
+ path: string | undefined;
260
+ line: number | undefined;
261
+ })[];
262
+ reason?: undefined;
263
+ }>;
264
+ };
265
+
266
+ interface InvokeAgentOptions {
267
+ /** The factory task kind the handoff creates, e.g. "verification". */
268
+ kind: string;
269
+ /** Model-facing description of what the target agent does and when to invoke it. */
270
+ description: string;
271
+ /**
272
+ * Base URL of the target agent's eve transport, e.g.
273
+ * `https://factory.example.com/eve/agents/verifier`. Resolved at call time so
274
+ * a deployment can derive it from its own origin.
275
+ */
276
+ targetUrl: () => string;
277
+ /** Bearer token for the target agent's eve channel, when it requires auth. */
278
+ token?: () => Promise<string | undefined>;
279
+ /** Extra headers for the session request, e.g. a deployment protection bypass. */
280
+ headers?: () => Record<string, string> | Promise<Record<string, string>>;
281
+ fetch?: typeof fetch;
282
+ }
283
+ /**
284
+ * A tool that lets one agent hand work to another, NMA-style: the caller
285
+ * decides to invoke; trusted code owns the how. The handoff is recorded as a
286
+ * factory task (single-winner dispatch, receipts), then a fresh session is
287
+ * started on the target agent carrying only the task id — never the caller's
288
+ * context. The session start is create-once on the task id, so a retried
289
+ * tool call cannot start a second session.
290
+ */
291
+ declare function invokeAgentTool(stores: FactoryStores, options: InvokeAgentOptions): eve_tools.ToolDefinition<{
292
+ repositoryIds: string[];
293
+ channel: string;
294
+ address: string;
295
+ brief: string;
296
+ parentTaskId?: string | undefined;
297
+ changeId?: string | undefined;
298
+ }, {
299
+ taskId: string;
300
+ kind: string;
301
+ state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
302
+ }> & {
303
+ execute(input: {
304
+ repositoryIds: string[];
305
+ channel: string;
306
+ address: string;
307
+ brief: string;
308
+ parentTaskId?: string | undefined;
309
+ changeId?: string | undefined;
310
+ }, ctx: eve_tools.ToolContext): Promise<{
311
+ taskId: string;
312
+ kind: string;
313
+ state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
314
+ }>;
315
+ };
316
+
317
+ /**
318
+ * The verifier's outcome tool. Writes evidence onto the change and moves it
319
+ * to ready only when the verdict is pass; a failed verdict leaves the change
320
+ * verifying with the evidence recorded, and the verification task itself
321
+ * ends with a receipt either way. The change's own code_change task follows
322
+ * the verdict too: succeeded on pass, failed on fail with the verifier's
323
+ * summary as the reason, so the ledger never shows a verified-and-rejected fix
324
+ * as still in progress. Fail closed: the agent cannot mark a change ready
325
+ * without supplying every evidence field.
326
+ */
327
+ declare function recordVerificationTool(stores: FactoryStores): eve_tools.ToolDefinition<{
328
+ taskId: string;
329
+ changeId: string;
330
+ verdict: "pass" | "fail";
331
+ evidence: {
332
+ reproVerified: boolean;
333
+ testsAdded: number;
334
+ checksGreen: boolean;
335
+ attackPassed: boolean;
336
+ scopeMatches: boolean;
337
+ previewUrl?: string | undefined;
338
+ };
339
+ confidence: "low" | "medium" | "high";
340
+ summary: string;
341
+ }, {
342
+ recorded: false;
343
+ reason: string;
344
+ verdict?: undefined;
345
+ changeState?: undefined;
346
+ taskState?: undefined;
347
+ } | {
348
+ recorded: true;
349
+ verdict: "pass" | "fail";
350
+ changeState: "verifying" | "ready" | "merged" | "deployed" | "rolled_out" | "rolled_back" | "closed";
351
+ taskState: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
352
+ reason?: undefined;
353
+ }> & {
354
+ execute(input: {
355
+ taskId: string;
356
+ changeId: string;
357
+ verdict: "pass" | "fail";
358
+ evidence: {
359
+ reproVerified: boolean;
360
+ testsAdded: number;
361
+ checksGreen: boolean;
362
+ attackPassed: boolean;
363
+ scopeMatches: boolean;
364
+ previewUrl?: string | undefined;
365
+ };
366
+ confidence: "low" | "medium" | "high";
367
+ summary: string;
368
+ }, ctx: eve_tools.ToolContext): Promise<{
369
+ recorded: false;
370
+ reason: string;
371
+ verdict?: undefined;
372
+ changeState?: undefined;
373
+ taskState?: undefined;
374
+ } | {
375
+ recorded: true;
376
+ verdict: "pass" | "fail";
377
+ changeState: "verifying" | "ready" | "merged" | "deployed" | "rolled_out" | "rolled_back" | "closed";
378
+ taskState: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
379
+ reason?: undefined;
380
+ }>;
381
+ };
382
+
383
+ declare const recordChangeInputSchema: z.ZodObject<{
384
+ taskId: z.ZodString;
385
+ repositoryId: z.ZodString;
386
+ prNumber: z.ZodNumber;
387
+ prUrl: z.ZodURL;
388
+ risk: z.ZodEnum<{
389
+ low: "low";
390
+ medium: "medium";
391
+ high: "high";
392
+ }>;
393
+ confidence: z.ZodEnum<{
394
+ low: "low";
395
+ medium: "medium";
396
+ high: "high";
397
+ }>;
398
+ summary: z.ZodString;
399
+ }, z.core.$strip>;
400
+ type RecordChangeInput = z.infer<typeof recordChangeInputSchema>;
401
+ type GateVerdict = {
402
+ ok: true;
403
+ } | {
404
+ ok: false;
405
+ reason: string;
406
+ };
407
+ interface FactoryToolsOptions {
408
+ /**
409
+ * Pre-action gate for record_change, run as an eve approval policy before
410
+ * the tool executes. Refusals reach the model as a denial with the reason.
411
+ * Gates must fail closed: when they cannot verify, they refuse.
412
+ */
413
+ recordChangeGate?: (input: RecordChangeInput) => Promise<GateVerdict>;
414
+ }
7
415
  /**
8
416
  * The factory's store operations wrapped as eve tools. Expose a tool to an
9
417
  * agent by re-exporting it from a file under agent/tools/, e.g.
10
418
  * `export default factoryTools(stores).get_task;`. Every write goes through
11
419
  * the engine, so agents inherit transition legality and receipts.
12
420
  */
13
- declare function factoryTools(stores: FactoryStores): {
421
+ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptions): {
14
422
  get_task: eve_tools.ToolDefinition<{
15
423
  taskId: string;
16
424
  }, {
@@ -32,6 +440,7 @@ declare function factoryTools(stores: FactoryStores): {
32
440
  updatedAt: string;
33
441
  repositoryIds?: string[] | undefined;
34
442
  area?: string | undefined;
443
+ approval?: "required" | "granted" | "denied" | undefined;
35
444
  dependsOn?: string[] | undefined;
36
445
  devbox?: {
37
446
  devboxId: string;
@@ -73,6 +482,7 @@ declare function factoryTools(stores: FactoryStores): {
73
482
  updatedAt: string;
74
483
  repositoryIds?: string[] | undefined;
75
484
  area?: string | undefined;
485
+ approval?: "required" | "granted" | "denied" | undefined;
76
486
  dependsOn?: string[] | undefined;
77
487
  devbox?: {
78
488
  devboxId: string;
@@ -191,6 +601,7 @@ declare function factoryTools(stores: FactoryStores): {
191
601
  updatedAt: string;
192
602
  repositoryIds?: string[] | undefined;
193
603
  area?: string | undefined;
604
+ approval?: "required" | "granted" | "denied" | undefined;
194
605
  dependsOn?: string[] | undefined;
195
606
  devbox?: {
196
607
  devboxId: string;
@@ -261,6 +672,7 @@ declare function factoryTools(stores: FactoryStores): {
261
672
  updatedAt: string;
262
673
  repositoryIds?: string[] | undefined;
263
674
  area?: string | undefined;
675
+ approval?: "required" | "granted" | "denied" | undefined;
264
676
  dependsOn?: string[] | undefined;
265
677
  devbox?: {
266
678
  devboxId: string;
@@ -280,6 +692,31 @@ declare function factoryTools(stores: FactoryStores): {
280
692
  };
281
693
  }>;
282
694
  };
695
+ finish_task: eve_tools.ToolDefinition<{
696
+ taskId: string;
697
+ summary: string;
698
+ }, {
699
+ finished: false;
700
+ reason: string;
701
+ taskState?: undefined;
702
+ } | {
703
+ finished: true;
704
+ taskState: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
705
+ reason?: undefined;
706
+ }> & {
707
+ execute(input: {
708
+ taskId: string;
709
+ summary: string;
710
+ }, ctx: eve_tools.ToolContext): Promise<{
711
+ finished: false;
712
+ reason: string;
713
+ taskState?: undefined;
714
+ } | {
715
+ finished: true;
716
+ taskState: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
717
+ reason?: undefined;
718
+ }>;
719
+ };
283
720
  report_blocked: eve_tools.ToolDefinition<{
284
721
  taskId: string;
285
722
  reason: string;
@@ -302,6 +739,7 @@ declare function factoryTools(stores: FactoryStores): {
302
739
  updatedAt: string;
303
740
  repositoryIds?: string[] | undefined;
304
741
  area?: string | undefined;
742
+ approval?: "required" | "granted" | "denied" | undefined;
305
743
  dependsOn?: string[] | undefined;
306
744
  devbox?: {
307
745
  devboxId: string;
@@ -341,6 +779,7 @@ declare function factoryTools(stores: FactoryStores): {
341
779
  updatedAt: string;
342
780
  repositoryIds?: string[] | undefined;
343
781
  area?: string | undefined;
782
+ approval?: "required" | "granted" | "denied" | undefined;
344
783
  dependsOn?: string[] | undefined;
345
784
  devbox?: {
346
785
  devboxId: string;
@@ -387,6 +826,7 @@ declare function factoryTools(stores: FactoryStores): {
387
826
  updatedAt: string;
388
827
  repositoryIds?: string[] | undefined;
389
828
  area?: string | undefined;
829
+ approval?: "required" | "granted" | "denied" | undefined;
390
830
  dependsOn?: string[] | undefined;
391
831
  devbox?: {
392
832
  devboxId: string;
@@ -432,6 +872,7 @@ declare function factoryTools(stores: FactoryStores): {
432
872
  updatedAt: string;
433
873
  repositoryIds?: string[] | undefined;
434
874
  area?: string | undefined;
875
+ approval?: "required" | "granted" | "denied" | undefined;
435
876
  dependsOn?: string[] | undefined;
436
877
  devbox?: {
437
878
  devboxId: string;
@@ -503,5 +944,19 @@ declare function factoryTools(stores: FactoryStores): {
503
944
  };
504
945
  };
505
946
  type FactoryTools = ReturnType<typeof factoryTools>;
947
+ /**
948
+ * Observe-only eve hooks that keep the ledger honest about session outcomes.
949
+ * Mount by re-exporting from agent/hooks/, e.g.
950
+ * `export default factoryHooks(stores).factory;`.
951
+ *
952
+ * turn.completed: a turn that ends while its task is still running means the
953
+ * agent finished talking without recording an outcome; the task moves to
954
+ * needs_human instead of rotting. The task is found by the session's
955
+ * channel address, which dispatch set from the task's replyTo.
956
+ */
957
+ declare function factoryHooks(stores: FactoryStores): {
958
+ factory: eve_hooks.HookDefinition<"turn.completed">;
959
+ };
960
+ type FactoryHooks = ReturnType<typeof factoryHooks>;
506
961
 
507
- export { type FactoryTools, factoryTools };
962
+ export { type CommandSandbox, type DeepsecScanOptions, type FactoryHooks, type FactoryTools, type FactoryToolsOptions, type FetchPullRequestOptions, type FetchPullRequestResult, type GateVerdict, type InvokeAgentOptions, type RecordChangeInput, type RecordFindingOptions, type RecordFindingResult, deepsecScanTool, factoryHooks, factoryTools, fetchPullRequestTool, findingFromDeepsec, invokeAgentTool, recordFinding, recordFindingTool, recordVerificationTool };