@windyroad/risk-scorer 0.19.9 → 0.19.10-preview.1276
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.
|
@@ -341,17 +341,25 @@ function registrationCandidates(input, role, target) {
|
|
|
341
341
|
reapRegisteredTransport();
|
|
342
342
|
if (!existsSync(transportDir())) return [];
|
|
343
343
|
const current = directoryBinding(input.cwd || process.cwd());
|
|
344
|
-
|
|
344
|
+
const registrations = readdirSync(transportDir())
|
|
345
345
|
.filter((name) => /^registration-[a-f0-9]{64}\.json$/.test(name))
|
|
346
346
|
.flatMap((name) => {
|
|
347
347
|
const path = join(transportDir(), name);
|
|
348
348
|
try {
|
|
349
349
|
const registered = JSON.parse(readFileSync(path, "utf8"));
|
|
350
|
-
if (registered.role !== role
|
|
350
|
+
if (registered.role !== role) return [];
|
|
351
351
|
if (role !== "wr-risk-scorer:pipeline" && (!current || registered.root !== current.root || registered.physical !== current.physical)) return [];
|
|
352
352
|
return [{ path, registered }];
|
|
353
353
|
} catch { return []; }
|
|
354
354
|
});
|
|
355
|
+
const exact = registrations.filter(({ registered }) => registered.target === target);
|
|
356
|
+
if (exact.length) return exact;
|
|
357
|
+
// Current Codex returns a task name at spawn and a child UUID at stop.
|
|
358
|
+
// The runtime parent session plus one invoking-checkout registration binds them.
|
|
359
|
+
if (input.hook_event_name !== "SubagentStop" || !current) return [];
|
|
360
|
+
return registrations.filter(({ registered }) =>
|
|
361
|
+
registered.parentSession === input.session_id &&
|
|
362
|
+
registered.root === current.root && registered.physical === current.physical);
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
function singleLine(output, label) {
|
|
@@ -412,14 +420,15 @@ function registrationValid(input, registered) {
|
|
|
412
420
|
|
|
413
421
|
function persistRegisteredPending(input) {
|
|
414
422
|
const role = input.agent_type;
|
|
415
|
-
const
|
|
416
|
-
if (!riskAgentRoles.has(role) || !
|
|
417
|
-
const candidates = registrationCandidates(input, role,
|
|
423
|
+
const reportedTarget = normalizeTarget(input.task_name || input.agent_name || input.agent_id);
|
|
424
|
+
if (!riskAgentRoles.has(role) || !reportedTarget) return false;
|
|
425
|
+
const candidates = registrationCandidates(input, role, reportedTarget);
|
|
418
426
|
if (candidates.length !== 1) {
|
|
419
427
|
diagnoseSubagentStop(input, "rejected", candidates.length ? "ambiguous-parent-registration" : "missing-parent-registration");
|
|
420
428
|
return false;
|
|
421
429
|
}
|
|
422
430
|
const { registered } = candidates[0];
|
|
431
|
+
const target = registered.target;
|
|
423
432
|
if (!registrationValid(input, registered)) return true;
|
|
424
433
|
let rejection;
|
|
425
434
|
const assessment = applicableAssessment(role, input.last_assistant_message, registered, (reason) => { rejection = reason; });
|
|
@@ -472,7 +481,17 @@ function consumeRegisteredPending(input) {
|
|
|
472
481
|
const claim = `${path}.claim`;
|
|
473
482
|
try { writeFileSync(claim, "", { flag: "wx", mode: 0o600 }); }
|
|
474
483
|
catch (error) { if (error?.code === "EEXIST") continue; throw error; }
|
|
484
|
+
let targetClaim;
|
|
475
485
|
try {
|
|
486
|
+
const targetInput = { session_id: pending.parentSession };
|
|
487
|
+
targetClaim = claimTarget(targetInput, pending.target);
|
|
488
|
+
if (!targetClaim) {
|
|
489
|
+
if (existsSync(statePath(targetInput, pending.target, ".done"))) {
|
|
490
|
+
renameSync(path, `${path}.done`);
|
|
491
|
+
rmSync(transportRegistrationPath(pending.parentSession, pending.role, pending.target), { force: true });
|
|
492
|
+
}
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
476
495
|
const markerRoot = pending.role === "wr-risk-scorer:pipeline" ? pending.assessmentRoot : pending.root;
|
|
477
496
|
const synthetic = { ...input, session_id: pending.parentSession, cwd: markerRoot, tool_name: "Agent",
|
|
478
497
|
tool_input: { subagent_type: pending.role, prompt: "" }, tool_response: { content: [{ type: "text", text: pending.output }] } };
|
|
@@ -483,10 +502,14 @@ function consumeRegisteredPending(input) {
|
|
|
483
502
|
}
|
|
484
503
|
const assessedAt = new Date(pending.completedAt);
|
|
485
504
|
for (const marker of markerPaths(pending.role, pending.parentSession, pending)) if (existsSync(marker)) utimesSync(marker, assessedAt, assessedAt);
|
|
505
|
+
renameSync(targetClaim.claim, targetClaim.done);
|
|
486
506
|
renameSync(path, `${path}.done`);
|
|
487
507
|
rmSync(transportRegistrationPath(pending.parentSession, pending.role, pending.target), { force: true });
|
|
488
|
-
rmSync(statePath(
|
|
489
|
-
} finally {
|
|
508
|
+
rmSync(statePath(targetInput, pending.target), { force: true });
|
|
509
|
+
} finally {
|
|
510
|
+
if (targetClaim) rmSync(targetClaim.claim, { force: true });
|
|
511
|
+
rmSync(claim, { force: true });
|
|
512
|
+
}
|
|
490
513
|
}
|
|
491
514
|
}
|
|
492
515
|
|
package/package.json
CHANGED