@a1hvdy/cc-openclaw 0.30.0 → 0.32.0

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 (207) hide show
  1. package/dist/src/channels/telegram-mirror/card-renderer.js +9 -5
  2. package/dist/src/channels/telegram-mirror/commands.js +0 -8
  3. package/dist/src/channels/telegram-mirror/status-line.js +32 -2
  4. package/dist/src/constants.js +16 -2
  5. package/dist/src/engines/persistent-session.js +11 -0
  6. package/dist/src/lib/config.js +40 -0
  7. package/dist/src/openai-compat/non-streaming-handler.js +2 -2
  8. package/dist/src/openai-compat/streaming-handler.js +121 -9
  9. package/package.json +3 -2
  10. package/dist/src/channels/adapter.d.ts +0 -103
  11. package/dist/src/channels/telegram-mirror/askuser.d.ts +0 -107
  12. package/dist/src/channels/telegram-mirror/burst-accumulator.d.ts +0 -96
  13. package/dist/src/channels/telegram-mirror/callback-mapping.d.ts +0 -61
  14. package/dist/src/channels/telegram-mirror/card-renderer.d.ts +0 -68
  15. package/dist/src/channels/telegram-mirror/card-state.d.ts +0 -83
  16. package/dist/src/channels/telegram-mirror/commands.d.ts +0 -183
  17. package/dist/src/channels/telegram-mirror/compose-buffer.d.ts +0 -71
  18. package/dist/src/channels/telegram-mirror/cost-views.d.ts +0 -58
  19. package/dist/src/channels/telegram-mirror/failure/callback-data-overflow.d.ts +0 -21
  20. package/dist/src/channels/telegram-mirror/failure/gateway-down.d.ts +0 -15
  21. package/dist/src/channels/telegram-mirror/failure/in-flight-conflict.d.ts +0 -15
  22. package/dist/src/channels/telegram-mirror/failure/index.d.ts +0 -23
  23. package/dist/src/channels/telegram-mirror/failure/model-5xx.d.ts +0 -16
  24. package/dist/src/channels/telegram-mirror/failure/network-blip.d.ts +0 -17
  25. package/dist/src/channels/telegram-mirror/failure/pool-exhausted-fallback.d.ts +0 -15
  26. package/dist/src/channels/telegram-mirror/failure/rate-limit.d.ts +0 -16
  27. package/dist/src/channels/telegram-mirror/failure/returning-after-24h.d.ts +0 -14
  28. package/dist/src/channels/telegram-mirror/failure/types.d.ts +0 -30
  29. package/dist/src/channels/telegram-mirror/inbound-handler.d.ts +0 -73
  30. package/dist/src/channels/telegram-mirror/index.d.ts +0 -32
  31. package/dist/src/channels/telegram-mirror/plan-attachment.d.ts +0 -120
  32. package/dist/src/channels/telegram-mirror/quota-reader.d.ts +0 -42
  33. package/dist/src/channels/telegram-mirror/sessions-keyboard.d.ts +0 -84
  34. package/dist/src/channels/telegram-mirror/soak-log.d.ts +0 -99
  35. package/dist/src/channels/telegram-mirror/state-machine.d.ts +0 -113
  36. package/dist/src/channels/telegram-mirror/status-line.d.ts +0 -51
  37. package/dist/src/channels/telegram-mirror/sync-commands.d.ts +0 -100
  38. package/dist/src/channels/telegram-mirror/threshold-watcher.d.ts +0 -54
  39. package/dist/src/channels/telegram-mirror/turn-bridge.d.ts +0 -125
  40. package/dist/src/cli/checks/bridge-wiring.d.ts +0 -14
  41. package/dist/src/cli/checks/config-schema.d.ts +0 -11
  42. package/dist/src/cli/checks/critical-openclaw-json-keys.d.ts +0 -21
  43. package/dist/src/cli/checks/install-path.d.ts +0 -11
  44. package/dist/src/cli/checks/patch-scaffold.d.ts +0 -17
  45. package/dist/src/cli/doctor.d.ts +0 -20
  46. package/dist/src/cli/index.d.ts +0 -8
  47. package/dist/src/cli/migrate.d.ts +0 -29
  48. package/dist/src/command-router/cc-handler.d.ts +0 -67
  49. package/dist/src/command-router/index.d.ts +0 -2
  50. package/dist/src/command-router/launch-policy.d.ts +0 -92
  51. package/dist/src/command-router/resume-policy.d.ts +0 -18
  52. package/dist/src/command-router/turn-formatter.d.ts +0 -19
  53. package/dist/src/config/loader.d.ts +0 -8
  54. package/dist/src/config/schema.d.ts +0 -192
  55. package/dist/src/constants.d.ts +0 -191
  56. package/dist/src/council/build-agent-prompt.d.ts +0 -11
  57. package/dist/src/council/cleanup-worktrees.d.ts +0 -10
  58. package/dist/src/council/consensus.d.ts +0 -20
  59. package/dist/src/council/council.d.ts +0 -67
  60. package/dist/src/council/index.d.ts +0 -2
  61. package/dist/src/council/system-prompt.d.ts +0 -16
  62. package/dist/src/council/write-worktree-claude-md.d.ts +0 -10
  63. package/dist/src/engines/base-oneshot-session.d.ts +0 -87
  64. package/dist/src/engines/heartbeat-guard.d.ts +0 -93
  65. package/dist/src/engines/index.d.ts +0 -8
  66. package/dist/src/engines/persistent-codex-session.d.ts +0 -16
  67. package/dist/src/engines/persistent-cursor-session.d.ts +0 -21
  68. package/dist/src/engines/persistent-custom-session.d.ts +0 -78
  69. package/dist/src/engines/persistent-gemini-session.d.ts +0 -21
  70. package/dist/src/engines/persistent-session.d.ts +0 -95
  71. package/dist/src/engines/resolve-bin.d.ts +0 -14
  72. package/dist/src/engines/subprocess-pool.d.ts +0 -78
  73. package/dist/src/health/handler.d.ts +0 -39
  74. package/dist/src/health/index.d.ts +0 -1
  75. package/dist/src/health/metrics.d.ts +0 -52
  76. package/dist/src/index.d.ts +0 -57
  77. package/dist/src/lib/auto-recovery.d.ts +0 -43
  78. package/dist/src/lib/cache-parity-decide.d.ts +0 -64
  79. package/dist/src/lib/cache-parity.d.ts +0 -38
  80. package/dist/src/lib/cc-cli-scan.d.ts +0 -52
  81. package/dist/src/lib/circuit-breaker.d.ts +0 -21
  82. package/dist/src/lib/config-service.d.ts +0 -106
  83. package/dist/src/lib/config.d.ts +0 -136
  84. package/dist/src/lib/cost-rollup.d.ts +0 -36
  85. package/dist/src/lib/debounce.d.ts +0 -12
  86. package/dist/src/lib/debug-tap.d.ts +0 -13
  87. package/dist/src/lib/domain-error.d.ts +0 -59
  88. package/dist/src/lib/drift-detector.d.ts +0 -46
  89. package/dist/src/lib/env-overrides.d.ts +0 -47
  90. package/dist/src/lib/error-formatter.d.ts +0 -91
  91. package/dist/src/lib/error-renderer.d.ts +0 -20
  92. package/dist/src/lib/heartbeat-config.d.ts +0 -34
  93. package/dist/src/lib/heartbeat-workaround.d.ts +0 -44
  94. package/dist/src/lib/html-render.d.ts +0 -50
  95. package/dist/src/lib/http-agent.d.ts +0 -47
  96. package/dist/src/lib/index.d.ts +0 -7
  97. package/dist/src/lib/index.js +0 -10
  98. package/dist/src/lib/json-array.d.ts +0 -10
  99. package/dist/src/lib/markdown-to-mdv2.d.ts +0 -53
  100. package/dist/src/lib/markdown-v2.d.ts +0 -27
  101. package/dist/src/lib/perf/async-compact.d.ts +0 -26
  102. package/dist/src/lib/perf/direct-sdk.d.ts +0 -26
  103. package/dist/src/lib/perf/haiku-route.d.ts +0 -19
  104. package/dist/src/lib/perf/predictive-continuation.d.ts +0 -18
  105. package/dist/src/lib/perf/read-batch.d.ts +0 -33
  106. package/dist/src/lib/perf/skill-list-collapse.d.ts +0 -22
  107. package/dist/src/lib/perf/speculative-bubble.d.ts +0 -27
  108. package/dist/src/lib/perf/typing-prefetch.d.ts +0 -25
  109. package/dist/src/lib/probes.d.ts +0 -50
  110. package/dist/src/lib/register-guard.d.ts +0 -56
  111. package/dist/src/lib/req-shape-log.d.ts +0 -31
  112. package/dist/src/lib/safe-upstream-probes.d.ts +0 -25
  113. package/dist/src/lib/session-registry.d.ts +0 -66
  114. package/dist/src/lib/spawn-async.d.ts +0 -18
  115. package/dist/src/lib/status-tee-reader.d.ts +0 -29
  116. package/dist/src/lib/sysprompt-strip.d.ts +0 -53
  117. package/dist/src/lib/telegram-bot-api.d.ts +0 -146
  118. package/dist/src/lib/telemetry.d.ts +0 -38
  119. package/dist/src/lib/test-mode.d.ts +0 -26
  120. package/dist/src/lib/trajectory.d.ts +0 -44
  121. package/dist/src/lib/vendor-paths.d.ts +0 -12
  122. package/dist/src/lifecycle/boot.d.ts +0 -48
  123. package/dist/src/lifecycle/patch-manifest.d.ts +0 -82
  124. package/dist/src/lifecycle/phase-import-upstream.d.ts +0 -12
  125. package/dist/src/lifecycle/phase-install-patches.d.ts +0 -12
  126. package/dist/src/lifecycle/phase-schedule-jobs.d.ts +0 -12
  127. package/dist/src/lifecycle/phase-start-server.d.ts +0 -11
  128. package/dist/src/lifecycle/phase-validate-config.d.ts +0 -9
  129. package/dist/src/lifecycle/phase-validate-upstream.d.ts +0 -11
  130. package/dist/src/lifecycle/phase-wire-handlers.d.ts +0 -12
  131. package/dist/src/lifecycle/safe-restart.d.ts +0 -99
  132. package/dist/src/logger.d.ts +0 -14
  133. package/dist/src/mcp/bridge.d.ts +0 -21
  134. package/dist/src/mcp/index.d.ts +0 -2
  135. package/dist/src/models.d.ts +0 -68
  136. package/dist/src/observability/event-bus.d.ts +0 -86
  137. package/dist/src/observability/get-event-bus.d.ts +0 -25
  138. package/dist/src/observability/observability-service.d.ts +0 -19
  139. package/dist/src/observability/perf-telemetry.d.ts +0 -65
  140. package/dist/src/observability/subscribers/metrics.d.ts +0 -11
  141. package/dist/src/observability/subscribers/session-capture.d.ts +0 -15
  142. package/dist/src/openai-compat/autonomy-rule.d.ts +0 -26
  143. package/dist/src/openai-compat/bridges/allowlist.d.ts +0 -19
  144. package/dist/src/openai-compat/bridges/factory.d.ts +0 -30
  145. package/dist/src/openai-compat/bridges/media-bridge.d.ts +0 -34
  146. package/dist/src/openai-compat/bridges/openclaw-api-shim.d.ts +0 -54
  147. package/dist/src/openai-compat/bridges/openclaw-native-tools.d.ts +0 -61
  148. package/dist/src/openai-compat/bridges/openclaw-tool-registry.d.ts +0 -26
  149. package/dist/src/openai-compat/bridges/tts-media-bridge.d.ts +0 -19
  150. package/dist/src/openai-compat/chat-cwd.d.ts +0 -22
  151. package/dist/src/openai-compat/cli-stream-parser.d.ts +0 -134
  152. package/dist/src/openai-compat/index.d.ts +0 -1
  153. package/dist/src/openai-compat/message-extractor.d.ts +0 -84
  154. package/dist/src/openai-compat/mode-flags.d.ts +0 -34
  155. package/dist/src/openai-compat/non-streaming-handler.d.ts +0 -29
  156. package/dist/src/openai-compat/openai-chunk-types.d.ts +0 -35
  157. package/dist/src/openai-compat/openai-compat.d.ts +0 -49
  158. package/dist/src/openai-compat/openai-types.d.ts +0 -71
  159. package/dist/src/openai-compat/parse-route-body.d.ts +0 -24
  160. package/dist/src/openai-compat/prompts.d.ts +0 -47
  161. package/dist/src/openai-compat/request-coalescer.d.ts +0 -77
  162. package/dist/src/openai-compat/response-formatter.d.ts +0 -33
  163. package/dist/src/openai-compat/session-key-resolver.d.ts +0 -41
  164. package/dist/src/openai-compat/skill-resolver.d.ts +0 -59
  165. package/dist/src/openai-compat/sse-translator.d.ts +0 -51
  166. package/dist/src/openai-compat/status-reporter.d.ts +0 -30
  167. package/dist/src/openai-compat/streaming-handler.d.ts +0 -52
  168. package/dist/src/openai-compat/tool-calls-parser.d.ts +0 -34
  169. package/dist/src/openai-compat/tool-results-serializer.d.ts +0 -60
  170. package/dist/src/openai-compat/tts-rule.d.ts +0 -20
  171. package/dist/src/openai-compat/voice-recovery.d.ts +0 -56
  172. package/dist/src/patches/cache-parity-registry.d.ts +0 -103
  173. package/dist/src/patches/claude-md-injection.d.ts +0 -10
  174. package/dist/src/patches/cwd-redirect.d.ts +0 -10
  175. package/dist/src/patches/embedded-server-route.d.ts +0 -23
  176. package/dist/src/patches/pricing-overrides.d.ts +0 -10
  177. package/dist/src/patches/resume-registry-restore.d.ts +0 -11
  178. package/dist/src/patches/session-pid-tracking.d.ts +0 -10
  179. package/dist/src/patches/sysprompt-strip.d.ts +0 -46
  180. package/dist/src/patches/tools-restoration.d.ts +0 -12
  181. package/dist/src/persistence/migration-v0.d.ts +0 -24
  182. package/dist/src/persistence/session-registry.d.ts +0 -58
  183. package/dist/src/proxy/anthropic-adapter.d.ts +0 -136
  184. package/dist/src/proxy/handler.d.ts +0 -39
  185. package/dist/src/proxy/index.d.ts +0 -4
  186. package/dist/src/proxy/schema-cleaner.d.ts +0 -11
  187. package/dist/src/proxy/thought-cache.d.ts +0 -19
  188. package/dist/src/session/embedded-server.d.ts +0 -25
  189. package/dist/src/session/inbox-manager.d.ts +0 -38
  190. package/dist/src/session/index.d.ts +0 -3
  191. package/dist/src/session/persisted-sessions.d.ts +0 -50
  192. package/dist/src/session/session-manager.d.ts +0 -247
  193. package/dist/src/session/watchdogs.d.ts +0 -92
  194. package/dist/src/session-bootstrap/boot-self-heal.d.ts +0 -32
  195. package/dist/src/session-bootstrap/cwd-patch.d.ts +0 -50
  196. package/dist/src/session-bootstrap/index.d.ts +0 -3
  197. package/dist/src/session-bootstrap/resume-registry.d.ts +0 -27
  198. package/dist/src/session-bootstrap/session-hygiene.d.ts +0 -23
  199. package/dist/src/session-bootstrap/sysprompt-strip.d.ts +0 -24
  200. package/dist/src/session-bootstrap/think-conflict-resolver.d.ts +0 -32
  201. package/dist/src/types/route.d.ts +0 -11
  202. package/dist/src/types/runtime-config.d.ts +0 -208
  203. package/dist/src/types/sse.d.ts +0 -29
  204. package/dist/src/types/tool-bridge.d.ts +0 -82
  205. package/dist/src/types/upstream.d.ts +0 -580
  206. package/dist/src/types.d.ts +0 -498
  207. package/dist/src/validation.d.ts +0 -31
