@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,60 +0,0 @@
1
- /**
2
- * Cluster B — Tool-result serializers.
3
- *
4
- * Extracted verbatim from `openai-compat.ts:153-211` (Phase 4 Cluster B
5
- * Module C). Two functions that serialize OpenAI `role:tool` messages
6
- * into the format Claude CLI expects, picked between by the runtime
7
- * `CC_OPENCLAW_TOOL_STREAM` flag:
8
- *
9
- * - `serializeToolResults(messages)` — legacy XML path. Wraps each
10
- * tool message in `<tool_result tool_call_id="...">` and concatenates
11
- * into a single `<tool_results>` block. Used when the model receives
12
- * tool definitions via the system prompt's `<available_tools>` XML.
13
- *
14
- * - `serializeToolResultsAsBlocks(messages)` — Phase 2 R4 native path.
15
- * Returns an array of Anthropic `tool_result` content blocks shaped
16
- * as `{ type, tool_use_id, content }`. Used when Claude CLI parses
17
- * tool results natively (CC_OPENCLAW_TOOL_STREAM=1).
18
- *
19
- * - `AnthropicToolResultBlock` — interface for the native shape.
20
- *
21
- * Both serializers are pure. Currently only called by
22
- * `message-extractor.ts:extractUserMessage` (Module D); the orchestrator
23
- * itself does not call them directly anymore.
24
- */
25
- import type { OpenAIChatMessage } from './openai-compat.js';
26
- /**
27
- * Serialize tool result messages into a text block for the CLI model.
28
- * Converts OpenAI `tool` role messages into <tool_result> tags.
29
- *
30
- * Legacy path (CC_OPENCLAW_TOOL_STREAM=0). Used when the model receives
31
- * tool definitions via the system prompt's <available_tools> XML block
32
- * and emits <tool_calls> XML in response. Tool-stream mode (R4) uses
33
- * `serializeToolResultsAsBlocks()` instead, returning native Anthropic
34
- * `tool_result` content blocks that Claude CLI parses directly.
35
- */
36
- export declare function serializeToolResults(messages: OpenAIChatMessage[]): string;
37
- /**
38
- * Phase 2 R4: native Anthropic `tool_result` content blocks.
39
- *
40
- * In tool-stream mode (CC_OPENCLAW_TOOL_STREAM=1), this replaces
41
- * `serializeToolResults()` XML wrapping. Returns blocks shaped like:
42
- *
43
- * { type: 'tool_result', tool_use_id: 'toolu_X', content: '...' }
44
- *
45
- * Claude CLI's stream-json input format accepts these as user-message
46
- * content arrays. The model then continues generation with the tool
47
- * result in context, emitting either more `tool_use` events or final
48
- * text — no XML round-tripping required.
49
- *
50
- * Wiring into the live request path lands with Phase 4 Pillar 0.5
51
- * tasks R1+R2 (parser+translator response-side integration), where
52
- * `extractUserMessage` produces structured content arrays in
53
- * tool-stream mode.
54
- */
55
- export interface AnthropicToolResultBlock {
56
- type: 'tool_result';
57
- tool_use_id: string;
58
- content: string;
59
- }
60
- export declare function serializeToolResultsAsBlocks(messages: OpenAIChatMessage[]): AnthropicToolResultBlock[];
@@ -1,20 +0,0 @@
1
- /**
2
- * TTS_RULE — voice-delivery rule prepended to `--append-system-prompt` when
3
- * `messages.tts.auto !== 'off'`. Defense-in-depth: ensures Savvy knows the
4
- * `[[tts:text]]` marker syntax even if CLAUDE.md gets autobackup-reverted
5
- * AND if OpenClaw upstream doesn't inject `buildTtsSystemPromptHint` into
6
- * the outbound openai-compat HTTP body.
7
- *
8
- * History:
9
- * - v0.10.2: rule auto-prepended when tts.auto !== 'off'.
10
- * - v0.10.3: REWRITTEN as imperative + with override authority + few-shot.
11
- * Previous wording ("wrap the spoken portion...") was interpreted by
12
- * Savvy as optional. 2026-05-11 evening test showed Savvy ending with
13
- * "Let me send the voice note now" followed by no markers and no voice
14
- * — model was looking for a tool to call OR treating the rule as a
15
- * suggestion. v0.10.3 explicitly forbids alternatives and gives an example.
16
- *
17
- * Extracted from `openai-compat.ts` 2026-05-13 — pure-string constant, no
18
- * I/O, no module state. Safe single-source for the canonical rule text.
19
- */
20
- export declare const TTS_RULE: string;
@@ -1,56 +0,0 @@
1
- /**
2
- * voice-recovery — server-side bridge that ensures voice delivery via
3
- * `[[tts:text]]...[[/tts:text]]` markers even when Savvy doesn't emit them.
4
- *
5
- * v0.10.3 turns cc-openclaw from a passive text proxy into an active
6
- * voice-aware bridge for three failure modes:
7
- *
8
- * 1. Savvy emits `<tool_calls>` XML for a native OpenClaw voice tool
9
- * (e.g. `message.voice`) that cc-openclaw can't execute. The XML
10
- * lands as raw text in the SSE stream. → `translateVoiceToolCalls`
11
- * rewrites it as `[[tts:text]]` markers.
12
- *
13
- * 2. User explicitly asks for voice but Savvy produces markerless text
14
- * (the dominant failure observed in the 2026-05-11 evening test).
15
- * → `autoWrapMissingMarkers` wraps the first sentence/paragraph
16
- * in markers so OpenClaw's `maybeApplyTtsToPayload` triggers.
17
- *
18
- * 3. Hint-loss between turns. → `detectVoiceIntent` gates recovery so
19
- * it only fires on explicit voice requests, never on accidental
20
- * voice-keyword matches in non-voice prompts.
21
- *
22
- * All functions are PURE — no side effects, no IO, no logging. Tests
23
- * exercise them directly via `tests/voice-recovery.test.ts`.
24
- */
25
- /** Default max chars inside the spoken block. Matches the TTS_RULE budget. */
26
- export declare const DEFAULT_MAX_SPOKEN_CHARS = 500;
27
- /** v0.10.4 — env-gated debug logger for triangulating voice-recovery
28
- * failure mode on Telegram vs. direct-probe paths. Single-line JSON for
29
- * grep-ability via `pm2 logs openclaw-gateway | grep _voice_debug`.
30
- * Disabled unless `CC_OPENCLAW_VOICE_DEBUG=1`. Safe to leave in code
31
- * permanently — the gate is a single string equality check. */
32
- export declare function _logVoiceDebug(label: string, fields: Record<string, unknown>): void;
33
- /** Detect whether the user's prompt explicitly requests a voice note. */
34
- export declare function detectVoiceIntent(userPrompt: string): boolean;
35
- /** Check whether the reply text already contains a complete `[[tts:text]]`
36
- * block (open + close pair). */
37
- export declare function hasTtsMarkers(text: string): boolean;
38
- /** If `text` contains a `<tool_calls>` XML block targeting a voice-delivery
39
- * tool, extract the spoken-text argument. Returns the spoken text or null. */
40
- export declare function extractTtsToolCallText(text: string): string | null;
41
- /** Rewrite `text`: if a voice-tool XML block is present, remove it and
42
- * insert a `[[tts:text]]<spoken>[[/tts:text]]` block in its place. Idempotent
43
- * when no voice-tool XML is present. */
44
- export declare function translateVoiceToolCalls(text: string): string;
45
- /** If `text` is missing voice markers, find a reasonable spoken summary
46
- * (first paragraph up to `maxSpokenChars`) and wrap it. Returns text with
47
- * the marker block prepended; the original first paragraph is left in place
48
- * as text expansion. Idempotent when markers already present. */
49
- export declare function autoWrapMissingMarkers(text: string, maxSpokenChars?: number): string;
50
- /** Convenience helper: run the full recovery pipeline on a reply when the
51
- * user has expressed voice intent. Returns the (possibly rewritten) text. */
52
- export declare function applyVoiceRecovery(userPrompt: string, replyText: string, maxSpokenChars?: number): {
53
- text: string;
54
- recovered: boolean;
55
- via: 'none' | 'tool-translate' | 'auto-wrap';
56
- };
@@ -1,103 +0,0 @@
1
- /**
2
- * PatchSpec: cache-parity-registry
3
- *
4
- * Second Phase E#3 PatchSpec, demonstrating that the pattern composes —
5
- * multiple specs can register in one PatchManifest and validate
6
- * independently. Drift-detection only at this stage; real install/uninstall
7
- * extracted from `src/lib/cache-parity.ts` lands in Phase E#3 proper.
8
- *
9
- * Drift contract: verifies `src/lib/cache-parity.ts` exports its canonical
10
- * registry path constant and at least one accessor function. If a future
11
- * refactor accidentally removes the registry writer, this probe surfaces
12
- * a DriftError at boot phase 3, preventing silent cache-parity regressions
13
- * of the v0.6.0 namespace-bug class.
14
- *
15
- * v0.16 extension (task-005):
16
- * Self-recovery on namespace mismatch. When the registry detects a
17
- * namespace mismatch (previously required a manual wipe), it now:
18
- * 1. Clears only the mismatched namespace entries from the local cache.
19
- * 2. Emits a 'cache-parity.namespace-mismatch-recovered' telemetry event
20
- * via the EventBus so the drift can be observed without interruption.
21
- * 3. Increments an internal restart-cycle counter so the test harness can
22
- * verify N consecutive mismatches all self-recovered.
23
- *
24
- * The self-recovery logic lives in CacheParityRecovery (exported below)
25
- * and is also exercised by the PatchSpec's expectedBehavior probe so every
26
- * boot validates that recovery works before traffic starts.
27
- */
28
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
29
- import { EventBus } from '../observability/event-bus.js';
30
- interface CacheParityTarget {
31
- readonly module: Record<string, unknown>;
32
- }
33
- export declare const cacheParityRegistrySpec: PatchSpec<CacheParityTarget>;
34
- export interface CacheParityRecoveryOptions {
35
- /** EventBus for emitting 'cache-parity.namespace-mismatch-recovered'. */
36
- bus: EventBus;
37
- /**
38
- * Path to the JSONL file where warning events are appended. Defaults to
39
- * REGISTRY_PATH (cc-openclaw-cache-registry.jsonl). Overridable in tests.
40
- */
41
- registryPath?: string;
42
- }
43
- /**
44
- * CacheParityRecovery — self-healing logic for namespace mismatches.
45
- *
46
- * Previously, a namespace mismatch in the cache-parity registry required a
47
- * manual wipe (OPENCLAW_CACHE_PARITY=0, delete file, re-enable). This class
48
- * automates recovery:
49
- * 1. Clear only the mismatched namespace's entries from the in-memory cache.
50
- * 2. Emit a telemetry event so the mismatch is observable in trajectory logs.
51
- * 3. Return the number of bytes cleared so the caller/test can assert on it.
52
- *
53
- * Lifecycle:
54
- * - One instance per gateway session (or per-test via constructor injection).
55
- * - restartCycle auto-increments on each recoverNamespaceMismatch() call,
56
- * allowing the test harness to verify 3 consecutive recoveries.
57
- * - The in-memory namespace cache is an independent Map — it does NOT write
58
- * to disk (that is src/lib/cache-parity.ts's job). This keeps concerns
59
- * separated and makes testing trivial.
60
- */
61
- export declare class CacheParityRecovery {
62
- private readonly bus;
63
- private readonly registryPath;
64
- /** In-memory namespace → cached prompt-hash map. */
65
- private readonly namespaceCache;
66
- /** Number of namespace mismatches recovered since construction. */
67
- private _restartCycle;
68
- constructor(opts: CacheParityRecoveryOptions);
69
- /**
70
- * Record a namespace entry. Called by the session bootstrap when it attaches
71
- * a system prompt under a given namespace key.
72
- */
73
- registerNamespace(namespace: string, promptHash: string): void;
74
- /**
75
- * Detect and self-recover a namespace mismatch.
76
- *
77
- * A mismatch is detected when `namespace` is present in the local cache
78
- * but the caller reports that the live registry's hash for that namespace
79
- * differs (i.e. a gateway restart changed the prompt). Recovery:
80
- * 1. Measure the number of entries about to be cleared.
81
- * 2. Delete the stale namespace from the in-memory cache.
82
- * 3. Emit 'cache-parity.namespace-mismatch-recovered' telemetry.
83
- * 4. Increment restartCycle.
84
- *
85
- * @returns The number of stale hash entries cleared.
86
- */
87
- recoverNamespaceMismatch(namespace: string): Promise<number>;
88
- /**
89
- * Check whether `namespace` is present in the local cache. Used by the
90
- * session bootstrap to decide whether a mismatch has occurred.
91
- */
92
- hasNamespace(namespace: string): boolean;
93
- /** Current number of recovered mismatch cycles. */
94
- get restartCycle(): number;
95
- /** Number of distinct namespaces currently tracked. */
96
- get namespaceCount(): number;
97
- private appendWarningToRegistry;
98
- /** Expose internal cache snapshot for test assertions. */
99
- _snapshotForTests(): Map<string, string[]>;
100
- /** Reset to clean state — used between test cycles. */
101
- _resetForTests(): void;
102
- }
103
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * PatchSpec: claude-md-injection — Phase E#3 scaffold.
3
- *
4
- * Target: CLAUDE.md inline sysprompt prepend (cwd-patch.ts:~489 area).
5
- * Pairs with sysprompt-strip but on the inject side. Drift-detection only today.
6
- */
7
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
8
- type ClaudeMdInjectionTarget = Record<string, unknown>;
9
- export declare const claudeMdInjectionSpec: PatchSpec<ClaudeMdInjectionTarget>;
10
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * PatchSpec: cwd-redirect — Phase E#3 scaffold.
3
- *
4
- * Target: workspace cwd injection in cwd-patch.ts:applyPatch step 1 (the
5
- * `'openai-'` session prefix branded type gate). Drift-detection only today.
6
- */
7
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
8
- type CwdRedirectTarget = Record<string, unknown>;
9
- export declare const cwdRedirectSpec: PatchSpec<CwdRedirectTarget>;
10
- export {};
@@ -1,23 +0,0 @@
1
- /**
2
- * PatchSpec: embedded-server-route
3
- *
4
- * Third Phase E#3 PatchSpec. Targets the 9-step route-patch closure
5
- * currently in `src/session-bootstrap/cwd-patch.ts:applyPatch` (~line 481).
6
- * That closure intercepts `EmbeddedServer.route` to inject:
7
- * - cwd redirect (workspace injection)
8
- * - tools restoration (drop the defensive `tools=''` block)
9
- * - CLAUDE.md inline sysprompt prepend
10
- * - cache-parity registry write
11
- * - token telemetry hook
12
- * - ... 4 more steps
13
- *
14
- * Phase E#3 full conversion: each of the 9 steps becomes its own sub-spec
15
- * (or this single spec internally composes them with named labels for
16
- * mutation-test granularity).
17
- *
18
- * Today: drift-detection only against the openclaw EmbeddedServer surface.
19
- */
20
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
21
- type EmbeddedServerRouteTarget = Record<string, unknown>;
22
- export declare const embeddedServerRouteSpec: PatchSpec<EmbeddedServerRouteTarget>;
23
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * PatchSpec: pricing-overrides — Phase E#3 scaffold.
3
- *
4
- * Target: the pricing-override import currently at
5
- * `src/session-bootstrap/cwd-patch.ts:1094`. Drift-detection only today.
6
- */
7
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
8
- type PricingTarget = Record<string, unknown>;
9
- export declare const pricingOverridesSpec: PatchSpec<PricingTarget>;
10
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * PatchSpec: resume-registry-restore — Phase E#3 scaffold.
3
- *
4
- * Target: Savvy resume-registry restoration logic in cwd-patch.ts. Reads
5
- * `~/.openclaw/savvy-resume-registry.json` and seeds SessionManager state.
6
- * Drift-detection only today.
7
- */
8
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
9
- type ResumeRegistryTarget = Record<string, unknown>;
10
- export declare const resumeRegistryRestoreSpec: PatchSpec<ResumeRegistryTarget>;
11
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * PatchSpec: session-pid-tracking — Phase E#3 scaffold.
3
- *
4
- * Target: PID map maintenance for `~/.openclaw/workspace/memory/session-pids.json`.
5
- * Currently in cwd-patch.ts + session-manager.ts. Drift-detection only today.
6
- */
7
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
8
- type SessionPidTarget = Record<string, unknown>;
9
- export declare const sessionPidTrackingSpec: PatchSpec<SessionPidTarget>;
10
- export {};
@@ -1,46 +0,0 @@
1
- /**
2
- * PatchSpec: sysprompt-strip
3
- *
4
- * Establishes the file convention for Phase E#3. NOT REGISTERED with any
5
- * PatchManifest yet — this is the documented template that real PatchSpec
6
- * files mirror as the cwd-patch.ts decomposition proceeds.
7
- *
8
- * Pattern for Phase E#3:
9
- * 1. One file per logical patch under `src/patches/<id>.spec.ts`.
10
- * 2. File <200 LOC.
11
- * 3. Exports a single `PatchSpec` instance as a named export.
12
- * 4. `resolve()` owns its upstream symbol lookup — no global target arg.
13
- * 5. `expectedShape` is sync, returns boolean; checks signature/props.
14
- * 6. `expectedBehavior` is async; runs a tiny invocation; <100ms.
15
- * 7. `install` + `uninstall` are paired and round-trip-safe.
16
- * 8. A companion `tests/patches/<id>.test.ts` proves shape + mutation necessity.
17
- *
18
- * Functional source for sysprompt-strip lives at `src/lib/sysprompt-strip.ts`
19
- * (pure function, reused as-is). The wrapper that
20
- * registers it as a Claude Code prototype patch lives at
21
- * `src/session-bootstrap/sysprompt-strip.ts`. Phase E#3 converts that wrapper
22
- * into the structured PatchSpec form below.
23
- */
24
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
25
- /**
26
- * PatchSpec: sysprompt-strip — first real Phase E#3 PatchSpec.
27
- *
28
- * Today this spec is **drift-detection only**: `resolve()` does a real
29
- * `await import('openclaw')` to verify the upstream package loads and
30
- * surfaces some exports. `install()` and `uninstall()` remain no-ops until
31
- * the cwd-patch.ts closure is fully extracted (multi-session work).
32
- *
33
- * Even in drift-detection-only mode this is meaningful: a future openclaw
34
- * publish that catastrophically loses its public API will cause `resolve()`
35
- * to throw → DriftError surfaces in `cc-openclaw doctor` output → boot
36
- * refuses install of any patches.
37
- *
38
- * Phase E#3 full conversion: replace the no-op install/uninstall with the
39
- * prototype-patch closure from `src/session-bootstrap/sysprompt-strip.ts`,
40
- * narrow `expectedShape` to verify `SessionManager.prototype.startSession`
41
- * specifically, and populate `expectedBehavior` with a sysprompt round-trip
42
- * fixture.
43
- */
44
- type SyspromptStripTarget = Record<string, unknown>;
45
- export declare const syspromptStripSpec: PatchSpec<SyspromptStripTarget>;
46
- export {};
@@ -1,12 +0,0 @@
1
- /**
2
- * PatchSpec: tools-restoration — Phase E#3 scaffold.
3
- *
4
- * Target: removal of the legacy `body.tools=''` defensive block. Phase 2
5
- * R5 — historically the proxy stripped tools; v0.5.x added Native streaming;
6
- * Phase E#3 finalizes by ensuring no leftover `tools=''` write-paths exist.
7
- * Drift-detection only today.
8
- */
9
- import type { PatchSpec } from '../lifecycle/patch-manifest.js';
10
- type ToolsRestorationTarget = Record<string, unknown>;
11
- export declare const toolsRestorationSpec: PatchSpec<ToolsRestorationTarget>;
12
- export {};
@@ -1,24 +0,0 @@
1
- /**
2
- * MigrationV0 — reads the legacy 4-file persistence format READ-ONLY into
3
- * SessionRegistry on first boot (Q5 resolution: auto-migrate read-only;
4
- * explicit `cc-openclaw migrate --commit` required for deletion).
5
- *
6
- * Legacy files (NEVER deleted by this module):
7
- * ~/.openclaw/claude-sessions.json
8
- * ~/.openclaw/savvy-resume-registry.json
9
- * ~/.openclaw/session-pids.json
10
- * ~/.openclaw/openclaw-cache-parity-registry.json
11
- *
12
- * Shapes are parsed permissively (unknown → narrowed via type guards).
13
- * Missing or malformed files are silently skipped — migration is best-effort.
14
- */
15
- import { type SessionState } from './session-registry.js';
16
- export declare class MigrationV0 {
17
- /**
18
- * Read all legacy files and return SessionState[] for loading into
19
- * SessionRegistry. NEVER modifies or deletes the source files.
20
- */
21
- readLegacy(): Promise<SessionState[]>;
22
- private readPidMap;
23
- private readCacheParityMap;
24
- }
@@ -1,58 +0,0 @@
1
- /**
2
- * SessionRegistry — typed, branded session state store.
3
- *
4
- * Closes the v0.6.0 namespace-bug class structurally:
5
- * - Branded SessionName ensures "openai-" prefix at the type level.
6
- * - asSessionName() throws DomainError.SessionPrefixMissing at runtime if
7
- * the prefix is missing — converting a class of silent bugs to compile errors
8
- * (branded type) + loud runtime errors (guard).
9
- *
10
- * skipPersistence is a typed enum, not a boolean cast (was AS4).
11
- *
12
- * WAL append and snapshot bodies are stubs; Phase E wires WalWriter/SnapshotWriter.
13
- */
14
- export type SessionName = string & {
15
- readonly __brand: 'SessionName';
16
- };
17
- /**
18
- * Runtime guard that enforces the "openai-" prefix.
19
- * Returns a branded SessionName on success.
20
- * Throws SessionPrefixMissing on failure.
21
- */
22
- export declare function asSessionName(s: string): SessionName;
23
- /**
24
- * skipPersistence enum mirrors the boolean-cast in legacy session-manager.ts
25
- * but is explicitly typed (AS4 fix).
26
- *
27
- * - "never" → always persist (default)
28
- * - "session-only" → persist during session, delete on completion
29
- * - "never-persist" → never write to disk (e.g. ephemeral test sessions)
30
- */
31
- type SkipPersistence = 'never' | 'session-only' | 'never-persist';
32
- export interface SessionState {
33
- name: SessionName;
34
- pid?: number;
35
- cwd: string;
36
- /** Entry in the cache-parity registry (Track B). */
37
- cacheRegistryEntry?: string;
38
- skipPersistence: SkipPersistence;
39
- /** ISO timestamp of last state transition. */
40
- updatedAt: string;
41
- }
42
- export declare class SessionRegistry {
43
- private readonly map;
44
- /**
45
- * Upsert a session state. Triggers a WAL append (stub in Phase D).
46
- */
47
- set(state: SessionState): void;
48
- get(name: SessionName): SessionState | undefined;
49
- delete(name: SessionName): void;
50
- /**
51
- * Write current Map state to snapshot file (stub in Phase D).
52
- * Phase E: delegates to SnapshotWriter.
53
- */
54
- snapshot(): Promise<void>;
55
- get size(): number;
56
- values(): IterableIterator<SessionState>;
57
- }
58
- export {};
@@ -1,136 +0,0 @@
1
- /**
2
- * Anthropic ↔ OpenAI Format Adapter
3
- *
4
- * Core conversion logic for translating between Anthropic Messages API format
5
- * and OpenAI Chat Completions format. Replaces the Python server.py (~2300 lines)
6
- * with pure TypeScript (~600 lines), no litellm dependency.
7
- *
8
- * Handles:
9
- * - Message format conversion (content blocks ↔ role/content strings)
10
- * - Tool schema conversion (Anthropic tools ↔ OpenAI function tools)
11
- * - Message normalization (re-interleave merged blocks for OpenAI)
12
- * - Response conversion (OpenAI response → Anthropic response)
13
- * - Streaming SSE conversion (OpenAI SSE → Anthropic SSE events)
14
- */
15
- import { isGeminiModel, isClaudeModel } from '../models.js';
16
- export interface AnthropicRequest {
17
- model: string;
18
- max_tokens: number;
19
- messages: AnthropicMessage[];
20
- system?: string | Array<{
21
- type: string;
22
- text: string;
23
- }>;
24
- tools?: AnthropicTool[];
25
- tool_choice?: {
26
- type: string;
27
- name?: string;
28
- };
29
- stream?: boolean;
30
- temperature?: number;
31
- top_p?: number;
32
- top_k?: number;
33
- thinking?: {
34
- type: string;
35
- budget_tokens?: number;
36
- };
37
- }
38
- export interface AnthropicMessage {
39
- role: 'user' | 'assistant' | 'system';
40
- content: string | AnthropicContentBlock[];
41
- }
42
- export interface AnthropicContentBlock {
43
- type: string;
44
- text?: string;
45
- id?: string;
46
- name?: string;
47
- input?: unknown;
48
- tool_use_id?: string;
49
- content?: unknown;
50
- [key: string]: unknown;
51
- }
52
- export interface AnthropicTool {
53
- name: string;
54
- description?: string;
55
- input_schema: Record<string, unknown>;
56
- }
57
- export interface AnthropicResponse {
58
- id: string;
59
- type: 'message';
60
- model: string;
61
- role: 'assistant';
62
- content: AnthropicContentBlock[];
63
- stop_reason: string | null;
64
- stop_sequence: string | null;
65
- usage: {
66
- input_tokens: number;
67
- output_tokens: number;
68
- cache_creation_input_tokens: number;
69
- cache_read_input_tokens: number;
70
- };
71
- }
72
- export interface OpenAIRequest {
73
- model: string;
74
- messages: OpenAIMessage[];
75
- max_completion_tokens?: number;
76
- temperature?: number;
77
- top_p?: number;
78
- stream?: boolean;
79
- tools?: OpenAITool[];
80
- tool_choice?: string | {
81
- type: string;
82
- function: {
83
- name: string;
84
- };
85
- };
86
- thinking?: {
87
- type: string;
88
- budget_tokens?: number;
89
- };
90
- }
91
- export interface OpenAIMessage {
92
- role: 'system' | 'user' | 'assistant' | 'tool';
93
- content?: string | null;
94
- tool_calls?: OpenAIToolCall[];
95
- tool_call_id?: string;
96
- }
97
- export interface OpenAIToolCall {
98
- id: string;
99
- type: 'function';
100
- function: {
101
- name: string;
102
- arguments: string;
103
- };
104
- extra_content?: Record<string, unknown>;
105
- }
106
- export interface OpenAITool {
107
- type: 'function';
108
- function: {
109
- name: string;
110
- description: string;
111
- parameters: Record<string, unknown>;
112
- };
113
- }
114
- export interface OpenAIResponse {
115
- id?: string;
116
- model?: string;
117
- choices: Array<{
118
- message?: {
119
- content?: string | null;
120
- tool_calls?: OpenAIToolCall[];
121
- };
122
- finish_reason?: string;
123
- }>;
124
- usage?: {
125
- prompt_tokens?: number;
126
- completion_tokens?: number;
127
- };
128
- }
129
- export { isGeminiModel, isClaudeModel };
130
- export declare function convertAnthropicToOpenAI(req: AnthropicRequest): OpenAIRequest;
131
- export declare function convertOpenAIToAnthropic(resp: OpenAIResponse, originalModel: string): AnthropicResponse;
132
- /**
133
- * Convert an OpenAI SSE stream to Anthropic SSE format.
134
- * Yields Anthropic-formatted SSE strings.
135
- */
136
- export declare function convertStreamOpenAIToAnthropic(stream: AsyncIterable<string>, originalModel: string): AsyncGenerator<string>;
@@ -1,39 +0,0 @@
1
- /**
2
- * Proxy HTTP Handler — registerHttpRoute handler for OpenClaw Plugin SDK
3
- *
4
- * Receives Anthropic-format requests from Claude Code CLI,
5
- * translates to OpenAI format, forwards to the target provider,
6
- * and translates the response back to Anthropic format.
7
- *
8
- * Supports:
9
- * - Direct Anthropic API passthrough (zero conversion)
10
- * - OpenAI/GPT models via format conversion
11
- * - Gemini models via format conversion + schema cleaning
12
- * - Gateway passthrough (OpenClaw gateway handles routing)
13
- * - Streaming and non-streaming modes
14
- */
15
- import type { ProxyConfig } from '../types.js';
16
- export interface ProxyEnv {
17
- anthropicApiKey?: string;
18
- openaiApiKey?: string;
19
- geminiApiKey?: string;
20
- gatewayUrl?: string;
21
- gatewayKey?: string;
22
- }
23
- interface HttpRequest {
24
- method: string;
25
- url: string;
26
- headers: Record<string, string>;
27
- body?: unknown;
28
- json(): Promise<unknown>;
29
- }
30
- interface HttpResponse {
31
- status(code: number): HttpResponse;
32
- json(data: unknown): void;
33
- setHeader(key: string, value: string): void;
34
- write(data: string): void;
35
- end(): void;
36
- flushHeaders?(): void;
37
- }
38
- export declare function createProxyHandler(config: ProxyConfig | undefined, env: ProxyEnv): (req: HttpRequest, res: HttpResponse) => Promise<boolean>;
39
- export {};
@@ -1,4 +0,0 @@
1
- export * from './anthropic-adapter.js';
2
- export * from './handler.js';
3
- export * from './schema-cleaner.js';
4
- export * from './thought-cache.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Gemini Tool Schema Cleaner
3
- *
4
- * Gemini doesn't support certain JSON Schema fields that Anthropic tools use.
5
- * This recursively cleans schemas for compatibility.
6
- */
7
- /**
8
- * Recursively clean a JSON Schema for Gemini compatibility.
9
- * Removes unsupported fields and string formats.
10
- */
11
- export declare function cleanGeminiSchema(schema: unknown): unknown;