Skip to content

Commit ca74f70

Browse files
V48 (impl-only): Discovery search after wave-1; product search keys
Discovery is sequential(parallel(comprehend, regurgitation), search). Deposit: search-depository-for-deposit-relevants. Read: search-depository-for-read-need-fits (fits-finding).
1 parent 5c79fcd commit ca74f70

9 files changed

Lines changed: 491 additions & 83 deletions

packages/asset-packs-pipelines/domain/src/__tests__/deposit-agent-prompt-contracts.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ const SPECS: DepositAgentPromptSpec[] = [
152152
input: {},
153153
},
154154
{
155-
title: 'DepositDepositorySearchAgent (Discovery: search-depository)',
155+
title: 'DepositDepositorySearchForRelevantsAgent (Discovery: search-depository-for-deposit-relevants)',
156156
agent: DepositDepositorySearchAgent,
157157
identity:
158-
'You are the SynthesizeAssetPacks Discovery agent that searches the Bitcode Depository',
158+
'You are Discovery search-depository-for-deposit-relevants. You run after codebase',
159159
requirements: 'From repository coordinates, sourceCheckoutCatalog (paths/samples), obfuscation guidance,',
160160
wrapper: 'Return ONLY {"guidance": {...}, "searchQueries": [...]}',
161161
schemaFields: [
@@ -167,7 +167,7 @@ const SPECS: DepositAgentPromptSpec[] = [
167167
'searchQueries',
168168
],
169169
ptrr: [
170-
'Plan: from sourceCheckoutCatalog paths, measurements, obfuscations, and demand context,',
170+
'Plan: use wave-1 codebase comprehension and inherent regurgitation outcomes plus',
171171
'Try: produce demand guidance and the searchQueries list the Depository search tool will run.',
172172
'Refine: ensure queries and guidance are grounded in sourceCheckoutCatalog evidence, demand-aligned, and source-safe.',
173173
'Retry: return minimal demand guidance and broad searchQueries rather than failing.',

packages/asset-packs-pipelines/domain/src/__tests__/deposit-setup-discovery-agents.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,25 +332,23 @@ describe('discovery conditional runtime registry roster', () => {
332332
};
333333
}
334334

335-
it('deposit mode registers exactly three Discovery agents (no synonym aliases)', () => {
335+
it('deposit mode registers wave-1 + search-depository-for-deposit-relevants', () => {
336336
const registry = recordingRegistry();
337337
registerDiscoveryAgents(registry, 'deposit');
338338
expect([...registry.registrations.keys()].sort()).toEqual([
339339
'discovery:comprehend-codebase',
340340
'discovery:inherent-regurgitation',
341-
'discovery:search-depository',
341+
'discovery:search-depository-for-deposit-relevants',
342342
]);
343343
});
344344

345-
it('read/default mode registers the same product three-agent Discovery roster', () => {
346-
for (const mode of [undefined, 'read']) {
347-
const registry = recordingRegistry();
348-
registerDiscoveryAgents(registry, mode);
349-
expect([...registry.registrations.keys()].sort()).toEqual([
350-
'discovery:comprehend-codebase',
351-
'discovery:inherent-regurgitation',
352-
'discovery:search-depository',
353-
]);
354-
}
345+
it('read mode registers wave-1 + search-depository-for-read-need-fits', () => {
346+
const registry = recordingRegistry();
347+
registerDiscoveryAgents(registry, 'read');
348+
expect([...registry.registrations.keys()].sort()).toEqual([
349+
'discovery:comprehend-codebase',
350+
'discovery:inherent-regurgitation',
351+
'discovery:search-depository-for-read-need-fits',
352+
]);
355353
});
356354
});

packages/asset-packs-pipelines/domain/src/__tests__/synthesize-asset-packs-phase-rosters.test.ts

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
jest.mock('@bitcode/generic-llms', () =>
1515
require('./support/generic-llms-mock').makeGenericLLMsMock());
1616

17-
import { registerDiscoveryAgents } from '../phases/discovery';
17+
import {
18+
registerDiscoveryAgents,
19+
DISCOVERY_COMPREHEND_CODEBASE,
20+
DISCOVERY_INHERENT_REGURGITATION,
21+
DISCOVERY_SEARCH_DEPOSITORY_FOR_DEPOSIT_RELEVANTS,
22+
DISCOVERY_SEARCH_DEPOSITORY_FOR_READ_NEED_FITS,
23+
} from '../phases/discovery';
1824
import { registerImplementationAgents } from '../phases/implementation';
1925
import { registerValidationAgentsForType } from '../phases/validation';
2026
import { registerFinishAgentsForType } from '../phases/finish';
@@ -33,6 +39,7 @@ import {
3339

3440
import depositCodebaseComprehensionAgent from '../agents/discovery/deposit-codebase-comprehension-agent';
3541
import depositDepositorySearchAgent from '../agents/discovery/deposit-depository-search-agent';
42+
import readDepositorySearchForNeedFitsAgent from '../agents/discovery/read-depository-search-for-need-fits-agent';
3643
import depositInherentRegurgitationAgent from '../agents/discovery/deposit-inherent-regurgitation-agent';
3744
import depositAssetPackSynthesisAgent from '../agents/implementation/deposit-asset-pack-synthesis-agent';
3845
import readAssetPackSynthesisAgent from '../agents/implementation/read-asset-pack-synthesis-agent';
@@ -66,39 +73,50 @@ async function resolveEntry(entry: any) {
6673
}
6774

6875
describe('per-mode agent rosters (conditional runtime registries)', () => {
69-
it('deposit discovery registers exactly the three deposit agents', async () => {
76+
it('deposit discovery registers wave-1 agents + deposit-relevants search', async () => {
7077
const registry = fakeRegistry();
7178
registerDiscoveryAgents(registry, 'deposit');
7279

7380
expect(Array.from(registry.entries.keys())).toEqual([
74-
'discovery:comprehend-codebase',
75-
'discovery:search-depository',
76-
'discovery:inherent-regurgitation',
81+
DISCOVERY_COMPREHEND_CODEBASE,
82+
DISCOVERY_INHERENT_REGURGITATION,
83+
DISCOVERY_SEARCH_DEPOSITORY_FOR_DEPOSIT_RELEVANTS,
7784
]);
78-
expect(await resolveEntry(registry.entries.get('discovery:comprehend-codebase'))).toBe(
85+
expect(await resolveEntry(registry.entries.get(DISCOVERY_COMPREHEND_CODEBASE))).toBe(
7986
depositCodebaseComprehensionAgent,
8087
);
81-
expect(await resolveEntry(registry.entries.get('discovery:search-depository'))).toBe(
82-
depositDepositorySearchAgent,
83-
);
84-
expect(await resolveEntry(registry.entries.get('discovery:inherent-regurgitation'))).toBe(
88+
expect(
89+
await resolveEntry(registry.entries.get(DISCOVERY_SEARCH_DEPOSITORY_FOR_DEPOSIT_RELEVANTS)),
90+
).toBe(depositDepositorySearchAgent);
91+
expect(await resolveEntry(registry.entries.get(DISCOVERY_INHERENT_REGURGITATION))).toBe(
8592
depositInherentRegurgitationAgent,
8693
);
8794
});
8895

89-
it.each([['read'], [undefined], ['deposit']])(
90-
'discovery (mode=%s) always registers the product three-agent roster',
91-
(mode) => {
92-
const registry = fakeRegistry();
93-
registerDiscoveryAgents(registry, mode);
96+
it('read discovery registers wave-1 agents + read-need-fits search', async () => {
97+
const registry = fakeRegistry();
98+
registerDiscoveryAgents(registry, 'read');
9499

95-
expect(Array.from(registry.entries.keys())).toEqual([
96-
'discovery:comprehend-codebase',
97-
'discovery:search-depository',
98-
'discovery:inherent-regurgitation',
99-
]);
100-
},
101-
);
100+
expect(Array.from(registry.entries.keys())).toEqual([
101+
DISCOVERY_COMPREHEND_CODEBASE,
102+
DISCOVERY_INHERENT_REGURGITATION,
103+
DISCOVERY_SEARCH_DEPOSITORY_FOR_READ_NEED_FITS,
104+
]);
105+
expect(
106+
await resolveEntry(registry.entries.get(DISCOVERY_SEARCH_DEPOSITORY_FOR_READ_NEED_FITS)),
107+
).toBe(readDepositorySearchForNeedFitsAgent);
108+
});
109+
110+
it('default (non-read) discovery registers deposit-relevants search', () => {
111+
const registry = fakeRegistry();
112+
registerDiscoveryAgents(registry, undefined);
113+
expect(Array.from(registry.entries.keys())).toContain(
114+
DISCOVERY_SEARCH_DEPOSITORY_FOR_DEPOSIT_RELEVANTS,
115+
);
116+
expect(Array.from(registry.entries.keys())).not.toContain(
117+
DISCOVERY_SEARCH_DEPOSITORY_FOR_READ_NEED_FITS,
118+
);
119+
});
102120

103121
it('implementation registers deposit-named vs read synthesis keys by mode', async () => {
104122
const depositKey = 'implementation:deposit-asset-pack-synthesis';
@@ -220,9 +238,14 @@ function harness(keys: string[]) {
220238
}
221239

222240
const DEPOSIT_DISCOVERY_KEYS = [
223-
'discovery:comprehend-codebase',
224-
'discovery:search-depository',
225-
'discovery:inherent-regurgitation',
241+
DISCOVERY_COMPREHEND_CODEBASE,
242+
DISCOVERY_INHERENT_REGURGITATION,
243+
DISCOVERY_SEARCH_DEPOSITORY_FOR_DEPOSIT_RELEVANTS,
244+
];
245+
const READ_DISCOVERY_KEYS = [
246+
DISCOVERY_COMPREHEND_CODEBASE,
247+
DISCOVERY_INHERENT_REGURGITATION,
248+
DISCOVERY_SEARCH_DEPOSITORY_FOR_READ_NEED_FITS,
226249
];
227250
const DEPOSIT_IMPLEMENTATION_KEY = 'implementation:deposit-asset-pack-synthesis';
228251
const DEPOSIT_VALIDATION_KEY =
@@ -241,23 +264,30 @@ const READ_FINISH_KEYS = [
241264
];
242265

243266
describe('product phase delegators execute the roster (execution-tree walk)', () => {
244-
it('deposit discovery runs comprehend-codebase ∥ search-depository ∥ inherent-regurgitation', async () => {
267+
it('deposit discovery: parallel(comprehend, regurgitation) then deposit-relevants search', async () => {
245268
const { calls, root } = harness(DEPOSIT_DISCOVERY_KEYS);
246269
const phaseExec = root.child('seq-2');
247270

248271
await depositDiscoveryPhase({ seed: true }, phaseExec);
249272

250-
// Parallel — assert set equality, not order.
251-
expect(new Set(calls)).toEqual(new Set(DEPOSIT_DISCOVERY_KEYS));
252273
expect(calls).toHaveLength(3);
274+
// Wave 1 (either order) then wave 2 search last.
275+
expect(new Set(calls.slice(0, 2))).toEqual(
276+
new Set([DISCOVERY_COMPREHEND_CODEBASE, DISCOVERY_INHERENT_REGURGITATION]),
277+
);
278+
expect(calls[2]).toBe(DISCOVERY_SEARCH_DEPOSITORY_FOR_DEPOSIT_RELEVANTS);
253279
});
254280

255-
it('read discovery reuses the three deposit discovery agent keys in parallel', async () => {
256-
const { calls, root } = harness(DEPOSIT_DISCOVERY_KEYS);
281+
it('read discovery: parallel(comprehend, regurgitation) then read-need-fits search', async () => {
282+
const { calls, root } = harness(READ_DISCOVERY_KEYS);
257283

258284
await readDiscoveryPhase({ seed: true }, root.child('seq-2'));
259285

260-
expect(new Set(calls)).toEqual(new Set(DEPOSIT_DISCOVERY_KEYS));
286+
expect(calls).toHaveLength(3);
287+
expect(new Set(calls.slice(0, 2))).toEqual(
288+
new Set([DISCOVERY_COMPREHEND_CODEBASE, DISCOVERY_INHERENT_REGURGITATION]),
289+
);
290+
expect(calls[2]).toBe(DISCOVERY_SEARCH_DEPOSITORY_FOR_READ_NEED_FITS);
261291
});
262292

263293
it('deposit implementation resolves deposit-asset-pack-synthesis', async () => {

packages/asset-packs-pipelines/domain/src/agents/discovery/deposit-depository-search-agent.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/**
2-
* Deposit depository-search agent — Discovery (parallel).
2+
* Discovery wave-2 agent: search-depository-for-deposit-relevants.
33
*
4-
* Plan: synthesize search queries from this run's sourceCheckoutCatalog,
4+
* Runs **after** parallel codebase comprehension + inherent regurgitation so
5+
* queries can use wave-1 grounding (especially comprehend-codebase).
6+
*
7+
* Deposit purpose: find **relevant** settled Depository supply / demand
8+
* alignment for this deposit synthesis run (not Need-fits — that is read).
9+
*
10+
* Plan: synthesize search queries from wave-1 signals, sourceCheckoutCatalog,
511
* obfuscations, measurements, and demand context.
612
* Try: call depository-asset-pack-search (embeddings policy + lexical rank).
7-
* Refine/Retry: source-safe demand guidance for Implementation.
13+
* Refine/Retry: source-safe demand/relevance guidance for Implementation.
814
*/
915

1016
import { factoryPTRRAgent } from '@bitcode/agent-generics';
@@ -44,10 +50,12 @@ const DepositorySearchOutputSchema = z.object({
4450
export type DepositReadDemandGuidance = z.infer<typeof ReadDemandGuidanceSchema>;
4551

4652
const IDENTITY = part(
47-
'You are the SynthesizeAssetPacks Discovery agent that searches the Bitcode Depository ' +
48-
'for settled AssetPack supply relevant to this deposit synthesis run. Build search ' +
49-
'queries from the sourceCheckoutCatalog, obfuscations, checkout measurements, and ' +
50-
'demand context so synthesized packs have high likelihood of future demand. Be source-safe.',
53+
'You are Discovery search-depository-for-deposit-relevants. You run after codebase ' +
54+
'comprehension and inherent regurgitation. Search the Bitcode Depository for settled ' +
55+
'AssetPack supply **relevant** to this deposit synthesis run. Build search queries from ' +
56+
'wave-1 comprehension signals, sourceCheckoutCatalog, obfuscations, checkout measurements, ' +
57+
'and demand context so synthesized packs align with likely demand. Be source-safe. ' +
58+
'This is deposit relevance search — not Need-fit search (that is the read product agent).',
5159
);
5260

5361
const REQUIREMENTS = part(
@@ -60,8 +68,9 @@ const REQUIREMENTS = part(
6068
);
6169

6270
const PLAN = part(
63-
'Plan: from sourceCheckoutCatalog paths, measurements, obfuscations, and demand context, ' +
64-
'synthesize Depository search queries that retrieve AssetPacks relevant to high-demand synthesis.',
71+
'Plan: use wave-1 codebase comprehension and inherent regurgitation outcomes plus ' +
72+
'sourceCheckoutCatalog, measurements, obfuscations, and demand context to synthesize ' +
73+
'Depository search queries that retrieve AssetPacks **relevant** to high-demand deposit synthesis.',
6574
);
6675
const TRY = part(
6776
'Try: produce demand guidance and the searchQueries list the Depository search tool will run.',
@@ -91,9 +100,9 @@ export const DepositDepositorySearchAgent = factoryPTRRAgent<
91100
z.infer<typeof DepositorySearchInputSchema>,
92101
z.infer<typeof DepositorySearchOutputSchema>
93102
>({
94-
name: 'DepositDepositorySearchAgent',
103+
name: 'DepositDepositorySearchForRelevantsAgent',
95104
description:
96-
'Plans Depository AssetPack search queries and produces read-demand guidance for deposit synthesis.',
105+
'Discovery wave-2: search Depository for deposit-relevant supply; query plan after codebase comprehension.',
97106
outputSchema: DepositorySearchOutputSchema,
98107
tools: ['depository-asset-pack-search'],
99108
prompt,

0 commit comments

Comments
 (0)