@chronicle.app/claude-code 0.3.0 → 0.5.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.
@@ -1,4 +1,4 @@
1
- import { Extractor, Record } from '@chronicle.app/etl';
1
+ import { Extractor, Record, type Survey, type SurveyOptions } from '@chronicle.app/etl';
2
2
  import { z } from 'zod';
3
3
  import ClaudeCodeTransformer from './ClaudeCodeTransformer.js';
4
4
  declare const ASSISTANT_MODES: readonly ["full", "terse", "off"];
@@ -87,6 +87,11 @@ export declare class ClaudeCodeExtractor extends Extractor<typeof ClaudeCodeExtr
87
87
  private readLocalAccount;
88
88
  private sessionFilesIn;
89
89
  extract(): AsyncGenerator<Record>;
90
+ /**
91
+ * The messages a run reads, when, and in how many sessions, from reading
92
+ * every transcript: nothing else in them says how many messages they hold.
93
+ */
94
+ survey(options?: SurveyOptions): Promise<Survey>;
90
95
  /** Apply the assistant and tools flags to a parsed session, in file order. */
91
96
  private messagesOf;
92
97
  /** The responses of a turn whose text becomes a Message. */
@@ -2,7 +2,7 @@ import { createReadStream, promises as fs } from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import readline from 'node:readline';
5
- import { Extractor } from '@chronicle.app/etl';
5
+ import { Extractor, countMonth } from '@chronicle.app/etl';
6
6
  import { z } from 'zod';
7
7
  import ClaudeCodeTransformer from './ClaudeCodeTransformer.js';
8
8
  const ASSISTANT_MODES = ['full', 'terse', 'off'];
@@ -131,6 +131,44 @@ export class ClaudeCodeExtractor extends Extractor {
131
131
  }
132
132
  }
133
133
  }
134
+ /**
135
+ * The messages a run reads, when, and in how many sessions, from reading
136
+ * every transcript: nothing else in them says how many messages they hold.
137
+ */
138
+ async survey(options = {}) {
139
+ // Every message in range, whatever the run's limit.
140
+ const all = new ClaudeCodeExtractor({ ...this.config, limit: undefined });
141
+ let count = 0;
142
+ let earliest;
143
+ let latest;
144
+ const sessions = new Set();
145
+ const byMonth = {};
146
+ await all.setup();
147
+ try {
148
+ for await (const { data, context } of all.extract()) {
149
+ count++;
150
+ sessions.add(context.sessionId);
151
+ const time = new Date(data.timestamp);
152
+ if (!earliest || time < earliest)
153
+ earliest = time;
154
+ if (!latest || time > latest)
155
+ latest = time;
156
+ if (options.byMonth)
157
+ countMonth(byMonth, time);
158
+ }
159
+ }
160
+ finally {
161
+ await all.teardown();
162
+ }
163
+ return {
164
+ messages: {
165
+ count,
166
+ ...(earliest && { earliest, latest }),
167
+ measures: [{ key: 'sessions', label: 'sessions', value: sessions.size }],
168
+ ...(options.byMonth && { byMonth }),
169
+ },
170
+ };
171
+ }
134
172
  /** Apply the assistant and tools flags to a parsed session, in file order. */
135
173
  *messagesOf(session, assistant, tools) {
136
174
  for (const turn of session.turns) {
@@ -40,13 +40,13 @@ export default class ClaudeCodeTransformer extends ChronicleTransformer {
40
40
  return [
41
41
  {
42
42
  '@type': 'MessageAction',
43
- '@key': BY_SOURCE_ID,
43
+ // Keyed by the message it sent.
44
+ '@key': ['@type', 'source', 'result.sourceId'],
44
45
  source: SOURCE,
45
- sourceId: message.uuid,
46
46
  timestamp: new Date(message.timestamp),
47
47
  agent: author,
48
- ...(!human && { instrument: this.model(message.model) }),
49
- object: {
48
+ ...(!human && { instrument: [this.model(message.model)] }),
49
+ result: {
50
50
  '@type': 'Message',
51
51
  '@key': BY_SOURCE_ID,
52
52
  source: SOURCE,
@@ -94,7 +94,7 @@ export default class ClaudeCodeTransformer extends ChronicleTransformer {
94
94
  */
95
95
  model(id) {
96
96
  return {
97
- '@type': 'SoftwareApplication',
97
+ '@type': 'AIModel',
98
98
  '@key': BY_HANDLE,
99
99
  source: ANTHROPIC,
100
100
  handle: id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chronicle.app/claude-code",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -19,9 +19,9 @@
19
19
  "type": "module",
20
20
  "description": "Chronicle claude-code extraction plugin",
21
21
  "devDependencies": {
22
- "@chronicle.app/etl": "0.3.0",
23
- "@chronicle.app/schema": "0.3.0",
24
- "@chronicle.app/tsconfig": "0.3.0",
22
+ "@chronicle.app/etl": "0.5.0",
23
+ "@chronicle.app/schema": "0.5.0",
24
+ "@chronicle.app/tsconfig": "0.5.0",
25
25
  "@types/node": "^22.10.1",
26
26
  "typescript": "^5.7.2"
27
27
  },
@@ -61,7 +61,12 @@
61
61
  "recordTypes": [
62
62
  "messages"
63
63
  ],
64
- "default": true
64
+ "default": true,
65
+ "locations": [
66
+ {
67
+ "path": "~/.claude/projects"
68
+ }
69
+ ]
65
70
  }
66
71
  }
67
72
  }