@threadcrumbs/common 0.1.8 → 0.1.9

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.
@@ -16,6 +16,7 @@ import fs from 'node:fs'
16
16
  import os from 'node:os'
17
17
  import path from 'node:path'
18
18
  import { resolveHermesHome } from '../lib/hermes-home.mjs'
19
+ import { titleFromPrompt } from '../lib/telemetry-fields.mjs'
19
20
 
20
21
  export { resolveHermesHome } from '../lib/hermes-home.mjs'
21
22
 
@@ -78,7 +79,7 @@ function toThread(row, pilot, chain, running) {
78
79
  return {
79
80
  id: `hermes:${pilot}:${chain.root.id}`,
80
81
  pilot,
81
- title: row.title || chain.root.title || 'Untitled thread',
82
+ title: titleFromPrompt(row.title || chain.root.title || '') || 'Untitled thread',
82
83
  preview: (chain.root.first_user || row.first_user || '').trim().slice(0, 280),
83
84
  project,
84
85
  projectPath,
@@ -254,12 +254,28 @@ function applyRecord(state, record) {
254
254
  state.firstBranch ||= state.gitBranch
255
255
  }
256
256
  if (state.detail && record.type === 'system' && ownRecord(state, record)) applySystem(state.detail, record, at || state.lastAt)
257
+ if (state.detail && record.type === 'attachment' && record.attachment?.type === 'hook_additional_context' && ownRecord(state, record)) {
258
+ applyDelivered(state.detail, record.attachment.content, at || state.lastAt)
259
+ }
257
260
  if (state.sizes && ownRecord(state, record)) applySent(state, record)
258
261
  if (!isTurn(state, record)) return
259
262
  if (record.type === 'user') applyUser(state, record, at || state.lastAt)
260
263
  else applyAssistant(state, record, at || state.lastAt)
261
264
  }
262
265
 
266
+ const DELIVERED = /(?:^|\n)([^\n]*):\n<<<threadgauge-([0-9a-f]{16})\n([\s\S]*?)\nthreadgauge-\2>>>/g
267
+ const FROM_USER = /^A message from the user\b/
268
+
269
+ function applyDelivered(detail, content, at) {
270
+ for (const block of Array.isArray(content) ? content : [content]) {
271
+ for (const m of text(block).matchAll(DELIVERED)) {
272
+ if (!FROM_USER.test(m[1].trim())) continue
273
+ const message = m[3].trim()
274
+ if (message) keepNewest(detail.prompts, { at, text: clipBlock(message, DETAIL_LIMITS.promptText), via: 'threadgauge' }, DETAIL_LIMITS.prompts)
275
+ }
276
+ }
277
+ }
278
+
263
279
  function applySystem(detail, record, at) {
264
280
  if (record.subtype === 'compact_boundary') {
265
281
  const meta = record.compactMetadata || {}