|
| 1 | +/** |
| 2 | + * Generate openclaw.plugin.json configSchema from LcmConfig type. |
| 3 | + * Run: npx tsx scripts/generate-manifest.ts |
| 4 | + */ |
| 5 | +import { readFileSync, writeFileSync } from "node:fs"; |
| 6 | +import { join } from "node:path"; |
| 7 | + |
| 8 | +// Config schema definitions - single source of truth |
| 9 | +// Keep in sync with src/db/config.ts LcmConfig type |
| 10 | +const CONFIG_SCHEMA_PROPERTIES: Record<string, unknown> = { |
| 11 | + enabled: { |
| 12 | + type: "boolean", |
| 13 | + description: "Enable or disable the plugin", |
| 14 | + }, |
| 15 | + contextThreshold: { |
| 16 | + type: "number", |
| 17 | + minimum: 0, |
| 18 | + maximum: 1, |
| 19 | + description: "Fraction of context window that triggers compaction (0.0–1.0)", |
| 20 | + }, |
| 21 | + incrementalMaxDepth: { |
| 22 | + type: "integer", |
| 23 | + minimum: -1, |
| 24 | + description: "How deep incremental compaction goes (0 = leaf only, -1 = unlimited)", |
| 25 | + }, |
| 26 | + freshTailCount: { |
| 27 | + type: "integer", |
| 28 | + minimum: 1, |
| 29 | + description: "Number of recent messages protected from compaction", |
| 30 | + }, |
| 31 | + leafMinFanout: { |
| 32 | + type: "integer", |
| 33 | + minimum: 2, |
| 34 | + }, |
| 35 | + condensedMinFanout: { |
| 36 | + type: "integer", |
| 37 | + minimum: 2, |
| 38 | + }, |
| 39 | + condensedMinFanoutHard: { |
| 40 | + type: "integer", |
| 41 | + minimum: 2, |
| 42 | + }, |
| 43 | + dbPath: { |
| 44 | + type: "string", |
| 45 | + description: "Path to LCM SQLite database (default: ~/.openclaw/lcm.db)", |
| 46 | + }, |
| 47 | + largeFileThresholdTokens: { |
| 48 | + type: "integer", |
| 49 | + minimum: 1000, |
| 50 | + description: "Token threshold for treating files as 'large'", |
| 51 | + }, |
| 52 | + useTokenizer: { |
| 53 | + type: "boolean", |
| 54 | + description: "Use precise tokenizer service instead of chars/4 heuristic", |
| 55 | + }, |
| 56 | + proxy: { |
| 57 | + type: "string", |
| 58 | + description: "HTTP(S) proxy URL for tokenizer downloads from HuggingFace", |
| 59 | + }, |
| 60 | + timezone: { |
| 61 | + type: "string", |
| 62 | + description: "IANA timezone for timestamps in summaries", |
| 63 | + }, |
| 64 | + pruneHeartbeatOk: { |
| 65 | + type: "boolean", |
| 66 | + description: "Delete HEARTBEAT_OK turn cycles from LCM storage", |
| 67 | + }, |
| 68 | + autocompactDisabled: { |
| 69 | + type: "boolean", |
| 70 | + description: "Disable automatic compaction", |
| 71 | + }, |
| 72 | + largeFileSummaryProvider: { |
| 73 | + type: "string", |
| 74 | + description: "Provider override for large-file summarization", |
| 75 | + }, |
| 76 | + largeFileSummaryModel: { |
| 77 | + type: "string", |
| 78 | + description: "Model override for large-file summarization", |
| 79 | + }, |
| 80 | +}; |
| 81 | + |
| 82 | +// UI hints for the control panel |
| 83 | +const UI_HINTS: Record<string, { label: string; help: string }> = { |
| 84 | + contextThreshold: { |
| 85 | + label: "Context Threshold", |
| 86 | + help: "Fraction of context window that triggers compaction (0.0–1.0)", |
| 87 | + }, |
| 88 | + incrementalMaxDepth: { |
| 89 | + label: "Incremental Max Depth", |
| 90 | + help: "How deep incremental compaction goes (0 = leaf only, -1 = unlimited)", |
| 91 | + }, |
| 92 | + freshTailCount: { |
| 93 | + label: "Fresh Tail Count", |
| 94 | + help: "Number of recent messages protected from compaction", |
| 95 | + }, |
| 96 | + dbPath: { |
| 97 | + label: "Database Path", |
| 98 | + help: "Path to LCM SQLite database (default: ~/.openclaw/lcm.db)", |
| 99 | + }, |
| 100 | + useTokenizer: { |
| 101 | + label: "Use Precise Tokenizer", |
| 102 | + help: "Use HuggingFace tokenizer service instead of chars/4 heuristic", |
| 103 | + }, |
| 104 | + proxy: { |
| 105 | + label: "Proxy URL", |
| 106 | + help: "HTTP(S) proxy for tokenizer downloads from HuggingFace", |
| 107 | + }, |
| 108 | +}; |
| 109 | + |
| 110 | +function generateManifest() { |
| 111 | + const manifestPath = join(import.meta.dirname, "..", "openclaw.plugin.json"); |
| 112 | + |
| 113 | + // Read existing manifest |
| 114 | + let manifest: Record<string, unknown>; |
| 115 | + try { |
| 116 | + const raw = readFileSync(manifestPath, "utf8"); |
| 117 | + manifest = JSON.parse(raw); |
| 118 | + } catch { |
| 119 | + manifest = {}; |
| 120 | + } |
| 121 | + |
| 122 | + // Update configSchema |
| 123 | + manifest.configSchema = { |
| 124 | + type: "object", |
| 125 | + additionalProperties: false, |
| 126 | + properties: CONFIG_SCHEMA_PROPERTIES, |
| 127 | + }; |
| 128 | + |
| 129 | + // Update uiHints |
| 130 | + manifest.uiHints = UI_HINTS; |
| 131 | + |
| 132 | + // Ensure basic fields exist |
| 133 | + if (!manifest.id) { |
| 134 | + manifest.id = "lossless-claw"; |
| 135 | + } |
| 136 | + |
| 137 | + // Write back |
| 138 | + writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8"); |
| 139 | + console.log("✓ Generated openclaw.plugin.json configSchema"); |
| 140 | + console.log(` Properties: ${Object.keys(CONFIG_SCHEMA_PROPERTIES).join(", ")}`); |
| 141 | +} |
| 142 | + |
| 143 | +generateManifest(); |
0 commit comments