@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.
- package/README.md +12 -10
- package/dist/package.json +2 -1
- package/dist/src/ai-enrichment/agent-orchestrator.d.ts +8 -2
- package/dist/src/ai-enrichment/agent-orchestrator.js +140 -70
- package/dist/src/ai-enrichment/provider-prompt.js +36 -2
- package/dist/src/cli.js +98 -51
- package/dist/src/config/scan-env.d.ts +5 -0
- package/dist/src/config/scan-env.js +12 -1
- package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -1
- package/dist/src/core/pipeline/scan-pipeline.js +7 -4
- package/dist/src/ui/brand.d.ts +28 -0
- package/dist/src/ui/brand.js +72 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +69 -0
- package/dist/src/ui/scan-progress-renderer.js +386 -0
- package/dist/src/ui/teaching-lines.d.ts +9 -0
- package/dist/src/ui/teaching-lines.js +144 -0
- package/dist/src/ui/types.d.ts +33 -0
- package/dist/src/ui/types.js +2 -0
- package/dist/src/upload/run-upload.d.ts +1 -1
- package/dist/src/upload/run-upload.js +21 -16
- package/dist/src/upload/types.d.ts +4 -0
- package/dist/tests/cli/cli.spec.js +77 -40
- package/dist/tests/unit/ai-enrichment/agent-orchestrator.spec.js +227 -147
- package/dist/tests/unit/ai-enrichment/provider-prompt.spec.js +35 -0
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +9 -0
- package/dist/tests/unit/config/scan-env-debug.spec.js +17 -8
- package/dist/tests/unit/ui/brand.spec.d.ts +1 -0
- package/dist/tests/unit/ui/brand.spec.js +52 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.d.ts +1 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +275 -0
- package/dist/tests/unit/ui/teaching-lines.spec.d.ts +1 -0
- package/dist/tests/unit/ui/teaching-lines.spec.js +62 -0
- package/dist/tests/unit/upload/run-upload.spec.js +29 -27
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -24,8 +24,10 @@ pnpm dlx @dataparade/cli scan .
|
|
|
24
24
|
|
|
25
25
|
**What to expect:**
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- In a TTY: brand header, staged progress (spinner → checkmarks), a short **What we found** summary (routes, databases, outbound services), and a clear next-step note.
|
|
28
|
+
- In CI / non-TTY (or with `NO_COLOR`): the same content as plain logs — no spinners or ANSI.
|
|
29
|
+
- On success: `[scan] dataflow.json written to /absolute/path/to/dataflow.json` (always printed for scripts/tests).
|
|
30
|
+
- When auto-upload runs: `[scan] Preview ready: <URL>` (plus a friendly next-step note with the same URL).
|
|
29
31
|
- By default, `dataflow.json` is created in the **current working directory** (override with `-o` / `--output`).
|
|
30
32
|
|
|
31
33
|
```bash
|
|
@@ -67,14 +69,14 @@ By default, the CLI writes `./dataflow.json` in the current working directory.
|
|
|
67
69
|
|
|
68
70
|
## Documentation
|
|
69
71
|
|
|
70
|
-
| Topic
|
|
71
|
-
|
|
72
|
-
| CLI hub (all topics)
|
|
73
|
-
| Scan arguments & flags
|
|
74
|
-
| `dataparade.config.json` | [Config file](https://app.dataparade.io/docs/cli-import-and-zip/config-file)
|
|
75
|
-
| Environment variables
|
|
76
|
-
| AI inference
|
|
77
|
-
| Scan patterns (YAML)
|
|
72
|
+
| Topic | Link |
|
|
73
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------ |
|
|
74
|
+
| CLI hub (all topics) | [CLI Run and Export](https://app.dataparade.io/docs/cli-import-and-zip) |
|
|
75
|
+
| Scan arguments & flags | [Scan arguments](https://app.dataparade.io/docs/cli-import-and-zip/scan-arguments) |
|
|
76
|
+
| `dataparade.config.json` | [Config file](https://app.dataparade.io/docs/cli-import-and-zip/config-file) |
|
|
77
|
+
| Environment variables | [Environment variables](https://app.dataparade.io/docs/cli-import-and-zip/environment-variables) |
|
|
78
|
+
| AI inference | [AI inference](https://app.dataparade.io/docs/cli-import-and-zip/ai-inference) |
|
|
79
|
+
| Scan patterns (YAML) | [Scan patterns](https://app.dataparade.io/docs/cli-import-and-zip/scan-patterns) |
|
|
78
80
|
|
|
79
81
|
---
|
|
80
82
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
+
"@clack/prompts": "^1.8.1",
|
|
57
58
|
"@dataparade/scanner": "github:DataParade-io/scanner#e66e1bcaef55b61214d170c617df529bd300fc89",
|
|
58
59
|
"@sentry/node": "^10.38.0",
|
|
59
60
|
"commander": "^12.1.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AiProposal, InferencePlannerResult, RunInferencePipelineInput, AiInferenceCandidate, AiProviderId, AiInferenceUsageSummary } from
|
|
2
|
-
import type { PlatformProxyProviderConfig } from
|
|
1
|
+
import type { AiProposal, InferencePlannerResult, RunInferencePipelineInput, AiInferenceCandidate, AiProviderId, AiInferenceUsageSummary } from './types';
|
|
2
|
+
import type { PlatformProxyProviderConfig } from './providers/platform-proxy-provider';
|
|
3
3
|
export interface AgentOrchestratorOptions {
|
|
4
4
|
provider: AiProviderId;
|
|
5
5
|
model: string;
|
|
@@ -21,6 +21,12 @@ export interface AgentOrchestratorOptions {
|
|
|
21
21
|
/** Hosted scan in VPC worker: loopback proxy → scan-cli-ai-helper Lambda. */
|
|
22
22
|
hostedWorkerInferProxyUrl?: string;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Hosted infer proxy rejects prompts over 512 KB, and the request body re-escapes
|
|
26
|
+
* the prompt JSON, so keep a margin below that.
|
|
27
|
+
*/
|
|
28
|
+
export declare const MAX_PROVIDER_PROMPT_BYTES = 400000;
|
|
29
|
+
export declare function isPromptTooLargeError(err: unknown): boolean;
|
|
24
30
|
export declare function generateAgenticProposals(input: RunInferencePipelineInput, plan: InferencePlannerResult, candidates: AiInferenceCandidate[], options: AgentOrchestratorOptions): Promise<{
|
|
25
31
|
proposals: Array<{
|
|
26
32
|
id: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_PROVIDER_PROMPT_BYTES = void 0;
|
|
4
|
+
exports.isPromptTooLargeError = isPromptTooLargeError;
|
|
3
5
|
exports.generateAgenticProposals = generateAgenticProposals;
|
|
4
6
|
const agents_1 = require("./agents");
|
|
5
7
|
const provider_prompt_1 = require("./provider-prompt");
|
|
@@ -15,6 +17,24 @@ const PROPERTY_AGENT_SLICE_SIZE = 12;
|
|
|
15
17
|
const TP_AGENT_MAX_ROUNDS = 3;
|
|
16
18
|
const TP_AGENT_MAX_FILES = 8;
|
|
17
19
|
const TP_AGENT_SEARCH_LIMIT = 6;
|
|
20
|
+
/**
|
|
21
|
+
* Hosted infer proxy rejects prompts over 512 KB, and the request body re-escapes
|
|
22
|
+
* the prompt JSON, so keep a margin below that.
|
|
23
|
+
*/
|
|
24
|
+
exports.MAX_PROVIDER_PROMPT_BYTES = 400_000;
|
|
25
|
+
const PROMPT_TOO_LARGE_RE = /request_body_too_large|prompt too large|prompt is too long|context_length_exceeded|maximum context length|\(413\)/i;
|
|
26
|
+
function promptBytes(prompt) {
|
|
27
|
+
return Buffer.byteLength(prompt, 'utf8');
|
|
28
|
+
}
|
|
29
|
+
function isPromptTooLargeError(err) {
|
|
30
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
31
|
+
return PROMPT_TOO_LARGE_RE.test(message);
|
|
32
|
+
}
|
|
33
|
+
function warnSkippedProviderCall(agent, detail) {
|
|
34
|
+
if (!(0, provider_contract_1.aiDebugEnabled)())
|
|
35
|
+
return;
|
|
36
|
+
console.warn(`[dataparade-ai] ${agent} provider call skipped: ${detail}`);
|
|
37
|
+
}
|
|
18
38
|
const IMPORT_RE = /\bimport\s+(?:[^"']+from\s+)?["']([^"']+)["']|\brequire\(["']([^"']+)["']\)/g;
|
|
19
39
|
function chunkCandidates(queue, size) {
|
|
20
40
|
const n = Math.max(1, Math.floor(size));
|
|
@@ -27,10 +47,10 @@ function chunkCandidates(queue, size) {
|
|
|
27
47
|
function shouldCallProviderForAgent(agent) {
|
|
28
48
|
// Flow patches are now merge-gated to intra-section changes only, so provider
|
|
29
49
|
// calls can safely support both property and flow-oriented queues.
|
|
30
|
-
return (agent ===
|
|
31
|
-
agent ===
|
|
32
|
-
agent ===
|
|
33
|
-
agent ===
|
|
50
|
+
return (agent === 'tpAgent' ||
|
|
51
|
+
agent === 'propertyAgent' ||
|
|
52
|
+
agent === 'directionAgent' ||
|
|
53
|
+
agent === 'interactionAgent');
|
|
34
54
|
}
|
|
35
55
|
function estimateTokens(text) {
|
|
36
56
|
// Rough but stable approximation used only for budget gating.
|
|
@@ -61,7 +81,7 @@ function gatherSeedPathsForCandidate(candidate, components) {
|
|
|
61
81
|
return [];
|
|
62
82
|
const out = new Set();
|
|
63
83
|
const sectionId = component.properties.section_id;
|
|
64
|
-
if (typeof sectionId ===
|
|
84
|
+
if (typeof sectionId === 'string' && sectionId.trim())
|
|
65
85
|
out.add(sectionId.trim());
|
|
66
86
|
for (const loc of component.sourceLocations ?? []) {
|
|
67
87
|
if (loc.filePath?.trim())
|
|
@@ -76,11 +96,18 @@ function gatherSeedPathsForCandidate(candidate, components) {
|
|
|
76
96
|
}
|
|
77
97
|
function gatherSearchTerms(componentName) {
|
|
78
98
|
const base = componentName.trim().toLowerCase();
|
|
79
|
-
const terms = new Set([
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
const terms = new Set([
|
|
100
|
+
base,
|
|
101
|
+
'auth',
|
|
102
|
+
'token',
|
|
103
|
+
'api',
|
|
104
|
+
'storage',
|
|
105
|
+
'database',
|
|
106
|
+
]);
|
|
107
|
+
if (base.includes('supabase')) {
|
|
108
|
+
terms.add('supabase');
|
|
109
|
+
terms.add('storage.from');
|
|
110
|
+
terms.add('create_client');
|
|
84
111
|
}
|
|
85
112
|
return [...terms].filter((t) => t.length >= 3);
|
|
86
113
|
}
|
|
@@ -102,27 +129,34 @@ function pickUniqueSearchMatches(matches, alreadyReviewed, limit) {
|
|
|
102
129
|
return [...preferred, ...fallback].slice(0, max);
|
|
103
130
|
}
|
|
104
131
|
function resolveRelativeImportPath(fromFile, rawImport) {
|
|
105
|
-
if (!rawImport.startsWith(
|
|
132
|
+
if (!rawImport.startsWith('.'))
|
|
106
133
|
return undefined;
|
|
107
|
-
const normalizedFrom = fromFile.replace(/\\/g,
|
|
108
|
-
const parts = normalizedFrom.split(
|
|
134
|
+
const normalizedFrom = fromFile.replace(/\\/g, '/');
|
|
135
|
+
const parts = normalizedFrom.split('/');
|
|
109
136
|
parts.pop();
|
|
110
|
-
for (const piece of rawImport.split(
|
|
111
|
-
if (piece ===
|
|
137
|
+
for (const piece of rawImport.split('/')) {
|
|
138
|
+
if (piece === '.' || piece === '')
|
|
112
139
|
continue;
|
|
113
|
-
if (piece ===
|
|
140
|
+
if (piece === '..')
|
|
114
141
|
parts.pop();
|
|
115
142
|
else
|
|
116
143
|
parts.push(piece);
|
|
117
144
|
}
|
|
118
|
-
const base = parts.join(
|
|
119
|
-
const candidates = [
|
|
145
|
+
const base = parts.join('/');
|
|
146
|
+
const candidates = [
|
|
147
|
+
base,
|
|
148
|
+
`${base}.ts`,
|
|
149
|
+
`${base}.js`,
|
|
150
|
+
`${base}.py`,
|
|
151
|
+
`${base}/index.ts`,
|
|
152
|
+
`${base}/index.js`,
|
|
153
|
+
];
|
|
120
154
|
return candidates[0];
|
|
121
155
|
}
|
|
122
156
|
function expandImportPaths(filePath, content) {
|
|
123
157
|
const out = [];
|
|
124
158
|
for (const match of content.matchAll(IMPORT_RE)) {
|
|
125
|
-
const rawImport = (match[1] ?? match[2] ??
|
|
159
|
+
const rawImport = (match[1] ?? match[2] ?? '').trim();
|
|
126
160
|
if (!rawImport)
|
|
127
161
|
continue;
|
|
128
162
|
const rel = resolveRelativeImportPath(filePath, rawImport);
|
|
@@ -140,7 +174,7 @@ function logToolStep(candidateId, step) {
|
|
|
140
174
|
const touched = step.filesTouched?.length ?? 0;
|
|
141
175
|
const stats = step.stats && Object.keys(step.stats).length > 0
|
|
142
176
|
? ` stats=${JSON.stringify(step.stats)}`
|
|
143
|
-
:
|
|
177
|
+
: '';
|
|
144
178
|
console.warn(`[dataparade-ai] tpAgent tool call candidate=${candidateId} round=${step.round} action=${step.action} files_touched=${touched} detail="${step.detail}"${stats}`);
|
|
145
179
|
}
|
|
146
180
|
async function generateAgenticProposals(input, plan, candidates, options) {
|
|
@@ -164,6 +198,28 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
164
198
|
model: options.model,
|
|
165
199
|
apiKey: options.apiKey,
|
|
166
200
|
});
|
|
201
|
+
const inferUnlessTooLarge = async (agent, prompt) => {
|
|
202
|
+
try {
|
|
203
|
+
return await (0, langsmith_tracing_1.traceDataparadeProviderInfer)({
|
|
204
|
+
providerId: options.provider,
|
|
205
|
+
model: options.model,
|
|
206
|
+
run: () => provider.infer({
|
|
207
|
+
prompt,
|
|
208
|
+
model: options.model,
|
|
209
|
+
endpoint: options.endpoint,
|
|
210
|
+
apiKey: options.apiKey,
|
|
211
|
+
maxTokens: options.maxTokens,
|
|
212
|
+
temperature: options.temperature,
|
|
213
|
+
}),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
if (!isPromptTooLargeError(err))
|
|
218
|
+
throw err;
|
|
219
|
+
warnSkippedProviderCall(agent, err instanceof Error ? err.message : String(err));
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
167
223
|
const generated = [];
|
|
168
224
|
const agenticTrace = [];
|
|
169
225
|
const aggregateUsage = {
|
|
@@ -175,12 +231,12 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
175
231
|
};
|
|
176
232
|
let sequence = 0;
|
|
177
233
|
for (const queue of plan.queues) {
|
|
178
|
-
if (!skipStructural && queue.agent ===
|
|
234
|
+
if (!skipStructural && queue.agent === 'tpAgent') {
|
|
179
235
|
for (const candidate of queue.queue) {
|
|
180
236
|
if (!candidate.componentId)
|
|
181
237
|
continue;
|
|
182
238
|
const component = input.components.find((item) => item.id === candidate.componentId);
|
|
183
|
-
if (!component || component.type !==
|
|
239
|
+
if (!component || component.type !== 'third_party')
|
|
184
240
|
continue;
|
|
185
241
|
const patch = (0, third_party_evidence_1.buildThirdPartyHeuristicProposal)({
|
|
186
242
|
candidate,
|
|
@@ -206,7 +262,7 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
206
262
|
if (!llmEnabled || !shouldCallProviderForAgent(queue.agent)) {
|
|
207
263
|
continue;
|
|
208
264
|
}
|
|
209
|
-
if (queue.agent ===
|
|
265
|
+
if (queue.agent === 'tpAgent') {
|
|
210
266
|
const maxCalls = Math.max(0, Math.floor(queue.maxModelCalls));
|
|
211
267
|
const maxCandidates = maxCalls === 0 ? 0 : Math.min(queue.queue.length, maxCalls);
|
|
212
268
|
const tpCandidates = queue.queue.slice(0, maxCandidates);
|
|
@@ -226,8 +282,8 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
226
282
|
reviewed.add(p);
|
|
227
283
|
appendTraceStep(traceSteps, {
|
|
228
284
|
round: 0,
|
|
229
|
-
action:
|
|
230
|
-
detail:
|
|
285
|
+
action: 'seed_files',
|
|
286
|
+
detail: 'Seed files from detectedFrom/sourceLocations/section_id',
|
|
231
287
|
filesTouched: [...reviewed],
|
|
232
288
|
stats: { seedCount: reviewed.size },
|
|
233
289
|
});
|
|
@@ -240,7 +296,7 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
240
296
|
reviewed.add(match.filePath);
|
|
241
297
|
appendTraceStep(traceSteps, {
|
|
242
298
|
round: 0,
|
|
243
|
-
action:
|
|
299
|
+
action: 'search_text',
|
|
244
300
|
detail: `Search term: ${term}`,
|
|
245
301
|
filesTouched: matches.map((m) => m.filePath),
|
|
246
302
|
stats: { hits: matches.length },
|
|
@@ -262,29 +318,32 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
262
318
|
preferredPaths,
|
|
263
319
|
}));
|
|
264
320
|
const estimatedTokens = estimateTokens(prompt) + Math.max(1, options.maxTokens ?? 8192);
|
|
265
|
-
if (queueBudget > 0 &&
|
|
321
|
+
if (queueBudget > 0 &&
|
|
322
|
+
queueBudgetSpent + estimatedTokens > queueBudget) {
|
|
266
323
|
appendTraceStep(traceSteps, {
|
|
267
324
|
round,
|
|
268
|
-
action:
|
|
269
|
-
detail:
|
|
325
|
+
action: 'provider_infer',
|
|
326
|
+
detail: 'Skipped provider inference due to queue budget limit',
|
|
270
327
|
filesTouched: preferredPaths,
|
|
271
328
|
stats: { estimatedTokens, queueBudget, queueBudgetSpent },
|
|
272
329
|
});
|
|
273
330
|
logToolStep(candidate.id, traceSteps[traceSteps.length - 1]);
|
|
274
331
|
break;
|
|
275
332
|
}
|
|
276
|
-
const providerResult =
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
})
|
|
287
|
-
|
|
333
|
+
const providerResult = promptBytes(prompt) > exports.MAX_PROVIDER_PROMPT_BYTES
|
|
334
|
+
? null
|
|
335
|
+
: await inferUnlessTooLarge(queue.agent, prompt);
|
|
336
|
+
if (!providerResult) {
|
|
337
|
+
appendTraceStep(traceSteps, {
|
|
338
|
+
round,
|
|
339
|
+
action: 'provider_infer',
|
|
340
|
+
detail: 'Skipped provider inference because the prompt is too large',
|
|
341
|
+
filesTouched: preferredPaths,
|
|
342
|
+
stats: { promptBytes: promptBytes(prompt) },
|
|
343
|
+
});
|
|
344
|
+
logToolStep(candidate.id, traceSteps[traceSteps.length - 1]);
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
288
347
|
if (queueBudget > 0)
|
|
289
348
|
queueBudgetSpent += estimatedTokens;
|
|
290
349
|
if (providerResult.usage) {
|
|
@@ -292,9 +351,10 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
292
351
|
aggregateUsage.inputTokens += providerResult.usage.inputTokens;
|
|
293
352
|
aggregateUsage.outputTokens += providerResult.usage.outputTokens;
|
|
294
353
|
aggregateUsage.totalTokens += providerResult.usage.totalTokens;
|
|
295
|
-
if (typeof providerResult.usage.estimatedCostUsd ===
|
|
354
|
+
if (typeof providerResult.usage.estimatedCostUsd === 'number') {
|
|
296
355
|
aggregateUsage.estimatedCostUsd =
|
|
297
|
-
(aggregateUsage.estimatedCostUsd ?? 0) +
|
|
356
|
+
(aggregateUsage.estimatedCostUsd ?? 0) +
|
|
357
|
+
providerResult.usage.estimatedCostUsd;
|
|
298
358
|
}
|
|
299
359
|
else {
|
|
300
360
|
aggregateUsage.estimatedCostUsd = undefined;
|
|
@@ -302,10 +362,13 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
302
362
|
}
|
|
303
363
|
appendTraceStep(traceSteps, {
|
|
304
364
|
round,
|
|
305
|
-
action:
|
|
306
|
-
detail:
|
|
365
|
+
action: 'provider_infer',
|
|
366
|
+
detail: 'Provider inference call for current reviewed file set',
|
|
307
367
|
filesTouched: preferredPaths,
|
|
308
|
-
stats: {
|
|
368
|
+
stats: {
|
|
369
|
+
reviewedCount: preferredPaths.length,
|
|
370
|
+
proposals: providerResult.proposals.length,
|
|
371
|
+
},
|
|
309
372
|
});
|
|
310
373
|
logToolStep(candidate.id, traceSteps[traceSteps.length - 1]);
|
|
311
374
|
const acceptedThisRound = [];
|
|
@@ -331,7 +394,9 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
331
394
|
const beforeExpand = reviewed.size;
|
|
332
395
|
const filesForExpand = [...reviewed].slice(0, maxFiles);
|
|
333
396
|
for (const fp of filesForExpand) {
|
|
334
|
-
const fi = input.files
|
|
397
|
+
const fi = input.files
|
|
398
|
+
? (0, scan_paths_1.resolveScannedFileExact)(input.files, fp)
|
|
399
|
+
: undefined;
|
|
335
400
|
if (!fi)
|
|
336
401
|
continue;
|
|
337
402
|
const imports = expandImportPaths(fi.path, fi.content);
|
|
@@ -350,8 +415,8 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
350
415
|
const added = reviewed.size - beforeExpand;
|
|
351
416
|
appendTraceStep(traceSteps, {
|
|
352
417
|
round,
|
|
353
|
-
action:
|
|
354
|
-
detail:
|
|
418
|
+
action: 'expand_imports',
|
|
419
|
+
detail: 'Expand import graph from reviewed files',
|
|
355
420
|
filesTouched: [...reviewed],
|
|
356
421
|
stats: { addedFiles: added, totalReviewed: reviewed.size },
|
|
357
422
|
});
|
|
@@ -361,8 +426,8 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
361
426
|
}
|
|
362
427
|
appendTraceStep(traceSteps, {
|
|
363
428
|
round: executedRounds,
|
|
364
|
-
action:
|
|
365
|
-
detail:
|
|
429
|
+
action: 'finalize',
|
|
430
|
+
detail: 'Finalize accepted proposals for candidate',
|
|
366
431
|
filesTouched: [...reviewed],
|
|
367
432
|
stats: { finalProposalCount: finalProposals.length },
|
|
368
433
|
});
|
|
@@ -386,8 +451,10 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
386
451
|
continue;
|
|
387
452
|
}
|
|
388
453
|
// Non-tp agents stay in bounded prompt batches.
|
|
389
|
-
const
|
|
390
|
-
const preparedProviderCalls =
|
|
454
|
+
const pendingSlices = chunkCandidates(queue.queue, PROPERTY_AGENT_SLICE_SIZE);
|
|
455
|
+
const preparedProviderCalls = [];
|
|
456
|
+
while (pendingSlices.length > 0) {
|
|
457
|
+
const slice = pendingSlices.shift();
|
|
391
458
|
const prompt = JSON.stringify((0, provider_prompt_1.buildProviderPromptPayload)({
|
|
392
459
|
agent: queue.agent,
|
|
393
460
|
queue: slice,
|
|
@@ -396,9 +463,20 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
396
463
|
sections: input.sections,
|
|
397
464
|
files: input.files,
|
|
398
465
|
}));
|
|
466
|
+
const bytes = promptBytes(prompt);
|
|
467
|
+
if (bytes > exports.MAX_PROVIDER_PROMPT_BYTES) {
|
|
468
|
+
if (slice.length > 1) {
|
|
469
|
+
const mid = Math.ceil(slice.length / 2);
|
|
470
|
+
pendingSlices.unshift(slice.slice(0, mid), slice.slice(mid));
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
warnSkippedProviderCall(queue.agent, `prompt for ${slice[0].id} is ${bytes} bytes (limit ${exports.MAX_PROVIDER_PROMPT_BYTES})`);
|
|
474
|
+
}
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
399
477
|
const estimatedTokens = estimateTokens(prompt) + Math.max(1, options.maxTokens ?? 8192);
|
|
400
|
-
|
|
401
|
-
}
|
|
478
|
+
preparedProviderCalls.push({ prompt, estimatedTokens });
|
|
479
|
+
}
|
|
402
480
|
const maxCalls = Math.max(0, Math.floor(queue.maxModelCalls));
|
|
403
481
|
const callsWithinLimit = maxCalls === 0
|
|
404
482
|
? []
|
|
@@ -414,7 +492,7 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
414
492
|
spent += call.estimatedTokens;
|
|
415
493
|
}
|
|
416
494
|
// Avoid starving property enrichment when estimated tokens are conservative.
|
|
417
|
-
if (queue.agent ===
|
|
495
|
+
if (queue.agent === 'propertyAgent' &&
|
|
418
496
|
budgetedCalls.length === 0 &&
|
|
419
497
|
callsWithinLimit.length > 0) {
|
|
420
498
|
budgetedCalls.push(callsWithinLimit[0]);
|
|
@@ -425,27 +503,19 @@ async function generateAgenticProposals(input, plan, candidates, options) {
|
|
|
425
503
|
budgetedCalls.push(...[]);
|
|
426
504
|
}
|
|
427
505
|
const providerConcurrency = Math.max(1, Math.floor(options.providerConcurrency ?? 1));
|
|
428
|
-
const providerResults = await mapWithConcurrency(budgetedCalls, providerConcurrency, (call) => (
|
|
429
|
-
providerId: options.provider,
|
|
430
|
-
model: options.model,
|
|
431
|
-
run: () => provider.infer({
|
|
432
|
-
prompt: call.prompt,
|
|
433
|
-
model: options.model,
|
|
434
|
-
endpoint: options.endpoint,
|
|
435
|
-
apiKey: options.apiKey,
|
|
436
|
-
maxTokens: options.maxTokens,
|
|
437
|
-
temperature: options.temperature,
|
|
438
|
-
}),
|
|
439
|
-
}));
|
|
506
|
+
const providerResults = await mapWithConcurrency(budgetedCalls, providerConcurrency, (call) => inferUnlessTooLarge(queue.agent, call.prompt));
|
|
440
507
|
for (const providerResult of providerResults) {
|
|
508
|
+
if (!providerResult)
|
|
509
|
+
continue;
|
|
441
510
|
if (providerResult.usage) {
|
|
442
511
|
aggregateUsage.providerCalls += 1;
|
|
443
512
|
aggregateUsage.inputTokens += providerResult.usage.inputTokens;
|
|
444
513
|
aggregateUsage.outputTokens += providerResult.usage.outputTokens;
|
|
445
514
|
aggregateUsage.totalTokens += providerResult.usage.totalTokens;
|
|
446
|
-
if (typeof providerResult.usage.estimatedCostUsd ===
|
|
515
|
+
if (typeof providerResult.usage.estimatedCostUsd === 'number') {
|
|
447
516
|
aggregateUsage.estimatedCostUsd =
|
|
448
|
-
(aggregateUsage.estimatedCostUsd ?? 0) +
|
|
517
|
+
(aggregateUsage.estimatedCostUsd ?? 0) +
|
|
518
|
+
providerResult.usage.estimatedCostUsd;
|
|
449
519
|
}
|
|
450
520
|
else {
|
|
451
521
|
aggregateUsage.estimatedCostUsd = undefined;
|
|
@@ -14,12 +14,44 @@ const MAX_SOURCE_LOCS = 12;
|
|
|
14
14
|
const MAX_FILES_IN_PROMPT = 28;
|
|
15
15
|
const MAX_CHARS_PER_FILE = 14_000;
|
|
16
16
|
const MAX_TOTAL_EXCERPT_CHARS = 100_000;
|
|
17
|
-
|
|
17
|
+
/** Cap per already-set property value; scanner evidence lists can reach hundreds of KB. */
|
|
18
|
+
const MAX_PROPERTY_VALUE_CHARS = 4_000;
|
|
19
|
+
const NON_ENRICHMENT_PROPERTY_KEYS = new Set([
|
|
20
|
+
'inference_status',
|
|
21
|
+
'propertyEvidence',
|
|
22
|
+
]);
|
|
18
23
|
function truncateChars(text, max) {
|
|
19
24
|
if (text.length <= max)
|
|
20
25
|
return text;
|
|
21
26
|
return `${text.slice(0, max)}\n\n...[truncated]`;
|
|
22
27
|
}
|
|
28
|
+
function compactDataActions(value) {
|
|
29
|
+
if (!Array.isArray(value))
|
|
30
|
+
return value;
|
|
31
|
+
const actions = value.map((entry) => entry && typeof entry === 'object' && 'action' in entry
|
|
32
|
+
? entry.action
|
|
33
|
+
: entry);
|
|
34
|
+
return [...new Set(actions)];
|
|
35
|
+
}
|
|
36
|
+
function capPropertyValue(value) {
|
|
37
|
+
if (JSON.stringify(value).length <= MAX_PROPERTY_VALUE_CHARS)
|
|
38
|
+
return value;
|
|
39
|
+
if (typeof value === 'string') {
|
|
40
|
+
return truncateChars(value, MAX_PROPERTY_VALUE_CHARS);
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
const kept = [];
|
|
44
|
+
let size = 2;
|
|
45
|
+
for (const item of value) {
|
|
46
|
+
size += JSON.stringify(item).length + 1;
|
|
47
|
+
if (size > MAX_PROPERTY_VALUE_CHARS)
|
|
48
|
+
break;
|
|
49
|
+
kept.push(item);
|
|
50
|
+
}
|
|
51
|
+
return kept;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
23
55
|
function pathsFromComponent(comp) {
|
|
24
56
|
if (!comp)
|
|
25
57
|
return [];
|
|
@@ -127,7 +159,9 @@ function slimComponentForLlm(component) {
|
|
|
127
159
|
sparseKeys.push(key);
|
|
128
160
|
}
|
|
129
161
|
else {
|
|
130
|
-
|
|
162
|
+
const compact = capPropertyValue(key === 'dataActions' ? compactDataActions(value) : value);
|
|
163
|
+
if (compact !== undefined)
|
|
164
|
+
propertiesSet[key] = compact;
|
|
131
165
|
}
|
|
132
166
|
}
|
|
133
167
|
const prioritizedSparseKeys = (0, property_priority_1.sortPropertyKeysByPriority)(sparseKeys);
|