modelstat 0.2.0 → 0.3.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.
package/dist/cli.mjs CHANGED
@@ -137,6 +137,62 @@ var init_git = __esm({
137
137
  }
138
138
  });
139
139
 
140
+ // ../../packages/parsers/src/git-outcome.ts
141
+ import { execFile as execFile2 } from "child_process";
142
+ import { promisify as promisify2 } from "util";
143
+ function parseGitLog(stdout) {
144
+ const out = [];
145
+ for (const record of stdout.split(RS)) {
146
+ const rec = record.trim();
147
+ if (!rec) continue;
148
+ const [sha = "", committedAt = "", subject = "", ...rest] = rec.split(FS);
149
+ out.push({ sha, committedAt, subject, body: rest.join(FS) });
150
+ }
151
+ return out;
152
+ }
153
+ function findMergeCommitForPr(commits, prNumber) {
154
+ const re = new RegExp(`(^|\\D)#${prNumber}(\\D|$)`);
155
+ return commits.find((c) => re.test(c.subject)) ?? null;
156
+ }
157
+ function isReverted(commits, mergeSha) {
158
+ if (!mergeSha) return false;
159
+ const short = mergeSha.slice(0, 7);
160
+ return commits.some(
161
+ (c) => c.body.includes(`This reverts commit ${mergeSha}`) || c.body.includes(`This reverts commit ${short}`)
162
+ );
163
+ }
164
+ function outcomeFromCommits(commits, prNumber) {
165
+ const merge = findMergeCommitForPr(commits, prNumber);
166
+ if (!merge) return { merged: false, merged_at: null, reverted: false };
167
+ return {
168
+ merged: true,
169
+ merged_at: merge.committedAt || null,
170
+ reverted: isReverted(commits, merge.sha)
171
+ };
172
+ }
173
+ async function checkPullRequestOutcome(cwd, prNumber) {
174
+ try {
175
+ const { stdout } = await pexec2("git", ["log", "-n", "1000", `--format=${GIT_LOG_FORMAT}`], {
176
+ cwd,
177
+ timeout: 4e3,
178
+ maxBuffer: 16 * 1024 * 1024
179
+ });
180
+ return outcomeFromCommits(parseGitLog(stdout), prNumber);
181
+ } catch {
182
+ return null;
183
+ }
184
+ }
185
+ var pexec2, FS, RS, GIT_LOG_FORMAT;
186
+ var init_git_outcome = __esm({
187
+ "../../packages/parsers/src/git-outcome.ts"() {
188
+ "use strict";
189
+ pexec2 = promisify2(execFile2);
190
+ FS = "";
191
+ RS = "";
192
+ GIT_LOG_FORMAT = `%H${FS}%cI${FS}%s${FS}%b${RS}`;
193
+ }
194
+ });
195
+
140
196
  // ../../packages/core/src/billing.ts
141
197
  var MILLION, FREE_INCLUDED_TOKENS, TEAM_INCLUDED_PER_SEAT;
