pairit 0.3.3 → 0.3.5

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 (3) hide show
  1. package/README.md +31 -0
  2. package/dist/index.js +127 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,6 +13,7 @@ A lightweight command line utility for working with Pairit experiment configurat
13
13
  - `media delete` — delete a media object from Cloud Storage
14
14
  - `data export` — export sessions, events, and chat messages for a config as CSV/JSON/JSONL
15
15
  - `admin add-user` / `admin remove-user` / `admin list-users` — manage the manager allowlist (admin role required)
16
+ - `admin activity` — show studies with recent sessions, live group studies first (admin role required)
16
17
 
17
18
  ## Install
18
19
 
@@ -96,6 +97,36 @@ Notes:
96
97
  - Self-removal is blocked.
97
98
  - The rejection page contact is set by `MANAGER_ADMIN_CONTACT_EMAIL` (defaults to `harang@pairium.ai`).
98
99
 
100
+ ## Activity (admin)
101
+
102
+ See what is running before you deploy production. Don't deploy while a group study is live.
103
+
104
+ ```bash
105
+ pairit admin activity # studies with sessions in the last 24 h
106
+ pairit admin activity --since 7d # look further back (30m, 2h, 7d, 1w)
107
+ pairit admin activity --json # the raw report
108
+ pairit admin activity --fail-if-live # exit 2 if a group study is live, for scripts
109
+ pairit --env staging admin activity # staging
110
+ ```
111
+
112
+ ```
113
+ 1 group study is live. Don't deploy production.
114
+ omh-test (owner@example.com): 3 active (2 in a group, 1 solo), 1 waiting in matchmaking
115
+
116
+ STUDY OWNER ACTIVE (GROUP/SOLO) WAITING TODAY TOTAL FLAGS
117
+ ● omh-test owner@example.com 3 (2/1) 1 5 127 group,chat,live-workspace,agents
118
+ survey-a r@example.com 1 (0/1) 0 9 40 html
119
+ ```
120
+
121
+ - **Active**: sessions that have not finished, changed in the last 15 minutes, and started in the last 12 hours. **Group** sessions have been matched into a group; **solo** ones have not.
122
+ - Older sessions that still change are listed under "Not counted". This is usually a browser tab left open on a page whose `html` component saves on a timer.
123
+ - **Waiting**: active sessions on a page with a `matchmaking` component that have not been matched yet.
124
+ - **Today**: sessions started in the last 24 hours. **Total**: all sessions of the config.
125
+ - **Flags**: `group` (the config has a matchmaking pool or component), then the features it uses: `chat`, `live-workspace`, `html`, `agents`.
126
+ - A group study is **live** when it has any active session. Live group studies come first and are marked `●`.
127
+
128
+ `scripts/deploy.sh production` runs `admin activity --fail-if-live` and stops if a group study is live. The manager endpoint is `GET /admin/activity` (optional `since`, an ISO date).
129
+
99
130
  ## Per-experiment LLM credentials
100
131
 
101
132
  If your config uses AI agents, attach provider credentials when uploading:
package/dist/index.js CHANGED
@@ -9230,7 +9230,7 @@ var fallbackAttemptSymbol, __dirname2, localXdgOpenPath, platform, arch, tryEach
9230
9230
  "microsoft-edge.desktop": "edge",
9231
9231
  "com.apple.safari": "safari"
9232
9232
  };
