@senpi-ai/runtime 3.0.12 → 3.0.30
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/approvals/approval-store.d.ts +35 -0
- package/dist/approvals/approval-store.d.ts.map +1 -0
- package/dist/approvals/approval-store.js +87 -0
- package/dist/approvals/approval-store.js.map +1 -0
- package/dist/approvals/manifest.d.ts +47 -0
- package/dist/approvals/manifest.d.ts.map +1 -0
- package/dist/approvals/manifest.js +90 -0
- package/dist/approvals/manifest.js.map +1 -0
- package/dist/approvals/telemetry.d.ts +41 -0
- package/dist/approvals/telemetry.d.ts.map +1 -0
- package/dist/approvals/telemetry.js +35 -0
- package/dist/approvals/telemetry.js.map +1 -0
- package/dist/approvals/tool-approval-gate.d.ts +96 -0
- package/dist/approvals/tool-approval-gate.d.ts.map +1 -0
- package/dist/approvals/tool-approval-gate.js +233 -0
- package/dist/approvals/tool-approval-gate.js.map +1 -0
- package/dist/approvals/tool-approvals-manifest.json +27 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -21
- package/dist/index.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.d.ts +37 -12
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +136 -17
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/gateway-restart.d.ts +4 -4
- package/dist/runtime/auto-update/gateway-restart.js +4 -4
- package/dist/runtime/auto-update/types.d.ts +1 -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-api/config.d.ts +2 -2
- package/dist/runtime-api/config.js +4 -4
- package/dist/runtime-api/config.js.map +1 -1
- package/dist/runtime-api/handlers/ingest-signals.d.ts +5 -3
- package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -1
- package/dist/runtime-api/handlers/ingest-signals.js +14 -5
- package/dist/runtime-api/handlers/ingest-signals.js.map +1 -1
- package/dist/runtime-api/intake/ingest-mutex.d.ts +16 -0
- package/dist/runtime-api/intake/ingest-mutex.d.ts.map +1 -0
- package/dist/runtime-api/intake/ingest-mutex.js +18 -0
- package/dist/runtime-api/intake/ingest-mutex.js.map +1 -0
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +8 -2
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/telemetry/metrics.d.ts +11 -0
- package/dist/telemetry/metrics.d.ts.map +1 -1
- package/dist/telemetry/metrics.js +22 -0
- package/dist/telemetry/metrics.js.map +1 -1
- package/dist/utils/event-catalog.d.ts +103 -2
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +28 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/openclaw.plugin.json +10 -1
- package/package.json +3 -2
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { ToolApprovalStore } from "./approval-store.js";
|
|
2
|
+
import { loadToolApprovalsManifest, } from "./manifest.js";
|
|
3
|
+
import { defaultGateTelemetry } from "./telemetry.js";
|
|
4
|
+
/** Env var that overrides the `toolApprovals` plugin config and the manifest default. */
|
|
5
|
+
export const TOOL_APPROVALS_ENV_VAR = "SENPI_TOOL_APPROVALS";
|
|
6
|
+
// Gateway schema hard limits (plugin.approval.request rejects, not truncates,
|
|
7
|
+
// beyond these — openclaw PLUGIN_APPROVAL_TITLE_MAX_LENGTH / _DESCRIPTION_).
|
|
8
|
+
const TITLE_MAX_LENGTH = 80;
|
|
9
|
+
const DESCRIPTION_MAX_LENGTH = 256;
|
|
10
|
+
/**
|
|
11
|
+
* Match a tool-registry name against the senpi MCP server and return the bare
|
|
12
|
+
* tool name. Covers the embedded-MCP shape (`senpi__create_position`), the
|
|
13
|
+
* CLI-runner backend shape (`mcp__senpi__create_position`), and openclaw's
|
|
14
|
+
* server-name dedupe suffix (`senpi-2__…`).
|
|
15
|
+
*/
|
|
16
|
+
export function matchSenpiTool(toolName) {
|
|
17
|
+
if (typeof toolName !== "string") {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const match = /^(?:mcp__)?senpi(?:-\d+)?__(.+)$/.exec(toolName);
|
|
21
|
+
return match ? match[1] : null;
|
|
22
|
+
}
|
|
23
|
+
export function isToolApprovalsMode(value) {
|
|
24
|
+
return value === "off" || value === "trades" || value === "all";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the gate mode: env {@link TOOL_APPROVALS_ENV_VAR} > plugin config
|
|
28
|
+
* `toolApprovals` > manifest `defaults.mode`. Unrecognized values warn and
|
|
29
|
+
* fall through to the manifest default rather than silently disabling the gate.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveToolApprovalsMode(params) {
|
|
32
|
+
const manifestDefault = (params.manifest ?? loadToolApprovalsManifest()).defaults.mode;
|
|
33
|
+
const candidates = [
|
|
34
|
+
{ source: `env ${TOOL_APPROVALS_ENV_VAR}`, value: params.env?.[TOOL_APPROVALS_ENV_VAR] },
|
|
35
|
+
{ source: 'plugin config "toolApprovals"', value: params.pluginConfig?.toolApprovals },
|
|
36
|
+
];
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if (candidate.value === undefined || candidate.value === null || candidate.value === "") {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const normalized = typeof candidate.value === "string" ? candidate.value.trim().toLowerCase() : candidate.value;
|
|
42
|
+
if (isToolApprovalsMode(normalized)) {
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
params.logger?.warn(`[senpi-tool-approvals] unrecognized ${candidate.source} value ${JSON.stringify(candidate.value)}; using manifest default "${manifestDefault}" (expected off|trades|all)`);
|
|
46
|
+
return manifestDefault;
|
|
47
|
+
}
|
|
48
|
+
return manifestDefault;
|
|
49
|
+
}
|
|
50
|
+
function truncate(value, maxLength) {
|
|
51
|
+
return value.length <= maxLength ? value : `${value.slice(0, maxLength - 1)}…`;
|
|
52
|
+
}
|
|
53
|
+
function str(value) {
|
|
54
|
+
if (typeof value === "string" && value.trim())
|
|
55
|
+
return value.trim();
|
|
56
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
57
|
+
return String(value);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Human sentence for a senpi trade tool call, mirroring senpi-web's own
|
|
62
|
+
* per-tool phrasing (its `getDescription` registry).
|
|
63
|
+
*
|
|
64
|
+
* Why the plugin builds this rather than leaving it to the UI: senpi-web keys
|
|
65
|
+
* that registry by the **bare** tool name and feeds it the call `args`, but for
|
|
66
|
+
* plugin approvals openclaw sends the prefixed registry name
|
|
67
|
+
* (`senpi__create_position`) and has **no `args` field at all` in
|
|
68
|
+
* `PluginApprovalRequestParamsSchema` (additionalProperties: false). So the UI
|
|
69
|
+
* takes its fallback branch and renders `description` verbatim, with no args
|
|
70
|
+
* block — meaning this string is the *only* place the user sees what they are
|
|
71
|
+
* approving. It must therefore carry the numbers, not just the intent.
|
|
72
|
+
*/
|
|
73
|
+
export function describeSenpiToolCall(tool, params) {
|
|
74
|
+
const p = (params ?? {});
|
|
75
|
+
const asset = str(p.asset) ?? str(p.coin) ?? str(p.symbol);
|
|
76
|
+
const strategyId = str(p.strategyId) ?? str(p.strategy_id);
|
|
77
|
+
const amount = str(p.amount) ?? str(p.usdAmount) ?? str(p.margin);
|
|
78
|
+
const leverage = str(p.leverage);
|
|
79
|
+
const direction = str(p.direction) ?? str(p.side);
|
|
80
|
+
const parts = [];
|
|
81
|
+
switch (tool) {
|
|
82
|
+
case "create_position": {
|
|
83
|
+
parts.push(`Open a ${direction ?? ""} position on ${asset ?? "?"}`.replace(/\s+/g, " "));
|
|
84
|
+
if (amount)
|
|
85
|
+
parts.push(`margin $${amount}`);
|
|
86
|
+
if (leverage)
|
|
87
|
+
parts.push(`${leverage}x`);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "close_position":
|
|
91
|
+
parts.push(`Close position ${str(p.positionId) ?? asset ?? ""}`.trim());
|
|
92
|
+
break;
|
|
93
|
+
case "edit_position":
|
|
94
|
+
parts.push(`Edit position ${str(p.positionId) ?? asset ?? ""}`.trim());
|
|
95
|
+
break;
|
|
96
|
+
case "cancel_order":
|
|
97
|
+
parts.push(`Cancel order ${str(p.orderId) ?? ""}`.trim());
|
|
98
|
+
break;
|
|
99
|
+
case "strategy_create":
|
|
100
|
+
case "strategy_create_custom_strategy":
|
|
101
|
+
parts.push(`Create strategy ${str(p.name) ?? asset ?? ""}`.trim());
|
|
102
|
+
break;
|
|
103
|
+
case "strategy_close":
|
|
104
|
+
case "strategy_close_positions":
|
|
105
|
+
parts.push(`Close strategy ${strategyId ?? ""}`.trim());
|
|
106
|
+
break;
|
|
107
|
+
case "strategy_update":
|
|
108
|
+
parts.push(`Update strategy ${strategyId ?? ""}`.trim());
|
|
109
|
+
break;
|
|
110
|
+
case "strategy_pause":
|
|
111
|
+
parts.push(`Pause strategy ${strategyId ?? ""}`.trim());
|
|
112
|
+
break;
|
|
113
|
+
case "strategy_top_up":
|
|
114
|
+
parts.push(`Add ${amount ? `$${amount} ` : ""}funds to strategy ${strategyId ?? ""}`.trim());
|
|
115
|
+
break;
|
|
116
|
+
case "strategy_withdraw_funds":
|
|
117
|
+
parts.push(`Withdraw ${amount ? `$${amount} ` : ""}from strategy ${strategyId ?? ""}`.trim());
|
|
118
|
+
break;
|
|
119
|
+
case "strategy_bridge_funds_from_hyperliquid_to_evm":
|
|
120
|
+
parts.push(`Bridge ${amount ? `$${amount} ` : ""}from Hyperliquid to EVM`.trim());
|
|
121
|
+
break;
|
|
122
|
+
case "transfer_spot_to_perps":
|
|
123
|
+
parts.push(`Transfer ${amount ? `$${amount} ` : ""}from spot to perps`.trim());
|
|
124
|
+
break;
|
|
125
|
+
case "send_usdc":
|
|
126
|
+
parts.push(`Send ${amount ? `$${amount} ` : ""}USDC to ${str(p.to) ?? "?"}`.trim());
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
return parts.filter(Boolean).join(" · ");
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Prompt body: the human sentence when we know the tool, plus the compact raw
|
|
135
|
+
* args so the exact numbers are always visible (senpi-web renders no args block
|
|
136
|
+
* for plugin approvals — see {@link describeSenpiToolCall}). Capped to the
|
|
137
|
+
* gateway's description limit, which rejects (not truncates) anything longer.
|
|
138
|
+
*/
|
|
139
|
+
export function buildApprovalDescription(tool, params) {
|
|
140
|
+
let args = "";
|
|
141
|
+
try {
|
|
142
|
+
args = params === undefined ? "" : JSON.stringify(params);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
args = "[unserializable params]";
|
|
146
|
+
}
|
|
147
|
+
const hasArgs = Boolean(args) && args !== "{}";
|
|
148
|
+
const sentence = describeSenpiToolCall(tool, params);
|
|
149
|
+
const head = sentence ?? tool;
|
|
150
|
+
const base = hasArgs ? `${head} — ${args}` : head;
|
|
151
|
+
return truncate(base, DESCRIPTION_MAX_LENGTH);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Register the `before_tool_call` approval gate. No-op in `off` mode.
|
|
155
|
+
* Returns the store (for tests/introspection) when registered.
|
|
156
|
+
*/
|
|
157
|
+
export function registerToolApprovalGate(options) {
|
|
158
|
+
const { api, mode, stateDir, logger } = options;
|
|
159
|
+
if (mode === "off") {
|
|
160
|
+
logger?.info("[senpi-tool-approvals] disabled (mode=off)");
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
const manifest = options.manifest ?? loadToolApprovalsManifest();
|
|
164
|
+
const telemetry = options.telemetry ?? defaultGateTelemetry;
|
|
165
|
+
const tradeTools = new Set(manifest.tradeTools);
|
|
166
|
+
const timeoutMs = manifest.defaults.timeoutMs;
|
|
167
|
+
const store = new ToolApprovalStore(stateDir, logger);
|
|
168
|
+
logger?.info(`[senpi-tool-approvals] enabled | mode=${mode} tradeTools=${tradeTools.size} allowAlways=${store.size} timeoutMs=${timeoutMs}`);
|
|
169
|
+
api.on("before_tool_call", (event) => {
|
|
170
|
+
// The registry name openclaw uses on the wire (e.g. `senpi__create_position`).
|
|
171
|
+
// Telemetry keys on it for consistency with the span/tool.called stream,
|
|
172
|
+
// which use the prefixed name too. Set inside the try so a hostile event
|
|
173
|
+
// shape can't escape the fail-open catch.
|
|
174
|
+
let wireName;
|
|
175
|
+
try {
|
|
176
|
+
const ev = event;
|
|
177
|
+
wireName = typeof ev?.toolName === "string" ? ev.toolName : undefined;
|
|
178
|
+
const tool = matchSenpiTool(ev?.toolName);
|
|
179
|
+
if (!tool) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const isTrade = tradeTools.has(tool);
|
|
183
|
+
if (mode === "trades" && !isTrade) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
if (store.isAllowedAlways(tool)) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
requireApproval: {
|
|
191
|
+
title: truncate(`Senpi trade approval: ${tool}`, TITLE_MAX_LENGTH),
|
|
192
|
+
description: buildApprovalDescription(tool, ev?.params),
|
|
193
|
+
severity: isTrade ? "critical" : "warning",
|
|
194
|
+
timeoutMs,
|
|
195
|
+
timeoutBehavior: "deny",
|
|
196
|
+
onResolution: (decision) => {
|
|
197
|
+
const name = wireName ?? `senpi__${tool}`;
|
|
198
|
+
if (decision === "allow-always") {
|
|
199
|
+
store.rememberAllowAlways(tool);
|
|
200
|
+
logger?.info(`[senpi-tool-approvals] allow-always persisted | tool=${tool}`);
|
|
201
|
+
}
|
|
202
|
+
else if (decision === "deny") {
|
|
203
|
+
telemetry.denied(name, "user_denied");
|
|
204
|
+
}
|
|
205
|
+
else if (decision === "timeout") {
|
|
206
|
+
// The user missed the prompt: a state-changing tool the gateway
|
|
207
|
+
// fails closed. A real product signal, and otherwise invisible.
|
|
208
|
+
telemetry.denied(name, "approval_timeout");
|
|
209
|
+
}
|
|
210
|
+
// Audit every terminal decision — the only record of the approve
|
|
211
|
+
// path (allow-once vs allow-always). `cancelled` (run aborted) is
|
|
212
|
+
// not a user decision, so it's excluded.
|
|
213
|
+
if (decision === "allow-once" ||
|
|
214
|
+
decision === "allow-always" ||
|
|
215
|
+
decision === "deny" ||
|
|
216
|
+
decision === "timeout") {
|
|
217
|
+
telemetry.resolved(name, decision, isTrade);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
// Never break the tool pipeline on a gate bug — fail OPEN, but make it
|
|
225
|
+
// loud: this is the one place a money-safety gate stops protecting.
|
|
226
|
+
logger?.warn(`[senpi-tool-approvals] gate handler failed; tool proceeds ungated | err=${err instanceof Error ? err.message : String(err)}`);
|
|
227
|
+
telemetry.gateError(err, wireName);
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return store;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=tool-approval-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-approval-gate.js","sourceRoot":"","sources":["../../src/approvals/tool-approval-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,yBAAyB,GAG1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAsB,MAAM,gBAAgB,CAAC;AA0C1E,yFAAyF;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D,8EAA8E;AAC9E,6EAA6E;AAC7E,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,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AAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,uEAAuE;YACvE,oEAAoE;YACpE,MAAM,EAAE,IAAI,CACV,2EAA2E,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9H,CAAC;YACF,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACnC,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"defaults": {
|
|
4
|
+
"mode": "trades",
|
|
5
|
+
"timeoutMs": 600000
|
|
6
|
+
},
|
|
7
|
+
"tradeTools": [
|
|
8
|
+
"create_position",
|
|
9
|
+
"close_position",
|
|
10
|
+
"edit_position",
|
|
11
|
+
"cancel_order",
|
|
12
|
+
"strategy_create",
|
|
13
|
+
"strategy_create_custom_strategy",
|
|
14
|
+
"strategy_close",
|
|
15
|
+
"strategy_close_positions",
|
|
16
|
+
"strategy_update",
|
|
17
|
+
"strategy_pause",
|
|
18
|
+
"strategy_top_up",
|
|
19
|
+
"strategy_withdraw_funds",
|
|
20
|
+
"strategy_bridge_funds_from_hyperliquid_to_evm",
|
|
21
|
+
"transfer_spot_to_perps",
|
|
22
|
+
"send_usdc",
|
|
23
|
+
"ratchet_stop_add",
|
|
24
|
+
"ratchet_stop_edit",
|
|
25
|
+
"ratchet_stop_delete"
|
|
26
|
+
]
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* the loader's relative-import path entirely.
|
|
13
13
|
*/
|
|
14
14
|
import type { SenpiEventBus } from "./dsl/events/index.js";
|
|
15
|
+
import { type ToolApprovalsMode } from "./approvals/tool-approval-gate.js";
|
|
15
16
|
/** Initialize all core features (DSL, risk, health) on the given event bus. */
|
|
16
17
|
export declare function initCore(bus: SenpiEventBus): void;
|
|
17
18
|
export { initDsl, DslPlugin, dslLogger, setDslLogLevel, parseDslPluginConfig, DslConfigValidationError, dslValidationIssue, EVENTS as DslEvents, DSL_EVENTS, } from "./dsl/index.js";
|
|
@@ -46,6 +47,15 @@ export interface SenpiRuntimePluginConfig {
|
|
|
46
47
|
stateDir?: string;
|
|
47
48
|
apiKey?: string;
|
|
48
49
|
logLevel?: string;
|
|
50
|
+
/**
|
|
51
|
+
* MCP tool approval gate mode override (see src/approvals/tool-approval-gate.ts):
|
|
52
|
+
* "trades" requires interactive approval for state-changing senpi MCP tools,
|
|
53
|
+
* "all" gates every senpi MCP tool, "off" disables the gate. The gated tool
|
|
54
|
+
* set and the default mode ship in the checked-in
|
|
55
|
+
* src/approvals/tool-approvals-manifest.json. Precedence:
|
|
56
|
+
* env SENPI_TOOL_APPROVALS > this setting > manifest default.
|
|
57
|
+
*/
|
|
58
|
+
toolApprovals?: ToolApprovalsMode;
|
|
49
59
|
autoUpdate?: Record<string, unknown>;
|
|
50
60
|
skillsManager?: {
|
|
51
61
|
enabled?: boolean;
|
|
@@ -135,6 +145,11 @@ interface PluginApi {
|
|
|
135
145
|
}) => void | Promise<void>, opts?: {
|
|
136
146
|
scope?: OperatorScope;
|
|
137
147
|
}): void;
|
|
148
|
+
registerReload?: (registration: {
|
|
149
|
+
restartPrefixes?: string[];
|
|
150
|
+
hotPrefixes?: string[];
|
|
151
|
+
noopPrefixes?: string[];
|
|
152
|
+
}) => void;
|
|
138
153
|
on(hookName: string, handler: (...args: unknown[]) => void | Promise<void>, opts?: {
|
|
139
154
|
priority?: number;
|
|
140
155
|
}): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmCH,OAAO,KAAK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AG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EACrD,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3B,IAAI,CAAC;CACT;AAyID;;;GAGG;AACH,QAAA,MAAM,kBAAkB;;;;;;qBAUP,OAAO;;kBAQR,SAAS;CAoiDxB,CAAC;AA+MF,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ import { initOtelSdk, shutdownOtelSdk } from "./telemetry/otel-sdk.js";
|
|
|
39
39
|
import { getLogLevel, getLogLevelSource, parseLogLevel, setErrorNotifier, setLogLevel, } from "./utils/logger.js";
|
|
40
40
|
import { ExternalScannerIngestError, } from "./scanners/external-scanner-receiver.js";
|
|
41
41
|
import { createLogger } from "./utils/logger.js";
|
|
42
|
+
import { registerToolApprovalGate, resolveToolApprovalsMode, } from "./approvals/tool-approval-gate.js";
|
|
42
43
|
import { EVENT_NAME, eventAttrs } from "./utils/event-catalog.js";
|
|
43
44
|
import { emitEvent } from "./actions/event-derivation.js";
|
|
44
45
|
import { buildRuntimeCreatedEvent, buildRuntimeDeletedEvent } from "./runtime/lifecycle-events.js";
|
|
@@ -49,6 +50,7 @@ import { startApi } from "./runtime-api/lifecycle.js";
|
|
|
49
50
|
import { ingestSignalsHandler } from "./runtime-api/handlers/ingest-signals.js";
|
|
50
51
|
import { createIntakeContext } from "./runtime-api/intake/intake-context.js";
|
|
51
52
|
import { wireRuntime, intakeUrlFor } from "./runtime-api/intake/intake-mount.js";
|
|
53
|
+
import { ingestDispatchMutex, ingestDispatchKey } from "./runtime-api/intake/ingest-mutex.js";
|
|
52
54
|
import { loadRuntimeConfig } from "./runtime/load-runtime-config.js";
|
|
53
55
|
/** Initialize all core features (DSL, risk, health) on the given event bus. */
|
|
54
56
|
export function initCore(bus) {
|
|
@@ -292,6 +294,28 @@ const senpiRuntimePlugin = {
|
|
|
292
294
|
err: err instanceof Error ? err.message : String(err),
|
|
293
295
|
});
|
|
294
296
|
}
|
|
297
|
+
// MCP tool approval gate — state-changing senpi MCP tools require an
|
|
298
|
+
// interactive user approval before executing. Prompts reach senpi-web via
|
|
299
|
+
// the bridge's operator.approvals-scoped gateway connection; allow-always
|
|
300
|
+
// decisions persist in <stateDir>/tool-approvals.json.
|
|
301
|
+
// See docs/mcp-tool-approvals-design.md.
|
|
302
|
+
try {
|
|
303
|
+
registerToolApprovalGate({
|
|
304
|
+
api,
|
|
305
|
+
mode: resolveToolApprovalsMode({
|
|
306
|
+
pluginConfig: config,
|
|
307
|
+
env: process.env,
|
|
308
|
+
logger: pluginLogger,
|
|
309
|
+
}),
|
|
310
|
+
stateDir: baseStateDir,
|
|
311
|
+
logger: pluginLogger,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
pluginLogger.warn("[senpi-runtime] failed to register tool approval gate", {
|
|
316
|
+
err: err instanceof Error ? err.message : String(err),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
295
319
|
const runtimeHandles = new Map();
|
|
296
320
|
let apiHandle;
|
|
297
321
|
// Supervised scanner state — module-scoped so stop() can reach them.
|
|
@@ -378,6 +402,19 @@ const senpiRuntimePlugin = {
|
|
|
378
402
|
stateDir: join(baseStateDir, "skills-manager"),
|
|
379
403
|
logger: pluginLogger,
|
|
380
404
|
});
|
|
405
|
+
// AutoUpdateCoordinator's LoggerLike requires `event()` (first-class `auto_update.*`
|
|
406
|
+
// telemetry) alongside info/warn/error. `pluginLogger` mirrors the gateway's own
|
|
407
|
+
// info/warn/error sink but has no `event()` (PluginLogger/api.logger predates the event
|
|
408
|
+
// catalog) — so info/warn/error keep routing through pluginLogger unchanged, and `event()`
|
|
409
|
+
// is delegated to a dedicated OTel-backed logger, matching the `apiLogger.event(...)`
|
|
410
|
+
// pattern already used for `runtime.scanners_unwired` above.
|
|
411
|
+
const autoUpdateEventLogger = createLogger("[senpi-core][auto-update]");
|
|
412
|
+
const autoUpdateLogger = {
|
|
413
|
+
info: (...args) => pluginLogger.info(...args),
|
|
414
|
+
warn: (...args) => pluginLogger.warn(...args),
|
|
415
|
+
error: (message, meta) => pluginLogger.error(message, meta),
|
|
416
|
+
event: autoUpdateEventLogger.event,
|
|
417
|
+
};
|
|
381
418
|
const autoUpdateConfig = resolveAutoUpdateConfig(config?.autoUpdate);
|
|
382
419
|
const autoUpdateCoordinator = new AutoUpdateCoordinator({
|
|
383
420
|
enabled: true,
|
|
@@ -385,22 +422,10 @@ const senpiRuntimePlugin = {
|
|
|
385
422
|
packageName: PLUGIN_PACKAGE_NAME,
|
|
386
423
|
currentVersion: VERSION,
|
|
387
424
|
stateDir: join(baseStateDir, "auto-update"),
|
|
388
|
-
logger:
|
|
425
|
+
logger: autoUpdateLogger,
|
|
389
426
|
notify: lifecycleNotifications
|
|
390
427
|
? (msg) => lifecycleNotifications.notify(msg)
|
|
391
428
|
: async () => { },
|
|
392
|
-
stopRuntimesForUpdate: async () => {
|
|
393
|
-
// Stop supervised scanner children BEFORE stopping runtime handles so
|
|
394
|
-
// scaffold processes do not POST to a handle that is already torn down.
|
|
395
|
-
// Mirrors the service stop() teardown order.
|
|
396
|
-
if (launchers.size > 0) {
|
|
397
|
-
await Promise.allSettled([...launchers.values()].map((l) => l.stop()));
|
|
398
|
-
launchers.clear();
|
|
399
|
-
}
|
|
400
|
-
for (const [, handle] of runtimeHandles) {
|
|
401
|
-
await handle.stop();
|
|
402
|
-
}
|
|
403
|
-
},
|
|
404
429
|
// Use the resolved npm package name (not a hardcoded plugin id) so
|
|
405
430
|
// the update follows the same npm channel as the version check —
|
|
406
431
|
// see runtime/auto-update/run-update-command.ts.
|
|
@@ -431,6 +456,19 @@ const senpiRuntimePlugin = {
|
|
|
431
456
|
await skillsCoordinator.runTickOnce();
|
|
432
457
|
},
|
|
433
458
|
});
|
|
459
|
+
// Tell the gateway's config-reload planner that a write to this leaf
|
|
460
|
+
// requires a full restart, not just a plugin hot-reload. Without this,
|
|
461
|
+
// the write in gateway-restart.ts falls through to the generic
|
|
462
|
+
// `plugins` hot-reload rule and the auto-update coordinator's restart
|
|
463
|
+
// request is silently downgraded to a no-op hot reload.
|
|
464
|
+
// Scoped to the exact leaf (not the whole plugins.entries.<id> subtree)
|
|
465
|
+
// so unrelated config edits (e.g. logLevel) keep hot-reloading instead
|
|
466
|
+
// of forcing a gateway restart.
|
|
467
|
+
if (typeof api.registerReload === "function") {
|
|
468
|
+
api.registerReload({
|
|
469
|
+
restartPrefixes: [`plugins.entries.${api.id}.config.autoUpdate.lastRestartTrigger`],
|
|
470
|
+
});
|
|
471
|
+
}
|
|
434
472
|
api.registerService({
|
|
435
473
|
id: "senpi-runtime",
|
|
436
474
|
async start() {
|
|
@@ -486,8 +524,14 @@ const senpiRuntimePlugin = {
|
|
|
486
524
|
// Trace the sizing-relevant fields the narrowed request carries, so a
|
|
487
525
|
// field dropped at this seam is visible instead of vanishing silently.
|
|
488
526
|
apiLogger.debug(`[intake] ingest req signal_id=${signal.signal_id} scanner=${resolved.scannerName} asset=${signal.asset} direction=${signal.direction} marginPct=${signal.marginPct} leverage=${signal.leverage}`);
|
|
489
|
-
|
|
490
|
-
|
|
527
|
+
// Serialize dispatch behind the shared per-key lock (engine guard
|
|
528
|
+
// identity) so a same-scanner batch or overlapping POSTs ingest one
|
|
529
|
+
// at a time instead of the engine rejecting all but the first as
|
|
530
|
+
// UNAVAILABLE. Still void — the POST response never blocks on the
|
|
531
|
+
// trade, just on lock ordering.
|
|
532
|
+
const key = ingestDispatchKey(resolved.runtimeId, resolved.scannerName);
|
|
533
|
+
void ingestDispatchMutex
|
|
534
|
+
.withKeyLock(key, () => h.ingestExternalScannerData(request))
|
|
491
535
|
.then(() => {
|
|
492
536
|
apiLogger.info(`[intake] ingest ok signal_id=${signal.signal_id} scanner=${resolved.scannerName} asset=${signal.asset} scanner_id=${scannerId}`);
|
|
493
537
|
})
|
|
@@ -604,9 +648,8 @@ const senpiRuntimePlugin = {
|
|
|
604
648
|
catch (err) {
|
|
605
649
|
pluginLogger.error("[senpi-runtime] HTTP API failed to start; rolling back lifecycle", { err });
|
|
606
650
|
// Mirror the lifecycle-stop teardown order: stop the coordinator
|
|
607
|
-
// first so it cannot schedule a tick
|
|
608
|
-
//
|
|
609
|
-
// above.
|
|
651
|
+
// first so it cannot schedule a tick mid-rollback, then stop every
|
|
652
|
+
// runtime handle that was hydrated above.
|
|
610
653
|
await autoUpdateCoordinator.stop().catch(() => { });
|
|
611
654
|
// Stop any launchers so spawned scaffolds are not leaked.
|
|
612
655
|
await Promise.allSettled([...launchers.values()].map((l) => l.stop()));
|
|
@@ -663,9 +706,8 @@ const senpiRuntimePlugin = {
|
|
|
663
706
|
await Promise.allSettled([...launchers.values()].map((l) => l.stop()));
|
|
664
707
|
launchers.clear();
|
|
665
708
|
}
|
|
666
|
-
// Stop the coordinator next so it cannot schedule a new tick
|
|
667
|
-
//
|
|
668
|
-
// we are tearing down the handles below.
|
|
709
|
+
// Stop the coordinator next so it cannot schedule a new tick while we
|
|
710
|
+
// are tearing down the handles below.
|
|
669
711
|
await autoUpdateCoordinator.stop();
|
|
670
712
|
await skillsCoordinator.stop();
|
|
671
713
|
const ids = Array.from(runtimeHandles.keys());
|