@thinkrun/cli 0.1.38 → 0.1.40

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 (58) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +23 -0
  3. package/dist/scripts/browse.sh +40 -7
  4. package/dist/shared/group-binding-key.d.ts +5 -0
  5. package/dist/shared/group-binding-key.js +15 -0
  6. package/dist/shared/group-binding-key.test.js +50 -0
  7. package/dist/shared/native-type-budget.d.ts +16 -0
  8. package/dist/shared/native-type-budget.js +28 -0
  9. package/dist/shared/onboarding-drips.d.ts +13 -0
  10. package/dist/shared/onboarding-drips.js +100 -0
  11. package/dist/shared/onboarding-public-consent.cjs +3 -0
  12. package/dist/shared/onboarding-public-consent.d.ts +1 -0
  13. package/dist/shared/onboarding-public-consent.js +3 -0
  14. package/dist/shared/onboarding-public-consent.json +3 -0
  15. package/dist/shared/recording-upload.js +11 -4
  16. package/dist/shared/recording-upload.test.js +16 -0
  17. package/dist/src/adapters/cloud.d.ts +2 -0
  18. package/dist/src/adapters/cloud.d.ts.map +1 -1
  19. package/dist/src/adapters/cloud.js +112 -17
  20. package/dist/src/adapters/cloud.js.map +1 -1
  21. package/dist/src/adapters/index.d.ts.map +1 -1
  22. package/dist/src/adapters/index.js +30 -5
  23. package/dist/src/adapters/index.js.map +1 -1
  24. package/dist/src/adapters/local.d.ts +2 -0
  25. package/dist/src/adapters/local.d.ts.map +1 -1
  26. package/dist/src/adapters/local.js +23 -8
  27. package/dist/src/adapters/local.js.map +1 -1
  28. package/dist/src/commands/actions.d.ts.map +1 -1
  29. package/dist/src/commands/actions.js +13 -15
  30. package/dist/src/commands/actions.js.map +1 -1
  31. package/dist/src/commands/analyze.d.ts.map +1 -1
  32. package/dist/src/commands/analyze.js +29 -1
  33. package/dist/src/commands/analyze.js.map +1 -1
  34. package/dist/src/commands/cloud.d.ts.map +1 -1
  35. package/dist/src/commands/cloud.js +3 -1
  36. package/dist/src/commands/cloud.js.map +1 -1
  37. package/dist/src/commands/evaluate-helpers.d.ts.map +1 -1
  38. package/dist/src/commands/evaluate-helpers.js +10 -2
  39. package/dist/src/commands/evaluate-helpers.js.map +1 -1
  40. package/dist/src/commands/install.d.ts +11 -0
  41. package/dist/src/commands/install.d.ts.map +1 -1
  42. package/dist/src/commands/install.js +129 -12
  43. package/dist/src/commands/install.js.map +1 -1
  44. package/dist/src/local-bridge-timing.d.ts +3 -0
  45. package/dist/src/local-bridge-timing.d.ts.map +1 -1
  46. package/dist/src/local-bridge-timing.js +3 -0
  47. package/dist/src/local-bridge-timing.js.map +1 -1
  48. package/dist/src/types.d.ts +3 -1
  49. package/dist/src/types.d.ts.map +1 -1
  50. package/dist/src/utils.d.ts +9 -3
  51. package/dist/src/utils.d.ts.map +1 -1
  52. package/dist/src/utils.js +24 -3
  53. package/dist/src/utils.js.map +1 -1
  54. package/dist/src/working-location.d.ts +1 -1
  55. package/dist/src/working-location.d.ts.map +1 -1
  56. package/dist/src/working-location.js +89 -67
  57. package/dist/src/working-location.js.map +1 -1
  58. package/package.json +6 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # Changelog — @thinkrun/cli
