@reefclaw/connect 0.1.36 → 0.1.38

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 (50) hide show
  1. package/assets/bridge/gateway/gateway-ws-client.d.ts +2 -0
  2. package/assets/bridge/gateway/gateway-ws-client.js +6 -0
  3. package/assets/bridge/heartbeat-runs-state.d.ts +16 -0
  4. package/assets/bridge/heartbeat-runs-state.js +58 -0
  5. package/assets/bridge/heartbeat-runs.d.ts +99 -0
  6. package/assets/bridge/heartbeat-runs.js +300 -0
  7. package/assets/bridge/heartbeat-transcript.d.ts +209 -0
  8. package/assets/bridge/heartbeat-transcript.js +688 -0
  9. package/assets/bridge/index.js +31 -0
  10. package/assets/bridge/model-health.d.ts +37 -0
  11. package/assets/bridge/model-health.js +97 -0
  12. package/assets/bridge/provider.d.ts +5 -1
  13. package/assets/bridge/providers/gateway.d.ts +25 -1
  14. package/assets/bridge/providers/gateway.js +167 -2
  15. package/assets/bridge/providers/mock.js +1 -0
  16. package/assets/bridge/shock-wake.d.ts +80 -0
  17. package/assets/bridge/shock-wake.js +291 -0
  18. package/assets/bridge/types.d.ts +41 -0
  19. package/assets/plugin/config/agent-config-client.d.ts +3 -1
  20. package/assets/plugin/config/agent-config-client.js +4 -0
  21. package/assets/plugin/config/gate-store.d.ts +3 -0
  22. package/assets/plugin/config/gate-store.js +11 -2
  23. package/assets/plugin/config/loss-streak-config.d.ts +2 -0
  24. package/assets/plugin/config/loss-streak-config.js +33 -0
  25. package/assets/plugin/config/plugin-config-io.d.ts +19 -0
  26. package/assets/plugin/config/reentry-cooldown-config.d.ts +7 -0
  27. package/assets/plugin/config/reentry-cooldown-config.js +59 -0
  28. package/assets/plugin/index.js +5 -0
  29. package/assets/plugin/ingest/position-auto-capture.js +35 -2
  30. package/assets/plugin/openclaw.plugin.json +1 -1
  31. package/assets/plugin/portfolio/directional-scoreboard.d.ts +17 -0
  32. package/assets/plugin/portfolio/directional-scoreboard.js +71 -0
  33. package/assets/plugin/portfolio/reentry-tracker.d.ts +38 -1
  34. package/assets/plugin/portfolio/reentry-tracker.js +49 -0
  35. package/assets/plugin/signals/change-of-character.d.ts +38 -0
  36. package/assets/plugin/signals/change-of-character.js +93 -0
  37. package/assets/plugin/signals/types.js +1 -1
  38. package/assets/plugin/simulator/types.d.ts +11 -0
  39. package/assets/plugin/strategy/evaluator.d.ts +4 -0
  40. package/assets/plugin/tools/create-order.js +72 -2
  41. package/assets/plugin/tools/reentry-cooldown.d.ts +33 -0
  42. package/assets/plugin/tools/reentry-cooldown.js +74 -0
  43. package/assets/plugin/tools/scan-pairs.d.ts +7 -0
  44. package/assets/plugin/tools/scan-pairs.js +47 -0
  45. package/assets/shared/signals/change-of-character.d.ts +38 -0
  46. package/assets/shared/signals/change-of-character.js +86 -0
  47. package/assets/skill/SKILL.md +2 -2
  48. package/dist/cli.js +11 -2
  49. package/dist/plugin.js +70 -28
  50. package/package.json +1 -1
