@lawrenceliang-btc/atel-sdk 1.1.17 → 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 +21 -17
- package/package.json +1 -1
package/bin/atel.mjs
CHANGED
|
@@ -3681,23 +3681,25 @@ ${callbackFailed}
|
|
|
3681
3681
|
if (localAction.ok && !localAction.skipped) {
|
|
3682
3682
|
// Guard: if agent hook already submitted via its own shell command during execution,
|
|
3683
3683
|
// the milestone status will have changed. Re-check before double-submitting.
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
const
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
}
|
|
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;
|
|
3701
3703
|
}
|
|
3702
3704
|
executeRecommendedActionDirect(hookEvent, localAction.action, hookCwd || process.cwd(), hookKey)
|
|
3703
3705
|
.then((execResult) => {
|
|
@@ -3713,6 +3715,8 @@ ${callbackFailed}
|
|
|
3713
3715
|
finishHook();
|
|
3714
3716
|
});
|
|
3715
3717
|
return;
|
|
3718
|
+
}); // guardCheck.then
|
|
3719
|
+
return;
|
|
3716
3720
|
}
|
|
3717
3721
|
|
|
3718
3722
|
log({ event: 'agent_cmd_done', eventType: hookEvent, stdout: summarizeAgentOutput(stdout, 300) });
|