2
+
3
+ <!-- GENERATED from the public release notes by scripts/generate-package-changelogs.ts.
4
+ Do not edit by hand: run `bun run generate:package-changelogs`. -->
5
+
6
+ Full history, including changes outside this package: https://thinkrun.ai/changelog
7
+
8
+ ## 0.1.39 — 2026-10-04
9
+
10
+ **CLI 0.1.39 keeps large page reads connected.** Install the updated CLI and run `thinkrun install --force` to upgrade to native host 1.0.8. Reading a page with more than 1 MiB of HTML no longer drops the browser connection, so you can continue opening, reading, and closing tabs in a batch.
11
+
12
+ **CLI 0.1.39 supports custom Chromium data directories on Linux and macOS.** If you start Chromium with `--user-data-dir`, register the same absolute path with `thinkrun install --user-data-dir "/path/to/browser-data"`. Use `thinkrun install --check --user-data-dir "/path/to/browser-data"` to verify that profile's registration.
13
+
14
+ ## 0.1.38 — 2026-09-02
15
+
16
+ **Upload a recording straight from an agent.** CLI 0.1.38 and MCP 0.3.14 can upload a video file as a recording directly, so an agent can hand you back a recording without the browser extension in the loop.
17
+
18
+ ## 0.1.36 — 2026-08-18
19
+
20
+ **CLI 0.1.36 — transactional tab ownership and durable Activity Feed sessions.** Claiming a tab is now all-or-nothing, and sessions survive in the Activity Feed rather than vanishing.
21
+
22
+ **The CLI and MCP agree on what input commands do.** Across CLI 0.1.36 and MCP 0.3.13: `type` appends by default, `clear` replaces existing content, `fill` replaces directly, and `delay` is a bounded per-character value. Help text, tool descriptions, and the connector schema now all say the same thing.
23
+
24
+ ## 0.1.35 — 2026-07-14
25
+
26
+ **CLI 0.1.35 recovers from a stale local bridge port.** `thinkrun` and `thinkrun doctor` used to keep talking to a port the local bridge had moved off. They now re-discover it instead of reporting a broken connection.
27
+
28
+ ## 0.1.34 — 2026-07-06
29
+
30
+ **A stale extension id no longer silently breaks the local host.** After reinstalling the extension, the native host could hold an old id and simply stop responding, with nothing explaining why. It is detected and reported now, and CLI 0.1.34 ships the fix.
31
+
32
+ ## 0.1.32 — 2026-07-01
33
+
34
+ **CLI 0.1.32 — the Chrome Web Store extension connects out of the box.** The published extension no longer needs manual wiring to reach the local bridge.
35
+
36
+ ## 0.1.28 — 2026-06-18
37
+
38
+ **CLI 0.1.28 — a popup option that did nothing now works.** The option was accepted and silently ignored.
package/README.md CHANGED
@@ -26,6 +26,29 @@ npm install -g /path/to/mech-browse/packages/cli
26
26
  thinkrun setup
27
27
  ```
28
28
 
29
+ ## Custom Chromium data directories
30
+
31
+ On Linux and macOS, register the native host for the exact directory passed to
32
+ Chromium's `--user-data-dir`:
33
+
34
+ ```bash
35
+ thinkrun install --user-data-dir "/absolute/path/Chromium data" --extension-id <extension-id>
36
+ thinkrun install --check --user-data-dir "/absolute/path/Chromium data"
37
+ ```
38
+
39
+ Use the data directory itself, not its `Default` or `Profile 1` subdirectory.
40
+ The installer writes `NativeMessagingHosts/com.thinkbrowse.host.json` there,
41
+ creates the directory if needed, and preserves previously allowed extension IDs.
42
+ With this option, registration and inspection target only that directory; the
43
+ binary is still installed in `~/.thinkbrowse/bin`. Without it, standard browser
44
+ registration works as before. Windows uses registry registration and does not
45
+ support this option.
46
+
47
+ [Chromium's path provider](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/chrome_paths.cc)
48
+ resolves user native messaging manifests from the active user data directory.
49
+ Register each custom directory separately, then reconnect or reload the ThinkRun
50
+ extension if it previously reported a missing native host.
51
+
29
52
  ## Quick Start
30
53
 
31
54
  ```bash
@@ -554,24 +554,57 @@ case "${1:-help}" in
554
554
  echo "$RESP" >&2
555
555
  exit 1
556
556
  fi
