@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.
Files changed (2) hide show
  1. package/bin/atel.mjs +21 -17
  2. 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
- if (['milestone_rejected', 'milestone_verified', 'milestone_plan_confirmed'].includes(hookEvent)) {
3685
- const guardCmd = localAction.action?.command;
3686
- if (Array.isArray(guardCmd) && guardCmd[0] === 'atel' && guardCmd[1] === 'milestone-submit' && guardCmd[2]) {
3687
- try {
3688
- const guardResp = await fetch(`${PLATFORM_URL}/trade/v1/order/${guardCmd[2]}/milestones`, { signal: AbortSignal.timeout(8000) });
3689
- if (guardResp.ok) {
3690
- const guardState = await guardResp.json();
3691
- const guardIdx = Number.parseInt(String(guardCmd[3]), 10);
3692
- const guardMs = Array.isArray(guardState?.milestones) ? guardState.milestones.find(m => m.index === guardIdx) : null;
3693
- if (guardMs && guardMs.status === 'submitted') {
3694
- log({ event: 'agent_cmd_done', eventType: hookEvent, mode: 'already_submitted_by_agent', dedupeKey: hookKey });
3695
- finishHook();
3696
- return;
3697
- }
3698
- }
3699
- } catch {}
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) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawrenceliang-btc/atel-sdk",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "ATEL Protocol SDK - Agent Trust & Exchange Layer",
5
5
  "repository": {
6
6
  "type": "git",