@danforthh/aimprint-sync 1.0.1 → 1.0.2

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 (2) hide show
  1. package/dist/index.js +22 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -152,19 +152,24 @@ var REAL_PROJECTS_DIR = (() => {
152
152
  })();
153
153
  var MACHINE = import_node_os2.default.hostname();
154
154
  var BATCH_SIZE = 100;
155
- function estimateCost(model, input, output, cacheRead, cacheCreation) {
156
- const p = {
157
- "claude-fable-5": [10, 50, 1, 12.5],
158
- "claude-opus-4-8": [5, 25, 0.5, 6.25],
159
- "claude-opus-4-7": [5, 25, 0.5, 6.25],
160
- "claude-opus-4-6": [5, 25, 0.5, 6.25],
161
- "claude-opus-4-5": [5, 25, 0.5, 6.25],
162
- "claude-sonnet-4-6": [3, 15, 0.3, 3.75],
163
- "claude-sonnet-4-5": [3, 15, 0.3, 3.75],
164
- "claude-haiku-4-5": [1, 5, 0.1, 1.25]
165
- };
166
- const [pi, po, pr, pc] = p[model] ?? [3, 15, 0.3, 3.75];
167
- return (input * pi + output * po + cacheRead * pr + cacheCreation * pc) / 1e6;
155
+ function detectLineSepSize(filePath) {
156
+ const buf = Buffer.alloc(1024);
157
+ let fd;
158
+ try {
159
+ fd = import_node_fs2.default.openSync(filePath, "r");
160
+ const n = import_node_fs2.default.readSync(fd, buf, 0, 1024, 0);
161
+ for (let i = 0; i < n - 1; i++) {
162
+ if (buf[i] === 13 && buf[i + 1] === 10) return 2;
163
+ }
164
+ return 1;
165
+ } catch {
166
+ return 1;
167
+ } finally {
168
+ if (fd !== void 0) try {
169
+ import_node_fs2.default.closeSync(fd);
170
+ } catch {
171
+ }
172
+ }
168
173
  }
169
174
  var TICKET_RE = /\b(PROTOP-\d+|PORTV4-\d+|NODE20-\d+)\b/i;
170
175
  function extractTicket(branch) {
@@ -175,6 +180,7 @@ function extractTicket(branch) {
175
180
  async function parseFile(filePath, offset) {
176
181
  const stat = import_node_fs2.default.statSync(filePath);
177
182
  if (stat.size <= offset) return { records: /* @__PURE__ */ new Map(), sessions: /* @__PURE__ */ new Map(), newOffset: offset };
183
+ const sepSize = detectLineSepSize(filePath);
178
184
  const fd = import_node_fs2.default.openSync(filePath, "r");
179
185
  const stream = import_node_fs2.default.createReadStream(filePath, { start: offset, fd, autoClose: true });
180
186
  const rl = import_node_readline.default.createInterface({ input: stream, crlfDelay: Infinity });
@@ -183,7 +189,7 @@ async function parseFile(filePath, offset) {
183
189
  let newOffset = offset;
184
190
  const lastUserMessage = /* @__PURE__ */ new Map();
185
191
  for await (const line of rl) {
186
- newOffset += Buffer.byteLength(line + "\n");
192
+ newOffset += Buffer.byteLength(line) + sepSize;
187
193
  if (!line.trim()) continue;
188
194
  let d;
189
195
  try {
@@ -283,7 +289,8 @@ async function parseFile(filePath, offset) {
283
289
  cache_read: cacheR,
284
290
  cache_creation: cacheC,
285
291
  is_sidechain: d.isSidechain ? 1 : 0,
286
- cost_usd: estimateCost(sess.model, input, output, cacheR, cacheC),
292
+ cost_usd: 0,
293
+ // worker recomputes server-side from its own pricing table
287
294
  request_category: reqCategory
288
295
  });
289
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danforthh/aimprint-sync",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Sync Claude Code token logs to your Aimprint dashboard",
5
5
  "type": "commonjs",
6
6
  "bin": {