557
- # Poll until ready (max 120s for cold machine start)
558
- for i in $(seq 1 40); do
559
- STATUS=$(curl -s "${H[@]}" "$BASE/api/sessions/$SID" | jq -r '.data.status // .status // "unknown"')
557
+ # Each status GET and sleep consumes the same 120s elapsed-seconds budget.
558
+ READY_TIMEOUT_SECONDS=120
559
+ READY_MAX_POLLS=40
560
+ READY_SLEEP_SECONDS=3
561
+ READY_STARTED_SECONDS=$SECONDS
562
+ for i in $(seq 1 "$READY_MAX_POLLS"); do
563
+ READY_ELAPSED_SECONDS=$((SECONDS - READY_STARTED_SECONDS))
564
+ READY_REMAINING_SECONDS=$((READY_TIMEOUT_SECONDS - READY_ELAPSED_SECONDS))
565
+ if [ "$READY_REMAINING_SECONDS" -le 0 ]; then
566
+ break
567
+ fi
568
+ REQUEST_TIMEOUT_SECONDS="$READY_REMAINING_SECONDS"
569
+ STATUS_RESPONSE=$(curl -s --max-time "$REQUEST_TIMEOUT_SECONDS" "${H[@]}" \
570
+ "$BASE/api/sessions/$SID" 2>/dev/null || true)
571
+ READY_ELAPSED_SECONDS=$((SECONDS - READY_STARTED_SECONDS))
572
+ if [ "$READY_ELAPSED_SECONDS" -ge "$READY_TIMEOUT_SECONDS" ]; then
573
+ break
574
+ fi
575
+ CANONICAL_SESSION=$(printf '%s' "$STATUS_RESPONSE" | jq -cse 'if length != 1 then {} else .[0] as $root | if ($root | type) != "object" or $root.success == false then {} elif ($root | has("data")) then (if ($root.data | type) == "object" then $root.data else {} end) else $root end end' 2>/dev/null) || CANONICAL_SESSION='{}'
576
+ STATUS=$(printf '%s' "$CANONICAL_SESSION" | jq -r 'if (.status | type) == "string" then .status else "unknown" end' 2>/dev/null) || STATUS="unknown"
577
+ BROWSER_READY=$(printf '%s' "$CANONICAL_SESSION" | jq -r 'if (.browserReady | type) == "boolean" then (.browserReady | tostring) else "missing" end' 2>/dev/null) || BROWSER_READY="missing"
560
578
  case "$STATUS" in
561
579
  ready|active|running)
562
- echo "$SID"
563
- exit 0
580
+ if [ "$BROWSER_READY" = "true" ]; then
581
+ echo "$SID"
582
+ exit 0
583
+ fi
584
+ printf "." >&2
564
585
  ;;
565
586
  creating|provisioning|pending)
566
587
  printf "." >&2
567
- sleep 3
568
588
  ;;
569
- failed|error|terminated)
589
+ failed|error|terminated|closed|completed|cancelled)
570
590
  echo "" >&2
571
591
  echo "ERROR: Session $SID failed with status: $STATUS" >&2
572
592
  exit 1
573
593
  ;;
594
+ *)
595
+ printf "." >&2
596
+ ;;
574
597
  esac
598
+ READY_ELAPSED_SECONDS=$((SECONDS - READY_STARTED_SECONDS))
599
+ READY_REMAINING_SECONDS=$((READY_TIMEOUT_SECONDS - READY_ELAPSED_SECONDS))
600
+ if [ "$READY_REMAINING_SECONDS" -le 0 ]; then
601
+ break
602
+ fi
603
+ SLEEP_SECONDS="$READY_SLEEP_SECONDS"
604
+ if [ "$READY_REMAINING_SECONDS" -lt "$SLEEP_SECONDS" ]; then
605
+ SLEEP_SECONDS="$READY_REMAINING_SECONDS"
606
+ fi
607
+ sleep "$SLEEP_SECONDS"
575
608
  done
576
609
  echo "" >&2
577
610
  echo "ERROR: Session $SID not ready after 120s" >&2
