@dataparade/cli 0.0.20 → 0.0.22

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 (34) hide show
  1. package/README.md +12 -10
  2. package/dist/package.json +2 -1
  3. package/dist/src/ai-enrichment/agent-orchestrator.d.ts +8 -2
  4. package/dist/src/ai-enrichment/agent-orchestrator.js +140 -70
  5. package/dist/src/ai-enrichment/provider-prompt.js +36 -2
  6. package/dist/src/cli.js +98 -51
  7. package/dist/src/config/scan-env.d.ts +5 -0
  8. package/dist/src/config/scan-env.js +12 -1
  9. package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -1
  10. package/dist/src/core/pipeline/scan-pipeline.js +7 -4
  11. package/dist/src/ui/brand.d.ts +28 -0
  12. package/dist/src/ui/brand.js +72 -0
  13. package/dist/src/ui/scan-progress-renderer.d.ts +69 -0
  14. package/dist/src/ui/scan-progress-renderer.js +386 -0
  15. package/dist/src/ui/teaching-lines.d.ts +9 -0
  16. package/dist/src/ui/teaching-lines.js +144 -0
  17. package/dist/src/ui/types.d.ts +33 -0
  18. package/dist/src/ui/types.js +2 -0
  19. package/dist/src/upload/run-upload.d.ts +1 -1
  20. package/dist/src/upload/run-upload.js +21 -16
  21. package/dist/src/upload/types.d.ts +4 -0
  22. package/dist/tests/cli/cli.spec.js +77 -40
  23. package/dist/tests/unit/ai-enrichment/agent-orchestrator.spec.js +227 -147
  24. package/dist/tests/unit/ai-enrichment/provider-prompt.spec.js +35 -0
  25. package/dist/tests/unit/cli/scan-quota-flow.spec.js +9 -0
  26. package/dist/tests/unit/config/scan-env-debug.spec.js +17 -8
  27. package/dist/tests/unit/ui/brand.spec.d.ts +1 -0
  28. package/dist/tests/unit/ui/brand.spec.js +52 -0
  29. package/dist/tests/unit/ui/scan-progress-renderer.spec.d.ts +1 -0
  30. package/dist/tests/unit/ui/scan-progress-renderer.spec.js +275 -0
  31. package/dist/tests/unit/ui/teaching-lines.spec.d.ts +1 -0
  32. package/dist/tests/unit/ui/teaching-lines.spec.js +62 -0
  33. package/dist/tests/unit/upload/run-upload.spec.js +29 -27
  34. package/package.json +2 -1