@@ -0,0 +1,209 @@
1
+ /** Max tool calls kept per record (the census still counts every call). */
2
+ export declare const TOOL_CALLS_MAX = 250;
3
+ /** Max chars of a tool call's JSON arguments. */
4
+ export declare const ARGS_MAX = 300;
5
+ /** Max chars of a tool result's text. */
6
+ export declare const RESULT_MAX = 400;
7
+ /** Max chars of the agent's final report text. */
8
+ export declare const SUMMARY_MAX = 4000;
9
+ /** Max model events kept. */
10
+ export declare const MODEL_EVENTS_MAX = 50;
11
+ /** Target upper bound for a serialized record (bytes). */
12
+ export declare const RECORD_MAX_BYTES = 200000;
13
+ export interface HeartbeatToolCall {
14
+ /** The gateway's toolCallId (pairs the call with its result). */
15
+ id: string;
16
+ name: string;
17
+ /** Epoch ms of the assistant message that issued the call, when known. */
18
+ at: number | null;
19
+ /** false when the tool result flagged isError; null when no result was seen. */
20
+ ok: boolean | null;
21
+ /** Compact JSON of the arguments, truncated; '[redacted]' for sensitive tools. */
22
+ args: string;
23
+ /** Truncated result text ('' when no result was seen). */
24
+ result: string;
25
+ /** result.timestamp − call.timestamp when both are present. */
26
+ durationMs: number | null;
27
+ }
28
+ export type HeartbeatModelEventKind = 'model_change' | 'thinking_level_change' | 'fallback_step' | 'error';
29
+ export interface HeartbeatModelEvent {
30
+ kind: HeartbeatModelEventKind;
31
+ at: number | null;
32
+ detail: string;
33
+ }
34
+ export type HeartbeatRunStatus = 'ok' | 'error' | 'incomplete' | 'unknown';
35
+ export interface HeartbeatTokens {
36
+ input: number | null;
37
+ output: number | null;
38
+ cacheRead: number | null;
39
+ cacheWrite: number | null;
40
+ total: number | null;
41
+ /** Where the counts came from — the dashboard labels 'none' as "n/a". */
42
+ source: 'run_log' | 'trajectory' | 'transcript' | 'none';
43
+ }
44
+ export interface HeartbeatRunRecord {
45
+ /** The isolated cron session id — one per beat, the idempotency key. */
46
+ runId: string;
47
+ cronJobId: string | null;
48
+ cronJobName: string | null;
49
+ trigger: 'cron' | 'unknown';
50
+ status: HeartbeatRunStatus;
51
+ startedAtMs: number;
52
+ endedAtMs: number | null;
53
+ durationMs: number | null;
54
+ /** `<provider>/<model>` that answered, when known. */
55
+ model: string | null;
56
+ tokens: HeartbeatTokens;
57
+ toolCallCount: number;
58
+ toolErrorCount: number;
59
+ toolCensus: Record<string, number>;
60
+ toolCalls: HeartbeatToolCall[];
61
+ /** The agent's final report text (what went to Telegram), truncated. */
62
+ summary: string | null;
63
+ modelEvents: HeartbeatModelEvent[];
64
+ /** Run-level error text (cron run log / promptError / assistant errorMessage). */
65
+ error: string | null;
66
+ /** OpenClaw FailoverReason from the cron run log (auth, rate_limit, format, …). */
67
+ errorReason: string | null;
68
+ mode: 'paper' | 'live' | null;
69
+ meta: {
70
+ transcriptBytes: number;
71
+ trajectoryBytes: number | null;
72
+ assistantMessages: number;
73
+ /** True when tool calls / results / summary were trimmed to fit the caps. */
74
+ truncated: boolean;
75
+ /** Tool catalog size the session started with (trajectory session.started). */
76
+ toolCount: number | null;
77
+ /** Model API the assistant messages carry (e.g. "openai-chatgpt-responses"). */
78
+ api: string | null;
79
+ thinkingLevel: string | null;
80
+ };
81
+ }
82
+ /** The subset of an OpenClaw cron run-log entry the recorder consumes
83
+ * (gateway RPC `cron.runs` → `entries[]`, vendored `run-log-types.ts`). */
84
+ export interface CronRunLogLite {
85
+ sessionId: string | null;
86
+ runId: string | null;
87
+ status: string | null;
88
+ error: string | null;
89
+ errorReason: string | null;
90
+ runAtMs: number | null;
91
+ durationMs: number | null;
92
+ model: string | null;
93
+ provider: string | null;
94
+ usage: {
95
+ input: number | null;
96
+ output: number | null;
97
+ cacheRead: number | null;
98
+ cacheWrite: number | null;
99
+ total: number | null;
100
+ } | null;
101
+ }
102
+ /** OpenClaw's state dir — `OPENCLAW_STATE_DIR` is the real override (the
103
+ * bridge historically read a non-existent OPENCLAW_HOME; honour both). */
104
+ export declare function resolveOpenClawStateDir(env?: NodeJS.ProcessEnv): string;
105
+ export declare function resolveSessionsDir(agentId?: string, env?: NodeJS.ProcessEnv): string;
106
+ export interface SessionCandidate {
107
+ sessionId: string;
108
+ file: string;
109
+ trajectoryFile: string | null;
110
+ mtimeMs: number;
111
+ sizeBytes: number;
112
+ }
113
+ /** Every `<sessionId>.jsonl` transcript in `dir` (not sidecars, checkpoints,
114
+ * topic files or retired copies) modified at/after `minMtimeMs`, excluding
115
+ * `exclude`d session ids. Never throws — a missing dir yields []. */
116
+ export declare function listSessionCandidates(dir: string, opts?: {
117
+ minMtimeMs?: number;
118
+ exclude?: Set<string>;
119
+ }): SessionCandidate[];
120
+ export interface CronMarker {
121
+ jobId: string;
122
+ jobName: string | null;
123
+ }
124
+ export declare function parseCronMarker(text: string | null | undefined): CronMarker | null;
125
+ /** Read only the head of a transcript and report whether its first user
126
+ * message carries the `[cron:…]` marker. `null` = inconclusive (no user
127
+ * message within the head) — callers then fall back to the trajectory key. */
128
+ export declare function readCronMarker(file: string, headBytes?: number): CronMarker | null | undefined;
129
+ export interface TranscriptUsage {
130
+ input: number;
131
+ output: number;
132
+ cacheRead: number;
133
+ cacheWrite: number;
134
+ total: number;
135
+ }
136
+ export interface ParsedTranscript {
137
+ sessionId: string | null;
138
+ headerAtMs: number | null;
139
+ cron: CronMarker | null;
140
+ firstUserAtMs: number | null;
141
+ lastAtMs: number | null;
142
+ toolCalls: HeartbeatToolCall[];
143
+ /** Total calls seen (may exceed toolCalls.length once the cap trims). */
144
+ toolCallTotal: number;
145
+ toolErrorCount: number;
146
+ toolCensus: Record<string, number>;
147
+ assistantCount: number;
148
+ finalText: string | null;
149
+ /** `<provider>/<model>` ids in order of first appearance. */
150
+ models: string[];
151
+ api: string | null;
152
+ usage: TranscriptUsage;
153
+ usageNonZero: boolean;
154
+ lastStopReason: string | null;
155
+ lastErrorMessage: string | null;
156
+ modelEvents: HeartbeatModelEvent[];
157
+ thinkingLevel: string | null;
158
+ /** The last assistant message ended the turn (not mid tool-chain). */
159
+ complete: boolean;
160
+ truncated: boolean;
161
+ bytes: number;
162
+ }
163
+ /** Text of a content block / content array in every shape OpenClaw writes. */
164
+ export declare function textOf(content: unknown, depth?: number): string;
165
+ export declare function parseSessionTranscript(text: string): ParsedTranscript;
166
+ export interface ParsedTrajectory {
167
+ sessionKey: string | null;
168
+ runId: string | null;
169
+ provider: string | null;
170
+ modelId: string | null;
171
+ modelApi: string | null;
172
+ toolCount: number | null;
173
+ trigger: string | null;
174
+ thinkLevel: string | null;
175
+ ended: {
176
+ status: string | null;
177
+ timedOut: boolean;
178
+ promptError: string | null;
179
+ } | null;
180
+ /** From an UNtruncated model.completed event. */
181
+ usage: TranscriptUsage | null;
182
+ fallbackSteps: HeartbeatModelEvent[];
183
+ toolCallEvents: number;
184
+ firstTs: number | null;
185
+ lastTs: number | null;
186
+ bytes: number;
187
+ }
188
+ export declare function parseTrajectory(text: string): ParsedTrajectory;
189
+ export declare function isCronSessionKey(key: string | null | undefined): boolean;
190
+ export interface BuildRecordInput {
191
+ sessionId: string;
192
+ transcript: ParsedTranscript;
193
+ trajectory: ParsedTrajectory | null;
194
+ runLog: CronRunLogLite | null;
195
+ mode: 'paper' | 'live' | null;
196
+ /** Fallback start time when neither file carries one (file mtime). */
197
+ fallbackStartedAtMs: number;
198
+ }
199
+ export declare function buildHeartbeatRunRecord(i: BuildRecordInput): HeartbeatRunRecord;
200
+ /** Shrink a record until its JSON fits `maxBytes`: first shorter tool
201
+ * results, then no results, then fewer tool calls. Pure; returns a copy. */
202
+ export declare function shrinkRecord(record: HeartbeatRunRecord, maxBytes?: number): HeartbeatRunRecord;
203
+ export interface ReadSessionResult {
204
+ transcript: ParsedTranscript;
205
+ trajectory: ParsedTrajectory | null;
206
+ }
207
+ /** Read + parse a candidate's transcript and (when present) its trajectory.
208
+ * Never throws on a missing/torn file — a missing transcript yields null. */
209
+ export declare function readSession(c: SessionCandidate): ReadSessionResult | null;