@@ -0,0 +1,5 @@
1
+ /** Return a collision-resistant filesystem key for a caller-provided group name. */
2
+ export declare function getGroupBindingKey(group: string): string;
3
+
4
+ /** Return the historical key for read-only legacy lookup and safe cleanup. */
5
+ export declare function getLegacyGroupBindingKey(group: string): string;
@@ -0,0 +1,15 @@
1
+ import { createHash } from 'node:crypto';
2
+
3
+ const GROUP_KEY_STEM_LIMIT = 64;
4
+
5
+ /** Return a collision-resistant filesystem key for a caller-provided group name. */
6
+ export function getGroupBindingKey(group) {
7
+ const stem = group.replace(/[^A-Za-z0-9_-]/g, '_').slice(0, GROUP_KEY_STEM_LIMIT);
8
+ const digest = createHash('sha256').update(Buffer.from(group, 'utf16le')).digest('hex');
9
+ return `${stem}~${digest}`;
10
+ }
11
+
12
+ /** Return the historical key for read-only legacy lookup and safe cleanup. */
13
+ export function getLegacyGroupBindingKey(group) {
14
+ return group.replace(/[^A-Za-z0-9_-]/g, '_') || 'default';
15
+ }
@@ -0,0 +1,50 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { createHash } from 'node:crypto';
3
+ import { getGroupBindingKey, getLegacyGroupBindingKey } from './group-binding-key.js';
4
+
5
+ describe('group binding keys', () => {
6
+ test('puts every name in a bounded hashed namespace', () => {
7
+ for (const group of ['agent_42-team', 'a'.repeat(240), 'a'.repeat(241)]) {
8
+ const key = getGroupBindingKey(group);
9
+ expect(key).not.toBe(group);
10
+ expect(key).toMatch(/^[A-Za-z0-9_-]*~[a-f0-9]{64}$/);
11
+ expect(key.length).toBeLessThanOrEqual(129);
12
+ }
13
+ });
14
+
15
+ test('case-folding variants get distinct keys on case-insensitive filesystems', () => {
16
+ const keys = ['Team', 'team', 'TEAM'].map(getGroupBindingKey);
17
+ expect(new Set(keys).size).toBe(3);
18
+ });
19
+
20
+ test('Windows device basenames are hashed into valid non-device filenames', () => {
21
+ for (const group of ['con', 'prn', 'aux', 'nul', 'com1', 'com9', 'lpt1', 'lpt9']) {
22
+ const key = getGroupBindingKey(group);
23
+ expect(key).not.toBe(group);
24
+ expect(key).toMatch(/^[a-z0-9_-]*~[a-f0-9]{64}$/);
25
+ expect(key).not.toMatch(/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/);
26
+ }
27
+ });
28
+
29
+ test('separates names that collided under the historical sanitizer', () => {
30
+ expect(getLegacyGroupBindingKey('a b')).toBe(getLegacyGroupBindingKey('a_b'));
31
+ expect(getGroupBindingKey('a b')).not.toBe(getGroupBindingKey('a_b'));
32
+ });
33
+
34
+ test('hashes Unicode and lone surrogate code units distinctly within the path bound', () => {
35
+ for (const group of ['研究', '\uD800', '\uDC00', 'x'.repeat(400) + ' /unsafe']) {
36
+ const key = getGroupBindingKey(group);
37
+ const expectedHash = createHash('sha256').update(Buffer.from(group, 'utf16le')).digest('hex');
38
+ expect(key.endsWith(`~${expectedHash}`)).toBe(true);
39
+ expect(key.length).toBeLessThanOrEqual(129);
40
+ expect(key).toMatch(/^[A-Za-z0-9_-]*~[a-f0-9]{64}$/);
41
+ }
42
+ expect(getGroupBindingKey('\uD800')).not.toBe(getGroupBindingKey('\uDC00'));
43
+ });
44
+
45
+ test('empty input hashes independently of the legacy default alias', () => {
46
+ expect(getLegacyGroupBindingKey('')).toBe('default');
47
+ expect(getGroupBindingKey('')).not.toBe('default');
48
+ expect(getGroupBindingKey('')).toMatch(/^~[a-f0-9]{64}$/);
49
+ });
50
+ });
@@ -0,0 +1,16 @@
1
+ export declare const NATIVE_TYPE_EXECUTION_BUFFER_MS: 5000;
2
+ export declare const NATIVE_TYPE_MAX_TIMEOUT_MS: 600000;
3
+
4
+ export interface NativeTypeBudget {
5
+ characterCount: number;
6
+ delayMs: number;
7
+ requiredTimeoutMs: number;
8
+ timeoutMs: number;
9
+ exceedsLimit: boolean;
10
+ }
11
+
12
+ export declare function getNativeTypeBudget(
13
+ text: string,
14
+ delay: number | undefined,
15
+ defaultTimeoutMs: number,
16
+ ): NativeTypeBudget;
@@ -0,0 +1,28 @@
1
+ export const NATIVE_TYPE_EXECUTION_BUFFER_MS = 5_000;
2
+ export const NATIVE_TYPE_MAX_TIMEOUT_MS = 600_000;
3
+
4
+ /**
5
+ * Compute the native host's typing command timeout without dispatching it.
6
+ * Character count follows Unicode code points, matching Array.from(text).
7
+ */
8
+ export function getNativeTypeBudget(text, delay, defaultTimeoutMs) {
9
+ const characterCount = Array.from(text).length;
10
+ const normalizedDelayMs = typeof delay === 'number' && Number.isFinite(delay) && delay > 0
11
+ ? delay
12
+ : 0;
13
+ const requiredTimeoutMs = Math.ceil(
14
+ characterCount * normalizedDelayMs + NATIVE_TYPE_EXECUTION_BUFFER_MS,
15
+ );
16
+ const timeoutMs = Math.min(
17
+ NATIVE_TYPE_MAX_TIMEOUT_MS,
18
+ Math.max(defaultTimeoutMs, requiredTimeoutMs),
19
+ );
20
+
21
+ return {
22
+ characterCount,
23
+ delayMs: normalizedDelayMs,
24
+ requiredTimeoutMs,
25
+ timeoutMs,
26
+ exceedsLimit: requiredTimeoutMs > NATIVE_TYPE_MAX_TIMEOUT_MS,
27
+ };
28
+ }
@@ -0,0 +1,13 @@
1
+ export const LEDGER_DDL: string;
2
+ export interface OnboardingEnv { [key: string]: string | undefined }
3
+ export type Sql = (query: string, parameters?: readonly unknown[]) => Promise<any[]>;
4
+ export function onboardingConfig(env: OnboardingEnv): { since: string; sequenceId: string; version: number; recipients: string[] | null } | null;
5
+ export interface OnboardingSdk {
6
+ enroll(input: { sequenceId: string; version: number; subjectId: string; email: string; consent: true }): Promise<{ data: { id: string } }>;
7
+ getEnrollment(id: string): Promise<{ data: { status: string } }>;
8
+ track(input: { id: string; subjectId: string; name: string }): Promise<unknown>;
9
+ }
10
+ export interface SqlDatabase { executeQuery(query: { sql: string; parameters: readonly unknown[]; query: { kind: 'RawNode'; sqlFragments: string[]; parameters: unknown[] } }): Promise<{ rows: any[] }> }
11
+ export function onboardingSql(env: OnboardingEnv, createMechKysely: (options: { appId: string; apiKey: string }) => SqlDatabase): Sql;
12
+ export function queueVerifiedSignup(env: OnboardingEnv, subjectId: string, execute: (env: OnboardingEnv) => Sql): Promise<void>;
13
+ export function pumpOnboarding(options: { env: OnboardingEnv; sql: Sql; sdk: OnboardingSdk; completedTask: (subjectId: string, since: string) => Promise<boolean>; limit?: number }): Promise<{ enrolled: number; activated: number; failed: number }>;
@@ -0,0 +1,100 @@
1
+ // Specialized delivery ledger for this one onboarding sequence. No runtime DDL.
2
+ export const LEDGER_DDL = `CREATE TABLE circleinbox_onboarding (
3
+ subject_id TEXT PRIMARY KEY, email TEXT NOT NULL,
4
+ enrollment_id TEXT, enrolled_at TIMESTAMPTZ, activated_at TIMESTAMPTZ, finished_at TIMESTAMPTZ,
5
+ checked_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
6
+ )`;
7
+
8
+ export function onboardingConfig(env) {
9
+ if (env.CIRCLEINBOX_ONBOARDING_ENABLED !== 'true') return null;
10
+ const since = new Date(env.CIRCLEINBOX_ONBOARDING_SINCE || '');
11
+ if (!Number.isFinite(since.getTime()) || env.CIRCLEINBOX_ONBOARDING_CONSENT !== 'true') {
12
+ throw new Error('Onboarding requires an explicit enable timestamp and consent assertion');
13
+ }
14
+ if (!env.CIRCLEINBOX_API_KEY || !Number.isSafeInteger(Number(env.CIRCLEINBOX_ONBOARDING_SEQUENCE_VERSION)) || Number(env.CIRCLEINBOX_ONBOARDING_SEQUENCE_VERSION) < 1) {
15
+ throw new Error('Onboarding requires credentials and a published sequence version');
16
+ }
17
+ const allowAll = env.CIRCLEINBOX_ONBOARDING_ALLOW_ALL_NEW_USERS === 'true';
18
+ const raw = env.CIRCLEINBOX_ONBOARDING_RECIPIENT_ALLOWLIST?.trim() || '';
19
+ if (allowAll === Boolean(raw) || raw.length > 5100) throw new Error('Onboarding requires exactly one recipient scope');
20
+ const recipients = raw ? [...new Set(raw.split(',').map((email) => email.trim().toLowerCase()))] : null;
21
+ if (recipients && (recipients.length > 20 || recipients.some((email) => email.length > 254 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)))) {
22
+ throw new Error('Onboarding recipient allowlist must contain 1 to 20 valid emails');
23
+ }
24
+ return { since: since.toISOString(), sequenceId: 'thinkrun-onboarding', version: Number(env.CIRCLEINBOX_ONBOARDING_SEQUENCE_VERSION), recipients };
25
+ }
26
+
27
+ export function onboardingSql(env, createMechKysely) {
28
+ const db = createMechKysely({ appId: env.MECH_APP_ID || env.MECH_BROWSE_APP_ID || '', apiKey: env.MECH_API_KEY });
29
+ return async (sql, parameters = []) => {
30
+ // executeQuery accepts this CompiledQuery directly; SQL is already compiled and bound.
31
+ const result = await db.executeQuery({ sql, parameters, query: { kind: 'RawNode', sqlFragments: [sql], parameters: [] } });
32
+ return result.rows;
33
+ };
34
+ }
35
+
36
+ export async function queueVerifiedSignup(env, subjectId, execute) {
37
+ const config = onboardingConfig(env);
38
+ if (!config) return;
39
+ const sql = execute(env);
40
+ // A successful verification is the source of truth; do not trust request email.
41
+ await sql(`INSERT INTO circleinbox_onboarding (subject_id,email)
42
+ SELECT id::text,email FROM users WHERE id=$1 AND email_verified=true AND created_at >= $2::timestamptz
43
+ AND ($3::text[] IS NULL OR lower(email)=ANY($3::text[]))
44
+ ON CONFLICT (subject_id) DO NOTHING`, [subjectId, config.since, config.recipients]);
45
+ }
46
+
47
+ export async function pumpOnboarding({ env, sql, sdk, completedTask, limit = 25 }) {
48
+ const config = onboardingConfig(env);
49
+ if (!config) return { enrolled: 0, activated: 0, failed: 0 };
50
+ // Commit queued ledger rows BEFORE any remote SDK call, even during an outage.
51
+ // Exclude every queued subject (including enrolled_at=null); the next pass can
52
+ // discover users beyond this batch while earlier deliveries remain pending.
53
+ // This closes the post-auth enqueue gap for newly created verified accounts.
54
+ await sql(`INSERT INTO circleinbox_onboarding (subject_id,email)
55
+ SELECT u.id::text,u.email FROM users u WHERE u.email_verified=true AND u.created_at >= $1::timestamptz
56
+ AND ($2::text[] IS NULL OR lower(u.email)=ANY($2::text[]))
57
+ AND NOT EXISTS (SELECT 1 FROM circleinbox_onboarding o WHERE o.subject_id=u.id::text)
58
+ ORDER BY u.created_at,u.id LIMIT 100 ON CONFLICT (subject_id) DO NOTHING`, [config.since, config.recipients]);
59
+ const rows = await sql(`SELECT subject_id,email,enrolled_at,enrollment_id FROM circleinbox_onboarding
60
+ WHERE activated_at IS NULL AND finished_at IS NULL
61
+ AND ($2::text[] IS NULL OR lower(email)=ANY($2::text[]))
62
+ ORDER BY checked_at,subject_id LIMIT $1`, [limit, config.recipients]);
63
+ const result = { enrolled: 0, activated: 0, failed: 0 };
64
+ for (const row of rows) {
65
+ let failed = false;
66
+ try {
67
+ let enrollmentId = row.enrollment_id;
68
+ if (!row.enrolled_at || !enrollmentId) {
69
+ // API contract: UNIQUE(org,sequenceId,subjectId) across versions. Identical
70
+ // enroll replays return the same resource; changed payloads return409.
71
+ // Replaying after a lost ledger acknowledgment cannot create another workflow.
72
+ const enrollment = await sdk.enroll({ sequenceId: config.sequenceId, version: config.version, subjectId: row.subject_id, email: row.email, consent: true });
73
+ enrollmentId = enrollment?.data?.id;
74
+ if (typeof enrollmentId !== 'string' || !enrollmentId) throw new Error('InvalidEnrollmentResponse');
75
+ await sql('UPDATE circleinbox_onboarding SET enrolled_at=CURRENT_TIMESTAMP,enrollment_id=$2 WHERE subject_id=$1', [row.subject_id, enrollmentId]);
76
+ result.enrolled++;
77
+ }
78
+ const remote = await sdk.getEnrollment(enrollmentId);
79
+ if (['completed', 'cancelled', 'suppressed', 'failed', 'unknown'].includes(remote?.data?.status)) {
80
+ await sql('UPDATE circleinbox_onboarding SET finished_at=CURRENT_TIMESTAMP WHERE subject_id=$1', [row.subject_id]);
81
+ continue;
82
+ }
83
+ if (!['active', 'waiting', 'sending'].includes(remote?.data?.status)) throw new Error('InvalidEnrollmentResponse');
84
+ if (await completedTask(row.subject_id, config.since)) {
85
+ await sdk.track({ id: `thinkrun:activated:${row.subject_id}`, subjectId: row.subject_id, name: 'thinkrun.task_completed' });
86
+ await sql('UPDATE circleinbox_onboarding SET activated_at=CURRENT_TIMESTAMP WHERE subject_id=$1', [row.subject_id]);
87
+ result.activated++;
88
+ }
89
+ } catch {
90
+ // Status remains pending; retry uses stable enrollment/event identifiers.
91
+ failed = true;
92
+ result.failed++;
93
+ } finally {
94
+ try { await sql('UPDATE circleinbox_onboarding SET checked_at=CURRENT_TIMESTAMP WHERE subject_id=$1', [row.subject_id]); }
95
+ catch { if (!failed) result.failed++; }
96
+ }
97
+ }
98
+ return result;
99
+ }
100
+
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ exports.ONBOARDING_PUBLIC_DEFAULT_CONSENT_VERSION = require('./onboarding-public-consent.json').version;
@@ -0,0 +1 @@
1
+ export const ONBOARDING_PUBLIC_DEFAULT_CONSENT_VERSION: string;
@@ -0,0 +1,3 @@
1
+ import contract from './onboarding-public-consent.json' assert { type: 'json' };
2
+
3
+ export const ONBOARDING_PUBLIC_DEFAULT_CONSENT_VERSION = contract.version;
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": "public-v1"
3
+ }
@@ -3,6 +3,7 @@
3
3
  * never media bytes supplied by an API caller, and talks to the recording API