@@ -5,62 +5,62 @@ const chat_completions_family_1 = require("../../../src/ai-enrichment/providers/
5
5
  function tpCandidate(id, componentId) {
6
6
  return {
7
7
  id,
8
- candidateType: "third_party",
8
+ candidateType: 'third_party',
9
9
  priority: 90,
10
10
  componentId,
11
11
  missingFields: [],
12
- rationale: "r",
12
+ rationale: 'r',
13
13
  hints: [],
14
14
  };
15
15
  }
16
16
  function propertyCandidate(id, componentId) {
17
17
  return {
18
18
  id,
19
- candidateType: "node_property",
19
+ candidateType: 'node_property',
20
20
  priority: 50,
21
21
  componentId,
22
- missingFields: ["encryption_at_rest"],
23
- rationale: "r",
22
+ missingFields: ['encryption_at_rest'],
23
+ rationale: 'r',
24
24
  hints: [],
25
25
  };
26
26
  }
27
- describe("generateAgenticProposals", () => {
27
+ describe('generateAgenticProposals', () => {
28
28
  let inferSpy;
29
29
  beforeEach(() => {
30
30
  inferSpy = jest
31
- .spyOn(chat_completions_family_1.ChatCompletionsFamilyProvider.prototype, "infer")
31
+ .spyOn(chat_completions_family_1.ChatCompletionsFamilyProvider.prototype, 'infer')
32
32
  .mockResolvedValue({ proposals: [] });
33
33
  });
34
34
  afterEach(() => {
35
35
  inferSpy.mockRestore();
36
36
  });
37
- it("invokes the provider once per third-party queue item (tpAgent)", async () => {
37
+ it('invokes the provider once per third-party queue item (tpAgent)', async () => {
38
38
  const components = [
39
39
  {
40
- id: "tp_a",
41
- name: "A",
42
- type: "third_party",
40
+ id: 'tp_a',
41
+ name: 'A',
42
+ type: 'third_party',
43
43
  confidence: 0.9,
44
44
  detectedFrom: [],
45
45
  sourceLocations: [],
46
46
  properties: { vendor: null },
47
47
  },
48
48
  {
49
- id: "tp_b",
50
- name: "B",
51
- type: "third_party",
49
+ id: 'tp_b',
50
+ name: 'B',
51
+ type: 'third_party',
52
52
  confidence: 0.9,
53
53
  detectedFrom: [],
54
54
  sourceLocations: [],
55
55
  properties: { vendor: null },
56
56
  },
57
57
  ];
58
- const c1 = tpCandidate("c1", "tp_a");
59
- const c2 = tpCandidate("c2", "tp_b");
58
+ const c1 = tpCandidate('c1', 'tp_a');
59
+ const c2 = tpCandidate('c2', 'tp_b');
60
60
  await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, {
61
61
  queues: [
62
62
  {
63
- agent: "tpAgent",
63
+ agent: 'tpAgent',
64
64
  queue: [c1, c2],
65
65
  budgetTokens: 200_000,
66
66
  maxModelCalls: 10,
@@ -68,9 +68,9 @@ describe("generateAgenticProposals", () => {
68
68
  ],
69
69
  droppedCandidates: [],
70
70
  }, [c1, c2], {
71
- provider: "openai",
72
- model: "gpt-4o-mini",
73
- apiKey: "sk-test",
71
+ provider: 'openai',
72
+ model: 'gpt-4o-mini',
73
+ apiKey: 'sk-test',
74
74
  toolLoopMaxRounds: 1,
75
75
  });
76
76
  expect(inferSpy).toHaveBeenCalledTimes(2);
@@ -79,33 +79,33 @@ describe("generateAgenticProposals", () => {
79
79
  expect(payload.candidates).toHaveLength(1);
80
80
  }
81
81
  });
82
- it("batches propertyAgent into a single infer call", async () => {
82
+ it('batches propertyAgent into a single infer call', async () => {
83
83
  const components = [
84
84
  {
85
- id: "asset_1",
86
- name: "DB",
87
- type: "asset",
85
+ id: 'asset_1',
86
+ name: 'DB',
87
+ type: 'asset',
88
88
  confidence: 0.9,
89
89
  detectedFrom: [],
90
90
  sourceLocations: [],
91
91
  properties: {},
92
92
  },
93
93
  {
94
- id: "asset_2",
95
- name: "Cache",
96
- type: "asset",
94
+ id: 'asset_2',
95
+ name: 'Cache',
96
+ type: 'asset',
97
97
  confidence: 0.9,
98
98
  detectedFrom: [],
99
99
  sourceLocations: [],
100
100
  properties: {},
101
101
  },
102
102
  ];
103
- const c1 = propertyCandidate("p1", "asset_1");
104
- const c2 = propertyCandidate("p2", "asset_2");
103
+ const c1 = propertyCandidate('p1', 'asset_1');
104
+ const c2 = propertyCandidate('p2', 'asset_2');
105
105
  await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, {
106
106
  queues: [
107
107
  {
108
- agent: "propertyAgent",
108
+ agent: 'propertyAgent',
109
109
  queue: [c1, c2],
110
110
  budgetTokens: 200_000,
111
111
  maxModelCalls: 10,
@@ -113,52 +113,52 @@ describe("generateAgenticProposals", () => {
113
113
  ],
114
114
  droppedCandidates: [],
115
115
  }, [c1, c2], {
116
- provider: "openai",
117
- model: "gpt-4o-mini",
118
- apiKey: "sk-test",
116
+ provider: 'openai',
117
+ model: 'gpt-4o-mini',
118
+ apiKey: 'sk-test',
119
119
  toolLoopMaxRounds: 1,
120
120
  });
121
121
  expect(inferSpy).toHaveBeenCalledTimes(1);
122
122
  const payload = JSON.parse(inferSpy.mock.calls[0][0].prompt);
123
123
  expect(payload.candidates).toHaveLength(2);
124
124
  });
125
- it("respects maxModelCalls limit for tpAgent provider calls", async () => {
125
+ it('respects maxModelCalls limit for tpAgent provider calls', async () => {
126
126
  const components = [
127
127
  {
128
- id: "tp_a",
129
- name: "A",
130
- type: "third_party",
128
+ id: 'tp_a',
129
+ name: 'A',
130
+ type: 'third_party',
131
131
  confidence: 0.9,
132
132
  detectedFrom: [],
133
133
  sourceLocations: [],
134
134
  properties: { vendor: null },
135
135
  },
136
136
  {
137
- id: "tp_b",
138
- name: "B",
139
- type: "third_party",
137
+ id: 'tp_b',
138
+ name: 'B',
139
+ type: 'third_party',
140
140
  confidence: 0.9,
141
141
  detectedFrom: [],
142
142
  sourceLocations: [],
143
143
  properties: { vendor: null },
144
144
  },
145
145
  {
146
- id: "tp_c",
147
- name: "C",
148
- type: "third_party",
146
+ id: 'tp_c',
147
+ name: 'C',
148
+ type: 'third_party',
149
149
  confidence: 0.9,
150
150
  detectedFrom: [],
151
151
  sourceLocations: [],
152
152
  properties: { vendor: null },
153
153
  },
154
154
  ];
155
- const c1 = tpCandidate("c1", "tp_a");
156
- const c2 = tpCandidate("c2", "tp_b");
157
- const c3 = tpCandidate("c3", "tp_c");
155
+ const c1 = tpCandidate('c1', 'tp_a');
156
+ const c2 = tpCandidate('c2', 'tp_b');
157
+ const c3 = tpCandidate('c3', 'tp_c');
158
158
  await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, {
159
159
  queues: [
160
160
  {
161
- agent: "tpAgent",
161
+ agent: 'tpAgent',
162
162
  queue: [c1, c2, c3],
163
163
  budgetTokens: 100_000,
164
164
  maxModelCalls: 2,
@@ -166,30 +166,30 @@ describe("generateAgenticProposals", () => {
166
166
  ],
167
167
  droppedCandidates: [],
168
168
  }, [c1, c2, c3], {
169
- provider: "openai",
170
- model: "gpt-4o-mini",
171
- apiKey: "sk-test",
169
+ provider: 'openai',
170
+ model: 'gpt-4o-mini',
171
+ apiKey: 'sk-test',
172
172
  toolLoopMaxRounds: 1,
173
173
  });
174
174
  expect(inferSpy).toHaveBeenCalledTimes(2);
175
175
  });
176
- it("respects budgetTokens and skips provider calls when budget is exhausted", async () => {
176
+ it('respects budgetTokens and skips provider calls when budget is exhausted', async () => {
177
177
  const components = [
178
178
  {
179
- id: "tp_a",
180
- name: "A",
181
- type: "third_party",
179
+ id: 'tp_a',
180
+ name: 'A',
181
+ type: 'third_party',
182
182
  confidence: 0.9,
183
183
  detectedFrom: [],
184
184
  sourceLocations: [],
185
185
  properties: { vendor: null },
186
186
  },
187
187
  ];
188
- const c1 = tpCandidate("c1", "tp_a");
188
+ const c1 = tpCandidate('c1', 'tp_a');
189
189
  await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, {
190
190
  queues: [
191
191
  {
192
- agent: "tpAgent",
192
+ agent: 'tpAgent',
193
193
  queue: [c1],
194
194
  budgetTokens: 1,
195
195
  maxModelCalls: 1,
@@ -197,19 +197,19 @@ describe("generateAgenticProposals", () => {
197
197
  ],
198
198
  droppedCandidates: [],
199
199
  }, [c1], {
200
- provider: "openai",
201
- model: "gpt-4o-mini",
202
- apiKey: "sk-test",
200
+ provider: 'openai',
201
+ model: 'gpt-4o-mini',
202
+ apiKey: 'sk-test',
203
203
  toolLoopMaxRounds: 1,
204
204
  });
205
205
  expect(inferSpy).toHaveBeenCalledTimes(0);
206
206
  });
207
- it("invokes the provider for interactionAgent when the queue is eligible", async () => {
207
+ it('invokes the provider for interactionAgent when the queue is eligible', async () => {
208
208
  const components = [
209
209
  {
210
- id: "asset_1",
211
- name: "A",
212
- type: "asset",
210
+ id: 'asset_1',
211
+ name: 'A',
212
+ type: 'asset',
213
213
  confidence: 0.9,
214
214
  detectedFrom: [],
215
215
  sourceLocations: [],
@@ -217,17 +217,17 @@ describe("generateAgenticProposals", () => {
217
217
  },
218
218
  ];
219
219
  const interactionCandidate = {
220
- id: "m1",
221
- candidateType: "missing_interaction",
220
+ id: 'm1',
221
+ candidateType: 'missing_interaction',
222
222
  priority: 80,
223
223
  missingFields: [],
224
- rationale: "r",
225
- hints: ["frontend", "backend"],
224
+ rationale: 'r',
225
+ hints: ['frontend', 'backend'],
226
226
  };
227
227
  await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, {
228
228
  queues: [
229
229
  {
230
- agent: "interactionAgent",
230
+ agent: 'interactionAgent',
231
231
  queue: [interactionCandidate],
232
232
  budgetTokens: 200_000,
233
233
  maxModelCalls: 10,
@@ -235,14 +235,14 @@ describe("generateAgenticProposals", () => {
235
235
  ],
236
236
  droppedCandidates: [],
237
237
  }, [interactionCandidate], {
238
- provider: "openai",
239
- model: "gpt-4o-mini",
240
- apiKey: "sk-test",
238
+ provider: 'openai',
239
+ model: 'gpt-4o-mini',
240
+ apiKey: 'sk-test',
241
241
  toolLoopMaxRounds: 1,
242
242
  });
243
243
  expect(inferSpy).toHaveBeenCalledTimes(1);
244
244
  });
245
- it("aggregates provider token usage across calls", async () => {
245
+ it('aggregates provider token usage across calls', async () => {
246
246
  inferSpy.mockResolvedValue({
247
247
  proposals: [],
248
248
  usage: {
@@ -254,30 +254,30 @@ describe("generateAgenticProposals", () => {
254
254
  });
255
255
  const components = [
256
256
  {
257
- id: "tp_a",
258
- name: "A",
259
- type: "third_party",
257
+ id: 'tp_a',
258
+ name: 'A',
259
+ type: 'third_party',
260
260
  confidence: 0.9,
261
261
  detectedFrom: [],
262
262
  sourceLocations: [],
263
263
  properties: { vendor: null },
264
264
  },
265
265
  {
266
- id: "tp_b",
267
- name: "B",
268
- type: "third_party",
266
+ id: 'tp_b',
267
+ name: 'B',
268
+ type: 'third_party',
269
269
  confidence: 0.9,
270
270
  detectedFrom: [],
271
271
  sourceLocations: [],
272
272
  properties: { vendor: null },
273
273
  },
274
274
  ];
275
- const c1 = tpCandidate("c1", "tp_a");
276
- const c2 = tpCandidate("c2", "tp_b");
275
+ const c1 = tpCandidate('c1', 'tp_a');
276
+ const c2 = tpCandidate('c2', 'tp_b');
277
277
  const out = await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, {
278
278
  queues: [
279
279
  {
280
- agent: "tpAgent",
280
+ agent: 'tpAgent',
281
281
  queue: [c1, c2],
282
282
  budgetTokens: 200_000,
283
283
  maxModelCalls: 10,
@@ -285,9 +285,9 @@ describe("generateAgenticProposals", () => {
285
285
  ],
286
286
  droppedCandidates: [],
287
287
  }, [c1, c2], {
288
- provider: "openai",
289
- model: "gpt-4o-mini",
290
- apiKey: "sk-test",
288
+ provider: 'openai',
289
+ model: 'gpt-4o-mini',
290
+ apiKey: 'sk-test',
291
291
  toolLoopMaxRounds: 1,
292
292
  });
293
293
  expect(out.usageSummary).toMatchObject({
@@ -299,29 +299,29 @@ describe("generateAgenticProposals", () => {
299
299
  });
300
300
  expect(out.usageSummary?.agenticTrace?.length).toBe(2);
301
301
  });
302
- it("adds deterministic third-party heuristic proposals with evidence", async () => {
302
+ it('adds deterministic third-party heuristic proposals with evidence', async () => {
303
303
  inferSpy.mockResolvedValue({ proposals: [] });
304
304
  const components = [
305
305
  {
306
- id: "tp_stripe",
307
- name: "Stripe",
308
- type: "third_party",
306
+ id: 'tp_stripe',
307
+ name: 'Stripe',
308
+ type: 'third_party',
309
309
  confidence: 0.9,
310
310
  detectedFrom: [
311
311
  {
312
- pattern: "external_api_call",
312
+ pattern: 'external_api_call',
313
313
  sourceLocation: {
314
- filePath: "backend/payments/index.ts",
314
+ filePath: 'backend/payments/index.ts',
315
315
  startLine: 1,
316
316
  endLine: 1,
317
317
  },
318
318
  },
319
319
  ],
320
320
  sourceLocations: [
321
- { filePath: "backend/payments/index.ts", startLine: 1, endLine: 1 },
321
+ { filePath: 'backend/payments/index.ts', startLine: 1, endLine: 1 },
322
322
  ],
323
323
  properties: {
324
- section_id: "backend/payments",
324
+ section_id: 'backend/payments',
325
325
  vendor: null,
326
326
  api_type: null,
327
327
  authentication_method: null,
@@ -334,61 +334,63 @@ describe("generateAgenticProposals", () => {
334
334
  dataFlows: [],
335
335
  files: [
336
336
  {
337
- path: "backend/payments/index.ts",
338
- name: "index.ts",
339
- language: "typescript",
337
+ path: 'backend/payments/index.ts',
338
+ name: 'index.ts',
339
+ language: 'typescript',
340
340
  size: 180,
341
341
  content: [
342
342
  'import Stripe from "stripe";',
343
343
  'await fetch("https://api.stripe.com/v1/customers", {',
344
- " headers: { Authorization: `Bearer ${process.env.STRIPE_API_KEY}` },",
345
- "});",
346
- ].join("\n"),
344
+ ' headers: { Authorization: `Bearer ${process.env.STRIPE_API_KEY}` },',
345
+ '});',
346
+ ].join('\n'),
347
347
  },
348
348
  {
349
- path: "backend/payments/package.json",
350
- name: "package.json",
351
- language: "json",
349
+ path: 'backend/payments/package.json',
350
+ name: 'package.json',
351
+ language: 'json',
352
352
  size: 60,
353
- content: JSON.stringify({ dependencies: { stripe: "^17.0.0" } }),
353
+ content: JSON.stringify({ dependencies: { stripe: '^17.0.0' } }),
354
354
  },
355
355
  ],
356
356
  }, {
357
357
  queues: [
358
358
  {
359
- agent: "tpAgent",
360
- queue: [tpCandidate("c1", "tp_stripe")],
359
+ agent: 'tpAgent',
360
+ queue: [tpCandidate('c1', 'tp_stripe')],
361
361
  budgetTokens: 200_000,
362
362
  maxModelCalls: 1,
363
363
  },
364
364
  ],
365
365
  droppedCandidates: [],
366
- }, [tpCandidate("c1", "tp_stripe")], {
367
- provider: "openai",
368
- model: "gpt-4o-mini",
369
- apiKey: "sk-test",
366
+ }, [tpCandidate('c1', 'tp_stripe')], {
367
+ provider: 'openai',
368
+ model: 'gpt-4o-mini',
369
+ apiKey: 'sk-test',
370
370
  toolLoopMaxRounds: 1,
371
371
  });
372
- const heuristic = out.proposals.find((item) => item.id.startsWith("heuristic_"));
372
+ const heuristic = out.proposals.find((item) => item.id.startsWith('heuristic_'));
373
373
  expect(heuristic).toBeDefined();
374
- expect(heuristic?.proposal.kind).toBe("component_patch");
375
- if (heuristic?.proposal.kind === "component_patch") {
374
+ expect(heuristic?.proposal.kind).toBe('component_patch');
375
+ if (heuristic?.proposal.kind === 'component_patch') {
376
376
  expect(Object.keys(heuristic.proposal.setProperties).length).toBeGreaterThan(0);
377
377
  expect(heuristic.proposal.evidence.length).toBeGreaterThan(0);
378
- expect(heuristic.proposal.provider).toBe("mock");
379
- expect(heuristic.proposal.agent).toBe("tpAgent");
378
+ expect(heuristic.proposal.provider).toBe('mock');
379
+ expect(heuristic.proposal.agent).toBe('tpAgent');
380
380
  }
381
381
  });
382
- it("persists agentic trace for tp tool loop runs", async () => {
382
+ it('persists agentic trace for tp tool loop runs', async () => {
383
383
  inferSpy.mockResolvedValue({ proposals: [] });
384
384
  const components = [
385
385
  {
386
- id: "tp_trace",
387
- name: "Stripe",
388
- type: "third_party",
386
+ id: 'tp_trace',
387
+ name: 'Stripe',
388
+ type: 'third_party',
389
389
  confidence: 0.9,
390
390
  detectedFrom: [],
391
- sourceLocations: [{ filePath: "src/payments.ts", startLine: 1, endLine: 1 }],
391
+ sourceLocations: [
392
+ { filePath: 'src/payments.ts', startLine: 1, endLine: 1 },
393
+ ],
392
394
  properties: { vendor: null },
393
395
  },
394
396
  ];
@@ -397,9 +399,9 @@ describe("generateAgenticProposals", () => {
397
399
  dataFlows: [],
398
400
  files: [
399
401
  {
400
- path: "src/payments.ts",
401
- name: "payments.ts",
402
- language: "typescript",
402
+ path: 'src/payments.ts',
403
+ name: 'payments.ts',
404
+ language: 'typescript',
403
405
  size: 64,
404
406
  content: 'import x from "./client";\nexport const payments = true;',
405
407
  },
@@ -407,34 +409,34 @@ describe("generateAgenticProposals", () => {
407
409
  }, {
408
410
  queues: [
409
411
  {
410
- agent: "tpAgent",
411
- queue: [tpCandidate("c_trace", "tp_trace")],
412
+ agent: 'tpAgent',
413
+ queue: [tpCandidate('c_trace', 'tp_trace')],
412
414
  budgetTokens: 100_000,
413
415
  maxModelCalls: 1,
414
416
  },
415
417
  ],
416
418
  droppedCandidates: [],
417
- }, [tpCandidate("c_trace", "tp_trace")], {
418
- provider: "openai",
419
- model: "gpt-4o-mini",
420
- apiKey: "sk-test",
419
+ }, [tpCandidate('c_trace', 'tp_trace')], {
420
+ provider: 'openai',
421
+ model: 'gpt-4o-mini',
422
+ apiKey: 'sk-test',
421
423
  toolLoopMaxRounds: 1,
422
424
  });
423
425
  expect(out.usageSummary?.agenticTrace).toBeDefined();
424
426
  expect(out.usageSummary?.agenticTrace?.length).toBe(1);
425
427
  expect(out.usageSummary?.agenticTrace?.[0]?.toolCalls.length).toBeGreaterThan(0);
426
428
  });
427
- it("deduplicates repeated search hits and prefers unseen files", async () => {
429
+ it('deduplicates repeated search hits and prefers unseen files', async () => {
428
430
  inferSpy.mockResolvedValue({ proposals: [] });
429
431
  const components = [
430
432
  {
431
- id: "tp_search_dedupe",
432
- name: "Supabase",
433
- type: "third_party",
433
+ id: 'tp_search_dedupe',
434
+ name: 'Supabase',
435
+ type: 'third_party',
434
436
  confidence: 0.9,
435
437
  detectedFrom: [],
436
- sourceLocations: [{ filePath: "src/a.ts", startLine: 1, endLine: 1 }],
437
- properties: { vendor: null, section_id: "src" },
438
+ sourceLocations: [{ filePath: 'src/a.ts', startLine: 1, endLine: 1 }],
439
+ properties: { vendor: null, section_id: 'src' },
438
440
  },
439
441
  ];
440
442
  const out = await (0, agent_orchestrator_1.generateAgenticProposals)({
@@ -442,16 +444,16 @@ describe("generateAgenticProposals", () => {
442
444
  dataFlows: [],
443
445
  files: [
444
446
  {
445
- path: "src/a.ts",
446
- name: "a.ts",
447
- language: "typescript",
447
+ path: 'src/a.ts',
448
+ name: 'a.ts',
449
+ language: 'typescript',
448
450
  size: 200,
449
451
  content: "const one = 'supabase';\nconst two = 'supabase';\nconst three = 'supabase';\n",
450
452
  },
451
453
  {
452
- path: "src/b.ts",
453
- name: "b.ts",
454
- language: "typescript",
454
+ path: 'src/b.ts',
455
+ name: 'b.ts',
456
+ language: 'typescript',
455
457
  size: 120,
456
458
  content: "const other = 'supabase';\n",
457
459
  },
@@ -459,25 +461,103 @@ describe("generateAgenticProposals", () => {
459
461
  }, {
460
462
  queues: [
461
463
  {
462
- agent: "tpAgent",
463
- queue: [tpCandidate("c_search_dedupe", "tp_search_dedupe")],
464
+ agent: 'tpAgent',
465
+ queue: [tpCandidate('c_search_dedupe', 'tp_search_dedupe')],
464
466
  budgetTokens: 100_000,
465
467
  maxModelCalls: 1,
466
468
  },
467
469
  ],
468
470
  droppedCandidates: [],
469
- }, [tpCandidate("c_search_dedupe", "tp_search_dedupe")], {
470
- provider: "openai",
471
- model: "gpt-4o-mini",
472
- apiKey: "sk-test",
471
+ }, [tpCandidate('c_search_dedupe', 'tp_search_dedupe')], {
472
+ provider: 'openai',
473
+ model: 'gpt-4o-mini',
474
+ apiKey: 'sk-test',
473
475
  toolLoopMaxRounds: 1,
474
476
  });
475
477
  const trace = out.usageSummary?.agenticTrace?.[0];
476
478
  expect(trace).toBeDefined();
477
- const searchCall = trace?.toolCalls.find((step) => step.action === "search_text");
479
+ const searchCall = trace?.toolCalls.find((step) => step.action === 'search_text');
478
480
  expect(searchCall).toBeDefined();
479
481
  const touched = searchCall?.filesTouched ?? [];
480
482
  expect(new Set(touched).size).toBe(touched.length);
481
- expect(touched).toContain("src/b.ts");
483
+ expect(touched).toContain('src/b.ts');
484
+ });
485
+ describe('oversized prompts', () => {
486
+ function largeAsset(id) {
487
+ const properties = { vendor: null };
488
+ for (let i = 0; i < 30; i += 1)
489
+ properties[`note_${i}`] = 'x'.repeat(3_900);
490
+ return {
491
+ id,
492
+ name: id,
493
+ type: 'asset',
494
+ confidence: 0.9,
495
+ detectedFrom: [],
496
+ sourceLocations: [],
497
+ properties,
498
+ };
499
+ }
500
+ function propertyPlan(candidates) {
501
+ return {
502
+ queues: [
503
+ {
504
+ agent: 'propertyAgent',
505
+ queue: candidates,
506
+ budgetTokens: 10_000_000,
507
+ maxModelCalls: 20,
508
+ },
509
+ ],
510
+ droppedCandidates: [],
511
+ };
512
+ }
513
+ const orchestratorOptions = {
514
+ provider: 'openai',
515
+ model: 'gpt-4o-mini',
516
+ apiKey: 'sk-test',
517
+ toolLoopMaxRounds: 1,
518
+ };
519
+ it('splits a propertyAgent batch until each prompt fits the size limit', async () => {
520
+ const components = Array.from({ length: 12 }, (_, i) => largeAsset(`asset_${i}`));
521
+ const candidates = components.map((c) => propertyCandidate(`p_${c.id}`, c.id));
522
+ await (0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, propertyPlan(candidates), candidates, orchestratorOptions);
523
+ expect(inferSpy.mock.calls.length).toBeGreaterThan(1);
524
+ const sent = [];
525
+ for (const call of inferSpy.mock.calls) {
526
+ const prompt = call[0].prompt;
527
+ expect(Buffer.byteLength(prompt, 'utf8')).toBeLessThanOrEqual(agent_orchestrator_1.MAX_PROVIDER_PROMPT_BYTES);
528
+ const payload = JSON.parse(prompt);
529
+ sent.push(...payload.candidates.map((c) => c.id));
530
+ }
531
+ expect(sent).toEqual(candidates.map((c) => c.id));
532
+ });
533
+ it('skips a call the provider rejects as too large and keeps the scan going', async () => {
534
+ inferSpy
535
+ .mockRejectedValueOnce(new Error('request_body_too_large'))
536
+ .mockResolvedValueOnce({ proposals: [] });
537
+ const components = [largeAsset('asset_a')];
538
+ const candidates = [propertyCandidate('p_a', 'asset_a')];
539
+ await expect((0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, propertyPlan(candidates), candidates, orchestratorOptions)).resolves.toEqual(expect.objectContaining({ proposals: [] }));
540
+ });
541
+ it('still fails the scan for provider errors unrelated to prompt size', async () => {
542
+ inferSpy.mockRejectedValueOnce(new Error('Invalid workspace API key'));
543
+ const components = [largeAsset('asset_a')];
544
+ const candidates = [propertyCandidate('p_a', 'asset_a')];
545
+ await expect((0, agent_orchestrator_1.generateAgenticProposals)({ components, dataFlows: [] }, propertyPlan(candidates), candidates, orchestratorOptions)).rejects.toThrow('Invalid workspace API key');
546
+ });
547
+ });
548
+ });
549
+ describe('isPromptTooLargeError', () => {
550
+ it.each([
551
+ 'request_body_too_large',
552
+ 'prompt too large',
553
+ 'prompt is too long: 250000 tokens > 200000 maximum',
554
+ "This model's maximum context length is 128000 tokens",
555
+ 'Hosted scan AI infer failed (413)',
556
+ ])('matches %s', (message) => {
557
+ expect((0, agent_orchestrator_1.isPromptTooLargeError)(new Error(message))).toBe(true);
558
+ });
559
+ it('does not match auth or quota errors', () => {
560
+ expect((0, agent_orchestrator_1.isPromptTooLargeError)(new Error('platform_llm_not_configured'))).toBe(false);
561
+ expect((0, agent_orchestrator_1.isPromptTooLargeError)(new Error('Platform AI infer failed (402)'))).toBe(false);
482
562
  });
483
563
  });