@senpi-ai/runtime 3.0.13 → 3.0.35

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 (198) hide show
  1. package/README.md +7 -4
  2. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  3. package/dist/actions/close-position/close-position.action.js +2 -7
  4. package/dist/actions/close-position/close-position.action.js.map +1 -1
  5. package/dist/actions/decision-error-notification.d.ts +35 -0
  6. package/dist/actions/decision-error-notification.d.ts.map +1 -0
  7. package/dist/actions/decision-error-notification.js +58 -0
  8. package/dist/actions/decision-error-notification.js.map +1 -0
  9. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  10. package/dist/actions/open-position/open-position.action.js +50 -7
  11. package/dist/actions/open-position/open-position.action.js.map +1 -1
  12. package/dist/actions/types.d.ts +2 -0
  13. package/dist/actions/types.d.ts.map +1 -1
  14. package/dist/approvals/approval-store.d.ts +35 -0
  15. package/dist/approvals/approval-store.d.ts.map +1 -0
  16. package/dist/approvals/approval-store.js +87 -0
  17. package/dist/approvals/approval-store.js.map +1 -0
  18. package/dist/approvals/manifest.d.ts +47 -0
  19. package/dist/approvals/manifest.d.ts.map +1 -0
  20. package/dist/approvals/manifest.js +90 -0
  21. package/dist/approvals/manifest.js.map +1 -0
  22. package/dist/approvals/telemetry.d.ts +41 -0
  23. package/dist/approvals/telemetry.d.ts.map +1 -0
  24. package/dist/approvals/telemetry.js +35 -0
  25. package/dist/approvals/telemetry.js.map +1 -0
  26. package/dist/approvals/tool-approval-gate.d.ts +96 -0
  27. package/dist/approvals/tool-approval-gate.d.ts.map +1 -0
  28. package/dist/approvals/tool-approval-gate.js +233 -0
  29. package/dist/approvals/tool-approval-gate.js.map +1 -0
  30. package/dist/approvals/tool-approvals-manifest.json +27 -0
  31. package/dist/cli/guide-commands.d.ts.map +1 -1
  32. package/dist/cli/guide-commands.js +6 -7
  33. package/dist/cli/guide-commands.js.map +1 -1
  34. package/dist/cli/senpi-cli-config.d.ts +0 -17
  35. package/dist/cli/senpi-cli-config.d.ts.map +1 -1
  36. package/dist/cli/senpi-cli-config.js +0 -30
  37. package/dist/cli/senpi-cli-config.js.map +1 -1
  38. package/dist/cli/senpi-config-commands.d.ts +1 -1
  39. package/dist/cli/senpi-config-commands.d.ts.map +1 -1
  40. package/dist/cli/senpi-config-commands.js +1 -16
  41. package/dist/cli/senpi-config-commands.js.map +1 -1
  42. package/dist/constants/dsl/index.d.ts +1 -5
  43. package/dist/constants/dsl/index.d.ts.map +1 -1
  44. package/dist/constants/dsl/index.js +1 -5
  45. package/dist/constants/dsl/index.js.map +1 -1
  46. package/dist/dsl/engine-client/event-mapping.d.ts +1 -1
  47. package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
  48. package/dist/dsl/engine-client/event-mapping.js +6 -0
  49. package/dist/dsl/engine-client/event-mapping.js.map +1 -1
  50. package/dist/dsl/events/build-closed-event.d.ts +1 -1
  51. package/dist/dsl/events/build-closed-event.js +1 -1
  52. package/dist/dsl/events/handlers.js +1 -1
  53. package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
  54. package/dist/dsl/monitor/process-one-position.js +5 -3
  55. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  56. package/dist/dsl/notifications/format-utils.d.ts +1 -11
  57. package/dist/dsl/notifications/format-utils.d.ts.map +1 -1
  58. package/dist/dsl/notifications/format-utils.js +1 -48
  59. package/dist/dsl/notifications/format-utils.js.map +1 -1
  60. package/dist/dsl/notifications/formatter.d.ts +17 -28
  61. package/dist/dsl/notifications/formatter.d.ts.map +1 -1
  62. package/dist/dsl/notifications/formatter.js +46 -129
  63. package/dist/dsl/notifications/formatter.js.map +1 -1
  64. package/dist/dsl/notifications/index.d.ts +2 -10
  65. package/dist/dsl/notifications/index.d.ts.map +1 -1
  66. package/dist/dsl/notifications/index.js +127 -50
  67. package/dist/dsl/notifications/index.js.map +1 -1
  68. package/dist/dsl/notifications/raise-correlator.d.ts +87 -0
  69. package/dist/dsl/notifications/raise-correlator.d.ts.map +1 -0
  70. package/dist/dsl/notifications/raise-correlator.js +136 -0
  71. package/dist/dsl/notifications/raise-correlator.js.map +1 -0
  72. package/dist/dsl/notifications/stop-raise-ratchet.d.ts +76 -0
  73. package/dist/dsl/notifications/stop-raise-ratchet.d.ts.map +1 -0
  74. package/dist/dsl/notifications/stop-raise-ratchet.js +113 -0
  75. package/dist/dsl/notifications/stop-raise-ratchet.js.map +1 -0
  76. package/dist/dsl/plugin/index.d.ts.map +1 -1
  77. package/dist/dsl/plugin/index.js +0 -27
  78. package/dist/dsl/plugin/index.js.map +1 -1
  79. package/dist/dsl/plugin/options.d.ts +3 -7
  80. package/dist/dsl/plugin/options.d.ts.map +1 -1
  81. package/dist/index.d.ts +15 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +70 -142
  84. package/dist/index.js.map +1 -1
  85. package/dist/prompt/session-context-seed-hook.d.ts +11 -0
  86. package/dist/prompt/session-context-seed-hook.d.ts.map +1 -0
  87. package/dist/prompt/session-context-seed-hook.js +99 -0
  88. package/dist/prompt/session-context-seed-hook.js.map +1 -0
  89. package/dist/runtime/auto-update/coordinator.d.ts +39 -15
  90. package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
  91. package/dist/runtime/auto-update/coordinator.js +152 -34
  92. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  93. package/dist/runtime/auto-update/gateway-restart.d.ts +4 -4
  94. package/dist/runtime/auto-update/gateway-restart.js +4 -4
  95. package/dist/runtime/auto-update/types.d.ts +1 -0
  96. package/dist/runtime/auto-update/types.d.ts.map +1 -1
  97. package/dist/runtime/auto-update/types.js.map +1 -1
  98. package/dist/runtime/backend-pause-registry.d.ts +38 -0
  99. package/dist/runtime/backend-pause-registry.d.ts.map +1 -0
  100. package/dist/runtime/backend-pause-registry.js +51 -0
  101. package/dist/runtime/backend-pause-registry.js.map +1 -0
  102. package/dist/runtime/create-action-context.d.ts.map +1 -1
  103. package/dist/runtime/create-action-context.js +1 -0
  104. package/dist/runtime/create-action-context.js.map +1 -1
  105. package/dist/runtime/create-runtime-context.d.ts +1 -0
  106. package/dist/runtime/create-runtime-context.d.ts.map +1 -1
  107. package/dist/runtime/create-runtime-context.js +3 -0
  108. package/dist/runtime/create-runtime-context.js.map +1 -1
  109. package/dist/runtime/decision-errors.d.ts +46 -53
  110. package/dist/runtime/decision-errors.d.ts.map +1 -1
  111. package/dist/runtime/decision-errors.js +72 -111
  112. package/dist/runtime/decision-errors.js.map +1 -1
  113. package/dist/runtime/notifications.d.ts +37 -16
  114. package/dist/runtime/notifications.d.ts.map +1 -1
  115. package/dist/runtime/notifications.js +211 -67
  116. package/dist/runtime/notifications.js.map +1 -1
  117. package/dist/runtime/runtime.d.ts +16 -2
  118. package/dist/runtime/runtime.d.ts.map +1 -1
  119. package/dist/runtime/runtime.js +109 -31
  120. package/dist/runtime/runtime.js.map +1 -1
  121. package/dist/runtime/strategy-lifecycle.d.ts +23 -9
  122. package/dist/runtime/strategy-lifecycle.d.ts.map +1 -1
  123. package/dist/runtime/strategy-lifecycle.js +90 -38
  124. package/dist/runtime/strategy-lifecycle.js.map +1 -1
  125. package/dist/runtime/supervisor/long-running-supervisor.js +3 -3
  126. package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
  127. package/dist/runtime-api/lifecycle.d.ts +1 -1
  128. package/dist/runtime-api/lifecycle.js +1 -1
  129. package/dist/scanners/providers/client.d.ts.map +1 -1
  130. package/dist/scanners/providers/client.js +4 -1
  131. package/dist/scanners/providers/client.js.map +1 -1
  132. package/dist/scanners/providers/factory.d.ts.map +1 -1
  133. package/dist/scanners/providers/factory.js +43 -2
  134. package/dist/scanners/providers/factory.js.map +1 -1
  135. package/dist/scanners/runtime-module.d.ts.map +1 -1
  136. package/dist/scanners/runtime-module.js +35 -0
  137. package/dist/scanners/runtime-module.js.map +1 -1
  138. package/dist/scripts/run-dsl-standalone-live.d.ts +8 -6
  139. package/dist/scripts/run-dsl-standalone-live.d.ts.map +1 -1
  140. package/dist/scripts/run-dsl-standalone-live.js +26 -25
  141. package/dist/scripts/run-dsl-standalone-live.js.map +1 -1
  142. package/dist/senpi/client.d.ts.map +1 -1
  143. package/dist/senpi/client.js +10 -3
  144. package/dist/senpi/client.js.map +1 -1
  145. package/dist/senpi/tool-errors.d.ts +30 -0
  146. package/dist/senpi/tool-errors.d.ts.map +1 -0
  147. package/dist/senpi/tool-errors.js +87 -0
  148. package/dist/senpi/tool-errors.js.map +1 -0
  149. package/dist/senpi/types.d.ts +4 -0
  150. package/dist/senpi/types.d.ts.map +1 -1
  151. package/dist/skills-manager/coordinator.d.ts +2 -2
  152. package/dist/skills-manager/coordinator.js +2 -2
  153. package/dist/telemetry/metrics.d.ts +11 -0
  154. package/dist/telemetry/metrics.d.ts.map +1 -1
  155. package/dist/telemetry/metrics.js +22 -0
  156. package/dist/telemetry/metrics.js.map +1 -1
  157. package/dist/test-setup.d.ts +2 -0
  158. package/dist/test-setup.d.ts.map +1 -0
  159. package/dist/test-setup.js +21 -0
  160. package/dist/test-setup.js.map +1 -0
  161. package/dist/types/dsl/index.d.ts +14 -1
  162. package/dist/types/dsl/index.d.ts.map +1 -1
  163. package/dist/types/notification.d.ts +102 -1
  164. package/dist/types/notification.d.ts.map +1 -1
  165. package/dist/types/notification.js +80 -1
  166. package/dist/types/notification.js.map +1 -1
  167. package/dist/types/runtime.d.ts +13 -0
  168. package/dist/types/runtime.d.ts.map +1 -1
  169. package/dist/types/session-context.d.ts +19 -0
  170. package/dist/types/session-context.d.ts.map +1 -0
  171. package/dist/types/session-context.js +20 -0
  172. package/dist/types/session-context.js.map +1 -0
  173. package/dist/utils/event-catalog.d.ts +103 -2
  174. package/dist/utils/event-catalog.d.ts.map +1 -1
  175. package/dist/utils/event-catalog.js +28 -0
  176. package/dist/utils/event-catalog.js.map +1 -1
  177. package/dist/utils/logger.d.ts +2 -18
  178. package/dist/utils/logger.d.ts.map +1 -1
  179. package/dist/utils/logger.js +2 -40
  180. package/dist/utils/logger.js.map +1 -1
  181. package/openclaw.plugin.json +10 -1
  182. package/package.json +3 -2
  183. package/dist/actions/notifications/formatter.d.ts +0 -39
  184. package/dist/actions/notifications/formatter.d.ts.map +0 -1
  185. package/dist/actions/notifications/formatter.js +0 -68
  186. package/dist/actions/notifications/formatter.js.map +0 -1
  187. package/dist/actions/notifications/index.d.ts +0 -37
  188. package/dist/actions/notifications/index.d.ts.map +0 -1
  189. package/dist/actions/notifications/index.js +0 -89
  190. package/dist/actions/notifications/index.js.map +0 -1
  191. package/dist/dsl/notifications/close-resolver.d.ts +0 -92
  192. package/dist/dsl/notifications/close-resolver.d.ts.map +0 -1
  193. package/dist/dsl/notifications/close-resolver.js +0 -309
  194. package/dist/dsl/notifications/close-resolver.js.map +0 -1
  195. package/dist/dsl/notifications/types.d.ts +0 -27
  196. package/dist/dsl/notifications/types.d.ts.map +0 -1
  197. package/dist/dsl/notifications/types.js +0 -5
  198. package/dist/dsl/notifications/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/format-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmBH;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAYjE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI1C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBpE;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKhD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAAG,OAAO,GAC1B,MAAM,CAUR"}