@@ -1,65 +0,0 @@
1
- /**
2
- * Perf-baseline telemetry (M8 — cache-miss-telemetry).
3
- *
4
- * Appends structured perf events to `~/.openclaw/workspace/memory/sysprompt-cost.jsonl`
5
- * alongside the existing token-cost records. Every record carries an `event`
6
- * field so consumers can filter:
7
- *
8
- * - "token_cost" → legacy per-request sysprompt+user char/token estimate
9
- * (emitted by cwd-patch.ts; tagged by this module on read).
10
- * - "cache_check" → outcome of the Track-B cache parity decision: hit/miss
11
- * with a structured `cause` (registry_empty | hash_mismatch
12
- * | session_unknown | disabled). Drives idea #8.
13
- * - "first_byte" → first user-visible content delta sent to the SSE client.
14
- * `elapsed_ms` is measured from request receive (turnStartMs
15
- * in streaming-handler.ts). This is the baseline for the
16
- * plan's ≥50% p50 latency drop exit criterion.
17
- * - "turn_end" → final SSE stop chunk written. `elapsed_ms` is total turn
18
- * wall-clock. Pair with first_byte to derive generation-vs-
19
- * latency split per turn.
20
- *
21
- * Flag: CC_OPENCLAW_PERF_CACHE_TELEMETRY (default ON; opt-out with 0/false/off).
22
- * Goes through the same shim pattern as the legacy telemetry getters
23
- * (ConfigService when present, env fallback for tests).
24
- *
25
- * Why same file as token_cost: the plan's verify query targets sysprompt-cost.jsonl
26
- * directly; splitting would require operators to remember two paths and would
27
- * break the single `jq` pipeline. The `event` field makes filtering trivial.
28
- */
29
- type PerfEventName = 'cache_check' | 'first_byte' | 'turn_end';
30
- type CacheCheckCause = 'hit' | 'warm_hash' | 'registry_empty' | 'hash_mismatch' | 'session_unknown' | 'disabled';
31
- interface PerfEventBase {
32
- event: PerfEventName;
33
- sessionKey?: string;
34
- }
35
- interface CacheCheckEvent extends PerfEventBase {
36
- event: 'cache_check';
37
- outcome: 'hit' | 'miss';
38
- cause: CacheCheckCause;
39
- sysHash?: string;
40
- }
41
- interface FirstByteEvent extends PerfEventBase {
42
- event: 'first_byte';
43
- elapsed_ms: number;
44
- model?: string;
45
- tool_stream?: boolean;
46
- }
47
- interface TurnEndEvent extends PerfEventBase {
48
- event: 'turn_end';
49
- elapsed_ms: number;
50
- first_byte_ms?: number;
51
- finish_reason?: 'stop' | 'tool_calls' | 'length' | string;
52
- tool_calls?: number;
53
- bytes_out?: number;
54
- }
55
- export type PerfEvent = CacheCheckEvent | FirstByteEvent | TurnEndEvent;
56
- /**
57
- * Append a perf event to sysprompt-cost.jsonl. No-op when the flag is off
58
- * or when an I/O error occurs — telemetry must never break a live turn.
59
- */
60
- export declare function writePerfEvent(event: PerfEvent): void;
61
- /** Test hook — replace the file-writing sink with an in-memory collector. */
62
- export declare function _setPerfWriterForTests(w: (line: string) => void): void;
63
- /** Test hook — restore the default file-writing sink. */
64
- export declare function _restorePerfWriterForTests(): void;
65
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * MetricsSubscriber — collects per-session token and timing metrics.
3
- *
4
- * Replaces globalThis.__openclaw_perfMap (AS2).
5
- * Phase E wires real aggregation and exposes metrics via /enhancer/metrics.
6
- * Stub body here.
7
- */
8
- import type { EventBus } from '../event-bus.js';
9
- export declare class MetricsSubscriber {
10
- register(bus: EventBus): void;
11
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * SessionCaptureSubscriber — replaces the 5s ultrareview poller (LP2).
3
- *
4
- * Wired in boot phase 5 (wire-handlers) BEFORE traffic starts.
5
- * Phase E implements the real capture logic (writing to SessionRegistry WAL,
6
- * updating live-card state, etc.). Stub body here.
7
- */
8
- import type { EventBus } from '../event-bus.js';
9
- export declare class SessionCaptureSubscriber {
10
- /**
11
- * Register listeners on the bus. Returns nothing; unsubscribe handles
12
- * are held internally (Phase E: stored for clean shutdown).
13
- */
14
- register(bus: EventBus): void;
15
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * AUTONOMY_RULE — "act, don't ask" posture injected into the Savvy chat path.
3
- *
4
- * Why: the openai-compat (Telegram) path does not reliably load the owner's
5
- * CLAUDE.md "Execute, don't discuss" rules (tmpdir CWD), so the model reverts to
6
- * Claude's base posture of asking on ambiguous forks. Combined with a Telegram
7
- * AskUserQuestion round-trip that silently drops answers, this made Savvy stall
8
- * and require many prods to finish one task. This rule restores the terminal-CLI
9
- * posture: decide and execute, complete the whole task in one turn.
10
- *
11
- * Gated by CC_OPENCLAW_AUTONOMY_RULE (default on; set '0' to disable). Prepended
12
- * at the same injection points as TTS_RULE in openai-compat.ts so it lands in
13
- * both the REPLACE (--system-prompt) and APPEND (--append-system-prompt) paths.
14
- *
15
- * Pure-string constant — no I/O, no module state.
16
- */
17
- export declare const AUTONOMY_RULE: string;
18
- /**
19
- * Merge AskUserQuestion into a session's disallowedTools when suppression is on.
20
- * The Telegram answer round-trip silently drops taps, so a question there stalls
21
- * the turn — suppressing the tool is the hard guarantee behind AUTONOMY_RULE's
22
- * "decide, do not ask" posture. Returns `prior` unchanged when suppression is
23
- * off (so callers only set disallowedTools when there's something to set). Pure
24
- * + dedup so it's unit-testable and idempotent across repeated session creates.
25
- */
26
- export declare function withAskUserSuppressed(prior: string[] | undefined, suppress: boolean): string[] | undefined;
@@ -1,19 +0,0 @@
1
- /**
2
- * OpenClaw native tool allowList — typed-config-driven (Phase E #1, Q1 resolution).
3
- *
4
- * Reads from `ConfigService.config.nativeToolsAllowList` when available;
5
- * falls back to the v0.11.x hardcoded default when `ConfigService` is unset
6
- * (tests, scripts run without a boot path). The hardcoded fallback is
7
- * intentionally identical to what shipped at v0.11.0 so existing tests that
8
- * import `OPENCLAW_TOOL_ALLOWLIST` keep passing without rewrite.
9
- *
10
- * Env override: `CC_OPENCLAW_NATIVE_TOOLS_ALLOWLIST="message.voice,message.image,..."`.
11
- * Q1 expanded default ships at v1.0.0-rc1 alongside the `CC_OPENCLAW_NATIVE_TOOLS=1` flip.
12
- */
13
- /**
14
- * v0.11.x default — kept exported for legacy callers and for the
15
- * `ConfigService`-unset fallback path. New code should call `isAllowedTool`.
16
- */
17
- export declare const OPENCLAW_TOOL_ALLOWLIST: ReadonlySet<string>;
18
- /** Return true when `toolName` is in the active allowList. */
19
- export declare function isAllowedTool(toolName: string): boolean;
@@ -1,30 +0,0 @@
1
- /**
2
- * factory.ts — Bridge factory: reads env flags and returns the active IToolBridge.
3
- *
4
- * Mode precedence (highest wins):
5
- * CC_OPENCLAW_NATIVE_TOOLS=1 → OpenClawNative (v0.11.0, default OFF)
6
- * CC_OPENCLAW_TOOL_STREAM=1 → NativeStream
7
- * OPENAI_COMPAT_TOOLS_PER_MESSAGE=1 → PerMessage
8
- * (default) → Embedded
9
- *
10
- * The three existing modes (Embedded, PerMessage, NativeStream) are NOT
11
- * implemented as full IToolBridge classes in this PR — their logic lives
12
- * inside openai-compat.ts. The factory stubs them as thin wrappers that
13
- * satisfy IToolBridge so callers can type-check against the interface.
14
- * Only OpenClawNativeBridge is a real implementation here.
15
- *
16
- * Coexistence rule: existing flag readers (`isToolsPerMessageModeEnabled`,
17
- * `isToolStreamMode`) are not touched — factory reads them via the same
18
- * env vars, not via those helpers, to avoid coupling factory → mode-flags.
19
- */
20
- import type { IToolBridge } from '../../types/tool-bridge.js';
21
- import { ToolMode } from '../../types/tool-bridge.js';
22
- /**
23
- * Return the active IToolBridge based on env flags.
24
- *
25
- * Call once per request — bridges are lightweight and stateless (except
26
- * OpenClawNativeToolsBridge which caches the gateway config read).
27
- */
28
- export declare function makeToolBridge(): IToolBridge;
29
- /** Read the active mode without constructing a bridge. Useful for logging. */
30
- export declare function activeToolMode(): ToolMode;
@@ -1,34 +0,0 @@
1
- /**
2
- * media-bridge.ts — Shared contract for media delivery bridges.
3
- *
4
- * `MediaBridge` is the interface all media-type sub-bridges implement.
5
- * `TtsMediaBridge` (tts-media-bridge.ts) is the v0.11.0 concrete impl.
6
- * Future: `ImageMediaBridge`, `FileMediaBridge` for v0.12.0.
7
- */
8
- /** Structured result from a media bridge execution. */
9
- export interface MediaBridgeResult {
10
- /** Text to inject into the SSE stream in place of the tool_call. */
11
- readonly text: string;
12
- /** Whether the bridge produced output via the native channel. */
13
- readonly delivered: boolean;
14
- /** Delivery channel used. Informational — not load-bearing. */
15
- readonly via: string;
16
- }
17
- /** Every media sub-bridge must satisfy this contract. */
18
- export interface MediaBridge {
19
- /** Canonical tool name this bridge handles (e.g. `message.voice`). */
20
- readonly toolName: string;
21
- /**
22
- * Execute the media delivery. `args` is the raw JSON-parsed tool arguments
23
- * from the model's tool_call. Returns a `MediaBridgeResult` — never throws;
24
- * fallback text is always produced on error.
25
- */
26
- execute(args: Record<string, unknown>): Promise<MediaBridgeResult>;
27
- }
28
- /** Thrown by bridge internals for structured error propagation.
29
- * Caught at the `OpenClawNativeToolsBridge` boundary — never escapes to callers. */
30
- export declare class MediaBridgeError extends Error {
31
- readonly toolName: string;
32
- readonly cause?: unknown | undefined;
33
- constructor(message: string, toolName: string, cause?: unknown | undefined);
34
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * OpenClawApiShim — typed subset of the OpenClaw plugin API surface.
3
- *
4
- * Q2 resolution: the upstream OpenClaw plugin API has no semver contract.
5
- * Rather than depend on it directly, all native-tool calls go through this
6
- * shim which exposes only the methods cc-openclaw needs.
7
- *
8
- * `validateShape(api)` runs at boot phase 3 (`validate-upstream`) and is
9
- * registered as a `PatchSpec.expectedShape` probe. Failure → `DriftError`
10
- * and boot refuses (per PatchManifest atomic-install contract).
11
- *
12
- * Phase D: types + probe shipped; `dispatch` stubbed and throws
13
- * `NotImplemented` until Phase E wires the live OpenClaw `api.tool.dispatch`.
14
- */
15
- /**
16
- * Inbound dispatch types for the v1.0.0 ToolBridge strategy. These are
17
- * complementary to the existing `IToolBridge` at `src/types/tool-bridge.ts`
18
- * (which handles outbound tools-to-CLI wiring). Phase E consolidates the
19
- * two interfaces if a clean merge is possible.
20
- */
21
- export interface ToolUseCall {
22
- readonly id: string;
23
- readonly name: string;
24
- readonly input: unknown;
25
- }
26
- export interface ToolUseResult {
27
- readonly toolUseId: string;
28
- readonly content: string;
29
- readonly isError?: boolean;
30
- }
31
- /** Minimum surface area the shim requires from `openclaw.PluginApi`. */
32
- export interface OpenClawApiSurface {
33
- readonly tool: {
34
- readonly dispatch: (name: string, input: unknown) => Promise<unknown>;
35
- readonly list: () => ReadonlyArray<{
36
- readonly name: string;
37
- }>;
38
- };
39
- }
40
- export declare class OpenClawApiShim {
41
- private readonly api;
42
- constructor(api: OpenClawApiSurface);
43
- /**
44
- * Phase 3 probe — returns true when `api.tool.dispatch` and `api.tool.list`
45
- * exist as callable methods. Used as a `PatchSpec.expectedShape` probe.
46
- */
47
- static validateShape(api: unknown): boolean;
48
- /**
49
- * Dispatch a Claude `tool_use` event to OpenClaw's plugin API. Phase D stub.
50
- */
51
- dispatch(_call: ToolUseCall): Promise<ToolUseResult>;
52
- /** Phase D helper — exposes the underlying surface for tests. */
53
- getApi(): OpenClawApiSurface;
54
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * openclaw-native-tools.ts — IToolBridge impl for ToolMode.OpenClawNative.
3
- *
4
- * v0.11.0 investigation result: OpenClaw DOES expose `/tools/invoke` at
5
- * `http://127.0.0.1:18790` with Bearer token auth (confirmed in
6
- * extensions/cc-openclaw/openclaw-mcp-bridge.cjs). However, the gateway's
7
- * `tools.allow` list in openclaw.json only includes `claude_session_*` and
8
- * council/ultraplan commands — `message.voice` is NOT there. Invoking
9
- * `/tools/invoke` for voice would 404/401 at runtime.
10
- *
11
- * Decision: Path B (internal marker translation) for v0.11.0. `executeNative`
12
- * routes `message.voice` through TtsMediaBridge → `[[tts:text]]` markers.
13
- * OpenClaw's existing `maybeApplyTtsToPayload` picks them up downstream.
14
- * This is identical to the voice-recovery.ts rescue path — the difference is
15
- * the call site: here the model emits a proper tool_call, not raw text XML.
16
- *
17
- * Path A (real HTTP POST to `/tools/invoke`) is fully wired in `executeHttp`
18
- * and ready to activate in v0.12.0 when A1 adds `message.voice` to
19
- * `gateway.tools.allow` in openclaw.json.
20
- */
21
- import type { IToolBridge, ToolDefinition, TranslatedToolUseDelta } from '../../types/tool-bridge.js';
22
- import { ToolMode } from '../../types/tool-bridge.js';
23
- interface GatewayConfig {
24
- url: string;
25
- token: string;
26
- }
27
- export declare class OpenClawNativeToolsBridge implements IToolBridge {
28
- readonly mode = ToolMode.OpenClawNative;
29
- private readonly _gwConfig;
30
- constructor(gwConfig?: GatewayConfig);
31
- /**
32
- * Build a minimal tool preamble listing only the tools the bridge can
33
- * actually handle (allowlisted + registered). The full schema is omitted —
34
- * the caller's system prompt already advertises it. This is a safety marker
35
- * so Savvy knows the bridge is active.
36
- */
37
- buildToolPreamble(tools: ReadonlyArray<ToolDefinition> | undefined): string;
38
- /**
39
- * Translate a tool_use event from the Claude stream into an OpenAI delta.
40
- * This bridge does NOT intercept mid-stream events — tool execution happens
41
- * in `executeNative` after the full turn completes. Return null always.
42
- */
43
- translateToolUse(_event: unknown): TranslatedToolUseDelta;
44
- /** Serialize a tool result back as XML for the next turn's user message. */
45
- serializeToolResult(call: import('../../types/route.js').OpenAIToolCall, result: string): string;
46
- /**
47
- * Execute a `message.voice` (or other allowlisted) tool call.
48
- *
49
- * v0.11.0: routes through TtsMediaBridge (Path B — marker translation).
50
- * Returns the TTS marker text to inject into the SSE stream.
51
- *
52
- * When `CC_OPENCLAW_NATIVE_TOOLS_HTTP=1` is set, falls through to Path A
53
- * (real HTTP POST). Reserved for v0.12.0 activation.
54
- */
55
- executeNative(toolName: string, args: Record<string, unknown>): Promise<{
56
- text: string;
57
- delivered: boolean;
58
- via: string;
59
- }>;
60
- }
61
- export {};
@@ -1,26 +0,0 @@
1
- /**
2
- * openclaw-tool-registry.ts — Registry that maps allowed tool names to their
3
- * MediaBridge implementations.
4
- *
5
- * v0.11.0 only registers `message.voice` → TtsMediaBridge. The registry is
6
- * lazy-constructed per-request (stateless) so future parallel agents can add
7
- * bridges without contention.
8
- */
9
- import type { MediaBridge } from './media-bridge.js';
10
- /** Resolved bridge for a given tool name, or null when not in allowlist. */
11
- export interface ResolvedBridge {
12
- readonly bridge: MediaBridge;
13
- readonly toolName: string;
14
- }
15
- /**
16
- * Look up the MediaBridge for `toolName`.
17
- * Returns null when the tool is not in the v0.11.0 allowlist OR has no
18
- * registered implementation.
19
- */
20
- export declare function resolveToolBridge(toolName: string): ResolvedBridge | null;
21
- /**
22
- * Return every tool name currently in the registry (i.e. allowed + implemented).
23
- * Used by `OpenClawNativeToolsBridge.buildToolPreamble` to filter the caller's
24
- * tool list down to what the bridge can actually handle.
25
- */
26
- export declare function registeredToolNames(): ReadonlySet<string>;
@@ -1,19 +0,0 @@
1
- /**
2
- * tts-media-bridge.ts — MediaBridge impl for `message.voice`.
3
- *
4
- * v0.11.0 Path B strategy: instead of POSTing to a TTS HTTP endpoint, this
5
- * bridge converts `message.voice` tool args into `[[tts:text]]` markers that
6
- * OpenClaw's existing `maybeApplyTtsToPayload` downstream picks up — the same
7
- * channel voice-recovery.ts uses. This gives the tool-boundary UX (Savvy sees
8
- * a proper tool interface; callers see tool_call deltas) without requiring a
9
- * new OpenClaw endpoint.
10
- *
11
- * The bridge imports from voice-recovery.ts and reuses its marker constants
12
- * and truncation logic. No logic is duplicated.
13
- */
14
- import type { MediaBridge, MediaBridgeResult } from './media-bridge.js';
15
- export declare const TTS_TOOL_NAME = "message.voice";
16
- export declare class TtsMediaBridge implements MediaBridge {
17
- readonly toolName = "message.voice";
18
- execute(args: Record<string, unknown>): Promise<MediaBridgeResult>;
19
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * resolveChatCwd — working directory for an openai-compat (Telegram chat) session.
3
- *
4
- * Default: a neutral per-session tmpdir, so the claude CLI does NOT load
5
- * CLAUDE.md / git state / project context (keeps chat turns cheap and clean —
6
- * this is the deliberate v0.x choice).
7
- *
8
- * Opt-in (v0.27.12): set CC_OPENCLAW_CHAT_CWD to an existing directory and chat
9
- * sessions run there — the CLI then loads that project's CLAUDE.md + git context
10
- * like the terminal CLI does, and the CLI's "cwd reset" lands on the project dir
11
- * instead of a tmpdir. This closes the chat-vs-terminal project-context parity
12
- * gap as an explicit, per-deployment opt-in, so the default stays zero-token-
13
- * overhead. A blank/unset/nonexistent value falls back to the tmpdir, so a
14
- * misconfigured path can never break session creation.
15
- *
16
- * Pure (deps injectable) for unit-testing.
17
- */
18
- export declare function resolveChatCwd(sessionName: string, opts?: {
19
- cwdOverride?: string;
20
- dirExists?: (p: string) => boolean;
21
- tmpDir?: string;
22
- }): string;
@@ -1,134 +0,0 @@
1
- /**
2
- * Claude CLI streaming output parser.
3
- *
4
- * Reads NDJSON from `claude --output-format=stream-json --include-partial-messages`
5
- * and emits typed events. The CLI's stream-json wraps Anthropic Messages API
6
- * stream events inside an envelope:
7
- *
8
- * {"type":"stream_event","event":{<anthropic_event>},...}
9
- *
10
- * Other envelope types include `system`, `assistant`, `rate_limit_event`,
11
- * `result`, plus hook lifecycle events.
12
- *
13
- * This module unwraps `stream_event` envelopes and emits the inner Anthropic
14
- * Messages API events directly. Other envelope types pass through with their
15
- * own ParsedEvent variants so downstream consumers can react (e.g. the budget
16
- * guard listens to `rate_limit_event` and `result`).
17
- *
18
- * Captured against Claude CLI v2.1.119. Fixture corpus lives at
19
- * tests/streaming/fixtures/*.ndjson.
20
- */
21
- export type AnthropicEvent = {
22
- type: 'message_start';
23
- message: AnthropicMessage;
24
- } | {
25
- type: 'content_block_start';
26
- index: number;
27
- content_block: ContentBlockStart;
28
- } | {
29
- type: 'content_block_delta';
30
- index: number;
31
- delta: ContentBlockDelta;
32
- } | {
33
- type: 'content_block_stop';
34
- index: number;
35
- } | {
36
- type: 'message_delta';
37
- delta: MessageDeltaBody;
38
- usage?: MessageUsage;
39
- } | {
40
- type: 'message_stop';
41
- } | {
42
- type: 'error';
43
- error: {
44
- type: string;
45
- message: string;
46
- };
47
- };
48
- export interface AnthropicMessage {
49
- id: string;
50
- model: string;
51
- role?: string;
52
- content?: unknown[];
53
- stop_reason?: string | null;
54
- stop_sequence?: string | null;
55
- usage?: MessageUsage;
56
- }
57
- export interface MessageUsage {
58
- input_tokens?: number;
59
- output_tokens?: number;
60
- cache_creation_input_tokens?: number;
61
- cache_read_input_tokens?: number;
62
- }
63
- export interface MessageDeltaBody {
64
- stop_reason?: string;
65
- stop_sequence?: string | null;
66
- stop_details?: unknown;
67
- }
68
- export type ContentBlockStart = {
69
- type: 'text';
70
- text: string;
71
- } | {
72
- type: 'tool_use';
73
- id: string;
74
- name: string;
75
- input: Record<string, unknown>;
76
- caller?: unknown;
77
- } | {
78
- type: 'thinking';
79
- thinking: string;
80
- signature: string;
81
- };
82
- export type ContentBlockDelta = {
83
- type: 'text_delta';
84
- text: string;
85
- } | {
86
- type: 'input_json_delta';
87
- partial_json: string;
88
- } | {
89
- type: 'thinking_delta';
90
- thinking: string;
91
- } | {
92
- type: 'signature_delta';
93
- signature: string;
94
- };
95
- export type ParsedEvent = AnthropicEvent | {
96
- type: 'system';
97
- subtype: string;
98
- raw: Record<string, unknown>;
99
- } | {
100
- type: 'assistant';
101
- message: AnthropicMessage;
102
- sessionId?: string;
103
- parentToolUseId?: string | null;
104
- } | {
105
- type: 'rate_limit_event';
106
- rateLimitInfo: Record<string, unknown>;
107
- } | {
108
- type: 'result';
109
- subtype: string;
110
- isError: boolean;
111
- result?: string;
112
- durationMs?: number;
113
- usage?: MessageUsage;
114
- totalCostUsd?: number;
115
- raw: Record<string, unknown>;
116
- } | {
117
- type: 'unknown';
118
- raw: unknown;
119
- } | {
120
- type: 'parse_error';
121
- error: {
122
- type: string;
123
- message: string;
124
- };
125
- rawLine?: string;
126
- };
127
- export interface CliStreamParser {
128
- /** Push a chunk of stdout. Returns events derivable from any complete lines.
129
- * Incomplete trailing line stays in the buffer for the next call. */
130
- push(chunk: string): ParsedEvent[];
131
- /** Flush any remaining buffered partial line. Returns final events (or empty). */
132
- flush(): ParsedEvent[];
133
- }
134
- export declare function createCliStreamParser(): CliStreamParser;
@@ -1 +0,0 @@
1
- export * from './openai-compat.js';
@@ -1,84 +0,0 @@
1
- /**
2
- * Cluster B — Message extractor.
3
- *
4
- * Extracted verbatim from `openai-compat.ts:177-301` (Phase 4 Cluster B
5
- * Module D). Single function that converts an OpenAI `messages[]` array
6
- * into the inputs Claude CLI's bridge expects:
7
- *
8
- * - systemPrompt — joined `role:system` content, undefined if none
9
- * - userMessage — last user message (with skill-inline applied)
10
- * OR XML-wrapped tool-result block when the
11
- * last non-system message is `role:tool`
12
- * - userMessageBlocks — tool-stream mode only: native Anthropic
13
- * content blocks (tool_result + text) for the
14
- * stream-json input path
15
- * - isNewConversation — drives session-create vs session-append
16
- *
17
- * Single call site in the orchestrator (handleChatCompletion line 482).
18
- * The two types `UserMessageBlock` and `ExtractedMessage` are also re-
19
- * exported from openai-compat.ts for callers across the orchestrator
20
- * (formatCompletionResponse + helpers all consume them as parameters).
21
- *
22
- * Session-reset semantics:
23
- * - X-Session-Reset: 1|true → always treated as new conversation
24
- * - OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1 (env) → legacy
25
- * "system + single user ⇒ new conversation" rule, opt-in for
26
- * callers that re-send the full transcript every turn
27
- * - Default (env unset) → only the explicit header creates a new
28
- * conversation; persistent CLI sessions survive across turns and
29
- * benefit from Anthropic prompt caching (PR #40)
30
- */
31
- import type { OpenAIChatMessage } from './openai-compat.js';
32
- import { type AnthropicToolResultBlock } from './tool-results-serializer.js';
33
- /**
34
- * Phase 2 R4 wire-up: optional structured content for tool-stream mode.
35
- * When set, consumers should send this array to the subprocess instead of
36
- * the legacy XML-wrapped `userMessage` string. Each element is either a
37
- * native Anthropic `tool_result` block (for prior tool outputs) or a
38
- * `text` block (for the user's follow-up message).
39
- */
40
- export type UserMessageBlock = AnthropicToolResultBlock | {
41
- type: 'text';
42
- text: string;
43
- };
44
- export interface ExtractedMessage {
45
- systemPrompt: string | undefined;
46
- userMessage: string;
47
- /**
48
- * Populated only in tool-stream mode when the last non-system message
49
- * is a tool-role result. Carries native Anthropic tool_result blocks
50
- * + optional follow-up text. When undefined, consumers fall back to
51
- * the string `userMessage` (legacy XML-wrapped path).
52
- */
53
- userMessageBlocks?: UserMessageBlock[];
54
- isNewConversation: boolean;
55
- /** v0.19.1 M3 — slash command detected at message start, for live-card pill. */
56
- slashCommand?: {
57
- cmd: string;
58
- mode?: string;
59
- };
60
- }
61
- /**
62
- * Extract the relevant parts from an OpenAI messages array.
63
- *
64
- * Sessions are stateful — we only need the last user message. The tricky
65
- * question is whether to start a fresh session or append to the existing one.
66
- *
67
- * Default mode (no env var): only honor an explicit `X-Session-Reset: 1`
68
- * header. This is correct for clients that maintain their own conversation
69
- * transcript and forward only the latest user turn (OpenClaw main agent
70
- * loop, cron jobs, subagents). The previous heuristic
71
- * (`nonSystemMessages.length <= 1`) fired on every such request, killing the
72
- * persistent CLI every turn and preventing Anthropic prompt caching from
73
- * ever warming. Originally diagnosed in PR #40 by @megayounus786.
74
- *
75
- * Legacy mode (`OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1`): restore the old
76
- * `system + single user ⇒ new conversation` rule, for clients that re-send
77
- * the full transcript on every turn (ChatGPT-Next-Web, Open WebUI, data
78
- * labeling tools, etc). They use the transcript shape itself as their only
79
- * "start a new conversation" signal.
80
- *
81
- * The env var is read on every call so ops can flip it via launchctl setenv
82
- * without restarting the server.
83
- */
84
- export declare function extractUserMessage(messages: OpenAIChatMessage[], headers?: Record<string, string | string[] | undefined>): ExtractedMessage;
@@ -1,34 +0,0 @@
1
- /**
2
- * Cluster B beachhead — tool-mode flag predicates.
3
- *
4
- * Extracted from `openai-compat.ts` so that `session-key-resolver.ts`
5
- * (and future Cluster B modules) can read these flags without creating
6
- * a circular import back into the orchestrator.
7
- *
8
- * Behavior preserved bit-for-bit from the original definitions in
9
- * `openai-compat.ts:126-142`. openai-compat.ts re-exports both
10
- * functions for any external caller that previously imported them
11
- * from there (none exist today, but the re-export is cheap insurance).
12
- *
13
- * Cluster B follow-on will fold these into the `IToolBridge` strategy
14
- * pattern (PRP §5 Cluster B `bridges/factory.ts`); for now they
15
- * remain free-function predicates.
16
- */
17
- /**
18
- * Legacy mode: when set, tool definitions are prepended to every user
19
- * message instead of being baked into the session system prompt. Defeats
20
- * prompt caching but allows mutating the tool list mid-session.
21
- *
22
- * Truthy values: '1', 'true', 'yes' (case-insensitive, trimmed).
23
- */
24
- export declare function isToolsPerMessageModeEnabled(): boolean;
25
- /**
26
- * Phase 2 R5: tool-stream mode flag. When `CC_OPENCLAW_TOOL_STREAM=1`
27
- * AND the caller provides `tools[]`, cc-openclaw skips the defensive
28
- * "no tools" system prompt and does NOT clear `sessionConfig.tools`,
29
- * allowing Claude CLI's native tool_use events to flow through the
30
- * parser+translator pipeline.
31
- *
32
- * Strict opt-in: only true when env value is exactly `'1'`.
33
- */
34
- export declare function isToolStreamMode(): boolean;