@cchistory/lite 0.7.0 → 0.8.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 (221) hide show
  1. package/INSTALL.md +1 -1
  2. package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
  3. package/apps/lite-cli/dist/agent-contract.js +29 -4
  4. package/apps/lite-cli/dist/agent-contract.js.map +1 -1
  5. package/apps/lite-cli/dist/index.d.ts.map +1 -1
  6. package/apps/lite-cli/dist/index.js +87 -48
  7. package/apps/lite-cli/dist/index.js.map +1 -1
  8. package/apps/lite-cli/dist/index.test.js +32 -0
  9. package/apps/lite-cli/dist/index.test.js.map +1 -1
  10. package/apps/lite-cli/dist/json-v2.d.ts.map +1 -1
  11. package/apps/lite-cli/dist/json-v2.js +8 -1
  12. package/apps/lite-cli/dist/json-v2.js.map +1 -1
  13. package/apps/lite-cli/dist/stats-command.d.ts +52 -0
  14. package/apps/lite-cli/dist/stats-command.d.ts.map +1 -0
  15. package/apps/lite-cli/dist/stats-command.js +322 -0
  16. package/apps/lite-cli/dist/stats-command.js.map +1 -0
  17. package/apps/lite-cli/dist/stats-command.test.d.ts +2 -0
  18. package/apps/lite-cli/dist/stats-command.test.d.ts.map +1 -0
  19. package/apps/lite-cli/dist/stats-command.test.js +154 -0
  20. package/apps/lite-cli/dist/stats-command.test.js.map +1 -0
  21. package/apps/lite-cli/dist/stats-render.d.ts +21 -0
  22. package/apps/lite-cli/dist/stats-render.d.ts.map +1 -0
  23. package/apps/lite-cli/dist/stats-render.js +207 -0
  24. package/apps/lite-cli/dist/stats-render.js.map +1 -0
  25. package/apps/lite-cli/dist/version.d.ts +1 -1
  26. package/apps/lite-cli/dist/version.js +1 -1
  27. package/apps/lite-tui/dist/index.d.ts.map +1 -1
  28. package/apps/lite-tui/dist/index.js +75 -4
  29. package/apps/lite-tui/dist/index.js.map +1 -1
  30. package/apps/lite-tui/dist/input.d.ts.map +1 -1
  31. package/apps/lite-tui/dist/input.js +124 -3
  32. package/apps/lite-tui/dist/input.js.map +1 -1
  33. package/apps/lite-tui/dist/model.d.ts +29 -4
  34. package/apps/lite-tui/dist/model.d.ts.map +1 -1
  35. package/apps/lite-tui/dist/model.js +90 -8
  36. package/apps/lite-tui/dist/model.js.map +1 -1
  37. package/apps/lite-tui/dist/render.d.ts +1 -1
  38. package/apps/lite-tui/dist/render.d.ts.map +1 -1
  39. package/apps/lite-tui/dist/render.js +21 -51
  40. package/apps/lite-tui/dist/render.js.map +1 -1
  41. package/apps/lite-tui/dist/state.d.ts +3 -1
  42. package/apps/lite-tui/dist/state.d.ts.map +1 -1
  43. package/apps/lite-tui/dist/state.js +31 -13
  44. package/apps/lite-tui/dist/state.js.map +1 -1
  45. package/apps/lite-tui/dist/state.test.js +118 -0
  46. package/apps/lite-tui/dist/state.test.js.map +1 -1
  47. package/apps/lite-tui/dist/stats-dashboard.test.d.ts +2 -0
  48. package/apps/lite-tui/dist/stats-dashboard.test.d.ts.map +1 -0
  49. package/apps/lite-tui/dist/stats-dashboard.test.js +191 -0
  50. package/apps/lite-tui/dist/stats-dashboard.test.js.map +1 -0
  51. package/apps/lite-tui/dist/stats-query.d.ts +11 -0
  52. package/apps/lite-tui/dist/stats-query.d.ts.map +1 -0
  53. package/apps/lite-tui/dist/stats-query.js +104 -0
  54. package/apps/lite-tui/dist/stats-query.js.map +1 -0
  55. package/apps/lite-tui/dist/stats-render.d.ts +9 -0
  56. package/apps/lite-tui/dist/stats-render.d.ts.map +1 -0
  57. package/apps/lite-tui/dist/stats-render.js +311 -0
  58. package/apps/lite-tui/dist/stats-render.js.map +1 -0
  59. package/apps/lite-tui/dist/stats-state.d.ts +121 -0
  60. package/apps/lite-tui/dist/stats-state.d.ts.map +1 -0
  61. package/apps/lite-tui/dist/stats-state.js +335 -0
  62. package/apps/lite-tui/dist/stats-state.js.map +1 -0
  63. package/apps/lite-tui/dist/version.d.ts +1 -1
  64. package/apps/lite-tui/dist/version.js +1 -1
  65. package/docs/guide/lite.md +23 -4
  66. package/docs/guide/pricing.example.json +38 -0
  67. package/node_modules/@cchistory/canonical/dist/index.d.ts +7 -2
  68. package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
  69. package/node_modules/@cchistory/canonical/dist/index.js +7 -2
  70. package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
  71. package/node_modules/@cchistory/canonical/dist/index.test.js +62 -1
  72. package/node_modules/@cchistory/canonical/dist/index.test.js.map +1 -1
  73. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.d.ts +11 -0
  74. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.d.ts.map +1 -0
  75. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.js +96 -0
  76. package/node_modules/@cchistory/canonical/dist/model-pricing-catalog.js.map +1 -0
  77. package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts +1 -1
  78. package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts.map +1 -1
  79. package/node_modules/@cchistory/canonical/dist/projection-audit.js +20 -0
  80. package/node_modules/@cchistory/canonical/dist/projection-audit.js.map +1 -1
  81. package/node_modules/@cchistory/canonical/dist/query.js +1 -1
  82. package/node_modules/@cchistory/canonical/dist/query.js.map +1 -1
  83. package/node_modules/@cchistory/canonical/dist/read-order.d.ts +2 -0
  84. package/node_modules/@cchistory/canonical/dist/read-order.d.ts.map +1 -1
  85. package/node_modules/@cchistory/canonical/dist/read-order.js +10 -0
  86. package/node_modules/@cchistory/canonical/dist/read-order.js.map +1 -1
  87. package/node_modules/@cchistory/canonical/dist/session-family.js +2 -2
  88. package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -1
  89. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -1
  90. package/node_modules/@cchistory/canonical/dist/session-interpreter.js +25 -1
  91. package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -1
  92. package/node_modules/@cchistory/canonical/dist/usage-breakdown.d.ts +37 -0
  93. package/node_modules/@cchistory/canonical/dist/usage-breakdown.d.ts.map +1 -0
  94. package/node_modules/@cchistory/canonical/dist/usage-breakdown.js +274 -0
  95. package/node_modules/@cchistory/canonical/dist/usage-breakdown.js.map +1 -0
  96. package/node_modules/@cchistory/canonical/dist/usage-pricing-config.d.ts +11 -0
  97. package/node_modules/@cchistory/canonical/dist/usage-pricing-config.d.ts.map +1 -0
  98. package/node_modules/@cchistory/canonical/dist/usage-pricing-config.js +297 -0
  99. package/node_modules/@cchistory/canonical/dist/usage-pricing-config.js.map +1 -0
  100. package/node_modules/@cchistory/canonical/dist/usage-pricing.d.ts +28 -0
  101. package/node_modules/@cchistory/canonical/dist/usage-pricing.d.ts.map +1 -0
  102. package/node_modules/@cchistory/canonical/dist/usage-pricing.js +267 -0
  103. package/node_modules/@cchistory/canonical/dist/usage-pricing.js.map +1 -0
  104. package/node_modules/@cchistory/canonical/dist/usage-pricing.test.d.ts +2 -0
  105. package/node_modules/@cchistory/canonical/dist/usage-pricing.test.d.ts.map +1 -0
  106. package/node_modules/@cchistory/canonical/dist/usage-pricing.test.js +365 -0
  107. package/node_modules/@cchistory/canonical/dist/usage-pricing.test.js.map +1 -0
  108. package/node_modules/@cchistory/canonical/dist/usage-time.d.ts +53 -0
  109. package/node_modules/@cchistory/canonical/dist/usage-time.d.ts.map +1 -0
  110. package/node_modules/@cchistory/canonical/dist/usage-time.js +323 -0
  111. package/node_modules/@cchistory/canonical/dist/usage-time.js.map +1 -0
  112. package/node_modules/@cchistory/canonical/dist/usage.d.ts +46 -31
  113. package/node_modules/@cchistory/canonical/dist/usage.d.ts.map +1 -1
  114. package/node_modules/@cchistory/canonical/dist/usage.js +187 -96
  115. package/node_modules/@cchistory/canonical/dist/usage.js.map +1 -1
  116. package/node_modules/@cchistory/canonical/package.json +1 -1
  117. package/node_modules/@cchistory/domain/dist/index.d.ts +22 -2
  118. package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
  119. package/node_modules/@cchistory/domain/dist/index.js +1 -0
  120. package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
  121. package/node_modules/@cchistory/domain/dist/usage-pricing.d.ts +145 -0
  122. package/node_modules/@cchistory/domain/dist/usage-pricing.d.ts.map +1 -0
  123. package/node_modules/@cchistory/domain/dist/usage-pricing.js +7 -0
  124. package/node_modules/@cchistory/domain/dist/usage-pricing.js.map +1 -0
  125. package/node_modules/@cchistory/domain/package.json +1 -1
  126. package/node_modules/@cchistory/live-runtime/dist/antigravity.test.d.ts +2 -0
  127. package/node_modules/@cchistory/live-runtime/dist/antigravity.test.d.ts.map +1 -0
  128. package/node_modules/@cchistory/live-runtime/dist/antigravity.test.js +104 -0
  129. package/node_modules/@cchistory/live-runtime/dist/antigravity.test.js.map +1 -0
  130. package/node_modules/@cchistory/live-runtime/dist/grok-bot.test.d.ts +2 -0
  131. package/node_modules/@cchistory/live-runtime/dist/grok-bot.test.d.ts.map +1 -0
  132. package/node_modules/@cchistory/live-runtime/dist/grok-bot.test.js +211 -0
  133. package/node_modules/@cchistory/live-runtime/dist/grok-bot.test.js.map +1 -0
  134. package/node_modules/@cchistory/live-runtime/dist/index.d.ts +13 -2
  135. package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
  136. package/node_modules/@cchistory/live-runtime/dist/index.js +61 -3
  137. package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
  138. package/node_modules/@cchistory/live-runtime/dist/index.test.js +37 -1
  139. package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
  140. package/node_modules/@cchistory/live-runtime/package.json +1 -1
  141. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.d.ts.map +1 -1
  142. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.js +10 -0
  143. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.js.map +1 -1
  144. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts +4 -0
  145. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts.map +1 -1
  146. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.js.map +1 -1
  147. package/node_modules/@cchistory/source-adapters/dist/core/discovery.d.ts.map +1 -1
  148. package/node_modules/@cchistory/source-adapters/dist/core/discovery.js +16 -2
  149. package/node_modules/@cchistory/source-adapters/dist/core/discovery.js.map +1 -1
  150. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
  151. package/node_modules/@cchistory/source-adapters/dist/core/parser.js +78 -3
  152. package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
  153. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
  154. package/node_modules/@cchistory/source-adapters/dist/core/probe.js +159 -35
  155. package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
  156. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js +2 -1
  157. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js.map +1 -1
  158. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
  159. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +11 -0
  160. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
  161. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +1 -1
  162. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -1
  163. package/node_modules/@cchistory/source-adapters/dist/core/user-text.d.ts +9 -7
  164. package/node_modules/@cchistory/source-adapters/dist/core/user-text.d.ts.map +1 -1
  165. package/node_modules/@cchistory/source-adapters/dist/core/user-text.js +34 -8
  166. package/node_modules/@cchistory/source-adapters/dist/core/user-text.js.map +1 -1
  167. package/node_modules/@cchistory/source-adapters/dist/core/utils.test.js +11 -0
  168. package/node_modules/@cchistory/source-adapters/dist/core/utils.test.js.map +1 -1
  169. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +2 -0
  170. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
  171. package/node_modules/@cchistory/source-adapters/dist/index.test.js +2 -0
  172. package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
  173. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.d.ts +1 -0
  174. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.d.ts.map +1 -1
  175. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.js +2 -0
  176. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.js.map +1 -1
  177. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/protobuf.d.ts +18 -0
  178. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/protobuf.d.ts.map +1 -0
  179. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/protobuf.js +105 -0
  180. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/protobuf.js.map +1 -0
  181. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.d.ts +8 -0
  182. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.d.ts.map +1 -0
  183. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.js +227 -0
  184. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/sqlite.js.map +1 -0
  185. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/usage.d.ts +6 -0
  186. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/usage.d.ts.map +1 -0
  187. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/usage.js +22 -0
  188. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/usage.js.map +1 -0
  189. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity-sqlite.test.d.ts +2 -0
  190. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity-sqlite.test.d.ts.map +1 -0
  191. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity-sqlite.test.js +145 -0
  192. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity-sqlite.test.js.map +1 -0
  193. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.d.ts +1 -0
  194. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.d.ts.map +1 -1
  195. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.js +14 -5
  196. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.js.map +1 -1
  197. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/runtime.d.ts +27 -0
  198. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/runtime.d.ts.map +1 -0
  199. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/runtime.js +262 -0
  200. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/runtime.js.map +1 -0
  201. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/title.d.ts +18 -0
  202. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/title.d.ts.map +1 -0
  203. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/title.js +101 -0
  204. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot/title.js.map +1 -0
  205. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.d.ts +17 -0
  206. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.d.ts.map +1 -0
  207. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.js +145 -0
  208. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.js.map +1 -0
  209. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.test.d.ts +2 -0
  210. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.test.d.ts.map +1 -0
  211. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.test.js +423 -0
  212. package/node_modules/@cchistory/source-adapters/dist/platforms/grok-bot.test.js.map +1 -0
  213. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.d.ts.map +1 -1
  214. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js +2 -0
  215. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js.map +1 -1
  216. package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts +1 -1
  217. package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts.map +1 -1
  218. package/node_modules/@cchistory/source-adapters/dist/platforms/types.js +2 -1
  219. package/node_modules/@cchistory/source-adapters/dist/platforms/types.js.map +1 -1
  220. package/node_modules/@cchistory/source-adapters/package.json +1 -1
  221. package/package.json +5 -5