9233
- const flags = {
9233
+ const flags2 = {
9234
9234
  chrome: "--incognito",
9235
9235
  brave: "--incognito",
9236
9236
  firefox: "--private-window",
@@ -9250,7 +9250,7 @@ var fallbackAttemptSymbol, __dirname2, localXdgOpenPath, platform, arch, tryEach
9250
9250
  if (browserName === "safari") {
9251
9251
  throw new Error("Safari doesn't support opening in private mode via command line");
9252
9252
  }
9253
- appArguments.push(flags[browserName]);
9253
+ appArguments.push(flags2[browserName]);
9254
9254
  }
9255
9255
  return baseOpen({
9256
9256
  ...options,
@@ -9480,6 +9480,103 @@ var {
9480
9480
  // src/index.ts
9481
9481
  var import_yaml = __toESM(require_dist(), 1);
9482
9482
 
9483
+ // src/activity.ts
9484
+ var UNIT_MS = {
9485
+ m: 60 * 1000,
9486
+ h: 60 * 60 * 1000,
9487
+ d: 24 * 60 * 60 * 1000,
9488
+ w: 7 * 24 * 60 * 60 * 1000
9489
+ };
9490
+ function parseDuration(value) {
9491
+ const match = /^(\d+)\s*([mhdw])$/.exec(value.trim());
9492
+ if (!match || Number(match[1]) <= 0) {
9493
+ throw new Error(`Invalid duration "${value}". Use a number and a unit: 30m, 2h, 7d, 1w.`);
9494
+ }
9495
+ return Number(match[1]) * UNIT_MS[match[2]];
9496
+ }
9497
+ function isLive(entry) {
9498
+ return entry.isGroupStudy && entry.activeNow.total > 0;
9499
+ }
9500
+ function owner(entry) {
9501
+ return entry.ownerEmail ?? entry.ownerId ?? "-";
9502
+ }
9503
+ function flags(entry) {
9504
+ const list = [];
9505
+ if (entry.isGroupStudy)
9506
+ list.push("group");
9507
+ if (entry.features.chat)
9508
+ list.push("chat");
9509
+ if (entry.features.liveWorkspace)
9510
+ list.push("live-workspace");
9511
+ if (entry.features.html)
9512
+ list.push("html");
9513
+ if (entry.features.agents)
9514
+ list.push("agents");
9515
+ return list.join(",") || "-";
9516
+ }
9517
+ function describeLiveStudy(entry) {
9518
+ const { total, inGroup, solo } = entry.activeNow;
9519
+ return `${entry.configId} (${owner(entry)}): ${total} active (${inGroup} in a group, ${solo} solo), ${entry.waitingInMatchmaking} waiting in matchmaking`;
9520
+ }
9521
+ function formatActivity(report, options = {}) {
9522
+ const paint = (code, text) => options.color ? `\x1B[${code}m${text}\x1B[0m` : text;
9523
+ const lines = [];
9524
+ const live = report.configs.filter(isLive);
9525
+ if (live.length > 0) {
9526
+ lines.push(paint("1;31", `${live.length} group ${live.length === 1 ? "study is" : "studies are"} live. Don't deploy production.`));
9527
+ for (const entry of live)
9528
+ lines.push(` ${describeLiveStudy(entry)}`);
9529
+ } else {
9530
+ lines.push("No group study is live.");
9531
+ }
9532
+ lines.push("");
9533
+ if (report.configs.length === 0) {
9534
+ lines.push(`No sessions since ${report.since}.`);
9535
+ return lines.join(`
9536
+ `);
9537
+ }
9538
+ const rows = [
9539
+ ...live,
9540
+ ...report.configs.filter((entry) => !isLive(entry))
9541
+ ].map((entry) => ({
9542
+ live: isLive(entry),
9543
+ cells: [
9544
+ entry.configId,
9545
+ owner(entry),
9546
+ `${entry.activeNow.total} (${entry.activeNow.inGroup}/${entry.activeNow.solo})`,
9547
+ String(entry.waitingInMatchmaking),
9548
+ String(entry.startedToday),
9549
+ String(entry.totalSessions),
9550
+ flags(entry)
9551
+ ]
9552
+ }));
9553
+ const header = [
9554
+ "STUDY",
9555
+ "OWNER",
9556
+ "ACTIVE (GROUP/SOLO)",
9557
+ "WAITING",
9558
+ "TODAY",
9559
+ "TOTAL",
9560
+ "FLAGS"
9561
+ ];
9562
+ const widths = header.map((title, i) => Math.max(title.length, ...rows.map((row) => row.cells[i].length)));
9563
+ const join = (cells) => cells.map((cell, i) => i === cells.length - 1 ? cell : cell.padEnd(widths[i])).join(" ");
9564
+ lines.push(` ${join(header)}`);
9565
+ for (const row of rows) {
9566
+ const text = join(row.cells);
9567
+ lines.push(row.live ? paint("1;31", `● ${text}`) : ` ${text}`);
9568
+ }
9569
+ lines.push("");
9570
+ const stale = report.configs.filter((entry) => (entry.staleOpen ?? 0) > 0);
9571
+ if (stale.length > 0 && report.staleAfterHours) {
9572
+ lines.push(`Not counted: sessions that started over ${report.staleAfterHours} h ago but still change, usually a tab left open: ${stale.map((entry) => `${entry.configId} (${entry.staleOpen})`).join(", ")}.`);
9573
+ }
9574
+ const started = report.staleAfterHours ? `, changed in the last ${report.activeWindowMinutes} min, and started in the last ${report.staleAfterHours} h` : ` and changed in the last ${report.activeWindowMinutes} min`;
9575
+ lines.push(`Since ${report.since}. Active: not finished${started}. Today: started in the last 24 h.`);
9576
+ return lines.join(`
9577
+ `);
9578
+ }
9579
+
9483
9580
  // src/auth.ts
9484
9581
  import { mkdir, readFile, writeFile } from "node:fs/promises";
9485
9582
  import { homedir } from "node:os";
@@ -9930,7 +10027,7 @@ function singleGroupSize(config) {
9930
10027
 
9931
10028
  // src/index.ts
9932
10029
  var program2 = new Command;
9933
- program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.3").option("--env <name>", "Target environment: staging or production", (value) => {
10030
+ program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.5").option("--env <name>", "Target environment: staging or production", (value) => {
9934
10031
  try {
9935
10032
  return parseEnvName(value);
9936
10033
  } catch (error) {
@@ -10139,7 +10236,7 @@ dataCommand.command("export").argument("<configId>", "Config ID to export data f
10139
10236
  reportCliError("Export failed", error);
10140
10237
  }
10141
10238
  });
10142
- var adminCommand = program2.command("admin").description("Manage manager allowlist (admin only)");
10239
+ var adminCommand = program2.command("admin").description("Manage the manager allowlist and see activity (admin only)");
10143
10240
  adminCommand.command("add-user").argument("<email>", "Email to allow").option("--admin", "Grant admin privileges").description("Add a user to the manager allowlist").action(async (email, options) => {
10144
10241
  try {
10145
10242
  const response = await callFunctions("/admin/users", {
@@ -10190,6 +10287,32 @@ adminCommand.command("list-users").description("List users on the manager allowl
10190
10287
  reportCliError("List users failed", error);
10191
10288
  }
10192
10289
  });
10290
+ adminCommand.command("activity").description("Show studies with recent sessions, live group studies first (check before deploying production)").option("--since <duration>", "How far back to look, e.g. 2h, 7d", (value) => {
10291
+ try {
10292
+ return parseDuration(value);
10293
+ } catch (error) {
10294
+ throw new InvalidArgumentError(error.message);
10295
+ }
10296
+ }).option("--json", "Print the raw report as JSON").option("--fail-if-live", "Exit with code 2 if any group study has active participants").action(async (options) => {
10297
+ try {
10298
+ const query = options.since ? `?since=${encodeURIComponent(new Date(Date.now() - options.since).toISOString())}` : "";
10299
+ const report = await callFunctions(`/admin/activity${query}`, {
10300
+ method: "GET"
10301
+ });
10302
+ if (options.json) {
10303
+ console.log(JSON.stringify(report, null, 2));
10304
+ } else {
10305
+ console.log(formatActivity(report, {
10306
+ color: Boolean(process11.stdout.isTTY) && !process11.env.NO_COLOR
10307
+ }));
10308
+ }
10309
+ if (options.failIfLive && report.liveGroupStudies.length > 0) {
10310
+ process11.exitCode = 2;
10311
+ }
10312
+ } catch (error) {
10313
+ reportCliError("Activity failed", error);
10314
+ }
10315
+ });
10193
10316
  program2.parseAsync(process11.argv).catch((err) => {
10194
10317
  console.error(err);
10195
10318
  process11.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pairit",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "CLI for the Pairit behavioral science experiment platform",
5
5
  "type": "module",
6
6
  "bin": {