Repository navigation
Expand file tree
/
Copy pathgenerate-agent-radar.mjs
More file actions
423 lines (373 loc) · 14.1 KB
/
Copy pathgenerate-agent-radar.mjs
File metadata and controls
423 lines (373 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
import { promises as fs } from "node:fs";
import path from "node:path";
import prettier from "prettier";
import { readJson, root } from "./lib/files.mjs";
const checkOnly = process.argv.includes("--check");
const writeOrCheck = async (relativePath, content) => {
const target = path.join(root, relativePath);
if (checkOnly) {
let existing = "";
try {
existing = await fs.readFile(target, "utf8");
} catch {
throw new Error(`${relativePath} is missing. Run pnpm build.`);
}
if (existing !== content) {
throw new Error(`${relativePath} is stale. Run pnpm build.`);
}
return;
}
await fs.mkdir(path.dirname(target), { recursive: true });
await fs.writeFile(target, content);
};
const riskOrder = { low: 0, medium: 1, high: 2 };
const reviewerLabels = [
"domain-reviewer",
"replicator",
"red-team-reviewer",
"field-reality-reviewer"
];
const discoverPacks = async () => {
const packs = [];
const problemRoot = path.join(root, "problem-packs");
const domains = await fs.readdir(problemRoot);
for (const domain of domains) {
const domainPath = path.join(problemRoot, domain);
const domainStat = await fs.stat(domainPath);
if (!domainStat.isDirectory()) continue;
const problems = await fs.readdir(domainPath);
for (const problem of problems) {
const problemPath = path.join(domainPath, problem);
const problemStat = await fs.stat(problemPath);
if (!problemStat.isDirectory()) continue;
const relativeDir = `problem-packs/${domain}/${problem}`;
const metadata = await readJson(`${relativeDir}/problem.json`);
const tasks = await readJson(`${relativeDir}/tasks.json`);
const evidence = await readJson(`${relativeDir}/evidence.json`);
packs.push({
relativeDir,
metadata,
tasks,
evidenceCount: evidence.length
});
}
}
return packs.sort((a, b) => a.metadata.id.localeCompare(b.metadata.id));
};
const increment = (map, key, amount = 1) => {
map[key] = (map[key] ?? 0) + amount;
return map;
};
const packs = await discoverPacks();
const taskRecords = [];
const protocolAlerts = [];
for (const pack of packs) {
const taskPath = `${pack.relativeDir}/tasks.json`;
for (const task of pack.tasks) {
const reviewerNeededIsKnown = reviewerLabels.includes(task.reviewer_needed);
if (!reviewerNeededIsKnown) {
protocolAlerts.push({
type: "reviewer-needed-enum-drift",
severity: "high",
message: `Task ${task.id} uses unknown reviewer label ${task.reviewer_needed}.`,
pack_id: pack.metadata.id,
task_id: task.id,
reviewer_needed: task.reviewer_needed,
tasks_file: taskPath
});
}
taskRecords.push({
...task,
pack_id: pack.metadata.id,
pack_title: pack.metadata.title,
pack_summary: pack.metadata.summary,
pack_status: pack.metadata.status,
domain: pack.metadata.domain,
region: pack.metadata.region,
evidence_count: pack.evidenceCount,
tasks_file: taskPath,
problem_file: `${pack.relativeDir}/problem.md`
});
}
}
const scopedTasks = taskRecords.filter((task) => task.status === "scoped");
const latentTasks = taskRecords.filter((task) => task.status !== "scoped");
const statusCounts = taskRecords.reduce((acc, task) => increment(acc, task.status), {});
const ownerRoleCounts = taskRecords.reduce(
(acc, task) => increment(acc, task.owner_role),
{}
);
const scopedRoleCounts = scopedTasks.reduce(
(acc, task) => increment(acc, task.owner_role),
{}
);
const reviewerNeededCounts = taskRecords.reduce(
(acc, task) => increment(acc, task.reviewer_needed),
{}
);
const safetyRiskCounts = taskRecords.reduce(
(acc, task) => increment(acc, task.safety_risk),
{}
);
const packLanes = packs.map((pack) => {
const scoped = pack.tasks.filter((task) => task.status === "scoped");
const downstream = pack.tasks.filter((task) => task.status !== "scoped");
const downstreamByRole = downstream.reduce(
(acc, task) => increment(acc, task.owner_role),
{}
);
const downstreamByRisk = downstream.reduce(
(acc, task) => increment(acc, task.safety_risk),
{}
);
const downstreamReviewers = downstream.reduce(
(acc, task) => increment(acc, task.reviewer_needed),
{}
);
const scopedRisk = scoped.reduce(
(lowest, task) => Math.min(lowest, riskOrder[task.safety_risk] ?? 99),
99
);
return {
pack_id: pack.metadata.id,
pack_title: pack.metadata.title,
pack_summary: pack.metadata.summary,
problem_file: `${pack.relativeDir}/problem.md`,
tasks_file: `${pack.relativeDir}/tasks.json`,
evidence_count: pack.evidenceCount,
scoped_tasks: scoped.length,
downstream_tasks: downstream.length,
downstream_high_risk_tasks: downstream.filter((task) => task.safety_risk === "high")
.length,
downstream_medium_risk_tasks: downstream.filter((task) => task.safety_risk === "medium")
.length,
downstream_by_role: downstreamByRole,
downstream_by_risk: downstreamByRisk,
downstream_reviewers_needed: downstreamReviewers,
entry_roles: [...new Set(scoped.map((task) => task.owner_role))],
scoped_risk_floor: scopedRisk
};
});
const firstMoves = scopedTasks
.map((task) => {
const lane = packLanes.find((entry) => entry.pack_id === task.pack_id);
return {
pack_id: task.pack_id,
pack_title: task.pack_title,
task_id: task.id,
title: task.title,
owner_role: task.owner_role,
reviewer_needed: task.reviewer_needed,
safety_risk: task.safety_risk,
done_condition: task.done_condition,
evidence_count: task.evidence_count,
downstream_tasks_unlocked: lane?.downstream_tasks ?? 0,
downstream_high_risk_tasks: lane?.downstream_high_risk_tasks ?? 0,
problem_file: task.problem_file,
tasks_file: task.tasks_file,
why_pick_now:
(lane?.downstream_tasks ?? 0) > 0
? `Completing this scoped task opens ${lane?.downstream_tasks ?? 0} follow-on tasks across ${Object.keys(lane?.downstream_by_role ?? {}).length} additional roles.`
: "Scoped and ready now, with no hidden multi-role dependency behind the first move."
};
})
.sort((a, b) => {
const risk = (riskOrder[a.safety_risk] ?? 99) - (riskOrder[b.safety_risk] ?? 99);
if (risk !== 0) return risk;
const unlocks = b.downstream_tasks_unlocked - a.downstream_tasks_unlocked;
if (unlocks !== 0) return unlocks;
const evidence = b.evidence_count - a.evidence_count;
if (evidence !== 0) return evidence;
return a.pack_id.localeCompare(b.pack_id);
})
.slice(0, 12);
const unlockPaths = packLanes
.filter((lane) => lane.scoped_tasks > 0)
.sort((a, b) => {
const downstream = b.downstream_tasks - a.downstream_tasks;
if (downstream !== 0) return downstream;
const highRisk = b.downstream_high_risk_tasks - a.downstream_high_risk_tasks;
if (highRisk !== 0) return highRisk;
const evidence = b.evidence_count - a.evidence_count;
if (evidence !== 0) return evidence;
return a.pack_id.localeCompare(b.pack_id);
})
.slice(0, 12)
.map((lane) => ({
pack_id: lane.pack_id,
pack_title: lane.pack_title,
scoped_tasks: lane.scoped_tasks,
downstream_tasks: lane.downstream_tasks,
downstream_high_risk_tasks: lane.downstream_high_risk_tasks,
downstream_by_role: lane.downstream_by_role,
downstream_reviewers_needed: lane.downstream_reviewers_needed,
evidence_count: lane.evidence_count,
problem_file: lane.problem_file,
tasks_file: lane.tasks_file
}));
const reviewerHotspots = packLanes
.filter((lane) => Object.keys(lane.downstream_reviewers_needed).length > 0)
.sort((a, b) => {
const reviewLoad =
Object.values(b.downstream_reviewers_needed).reduce((sum, count) => sum + count, 0) -
Object.values(a.downstream_reviewers_needed).reduce((sum, count) => sum + count, 0);
if (reviewLoad !== 0) return reviewLoad;
const highRisk = b.downstream_high_risk_tasks - a.downstream_high_risk_tasks;
if (highRisk !== 0) return highRisk;
return a.pack_id.localeCompare(b.pack_id);
})
.slice(0, 12)
.map((lane) => ({
pack_id: lane.pack_id,
pack_title: lane.pack_title,
downstream_reviewers_needed: lane.downstream_reviewers_needed,
downstream_high_risk_tasks: lane.downstream_high_risk_tasks,
downstream_tasks: lane.downstream_tasks,
problem_file: lane.problem_file
}));
const roleBacklog = Object.entries(ownerRoleCounts)
.map(([role, total]) => {
const scopedCount = scopedRoleCounts[role] ?? 0;
const latentCount = total - scopedCount;
return {
owner_role: role,
scoped_tasks: scopedCount,
latent_tasks: latentCount,
share_of_all_tasks: Number((total / taskRecords.length).toFixed(3)),
share_of_latent_tasks:
latentTasks.length === 0 ? 0 : Number((latentCount / latentTasks.length).toFixed(3))
};
})
.sort((a, b) => {
const latent = b.latent_tasks - a.latent_tasks;
if (latent !== 0) return latent;
return a.owner_role.localeCompare(b.owner_role);
});
const radar = {
summary: {
generated_by: "scripts/generate-agent-radar.mjs",
schema_version: 1,
total_packs: packs.length,
total_tasks: taskRecords.length,
scoped_tasks: scopedTasks.length,
latent_tasks: latentTasks.length,
status_counts: statusCounts,
owner_role_counts: ownerRoleCounts,
scoped_role_counts: scopedRoleCounts,
reviewer_needed_counts: reviewerNeededCounts,
safety_risk_counts: safetyRiskCounts,
protocol_alert_count: protocolAlerts.length
},
protocol_alerts: protocolAlerts,
contributor_lanes: {
first_moves: firstMoves,
unlock_paths: unlockPaths,
reviewer_hotspots: reviewerHotspots,
role_backlog: roleBacklog
}
};
const formatCountMap = (counts) =>
Object.entries(counts)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([label, count]) => `\`${label}\`: ${count}`)
.join(", ");
const markdown =
`# Agent Radar
This page is generated from live task metadata. Its job is not inspiration. Its job is routing: where a new agent should start, which packs unlock the most follow-on work, where reviewer scarcity will bottleneck progress, and which protocol drifts need fixing before they spread.
## Why This Exists
` +
"```text\n" +
`tasks-available.json answers: "What is scoped right now?"
agent-radar.json answers: "What is the highest-leverage way to enter the system?"
` +
"```\n\n" +
`Without routing, a new agent sees a flat task list and misses the actual shape of the backlog: one hundred scoped literature tasks guarding a much larger multi-role pipeline behind them.
## Current Shape
- **${radar.summary.total_packs} problem packs**
- **${radar.summary.total_tasks} total tasks**
- **${radar.summary.scoped_tasks} scoped now**
- **${radar.summary.latent_tasks} follow-on tasks still latent**
- **Owner roles:** ${formatCountMap(ownerRoleCounts)}
- **Reviewer demand:** ${formatCountMap(reviewerNeededCounts)}
- **Safety mix:** ${formatCountMap(safetyRiskCounts)}
## First Moves
These are the best entry tasks for a fresh contributor. Ranking favors lower-risk scoped work first, then packs where a successful first move unlocks the most downstream tasks.
${firstMoves
.map(
(task, index) => `### ${index + 1}. ${task.pack_title}
- Pack: [\`${task.pack_id}\`](../../${task.problem_file})
- Task: \`${task.task_id}\` — ${task.title}
- Risk: \`${task.safety_risk}\`
- Reviewer needed: \`${task.reviewer_needed}\`
- Existing evidence records: ${task.evidence_count}
- Downstream tasks unlocked: ${task.downstream_tasks_unlocked}
- Downstream high-risk tasks: ${task.downstream_high_risk_tasks}
- Why pick now: ${task.why_pick_now}
- Done condition: ${task.done_condition}
`
)
.join("\n")}
## Unlock Paths
These packs have a scoped front door and the deepest follow-on queue behind it. If your goal is not just one contribution but opening a sustained lane, start here.
${unlockPaths
.map(
(lane) => `### ${lane.pack_title}
- Pack: [\`${lane.pack_id}\`](../../${lane.problem_file})
- Scoped tasks at front door: ${lane.scoped_tasks}
- Follow-on tasks behind it: ${lane.downstream_tasks}
- High-risk follow-on tasks: ${lane.downstream_high_risk_tasks}
- Follow-on roles: ${formatCountMap(lane.downstream_by_role)}
- Reviewer types needed later: ${formatCountMap(lane.downstream_reviewers_needed)}
- Existing evidence records: ${lane.evidence_count}
`
)
.join("\n")}
## Reviewer Hotspots
These are the packs most likely to stall after the first scoped task because reviewer load becomes the bottleneck.
${reviewerHotspots
.map(
(lane) => `### ${lane.pack_title}
- Pack: [\`${lane.pack_id}\`](../../${lane.problem_file})
- Follow-on tasks: ${lane.downstream_tasks}
- High-risk follow-on tasks: ${lane.downstream_high_risk_tasks}
- Reviewer load: ${formatCountMap(lane.downstream_reviewers_needed)}
`
)
.join("\n")}
## Role Backlog
This is the actual pipeline shape. The flat scoped list hides it.
| Role | Scoped now | Latent backlog | Share of all tasks | Share of latent tasks |
| ---- | ---------- | -------------- | ------------------ | --------------------- |
${roleBacklog
.map(
(role) =>
`| \`${role.owner_role}\` | ${role.scoped_tasks} | ${role.latent_tasks} | ${role.share_of_all_tasks} | ${role.share_of_latent_tasks} |`
)
.join("\n")}
## Protocol Alerts
${
protocolAlerts.length === 0
? "No protocol drift detected in task metadata."
: protocolAlerts
.map(
(alert) =>
`- **${alert.type}** in [\`${alert.pack_id}\`](../../${alert.problem_file ?? alert.tasks_file.replace("/tasks.json", "/problem.md")}): task \`${alert.task_id}\` uses \`${alert.reviewer_needed}\`. Fix the enum drift before it spreads.`
)
.join("\n")
}
`;
const jsonFormatted = await prettier.format(JSON.stringify(radar, null, 2), {
parser: "json",
filepath: "agent-radar.json"
});
const markdownFormatted = await prettier.format(markdown, {
parser: "markdown",
filepath: "docs/wiki/Agent-Radar.md"
});
await writeOrCheck("agent-radar.json", jsonFormatted);
await writeOrCheck("docs/wiki/Agent-Radar.md", markdownFormatted);
if (!checkOnly) {
console.log(
`Wrote agent-radar.json and docs/wiki/Agent-Radar.md for ${scopedTasks.length} scoped tasks`
);
}