1
+ {"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/format-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmBH;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAYjE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI1C"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * User-facing number formatting for DSL Telegram notifications (smart decimals, signs, duration).
2
+ * User-facing number formatting for DSL notifications (smart decimals, signs).
3
3
  */
4
4
  /**
5
5
  * Strip `xyz:` prefix for major-coin detection.
@@ -52,51 +52,4 @@ export function fmtRoe(pct) {
52
52
  const sign = pct >= 0 ? "+" : "";
53
53
  return `${sign}${pct.toFixed(1)}%`;
54
54
  }
55
- /**
56
- * Human duration between two ISO timestamps: `45m`, `2h 30m`, `1d 2h`.
57
- */
58
- export function fmtDuration(startIso, endIso) {
59
- const a = Date.parse(startIso);
60
- const b = Date.parse(endIso);
61
- if (!Number.isFinite(a) || !Number.isFinite(b))
62
- return "—";
63
- let ms = Math.max(0, b - a);
64
- const days = Math.floor(ms / (24 * 60 * 60 * 1000));
65
- ms -= days * 24 * 60 * 60 * 1000;
66
- const hours = Math.floor(ms / (60 * 60 * 1000));
67
- ms -= hours * 60 * 60 * 1000;
68
- const minutes = Math.floor(ms / (60 * 1000));
69
- if (days > 0) {
70
- return hours > 0 ? `${days}d ${hours}h` : `${days}d`;
71
- }
72
- if (hours > 0) {
73
- return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
74
- }
75
- return `${minutes}m`;
76
- }
77
- /** Collateral display: trim meaningless trailing zeros (e.g. $500, $493.20). */
78
- export function fmtMargin(amount) {
79
- if (!Number.isFinite(amount))
80
- return "$0";
81
- const ap = Math.abs(amount);
82
- const digits = ap >= 100 ? 0 : ap >= 1 ? 2 : 4;
83
- return formatUsdWithCommas(amount, digits);
84
- }
85
- /**
86
- * Signed distance from entry to protective floor as a negative percentage (user-facing buffer).
87
- */
88
- export function fmtFloorDistancePct(entry, floor, direction) {
89
- if (!Number.isFinite(entry) || entry === 0 || !Number.isFinite(floor))
90
- return "0.0%";
91
- let pct;
92
- if (direction === "LONG") {
93
- pct = ((floor - entry) / entry) * 100;
94
- }
95
- else {
96
- pct = ((entry - floor) / entry) * 100;
97
- }
98
- if (pct > 0)
99
- pct = -pct;
100
- return `${pct.toFixed(1)}%`;
101
- }
102
55
  //# sourceMappingURL=format-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-utils.js","sourceRoot":"","sources":["../../../src/dsl/notifications/format-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACvB,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,mBAAmB,CAAC,CAAS,EAAE,cAAsB;IAC5D,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QACpC,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,KAAK;QACf,qBAAqB,EAAE,cAAc;QACrC,qBAAqB,EAAE,cAAc;KACtC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAc;IACvD,IAAI,CAAC,MAAM,CAAC,QAAQ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AC,CAAC;SAC5B,IAAI,EAAE,GAAG,GAAG;QAAE,MAAM,GAAG,CAAC,CAAC;;QACzB,MAAM,GAAG,CAAC,CAAC;IAChB,OAAO,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,OAAO,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,OAAO,GAAG,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;AACpD,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IACzC,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACjC,OAAO,GAAG,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;AACrC,CAAC"}
@@ -1,37 +1,26 @@
1
1
  /**
2
- * Plain-text messages for DSL lifecycle Telegram notifications.
2
+ * Plain-text messages for DSL lifecycle notifications.
3
3
  */
4
- import type { DslCreatedEvent, DslTierAdvancedEvent, DslSlUpdatedEvent, DslHeartbeatEvent } from "../../types/dsl/index.js";
5
- import type { PendingCloseNotification } from "./types.js";
4
+ import type { DslCreatedEvent, DslTierAdvancedEvent, DslSlUpdatedEvent } from "../../types/dsl/index.js";
5
+ import type { NotificationCopy } from "../../types/notification.js";
6
6
  /**
7
- * User-facing line for `dsl.created`. Returns `null` when the position change should stay silent
8
- * (increase / decrease / flip rebuilds).
7
+ * DSL-activated notification: fired when the runtime attaches a trailing DSL at
8
+ * position open. Label-free — the DSL subscriber applies the `[strategy]` prefix
9
+ * (and push-title truncation) before it ships. Every value comes from the event.
10
+ *
11
+ * The title carries the position and opts out of the label: the label plus the
12
+ * position would not fit the 32-unit push-title budget, and the position is what
13
+ * a glance needs. The body still ships the label.
9
14
  */
10
- export declare function formatDslCreated(e: DslCreatedEvent): string | null;
15
+ export declare function formatDslCreated(e: DslCreatedEvent): NotificationCopy;
11
16
  /**
12
- * Tier / profit-lock notification.
17
+ * Tier / profit-lock notification. Label-free — the DSL subscriber applies the
18
+ * `[strategy]` prefix (and push-title truncation) before it ships.
13
19
  */
14
- export declare function formatDslTierAdvanced(e: DslTierAdvancedEvent): string;
15
- export declare function formatDslSlUpdated(e: DslSlUpdatedEvent): string;
16
- export declare function formatDslClosePending(e: {
17
- asset: string;
18
- attempt: number;
19
- }): string;
20
- export declare function plainEnglishCloseReason(closeReason: string): string;
21
- export interface CloseEnrichment {
22
- realizedPnl: number;
23
- closePx: number;
24
- totalFees: number;
25
- }
20
+ export declare function formatDslTierAdvanced(e: DslTierAdvancedEvent): NotificationCopy;
26
21
  /**
27
- * Full three-line close when trade history matched.
22
+ * Stop-raise notification. Label-free — the DSL subscriber applies the
23
+ * `[strategy]` prefix (and push-title truncation) before it ships.
28
24
  */
29
- export declare function formatDslClosedEnriched(p: PendingCloseNotification, x: CloseEnrichment): string;
30
- /** Timeout path: no reliable exit PnL from history. */
31
- export declare function formatDslClosedFallback(p: PendingCloseNotification): string;
32
- export declare function formatDslDeleted(e: {
33
- asset: string;
34
- dex?: string;
35
- }): string;
36
- export declare function formatDslHeartbeat(e: DslHeartbeatEvent): string;
25
+ export declare function formatDslSlUpdated(e: DslSlUpdatedEvent): NotificationCopy;
37
26
  //# sourceMappingURL=formatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,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ClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAOpE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,eAAe,GAAG,gBAAgB,CAsBrE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,oBAAoB,GAAG,gBAAgB,CAgB/E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CAOzE"}
@@ -1,35 +1,43 @@
1
1
  /**
2
- * Plain-text messages for DSL lifecycle Telegram notifications.
2
+ * Plain-text messages for DSL lifecycle notifications.
3
3
  */
4
- import { fmtUsdPrice, fmtUsdPnl, fmtRoe, fmtDuration, fmtMargin, fmtFloorDistancePct, } from "./format-utils.js";
5
- function fmtDex(dex) {
6
- return dex ? ` (${dex})` : "";
7
- }
8
- function fmtLeverage(leverage) {
9
- const n = Number.isFinite(leverage) && leverage > 0 ? leverage : 1;
10
- return `${Number.isInteger(n) ? n : n.toFixed(1)}x`;
11
- }
4
+ import { fmtUsdPrice, fmtUsdPnl, fmtRoe, } from "./format-utils.js";
12
5
  /**
13
- * User-facing line for `dsl.created`. Returns `null` when the position change should stay silent
14
- * (increase / decrease / flip rebuilds).
6
+ * DSL-activated notification: fired when the runtime attaches a trailing DSL at
7
+ * position open. Label-free — the DSL subscriber applies the `[strategy]` prefix
8
+ * (and push-title truncation) before it ships. Every value comes from the event.
9
+ *
10
+ * The title carries the position and opts out of the label: the label plus the
11
+ * position would not fit the 32-unit push-title budget, and the position is what
12
+ * a glance needs. The body still ships the label.
15
13
  */
16
14
  export function formatDslCreated(e) {
17
- if (e.triggerReason !== "position_opened")
18
- return null;
19
- const dex = fmtDex(e.dex);
20
- const dist = fmtFloorDistancePct(e.entryPrice, e.floorPrice, e.direction);
21
- const lev = e.leverage != null && Number.isFinite(e.leverage) ? e.leverage : 1;
22
- const line1 = `Opened ${e.asset}${dex} ${e.direction} at ${fmtUsdPrice(e.entryPrice, e.asset)} · ${fmtLeverage(lev)} · ${fmtMargin(e.margin ?? 0)} margin`;
23
- const line2 = `DSL active: ${fmtUsdPrice(e.floorPrice, e.asset)} (${dist} from entry)`;
24
- return `${line1}\n${line2}`;
15
+ const asset = e.asset;
16
+ // Ticker as the app renders it; the raw symbol still drives price decimals.
17
+ const ticker = `$${asset}`;
18
+ const direction = e.direction;
19
+ const leverage = e.leverage;
20
+ // % gap between entry and the initial stop floor; abs so LONG (floor below) and
21
+ // SHORT (floor above) both read as a positive distance "away".
22
+ const distPct = Number.isFinite(e.entryPrice) && e.entryPrice !== 0
23
+ ? Math.abs((e.entryPrice - e.floorPrice) / e.entryPrice) * 100
24
+ : 0;
25
+ const dist = fmtRoe(distPct);
26
+ const position = `${ticker} ${direction} ${leverage}×`;
27
+ return {
28
+ pushTitle: `DSL activated on ${position}`,
29
+ skipTitleLabel: true,
30
+ pushBody: `DSL activated on ${position}`,
31
+ inApp: `DSL activated on ${position} — ` +
32
+ `stop at ${fmtUsdPrice(e.floorPrice, asset)} (${dist} away) — trails up as the trade gains.`,
33
+ };
25
34
  }
26
35
  /**
27
- * Tier / profit-lock notification.
36
+ * Tier / profit-lock notification. Label-free — the DSL subscriber applies the
37
+ * `[strategy]` prefix (and push-title truncation) before it ships.
28
38
  */
29
39
  export function formatDslTierAdvanced(e) {
30
- const dex = fmtDex(e.dex ?? "");
31
- const tierNum = e.tier + 1;
32
- const label = `T${tierNum}`;
40
+ const asset = e.asset;
33
41
  const margin = e.margin ?? 0;
34
42
  const lockedPct = e.lockedProfitPct ?? 0;
35
43
  const lockedUsd = margin * (lockedPct / 100);
@@ -37,114 +45,23 @@ export function formatDslTierAdvanced(e) {
37
45
  const hw = e.highWaterRoe ?? 0;
38
46
  const currentPnl = margin * (curRoe / 100);
39
47
  const direction = e.direction ?? "LONG";
40
- const line1 = `${e.asset}${dex} ${direction} — DSL ${label} 🔒 min ${fmtUsdPnl(lockedUsd)} (${fmtRoe(lockedPct)})`;
41
- const line2 = `Stop raised to ${fmtUsdPrice(e.newFloorPrice, e.asset)} · Current: ${fmtUsdPnl(currentPnl)} (${fmtRoe(curRoe)}) · High: ${fmtRoe(hw)}`;
42
- const line3 = `Position still live — trailing for more.`;
43
- return [line1, line2, line3].join("\n");
44
- }
45
- export function formatDslSlUpdated(e) {
46
- const dex = fmtDex(e.dex ?? "");
47
- return `DSL SL updated: ${e.asset}${dex} — ${fmtUsdPrice(e.newSLPrice, e.asset)}`;
48
- }
49
- export function formatDslClosePending(e) {
50
- return `DSL close pending: ${e.asset} (attempt ${e.attempt})`;
51
- }
52
- const CLOSE_REASON_LABEL = {
53
- exchange_sl_hit: "Exchange SL hit",
54
- dsl_breach: "DSL breach",
55
- hard_timeout: "DSL hard timeout",
56
- weak_peak_cut: "DSL weak peak cut",
57
- dead_weight_cut: "DSL dead weight cut",
58
- close_position_failed: "DSL close failed",
59
- backend_sl_triggered: "Exchange SL hit",
60
- backend_manually_closed: "Position manually closed",
61
- backend_liquidated: "Position liquidated",
62
- backend_adl: "Position auto-deleveraged",
63
- backend_deleted: "DSL deleted",
64
- backend_closed: "Position closed",
65
- manual_close: "Manual close",
66
- closed_externally: "Closed externally",
67
- flipped: "Position flipped",
68
- manual: "Manual close",
69
- dsl_deleted: "DSL removed",
70
- position_increased: "Position increased",
71
- position_decreased: "Position decreased",
72
- };
73
- export function plainEnglishCloseReason(closeReason) {
74
- return CLOSE_REASON_LABEL[closeReason] ?? closeReason.replace(/_/g, " ");
48
+ return {
49
+ pushTitle: "🔒 Profit locked",
50
+ pushBody: `DSL locked ${fmtUsdPnl(lockedUsd)} on ${asset}`,
51
+ inApp: `🔒 ${asset} ${direction} — DSL locked in ${fmtUsdPnl(lockedUsd)} (${fmtRoe(lockedPct)}) ` +
52
+ `Stop raised to ${fmtUsdPrice(e.newFloorPrice, asset)} · now ${fmtUsdPnl(currentPnl)} (${fmtRoe(curRoe)}) · peak ${fmtRoe(hw)} · still running, trailing for more`,
53
+ };
75
54
  }
76
55
  /**
77
- * Context-aware close reason sentence for user-facing notifications.
78
- * Uses position context (tier reached, peak ROE, duration, profitability) to produce
79
- * a plain-English explanation rather than a generic label.
56
+ * Stop-raise notification. Label-free — the DSL subscriber applies the
57
+ * `[strategy]` prefix (and push-title truncation) before it ships.
80
58
  */
81
- function buildCloseReasonText(p, realizedPnl) {
82
- const { closeReason, currentTierIndex, peakROE } = p;
83
- if (closeReason === "dsl_breach" || closeReason === "exchange_sl_hit") {
84
- if (currentTierIndex != null && currentTierIndex >= 0) {
85
- return `DSL locked profit at T${currentTierIndex + 1} and triggered on pullback.`;
86
- }
87
- return "DSL stop triggered. Position never reached profit lock.";
88
- }
89
- if (closeReason === "hard_timeout") {
90
- const startMs = Date.parse(p.createdAt);
91
- const endMs = Date.parse(p.closedAt);
92
- const hours = Number.isFinite(startMs) && Number.isFinite(endMs)
93
- ? Math.round((endMs - startMs) / (60 * 60 * 1000))
94
- : 0;
95
- const inProfit = (realizedPnl != null ? realizedPnl : p.currentROE) >= 0;
96
- const suffix = inProfit ? " Closed in profit." : " Closed at a loss.";
97
- return `DSL timeout at ${hours}h.${suffix}`;
98
- }
99
- if (closeReason === "dead_weight_cut") {
100
- return "DSL cut — position stalled with no momentum.";
101
- }
102
- if (closeReason === "weak_peak_cut") {
103
- return `DSL cut — peaked at +${(peakROE ?? 0).toFixed(1)}% ROE then faded.`;
104
- }
105
- return plainEnglishCloseReason(closeReason);
106
- }
107
- /**
108
- * Full three-line close when trade history matched.
109
- */
110
- export function formatDslClosedEnriched(p, x) {
111
- const roePct = p.margin > 0 ? (x.realizedPnl / p.margin) * 100 : (p.currentROE ?? 0);
112
- const pnlLine = `${p.asset} ${p.direction} closed — ${fmtUsdPnl(x.realizedPnl)} (${fmtRoe(roePct)})`;
113
- const entryExit = `Entry ${fmtUsdPrice(p.entryPrice, p.asset)} → Exit ${fmtUsdPrice(x.closePx, p.asset)} · ${fmtLeverage(p.leverage)} · Held ${fmtDuration(p.createdAt, p.closedAt)}`;
114
- const feeUsd = `$${Math.abs(x.totalFees).toFixed(2)}`;
115
- const fees = `Fees: ${feeUsd} · ${buildCloseReasonText(p, x.realizedPnl)}`;
116
- return `${pnlLine}\n${entryExit}\n${fees}`;
117
- }
118
- /** Timeout path: no reliable exit PnL from history. */
119
- export function formatDslClosedFallback(p) {
120
- const line1 = `${p.asset} ${p.direction} closed`;
121
- const line2 = `Entry ${fmtUsdPrice(p.entryPrice, p.asset)} · ${fmtLeverage(p.leverage)} · Held ${fmtDuration(p.createdAt, p.closedAt)}`;
122
- const line3 = buildCloseReasonText(p);
123
- return `${line1}\n${line2}\n${line3}`;
124
- }
125
- export function formatDslDeleted(e) {
126
- const dex = fmtDex(e.dex ?? "");
127
- return `DSL deleted: ${e.asset}${dex}`;
128
- }
129
- function fmtElapsedOpen(mins) {
130
- if (!Number.isFinite(mins) || mins < 0)
131
- return "—";
132
- if (mins < 60)
133
- return `${Math.round(mins)}m`;
134
- const h = Math.floor(mins / 60);
135
- const m = Math.round(mins % 60);
136
- return m > 0 ? `${h}h ${m}m` : `${h}h`;
137
- }
138
- export function formatDslHeartbeat(e) {
139
- const dex = fmtDex(e.dex);
140
- const margin = e.margin ?? 0;
141
- const currentPnl = margin * (e.currentROE / 100);
142
- const line1 = `${e.asset}${dex} ${e.direction} active for ${fmtElapsedOpen(e.elapsedMinutes)} — ${fmtUsdPnl(currentPnl)} (${fmtRoe(e.currentROE)})`;
143
- const lockedPnl = margin * ((e.lockedProfitPct ?? 0) / 100);
144
- const lockedStatus = (e.lockedProfitPct ?? 0) > 0
145
- ? `${fmtUsdPnl(lockedPnl)} profit locked`
146
- : "No profit locked yet";
147
- const line2 = `Stop at ${fmtUsdPrice(e.floorPrice, e.asset)} · ${lockedStatus}`;
148
- return [line1, line2].join("\n");
59
+ export function formatDslSlUpdated(e) {
60
+ const asset = e.asset;
61
+ return {
62
+ pushTitle: "📈 Stop raised",
63
+ pushBody: `${asset} stop → ${fmtUsdPrice(e.newSLPrice, asset)}`,
64
+ inApp: `${asset} — DSL stop raised to ${fmtUsdPrice(e.newSLPrice, asset)} Locking in more of your gain.`,
65
+ };
149
66
  }
150
67
  //# sourceMappingURL=formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/dsl/notifications/formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EACL,WAAW,EACX,SAAS,EACT,MAAM,EACN,WAAW,EACX,SAAS,EACT,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,QAAgB;IACnC,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IACjD,IAAI,CAAC,CAAC,aAAa,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IACvD,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,mBAAmB,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,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EventBus } from "../events/index.js";
5
- import type { NotificationService } from "../../types/notification.js";
6
- import { type CloseNotificationResolver } from "./close-resolver.js";
7
- export type { CloseNotificationResolver } from "./close-resolver.js";
5
+ import type { NotificationPayload, NotificationService } from "../../types/notification.js";
8
6
  export interface DslNotificationOptions {
9
- /** Also notify when the exchange SL price is updated (can fire every tick; default: false). */
10
- notifySlUpdates?: boolean;
11
7
  /**
12
8
  * Recipe name to prefix every notification message (e.g. "[my-recipe] DSL started: ...").
13
9
  * When omitted, no prefix is added.
14
10
  */
15
11
  strategyName?: string;
16
- /**
17
- * Resolves deferred close lines from trade history; when set, `dsl.closed` is enqueued instead of
18
- * notifying immediately.
19
- */
20
- closeResolver?: CloseNotificationResolver | null;
21
12
  }
22
13
  export interface DslNotificationSubscriber {
23
14
  dispose(): void;
24
15
  }
16
+ export declare function safeNotify(notifier: NotificationService, input: string | NotificationPayload): void;
25
17
  export declare function createDslNotificationSubscriber(bus: SenpiEventBus, notifier: NotificationService, options?: DslNotificationOptions): DslNotificationSubscriber;
26
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAmBvE,OAAO,EAA8B,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAIjG,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE,MAAM,WAAW,sBAAsB;IACrC,+FAA+F;IAC/F,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,IAAI,IAAI,CAAC;CACjB;AAwBD,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,aAAa,EAClB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,yBAAyB,CA4E3B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dsl/notifications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAoB,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AA+B9G,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,MAAM,GAAG,mBAAmB,GAClC,IAAI,CAWN;AAwDD,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,aAAa,EAClB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,yBAAyB,CAuG3B"}
@@ -1,22 +1,73 @@
1
1
  /**
2
2
  * Subscribes to DSL_EVENTS on the bus and forwards formatted strings to NotificationService.
3
3
  */
4
+ import { applyMessagePrefix, labelPrefix } from "../../types/notification.js";
4
5
  import { DSL_EVENTS } from "../../constants/dsl/index.js";
5
6
  import { createLogger } from "../../utils/logger.js";
6
- import { formatDslCreated, formatDslTierAdvanced, formatDslSlUpdated, formatDslClosePending, formatDslClosedFallback, formatDslDeleted, formatDslHeartbeat, } from "./formatter.js";
7
- import { buildPendingCloseFromEvent } from "./close-resolver.js";
7
+ import { randomUUID } from "node:crypto";
8
+ import { formatDslCreated, formatDslTierAdvanced, formatDslSlUpdated, } from "./formatter.js";
9
+ import { RaiseCorrelator, raiseKey } from "./raise-correlator.js";
10
+ import { StopRaiseRatchet } from "./stop-raise-ratchet.js";
11
+ /**
12
+ * Baseline key for the favorable-floor ratchet. Prefer the instance-scoped
13
+ * `correlationId` (fresh per DSL rebuild → auto-resets the baseline); fall back
14
+ * to the cross-flow position key so a missing id never collapses distinct
15
+ * positions onto one bucket.
16
+ */
17
+ function ratchetKey(ev) {
18
+ if (ev.correlationId != null && ev.correlationId !== "")
19
+ return ev.correlationId;
20
+ return raiseKey(ev);
21
+ }
8
22
  const logger = createLogger("[senpi-core][dsl-notifications]");
9
- function safeNotify(notifier, message) {
23
+ export function safeNotify(notifier, input) {
10
24
  try {
11
- const result = notifier.notify(message);
25
+ const result = notifier.notify(input);
12
26
  if (result != null && typeof result.then === "function") {
13
- void result.catch((err) => logger.warn("[dsl-notifications] notify rejected", { err, message }));
27
+ void result.catch((err) => logger.warn("[dsl-notifications] notify rejected", { err, input }));
14
28
  }
15
29
  }
16
30
  catch (err) {
17
- logger.warn("[dsl-notifications] notify threw synchronously", { err, message });
31
+ logger.warn("[dsl-notifications] notify threw synchronously", { err, input });
18
32
  }
19
33
  }
34
+ /**
35
+ * Builds the notification payload for a runtime-emitted trailing-stop event
36
+ * (profit-lock / stop-raise). Because the runtime holds the strategy context for
37
+ * the position, these open an agent chat by category alone — no order id and no
38
+ * lifecycle reason is consulted. The generic seed lives inside `context` (the
39
+ * notification service persists `context` verbatim and reads `context.contextText`
40
+ * from it; a sibling on the payload root is dropped before the wire).
41
+ *
42
+ * Fail-safe: without a strategy address the chat has nothing to key on (a dead
43
+ * tap), so we WARN and ship the message non-openable rather than an empty seed.
44
+ */
45
+ function buildOpenablePayload(copy, subtype, address, createdAt, asset, dex) {
46
+ const message = copy.inApp;
47
+ // A blank (empty or whitespace-only) address is as unusable a chat key as a
48
+ // missing one, so it takes the same non-openable path.
49
+ if (!address || address.trim() === "") {
50
+ logger.warn("[dsl-notifications] openable notification missing strategy address; delivering non-openable", {
51
+ subtype,
52
+ });
53
+ return { message, canOpenAgentChat: false, subtype, copy };
54
+ }
55
+ return {
56
+ message,
57
+ canOpenAgentChat: true,
58
+ subtype,
59
+ copy,
60
+ context: {
61
+ notificationId: randomUUID(),
62
+ subtype,
63
+ createdAt,
64
+ address,
65
+ asset,
66
+ dex,
67
+ contextText: message,
68
+ },
69
+ };
70
+ }
20
71
  /** Ensures formatter + notify never throw back into `bus.emit` (would break DSL callers). */
21
72
  function runNotificationHandler(fn) {
22
73
  try {
@@ -27,75 +78,101 @@ function runNotificationHandler(fn) {
27
78
  }
28
79
  }
29
80
  export function createDslNotificationSubscriber(bus, notifier, options) {
30
- const notifySlUpdates = options?.notifySlUpdates ?? false;
31
- const prefix = options?.strategyName ? `[${options.strategyName}] ` : "";
32
- const closeResolver = options?.closeResolver ?? null;
33
- function notify(message) {
34
- safeNotify(notifier, `${prefix}${message}`);
81
+ const prefix = labelPrefix(options?.strategyName);
82
+ function notify(input) {
83
+ safeNotify(notifier, applyMessagePrefix(input, prefix));
35
84
  }
85
+ // PF-2: a single DSL raise must yield EITHER "Profit locked" OR "Stop raised",
86
+ // never both. When a tier advance locks profit (lockedProfitPct > 0) it emits
87
+ // Profit locked and records intent here; the paired SL_UPDATED for the same
88
+ // raise is then suppressed. A tier that locks nothing (<= 0) emits no
89
+ // Profit-locked message and lets its stop-raise through. See RaiseCorrelator.
90
+ const correlator = new RaiseCorrelator();
91
+ // Gate "Stop raised" to GENUINE raises only. Keeps, per position instance, the
92
+ // most-favorable exchange-SL floor seen; fires only when a new floor beats it
93
+ // in the favorable direction. Suppresses the initial placement and every
94
+ // non-raise SL_UPDATED (tier-reset / lock_hw_pct retreat / backend re-anchor).
95
+ // Sits alongside the PF-2 correlator; the two gates are independent (this one
96
+ // is additional).
97
+ const stopRaiseRatchet = new StopRaiseRatchet();
98
+ // DSL attached at position open → "DSL activated". Gated to fresh opens only:
99
+ // resize/flip/rebuild (position_increased/decreased/flipped/adopted) re-emit
100
+ // dsl.created for bookkeeping but must not re-announce activation.
36
101
  const onCreated = (e) => {
37
102
  runNotificationHandler(() => {
38
- const text = formatDslCreated(e);
39
- if (text == null)
103
+ const ev = e;
104
+ if (ev.triggerReason !== "position_opened") {
105
+ logger.debug("[dsl-notifications] dsl.created ignored: not a fresh open", {
106
+ asset: ev.asset,
107
+ triggerReason: ev.triggerReason,
108
+ });
40
109
  return;
41
- notify(text);
110
+ }
111
+ const copy = formatDslCreated(ev);
112
+ notify(buildOpenablePayload(copy, "DSL_ACTIVATED", ev.address, ev.timestamp, ev.asset, ev.dex));
42
113
  });
43
114
  };
44
115
  const onTierAdvanced = (e) => {
45
116
  runNotificationHandler(() => {
46
- notify(formatDslTierAdvanced(e));
117
+ const ev = e;
118
+ const key = raiseKey(ev);
119
+ // lockedUSD > 0 ⟺ lockedProfitPct > 0 (lockedUSD = margin * pct/100, margin >= 0).
120
+ if ((ev.lockedProfitPct ?? 0) > 0) {
121
+ correlator.recordProfitLock(key, ev.timestamp);
122
+ const copy = formatDslTierAdvanced(ev);
123
+ notify(buildOpenablePayload(copy, "DSL_PROFIT_LOCK", ev.address, ev.timestamp, ev.asset, ev.dex));
124
+ }
125
+ else {
126
+ // Else branch: nothing locked ("+$0.00"). Suppress the Profit-locked
127
+ // message and clear any stale marker so the paired stop-raise emits.
128
+ correlator.clear(key);
129
+ logger.debug("[dsl-notifications] tier advance locked no profit; deferring to stop-raise", {
130
+ asset: ev.asset,
131
+ });
132
+ }
47
133
  });
48
134
  };
49
135
  const onSlUpdated = (e) => {
50
- if (!notifySlUpdates)
51
- return;
52
- runNotificationHandler(() => {
53
- notify(formatDslSlUpdated(e));
54
- });
55
- };
56
- const onClosePending = (e) => {
57
- runNotificationHandler(() => {
58
- notify(formatDslClosePending(e));
59
- });
60
- };
61
- const onClosed = (e) => {
62
136
  runNotificationHandler(() => {
63
137
  const ev = e;
64
- if (closeResolver) {
65
- void closeResolver.enqueue(ev).catch((err) => logger.warn("[dsl-notifications] close enqueue failed", { err }));
138
+ // Ratchet the per-instance baseline FIRST — unconditionally, before any
139
+ // suppression — so a correlator-suppressed profit-lock still advances the
140
+ // most-favorable floor. `isGenuineRaise` is judged against the PRIOR
141
+ // baseline (before this advance).
142
+ const isGenuineRaise = stopRaiseRatchet.evaluate(ratchetKey(ev), ev.newSLPrice, ev.direction);
143
+ if (correlator.shouldSuppressStopRaise(raiseKey(ev), ev.timestamp)) {
144
+ logger.debug("[dsl-notifications] stop-raise suppressed: same raise already sent Profit locked", {
145
+ asset: ev.asset,
146
+ });
66
147
  return;
67
148
  }
68
- const pending = buildPendingCloseFromEvent(ev, "immediate");
69
- notify(formatDslClosedFallback(pending));
70
- });
71
- };
72
- const onDeleted = (e) => {
73
- runNotificationHandler(() => {
74
- notify(formatDslDeleted(e));
75
- });
76
- };
77
- const onHeartbeat = (e) => {
78
- runNotificationHandler(() => {
79
- notify(formatDslHeartbeat(e));
149
+ if (!isGenuineRaise) {
150
+ logger.debug("[dsl-notifications] stop-raise suppressed: placement or non-raise SL_UPDATED", {
151
+ asset: ev.asset,
152
+ newSLPrice: ev.newSLPrice,
153
+ direction: ev.direction,
154
+ });
155
+ return;
156
+ }
157
+ const copy = formatDslSlUpdated(ev);
158
+ // The SL-updated event carries no book, so the seed omits `dex`.
159
+ notify(buildOpenablePayload(copy, "DSL_STOP_RAISE", ev.address, ev.timestamp, ev.asset));
80
160
  });
81
161
  };
162
+ // DSL_EVENTS.DELETED and DSL_EVENTS.HEARTBEAT are intentionally not
163
+ // subscribed here: both were pure lifecycle/periodic pings with no
164
+ // notification subtype (unroutable to a preference bucket). The bus events
165
+ // themselves still fire for other consumers (e.g. dev/telemetry logging in
166
+ // src/scripts/run-dsl-standalone-*.ts); only the notify() forwarding was
167
+ // removed.
82
168
  bus.on(DSL_EVENTS.CREATED, onCreated);
83
169
  bus.on(DSL_EVENTS.TIER_ADVANCED, onTierAdvanced);
84
170
  bus.on(DSL_EVENTS.SL_UPDATED, onSlUpdated);
85
- bus.on(DSL_EVENTS.CLOSE_PENDING, onClosePending);
86
- bus.on(DSL_EVENTS.CLOSED, onClosed);
87
- bus.on(DSL_EVENTS.DELETED, onDeleted);
88
- bus.on(DSL_EVENTS.HEARTBEAT, onHeartbeat);
89
171
  return {
90
172
  dispose() {
91
173
  bus.off(DSL_EVENTS.CREATED, onCreated);
92
174
  bus.off(DSL_EVENTS.TIER_ADVANCED, onTierAdvanced);
93
175
  bus.off(DSL_EVENTS.SL_UPDATED, onSlUpdated);
94
- bus.off(DSL_EVENTS.CLOSE_PENDING, onClosePending);
95
- bus.off(DSL_EVENTS.CLOSED, onClosed);
96
- bus.off(DSL_EVENTS.DELETED, onDeleted);
97
- bus.off(DSL_EVENTS.HEARTBEAT, onHeartbeat);
98
- closeResolver?.stop();
99
176
  },
100
177
  };
101
178
  }