4
4
  * directly (not through the browser extension/native bridge).
5
5
  */
6
+ import { createHash } from 'node:crypto';
6
7
  import { createReadStream } from 'node:fs';
7
8
  import { access, lstat, open } from 'node:fs/promises';
8
9
  import { constants } from 'node:fs';
@@ -105,10 +106,13 @@ export async function uploadRecordingFile(options) {
105
106
  handle = await open(file.path, constants.O_RDONLY | (constants.O_NOFOLLOW || 0));
106
107
  const opened = await handle.stat();
107
108
  if (!opened.isFile() || opened.size !== file.sizeBytes || opened.dev !== file.device || opened.ino !== file.inode) throw new RecordingUploadError('FILE_CHANGED', 'Recording file changed during validation');
108
- const stream = () => createReadStream(file.path, { fd: handle.fd, autoClose: false });
109
+ const stream = () => createReadStream(file.path, { fd: handle.fd, autoClose: false, start: 0 });
110
+ const digest = createHash('sha256');
111
+ for await (const chunk of stream()) digest.update(chunk);
112
+ const videoChecksumSha256 = digest.digest('hex');
109
113
  const created = requireSuccess(await request(fetchImpl, `${baseUrl}/api/feedback/recordings`, {
110
114
  method: 'POST', headers: headers(options.apiKey), body: JSON.stringify({
111
- source: 'cli', videoContentType: file.contentType,
115
+ source: 'cli', videoContentType: file.contentType, videoBytes: file.sizeBytes, videoChecksumSha256,
112
116
  metadata: { version: '1.0', duration: 0, url, title, profile: 'simple', intent, features: { audio: false, console: false, network: false, dom: false } },
113
117
  actions: [], browserState: { consoleLogs: [], networkRequests: [] }, elements: [],
114
118
  }),
@@ -127,11 +131,14 @@ export async function uploadRecordingFile(options) {
127
131
  uploadStarted = true;
128
132
  // Axios preserves Content-Length for Node file streams; fetch sends these
129
133
  // as chunked bodies and R2's presigned endpoint rejects them with HTTP 411.
134
+ const directHeaders = new Headers(created.presignedVideoHeaders);
135
+ directHeaders.set('Content-Type', created.presignedVideoContentType || file.contentType);
136
+ directHeaders.set('Content-Length', String(file.sizeBytes));
130
137
  let direct;
131
138
  try {
132
139
  direct = options.fetchImpl
133
- ? await fetchImpl(created.uploadUrl, { method: 'PUT', headers: { 'Content-Type': created.presignedVideoContentType || file.contentType, 'Content-Length': String(file.sizeBytes) }, body: stream(), duplex: 'half', signal: AbortSignal.timeout(UPLOAD_TIMEOUT_MS) })
134
- : await axios.put(created.uploadUrl, stream(), { headers: { 'Content-Type': created.presignedVideoContentType || file.contentType, 'Content-Length': String(file.sizeBytes) }, maxBodyLength: MAX_RECORDING_UPLOAD_BYTES, timeout: UPLOAD_TIMEOUT_MS, validateStatus: () => true });
140
+ ? await fetchImpl(created.uploadUrl, { method: 'PUT', headers: directHeaders, body: stream(), duplex: 'half', signal: AbortSignal.timeout(UPLOAD_TIMEOUT_MS) })
141
+ : await axios.put(created.uploadUrl, stream(), { headers: { ...created.presignedVideoHeaders, 'Content-Type': created.presignedVideoContentType || file.contentType, 'Content-Length': String(file.sizeBytes) }, maxBodyLength: MAX_RECORDING_UPLOAD_BYTES, timeout: UPLOAD_TIMEOUT_MS, validateStatus: () => true });
135
142
  } catch (error) {
136
143
  if (isDefinitivePreTransferError(error)) uploadStarted = false;
137
144
  throw error;
@@ -34,6 +34,22 @@ describe('agent recording upload', () => {
34
34
  expect(calls).toHaveLength(3);
35
35
  });
36
36
 
37
+ test('normalizes supplied direct-upload header names without comma-joining values', async () => {
38
+ const path = await fixture(); let checked = false;
39
+ const fetchImpl = async (url, init = {}) => {
40
+ if (String(url).endsWith('/recordings')) return Response.json({ success: true, recordingId: 'rec-12345678', uploadUrl: 'https://signed.example.test/token', uploadToken: 'token', presignedVideoObjectId: 'object-1', presignedVideoContentType: 'video/webm', presignedVideoHeaders: { 'content-type': 'video/webm', 'content-length': '5' } });
41
+ if (String(url).startsWith('https://signed.')) {
42
+ const headers = new Headers(init.headers);
43
+ expect(headers.get('content-type')).toBe('video/webm');
44
+ expect(headers.get('content-length')).toBe('5');
45
+ checked = true; return new Response('', { status: 200 });
46
+ }
47
+ return Response.json({ success: true, analysisEnqueued: false });
48
+ };
49
+ await uploadRecordingFile({ path, apiBase: 'https://api.example.test', fetchImpl });
50
+ expect(checked).toBe(true);
51
+ });
52
+
37
53
  test('falls back to the authenticated streaming endpoint when no presign is offered', async () => {
38
54
  const path = await fixture('capture.mov'); const calls = [];
39
55
  const fetchImpl = async (url, init = {}) => {
@@ -9,6 +9,7 @@ export declare class CloudAdapter implements BrowserAdapter {
9
9
  private defaultTimeout;
10
10
  constructor(apiKey?: string, baseUrl?: string);
11
11
  private request;
12
+ private isTransientReadFailure;
12
13
  private sleep;
13
14
  private getActiveSessionId;
14
15
  /**
@@ -36,6 +37,7 @@ export declare class CloudAdapter implements BrowserAdapter {
36
37
  waitForSessionReady(sessionId: string, timeout?: number): Promise<Session>;
37
38
  stopSession(sessionId?: string): Promise<void>;
38
39
  getSession(sessionId: string): Promise<Session>;
40
+ private readSession;
39
41
  listSessions(): Promise<Session[]>;
40
42
  listArtifacts(sessionId: string): Promise<any>;
41
43
  navigate(url: string, options?: NavigateOptions): Promise<ActionResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloud.ts"],"names":[],"mappings":"AAAA;;GAEG;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