@senpi-ai/runtime 3.0.166 → 3.0.172

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 (95) hide show
  1. package/dist/cli/guide-commands.d.ts.map +1 -1
  2. package/dist/cli/guide-commands.js +3 -0
  3. package/dist/cli/guide-commands.js.map +1 -1
  4. package/dist/deploy/orchestrator.d.ts +9 -0
  5. package/dist/deploy/orchestrator.d.ts.map +1 -1
  6. package/dist/deploy/orchestrator.js +23 -1
  7. package/dist/deploy/orchestrator.js.map +1 -1
  8. package/dist/deploy/register.d.ts +1 -0
  9. package/dist/deploy/register.d.ts.map +1 -1
  10. package/dist/deploy/register.js.map +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +113 -14
  13. package/dist/index.js.map +1 -1
  14. package/dist/runtime/boot-skip.d.ts +3 -0
  15. package/dist/runtime/boot-skip.d.ts.map +1 -1
  16. package/dist/runtime/boot-skip.js +7 -3
  17. package/dist/runtime/boot-skip.js.map +1 -1
  18. package/dist/runtime/lifecycle-events.d.ts +6 -0
  19. package/dist/runtime/lifecycle-events.d.ts.map +1 -1
  20. package/dist/runtime/lifecycle-events.js +1 -0
  21. package/dist/runtime/lifecycle-events.js.map +1 -1
  22. package/dist/runtime/run.d.ts +2 -0
  23. package/dist/runtime/run.d.ts.map +1 -1
  24. package/dist/runtime/run.js +1 -0
  25. package/dist/runtime/run.js.map +1 -1
  26. package/dist/runtime/runtime-schema.d.ts +100 -100
  27. package/dist/runtime/runtime.d.ts +2 -0
  28. package/dist/runtime/runtime.d.ts.map +1 -1
  29. package/dist/runtime/runtime.js +1 -0
  30. package/dist/runtime/runtime.js.map +1 -1
  31. package/dist/runtime-api/routes/signals.d.ts.map +1 -1
  32. package/dist/runtime-api/routes/signals.js +25 -1
  33. package/dist/runtime-api/routes/signals.js.map +1 -1
  34. package/dist/runtime-api/routes/signals.schema.d.ts +2 -0
  35. package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -1
  36. package/dist/runtime-api/routes/signals.schema.js +4 -0
  37. package/dist/runtime-api/routes/signals.schema.js.map +1 -1
  38. package/dist/scanners/external/scaffold/ctx.py +55 -1
  39. package/dist/scanners/external/scaffold/delivery.py +11 -7
  40. package/dist/scanners/external/scaffold/preflight.py +1 -1
  41. package/dist/scanners/external/scaffold/scaffold.py +7 -2
  42. package/dist/senpi/client.d.ts +9 -1
  43. package/dist/senpi/client.d.ts.map +1 -1
  44. package/dist/senpi/client.js +26 -1
  45. package/dist/senpi/client.js.map +1 -1
  46. package/dist/senpi/types.d.ts +19 -0
  47. package/dist/senpi/types.d.ts.map +1 -1
  48. package/dist/senpi/types.js +0 -1
  49. package/dist/senpi/types.js.map +1 -1
  50. package/dist/skills-manager/bootstrap.d.ts +5 -2
  51. package/dist/skills-manager/bootstrap.d.ts.map +1 -1
  52. package/dist/skills-manager/bootstrap.js +24 -4
  53. package/dist/skills-manager/bootstrap.js.map +1 -1
  54. package/dist/skills-manager/coordinator.d.ts +32 -3
  55. package/dist/skills-manager/coordinator.d.ts.map +1 -1
  56. package/dist/skills-manager/coordinator.js +317 -29
  57. package/dist/skills-manager/coordinator.js.map +1 -1
  58. package/dist/skills-manager/install-error.d.ts +34 -0
  59. package/dist/skills-manager/install-error.d.ts.map +1 -0
  60. package/dist/skills-manager/install-error.js +31 -0
  61. package/dist/skills-manager/install-error.js.map +1 -0
  62. package/dist/skills-manager/types.d.ts +55 -7
  63. package/dist/skills-manager/types.d.ts.map +1 -1
  64. package/dist/skills-manager/utils.d.ts +8 -0
  65. package/dist/skills-manager/utils.d.ts.map +1 -1
  66. package/dist/skills-manager/utils.js +15 -0
  67. package/dist/skills-manager/utils.js.map +1 -1
  68. package/dist/skills-manager/writer.d.ts.map +1 -1
  69. package/dist/skills-manager/writer.js +35 -14
  70. package/dist/skills-manager/writer.js.map +1 -1
  71. package/dist/strategy/__tests__/fixtures/hawk-facts.d.ts +10 -0
  72. package/dist/strategy/__tests__/fixtures/hawk-facts.d.ts.map +1 -0
  73. package/dist/strategy/__tests__/fixtures/hawk-facts.js +35 -0
  74. package/dist/strategy/__tests__/fixtures/hawk-facts.js.map +1 -0
  75. package/dist/strategy/facts-sync.d.ts +87 -0
  76. package/dist/strategy/facts-sync.d.ts.map +1 -0
  77. package/dist/strategy/facts-sync.js +201 -0
  78. package/dist/strategy/facts-sync.js.map +1 -0
  79. package/dist/strategy/facts.d.ts +79 -0
  80. package/dist/strategy/facts.d.ts.map +1 -0
  81. package/dist/strategy/facts.js +192 -0
  82. package/dist/strategy/facts.js.map +1 -0
  83. package/dist/strategy/index.d.ts +1 -0
  84. package/dist/strategy/index.d.ts.map +1 -1
  85. package/dist/strategy/index.js +1 -0
  86. package/dist/strategy/index.js.map +1 -1
  87. package/dist/utils/event-catalog.d.ts +143 -0
  88. package/dist/utils/event-catalog.d.ts.map +1 -1
  89. package/dist/utils/event-catalog.js +12 -0
  90. package/dist/utils/event-catalog.js.map +1 -1
  91. package/dist/utils/perp-coin.d.ts.map +1 -1
  92. package/dist/utils/perp-coin.js +2 -1
  93. package/dist/utils/perp-coin.js.map +1 -1
  94. package/openclaw.plugin.json +1 -1
  95. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ /** The hawk stock package's facts (`stock-packages/hawk`), read off its yaml by hand (ticket 122). */
