@lawrenceliang-btc/atel-sdk 1.1.16 → 1.1.18
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/bin/atel.mjs +24 -0
- package/package.json +1 -1
package/bin/atel.mjs
CHANGED
|
@@ -3679,6 +3679,28 @@ ${callbackFailed}
|
|
|
3679
3679
|
return;
|
|
3680
3680
|
}
|
|
3681
3681
|
if (localAction.ok && !localAction.skipped) {
|
|
3682
|
+
// Guard: if agent hook already submitted via its own shell command during execution,
|
|
3683
|
+
// the milestone status will have changed. Re-check before double-submitting.
|
|
3684
|
+
const guardCmd = localAction.action?.command;
|
|
3685
|
+
const needsGuard = ['milestone_rejected', 'milestone_verified', 'milestone_plan_confirmed'].includes(hookEvent)
|
|
3686
|
+
&& Array.isArray(guardCmd) && guardCmd[0] === 'atel' && guardCmd[1] === 'milestone-submit' && guardCmd[2];
|
|
3687
|
+
const guardCheck = needsGuard
|
|
3688
|
+
? fetch(`${PLATFORM_URL}/trade/v1/order/${guardCmd[2]}/milestones`, { signal: AbortSignal.timeout(8000) })
|
|
3689
|
+
.then(r => r.ok ? r.json() : null)
|
|
3690
|
+
.then(state => {
|
|
3691
|
+
if (!state) return false;
|
|
3692
|
+
const idx = Number.parseInt(String(guardCmd[3]), 10);
|
|
3693
|
+
const ms = Array.isArray(state?.milestones) ? state.milestones.find(m => m.index === idx) : null;
|
|
3694
|
+
return ms && ms.status === 'submitted';
|
|
3695
|
+
})
|
|
3696
|
+
.catch(() => false)
|
|
3697
|
+
: Promise.resolve(false);
|
|
3698
|
+
guardCheck.then(alreadySubmitted => {
|
|
3699
|
+
if (alreadySubmitted) {
|
|
3700
|
+
log({ event: 'agent_cmd_done', eventType: hookEvent, mode: 'already_submitted_by_agent', dedupeKey: hookKey });
|
|
3701
|
+
finishHook();
|
|
3702
|
+
return;
|
|
3703
|
+
}
|
|
3682
3704
|
executeRecommendedActionDirect(hookEvent, localAction.action, hookCwd || process.cwd(), hookKey)
|
|
3683
3705
|
.then((execResult) => {
|
|
3684
3706
|
if (execResult.ok) {
|
|
@@ -3693,6 +3715,8 @@ ${callbackFailed}
|
|
|
3693
3715
|
finishHook();
|
|
3694
3716
|
});
|
|
3695
3717
|
return;
|
|
3718
|
+
}); // guardCheck.then
|
|
3719
|
+
return;
|
|
3696
3720
|
}
|
|
3697
3721
|
|
|
3698
3722
|
log({ event: 'agent_cmd_done', eventType: hookEvent, stdout: summarizeAgentOutput(stdout, 300) });
|