@@ -0,0 +1,262 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { DatabaseSync } from "node:sqlite";
4
+ import { maxIso, minIso } from "@cchistory/domain";
5
+ import { readBudgetedSqliteRows } from "../../core/read-budget.js";
6
+ import { parseGrokBotAgentIdFromPath } from "../grok-bot.js";
7
+ import { extractGrokBotProfileUpdateName, isGrokBotHiddenPromptText, resolveGrokBotSessionTitle, } from "./title.js";
8
+ /**
9
+ * Read one Grok Bot sidebar-agent store.db into a single session seed.
10
+ * Prefer message rows; keep non-message kinds as opaque evidence records so
11
+ * unexpected shapes stay visible instead of being dropped.
12
+ */
13
+ export function extractGrokBotStoreSeeds(platform, filePath, helpers, targetSessionRefs = [], budget) {
14
+ const agentId = parseGrokBotAgentIdFromPath(filePath) ?? path.basename(path.dirname(filePath));
15
+ const sessionId = `sess:${platform}:${agentId}`;
16
+ if (targetSessionRefs.length > 0 &&
17
+ !targetSessionRefs.some((ref) => ref === sessionId || ref === agentId || ref.endsWith(`:${agentId}`))) {
18
+ return [];
19
+ }
20
+ const db = new DatabaseSync(filePath, { readOnly: true });
21
+ try {
22
+ db.exec("BEGIN");
23
+ if (!tableExists(db, "transcript_entries")) {
24
+ throw new Error("Grok Bot store is missing the transcript_entries table");
25
+ }
26
+ const rows = readBudgetedSqliteRows(db, "SELECT seq, id, entry FROM transcript_entries ORDER BY seq, id", ["seq", "id", "entry"], [], budget, `${filePath}:transcript_entries`);
27
+ const profile = readGrokBotProfile(path.dirname(filePath), helpers);
28
+ const records = [
29
+ {
30
+ pointer: "meta",
31
+ observedAt: helpers.nowIso(),
32
+ rawJson: JSON.stringify({
33
+ id: sessionId,
34
+ source_session_id: agentId,
35
+ grok_bot: {
36
+ agent_id: agentId,
37
+ profile_name: profile?.name,
38
+ description: profile?.description,
39
+ },
40
+ }),
41
+ },
42
+ ];
43
+ let createdAt;
44
+ let updatedAt;
45
+ let firstUserText;
46
+ let profileUpdateName;
47
+ for (const row of rows) {
48
+ const entryId = helpers.asString(row.id) ?? `seq:${helpers.asNumber(row.seq) ?? records.length}`;
49
+ const rawEntry = helpers.asString(row.entry);
50
+ const parsed = helpers.safeJsonParse(rawEntry);
51
+ if (!helpers.isObject(parsed)) {
52
+ records.push({
53
+ pointer: `entry:${entryId}`,
54
+ observedAt: helpers.nowIso(),
55
+ // Keep the original value so the ordinary parser retains unknown
56
+ // evidence and emits its normal JSON/non-object loss diagnostic.
57
+ rawJson: rawEntry ?? "null",
58
+ });
59
+ continue;
60
+ }
61
+ const kind = helpers.asString(parsed.kind) ?? "unknown";
62
+ const observedAt = helpers.epochMillisToIso(helpers.asNumber(parsed.timestampMs)) ?? helpers.nowIso();
63
+ createdAt = minIso(createdAt, observedAt) ?? observedAt;
64
+ updatedAt = maxIso(updatedAt, observedAt) ?? observedAt;
65
+ if (kind === "message") {
66
+ const role = helpers.asString(parsed.role);
67
+ const supportedRole = role === "user" || role === "assistant" || role === "system" ||
68
+ role === "developer" || role === "tool";
69
+ // An inferred actor must not make an unusable store supersede JSONL.
70
+ // Unknown content retains the complete native entry and a parse loss.
71
+ const content = supportedRole ? normalizeMessageContent(parsed.content, helpers)
72
+ : [{ type: "grok_bot_unsupported_role", raw: parsed }];
73
+ const plainText = contentText(content, helpers);
74
+ if (!profileUpdateName) {
75
+ profileUpdateName = extractGrokBotProfileUpdateName(plainText);
76
+ }
77
+ if (role === "user" && !firstUserText && plainText && !isGrokBotHiddenPromptText(plainText)) {
78
+ firstUserText = plainText;
79
+ }
80
+ records.push({
81
+ pointer: `message:${entryId}`,
82
+ observedAt,
83
+ rawJson: JSON.stringify({
84
+ id: entryId,
85
+ role: supportedRole ? role : "system",
86
+ timestamp: observedAt,
87
+ content: content.length > 0 ? content : [{ type: "grok_bot_empty_message", raw: parsed }],
88
+ grok_bot: {
89
+ kind,
90
+ seq: helpers.asNumber(row.seq),
91
+ from_agent: parsed.fromAgent,
92
+ to_agent: parsed.toAgent,
93
+ },
94
+ }),
95
+ });
96
+ continue;
97
+ }
98
+ // Preserve non-message kinds as evidence without inventing user turns.
99
+ const opaqueText = summarizeOpaqueEntry(kind, parsed, helpers);
100
+ if (!profileUpdateName) {
101
+ profileUpdateName = extractGrokBotProfileUpdateName(opaqueText);
102
+ }
103
+ records.push({
104
+ pointer: `entry:${entryId}`,
105
+ observedAt,
106
+ rawJson: JSON.stringify({
107
+ id: entryId,
108
+ role: "system",
109
+ timestamp: observedAt,
110
+ content: ["event", "send-message", "user-attachment"].includes(kind) ? [
111
+ {
112
+ type: "text",
113
+ text: opaqueText,
114
+ synthetic: true,
115
+ },
116
+ ] : [{ type: "grok_bot_unknown_entry", raw: parsed }],
117
+ grok_bot: {
118
+ kind,
119
+ seq: helpers.asNumber(row.seq),
120
+ raw: parsed,
121
+ },
122
+ }),
123
+ });
124
+ }
125
+ if (records.length === 1) {
126
+ return [];
127
+ }
128
+ const title = resolveGrokBotSessionTitle({
129
+ agentId,
130
+ profileName: profile?.name,
131
+ profileTitle: profile?.title,
132
+ profileUpdateName,
133
+ firstUserText,
134
+ truncate: helpers.truncate,
135
+ });
136
+ if (records[0]) {
137
+ const meta = helpers.safeJsonParse(records[0].rawJson);
138
+ if (helpers.isObject(meta)) {
139
+ records[0] = {
140
+ ...records[0],
141
+ observedAt: createdAt ?? records[0].observedAt,
142
+ rawJson: JSON.stringify({ ...meta, title }),
143
+ };
144
+ }
145
+ else {
146
+ records[0] = {
147
+ ...records[0],
148
+ observedAt: createdAt ?? records[0].observedAt,
149
+ };
150
+ }
151
+ }
152
+ return [
153
+ {
154
+ sessionId,
155
+ title,
156
+ createdAt,
157
+ updatedAt: updatedAt ?? createdAt,
158
+ records,
159
+ },
160
+ ];
161
+ }
162
+ finally {
163
+ db.close();
164
+ }
165
+ }
166
+ export function readGrokBotProfileFromAgentDir(agentDir, helpers) {
167
+ return readGrokBotProfile(agentDir, helpers);
168
+ }
169
+ export function resolveGrokBotProfilePathFromSourceFile(filePath) {
170
+ const normalized = filePath.replace(/\\/gu, "/");
171
+ const storeMatch = normalized.match(/^(.*)\/agents\/([^/]+)\/store\.db$/u);
172
+ if (storeMatch?.[1] && storeMatch[2]) {
173
+ return path.join(storeMatch[1], "agents", storeMatch[2], "profile.json");
174
+ }
175
+ const transcriptMatch = normalized.match(/^(.*)\/agent-transcripts\/([^/]+)\/[^/]+\.jsonl$/u);
176
+ if (transcriptMatch?.[1] && transcriptMatch[2]) {
177
+ return path.join(transcriptMatch[1], "agents", transcriptMatch[2], "profile.json");
178
+ }
179
+ return undefined;
180
+ }
181
+ export function loadGrokBotProfileTitleForSourceFile(filePath, helpers, agentId) {
182
+ const profilePath = resolveGrokBotProfilePathFromSourceFile(filePath);
183
+ if (!profilePath || !existsSync(profilePath)) {
184
+ return undefined;
185
+ }
186
+ const profile = readGrokBotProfile(path.dirname(profilePath), helpers);
187
+ if (!profile?.name?.trim() && !profile?.title?.trim()) {
188
+ return undefined;
189
+ }
190
+ return resolveGrokBotSessionTitle({
191
+ agentId,
192
+ profileName: profile?.name,
193
+ profileTitle: profile?.title,
194
+ truncate: helpers.truncate,
195
+ });
196
+ }
197
+ function normalizeMessageContent(content, helpers) {
198
+ if (typeof content === "string" && content.trim()) {
199
+ return [{ type: "text", text: content }];
200
+ }
201
+ if (Array.isArray(content)) {
202
+ return content.map((entry) => helpers.isObject(entry)
203
+ ? entry
204
+ : typeof entry === "string" && entry.trim()
205
+ ? { type: "text", text: entry }
206
+ : { type: "grok_bot_unsupported_content", raw: entry });
207
+ }
208
+ if (helpers.isObject(content)) {
209
+ const text = helpers.asString(content.text) ?? helpers.asString(content.content);
210
+ if (text?.trim()) {
211
+ return [{ type: "text", text }];
212
+ }
213
+ return [content];
214
+ }
215
+ return [];
216
+ }
217
+ function contentText(content, helpers) {
218
+ return content
219
+ .map((entry) => helpers.asString(entry.text) ?? helpers.asString(entry.content) ?? "")
220
+ .filter(Boolean)
221
+ .join("\n")
222
+ .trim();
223
+ }
224
+ function summarizeOpaqueEntry(kind, parsed, helpers) {
225
+ if (kind === "send-message") {
226
+ const message = helpers.isObject(parsed.message) ? parsed.message : undefined;
227
+ const text = helpers.asString(message?.content) ?? helpers.asString(parsed.content);
228
+ return text?.trim() ? `[send-message] ${helpers.truncate(text, 240)}` : "[send-message]";
229
+ }
230
+ if (kind === "user-attachment") {
231
+ const name = helpers.asString(parsed.file_name) ?? helpers.asString(parsed.file_path) ?? "attachment";
232
+ return `[user-attachment] ${name}`;
233
+ }
234
+ if (kind === "event") {
235
+ const event = helpers.isObject(parsed.event) ? parsed.event : undefined;
236
+ const type = helpers.asString(event?.type) ?? "event";
237
+ return `[event] ${type}`;
238
+ }
239
+ return `[${kind}]`;
240
+ }
241
+ function readGrokBotProfile(agentDir, helpers) {
242
+ try {
243
+ const raw = readFileSync(path.join(agentDir, "profile.json"), "utf8");
244
+ const parsed = helpers.safeJsonParse(raw);
245
+ if (!helpers.isObject(parsed)) {
246
+ return undefined;
247
+ }
248
+ return {
249
+ name: helpers.asString(parsed.name),
250
+ title: helpers.asString(parsed.title),
251
+ description: helpers.asString(parsed.description),
252
+ };
253
+ }
254
+ catch {
255
+ return undefined;
256
+ }
257
+ }
258
+ function tableExists(db, tableName) {
259
+ const row = db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?").get(tableName);
260
+ return typeof row?.name === "string";
261
+ }
262
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/platforms/grok-bot/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,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AAM,CAAC,WAAW,CAAC;SAClD,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,EAAgB,EAAE,SAAiB;IACtD,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,kEAAkE,CAAC,CAAC,GAAG,CAAC,SAAS,CAE3F,CAAC;IACd,OAAO,OAAO,GAAG,EAAE,IAAI,KAAK,QAAQ,CAAC;AACvC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Title + hidden-prompt helpers for Grok Bot sidebar agents.
3
+ * Prefer profile.json name, then SAND_AGENT_PROFILE_UPDATE payload, then first
4
+ * real user text, then a short agent id. Never leave SAND_HIDDEN_PROMPT as title.
5
+ */
6
+ export declare function isGrokBotHiddenPromptText(text: string | undefined): boolean;
7
+ export declare function extractGrokBotProfileUpdateName(text: string | undefined): string | undefined;
8
+ export declare function cleanGrokBotUserTitleText(text: string | undefined): string | undefined;
9
+ export declare function shortGrokBotAgentLabel(agentId: string): string;
10
+ export declare function resolveGrokBotSessionTitle(options: {
11
+ agentId: string;
12
+ profileName?: string;
13
+ profileTitle?: string;
14
+ profileUpdateName?: string;
15
+ firstUserText?: string;
16
+ truncate: (value: string, length: number) => string;
17
+ }): string;
18
+ //# sourceMappingURL=title.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title.d.ts","sourceRoot":"","sources":["../../../src/platforms/grok-bot/title.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAa3E;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAY5F;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAuBtF;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI9D;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CACrD,GAAG,MAAM,CAkBT"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Title + hidden-prompt helpers for Grok Bot sidebar agents.
3
+ * Prefer profile.json name, then SAND_AGENT_PROFILE_UPDATE payload, then first
4
+ * real user text, then a short agent id. Never leave SAND_HIDDEN_PROMPT as title.
5
+ */
6
+ const SAND_HIDDEN_PREFIX = "[SAND_HIDDEN_PROMPT]";
7
+ const PROFILE_UPDATE_RE = /SAND_AGENT_PROFILE_UPDATE:v1:([A-Za-z0-9_-]+)/u;
8
+ const TURN_TAG_RE = /^\[t\d+[a-z]?\d*\]\s*/iu;
9
+ const TIMESTAMP_RE = /<timestamp>[\s\S]*?<\/timestamp>/giu;
10
+ const USER_QUERY_RE = /<user_query>\s*([\s\S]*?)<\/user_query>/iu;
11
+ export function isGrokBotHiddenPromptText(text) {
12
+ if (!text) {
13
+ return false;
14
+ }
15
+ const trimmed = text.replace(/\r\n/g, "\n").trim();
16
+ if (!trimmed) {
17
+ return false;
18
+ }
19
+ if (trimmed.startsWith(SAND_HIDDEN_PREFIX)) {
20
+ return true;
21
+ }
22
+ const query = trimmed.match(USER_QUERY_RE)?.[1]?.trim();
23
+ return Boolean(query?.startsWith(SAND_HIDDEN_PREFIX));
24
+ }
25
+ export function extractGrokBotProfileUpdateName(text) {
26
+ if (!text) {
27
+ return undefined;
28
+ }
29
+ const match = text.match(PROFILE_UPDATE_RE);
30
+ const token = match?.[1];
31
+ if (!token) {
32
+ return undefined;
33
+ }
34
+ const payload = decodeBase64JsonObject(token);
35
+ const name = typeof payload?.name === "string" ? payload.name.trim() : undefined;
36
+ return name || undefined;
37
+ }
38
+ export function cleanGrokBotUserTitleText(text) {
39
+ if (!text) {
40
+ return undefined;
41
+ }
42
+ let value = text.replace(/\r\n/g, "\n").trim();
43
+ if (!value || isGrokBotHiddenPromptText(value)) {
44
+ return undefined;
45
+ }
46
+ const query = value.match(USER_QUERY_RE)?.[1]?.trim();
47
+ if (query) {
48
+ value = query;
49
+ }
50
+ value = value
51
+ .replace(TIMESTAMP_RE, " ")
52
+ .replace(TURN_TAG_RE, "")
53
+ .replace(/\s+/gu, " ")
54
+ .trim();
55
+ if (!value || isGrokBotHiddenPromptText(value)) {
56
+ return undefined;
57
+ }
58
+ return value;
59
+ }
60
+ export function shortGrokBotAgentLabel(agentId) {
61
+ const compact = agentId.replace(/[^a-zA-Z0-9]/gu, "");
62
+ const short = (compact || agentId).slice(0, 8);
63
+ return short || "agent";
64
+ }
65
+ export function resolveGrokBotSessionTitle(options) {
66
+ const profileName = options.profileName?.trim();
67
+ if (profileName) {
68
+ return options.truncate(profileName, 72);
69
+ }
70
+ const profileTitle = options.profileTitle?.trim();
71
+ if (profileTitle) {
72
+ return options.truncate(profileTitle, 72);
73
+ }
74
+ const updateName = options.profileUpdateName?.trim();
75
+ if (updateName) {
76
+ return options.truncate(updateName, 72);
77
+ }
78
+ const cleaned = cleanGrokBotUserTitleText(options.firstUserText);
79
+ if (cleaned) {
80
+ return options.truncate(cleaned, 72);
81
+ }
82
+ return shortGrokBotAgentLabel(options.agentId);
83
+ }
84
+ function decodeBase64JsonObject(token) {
85
+ const pad = "=".repeat((4 - (token.length % 4)) % 4);
86
+ const padded = `${token}${pad}`;
87
+ for (const encoding of ["base64url", "base64"]) {
88
+ try {
89
+ const raw = Buffer.from(padded, encoding).toString("utf8");
90
+ const parsed = JSON.parse(raw);
91
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
92
+ return parsed;
93
+ }
94
+ }
95
+ catch {
96
+ // try next encoding
97
+ }
98
+ }
99
+ return undefined;
100
+ }
101
+ //# sourceMappingURL=title.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title.js","sourceRoot":"","sources":["../../../src/platforms/grok-bot/title.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,iBAAiB,GAAG,gDAAgD,CAAC;AAC3E,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAC9C,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAC3D,MAAM,aAAa,GAAG,2CAA2C,CAAC;AAElE,MAAM,UAAU,yBAAyB,CAAC,IAAwB;IAChE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IACxD,OAAO,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,IAAwB;IACtE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC,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AM,QAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAU,EAAE,CAAC;QACxD,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAY,CAAC;YAC1C,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACnE,OAAO,MAAiC,CAAC;YAC3C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB;QACtB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { PlatformAdapter } from "./types.js";
2
+ export declare function isGrokBotStorePath(filePath: string): boolean;
3
+ export declare function isGrokBotTranscriptPath(filePath: string): boolean;
4
+ export declare function isGrokBotConversationBlobsPath(filePath: string): boolean;
5
+ export declare function parseGrokBotAgentIdFromPath(filePath: string): string | undefined;
6
+ export declare function resolveGrokBotDataRoot(baseDir: string): string;
7
+ export declare function listGrokBotSourceRoots(baseDir: string): string[];
8
+ export declare function uniqueExistingPaths(candidates: readonly string[]): string[];
9
+ /**
10
+ * Companion evidence for identity + SQLite WAL. conversation-blobs.db is an
11
+ * opaque LLM payload cache (often tens of MB) not referenced by store message
12
+ * rows; listing it for full-byte capture caused memory pressure and empty
13
+ * parse diagnostics without improving projection. Keep store.db as truth.
14
+ */
15
+ export declare function listGrokBotCompanionEvidencePaths(_baseDir: string, filePath: string): string[];
16
+ export declare const grokBotAdapter: PlatformAdapter;
17
+ //# sourceMappingURL=grok-bot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grok-bot.d.ts","sourceRoot":"","sources":["../../src/platforms/grok-bot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAOlD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAM5D;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGjE;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAMxE;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAehF;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAS9D;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAUhE;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAY3E;AAYD;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAmB9F;AAED,eAAO,MAAM,cAAc,EAAE,eA0C5B,CAAC"}
@@ -0,0 +1,145 @@
1
+ import path from "node:path";
2
+ import { normalizePathSeparators } from "../core/path-utils.js";
3
+ const STORE_BASENAME = "store.db";
4
+ const BLOBS_BASENAME = "conversation-blobs.db";
5
+ const AGENTS_DIR = "agents";
6
+ const TRANSCRIPTS_DIR = "agent-transcripts";
7
+ export function isGrokBotStorePath(filePath) {
8
+ const normalized = normalizePathSeparators(filePath);
9
+ return (path.basename(normalized) === STORE_BASENAME &&
10
+ /\/agents\/[^/]+\/store\.db$/u.test(normalized));
11
+ }
12
+ export function isGrokBotTranscriptPath(filePath) {
13
+ const normalized = normalizePathSeparators(filePath);
14
+ return normalized.includes(`/${TRANSCRIPTS_DIR}/`) && normalized.endsWith(".jsonl");
15
+ }
16
+ export function isGrokBotConversationBlobsPath(filePath) {
17
+ const normalized = normalizePathSeparators(filePath);
18
+ return (path.basename(normalized) === BLOBS_BASENAME &&
19
+ /\/agents\/[^/]+\/conversation-blobs\.db$/u.test(normalized));
20
+ }
21
+ export function parseGrokBotAgentIdFromPath(filePath) {
22
+ const normalized = normalizePathSeparators(filePath);
23
+ const storeMatch = normalized.match(/\/agents\/([^/]+)\/store\.db$/u);
24
+ if (storeMatch?.[1]) {
25
+ return storeMatch[1];
26
+ }
27
+ const blobsMatch = normalized.match(/\/agents\/([^/]+)\/conversation-blobs\.db$/u);
28
+ if (blobsMatch?.[1]) {
29
+ return blobsMatch[1];
30
+ }
31
+ const transcriptMatch = normalized.match(/\/agent-transcripts\/([^/]+)\/[^/]+\.jsonl$/u);
32
+ if (transcriptMatch?.[1]) {
33
+ return transcriptMatch[1];
34
+ }
35
+ return undefined;
36
+ }
37
+ export function resolveGrokBotDataRoot(baseDir) {
38
+ const normalized = normalizePathSeparators(baseDir);
39
+ if (normalized.endsWith(`/${AGENTS_DIR}`) || path.basename(normalized) === AGENTS_DIR) {
40
+ return path.dirname(path.normalize(baseDir));
41
+ }
42
+ if (normalized.endsWith(`/${TRANSCRIPTS_DIR}`) || path.basename(normalized) === TRANSCRIPTS_DIR) {
43
+ return path.dirname(path.normalize(baseDir));
44
+ }
45
+ return path.normalize(baseDir);
46
+ }
47
+ export function listGrokBotSourceRoots(baseDir) {
48
+ const normalized = normalizePathSeparators(baseDir);
49
+ if (normalized.endsWith(`/${AGENTS_DIR}`) || path.basename(normalized) === AGENTS_DIR) {
50
+ return [path.normalize(baseDir)];
51
+ }
52
+ if (normalized.endsWith(`/${TRANSCRIPTS_DIR}`) || path.basename(normalized) === TRANSCRIPTS_DIR) {
53
+ return [path.normalize(baseDir)];
54
+ }
55
+ const root = path.normalize(baseDir);
56
+ return [path.join(root, AGENTS_DIR), path.join(root, TRANSCRIPTS_DIR)];
57
+ }
58
+ export function uniqueExistingPaths(candidates) {
59
+ const seen = new Set();
60
+ const unique = [];
61
+ for (const candidate of candidates) {
62
+ const normalized = path.normalize(candidate);
63
+ if (seen.has(normalized)) {
64
+ continue;
65
+ }
66
+ seen.add(normalized);
67
+ unique.push(normalized);
68
+ }
69
+ return unique;
70
+ }
71
+ function resolveGrokBotDataRootFromTranscript(filePath) {
72
+ const normalized = normalizePathSeparators(filePath);
73
+ const marker = `/${TRANSCRIPTS_DIR}/`;
74
+ const index = normalized.lastIndexOf(marker);
75
+ if (index < 0) {
76
+ return undefined;
77
+ }
78
+ return normalized.slice(0, index);
79
+ }
80
+ /**
81
+ * Companion evidence for identity + SQLite WAL. conversation-blobs.db is an
82
+ * opaque LLM payload cache (often tens of MB) not referenced by store message
83
+ * rows; listing it for full-byte capture caused memory pressure and empty
84
+ * parse diagnostics without improving projection. Keep store.db as truth.
85
+ */
86
+ export function listGrokBotCompanionEvidencePaths(_baseDir, filePath) {
87
+ const companions = [];
88
+ if (isGrokBotStorePath(filePath)) {
89
+ const agentDir = path.dirname(filePath);
90
+ companions.push(path.join(agentDir, "profile.json"), `${filePath}-wal`, `${filePath}-shm`);
91
+ }
92
+ if (isGrokBotTranscriptPath(filePath)) {
93
+ const agentId = parseGrokBotAgentIdFromPath(filePath);
94
+ const dataRoot = resolveGrokBotDataRootFromTranscript(filePath);
95
+ if (agentId && dataRoot) {
96
+ const agentDir = path.join(dataRoot, AGENTS_DIR, agentId);
97
+ companions.push(path.join(agentDir, "profile.json"));
98
+ }
99
+ }
100
+ return companions;
101
+ }
102
+ export const grokBotAdapter = {
103
+ platform: "grok_bot",
104
+ supportTier: "experimental",
105
+ sessionTargeting: "hybrid",
106
+ projectionBoundary: "source",
107
+ getDefaultBaseDirCandidates: (options) => {
108
+ const homeDir = options.homeDir ?? "";
109
+ const envRoots = [
110
+ process.env.GROK_BOT_HOME,
111
+ process.env.AGENT_DATA,
112
+ process.env.SAND_DATA,
113
+ ]
114
+ .map((value) => value?.trim())
115
+ .filter((value) => Boolean(value))
116
+ .map((value) => path.normalize(value));
117
+ return uniqueExistingPaths([
118
+ ...envRoots,
119
+ path.join(homeDir, "agent-data"),
120
+ path.join(homeDir, "sand-data"),
121
+ path.join(homeDir, ".agent-data"),
122
+ path.join(homeDir, ".sand-data"),
123
+ ]);
124
+ },
125
+ getSourceRoots: (baseDir) => listGrokBotSourceRoots(baseDir),
126
+ matchesSourceFile: (filePath) => {
127
+ if (isGrokBotStorePath(filePath)) {
128
+ return true;
129
+ }
130
+ // Inventory stays path-only. The probe selects a preferred store only after
131
+ // its budgeted parse succeeds, using attempt-local evidence rather than mtime.
132
+ return isGrokBotTranscriptPath(filePath);
133
+ },
134
+ getSourceFilePriority: (filePath) => {
135
+ if (isGrokBotStorePath(filePath)) {
136
+ return 0;
137
+ }
138
+ if (isGrokBotTranscriptPath(filePath)) {
139
+ return 1;
140
+ }
141
+ return 2;
142
+ },
143
+ getCompanionEvidencePaths: (baseDir, filePath) => listGrokBotCompanionEvidencePaths(baseDir, filePath),
144
+ };
145
+ //# sourceMappingURL=grok-bot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grok-bot.js","sourceRoot":"","sources":["../../src/platforms/grok-bot.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAGhE,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAC/C,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAE5C,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,MAAM,UAAU,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IACrD,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,cAAc;QAC5C,8BAA8B,CAAC,IAAI,CAAC,UAAU,CAAC,CAChD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,MAAM,UAAU,GAAG,uBAAuB,CAAC,QAAQ,CAAC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,CAAC;IACL,CAAC;IACD,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC;IAC5D,iBAAiB,EAAE,CAAC,QAAQ,EAAE,EAAE;QAC9B,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,4EAA4E;QAC5E,+EAA+E;QAC/E,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IACD,qBAAqB,EAAE,CAAC,QAAQ,EAAE,EAAE;QAClC,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,yBAAyB,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,iCAAiC,CAAC,OAAO,EAAE,QAAQ,CAAC;CACvG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=grok-bot.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grok-bot.test.d.ts","sourceRoot":"","sources":["../../src/platforms/grok-bot.test.ts"],"names":[],"mappings":""}