@thinkrun/cli 0.1.27

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 (183) hide show
  1. package/README.md +349 -0
  2. package/dist/bin/thinkrun.d.ts +6 -0
  3. package/dist/bin/thinkrun.d.ts.map +1 -0
  4. package/dist/bin/thinkrun.js +124 -0
  5. package/dist/bin/thinkrun.js.map +1 -0
  6. package/dist/scripts/browse.sh +1107 -0
  7. package/dist/src/adapters/cloud.d.ts +79 -0
  8. package/dist/src/adapters/cloud.d.ts.map +1 -0
  9. package/dist/src/adapters/cloud.js +637 -0
  10. package/dist/src/adapters/cloud.js.map +1 -0
  11. package/dist/src/adapters/index.d.ts +47 -0
  12. package/dist/src/adapters/index.d.ts.map +1 -0
  13. package/dist/src/adapters/index.js +211 -0
  14. package/dist/src/adapters/index.js.map +1 -0
  15. package/dist/src/adapters/local-command-retry.d.ts +12 -0
  16. package/dist/src/adapters/local-command-retry.d.ts.map +1 -0
  17. package/dist/src/adapters/local-command-retry.js +224 -0
  18. package/dist/src/adapters/local-command-retry.js.map +1 -0
  19. package/dist/src/adapters/local.d.ts +136 -0
  20. package/dist/src/adapters/local.d.ts.map +1 -0
  21. package/dist/src/adapters/local.js +1273 -0
  22. package/dist/src/adapters/local.js.map +1 -0
  23. package/dist/src/adapters/types.d.ts +45 -0
  24. package/dist/src/adapters/types.d.ts.map +1 -0
  25. package/dist/src/adapters/types.js +6 -0
  26. package/dist/src/adapters/types.js.map +1 -0
  27. package/dist/src/commands/actions.d.ts +135 -0
  28. package/dist/src/commands/actions.d.ts.map +1 -0
  29. package/dist/src/commands/actions.js +2207 -0
  30. package/dist/src/commands/actions.js.map +1 -0
  31. package/dist/src/commands/agent-init.d.ts +16 -0
  32. package/dist/src/commands/agent-init.d.ts.map +1 -0
  33. package/dist/src/commands/agent-init.js +222 -0
  34. package/dist/src/commands/agent-init.js.map +1 -0
  35. package/dist/src/commands/analyze.d.ts +11 -0
  36. package/dist/src/commands/analyze.d.ts.map +1 -0
  37. package/dist/src/commands/analyze.js +238 -0
  38. package/dist/src/commands/analyze.js.map +1 -0
  39. package/dist/src/commands/cache.d.ts +6 -0
  40. package/dist/src/commands/cache.d.ts.map +1 -0
  41. package/dist/src/commands/cache.js +147 -0
  42. package/dist/src/commands/cache.js.map +1 -0
  43. package/dist/src/commands/cloud.d.ts +6 -0
  44. package/dist/src/commands/cloud.d.ts.map +1 -0
  45. package/dist/src/commands/cloud.js +332 -0
  46. package/dist/src/commands/cloud.js.map +1 -0
  47. package/dist/src/commands/config.d.ts +7 -0
  48. package/dist/src/commands/config.d.ts.map +1 -0
  49. package/dist/src/commands/config.js +208 -0
  50. package/dist/src/commands/config.js.map +1 -0
  51. package/dist/src/commands/doctor.d.ts +127 -0
  52. package/dist/src/commands/doctor.d.ts.map +1 -0
  53. package/dist/src/commands/doctor.js +684 -0
  54. package/dist/src/commands/doctor.js.map +1 -0
  55. package/dist/src/commands/evaluate-helpers.d.ts +6 -0
  56. package/dist/src/commands/evaluate-helpers.d.ts.map +1 -0
  57. package/dist/src/commands/evaluate-helpers.js +13 -0
  58. package/dist/src/commands/evaluate-helpers.js.map +1 -0
  59. package/dist/src/commands/install.d.ts +118 -0
  60. package/dist/src/commands/install.d.ts.map +1 -0
  61. package/dist/src/commands/install.js +975 -0
  62. package/dist/src/commands/install.js.map +1 -0
  63. package/dist/src/commands/release.d.ts +7 -0
  64. package/dist/src/commands/release.d.ts.map +1 -0
  65. package/dist/src/commands/release.js +123 -0
  66. package/dist/src/commands/release.js.map +1 -0
  67. package/dist/src/commands/reset-connection.d.ts +17 -0
  68. package/dist/src/commands/reset-connection.d.ts.map +1 -0
  69. package/dist/src/commands/reset-connection.js +141 -0
  70. package/dist/src/commands/reset-connection.js.map +1 -0
  71. package/dist/src/commands/session-debug.d.ts +23 -0
  72. package/dist/src/commands/session-debug.d.ts.map +1 -0
  73. package/dist/src/commands/session-debug.js +267 -0
  74. package/dist/src/commands/session-debug.js.map +1 -0
  75. package/dist/src/commands/setup.d.ts +53 -0
  76. package/dist/src/commands/setup.d.ts.map +1 -0
  77. package/dist/src/commands/setup.js +249 -0
  78. package/dist/src/commands/setup.js.map +1 -0
  79. package/dist/src/config/store.d.ts +39 -0
  80. package/dist/src/config/store.d.ts.map +1 -0
  81. package/dist/src/config/store.js +290 -0
  82. package/dist/src/config/store.js.map +1 -0
  83. package/dist/src/daemon/access.d.ts +53 -0
  84. package/dist/src/daemon/access.d.ts.map +1 -0
  85. package/dist/src/daemon/access.js +87 -0
  86. package/dist/src/daemon/access.js.map +1 -0
  87. package/dist/src/daemon/bridge-envelope.d.ts +96 -0
  88. package/dist/src/daemon/bridge-envelope.d.ts.map +1 -0
  89. package/dist/src/daemon/bridge-envelope.js +235 -0
  90. package/dist/src/daemon/bridge-envelope.js.map +1 -0
  91. package/dist/src/daemon/utils.d.ts +43 -0
  92. package/dist/src/daemon/utils.d.ts.map +1 -0
  93. package/dist/src/daemon/utils.js +134 -0
  94. package/dist/src/daemon/utils.js.map +1 -0
  95. package/dist/src/errors.d.ts +60 -0
  96. package/dist/src/errors.d.ts.map +1 -0
  97. package/dist/src/errors.js +87 -0
  98. package/dist/src/errors.js.map +1 -0
  99. package/dist/src/local-bridge-timing.d.ts +31 -0
  100. package/dist/src/local-bridge-timing.d.ts.map +1 -0
  101. package/dist/src/local-bridge-timing.js +41 -0
  102. package/dist/src/local-bridge-timing.js.map +1 -0
  103. package/dist/src/obstacle-recovery/classify-script.d.ts +16 -0
  104. package/dist/src/obstacle-recovery/classify-script.d.ts.map +1 -0
  105. package/dist/src/obstacle-recovery/classify-script.js +53 -0
  106. package/dist/src/obstacle-recovery/classify-script.js.map +1 -0
  107. package/dist/src/obstacle-recovery/obstacle-classifier.d.ts +21 -0
  108. package/dist/src/obstacle-recovery/obstacle-classifier.d.ts.map +1 -0
  109. package/dist/src/obstacle-recovery/obstacle-classifier.js +37 -0
  110. package/dist/src/obstacle-recovery/obstacle-classifier.js.map +1 -0
  111. package/dist/src/obstacle-recovery/state-fingerprint.d.ts +26 -0
  112. package/dist/src/obstacle-recovery/state-fingerprint.d.ts.map +1 -0
  113. package/dist/src/obstacle-recovery/state-fingerprint.js +85 -0
  114. package/dist/src/obstacle-recovery/state-fingerprint.js.map +1 -0
  115. package/dist/src/obstacle-recovery/types.d.ts +44 -0
  116. package/dist/src/obstacle-recovery/types.d.ts.map +1 -0
  117. package/dist/src/obstacle-recovery/types.js +16 -0
  118. package/dist/src/obstacle-recovery/types.js.map +1 -0
  119. package/dist/src/output/formatter.d.ts +55 -0
  120. package/dist/src/output/formatter.d.ts.map +1 -0
  121. package/dist/src/output/formatter.js +55 -0
  122. package/dist/src/output/formatter.js.map +1 -0
  123. package/dist/src/output/mode.d.ts +11 -0
  124. package/dist/src/output/mode.d.ts.map +1 -0
  125. package/dist/src/output/mode.js +16 -0
  126. package/dist/src/output/mode.js.map +1 -0
  127. package/dist/src/protected-flow/detector.d.ts +26 -0
  128. package/dist/src/protected-flow/detector.d.ts.map +1 -0
  129. package/dist/src/protected-flow/detector.js +75 -0
  130. package/dist/src/protected-flow/detector.js.map +1 -0
  131. package/dist/src/protected-flow/types.d.ts +24 -0
  132. package/dist/src/protected-flow/types.d.ts.map +1 -0
  133. package/dist/src/protected-flow/types.js +28 -0
  134. package/dist/src/protected-flow/types.js.map +1 -0
  135. package/dist/src/session/agent-identity.d.ts +65 -0
  136. package/dist/src/session/agent-identity.d.ts.map +1 -0
  137. package/dist/src/session/agent-identity.js +133 -0
  138. package/dist/src/session/agent-identity.js.map +1 -0
  139. package/dist/src/session/cli-session-sync.d.ts +72 -0
  140. package/dist/src/session/cli-session-sync.d.ts.map +1 -0
  141. package/dist/src/session/cli-session-sync.js +244 -0
  142. package/dist/src/session/cli-session-sync.js.map +1 -0
  143. package/dist/src/session/context.d.ts +24 -0
  144. package/dist/src/session/context.d.ts.map +1 -0
  145. package/dist/src/session/context.js +165 -0
  146. package/dist/src/session/context.js.map +1 -0
  147. package/dist/src/session/continuity.d.ts +33 -0
  148. package/dist/src/session/continuity.d.ts.map +1 -0
  149. package/dist/src/session/continuity.js +179 -0
  150. package/dist/src/session/continuity.js.map +1 -0
  151. package/dist/src/session/errors.d.ts +9 -0
  152. package/dist/src/session/errors.d.ts.map +1 -0
  153. package/dist/src/session/errors.js +31 -0
  154. package/dist/src/session/errors.js.map +1 -0
  155. package/dist/src/session/local-continuity.d.ts +16 -0
  156. package/dist/src/session/local-continuity.d.ts.map +1 -0
  157. package/dist/src/session/local-continuity.js +146 -0
  158. package/dist/src/session/local-continuity.js.map +1 -0
  159. package/dist/src/session/signal-handler.d.ts +24 -0
  160. package/dist/src/session/signal-handler.d.ts.map +1 -0
  161. package/dist/src/session/signal-handler.js +35 -0
  162. package/dist/src/session/signal-handler.js.map +1 -0
  163. package/dist/src/shared/local-recovery-policy.d.ts +40 -0
  164. package/dist/src/shared/local-recovery-policy.d.ts.map +1 -0
  165. package/dist/src/shared/local-recovery-policy.js +59 -0
  166. package/dist/src/shared/local-recovery-policy.js.map +1 -0
  167. package/dist/src/shared/recovery-state.d.ts +3 -0
  168. package/dist/src/shared/recovery-state.d.ts.map +1 -0
  169. package/dist/src/shared/recovery-state.js +9 -0
  170. package/dist/src/shared/recovery-state.js.map +1 -0
  171. package/dist/src/types.d.ts +131 -0
  172. package/dist/src/types.d.ts.map +1 -0
  173. package/dist/src/types.js +5 -0
  174. package/dist/src/types.js.map +1 -0
  175. package/dist/src/utils.d.ts +50 -0
  176. package/dist/src/utils.d.ts.map +1 -0
  177. package/dist/src/utils.js +147 -0
  178. package/dist/src/utils.js.map +1 -0
  179. package/dist/src/working-location.d.ts +107 -0
  180. package/dist/src/working-location.d.ts.map +1 -0
  181. package/dist/src/working-location.js +651 -0
  182. package/dist/src/working-location.js.map +1 -0
  183. package/package.json +65 -0
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Shared TypeScript types for ThinkRun CLI
3
+ */
4
+ export interface SessionOptions {
5
+ browser?: 'chromium' | 'firefox' | 'webkit';
6
+ proxy?: boolean;
7
+ stealth?: boolean;
8
+ headless?: boolean;
9
+ }
10
+ export interface Session {
11
+ sessionId: string;
12
+ status: 'pending' | 'creating' | 'provisioning' | 'active' | 'ready' | 'running' | 'busy' | 'error' | 'failed' | 'terminated' | 'closed';
13
+ currentUrl?: string;
14
+ title?: string;
15
+ createdAt: string;
16
+ isFlyMachine?: boolean;
17
+ machineId?: string;
18
+ actionCount?: number;
19
+ }
20
+ export interface ActionResult {
21
+ success: boolean;
22
+ data?: any;
23
+ error?: string;
24
+ }
25
+ export interface NavigateOptions {
26
+ waitUntil?: 'load' | 'domcontentloaded' | 'networkidle';
27
+ timeout?: number;
28
+ waitFor?: string;
29
+ }
30
+ export interface ClickOptions {
31
+ button?: 'left' | 'right' | 'middle';
32
+ count?: number;
33
+ delay?: number;
34
+ timeout?: number;
35
+ }
36
+ export interface TypeOptions {
37
+ delay?: number;
38
+ clear?: boolean;
39
+ mask?: boolean;
40
+ }
41
+ export interface ScreenshotOptions {
42
+ output?: string;
43
+ fullPage?: boolean;
44
+ selector?: string;
45
+ format?: 'png' | 'jpeg' | 'webp';
46
+ quality?: number;
47
+ maxDimension?: number;
48
+ caption?: string;
49
+ }
50
+ export interface ExtractOptions {
51
+ all?: boolean;
52
+ attr?: string;
53
+ format?: 'text' | 'json' | 'html';
54
+ }
55
+ export interface WaitOptions {
56
+ visible?: boolean;
57
+ hidden?: boolean;
58
+ timeout?: number;
59
+ }
60
+ export interface CLIConfig {
61
+ apiKey?: string;
62
+ /** Quarantined schema-invalid apiKey value (PRD 0086 B1). */
63
+ apiKeyInvalid?: string;
64
+ apiUrl?: string;
65
+ defaultBrowser?: string;
66
+ extensionId?: string;
67
+ registeredExtensionId?: string;
68
+ preferPackagedDefaultExtensionId?: boolean;
69
+ nativeHostVersion?: string;
70
+ nativeHostChecksum?: string;
71
+ localTabId?: string;
72
+ localAgentSessionId?: string;
73
+ cloudSessionId?: string;
74
+ activeSessionId?: string;
75
+ agentSessionId?: string;
76
+ /**
77
+ * Local transport mode (PRD 0086 Track A).
78
+ * 'native' (default): use native messaging host (classic path, unchanged behaviour).
79
+ * 'daemon': route CLI/MCP requests through the bridge daemon process.
80
+ *
81
+ * Note: the daemon is only spawned when THINKRUN_DAEMON_SPIKE=1 env flag is set
82
+ * (THINKBROWSE_DAEMON_SPIKE is still accepted as a legacy fallback).
83
+ * (host-side gate). Wiring config→env automatically is a task 6.11 follow-up.
84
+ */
85
+ localTransport?: 'native' | 'daemon';
86
+ }
87
+ export interface OutputOptions {
88
+ json?: boolean;
89
+ quiet?: boolean;
90
+ verbose?: boolean;
91
+ }
92
+ export interface DialogResult {
93
+ success: boolean;
94
+ hasDialog?: boolean;
95
+ dialog?: {
96
+ type: string;
97
+ message: string;
98
+ defaultValue?: string;
99
+ } | null;
100
+ history?: Array<{
101
+ type: string;
102
+ message: string;
103
+ action: string;
104
+ timestamp: string;
105
+ }>;
106
+ error?: string;
107
+ }
108
+ export interface ConsoleResult {
109
+ success: boolean;
110
+ logs?: Array<{
111
+ level: string;
112
+ text: string;
113
+ timestamp?: string;
114
+ url?: string;
115
+ }>;
116
+ count?: number;
117
+ error?: string;
118
+ }
119
+ export interface NetworkResult {
120
+ success: boolean;
121
+ requests?: Array<{
122
+ url: string;
123
+ method: string;
124
+ status?: number;
125
+ type?: string;
126
+ size?: number;
127
+ }>;
128
+ count?: number;
129
+ error?: string;
130
+ }
131
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;I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/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Shared utility functions
3
+ */
4
+ /** Default next-step hint when cloud API authentication fails. */
5
+ export declare const API_KEY_HELP_FALLBACK = "Run `thinkrun doctor` or check your API key at https://thinkbrowse.io/settings";
6
+ export declare function handleError(error: any, command?: string, startMs?: number): never;
7
+ export declare function isLocalApiUrl(apiUrl: string): boolean;
8
+ export declare const DEFAULT_BRIDGE_PORT = 3012;
9
+ /**
10
+ * Longer timeout for cold-start / health GET /tabs checks (e.g. embed verify script).
11
+ * Interactive CLI bridge calls should use {@link BRIDGE_REQUEST_TIMEOUT_MS}.
12
+ */
13
+ export declare const BRIDGE_HEALTH_PROBE_TIMEOUT_MS = 30000;
14
+ /**
15
+ * Default timeout for routine HTTP calls to the local native-host bridge
16
+ * (tab list, tab switch, session register, tab validation, task status/cancel).
17
+ * Keeps failures responsive when the bridge is down (vs waiting for cold-start).
18
+ */
19
+ export declare const BRIDGE_REQUEST_TIMEOUT_MS = 10000;
20
+ /**
21
+ * Bridge evaluate responses sometimes nest the return value in `data.result`
22
+ * (native host / test doubles). Fingerprint capture and obstacle classification
23
+ * expect the unwrapped value. Only unwraps a plain `{ result: ... }` wrapper
24
+ * (sole own enumerable string key `result`) so objects that legitimately
25
+ * include other fields alongside `result` are left intact. Only one level is
26
+ * unwrapped per call.
27
+ */
28
+ export declare function unwrapEvaluatePayload(data: unknown): unknown;
29
+ /**
30
+ * Read the native host bridge port from ~/.thinkbrowse/port.
31
+ * This path is intentionally frozen during the internal pass.
32
+ * Falls back to DEFAULT_BRIDGE_PORT if the file is missing or unparseable.
33
+ * This utility is shared by the doctor, tabs, and attach commands.
34
+ */
35
+ export declare function readBridgePort(portFilePath?: string): number;
36
+ /**
37
+ * Modification time of `~/.thinkbrowse/port` when present (ms since epoch).
38
+ * This path is intentionally frozen during the internal pass.
39
+ * Used by `thinkrun doctor` to warn when the file may be stale after a port rotation.
40
+ */
41
+ export declare function getBridgePortFileMtimeMs(portFilePath?: string): number | null;
42
+ /**
43
+ * When the port file is older than `maxAgeMs` relative to `nowMs`, returns the file's age in ms;
44
+ * otherwise null (fresh or missing file — missing yields null from stat).
45
+ */
46
+ export declare function getStaleBridgePortFileAgeMs(mtimeMs: number | null, opts?: {
47
+ nowMs?: number;
48
+ maxAgeMs?: number;
49
+ }): number | null;
50
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,kEAAkE;AAClE,eAAO,MAAM,qBAAqB,mFACgD,CAAC;AAEnF,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CA0CjF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAQrD;AAED,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,8BAA8B,QAA8C,CAAC;AAE1F;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAyC,CAAC;AAEhF;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAS5D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,YAAY,SAA0C,GAAG,MAAM,CAY7F;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,SAA0C,GAAG,MAAM,GAAG,IAAI,CAM9G;AAID;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,MAAM,GAAG,IAAI,CAMf"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Shared utility functions
3
+ */
4
+ import chalk from 'chalk';
5
+ import { existsSync, readFileSync, statSync } from 'fs';
6
+ import { join } from 'path';
7
+ import { homedir } from 'os';
8
+ import { ApiError, SessionError, ThinkRunError } from './errors.js';
9
+ import { isJsonMode } from './output/mode.js';
10
+ import { LOCAL_BRIDGE_HEALTH_PROBE_TIMEOUT_MS as SHARED_LOCAL_BRIDGE_HEALTH_PROBE_TIMEOUT_MS, LOCAL_BRIDGE_REQUEST_TIMEOUT_MS as SHARED_LOCAL_BRIDGE_REQUEST_TIMEOUT_MS, } from './local-bridge-timing.js';
11
+ /** Default next-step hint when cloud API authentication fails. */
12
+ export const API_KEY_HELP_FALLBACK = 'Run `thinkrun doctor` or check your API key at https://thinkbrowse.io/settings';
13
+ export function handleError(error, command, startMs) {
14
+ const durationMs = startMs !== undefined ? Date.now() - startMs : undefined;
15
+ if (isJsonMode()) {
16
+ const envelope = { success: false };
17
+ if (command)
18
+ envelope.command = command;
19
+ if (durationMs !== undefined)
20
+ envelope.durationMs = durationMs;
21
+ if (error instanceof ThinkRunError) {
22
+ envelope.error = error.message;
23
+ envelope.code = (error instanceof ApiError && error.nativeCode)
24
+ ? error.nativeCode
25
+ : error.code;
26
+ if (error instanceof ApiError && error.retryable !== undefined) {
27
+ envelope.retryable = error.retryable;
28
+ }
29
+ if (error.suggestion)
30
+ envelope.hint = error.suggestion;
31
+ if (error instanceof ApiError && error.upgradeUrl) {
32
+ envelope.upgradeUrl = error.upgradeUrl;
33
+ }
34
+ }
35
+ else {
36
+ envelope.error = error.message || String(error);
37
+ envelope.code = 'INTERNAL_ERROR';
38
+ }
39
+ process.stderr.write(JSON.stringify(envelope) + '\n');
40
+ process.exit(1);
41
+ }
42
+ // TTY mode
43
+ if (error instanceof ApiError || error instanceof SessionError) {
44
+ console.error(chalk.red('Error:'), error.message);
45
+ if (error instanceof ApiError && error.nativeCode === 'INSUFFICIENT_SCOPE' && error.upgradeUrl) {
46
+ console.error(chalk.yellow('Upgrade:'), error.upgradeUrl);
47
+ }
48
+ if (error.suggestion) {
49
+ console.error(chalk.yellow('Tip:'), error.suggestion);
50
+ }
51
+ }
52
+ else {
53
+ console.error(chalk.red('Error:'), error.message || error);
54
+ }
55
+ process.exit(1);
56
+ }
57
+ export function isLocalApiUrl(apiUrl) {
58
+ try {
59
+ const u = new URL(apiUrl);
60
+ if (u.protocol !== 'http:' && u.protocol !== 'https:')
61
+ return false;
62
+ return u.hostname === 'localhost' || u.hostname === '127.0.0.1' || u.hostname === '[::1]';
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
68
+ export const DEFAULT_BRIDGE_PORT = 3012;
69
+ /**
70
+ * Longer timeout for cold-start / health GET /tabs checks (e.g. embed verify script).
71
+ * Interactive CLI bridge calls should use {@link BRIDGE_REQUEST_TIMEOUT_MS}.
72
+ */
73
+ export const BRIDGE_HEALTH_PROBE_TIMEOUT_MS = SHARED_LOCAL_BRIDGE_HEALTH_PROBE_TIMEOUT_MS;
74
+ /**
75
+ * Default timeout for routine HTTP calls to the local native-host bridge
76
+ * (tab list, tab switch, session register, tab validation, task status/cancel).
77
+ * Keeps failures responsive when the bridge is down (vs waiting for cold-start).
78
+ */
79
+ export const BRIDGE_REQUEST_TIMEOUT_MS = SHARED_LOCAL_BRIDGE_REQUEST_TIMEOUT_MS;
80
+ /**
81
+ * Bridge evaluate responses sometimes nest the return value in `data.result`
82
+ * (native host / test doubles). Fingerprint capture and obstacle classification
83
+ * expect the unwrapped value. Only unwraps a plain `{ result: ... }` wrapper
84
+ * (sole own enumerable string key `result`) so objects that legitimately
85
+ * include other fields alongside `result` are left intact. Only one level is
86
+ * unwrapped per call.
87
+ */
88
+ export function unwrapEvaluatePayload(data) {
89
+ if (data === null || data === undefined)
90
+ return data;
91
+ if (typeof data !== 'object')
92
+ return data;
93
+ const o = data;
94
+ const keys = Object.keys(o);
95
+ if (keys.length === 1 && Object.prototype.hasOwnProperty.call(o, 'result')) {
96
+ return o.result;
97
+ }
98
+ return data;
99
+ }
100
+ /**
101
+ * Read the native host bridge port from ~/.thinkbrowse/port.
102
+ * This path is intentionally frozen during the internal pass.
103
+ * Falls back to DEFAULT_BRIDGE_PORT if the file is missing or unparseable.
104
+ * This utility is shared by the doctor, tabs, and attach commands.
105
+ */
106
+ export function readBridgePort(portFilePath = join(homedir(), '.thinkbrowse', 'port')) {
107
+ if (!existsSync(portFilePath))
108
+ return DEFAULT_BRIDGE_PORT;
109
+ try {
110
+ const raw = readFileSync(portFilePath, 'utf-8').trim();
111
+ const parsed = Number(raw);
112
+ if (Number.isInteger(parsed) && parsed > 0 && parsed <= 65535) {
113
+ return parsed;
114
+ }
115
+ }
116
+ catch {
117
+ // ignore
118
+ }
119
+ return DEFAULT_BRIDGE_PORT;
120
+ }
121
+ /**
122
+ * Modification time of `~/.thinkbrowse/port` when present (ms since epoch).
123
+ * This path is intentionally frozen during the internal pass.
124
+ * Used by `thinkrun doctor` to warn when the file may be stale after a port rotation.
125
+ */
126
+ export function getBridgePortFileMtimeMs(portFilePath = join(homedir(), '.thinkbrowse', 'port')) {
127
+ try {
128
+ return statSync(portFilePath).mtimeMs;
129
+ }
130
+ catch {
131
+ return null;
132
+ }
133
+ }
134
+ const DEFAULT_STALE_BRIDGE_PORT_FILE_MS = 5 * 60 * 1000;
135
+ /**
136
+ * When the port file is older than `maxAgeMs` relative to `nowMs`, returns the file's age in ms;
137
+ * otherwise null (fresh or missing file — missing yields null from stat).
138
+ */
139
+ export function getStaleBridgePortFileAgeMs(mtimeMs, opts) {
140
+ if (mtimeMs === null)
141
+ return null;
142
+ const nowMs = opts?.nowMs ?? Date.now();
143
+ const maxAgeMs = opts?.maxAgeMs ?? DEFAULT_STALE_BRIDGE_PORT_FILE_MS;
144
+ const ageMs = nowMs - mtimeMs;
145
+ return ageMs > maxAgeMs ? ageMs : null;
146
+ }
147
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/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,GAAG,IAAI,EAAE,QAAQ,IAAI,iCAAiC,CAAC;IACrE,MAAM,KAAK,GAAG,KAAK,GAAG,OAAO,CAAC;IAC9B,OAAO,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Working location and per-tab lock file management for CLI agent isolation.
3
+ *
4
+ * Each agent process that calls `thinkrun attach` or `thinkrun new-window`
5
+ * acquires an exclusive lock on the target Chrome tab so that two agents running
6
+ * simultaneously cannot clash on the same tab.
7
+ *
8
+ * Files written under `~/.thinkrun/` (or THINKRUN_LOCK_DIR in tests):
9
+ * locks/{tabId}.lock — who currently owns this tab (persists across commands)
10
+ * working-location.json — which tab this agent is currently using (shared, stable)
11
+ * groups/{name}.lock — named group pointing to a tab
12
+ *
13
+ * The working-location file uses a stable name (not PID-scoped) so that separate
14
+ * CLI command invocations (each a new process) can share the same attachment
15
+ * context. It is written by `attach`/`new-window` and removed only by an explicit
16
+ * `thinkrun release`. The lock files follow the same lease semantics: they
17
+ * persist until explicitly released or stale-lock detection overwrites them.
18
+ *
19
+ * During the internal rebrand pass, we still fall back to legacy
20
+ * `THINKBROWSE_LOCK_DIR` / `~/.thinkbrowse/` state if the new dir is not
21
+ * established yet.
22
+ */
23
+ export interface WorkingLocation {
24
+ tabId: number;
25
+ windowId?: number;
26
+ group?: string;
27
+ controlSessionId?: string;
28
+ pid: number;
29
+ /** Stable agent identifier — persists across all CLI invocations within an agent session. */
30
+ agentId?: string;
31
+ /** PID of the shell that invoked thinkrun — alive for the entire terminal session. */
32
+ ownerShellPid?: number;
33
+ setAt: string;
34
+ }
35
+ export interface ReclaimAuditEntry {
36
+ tabId: number;
37
+ reclaimedAt: string;
38
+ reclaimedByAgentId: string;
39
+ reason: 'stale_owner_shell' | 'stale_pid_legacy' | 'corrupt_existing_lock';
40
+ previousAgentId?: string;
41
+ previousPid?: number;
42
+ previousOwnerShellPid?: number;
43
+ previousControlSessionId?: string;
44
+ }
45
+ /** Path to the per-tab CLI session persistence file.
46
+ * Stored alongside other lock files so THINKRUN_LOCK_DIR / THINKBROWSE_LOCK_DIR
47
+ * test isolation applies.
48
+ * tabId is sanitized (alphanumeric + hyphens/underscores only) to prevent path traversal. */
49
+ export declare function getCliSessionFilePath(tabId: string | number): string;
50
+ export declare function getLastReclaimAudit(): ReclaimAuditEntry | null;
51
+ /**
52
+ * Acquire an exclusive lock on `tabId`. Throws with message starting
53
+ * `TAB_LOCKED:` if the tab is already locked by a live agent or PID.
54
+ * If the existing lock is stale (owner dead), it is silently overwritten.
55
+ *
56
+ * Ownership logic:
57
+ * 1. Same agentId → re-acquire (same agent, different invocation)
58
+ * 2. Different agentId → check ownerShellPid liveness
59
+ * alive → BLOCK: TAB_LOCKED with agent info
60
+ * dead → stale → overwrite
61
+ * 3. No agentId in existing lock → fall back to PID-based logic (backward compat)
62
+ */
63
+ export declare function acquireLock(tabId: number, group?: string): void;
64
+ /**
65
+ * Release the lock for `tabId`. No-op if the file doesn't exist.
66
+ *
67
+ * A lock can be released when:
68
+ * - This process's PID matches the lock's pid, OR
69
+ * - This process's agentId matches the lock's agentId (same agent, different invocation)
70
+ */
71
+ export declare function releaseLock(tabId: number): void;
72
+ /**
73
+ * Returns true when no live process holds the lock for `tabId`
74
+ * (either no lock file exists, or the locking PID is dead).
75
+ */
76
+ export declare function isLockStale(tabId: number): boolean;
77
+ /**
78
+ * Returns the WorkingLocation stored in the lock file for `tabId`, or null.
79
+ * Does not check whether the locking PID is alive.
80
+ */
81
+ export declare function getLockedBy(tabId: number): WorkingLocation | null;
82
+ /**
83
+ * Set the working location for this process.
84
+ * Acquires a lock on `tabId` (throws TAB_LOCKED if another live PID owns it)
85
+ * and writes the stable working-location file for cross-command persistence.
86
+ */
87
+ export declare function setWorkingLocation(loc: Omit<WorkingLocation, 'pid' | 'setAt'>): void;
88
+ /**
89
+ * Update the control-session identifier for the currently owned working location.
90
+ * Best-effort: no-op when no working location exists.
91
+ */
92
+ export declare function updateWorkingLocationControlSession(controlSessionId: string): void;
93
+ /**
94
+ * Return the working location for this process.
95
+ * Checks in-process memory first, then falls back to the on-disk file.
96
+ */
97
+ export declare function getWorkingLocation(): WorkingLocation | null;
98
+ /**
99
+ * Release the working location for this process (and optionally a named group).
100
+ * Deletes the lock file for the current tab and the working-location file.
101
+ *
102
+ * When `group` is provided and working-location.json is absent (e.g. after a
103
+ * crash or on a different machine), the group file itself is used to look up
104
+ * the tabId so the lock can be released by group name alone.
105
+ */
106
+ export declare function releaseWorkingLocation(group?: string): void;
107
+ //# sourceMappingURL=working-location.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"working-location.d.ts","sourceRoot":"","sources":["../../src/working-location.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAOH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC;AAsCD;;;8FAG8F;AAC9F,wB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