@senpi-ai/runtime 3.0.179 → 3.0.188
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/dist/actions/llm-decision/openclaw-llm-decision.d.ts +8 -0
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js +56 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
- package/dist/approvals/approval-store.d.ts +37 -7
- package/dist/approvals/approval-store.d.ts.map +1 -1
- package/dist/approvals/approval-store.js +127 -23
- package/dist/approvals/approval-store.js.map +1 -1
- package/dist/approvals/telemetry.d.ts +28 -3
- package/dist/approvals/telemetry.d.ts.map +1 -1
- package/dist/approvals/telemetry.js +8 -4
- package/dist/approvals/telemetry.js.map +1 -1
- package/dist/approvals/tool-approval-gate.d.ts +85 -0
- package/dist/approvals/tool-approval-gate.d.ts.map +1 -1
- package/dist/approvals/tool-approval-gate.js +197 -15
- package/dist/approvals/tool-approval-gate.js.map +1 -1
- package/dist/approvals/turn-context.d.ts +296 -0
- package/dist/approvals/turn-context.d.ts.map +1 -0
- package/dist/approvals/turn-context.js +594 -0
- package/dist/approvals/turn-context.js.map +1 -0
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +18 -3
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +80 -5
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/deploy/job.d.ts +32 -0
- package/dist/deploy/job.d.ts.map +1 -1
- package/dist/deploy/job.js +72 -7
- package/dist/deploy/job.js.map +1 -1
- package/dist/deploy/register.d.ts +12 -0
- package/dist/deploy/register.d.ts.map +1 -1
- package/dist/deploy/register.js +85 -2
- package/dist/deploy/register.js.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.d.ts +38 -2
- package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.js +67 -4
- package/dist/dsl/monitor/dsl-failure-events.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +25 -1
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/host/openclaw-host.d.ts +138 -0
- package/dist/host/openclaw-host.d.ts.map +1 -0
- package/dist/host/openclaw-host.js +177 -0
- package/dist/host/openclaw-host.js.map +1 -0
- package/dist/host/plugin-logger.d.ts +99 -0
- package/dist/host/plugin-logger.d.ts.map +1 -0
- package/dist/host/plugin-logger.js +142 -0
- package/dist/host/plugin-logger.js.map +1 -0
- package/dist/index.d.ts +56 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +695 -161
- package/dist/index.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.d.ts +220 -0
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +715 -22
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/gateway-restart.d.ts +60 -1
- package/dist/runtime/auto-update/gateway-restart.d.ts.map +1 -1
- package/dist/runtime/auto-update/gateway-restart.js +95 -21
- package/dist/runtime/auto-update/gateway-restart.js.map +1 -1
- package/dist/runtime/auto-update/idle-gate.d.ts +175 -0
- package/dist/runtime/auto-update/idle-gate.d.ts.map +1 -0
- package/dist/runtime/auto-update/idle-gate.js +229 -0
- package/dist/runtime/auto-update/idle-gate.js.map +1 -0
- package/dist/runtime/auto-update/install-results.d.ts +130 -0
- package/dist/runtime/auto-update/install-results.d.ts.map +1 -0
- package/dist/runtime/auto-update/install-results.js +264 -0
- package/dist/runtime/auto-update/install-results.js.map +1 -0
- package/dist/runtime/auto-update/money-call-tracker.d.ts +36 -0
- package/dist/runtime/auto-update/money-call-tracker.d.ts.map +1 -0
- package/dist/runtime/auto-update/money-call-tracker.js +129 -0
- package/dist/runtime/auto-update/money-call-tracker.js.map +1 -0
- package/dist/runtime/auto-update/register-idle-gate.d.ts +70 -0
- package/dist/runtime/auto-update/register-idle-gate.d.ts.map +1 -0
- package/dist/runtime/auto-update/register-idle-gate.js +127 -0
- package/dist/runtime/auto-update/register-idle-gate.js.map +1 -0
- package/dist/runtime/auto-update/run-update-command.d.ts +13 -0
- package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -1
- package/dist/runtime/auto-update/run-update-command.js +18 -0
- package/dist/runtime/auto-update/run-update-command.js.map +1 -1
- package/dist/runtime/auto-update/state-store.d.ts +14 -1
- package/dist/runtime/auto-update/state-store.d.ts.map +1 -1
- package/dist/runtime/auto-update/state-store.js +37 -3
- package/dist/runtime/auto-update/state-store.js.map +1 -1
- package/dist/runtime/auto-update/types.d.ts +52 -0
- package/dist/runtime/auto-update/types.d.ts.map +1 -1
- package/dist/runtime/auto-update/types.js.map +1 -1
- package/dist/runtime/auto-update/update-marker.d.ts +95 -0
- package/dist/runtime/auto-update/update-marker.d.ts.map +1 -0
- package/dist/runtime/auto-update/update-marker.js +185 -0
- package/dist/runtime/auto-update/update-marker.js.map +1 -0
- package/dist/runtime/auto-update/update-schedule.d.ts +67 -0
- package/dist/runtime/auto-update/update-schedule.d.ts.map +1 -0
- package/dist/runtime/auto-update/update-schedule.js +91 -0
- package/dist/runtime/auto-update/update-schedule.js.map +1 -0
- package/dist/runtime/decision-errors.d.ts +7 -0
- package/dist/runtime/decision-errors.d.ts.map +1 -1
- package/dist/runtime/decision-errors.js +15 -0
- package/dist/runtime/decision-errors.js.map +1 -1
- package/dist/runtime/process-state.d.ts +168 -0
- package/dist/runtime/process-state.d.ts.map +1 -0
- package/dist/runtime/process-state.js +81 -0
- package/dist/runtime/process-state.js.map +1 -0
- package/dist/runtime/reconcile-state.d.ts.map +1 -1
- package/dist/runtime/reconcile-state.js +18 -4
- package/dist/runtime/reconcile-state.js.map +1 -1
- package/dist/runtime/strategy-registry.d.ts +16 -0
- package/dist/runtime/strategy-registry.d.ts.map +1 -1
- package/dist/runtime/strategy-registry.js +7 -3
- package/dist/runtime/strategy-registry.js.map +1 -1
- package/dist/runtime/update-apply-deps.d.ts +5 -3
- package/dist/runtime/update-apply-deps.d.ts.map +1 -1
- package/dist/runtime/update-apply-deps.js +15 -3
- package/dist/runtime/update-apply-deps.js.map +1 -1
- package/dist/senpi/client.d.ts +29 -0
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +71 -2
- package/dist/senpi/client.js.map +1 -1
- package/dist/telemetry/metrics.d.ts +15 -1
- package/dist/telemetry/metrics.d.ts.map +1 -1
- package/dist/telemetry/metrics.js +25 -1
- package/dist/telemetry/metrics.js.map +1 -1
- package/dist/telemetry/otel-sdk.d.ts +12 -0
- package/dist/telemetry/otel-sdk.d.ts.map +1 -1
- package/dist/telemetry/otel-sdk.js +47 -1
- package/dist/telemetry/otel-sdk.js.map +1 -1
- package/dist/telemetry/spans/span-hooks.d.ts +18 -1
- package/dist/telemetry/spans/span-hooks.d.ts.map +1 -1
- package/dist/telemetry/spans/span-hooks.js +306 -96
- package/dist/telemetry/spans/span-hooks.js.map +1 -1
- package/dist/telemetry/tool-plane.d.ts +2 -0
- package/dist/telemetry/tool-plane.d.ts.map +1 -1
- package/dist/telemetry/tool-plane.js +1 -0
- package/dist/telemetry/tool-plane.js.map +1 -1
- package/dist/test-setup.js +7 -1
- package/dist/test-setup.js.map +1 -1
- package/dist/tool-surface/crib-cache.d.ts +21 -0
- package/dist/tool-surface/crib-cache.d.ts.map +1 -0
- package/dist/tool-surface/crib-cache.js +54 -0
- package/dist/tool-surface/crib-cache.js.map +1 -0
- package/dist/tool-surface/crib-hook.d.ts +78 -0
- package/dist/tool-surface/crib-hook.d.ts.map +1 -0
- package/dist/tool-surface/crib-hook.js +225 -0
- package/dist/tool-surface/crib-hook.js.map +1 -0
- package/dist/tool-surface/crib-sheet.d.ts +56 -0
- package/dist/tool-surface/crib-sheet.d.ts.map +1 -0
- package/dist/tool-surface/crib-sheet.js +129 -0
- package/dist/tool-surface/crib-sheet.js.map +1 -0
- package/dist/tool-surface/mcp-tool-source.d.ts +64 -0
- package/dist/tool-surface/mcp-tool-source.d.ts.map +1 -0
- package/dist/tool-surface/mcp-tool-source.js +189 -0
- package/dist/tool-surface/mcp-tool-source.js.map +1 -0
- package/dist/utils/event-catalog.d.ts +144 -6
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +25 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/widgets/tool.d.ts +9 -0
- package/dist/widgets/tool.d.ts.map +1 -1
- package/dist/widgets/tool.js +1 -0
- package/dist/widgets/tool.js.map +1 -1
- package/openclaw.plugin.json +11 -1
- package/package.json +5 -2
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide state the plugin must keep across a 10.x plugin reload, pinned on `globalThis`.
|
|
3
|
+
*
|
|
4
|
+
* OpenClaw 10.10 replaces a plugin whose `plugins.entries.<id>` changes (`reloadGatewayPlugins`)
|
|
5
|
+
* in the same gateway process, and it loads the replacement from a fresh source capture, so this
|
|
6
|
+
* module, `index.ts` and every class in them are evaluated again. A module-scope variable starts
|
|
7
|
+
* over; only `globalThis` is shared by every module copy (the reason `strategies-store.ts` pins its
|
|
8
|
+
* store there). What a reload must not forget lives here:
|
|
9
|
+
*
|
|
10
|
+
* - the deploy controller per deploys dir, and whether its boot scan ran: a re-registration must
|
|
11
|
+
* not stamp the deploy the previous registration is still running `interrupted`, and its
|
|
12
|
+
* `running()` / `inFlight()` must keep seeing that job so single-flight and the idle gate hold;
|
|
13
|
+
* - the trackers the self-update idle gate and the approval gate read (money calls, open
|
|
14
|
+
* approvals, run kinds), and the idle gate's own activity (user runs, subagents, queued and
|
|
15
|
+
* recent user messages), so an order, a prompt, a run or a message seen by the previous
|
|
16
|
+
* registration still counts after it; and the idle gate's lifecycle-listener handle, so a new
|
|
17
|
+
* registration unsubscribes the old listener instead of stacking one more per reload;
|
|
18
|
+
* - the approval gate's unclassified-block count that `senpi status` warns about;
|
|
19
|
+
* - the per-wallet install fence and the two locks that keep one change at a time: the per-runtime
|
|
20
|
+
* delete/apply lock and the registry-file lock. An install, apply or delete the previous
|
|
21
|
+
* registration started may still be running (a deploy job is not drained by a reload), and a
|
|
22
|
+
* second install on the same wallet, or an interleaved registry write, would break the
|
|
23
|
+
* one-runtime-per-wallet rule or drop a funded wallet's registry row;
|
|
24
|
+
* - the in-process order-call count, the facts-send lock and the 5.x notice latch.
|
|
25
|
+
*
|
|
26
|
+
* Only state lives here. Hooks, services and gateway methods are registered on each new `api`.
|
|
27
|
+
* Nothing held may write through an old registration's `api`: logging goes through
|
|
28
|
+
* {@link processLog}, which forwards to the latest full registration's logger.
|
|
29
|
+
*
|
|
30
|
+
* The held objects keep the class of the module copy that made them. That is safe while a reload
|
|
31
|
+
* loads the same code, which is the case this covers: an update installs new code and restarts the
|
|
32
|
+
* gateway, which starts a new process. A change to this shape must change {@link PROCESS_STATE_KEY}.
|
|
33
|
+
*/
|
|
34
|
+
import type { DeployJobController } from "../deploy/job.js";
|
|
35
|
+
import type { PendingApprovalTracker } from "../approvals/tool-approval-gate.js";
|
|
36
|
+
import type { TurnContextTracker } from "../approvals/turn-context.js";
|
|
37
|
+
import type { KeyedMutex } from "../utils/keyed-mutex.js";
|
|
38
|
+
import type { MoneyCallTracker } from "./auto-update/money-call-tracker.js";
|
|
39
|
+
import type { IdleGateActivity } from "./auto-update/idle-gate.js";
|
|
40
|
+
import type { ScannerRowLite } from "../deploy/orchestrator.js";
|
|
41
|
+
/** The logger shape the held objects write through. */
|
|
42
|
+
export interface ProcessLogger {
|
|
43
|
+
info(line: string): void;
|
|
44
|
+
warn(line: string): void;
|
|
45
|
+
error?(line: string): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* How a runtime an orphaned install started was settled (see {@link RuntimeHost}):
|
|
49
|
+
* - `running`: the live registration already runs a runtime on that id or wallet (`unwired` as
|
|
50
|
+
* its `unwiredRuntimes` records it);
|
|
51
|
+
* - `booted`: the live registration started the registry row itself (`unwired` as an install reports it);
|
|
52
|
+
* - `pending`: no live registration yet; the next service start boots the row;
|
|
53
|
+
* - `no-row`: the registry has no row under that id, so there is nothing to run;
|
|
54
|
+
* - `failed`: the live registration could not start the row; the next restart tries again.
|
|
55
|
+
*/
|
|
56
|
+
export type RuntimeHandOff = {
|
|
57
|
+
outcome: "running";
|
|
58
|
+
runtimeId: string;
|
|
59
|
+
unwired?: string;
|
|
60
|
+
} | {
|
|
61
|
+
outcome: "booted";
|
|
62
|
+
runtimeId: string;
|
|
63
|
+
unwired?: string;
|
|
64
|
+
} | {
|
|
65
|
+
outcome: "pending";
|
|
66
|
+
} | {
|
|
67
|
+
outcome: "no-row";
|
|
68
|
+
} | {
|
|
69
|
+
outcome: "failed";
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The registration whose service is running, as other registrations see it. An install that
|
|
74
|
+
* outlived its registration's service (a 10.x reload stopped it mid-install) hands its runtime here
|
|
75
|
+
* so the live registration owns and wires it, with its own api, hooks and logger.
|
|
76
|
+
*/
|
|
77
|
+
export interface RuntimeHost {
|
|
78
|
+
/**
|
|
79
|
+
* Make sure the registry row `runtimeId` runs in this registration: no-op when this registration
|
|
80
|
+
* already runs that id or a runtime on `walletKey` (folded), else start the row. Never throws.
|
|
81
|
+
*/
|
|
82
|
+
adoptRuntime(request: {
|
|
83
|
+
runtimeId: string;
|
|
84
|
+
walletKey: string;
|
|
85
|
+
}): Promise<RuntimeHandOff>;
|
|
86
|
+
/**
|
|
87
|
+
* The live registration's `deleteRuntimeCore`. A stopped registration forwards its deletes here:
|
|
88
|
+
* it holds no runtime handles, so its own delete would remove the row and archive the state dir
|
|
89
|
+
* while the live registration's runtime keeps trading.
|
|
90
|
+
*/
|
|
91
|
+
deleteRuntime(params: Record<string, unknown> | undefined): Promise<RuntimeDeleteResult>;
|
|
92
|
+
/** Whether the live registration runs `runtimeId` with its entry scanners wired (the deploy's H4 check). */
|
|
93
|
+
runtimeIsLive(runtimeId: string): Promise<boolean>;
|
|
94
|
+
/** The live registration's scanner rows for `runtimeId`, or null when it does not run it. */
|
|
95
|
+
getScannerRows(runtimeId: string): Promise<ScannerRowLite[] | null>;
|
|
96
|
+
}
|
|
97
|
+
/** What `deleteRuntimeCore` answers. */
|
|
98
|
+
export type RuntimeDeleteResult = {
|
|
99
|
+
ok: true;
|
|
100
|
+
payload: {
|
|
101
|
+
id: string;
|
|
102
|
+
};
|
|
103
|
+
} | {
|
|
104
|
+
ok: false;
|
|
105
|
+
error: {
|
|
106
|
+
code: string;
|
|
107
|
+
message: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/** Everything one gateway process keeps across plugin registrations. */
|
|
111
|
+
export interface RuntimeProcessState {
|
|
112
|
+
/** The latest full registration's `api.logger`; {@link processLog} forwards to it. */
|
|
113
|
+
logger: ProcessLogger | null;
|
|
114
|
+
/** One deploy controller per deploys dir, reused by every registration in this process. */
|
|
115
|
+
deployControllers: Map<string, DeployJobController>;
|
|
116
|
+
/** Deploys dirs whose boot scan already ran in this process. */
|
|
117
|
+
bootScanned: Set<string>;
|
|
118
|
+
moneyCalls?: MoneyCallTracker;
|
|
119
|
+
pendingApprovals?: PendingApprovalTracker;
|
|
120
|
+
turnContext?: TurnContextTracker;
|
|
121
|
+
/** What the self-update idle gate has seen (user runs, subagents, user messages). */
|
|
122
|
+
idleGateActivity?: IdleGateActivity;
|
|
123
|
+
/** The unsubscribe handle of the idle gate's `onAgentEvent` lifecycle listener, from the last full registration. */
|
|
124
|
+
idleGateUnsubscribe?: unknown;
|
|
125
|
+
/** Gated calls the 10.x approval gate refused as `run_unclassified` in this process, and when the last was. */
|
|
126
|
+
unclassifiedBlocks: number;
|
|
127
|
+
lastUnclassifiedBlockAt?: string;
|
|
128
|
+
/**
|
|
129
|
+
* The wallets (folded) with a runtime install running in this process, and which runtime. The
|
|
130
|
+
* `[E_WALLET_INSTALL_IN_FLIGHT]` fence in `installRuntimeCore` and the reaper's delete check read it.
|
|
131
|
+
*/
|
|
132
|
+
installsInFlight: Map<string, {
|
|
133
|
+
runtimeId: string;
|
|
134
|
+
startedAtMs: number;
|
|
135
|
+
}>;
|
|
136
|
+
/** One delete or update apply per runtime id at a time (`runtimeChangeLock`). */
|
|
137
|
+
runtimeChangeLock?: KeyedMutex;
|
|
138
|
+
/** One registry-file writer per state dir at a time (`withRegistryLock`). */
|
|
139
|
+
registryLock?: KeyedMutex;
|
|
140
|
+
/** The registration whose service is running; set at the end of its start, cleared by its stop. */
|
|
141
|
+
runtimeHost: RuntimeHost | null;
|
|
142
|
+
/**
|
|
143
|
+
* Runtimes an orphaned install handed off while no registration was live, runtime id → folded
|
|
144
|
+
* wallet. The next {@link RuntimeHost} adopts them when its start publishes it.
|
|
145
|
+
*/
|
|
146
|
+
pendingRuntimeHandOffs: Map<string, string>;
|
|
147
|
+
/** One StrategyFacts send per runtime at a time, across registrations. */
|
|
148
|
+
factsSendLock?: KeyedMutex;
|
|
149
|
+
/** Whether the 5.x "cannot classify runs" notice was logged in this process. */
|
|
150
|
+
legacyTurnClassificationNoticeLogged: boolean;
|
|
151
|
+
/** The runtime's own order/close MCP calls in flight, across every module copy. */
|
|
152
|
+
orderCallsInFlight: number;
|
|
153
|
+
}
|
|
154
|
+
/** The process's state, created on first use. Every module copy reads and writes the same object. */
|
|
155
|
+
export declare function runtimeProcessState(): RuntimeProcessState;
|
|
156
|
+
/** Drops the process state, as a new process would start. Tests only. */
|
|
157
|
+
export declare function resetRuntimeProcessStateForTests(): void;
|
|
158
|
+
/**
|
|
159
|
+
* Makes `logger` the sink {@link processLog} writes to. Called on every full registration, so a
|
|
160
|
+
* held object that outlives its registration (a running deploy) logs through the current one.
|
|
161
|
+
*/
|
|
162
|
+
export declare function bindProcessLogger(logger: ProcessLogger): void;
|
|
163
|
+
/**
|
|
164
|
+
* A logger that resolves the current registration's logger at each call. Never throws: it is the
|
|
165
|
+
* narration path of a running deploy, which a logger fault must not change.
|
|
166
|
+
*/
|
|
167
|
+
export declare const processLog: Required<ProcessLogger>;
|
|
168
|
+
//# sourceMappingURL=process-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-state.d.ts","sourceRoot":"","sources":["../../src/runtime/process-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,OAAO,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GACtB;IAAE,OAA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C1C,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,oHAAoH;IACpH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,+GAA+G;IAC/G,kBAAkB,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,iFAAiF;IACjF,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B,6EAA6E;IAC7E,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,mGAAmG;IACnG,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,0EAA0E;IAC1E,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,gFAAgF;IAChF,oCAAoC,EAAE,OAAO,CAAC;IAC9C,mFAAmF;IACnF,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAID,qGAAqG;AACrG,wBAAgB,mBAAmB,IAAI,mBAAmB,CAczD;AAED,yEAAyE;AACzE,wBAAgB,gCAAgC,IAAI,IAAI,CAEvD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAE7D;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,aAAa,CAI9C,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide state the plugin must keep across a 10.x plugin reload, pinned on `globalThis`.
|
|
3
|
+
*
|
|
4
|
+
* OpenClaw 10.10 replaces a plugin whose `plugins.entries.<id>` changes (`reloadGatewayPlugins`)
|
|
5
|
+
* in the same gateway process, and it loads the replacement from a fresh source capture, so this
|
|
6
|
+
* module, `index.ts` and every class in them are evaluated again. A module-scope variable starts
|
|
7
|
+
* over; only `globalThis` is shared by every module copy (the reason `strategies-store.ts` pins its
|
|
8
|
+
* store there). What a reload must not forget lives here:
|
|
9
|
+
*
|
|
10
|
+
* - the deploy controller per deploys dir, and whether its boot scan ran: a re-registration must
|
|
11
|
+
* not stamp the deploy the previous registration is still running `interrupted`, and its
|
|
12
|
+
* `running()` / `inFlight()` must keep seeing that job so single-flight and the idle gate hold;
|
|
13
|
+
* - the trackers the self-update idle gate and the approval gate read (money calls, open
|
|
14
|
+
* approvals, run kinds), and the idle gate's own activity (user runs, subagents, queued and
|
|
15
|
+
* recent user messages), so an order, a prompt, a run or a message seen by the previous
|
|
16
|
+
* registration still counts after it; and the idle gate's lifecycle-listener handle, so a new
|
|
17
|
+
* registration unsubscribes the old listener instead of stacking one more per reload;
|
|
18
|
+
* - the approval gate's unclassified-block count that `senpi status` warns about;
|
|
19
|
+
* - the per-wallet install fence and the two locks that keep one change at a time: the per-runtime
|
|
20
|
+
* delete/apply lock and the registry-file lock. An install, apply or delete the previous
|
|
21
|
+
* registration started may still be running (a deploy job is not drained by a reload), and a
|
|
22
|
+
* second install on the same wallet, or an interleaved registry write, would break the
|
|
23
|
+
* one-runtime-per-wallet rule or drop a funded wallet's registry row;
|
|
24
|
+
* - the in-process order-call count, the facts-send lock and the 5.x notice latch.
|
|
25
|
+
*
|
|
26
|
+
* Only state lives here. Hooks, services and gateway methods are registered on each new `api`.
|
|
27
|
+
* Nothing held may write through an old registration's `api`: logging goes through
|
|
28
|
+
* {@link processLog}, which forwards to the latest full registration's logger.
|
|
29
|
+
*
|
|
30
|
+
* The held objects keep the class of the module copy that made them. That is safe while a reload
|
|
31
|
+
* loads the same code, which is the case this covers: an update installs new code and restarts the
|
|
32
|
+
* gateway, which starts a new process. A change to this shape must change {@link PROCESS_STATE_KEY}.
|
|
33
|
+
*/
|
|
34
|
+
const PROCESS_STATE_KEY = Symbol.for("senpi.runtime.processState.v1");
|
|
35
|
+
/** The process's state, created on first use. Every module copy reads and writes the same object. */
|
|
36
|
+
export function runtimeProcessState() {
|
|
37
|
+
const holder = globalThis;
|
|
38
|
+
holder[PROCESS_STATE_KEY] ??= {
|
|
39
|
+
logger: null,
|
|
40
|
+
deployControllers: new Map(),
|
|
41
|
+
bootScanned: new Set(),
|
|
42
|
+
installsInFlight: new Map(),
|
|
43
|
+
runtimeHost: null,
|
|
44
|
+
pendingRuntimeHandOffs: new Map(),
|
|
45
|
+
legacyTurnClassificationNoticeLogged: false,
|
|
46
|
+
orderCallsInFlight: 0,
|
|
47
|
+
unclassifiedBlocks: 0,
|
|
48
|
+
};
|
|
49
|
+
return holder[PROCESS_STATE_KEY];
|
|
50
|
+
}
|
|
51
|
+
/** Drops the process state, as a new process would start. Tests only. */
|
|
52
|
+
export function resetRuntimeProcessStateForTests() {
|
|
53
|
+
delete globalThis[PROCESS_STATE_KEY];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Makes `logger` the sink {@link processLog} writes to. Called on every full registration, so a
|
|
57
|
+
* held object that outlives its registration (a running deploy) logs through the current one.
|
|
58
|
+
*/
|
|
59
|
+
export function bindProcessLogger(logger) {
|
|
60
|
+
runtimeProcessState().logger = logger;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A logger that resolves the current registration's logger at each call. Never throws: it is the
|
|
64
|
+
* narration path of a running deploy, which a logger fault must not change.
|
|
65
|
+
*/
|
|
66
|
+
export const processLog = {
|
|
67
|
+
info: (line) => forward("info", line),
|
|
68
|
+
warn: (line) => forward("warn", line),
|
|
69
|
+
error: (line) => forward("error", line),
|
|
70
|
+
};
|
|
71
|
+
function forward(level, line) {
|
|
72
|
+
try {
|
|
73
|
+
const logger = runtimeProcessState().logger;
|
|
74
|
+
const write = logger?.[level] ?? logger?.warn;
|
|
75
|
+
write?.call(logger, line);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Narration only.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=process-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-state.js","sourceRoot":"","sources":["../../src/runtime/process-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAuGH,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEtE,qGAAqG;AACrG,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,UAA2D,CAAC;IAC3E,MAAM,CAAC,iBAAiB,CAAC,KAAK;QAC5B,MAAM,EAAE,IAAI;QACZ,iBAAiB,EAAE,IAAI,GAAG,EAAE;QAC5B,WAAW,EAAE,IAAI,GAAG,EAAE;QACtB,gBAAgB,EAAE,IAAI,GAAG,EAAE;QAC3B,WAAW,EAAE,IAAI;QACjB,sBAAsB,EAAE,IAAI,GAAG,EAAE;QACjC,oCAAoC,EAAE,KAAK;QAC3C,kBAAkB,EAAE,CAAC;QACrB,kBAAkB,EAAE,CAAC;KACtB,CAAC;IACF,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACnC,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,gCAAgC;IAC9C,OAAQ,UAA4D,CAAC,iBAAiB,CAAC,CAAC;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAqB;IACrD,mBAAmB,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAA4B;IACjD,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;IACrC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;IACrC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;CACxC,CAAC;AAEF,SAAS,OAAO,CAAC,KAAgC,EAAE,IAAY;IAC7D,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC,MAAM,CAAC;QAC5C,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,MAAM,EAAE,IAAI,CAAC;QAC9C,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile-state.d.ts","sourceRoot":"","sources":["../../src/runtime/reconcile-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"reconcile-state.d.ts","sourceRoot":"","sources":["../../src/runtime/reconcile-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MA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|
|
@@ -9,6 +9,7 @@ import { buildStopHitClosedFields } from "../dsl/events/build-closed-event.js";
|
|
|
9
9
|
import { createLogger } from "../utils/logger.js";
|
|
10
10
|
import { withRetry } from "../utils/retry.js";
|
|
11
11
|
import { normalizeDslCoinDex } from "../utils/perp-coin.js";
|
|
12
|
+
import { recordDslDegradation } from "../telemetry/metrics.js";
|
|
12
13
|
const logger = createLogger("[senpi-core][reconcile]");
|
|
13
14
|
function positionKey(address, asset, dex) {
|
|
14
15
|
return `${address}:${asset}:${dex ?? ""}`;
|
|
@@ -16,7 +17,7 @@ function positionKey(address, asset, dex) {
|
|
|
16
17
|
async function resolveMissingPositionCloseReason(senpi, state, strategyState, strategyStateOnly) {
|
|
17
18
|
const slOrderId = state.slOrderId;
|
|
18
19
|
if (slOrderId == null)
|
|
19
|
-
return CLOSE_REASON.CLOSED_EXTERNALLY;
|
|
20
|
+
return { reason: CLOSE_REASON.CLOSED_EXTERNALLY, stopResting: false };
|
|
20
21
|
try {
|
|
21
22
|
const status = await withRetry(() => {
|
|
22
23
|
if (strategyState)
|
|
@@ -38,7 +39,8 @@ async function resolveMissingPositionCloseReason(senpi, state, strategyState, st
|
|
|
38
39
|
}),
|
|
39
40
|
});
|
|
40
41
|
if (status?.filled)
|
|
41
|
-
return CLOSE_REASON.EXCHANGE_SL_HIT;
|
|
42
|
+
return { reason: CLOSE_REASON.EXCHANGE_SL_HIT, stopResting: false };
|
|
43
|
+
return { reason: CLOSE_REASON.CLOSED_EXTERNALLY, stopResting: status?.status === "open" };
|
|
42
44
|
}
|
|
43
45
|
catch (err) {
|
|
44
46
|
logger.warn("reconcile: getOrderStatus failed while classifying missing position", {
|
|
@@ -48,7 +50,7 @@ async function resolveMissingPositionCloseReason(senpi, state, strategyState, st
|
|
|
48
50
|
err,
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
|
-
return CLOSE_REASON.CLOSED_EXTERNALLY;
|
|
53
|
+
return { reason: CLOSE_REASON.CLOSED_EXTERNALLY, stopResting: false };
|
|
52
54
|
}
|
|
53
55
|
export async function archiveGoneState(stateManager, senpi, state, opts) {
|
|
54
56
|
const ts = new Date().toISOString();
|
|
@@ -73,7 +75,7 @@ export async function archiveGoneState(stateManager, senpi, state, opts) {
|
|
|
73
75
|
outcome = "skipped";
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
|
-
const archivedCloseReason = await resolveMissingPositionCloseReason(senpi, state, opts?.strategyState, strategyStateOnly);
|
|
78
|
+
const { reason: archivedCloseReason, stopResting } = await resolveMissingPositionCloseReason(senpi, state, opts?.strategyState, strategyStateOnly);
|
|
77
79
|
const closedState = {
|
|
78
80
|
...state,
|
|
79
81
|
active: false,
|
|
@@ -87,6 +89,18 @@ export async function archiveGoneState(stateManager, senpi, state, opts) {
|
|
|
87
89
|
asset: state.asset,
|
|
88
90
|
closeReason: archivedCloseReason,
|
|
89
91
|
});
|
|
92
|
+
// The stop read `open` at archive time. The engine cancels it after the close fills,
|
|
93
|
+
// so this can be the gap before that cancel; a stop that stays is a leftover. The
|
|
94
|
+
// count makes either visible in telemetry, where a box log is not.
|
|
95
|
+
if (stopResting) {
|
|
96
|
+
logger.warn("reconcile: archived position's stop still resting at archive time", {
|
|
97
|
+
address: state.address,
|
|
98
|
+
asset: state.asset,
|
|
99
|
+
dex: normalizeDslCoinDex(state.asset, dex).dex,
|
|
100
|
+
slOrderId: state.slOrderId,
|
|
101
|
+
});
|
|
102
|
+
recordDslDegradation({ failure: "stop_resting_at_archive" });
|
|
103
|
+
}
|
|
90
104
|
if (opts?.bus) {
|
|
91
105
|
const tsEmit = new Date().toISOString();
|
|
92
106
|
// Dex only for a non-main book, so an xyz close is distinct from the same base coin on main.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile-state.js","sourceRoot":"","sources":["../../src/runtime/reconcile-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM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GAAG,EAAE,EAAE,CACnC,MAAM,CAAC,IAAI,CAAC,gDAAgD,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;aACtG,CACF,CAAC;YACF,4BAA4B,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC1C,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;gBAC1B,MAAM,IAAI,GAAI,CAAuB,CAAC,IAAI,IAAI,EAAE,CAAC;gBACjD,MAAM,GAAG,GAAI,CAAsB,CAAC,GAAG,IAAI,EAAE,CAAC;gBAC9C,IAAI,IAAI;oBAAE,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,2FAA2F,EAAE;gBACvG,OAAO;gBACP,GAAG;aACJ,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IACF,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE;QACrD,wBAAwB,EAAE,mBAAmB,CAAC,IAAI;QAClD,wBAAwB,EAAE,4BAA4B,CAAC,IAAI;KAC5D,CAAC,CAAC;IAEH,KAAK,MAAM,OAAO,IAAI,4BAA4B,EAAE,CAAC;QACnD,MAAM,oBAAoB,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE;YAC5E,GAAG;YACH,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC;YACpD,iBAAiB;SAClB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -65,6 +65,22 @@ export declare function readRegistry(stateDir: string): Promise<InstalledRuntime
|
|
|
65
65
|
* Write the registry atomically (temp file then rename).
|
|
66
66
|
*/
|
|
67
67
|
export declare function writeRegistry(stateDir: string, data: InstalledRuntimeRegistry): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* One read-modify-write of the registry at a time, across the whole process.
|
|
70
|
+
*
|
|
71
|
+
* Every writer — install, delete, an update's apply — reads the file, changes one entry, and writes
|
|
72
|
+
* a full snapshot back. Two of them interleaved both read the same snapshot, and the later atomic
|
|
73
|
+
* rename discards the earlier change: an installed runtime vanishes from the registry, a deleted
|
|
74
|
+
* one comes back, or an applied recipe silently reverts at the next boot. Keyed on the state dir
|
|
75
|
+
* (one registry file per dir), not the runtime id, because the collision is between writers of the
|
|
76
|
+
* same FILE whichever entry they touch. A process-wide lock is enough: the CLI dispatches every
|
|
77
|
+
* registry change to the gateway, so all writers run in this one process. The mutex lives in the
|
|
78
|
+
* process state (`process-state.ts`), so a writer from before a 10.x plugin reload (which
|
|
79
|
+
* evaluates a new copy of this module) and one from after it still take the same lock.
|
|
80
|
+
*
|
|
81
|
+
* The read must happen INSIDE `fn`: a snapshot read before taking the lock is exactly the stale copy
|
|
82
|
+
* this exists to prevent. NON-REENTRANT (see {@link KeyedMutex}) — never call it from inside itself.
|
|
83
|
+
*/
|
|
68
84
|
export declare function withRegistryLock<T>(stateDir: string, fn: () => Promise<T>): Promise<T>;
|
|
69
85
|
/**
|
|
70
86
|
* Validate that an entry has exactly one of runtimeYamlPath or runtimeYamlContent and id is safe.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/strategy-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"strategy-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/strategy-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,eAAO,MAAM,iBAAiB,4BAA4B,CAAC;AAI3D,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,uEAA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AAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAItF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,qBAAqB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAiBvG;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAMlH"}
|
|
@@ -9,6 +9,7 @@ import { readFile, writeFile, rename, mkdir } from "node:fs/promises";
|
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { createLogger } from "../utils/logger.js";
|
|
11
11
|
import { KeyedMutex } from "../utils/keyed-mutex.js";
|
|
12
|
+
import { runtimeProcessState } from "./process-state.js";
|
|
12
13
|
const logger = createLogger("[senpi-core][runtime-registry]");
|
|
13
14
|
export const REGISTRY_FILENAME = "installed_runtimes.json";
|
|
14
15
|
const PREV_REGISTRY_FILENAME = "installed_recipes.json";
|
|
@@ -241,14 +242,17 @@ export async function writeRegistry(stateDir, data) {
|
|
|
241
242
|
* one comes back, or an applied recipe silently reverts at the next boot. Keyed on the state dir
|
|
242
243
|
* (one registry file per dir), not the runtime id, because the collision is between writers of the
|
|
243
244
|
* same FILE whichever entry they touch. A process-wide lock is enough: the CLI dispatches every
|
|
244
|
-
* registry change to the gateway, so all writers run in this one process.
|
|
245
|
+
* registry change to the gateway, so all writers run in this one process. The mutex lives in the
|
|
246
|
+
* process state (`process-state.ts`), so a writer from before a 10.x plugin reload (which
|
|
247
|
+
* evaluates a new copy of this module) and one from after it still take the same lock.
|
|
245
248
|
*
|
|
246
249
|
* The read must happen INSIDE `fn`: a snapshot read before taking the lock is exactly the stale copy
|
|
247
250
|
* this exists to prevent. NON-REENTRANT (see {@link KeyedMutex}) — never call it from inside itself.
|
|
248
251
|
*/
|
|
249
|
-
const registryLock = new KeyedMutex();
|
|
250
252
|
export function withRegistryLock(stateDir, fn) {
|
|
251
|
-
|
|
253
|
+
const state = runtimeProcessState();
|
|
254
|
+
state.registryLock ??= new KeyedMutex();
|
|
255
|
+
return state.registryLock.withKeyLock(stateDir, fn);
|
|
252
256
|
}
|
|
253
257
|
/**
|
|
254
258
|
* Validate that an entry has exactly one of runtimeYamlPath or runtimeYamlContent and id is safe.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy-registry.js","sourceRoot":"","sources":["../../src/runtime/strategy-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"strategy-registry.js","sourceRoot":"","sources":["../../src/runtime/strategy-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,mB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1F,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -32,10 +32,12 @@ import { KeyedMutex } from "../utils/keyed-mutex.js";
|
|
|
32
32
|
* Two deletes of one runtime would otherwise both tear down its DSL and both emit
|
|
33
33
|
* `runtime.deleted`; under the lock the second finds the row gone.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
* runtime id so unrelated strategies still apply in parallel.
|
|
35
|
+
* Process-wide because the gateway holds one process per box and both calls arrive on it; keyed by
|
|
36
|
+
* runtime id so unrelated strategies still apply in parallel. The mutex lives in the process state
|
|
37
|
+
* (`process-state.ts`), not this module: a 10.x plugin reload evaluates a new copy of this module
|
|
38
|
+
* while an apply or delete the previous registration started may still hold the lock.
|
|
37
39
|
*/
|
|
38
|
-
export declare const runtimeChangeLock: KeyedMutex
|
|
40
|
+
export declare const runtimeChangeLock: Pick<KeyedMutex, "withKeyLock" | "hasKey">;
|
|
39
41
|
/** The part of a `verifyProof` result this needs: whether it passed, and what it hashed. */
|
|
40
42
|
export interface ProofOutcome {
|
|
41
43
|
ok: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-apply-deps.d.ts","sourceRoot":"","sources":["../../src/runtime/update-apply-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,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S,CAAA;CAAE;AAC3D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,gBAAgB,CAAC,EAAE,CACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,YAAY,KACjB,OAAO,CAAC,IAAI,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACxC,CACD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,YAAY,KACjB,OAAO,CAAC;IAAE,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBzC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GACnB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAiB5D"}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { readRegistry, writeRegistry, withRegistryLock } from "./strategy-registry.js";
|
|
17
17
|
import { KeyedMutex } from "../utils/keyed-mutex.js";
|
|
18
|
+
import { runtimeProcessState } from "./process-state.js";
|
|
18
19
|
/**
|
|
19
20
|
* One apply or delete at a time, per runtime, across the whole process.
|
|
20
21
|
*
|
|
@@ -31,10 +32,21 @@ import { KeyedMutex } from "../utils/keyed-mutex.js";
|
|
|
31
32
|
* Two deletes of one runtime would otherwise both tear down its DSL and both emit
|
|
32
33
|
* `runtime.deleted`; under the lock the second finds the row gone.
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
-
* runtime id so unrelated strategies still apply in parallel.
|
|
35
|
+
* Process-wide because the gateway holds one process per box and both calls arrive on it; keyed by
|
|
36
|
+
* runtime id so unrelated strategies still apply in parallel. The mutex lives in the process state
|
|
37
|
+
* (`process-state.ts`), not this module: a 10.x plugin reload evaluates a new copy of this module
|
|
38
|
+
* while an apply or delete the previous registration started may still hold the lock.
|
|
36
39
|
*/
|
|
37
|
-
export const runtimeChangeLock =
|
|
40
|
+
export const runtimeChangeLock = {
|
|
41
|
+
withKeyLock: (key, fn) => heldRuntimeChangeLock().withKeyLock(key, fn),
|
|
42
|
+
hasKey: (key) => heldRuntimeChangeLock().hasKey(key),
|
|
43
|
+
};
|
|
44
|
+
/** The process's {@link runtimeChangeLock} mutex, created on first use. */
|
|
45
|
+
function heldRuntimeChangeLock() {
|
|
46
|
+
const state = runtimeProcessState();
|
|
47
|
+
state.runtimeChangeLock ??= new KeyedMutex();
|
|
48
|
+
return state.runtimeChangeLock;
|
|
49
|
+
}
|
|
38
50
|
/**
|
|
39
51
|
* Decide whether a proof covers the recipe actually being applied.
|
|
40
52
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-apply-deps.js","sourceRoot":"","sources":["../../src/runtime/update-apply-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"update-apply-deps.js","sourceRoot":"","sources":["../../src/runtime/update-apply-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA+C;IAC3E,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,EAA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gBAAgB,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;QACxC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC/C,IAAI,KAAK,CAAC,EAAE,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;YACzC,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YAC3F,OAAO;gBACL,GAAG,IAAI;gBACP,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;oBAC3B,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,IAAI,EAAE;oBAClC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;gBACjD,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpE,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,aAAa,CAAC,YAAY,EAAE,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/senpi/client.d.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import type { McpTransport, SenpiClientConfig, CreatePositionRequest, CreatePositionResult, EditPositionResult, OrderStatus, GetPositionResult, OpenPosition, GetStrategyResult, GetOpenOrdersResult, GetTraderHistoryOptions, TraderHistoryEntry, GetTraderStateOptions, TraderStateResult, StrategyFundResult, CreateCustomStrategyParams, CreateCustomStrategyResult, StrategyMetadataPatch, StrategyMetadataPatchResult, PortfolioPayload, ClosePositionsRequest, GetPnlHistoryOptions, ListStrategiesFilters, StrategySummary, RatchetStopPosition, RatchetStopEvent, AddRatchetStopInput, EditRatchetStopInput, DeleteRatchetStopInput, QueryRatchetStopsInput, QueryRatchetStopEventsInput } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* MCP tools that move money or change protection: place, change or close an
|
|
4
|
+
* order or position, create and fund a strategy wallet, fund or withdraw,
|
|
5
|
+
* add, move or delete a stop. While one
|
|
6
|
+
* of these is in flight the box is not idle for a self-update restart
|
|
7
|
+
* (`runtime/auto-update/idle-gate.ts`): a restart mid-call would leave the
|
|
8
|
+
* caller without the outcome.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ORDER_CALL_TOOLS: ReadonlySet<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a bare Senpi tool name moves money or changes protection, for the
|
|
13
|
+
* self-update idle gate: {@link ORDER_CALL_TOOLS} plus every trade tool in the
|
|
14
|
+
* approval manifest (`approvals/tool-approvals-manifest.json`). One set for
|
|
15
|
+
* both counters, the in-process {@link senpiOrderCallsInFlight} and the agent's
|
|
16
|
+
* hook-counted calls, so a money tool added to the manifest is never missed by
|
|
17
|
+
* one of them. The explicit list keeps counting a tool even if the manifest
|
|
18
|
+
* stops gating it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isMoneyCallTool(bare: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Order/close MCP calls currently in flight across every `SenpiClient` in this process. The count
|
|
23
|
+
* lives in the process state, not this module: a 10.x plugin reload evaluates a new copy of this
|
|
24
|
+
* module while the previous copy's calls are still running, and the idle gate must see both.
|
|
25
|
+
*/
|
|
26
|
+
export declare function senpiOrderCallsInFlight(): number;
|
|
2
27
|
/**
|
|
3
28
|
* Typed error thrown by `SenpiClient` mutation methods when the response
|
|
4
29
|
* reports a failure at either layer (outer MCP envelope or inner engine
|
|
@@ -112,11 +137,15 @@ export declare class SenpiClient {
|
|
|
112
137
|
disconnect(): Promise<void>;
|
|
113
138
|
/**
|
|
114
139
|
* Wrap each Senpi MCP call in an on-site `tools/call` span (`mcp.*` + `gen_ai.tool.*`).
|
|
140
|
+
* Money calls ({@link isMoneyCallTool}) also count in
|
|
141
|
+
* {@link senpiOrderCallsInFlight} while they run.
|
|
115
142
|
* `withSpan` uses `startActiveSpan`, so it nests under the active trading waterfall and
|
|
116
143
|
* the auto-instrumented `POST /mcp` span nests under it; identity reuses the async-context
|
|
117
144
|
* bag (same source as the logger and trading spans).
|
|
118
145
|
*/
|
|
119
146
|
private callTool;
|
|
147
|
+
/** The span-wrapped body of {@link callTool}. */
|
|
148
|
+
private callToolSpan;
|
|
120
149
|
private callToolInner;
|
|
121
150
|
/**
|
|
122
151
|
* Run an MCP `audit_query` and return the unwrapped response payload.
|