2
+ export const HAWK_FACTS = {
3
+ v: 1,
4
+ assets: ["BTC", "ETH", "SOL"],
5
+ universe: "static",
6
+ direction: "long_short",
7
+ leverage_default: 5,
8
+ leverage_max: 5,
9
+ margin_pct: 20,
10
+ margin_pct_max: null,
11
+ slots: 1,
12
+ scan_interval_s: 300,
13
+ exit: {
14
+ loss_cap_pct: 5,
15
+ time_cap_min: 1440,
16
+ first_lock: [20, 25],
17
+ lock_steps: 5,
18
+ weak_peak_cut: null,
19
+ dead_weight_cut: null,
20
+ },
21
+ limits: {
22
+ max_entries_per_day: 2,
23
+ daily_loss_pct: 15,
24
+ loss_streak: { count: 3, pause_s: 3600 },
25
+ drawdown_halt_pct: 20,
26
+ same_market_wait_s: 14400,
27
+ },
28
+ };
29
+ /** The hawk stock package's `strategy.yaml` catalog copy, literally. */
30
+ export const HAWK_CATALOG = {
31
+ name: "Hawk — Breakout Buyer / Breakdown Seller",
32
+ tagline: "An onboarding-grade breakout trader on the liquid majors (BTC/ETH/SOL): goes LONG when price breaks above its 7-day high AND the 4h leaders are net long, SHORT when it breaks below the 7-day low AND the 4h leaders are net short, then cuts failed breakouts fast (tight 8% Phase 1) while letting a real one run on a wide Phase 2 ratchet.",
33
+ belief_plain: "Watches BTC, ETH and SOL. When one of them breaks above its highest price of the last week and the traders winning the last four hours are also leaning long, it buys; when one breaks below its weekly low and those winners are leaning short, it sells short. A fake breakout gets cut quickly, but a real one is given lots of room to run.",
34
+ };
35
+ //# sourceMappingURL=hawk-facts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hawk-facts.js","sourceRoot":"","sources":["../../../../src/strategy/__tests__/fixtures/hawk-facts.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,MAAM,CAAC,MAAM,UAAU,GAAkB;IACvC,CAAC,EAAE,CAAC;IACJ,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;IAC7B,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,YAAY;IACvB,gBAAgB,EAAE,CAAC;IACnB,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,EAAE;IACd,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,CAAC;IACR,eAAe,EAAE,GAAG;IACpB,IAAI,EAAE;QACJ,YAAY,EAAE,CAAC;QACf,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QACpB,UAAU,EAAE,CAAC;QACb,aAAa,EAAE,IAAI;QACnB,eAAe,EAAE,IAAI;KACtB;IACD,MAAM,EAAE;QACN,mBAAmB,EAAE,CAAC;QACtB,cAAc,EAAE,EAAE;QAClB,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;QACxC,iBAAiB,EAAE,EAAE;QACrB,kBAAkB,EAAE,KAAK;KAC1B;CACF,CAAC;AAEF,wEAAwE;AACxE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,0CAA0C;IAChD,OAAO,EACL,iVAAiV;IACnV,YAAY,EACV,iVAAiV;CACpV,CAAC"}
@@ -0,0 +1,87 @@
1
+ import type { RuntimeConfig } from "../runtime/runtime-schema.js";
2
+ import { type StrategyCatalogCopy, type StrategyFacts, type StrategyManifestLike } from "./facts.js";
3
+ export declare const FACTS_STATE_FILE = "strategy-facts.json";
4
+ /** Bound on one boot facts send (connect excluded; the SDK bounds that). Detached from boot either way. */
5
+ export declare const BOOT_FACTS_CALL_TIMEOUT_MS = 30000;
6
+ /** What this runtime last settled with the backend. */
7
+ export interface FactsSyncState {
8
+ v: 1;
9
+ /**
10
+ * Hash of the last send the backend accepted (`sent`) or refused for good (`refused`): of the facts
11
+ * alone, or of `{facts, catalog}` when a catalog went with them. A state from before the catalog
12
+ * was sent holds the facts-only hash, so it never matches a send that carries one.
13
+ */
14
+ hash: string;
15
+ /** The facts-only hash of the same send. Absent in states written before the catalog was sent. */
16
+ factsHash?: string;
17
+ outcome: "sent" | "refused";
18
+ /** The last facts the backend accepted, kept for the boot merge. Null when none ever was. */
19
+ sent: StrategyFacts | null;
20
+ }
21
+ export interface FactsPlan {
22
+ runtimeId: string;
23
+ wallet: string;
24
+ stateDir: string;
25
+ /** What this boot would send: the instance's facts, merged over the last accepted ones. */
26
+ facts: StrategyFacts;
27
+ /** The package's catalog copy when its manifest has all three fields; never partial. */
28
+ catalog: StrategyCatalogCopy | null;
29
+ hash: string;
30
+ /** This hash was already settled (sent or refused): nothing to send. */
31
+ unchanged: boolean;
32
+ /** The backend holds exactly these facts. Stamped on `runtime.started` as `senpi.strategy.facts_sent`. */
33
+ delivered: boolean;
34
+ previous: FactsSyncState | null;
35
+ }
36
+ /** The answer of one `strategy_patch_metadata` call, as `SenpiClient.patchStrategyMetadata` reads it. */
37
+ export interface FactsPatchResult {
38
+ success: boolean;
39
+ errorCode?: string;
40
+ message?: string;
41
+ retryable?: boolean;
42
+ }
43
+ export interface FactsSyncDeps {
44
+ /** The strategy id for a wallet, from the boot status read; undefined when that read did not say. */
45
+ strategyIdFor(wallet: string): string | undefined;
46
+ patch(strategyId: string, facts: StrategyFacts, catalog?: StrategyCatalogCopy): Promise<FactsPatchResult>;
47
+ }
48
+ export type FactsSyncOutcome = "sent" | "unchanged" | "refused" | "failed";
49
+ export interface FactsSyncResult {
50
+ outcome: FactsSyncOutcome;
51
+ /** Why it was refused or failed. */
52
+ detail?: string;
53
+ }
54
+ export declare function factsHash(facts: StrategyFacts): string;
55
+ /** Hash of what one send carries: the facts alone, or the facts with the catalog copy. */
56
+ export declare function sendHash(facts: StrategyFacts, catalog: StrategyCatalogCopy | null): string;
57
+ /**
58
+ * The package manifest of a runtime, best-effort. Stock packages are `<pkg>/strategy.yaml` beside
59
+ * `<pkg>/<instance>/runtime.yaml`; flat ones keep both in `<pkg>/`. So look in the runtime's own
60
+ * dir, then its parent, and take the parent's only when it declares this instance. Null when none
61
+ * is found or it will not parse; never throws. The files can change after deploy, and
62
+ * `runtime create` installs have no package at all.
63
+ */
64
+ export declare function readPackageManifest(runtimeYamlDir: string | undefined): Promise<StrategyManifestLike | null>;
65
+ /**
66
+ * Boot facts over the last accepted ones. A boot that cannot read the manifest loses the catalog
67
+ * fallback for assets and direction; it must not overwrite what the deploy sent with nulls. The
68
+ * boot's values win wherever they are non-null. Assets are carried over only when the boot does
69
+ * not know the universe either: a scanner that ranks a live board has no asset list by design.
70
+ */
71
+ export declare function mergeBootFacts(boot: StrategyFacts, lastSent: StrategyFacts | null): StrategyFacts;
72
+ /** The stored state, or null when there is none or it is unreadable (read as "never sent"). */
73
+ export declare function readFactsState(stateDir: string): Promise<FactsSyncState | null>;
74
+ /** What this boot would send for one instance. Local only: files, no network. */
75
+ export declare function planBootFacts(input: {
76
+ runtimeId: string;
77
+ wallet: string;
78
+ stateDir: string;
79
+ config: RuntimeConfig;
80
+ runtimeYamlDir?: string;
81
+ }): Promise<FactsPlan>;
82
+ /**
83
+ * Send one instance's planned facts, at most once. Never throws. A state write that fails after a
84
+ * send only costs a resend on the next boot.
85
+ */
86
+ export declare function syncBootFacts(plan: FactsPlan, deps: FactsSyncDeps): Promise<FactsSyncResult>;
87
+ //# sourceMappingURL=facts-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts-sync.d.ts","sourceRoot":"","sources":["../../src/strategy/facts-sync.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AACtD,2GAA2G;AAC3G,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAGjD,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,CAAC,CAAC;IACL;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,kGAAkG;IAClG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,6FAA6F;IAC7F,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,KAAK,EAAE,aAAa,CAAC;IACrB,wFAAwF;IACxF,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,SAAS,EAAE,OAAO,CAAC;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AAG,IAAI,CAAC,CAOrF;AAUD,iFAAiF;AACjF,wBAAsB,aAAa,CAAC,KAAK,EAAE;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBrB;AAuBD;;;GAGG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAgClG"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Boot-time StrategyFacts sync: at every boot, each running instance sends its facts to the backend
3
+ * (MCP `strategy_patch_metadata`) once, and only when they differ from what it last settled.
4
+ *
5
+ * The package files live only on the user's box, so sending at boot as well as at deploy gives
6
+ * every live package facts after one image rollout, without waiting for a redeploy.
7
+ *
8
+ * What "last settled" means is kept in the runtime's own state dir (`strategy-facts.json`): the
9
+ * hash of the last facts the backend accepted or refused for good. A refusal is final for that hash
10
+ * (the box does not retry it every boot); anything transient (UNAVAILABLE, a thrown call, an
11
+ * unknown strategy id) writes nothing, so the next boot tries once more. Nothing here loops, and
12
+ * nothing here may block boot or trading: the caller runs the send detached, after the runtimes
13
+ * are up.
14
+ */
15
+ import { randomUUID } from "node:crypto";
16
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
17
+ import { dirname, join, resolve } from "node:path";
18
+ import { parse as parseYaml } from "yaml";
19
+ import { z } from "zod";
20
+ import { errorText } from "../deploy/error-text.js";
21
+ import { computeConfigHash } from "../telemetry/identity.js";
22
+ import { catalogCopy, strategyFacts, } from "./facts.js";
23
+ export const FACTS_STATE_FILE = "strategy-facts.json";
24
+ /** Bound on one boot facts send (connect excluded; the SDK bounds that). Detached from boot either way. */
25
+ export const BOOT_FACTS_CALL_TIMEOUT_MS = 30_000;
26
+ const MANIFEST_FILE = "strategy.yaml";
27
+ export function factsHash(facts) {
28
+ return computeConfigHash(facts) ?? "";
29
+ }
30
+ /** Hash of what one send carries: the facts alone, or the facts with the catalog copy. */
31
+ export function sendHash(facts, catalog) {
32
+ return catalog ? (computeConfigHash({ facts, catalog }) ?? "") : factsHash(facts);
33
+ }
34
+ function isMap(value) {
35
+ return value !== null && typeof value === "object" && !Array.isArray(value);
36
+ }
37
+ async function readYamlMap(path) {
38
+ try {
39
+ const parsed = parseYaml(await readFile(path, "utf8"));
40
+ return isMap(parsed) ? parsed : null;
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ }
46
+ /** Does this manifest declare an instance whose runtime.yaml lives in `runtimeYamlDir`? */
47
+ function declaresDir(manifest, packageDir, runtimeYamlDir) {
48
+ const instances = Array.isArray(manifest.instances) ? manifest.instances : [];
49
+ return instances.some((inst) => isMap(inst) && typeof inst.runtime === "string" && dirname(resolve(packageDir, inst.runtime)) === runtimeYamlDir);
50
+ }
51
+ /**
52
+ * The package manifest of a runtime, best-effort. Stock packages are `<pkg>/strategy.yaml` beside
53
+ * `<pkg>/<instance>/runtime.yaml`; flat ones keep both in `<pkg>/`. So look in the runtime's own
54
+ * dir, then its parent, and take the parent's only when it declares this instance. Null when none
55
+ * is found or it will not parse; never throws. The files can change after deploy, and
56
+ * `runtime create` installs have no package at all.
57
+ */
58
+ export async function readPackageManifest(runtimeYamlDir) {
59
+ if (!runtimeYamlDir)
60
+ return null;
61
+ const dir = resolve(runtimeYamlDir);
62
+ const own = await readYamlMap(join(dir, MANIFEST_FILE));
63
+ if (own)
64
+ return { catalog: own.catalog };
65
+ const parentDir = dirname(dir);
66
+ const parent = await readYamlMap(join(parentDir, MANIFEST_FILE));
67
+ if (parent && declaresDir(parent, parentDir, dir))
68
+ return { catalog: parent.catalog };
69
+ return null;
70
+ }
71
+ /**
72
+ * Boot facts over the last accepted ones. A boot that cannot read the manifest loses the catalog
73
+ * fallback for assets and direction; it must not overwrite what the deploy sent with nulls. The
74
+ * boot's values win wherever they are non-null. Assets are carried over only when the boot does
75
+ * not know the universe either: a scanner that ranks a live board has no asset list by design.
76
+ */
77
+ export function mergeBootFacts(boot, lastSent) {
78
+ if (!lastSent)
79
+ return boot;
80
+ return {
81
+ ...boot,
82
+ assets: boot.assets ?? (boot.universe === null ? lastSent.assets : null),
83
+ direction: boot.direction ?? lastSent.direction,
84
+ };
85
+ }
86
+ function statePath(stateDir) {
87
+ return join(stateDir, FACTS_STATE_FILE);
88
+ }
89
+ /**
90
+ * The state file's shape. `sent` is checked as far as the MCP checks facts (`v: 1`): it was written
91
+ * by this module from a `StrategyFacts`, and a hand-edited one is merged and hashed, never trusted
92
+ * further than the backend would.
93
+ */
94
+ const factsSyncStateSchema = z.object({
95
+ v: z.literal(1),
96
+ hash: z.string(),
97
+ factsHash: z.string().optional(),
98
+ outcome: z.enum(["sent", "refused"]),
99
+ sent: z.object({ v: z.literal(1) }).passthrough().nullable(),
100
+ });
101
+ /** The stored state, or null when there is none or it is unreadable (read as "never sent"). */
102
+ export async function readFactsState(stateDir) {
103
+ try {
104
+ const parsed = factsSyncStateSchema.safeParse(JSON.parse(await readFile(statePath(stateDir), "utf8")));
105
+ return parsed.success ? ({ ...parsed.data, sent: parsed.data.sent }) : null;
106
+ }
107
+ catch {
108
+ return null;
109
+ }
110
+ }
111
+ async function writeFactsState(stateDir, state) {
112
+ await mkdir(stateDir, { recursive: true });
113
+ const target = statePath(stateDir);
114
+ const tmp = `${target}.${process.pid}.${randomUUID()}.tmp`;
115
+ await writeFile(tmp, JSON.stringify(state, null, 2), "utf8");
116
+ await rename(tmp, target);
117
+ }
118
+ /** What this boot would send for one instance. Local only: files, no network. */
119
+ export async function planBootFacts(input) {
120
+ const manifest = await readPackageManifest(input.runtimeYamlDir);
121
+ const previous = await readFactsState(input.stateDir);
122
+ const facts = mergeBootFacts(strategyFacts(input.config, manifest), previous?.sent ?? null);
123
+ const catalog = catalogCopy(manifest?.catalog);
124
+ const hash = sendHash(facts, catalog);
125
+ // Without a catalog this boot (no manifest, or an incomplete one) the facts alone are compared,
126
+ // so a catalog sent earlier does not make identical facts go out again. A refused pair never
127
+ // vouches for its facts alone.
128
+ const settled = previous?.hash === hash || (catalog === null && previous?.outcome === "sent" && previous.factsHash === hash);
129
+ return {
130
+ runtimeId: input.runtimeId,
131
+ wallet: input.wallet,
132
+ stateDir: input.stateDir,
133
+ facts,
134
+ catalog,
135
+ hash,
136
+ unchanged: settled,
137
+ delivered: previous?.outcome === "sent" && settled,
138
+ previous,
139
+ };
140
+ }
141
+ /**
142
+ * The only answers that judge the facts themselves, so repeating the send cannot change them:
143
+ * SERR044 (no such strategy), SERR045 (strategy not updatable), SERR180-182 (facts or catalog
144
+ * rejected) and INVALID_ARGUMENT (the MCP's schema check of facts or catalog). Everything else
145
+ * says something about the deployment, not the facts: NOT_FOUND from an MCP that does not know
146
+ * the tool yet, UNAUTHENTICATED from a gateway that does not know the route, UNAVAILABLE, INTERNAL,
147
+ * SERR032 (the box's token). Those retry on the next boot, whatever `retryable` says.
148
+ */
149
+ const FINAL_REFUSAL_CODES = new Set([
150
+ "SERR044",
151
+ "SERR045",
152
+ "SERR180",
153
+ "SERR181",
154
+ "SERR182",
155
+ "INVALID_ARGUMENT",
156
+ ]);
157
+ function isFinalRefusal(result) {
158
+ return result.errorCode !== undefined && FINAL_REFUSAL_CODES.has(result.errorCode);
159
+ }
160
+ /**
161
+ * Send one instance's planned facts, at most once. Never throws. A state write that fails after a
162
+ * send only costs a resend on the next boot.
163
+ */
164
+ export async function syncBootFacts(plan, deps) {
165
+ if (plan.unchanged)
166
+ return { outcome: "unchanged" };
167
+ const strategyId = deps.strategyIdFor(plan.wallet);
168
+ if (!strategyId)
169
+ return { outcome: "failed", detail: "no strategy id known for this wallet" };
170
+ let result;
171
+ try {
172
+ result = await deps.patch(strategyId, plan.facts, plan.catalog ?? undefined);
173
+ }
174
+ catch (err) {
175
+ return { outcome: "failed", detail: errorText(err) };
176
+ }
177
+ const detail = result.errorCode
178
+ ? `${result.errorCode}: ${result.message ?? "no message"}`
179
+ : "no error code in the answer";
180
+ let settled;
181
+ let state;
182
+ if (result.success) {
183
+ settled = { outcome: "sent" };
184
+ state = { v: 1, hash: plan.hash, factsHash: factsHash(plan.facts), outcome: "sent", sent: plan.facts };
185
+ }
186
+ else if (isFinalRefusal(result)) {
187
+ settled = { outcome: "refused", detail };
188
+ state = { v: 1, hash: plan.hash, factsHash: factsHash(plan.facts), outcome: "refused", sent: plan.previous?.sent ?? null };
189
+ }
190
+ else {
191
+ return { outcome: "failed", detail };
192
+ }
193
+ try {
194
+ await writeFactsState(plan.stateDir, state);
195
+ }
196
+ catch (err) {
197
+ return { ...settled, detail: `${settled.detail ? `${settled.detail}; ` : ""}state not saved: ${errorText(err)}` };
198
+ }
199
+ return settled;
200
+ }
201
+ //# sourceMappingURL=facts-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts-sync.js","sourceRoot":"","sources":["../../src/strategy/facts-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EACL,WAAW,EACX,aAAa,GAId,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AACtD,2GAA2G;AAC3G,MAAM,CAAC,MA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AC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IACzG,CAAC;SAAM,IAAI,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,OAAO,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QACzC,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC;IAC7H,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC;IACD,IAAI,CAAC;QACH,MAAM,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,EAAE,oBAAoB,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;IACpH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * StrategyFacts v1: what one runtime instance does, read from its own files. One value per
3
+ * instance, because each instance owns its own wallet.
4
+ *
5
+ * Facts only. No wording, no model, no scanner-input names or "what it looks for" hints: the same
6
+ * input means opposite things across packages (`minTraderCount` is "the crowd agrees" in Beaver and
7
+ * "the crowd is crowded, fade it" in Dog), so the only inputs read are ticker lists, a universe
8
+ * shape, an explicit long/short leg, and leverage/margin numbers. Rendering belongs to the backend.
9
+ *
10
+ * Pure: no I/O, never throws. Every field is null when the files do not say, never a guess. The
11
+ * exit block is read THROUGH THE ENGINE'S OWN READER (`mapRuntimeExitToDslConfig` + `parsePreset`,
12
+ * as `loadRuntimeConfig` and `runtime-descriptor.ts` do), so a fact here is what the DSL enforces.
13
+ *
14
+ * Port of the runtime-file fields of the pages-v2 prototype `strategy-describer/describe.py`.
15
+ */
16
+ import type { RuntimeConfig } from "../runtime/runtime-schema.js";
17
+ export type StrategyDirection = "long" | "short" | "long_short";
18
+ export interface StrategyExitFacts {
19
+ /** Max loss as % of margin. Enforced as the absolute floor even with phase 1 off (`floors.ts` phase1BaseFloor). */
20
+ loss_cap_pct: number;
21
+ time_cap_min: number | null;
22
+ /** [trigger_pct, lock_hw_pct] of the first profit-lock tier; null when phase 2 is off. */
23
+ first_lock: [number, number] | null;
24
+ /** Number of profit-lock tiers the engine acts on; 0 when phase 2 is off. */
25
+ lock_steps: number;
26
+ weak_peak_cut: {
27
+ after_min: number;
28
+ under_pct: number;
29
+ } | null;
30
+ dead_weight_cut: {
31
+ after_min: number;
32
+ } | null;
33
+ }
34
+ export interface StrategyLimitFacts {
35
+ max_entries_per_day: number | null;
36
+ daily_loss_pct: number | null;
37
+ /** Gate 3 runs only when both are set (`risk/guardrail.types.ts`), so it is both or null. */
38
+ loss_streak: {
39
+ count: number;
40
+ pause_s: number;
41
+ } | null;
42
+ drawdown_halt_pct: number | null;
43
+ same_market_wait_s: number | null;
44
+ }
45
+ /** Wire shape, snake_case, versioned. */
46
+ export interface StrategyFacts {
47
+ v: 1;
48
+ /** Static ticker list from the entry scanner's inputs, else the manifest's `catalog.assets`. */
49
+ assets: string[] | null;
50
+ /** "static" when the scanner names its tickers, "dynamic" when it picks from a live board. */
51
+ universe: "static" | "dynamic" | null;
52
+ /** Scanner `direction`/`leg` input when it is long or short, else the manifest's `catalog.direction`. */
53
+ direction: StrategyDirection | null;
54
+ leverage_default: number | null;
55
+ leverage_max: number | null;
56
+ margin_pct: number | null;
57
+ margin_pct_max: number | null;
58
+ slots: number | null;
59
+ scan_interval_s: number | null;
60
+ exit: StrategyExitFacts | null;
61
+ limits: StrategyLimitFacts | null;
62
+ }
63
+ /** The part of a package manifest (`strategy.yaml`) read here. `DeployPackage` satisfies it. */
64
+ export interface StrategyManifestLike {
65
+ catalog?: unknown;
66
+ }
67
+ /** The catalog copy the backend reads from `strategyMetadata.catalog` (ticket 116). */
68
+ export interface StrategyCatalogCopy {
69
+ name: string;
70
+ tagline: string;
71
+ belief_plain: string;
72
+ }
73
+ /**
74
+ * `{name, tagline, belief_plain}` out of a manifest's `catalog:` block, or null unless all three are
75
+ * non-empty strings: the MCP stores the catalog only whole, so a partial one would be dropped there.
76
+ */
77
+ export declare function catalogCopy(catalog: unknown): StrategyCatalogCopy | null;
78
+ export declare function strategyFacts(config: RuntimeConfig, manifest?: StrategyManifestLike | null): StrategyFacts;
79
+ //# sourceMappingURL=facts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.d.ts","sourceRoot":"","sources":["../../src/strategy/facts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,aAAa,EAA+B,MAAM,8BAA8B,CAAC;AAM/F,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,CAAC;AAEhE,MAAM,WAAW,iBAAiB;IAChC,mHAAmH;IACnH,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,0FAA0F;IAC1F,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACpC,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC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ACtB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAKxE;AAsKD,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,IAAI,GAAG,aAAa,CAgB1G"}
@@ -0,0 +1,192 @@
1
+ import { mapRuntimeExitToDslConfig } from "../runtime/map-exit-config.js";
2
+ import { parsePreset } from "../dsl/config/parse-preset.js";
3
+ import { DEFAULT_INTERVAL_MS, EXIT_DSL_PRESET_PATH } from "../constants/dsl/index.js";
4
+ /**
5
+ * `{name, tagline, belief_plain}` out of a manifest's `catalog:` block, or null unless all three are
6
+ * non-empty strings: the MCP stores the catalog only whole, so a partial one would be dropped there.
7
+ */
8
+ export function catalogCopy(catalog) {
9
+ if (!isMap(catalog))
10
+ return null;
11
+ const { name, tagline, belief_plain } = catalog;
12
+ const filled = (value) => typeof value === "string" && value.trim().length > 0;
13
+ return filled(name) && filled(tagline) && filled(belief_plain) ? { name, tagline, belief_plain } : null;
14
+ }
15
+ /** Input keys whose value is the scanner's own ticker list (or a single ticker), in priority order. */
16
+ const ASSET_KEYS = ["universe", "allowedAssets", "assets", "whitelist", "trackedAssets", "asset", "coin", "hedgeUniverse"];
17
+ /** Keys that hold a ticker list only as a list (never a single string). */
18
+ const LIST_ONLY_ASSET_KEYS = ["equities", "trackedCrypto", "riskAssets"];
19
+ /** Inputs that size a live, ranked universe instead of naming one. */
20
+ const DYNAMIC_UNIVERSE_KEYS = [
21
+ "universeVolFloorUsd", "universeMaxNames", "universeTopN", "topN", "maxUniverse", "universeSize",
22
+ "maxUniverseNames", "maxMainNames", "volFloorUsd", "leaderboardLimit", "shortlistByVol", "minOiUsd",
23
+ "xyzVolFloorUsd", "trackedXyz",
24
+ ];
25
+ const TICKER = /^(xyz:)?[A-Za-z0-9]{2,10}$/;
26
+ function num(value) {
27
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
28
+ }
29
+ function isMap(value) {
30
+ return value !== null && typeof value === "object" && !Array.isArray(value);
31
+ }
32
+ function tickers(value) {
33
+ if (!Array.isArray(value) || value.length === 0)
34
+ return null;
35
+ return value.every((x) => typeof x === "string" && TICKER.test(x)) ? value : null;
36
+ }
37
+ /** Every finite number inside a (possibly nested) tier map such as `leverageTiers`. */
38
+ function tierNumbers(value) {
39
+ if (num(value) !== null)
40
+ return [value];
41
+ if (Array.isArray(value))
42
+ return value.flatMap(tierNumbers);
43
+ if (isMap(value))
44
+ return Object.values(value).flatMap(tierNumbers);
45
+ return [];
46
+ }
47
+ function firstNum(inputs, keys) {
48
+ for (const k of keys) {
49
+ const n = num(inputs[k]);
50
+ if (n !== null)
51
+ return n;
52
+ }
53
+ return null;
54
+ }
55
+ function normalizeDirection(value) {
56
+ if (typeof value !== "string")
57
+ return null;
58
+ switch (value.trim().toLowerCase()) {
59
+ case "long":
60
+ case "long_only":
61
+ return "long";
62
+ case "short":
63
+ case "short_only":
64
+ return "short";
65
+ case "long_short":
66
+ return "long_short";
67
+ default:
68
+ return null;
69
+ }
70
+ }
71
+ function universeFacts(inputs, catalog) {
72
+ for (const k of ASSET_KEYS) {
73
+ const v = inputs[k];
74
+ const list = tickers(typeof v === "string" ? [v] : v);
75
+ if (list)
76
+ return { assets: list, universe: "static" };
77
+ }
78
+ for (const k of LIST_ONLY_ASSET_KEYS) {
79
+ const list = tickers(inputs[k]);
80
+ if (list)
81
+ return { assets: list, universe: "static" };
82
+ }
83
+ const dex = typeof inputs.dex === "string" ? inputs.dex.toLowerCase() : "";
84
+ if (dex === "xyz" || DYNAMIC_UNIVERSE_KEYS.some((k) => k in inputs))
85
+ return { assets: null, universe: "dynamic" };
86
+ // Declared, not observed: the manifest says which tickers, but not whether the scanner is held to them.
87
+ return { assets: tickers(catalog.assets), universe: null };
88
+ }
89
+ function directionFact(inputs, catalog) {
90
+ return (normalizeDirection(inputs.direction) ?? normalizeDirection(inputs.leg) ?? normalizeDirection(catalog.direction));
91
+ }
92
+ function leverageMax(inputs) {
93
+ const explicit = firstNum(inputs, ["maxLeverage", "leverageMax", "max_leverage"]);
94
+ if (explicit !== null)
95
+ return explicit;
96
+ const tiers = tierLeverages(inputs.leverageTiers);
97
+ if (tiers.length > 0)
98
+ return Math.max(...tiers);
99
+ return num(inputs.leverage);
100
+ }
101
+ /** A tier list is `{name: leverage}` or rows of `[min_score, leverage, margin_pct?]`: leverage is never a row's score or margin. */
102
+ function tierLeverages(value) {
103
+ const rows = Array.isArray(value) ? value : isMap(value) ? Object.values(value) : [];
104
+ return rows.flatMap((row) => {
105
+ const leverage = Array.isArray(row) ? num(row[1]) : num(row);
106
+ return leverage === null ? [] : [leverage];
107
+ });
108
+ }
109
+ function marginFacts(strategy, inputs) {
110
+ let marginPct = num(strategy.margin_pct);
111
+ let marginPctMax = null;
112
+ if (marginPct === null) {
113
+ marginPct = firstNum(inputs, ["marginPct", "marginPctBase", "margin_pct", "marginPctMax"]);
114
+ const tiers = tierNumbers(inputs.marginPctTiers);
115
+ if (marginPct === null && tiers.length > 0) {
116
+ marginPct = Math.min(...tiers);
117
+ marginPctMax = Math.max(...tiers);
118
+ }
119
+ }
120
+ if (marginPctMax === null) {
121
+ const cap = firstNum(inputs, ["maxMarginPct", "marginPctMax", "marginPctCap"]);
122
+ if (cap !== null && cap !== marginPct)
123
+ marginPctMax = cap;
124
+ }
125
+ return { margin_pct: marginPct, margin_pct_max: marginPctMax };
126
+ }
127
+ /** The preset the DSL monitor would run, or null when there is none or the engine refuses it. */
128
+ function enginePreset(exit) {
129
+ try {
130
+ const block = mapRuntimeExitToDslConfig(exit);
131
+ if (!isMap(block.dsl_preset))
132
+ return null;
133
+ // Same clamp floor `parseDslPluginConfig` passes: the exit poll interval, in minutes.
134
+ return parsePreset(EXIT_DSL_PRESET_PATH, block.dsl_preset, (block.interval_seconds ?? DEFAULT_INTERVAL_MS / 1000) / 60);
135
+ }
136
+ catch {
137
+ return null;
138
+ }
139
+ }
140
+ function exitFacts(exit) {
141
+ const preset = enginePreset(exit);
142
+ if (preset === null)
143
+ return null;
144
+ const tiers = preset.phase2Enabled ? preset.tiers : [];
145
+ const first = tiers[0];
146
+ return {
147
+ loss_cap_pct: preset.maxLossPct,
148
+ time_cap_min: preset.hardTimeout?.intervalInMinutes ?? null,
149
+ first_lock: first ? [first.triggerPct, first.lockHwPct] : null,
150
+ lock_steps: tiers.length,
151
+ weak_peak_cut: preset.weakPeakCut
152
+ ? { after_min: preset.weakPeakCut.intervalInMinutes, under_pct: preset.weakPeakCut.minValue }
153
+ : null,
154
+ dead_weight_cut: preset.deadWeightCut ? { after_min: preset.deadWeightCut.intervalInMinutes } : null,
155
+ };
156
+ }
157
+ function limitFacts(config) {
158
+ const gr = config.risk?.guard_rails;
159
+ if (!gr)
160
+ return null;
161
+ const count = num(gr.max_consecutive_losses);
162
+ const pause = num(gr.cooldown_seconds);
163
+ return {
164
+ max_entries_per_day: num(gr.max_entries_per_day),
165
+ daily_loss_pct: num(gr.daily_loss_limit_pct),
166
+ loss_streak: count !== null && pause !== null ? { count, pause_s: pause } : null,
167
+ drawdown_halt_pct: num(gr.drawdown_halt_pct),
168
+ same_market_wait_s: num(gr.per_asset_cooldown_seconds),
169
+ };
170
+ }
171
+ /** The scanner that produces entries: the first `external_scanner`. */
172
+ function entryScanner(config) {
173
+ return config.scanners?.find((s) => s.type === "external_scanner");
174
+ }
175
+ export function strategyFacts(config, manifest) {
176
+ const scanner = entryScanner(config);
177
+ const inputs = isMap(scanner?.inputs) ? scanner.inputs : {};
178
+ const catalog = isMap(manifest?.catalog) ? manifest.catalog : {};
179
+ return {
180
+ v: 1,
181
+ ...universeFacts(inputs, catalog),
182
+ direction: directionFact(inputs, catalog),
183
+ leverage_default: num(config.strategy.default_leverage),
184
+ leverage_max: leverageMax(inputs),
185
+ ...marginFacts(config.strategy, inputs),
186
+ slots: num(config.strategy.slots),
187
+ scan_interval_s: num(scanner?.interval_seconds),
188
+ exit: exitFacts(config.exit),
189
+ limits: limitFacts(config),
190
+ };
191
+ }
192
+ //# sourceMappingURL=facts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.js","sourceRoot":"","sources":["../../src/strategy/facts.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAyDtF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAChD,MAAM,MAAM,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IACzG,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1G,CAAC;AAID,uGAAuG;AACvG,MAAM,UAAU,GAAG,CAAC,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC3H,2EAA2E;AAC3E,MAAM,oBAAoB,GAAG,CAAC,UAAU,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;AACzE,sEAAsE;AACtE,MAAM,qBAAqB,GAAG;IAC5B,qBAAqB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc;IAChG,kBAAkB,EAAE,c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sC;IACzF,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,MAAM,GAAW,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACpE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,OAAO;QACL,CAAC,EAAE,CAAC;QACJ,GAAG,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC;QACjC,SAAS,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC;QACzC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QACvD,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC;QACjC,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC;QACvC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QACjC,eAAe,EAAE,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC;QAC/C,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC;KAC3B,CAAC;AACJ,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { StrategyStateImpl } from './strategy-state.js';
2
+ export { strategyFacts, type StrategyFacts, type StrategyExitFacts, type StrategyLimitFacts, type StrategyDirection, type StrategyManifestLike, } from './facts.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/strategy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/strategy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,GAC1B,MAAM,YAAY,CAAC"}