142
198
  var init_billing = __esm({
@@ -4540,7 +4596,7 @@ var init_redact_floor = __esm({
4540
4596
  pattern: /(?:sk|pk|rk)_test_[A-Za-z0-9]{24,}/g,
4541
4597
  replacement: "<REDACTED:stripe_test_key>"
4542
4598
  },
4543
- // Discord bot token (was daemon-sdk-only — the canonical drift example).
4599
+ // Discord bot token (was caught by only one redactor — the canonical drift example).
4544
4600
  {
4545
4601
  name: "discord_token",
4546
4602
  pattern: /[MN][A-Za-z\d]{23}\.[\w-]{6}\.[\w-]{27}/g,
@@ -4938,7 +4994,16 @@ var init_session_metadata = __esm({
4938
4994
  number: external_exports.number().int().positive(),
4939
4995
  url: external_exports.string().max(400).nullable().default(null),
4940
4996
  source: RefSource.default("content"),
4941
- confidence: external_exports.number().min(0).max(1).default(0.9)
4997
+ confidence: external_exports.number().min(0).max(1).default(0.9),
4998
+ // On-device verified-outcome signals — filled by the parsers' local git-check
4999
+ // (`checkPullRequestOutcome`) when the PR's repo is on disk. `null` = unknown;
5000
+ // the server's CPVO engine classifies verified/failed from these. Mirrors
5001
+ // core's `PullRequestRef` field-for-field.
5002
+ merged: external_exports.boolean().nullable().optional(),
5003
+ merged_at: external_exports.string().max(40).nullable().optional(),
5004
+ reverted: external_exports.boolean().nullable().optional(),
5005
+ hotfixed: external_exports.boolean().nullable().optional(),
5006
+ reopened: external_exports.boolean().nullable().optional()
4942
5007
  });
4943
5008
  CommitRef = external_exports.object({
4944
5009
  /** 7–40 char hex SHA. */
@@ -8367,11 +8432,11 @@ var init_cursor = __esm({
8367
8432
  });
8368
8433
 
8369
8434
  // ../../packages/parsers/src/discovery/index.ts
8370
- import { execFile as execFile2, execSync } from "child_process";
8435
+ import { execFile as execFile3, execSync } from "child_process";
8371
8436
  import { existsSync as existsSync3, statSync } from "fs";
8372
8437
  import { homedir, platform } from "os";
8373
8438
  import { join as join2, resolve as resolve2 } from "path";
8374
- import { promisify as promisify2 } from "util";
8439
+ import { promisify as promisify3 } from "util";
8375
8440
  async function discover(options = {}) {
8376
8441
  const os2 = platform() === "darwin" ? "macos" : "linux";
8377
8442
  const skip = new Set(options.skip ?? []);
@@ -8496,7 +8561,7 @@ function classifyInstallMethod(binPath, os2) {
8496
8561
  }
8497
8562
  async function safeVersionProbe(binPath) {
8498
8563
  try {
8499
- const { stdout } = await pexec2(binPath, ["--version"], { timeout: 1500 });
8564
+ const { stdout } = await pexec3(binPath, ["--version"], { timeout: 1500 });
8500
8565
  return stdout.trim().split(/\s+/).pop() ?? null;
8501
8566
  } catch {
8502
8567
  return null;
@@ -8701,11 +8766,11 @@ function dedupeIdentities(list) {
8701
8766
  }
8702
8767
  return Array.from(seen.values());
8703
8768
  }
8704
- var pexec2, H, SOURCES;
8769
+ var pexec3, H, SOURCES;
8705
8770
  var init_discovery = __esm({
8706
8771
  "../../packages/parsers/src/discovery/index.ts"() {
8707
8772
  "use strict";
8708
- pexec2 = promisify2(execFile2);
8773
+ pexec3 = promisify3(execFile3);
8709
8774
  H = (p) => p.startsWith("~") ? p.replace("~", homedir()) : p;
8710
8775
  SOURCES = [
8711
8776
  {
@@ -8797,6 +8862,7 @@ var init_src2 = __esm({
8797
8862
  "use strict";
8798
8863
  init_types();
8799
8864
  init_git();
8865
+ init_git_outcome();
8800
8866
  init_tool_action();
8801
8867
  init_claude_code();
8802
8868
  init_codex();
@@ -21668,7 +21734,7 @@ var require_mock_interceptor = __commonJS({
21668
21734
  var require_mock_client = __commonJS({
21669
21735
  "../../node_modules/.pnpm/undici@7.25.0/node_modules/undici/lib/mock/mock-client.js"(exports, module) {
21670
21736
  "use strict";
21671
- var { promisify: promisify4 } = __require("util");
21737
+ var { promisify: promisify5 } = __require("util");
21672
21738
  var Client = require_client();
21673
21739
  var { buildMockDispatch } = require_mock_utils();
21674
21740
  var {
@@ -21716,7 +21782,7 @@ var require_mock_client = __commonJS({
21716
21782
  this[kDispatches] = [];
21717
21783
  }
21718
21784
  async [kClose]() {
21719
- await promisify4(this[kOriginalClose])();
21785
+ await promisify5(this[kOriginalClose])();
21720
21786
  this[kConnected] = 0;
21721
21787
  this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
21722
21788
  }
@@ -21929,7 +21995,7 @@ var require_mock_call_history = __commonJS({
21929
21995
  var require_mock_pool = __commonJS({
21930
21996
  "../../node_modules/.pnpm/undici@7.25.0/node_modules/undici/lib/mock/mock-pool.js"(exports, module) {
21931
21997
  "use strict";
21932
- var { promisify: promisify4 } = __require("util");
21998
+ var { promisify: promisify5 } = __require("util");
21933
21999
  var Pool = require_pool();
21934
22000
  var { buildMockDispatch } = require_mock_utils();
21935
22001
  var {
@@ -21977,7 +22043,7 @@ var require_mock_pool = __commonJS({
21977
22043
  this[kDispatches] = [];
21978
22044
  }
21979
22045
  async [kClose]() {
21980
- await promisify4(this[kOriginalClose])();
22046
+ await promisify5(this[kOriginalClose])();
21981
22047
  this[kConnected] = 0;
21982
22048
  this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
21983
22049
  }
@@ -34612,25 +34678,25 @@ var init_constants2 = __esm({
34612
34678
 
34613
34679
  // ../../node_modules/.pnpm/stubborn-fs@2.0.0/node_modules/stubborn-fs/dist/index.js
34614
34680
  import fs from "fs";
34615
- import { promisify as promisify3 } from "util";
34616
- var FS, dist_default;
34681
+ import { promisify as promisify4 } from "util";
34682
+ var FS2, dist_default;
34617
34683
  var init_dist2 = __esm({
34618
34684
  "../../node_modules/.pnpm/stubborn-fs@2.0.0/node_modules/stubborn-fs/dist/index.js"() {
34619
34685
  "use strict";
34620
34686
  init_dist();
34621
34687
  init_dist();
34622
34688
  init_constants2();
34623
- FS = {
34689
+ FS2 = {
34624
34690
  attempt: {
34625
34691
  /* ASYNC */
34626
- chmod: attemptify_async_default(promisify3(fs.chmod), ATTEMPTIFY_CHANGE_ERROR_OPTIONS),
34627
- chown: attemptify_async_default(promisify3(fs.chown), ATTEMPTIFY_CHANGE_ERROR_OPTIONS),
34628
- close: attemptify_async_default(promisify3(fs.close), ATTEMPTIFY_NOOP_OPTIONS),
34629
- fsync: attemptify_async_default(promisify3(fs.fsync), ATTEMPTIFY_NOOP_OPTIONS),
34630
- mkdir: attemptify_async_default(promisify3(fs.mkdir), ATTEMPTIFY_NOOP_OPTIONS),
34631
- realpath: attemptify_async_default(promisify3(fs.realpath), ATTEMPTIFY_NOOP_OPTIONS),
34632
- stat: attemptify_async_default(promisify3(fs.stat), ATTEMPTIFY_NOOP_OPTIONS),
34633
- unlink: attemptify_async_default(promisify3(fs.unlink), ATTEMPTIFY_NOOP_OPTIONS),
34692
+ chmod: attemptify_async_default(promisify4(fs.chmod), ATTEMPTIFY_CHANGE_ERROR_OPTIONS),
34693
+ chown: attemptify_async_default(promisify4(fs.chown), ATTEMPTIFY_CHANGE_ERROR_OPTIONS),
34694
+ close: attemptify_async_default(promisify4(fs.close), ATTEMPTIFY_NOOP_OPTIONS),
34695
+ fsync: attemptify_async_default(promisify4(fs.fsync), ATTEMPTIFY_NOOP_OPTIONS),
34696
+ mkdir: attemptify_async_default(promisify4(fs.mkdir), ATTEMPTIFY_NOOP_OPTIONS),
34697
+ realpath: attemptify_async_default(promisify4(fs.realpath), ATTEMPTIFY_NOOP_OPTIONS),
34698
+ stat: attemptify_async_default(promisify4(fs.stat), ATTEMPTIFY_NOOP_OPTIONS),
34699
+ unlink: attemptify_async_default(promisify4(fs.unlink), ATTEMPTIFY_NOOP_OPTIONS),
34634
34700
  /* SYNC */
34635
34701
  chmodSync: attemptify_sync_default(fs.chmodSync, ATTEMPTIFY_CHANGE_ERROR_OPTIONS),
34636
34702
  chownSync: attemptify_sync_default(fs.chownSync, ATTEMPTIFY_CHANGE_ERROR_OPTIONS),
@@ -34644,14 +34710,14 @@ var init_dist2 = __esm({
34644
34710
  },
34645
34711
  retry: {
34646
34712
  /* ASYNC */
34647
- close: retryify_async_default(promisify3(fs.close), RETRYIFY_OPTIONS),
34648
- fsync: retryify_async_default(promisify3(fs.fsync), RETRYIFY_OPTIONS),
34649
- open: retryify_async_default(promisify3(fs.open), RETRYIFY_OPTIONS),
34650
- readFile: retryify_async_default(promisify3(fs.readFile), RETRYIFY_OPTIONS),
34651
- rename: retryify_async_default(promisify3(fs.rename), RETRYIFY_OPTIONS),
34652
- stat: retryify_async_default(promisify3(fs.stat), RETRYIFY_OPTIONS),
34653
- write: retryify_async_default(promisify3(fs.write), RETRYIFY_OPTIONS),
34654
- writeFile: retryify_async_default(promisify3(fs.writeFile), RETRYIFY_OPTIONS),
34713
+ close: retryify_async_default(promisify4(fs.close), RETRYIFY_OPTIONS),
34714
+ fsync: retryify_async_default(promisify4(fs.fsync), RETRYIFY_OPTIONS),
34715
+ open: retryify_async_default(promisify4(fs.open), RETRYIFY_OPTIONS),
34716
+ readFile: retryify_async_default(promisify4(fs.readFile), RETRYIFY_OPTIONS),
34717
+ rename: retryify_async_default(promisify4(fs.rename), RETRYIFY_OPTIONS),
34718
+ stat: retryify_async_default(promisify4(fs.stat), RETRYIFY_OPTIONS),
34719
+ write: retryify_async_default(promisify4(fs.write), RETRYIFY_OPTIONS),
34720
+ writeFile: retryify_async_default(promisify4(fs.writeFile), RETRYIFY_OPTIONS),
34655
34721
  /* SYNC */
34656
34722
  closeSync: retryify_sync_default(fs.closeSync, RETRYIFY_OPTIONS),
34657
34723
  fsyncSync: retryify_sync_default(fs.fsyncSync, RETRYIFY_OPTIONS),
@@ -34663,7 +34729,7 @@ var init_dist2 = __esm({
34663
34729
  writeFileSync: retryify_sync_default(fs.writeFileSync, RETRYIFY_OPTIONS)
34664
34730
  }
34665
34731
  };
34666
- dist_default = FS;
34732
+ dist_default = FS2;
34667
34733
  }
34668
34734
  });
34669
34735
 
@@ -45914,6 +45980,7 @@ async function buildSessionMetadata(segments, events, opts = {}) {
45914
45980
  const evs = eventsBySession.get(sessionId) ?? [];
45915
45981
  const segs = segsBySession.get(sessionId) ?? [];
45916
45982
  const parts = [];
45983
+ const slugToCwd = /* @__PURE__ */ new Map();
45917
45984
  const cwds = /* @__PURE__ */ new Set();
45918
45985
  for (const e of evs) {
45919
45986
  if (e.cwd) cwds.add(e.cwd);
@@ -45948,6 +46015,7 @@ async function buildSessionMetadata(segments, events, opts = {}) {
45948
46015
  g = null;
45949
46016
  }
45950
46017
  if (!g?.remote_slug) continue;
46018
+ slugToCwd.set(g.remote_slug.toLowerCase(), cwd);
45951
46019
  const refs = emptyDetectedRefs();
45952
46020
  refs.repos.push({
45953
46021
  host: g.remote_host ?? null,
@@ -45977,6 +46045,21 @@ async function buildSessionMetadata(segments, events, opts = {}) {
45977
46045
  }
45978
46046
  }
45979
46047
  const meta = dedupeSessionMetadata(parts);
46048
+ if (opts.checkPrOutcome && meta.pull_requests.length > 0) {
46049
+ for (const pr of meta.pull_requests) {
46050
+ const cwd = pr.slug ? slugToCwd.get(pr.slug.toLowerCase()) : void 0;
46051
+ if (!cwd) continue;
46052
+ try {
46053
+ const o = await opts.checkPrOutcome(cwd, pr.number);
46054
+ if (o) {
46055
+ pr.merged = o.merged;
46056
+ pr.merged_at = o.merged_at;
46057
+ pr.reverted = o.reverted;
46058
+ }
46059
+ } catch {
46060
+ }
46061
+ }
46062
+ }
45980
46063
  if (!isEmptySessionMetadata(meta)) out[sessionId] = meta;
45981
46064
  } catch {
45982
46065
  }
@@ -47245,7 +47328,8 @@ async function buildSessionMetadata2(segments, events) {
47245
47328
  const a = await getAdapters();
47246
47329
  return buildSessionMetadata(segments, events, {
47247
47330
  resolveGit: resolveGitContext,
47248
- extractLinks: a.extractLinks
47331
+ extractLinks: a.extractLinks,
47332
+ checkPrOutcome: checkPullRequestOutcome
47249
47333
  });
47250
47334
  }
47251
47335
  async function enrichScripts(drafts, contexts = []) {
@@ -47489,7 +47573,7 @@ var init_scan = __esm({
47489
47573
  init_api();
47490
47574
  init_config2();
47491
47575
  init_pipeline2();
47492
- DAEMON_VERSION = true ? "daemon-0.2.0" : "daemon-dev";
47576
+ DAEMON_VERSION = true ? "daemon-0.3.0" : "daemon-dev";
47493
47577
  BATCH_MAX_EVENTS = INGEST_BATCH_MAX_EVENTS;
47494
47578
  BATCH_MAX_TOOL_CALLS = 2e4;
47495
47579
  BATCH_BUFFER_HARD_CAP = BATCH_MAX_EVENTS * 2;
@@ -49999,7 +50083,7 @@ var init_daemon = __esm({
49999
50083
  init_machine_key();
50000
50084
  init_scan();
50001
50085
  init_single_flight();
50002
- DAEMON_VERSION2 = true ? "daemon-0.2.0" : "daemon-dev";
50086
+ DAEMON_VERSION2 = true ? "daemon-0.3.0" : "daemon-dev";
50003
50087
  HEARTBEAT_INTERVAL_MS = 1e4;
50004
50088
  SCAN_INTERVAL_MS = 5 * 60 * 1e3;
50005
50089
  DISCOVERY_INTERVAL_MS = 6e4;
@@ -50601,7 +50685,7 @@ function tryOpenBrowser(url) {
50601
50685
  return false;
50602
50686
  }
50603
50687
  }
50604
- var DAEMON_VERSION3 = true ? "daemon-0.2.0" : "daemon-dev";
50688
+ var DAEMON_VERSION3 = true ? "daemon-0.3.0" : "daemon-dev";
50605
50689
  function osFamily() {
50606
50690
  const p = platform5();
50607
50691
  if (p === "darwin") return "macos";