@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.
- package/README.md +349 -0
- package/dist/bin/thinkrun.d.ts +6 -0
- package/dist/bin/thinkrun.d.ts.map +1 -0
- package/dist/bin/thinkrun.js +124 -0
- package/dist/bin/thinkrun.js.map +1 -0
- package/dist/scripts/browse.sh +1107 -0
- package/dist/src/adapters/cloud.d.ts +79 -0
- package/dist/src/adapters/cloud.d.ts.map +1 -0
- package/dist/src/adapters/cloud.js +637 -0
- package/dist/src/adapters/cloud.js.map +1 -0
- package/dist/src/adapters/index.d.ts +47 -0
- package/dist/src/adapters/index.d.ts.map +1 -0
- package/dist/src/adapters/index.js +211 -0
- package/dist/src/adapters/index.js.map +1 -0
- package/dist/src/adapters/local-command-retry.d.ts +12 -0
- package/dist/src/adapters/local-command-retry.d.ts.map +1 -0
- package/dist/src/adapters/local-command-retry.js +224 -0
- package/dist/src/adapters/local-command-retry.js.map +1 -0
- package/dist/src/adapters/local.d.ts +136 -0
- package/dist/src/adapters/local.d.ts.map +1 -0
- package/dist/src/adapters/local.js +1273 -0
- package/dist/src/adapters/local.js.map +1 -0
- package/dist/src/adapters/types.d.ts +45 -0
- package/dist/src/adapters/types.d.ts.map +1 -0
- package/dist/src/adapters/types.js +6 -0
- package/dist/src/adapters/types.js.map +1 -0
- package/dist/src/commands/actions.d.ts +135 -0
- package/dist/src/commands/actions.d.ts.map +1 -0
- package/dist/src/commands/actions.js +2207 -0
- package/dist/src/commands/actions.js.map +1 -0
- package/dist/src/commands/agent-init.d.ts +16 -0
- package/dist/src/commands/agent-init.d.ts.map +1 -0
- package/dist/src/commands/agent-init.js +222 -0
- package/dist/src/commands/agent-init.js.map +1 -0
- package/dist/src/commands/analyze.d.ts +11 -0
- package/dist/src/commands/analyze.d.ts.map +1 -0
- package/dist/src/commands/analyze.js +238 -0
- package/dist/src/commands/analyze.js.map +1 -0
- package/dist/src/commands/cache.d.ts +6 -0
- package/dist/src/commands/cache.d.ts.map +1 -0
- package/dist/src/commands/cache.js +147 -0
- package/dist/src/commands/cache.js.map +1 -0
- package/dist/src/commands/cloud.d.ts +6 -0
- package/dist/src/commands/cloud.d.ts.map +1 -0
- package/dist/src/commands/cloud.js +332 -0
- package/dist/src/commands/cloud.js.map +1 -0
- package/dist/src/commands/config.d.ts +7 -0
- package/dist/src/commands/config.d.ts.map +1 -0
- package/dist/src/commands/config.js +208 -0
- package/dist/src/commands/config.js.map +1 -0
- package/dist/src/commands/doctor.d.ts +127 -0
- package/dist/src/commands/doctor.d.ts.map +1 -0
- package/dist/src/commands/doctor.js +684 -0
- package/dist/src/commands/doctor.js.map +1 -0
- package/dist/src/commands/evaluate-helpers.d.ts +6 -0
- package/dist/src/commands/evaluate-helpers.d.ts.map +1 -0
- package/dist/src/commands/evaluate-helpers.js +13 -0
- package/dist/src/commands/evaluate-helpers.js.map +1 -0
- package/dist/src/commands/install.d.ts +118 -0
- package/dist/src/commands/install.d.ts.map +1 -0
- package/dist/src/commands/install.js +975 -0
- package/dist/src/commands/install.js.map +1 -0
- package/dist/src/commands/release.d.ts +7 -0
- package/dist/src/commands/release.d.ts.map +1 -0
- package/dist/src/commands/release.js +123 -0
- package/dist/src/commands/release.js.map +1 -0
- package/dist/src/commands/reset-connection.d.ts +17 -0
- package/dist/src/commands/reset-connection.d.ts.map +1 -0
- package/dist/src/commands/reset-connection.js +141 -0
- package/dist/src/commands/reset-connection.js.map +1 -0
- package/dist/src/commands/session-debug.d.ts +23 -0
- package/dist/src/commands/session-debug.d.ts.map +1 -0
- package/dist/src/commands/session-debug.js +267 -0
- package/dist/src/commands/session-debug.js.map +1 -0
- package/dist/src/commands/setup.d.ts +53 -0
- package/dist/src/commands/setup.d.ts.map +1 -0
- package/dist/src/commands/setup.js +249 -0
- package/dist/src/commands/setup.js.map +1 -0
- package/dist/src/config/store.d.ts +39 -0
- package/dist/src/config/store.d.ts.map +1 -0
- package/dist/src/config/store.js +290 -0
- package/dist/src/config/store.js.map +1 -0
- package/dist/src/daemon/access.d.ts +53 -0
- package/dist/src/daemon/access.d.ts.map +1 -0
- package/dist/src/daemon/access.js +87 -0
- package/dist/src/daemon/access.js.map +1 -0
- package/dist/src/daemon/bridge-envelope.d.ts +96 -0
- package/dist/src/daemon/bridge-envelope.d.ts.map +1 -0
- package/dist/src/daemon/bridge-envelope.js +235 -0
- package/dist/src/daemon/bridge-envelope.js.map +1 -0
- package/dist/src/daemon/utils.d.ts +43 -0
- package/dist/src/daemon/utils.d.ts.map +1 -0
- package/dist/src/daemon/utils.js +134 -0
- package/dist/src/daemon/utils.js.map +1 -0
- package/dist/src/errors.d.ts +60 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +87 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/local-bridge-timing.d.ts +31 -0
- package/dist/src/local-bridge-timing.d.ts.map +1 -0
- package/dist/src/local-bridge-timing.js +41 -0
- package/dist/src/local-bridge-timing.js.map +1 -0
- package/dist/src/obstacle-recovery/classify-script.d.ts +16 -0
- package/dist/src/obstacle-recovery/classify-script.d.ts.map +1 -0
- package/dist/src/obstacle-recovery/classify-script.js +53 -0
- package/dist/src/obstacle-recovery/classify-script.js.map +1 -0
- package/dist/src/obstacle-recovery/obstacle-classifier.d.ts +21 -0
- package/dist/src/obstacle-recovery/obstacle-classifier.d.ts.map +1 -0
- package/dist/src/obstacle-recovery/obstacle-classifier.js +37 -0
- package/dist/src/obstacle-recovery/obstacle-classifier.js.map +1 -0
- package/dist/src/obstacle-recovery/state-fingerprint.d.ts +26 -0
- package/dist/src/obstacle-recovery/state-fingerprint.d.ts.map +1 -0
- package/dist/src/obstacle-recovery/state-fingerprint.js +85 -0
- package/dist/src/obstacle-recovery/state-fingerprint.js.map +1 -0
- package/dist/src/obstacle-recovery/types.d.ts +44 -0
- package/dist/src/obstacle-recovery/types.d.ts.map +1 -0
- package/dist/src/obstacle-recovery/types.js +16 -0
- package/dist/src/obstacle-recovery/types.js.map +1 -0
- package/dist/src/output/formatter.d.ts +55 -0
- package/dist/src/output/formatter.d.ts.map +1 -0
- package/dist/src/output/formatter.js +55 -0
- package/dist/src/output/formatter.js.map +1 -0
- package/dist/src/output/mode.d.ts +11 -0
- package/dist/src/output/mode.d.ts.map +1 -0
- package/dist/src/output/mode.js +16 -0
- package/dist/src/output/mode.js.map +1 -0
- package/dist/src/protected-flow/detector.d.ts +26 -0
- package/dist/src/protected-flow/detector.d.ts.map +1 -0
- package/dist/src/protected-flow/detector.js +75 -0
- package/dist/src/protected-flow/detector.js.map +1 -0
- package/dist/src/protected-flow/types.d.ts +24 -0
- package/dist/src/protected-flow/types.d.ts.map +1 -0
- package/dist/src/protected-flow/types.js +28 -0
- package/dist/src/protected-flow/types.js.map +1 -0
- package/dist/src/session/agent-identity.d.ts +65 -0
- package/dist/src/session/agent-identity.d.ts.map +1 -0
- package/dist/src/session/agent-identity.js +133 -0
- package/dist/src/session/agent-identity.js.map +1 -0
- package/dist/src/session/cli-session-sync.d.ts +72 -0
- package/dist/src/session/cli-session-sync.d.ts.map +1 -0
- package/dist/src/session/cli-session-sync.js +244 -0
- package/dist/src/session/cli-session-sync.js.map +1 -0
- package/dist/src/session/context.d.ts +24 -0
- package/dist/src/session/context.d.ts.map +1 -0
- package/dist/src/session/context.js +165 -0
- package/dist/src/session/context.js.map +1 -0
- package/dist/src/session/continuity.d.ts +33 -0
- package/dist/src/session/continuity.d.ts.map +1 -0
- package/dist/src/session/continuity.js +179 -0
- package/dist/src/session/continuity.js.map +1 -0
- package/dist/src/session/errors.d.ts +9 -0
- package/dist/src/session/errors.d.ts.map +1 -0
- package/dist/src/session/errors.js +31 -0
- package/dist/src/session/errors.js.map +1 -0
- package/dist/src/session/local-continuity.d.ts +16 -0
- package/dist/src/session/local-continuity.d.ts.map +1 -0
- package/dist/src/session/local-continuity.js +146 -0
- package/dist/src/session/local-continuity.js.map +1 -0
- package/dist/src/session/signal-handler.d.ts +24 -0
- package/dist/src/session/signal-handler.d.ts.map +1 -0
- package/dist/src/session/signal-handler.js +35 -0
- package/dist/src/session/signal-handler.js.map +1 -0
- package/dist/src/shared/local-recovery-policy.d.ts +40 -0
- package/dist/src/shared/local-recovery-policy.d.ts.map +1 -0
- package/dist/src/shared/local-recovery-policy.js +59 -0
- package/dist/src/shared/local-recovery-policy.js.map +1 -0
- package/dist/src/shared/recovery-state.d.ts +3 -0
- package/dist/src/shared/recovery-state.d.ts.map +1 -0
- package/dist/src/shared/recovery-state.js +9 -0
- package/dist/src/shared/recovery-state.js.map +1 -0
- package/dist/src/types.d.ts +131 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +5 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +50 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +147 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/working-location.d.ts +107 -0
- package/dist/src/working-location.d.ts.map +1 -0
- package/dist/src/working-location.js +651 -0
- package/dist/src/working-location.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protected-flow classification: detect when an action did not change state or hit a protected element.
|
|
3
|
+
*/
|
|
4
|
+
import { createBlockedOutcome } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Classify a bridge result into a blocked outcome when the bridge signals blocked.
|
|
7
|
+
* Returns null when the result does not indicate a blocked flow.
|
|
8
|
+
*/
|
|
9
|
+
export function classifyFromBridgeResult(data) {
|
|
10
|
+
if (!data || typeof data !== 'object')
|
|
11
|
+
return null;
|
|
12
|
+
const hint = data;
|
|
13
|
+
if (!hint.blocked)
|
|
14
|
+
return null;
|
|
15
|
+
const category = normalizeCategory(hint.blockedReason);
|
|
16
|
+
const handoffRequired = hint.handoffRequired ?? category === 'secure_hosted_field';
|
|
17
|
+
return createBlockedOutcome(category, {
|
|
18
|
+
handoffRequired,
|
|
19
|
+
target: hint.target,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function normalizeCategory(reason) {
|
|
23
|
+
if (reason === 'secure_hosted_field' || reason === 'no_op_click' ||
|
|
24
|
+
reason === 'custom_widget_mismatch' || reason === 'low_confidence') {
|
|
25
|
+
return reason;
|
|
26
|
+
}
|
|
27
|
+
if (typeof reason === 'string' && /hosted|secure|iframe|payment|auth/i.test(reason)) {
|
|
28
|
+
return 'secure_hosted_field';
|
|
29
|
+
}
|
|
30
|
+
if (typeof reason === 'string' && /no.?op|no.?change|unchanged/i.test(reason)) {
|
|
31
|
+
return 'no_op_click';
|
|
32
|
+
}
|
|
33
|
+
return 'low_confidence';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Classify from pre/post state comparison using StateFingerprint objects.
|
|
37
|
+
* Detects no-op actions by comparing page state before and after the action.
|
|
38
|
+
*
|
|
39
|
+
* Returns null if states differ (action had an effect) or if fingerprints are missing.
|
|
40
|
+
* Returns BlockedOutcome with 'no_op_click' if page state is unchanged.
|
|
41
|
+
*/
|
|
42
|
+
export function classifyFromStateCheck(actionType, preState, postState) {
|
|
43
|
+
if (preState === undefined || postState === undefined)
|
|
44
|
+
return null;
|
|
45
|
+
// Support legacy string comparison (backward compat)
|
|
46
|
+
if (typeof preState === 'string' || typeof postState === 'string') {
|
|
47
|
+
if (preState !== postState)
|
|
48
|
+
return null;
|
|
49
|
+
return createBlockedOutcome('no_op_click', { handoffRequired: false });
|
|
50
|
+
}
|
|
51
|
+
// URL changed → navigation occurred, action had an effect
|
|
52
|
+
if (preState.url !== postState.url)
|
|
53
|
+
return null;
|
|
54
|
+
// Title changed → page updated
|
|
55
|
+
if (preState.title !== postState.title)
|
|
56
|
+
return null;
|
|
57
|
+
// Form values changed → input had an effect
|
|
58
|
+
if (preState.formValues !== postState.formValues)
|
|
59
|
+
return null;
|
|
60
|
+
// Focused element changed → interaction had an effect
|
|
61
|
+
if (preState.focusedElement !== postState.focusedElement)
|
|
62
|
+
return null;
|
|
63
|
+
// Target hash changed → visible content near target updated
|
|
64
|
+
if (preState.targetHash !== undefined && postState.targetHash !== undefined &&
|
|
65
|
+
preState.targetHash !== postState.targetHash)
|
|
66
|
+
return null;
|
|
67
|
+
// Nothing changed — this was a no-op.
|
|
68
|
+
// Use action-specific message for non-click actions.
|
|
69
|
+
const outcome = createBlockedOutcome('no_op_click', { handoffRequired: false });
|
|
70
|
+
if (actionType !== 'click') {
|
|
71
|
+
outcome.message = `${actionType} did not change page state. The element may be unresponsive.`;
|
|
72
|
+
}
|
|
73
|
+
return outcome;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../src/protected-flow/detector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAWlD;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAa;IAEb,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACnD,MAAM,IAAI,GAAG,IAAyB,CAAC;IACvC,IAAI,CAAC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE/B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACvD,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,QAAQ,KAAK,qBAAqB,CAAC;IACnF,OAAO,oBAAoB,CAAC,QAAQ,EAAE;QACpC,eAAe;QACf,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAe;IACxC,IAAI,MAAM,KAAK,qBAAqB,IAAI,MAAM,KAAK,aAAa;QAC5D,MAAM,KAAK,wBAAwB,IAAI,MAAM,KAAK,gBAAgB,EAAE,CAAC;QACvE,OAAO,MAAM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KAAK,SAAS,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAE9D,sCAAsC;IACtC,qDAAqD;IACrD,MAAM,OAAO,GAAG,oBAAoB,CAAC,aAAa,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;IAChF,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,OAAO,CAAC,OAAO,GAAG,GAAG,UAAU,8DAA8D,CAAC;IAChG,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured outcomes for protected flows (hosted payment, auth, no-op interactions).
|
|
3
|
+
* Enables detect-and-stop semantics and human handoff instead of false success.
|
|
4
|
+
*/
|
|
5
|
+
/** Why an action was blocked. */
|
|
6
|
+
export type BlockerCategory = 'secure_hosted_field' | 'no_op_click' | 'custom_widget_mismatch' | 'low_confidence';
|
|
7
|
+
/** Structured blocked outcome — return this instead of success when automation cannot progress. */
|
|
8
|
+
export interface BlockedOutcome {
|
|
9
|
+
success: false;
|
|
10
|
+
blocked: true;
|
|
11
|
+
handoffRequired: boolean;
|
|
12
|
+
category: BlockerCategory;
|
|
13
|
+
message: string;
|
|
14
|
+
/** Optional selector or target that was blocked. */
|
|
15
|
+
target?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function isBlockedOutcome(value: unknown): value is BlockedOutcome;
|
|
18
|
+
/** Human-facing message for each category. */
|
|
19
|
+
export declare const BLOCKER_MESSAGES: Record<BlockerCategory, string>;
|
|
20
|
+
export declare function createBlockedOutcome(category: BlockerCategory, options?: {
|
|
21
|
+
handoffRequired?: boolean;
|
|
22
|
+
target?: string;
|
|
23
|
+
}): BlockedOutcome;
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/protected-flow/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iCAAiC;AACjC,MAAM,MAAM,eAAe,GACvB,qBAAqB,GACrB,aAAa,GACb,wBAAwB,GACxB,gBAAgB,CAAC;AAErB,mGAAmG;AACnG,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,IAAI,CAAC;IACd,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,eAAe,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAOxE;AAED,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAK5D,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,eAAe,EACzB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC3D,cAAc,CAShB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured outcomes for protected flows (hosted payment, auth, no-op interactions).
|
|
3
|
+
* Enables detect-and-stop semantics and human handoff instead of false success.
|
|
4
|
+
*/
|
|
5
|
+
export function isBlockedOutcome(value) {
|
|
6
|
+
return (typeof value === 'object' &&
|
|
7
|
+
value !== null &&
|
|
8
|
+
value.success === false &&
|
|
9
|
+
value.blocked === true);
|
|
10
|
+
}
|
|
11
|
+
/** Human-facing message for each category. */
|
|
12
|
+
export const BLOCKER_MESSAGES = {
|
|
13
|
+
secure_hosted_field: 'Secure payment or auth field detected. Human input required.',
|
|
14
|
+
no_op_click: 'Click did not change page state. The element may be in a protected iframe or unresponsive.',
|
|
15
|
+
custom_widget_mismatch: 'Custom widget did not respond to the action. Human input may be required.',
|
|
16
|
+
low_confidence: 'Interaction path is uncertain. Consider completing this step manually.',
|
|
17
|
+
};
|
|
18
|
+
export function createBlockedOutcome(category, options = {}) {
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
blocked: true,
|
|
22
|
+
handoffRequired: options.handoffRequired ?? category === 'secure_hosted_field',
|
|
23
|
+
category,
|
|
24
|
+
message: BLOCKER_MESSAGES[category],
|
|
25
|
+
target: options.target,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/protected-flow/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAwB,CAAC,OAAO,KAAK,KAAK;QAC1C,KAAwB,CAAC,OAAO,KAAK,IAAI,CAC3C,CAAC;AACJ,CAAC;AAED,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAoC;IAC/D,mBAAmB,EAAE,8DAA8D;IACnF,WAAW,EAAE,4FAA4F;IACzG,sBAAsB,EAAE,2EAA2E;IACnG,cAAc,EAAE,wEAAwE;CACzF,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAClC,QAAyB,EACzB,UAA0D,EAAE;IAE5D,OAAO;QACL,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,IAAI;QACb,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,QAAQ,KAAK,qBAAqB;QAC9E,QAAQ;QACR,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC;QACnC,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent identity — persistent `agentId` for stable tab ownership across CLI invocations.
|
|
3
|
+
*
|
|
4
|
+
* Each agent gets a stable `agentId` (prefix `agt_` + 12 hex chars) stored in
|
|
5
|
+
* `~/.thinkrun/agent.json` (or `THINKRUN_LOCK_DIR/agent.json` for tests).
|
|
6
|
+
* During the internal rebrand pass, we still fall back to legacy
|
|
7
|
+
* `THINKBROWSE_LOCK_DIR` / `~/.thinkbrowse/agent.json` if the new dir is not
|
|
8
|
+
* established yet.
|
|
9
|
+
* This ID persists across all CLI commands so the lock system can distinguish
|
|
10
|
+
* "same agent, new command" from "different competing agent".
|
|
11
|
+
*
|
|
12
|
+
* Resolution order for `resolveAgentId()`:
|
|
13
|
+
* 1. `THINKRUN_AGENT_ID` env var
|
|
14
|
+
* (`THINKBROWSE_AGENT_ID` legacy fallback)
|
|
15
|
+
* 2. `agent.json` on disk
|
|
16
|
+
* 3. Auto-created persistent local identity in `agent.json`
|
|
17
|
+
*
|
|
18
|
+
* Only callers that explicitly opt out of persistence should ever see the
|
|
19
|
+
* legacy ephemeral fallback.
|
|
20
|
+
*/
|
|
21
|
+
/** Persistent agent identity stored in `~/.thinkrun/agent.json`. */
|
|
22
|
+
export interface AgentIdentity {
|
|
23
|
+
/** Stable local identifier: `agt_` + 12 lowercase hex chars. */
|
|
24
|
+
agentId: string;
|
|
25
|
+
/** Optional human-readable label shown in the activity feed. */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** ISO timestamp of when this identity was first created. */
|
|
28
|
+
createdAt: string;
|
|
29
|
+
/** UUID returned by `POST /api/agents` when registered with ThinkRun cloud. */
|
|
30
|
+
cloudAgentId?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Path to the agent identity file.
|
|
33
|
+
* Uses `THINKRUN_LOCK_DIR` (with legacy THINKBROWSE_LOCK_DIR fallback) so
|
|
34
|
+
* test isolation applies automatically. */
|
|
35
|
+
export declare function getAgentFilePath(): string;
|
|
36
|
+
/** Generate a new agent ID: `agt_` followed by 12 lowercase hex characters. */
|
|
37
|
+
export declare function generateAgentId(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Persist an agent identity to disk.
|
|
40
|
+
* Writes atomically via a temp file + rename to prevent torn writes.
|
|
41
|
+
*/
|
|
42
|
+
export declare function saveAgentIdentity(identity: AgentIdentity): void;
|
|
43
|
+
/**
|
|
44
|
+
* Load the saved agent identity from disk.
|
|
45
|
+
* Returns `null` if the file is absent or malformed — never throws.
|
|
46
|
+
*/
|
|
47
|
+
export declare function loadAgentIdentity(): AgentIdentity | null;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the agent ID for the current invocation.
|
|
50
|
+
*
|
|
51
|
+
* Priority:
|
|
52
|
+
* 1. `THINKRUN_AGENT_ID` environment variable (explicit override)
|
|
53
|
+
* with `THINKBROWSE_AGENT_ID` as a legacy fallback
|
|
54
|
+
* 2. `agentId` from `~/.thinkrun/agent.json` (persistent, created by `agent-init`
|
|
55
|
+
* or auto-created on first use)
|
|
56
|
+
* 3. Legacy ephemeral fallback derived from `process.ppid` only when the caller
|
|
57
|
+
* explicitly disables persistence
|
|
58
|
+
*
|
|
59
|
+
* By default the CLI auto-creates and persists a stable local agent identity on
|
|
60
|
+
* first use so the no-explicit-ID path still has durable same-controller continuity.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveAgentId(options?: {
|
|
63
|
+
persistIfMissing?: boolean;
|
|
64
|
+
}): string;
|
|
65
|
+
//# sourceMappingURL=agent-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-identity.d.ts","sourceRoot":"","sources":["../../../src/session/agent-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAgBD;;4CAE4C;AAC5C,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAID,+EAA+E;AAC/E,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAmBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAI/D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,GAAG,IAAI,CAUxD;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CA2B/E"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent identity — persistent `agentId` for stable tab ownership across CLI invocations.
|
|
3
|
+
*
|
|
4
|
+
* Each agent gets a stable `agentId` (prefix `agt_` + 12 hex chars) stored in
|
|
5
|
+
* `~/.thinkrun/agent.json` (or `THINKRUN_LOCK_DIR/agent.json` for tests).
|
|
6
|
+
* During the internal rebrand pass, we still fall back to legacy
|
|
7
|
+
* `THINKBROWSE_LOCK_DIR` / `~/.thinkbrowse/agent.json` if the new dir is not
|
|
8
|
+
* established yet.
|
|
9
|
+
* This ID persists across all CLI commands so the lock system can distinguish
|
|
10
|
+
* "same agent, new command" from "different competing agent".
|
|
11
|
+
*
|
|
12
|
+
* Resolution order for `resolveAgentId()`:
|
|
13
|
+
* 1. `THINKRUN_AGENT_ID` env var
|
|
14
|
+
* (`THINKBROWSE_AGENT_ID` legacy fallback)
|
|
15
|
+
* 2. `agent.json` on disk
|
|
16
|
+
* 3. Auto-created persistent local identity in `agent.json`
|
|
17
|
+
*
|
|
18
|
+
* Only callers that explicitly opt out of persistence should ever see the
|
|
19
|
+
* legacy ephemeral fallback.
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync, readFileSync, mkdirSync, writeFileSync, renameSync, rmSync } from 'node:fs';
|
|
22
|
+
import { randomBytes } from 'node:crypto';
|
|
23
|
+
import { homedir } from 'node:os';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
// ─── Directory resolution ─────────────────────────────────────────────────────
|
|
26
|
+
function getLockDir() {
|
|
27
|
+
const configuredDir = process.env['THINKRUN_LOCK_DIR'] ?? process.env['THINKBROWSE_LOCK_DIR'];
|
|
28
|
+
if (configuredDir)
|
|
29
|
+
return configuredDir;
|
|
30
|
+
const thinkrunDir = join(homedir(), '.thinkrun');
|
|
31
|
+
const thinkbrowseDir = join(homedir(), '.thinkbrowse');
|
|
32
|
+
if (!existsSync(thinkrunDir) && existsSync(thinkbrowseDir)) {
|
|
33
|
+
return thinkbrowseDir;
|
|
34
|
+
}
|
|
35
|
+
return thinkrunDir;
|
|
36
|
+
}
|
|
37
|
+
/** Path to the agent identity file.
|
|
38
|
+
* Uses `THINKRUN_LOCK_DIR` (with legacy THINKBROWSE_LOCK_DIR fallback) so
|
|
39
|
+
* test isolation applies automatically. */
|
|
40
|
+
export function getAgentFilePath() {
|
|
41
|
+
return join(getLockDir(), 'agent.json');
|
|
42
|
+
}
|
|
43
|
+
// ─── Generation ───────────────────────────────────────────────────────────────
|
|
44
|
+
/** Generate a new agent ID: `agt_` followed by 12 lowercase hex characters. */
|
|
45
|
+
export function generateAgentId() {
|
|
46
|
+
return 'agt_' + randomBytes(6).toString('hex');
|
|
47
|
+
}
|
|
48
|
+
// ─── Atomic write helper ──────────────────────────────────────────────────────
|
|
49
|
+
let _atomicSeq = 0;
|
|
50
|
+
function atomicWriteJson(destPath, data) {
|
|
51
|
+
const tmp = `${destPath}.${process.pid}.${_atomicSeq++}.tmp`;
|
|
52
|
+
try {
|
|
53
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2), 'utf-8');
|
|
54
|
+
renameSync(tmp, destPath);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
try {
|
|
58
|
+
rmSync(tmp, { force: true });
|
|
59
|
+
}
|
|
60
|
+
catch { /* best-effort */ }
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// ─── Persistence ─────────────────────────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* Persist an agent identity to disk.
|
|
67
|
+
* Writes atomically via a temp file + rename to prevent torn writes.
|
|
68
|
+
*/
|
|
69
|
+
export function saveAgentIdentity(identity) {
|
|
70
|
+
const dir = getLockDir();
|
|
71
|
+
mkdirSync(dir, { recursive: true });
|
|
72
|
+
atomicWriteJson(getAgentFilePath(), identity);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Load the saved agent identity from disk.
|
|
76
|
+
* Returns `null` if the file is absent or malformed — never throws.
|
|
77
|
+
*/
|
|
78
|
+
export function loadAgentIdentity() {
|
|
79
|
+
try {
|
|
80
|
+
const path = getAgentFilePath();
|
|
81
|
+
if (!existsSync(path))
|
|
82
|
+
return null;
|
|
83
|
+
const data = JSON.parse(readFileSync(path, 'utf-8'));
|
|
84
|
+
if (typeof data?.agentId !== 'string')
|
|
85
|
+
return null;
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ─── Resolution ──────────────────────────────────────────────────────────────
|
|
93
|
+
/**
|
|
94
|
+
* Resolve the agent ID for the current invocation.
|
|
95
|
+
*
|
|
96
|
+
* Priority:
|
|
97
|
+
* 1. `THINKRUN_AGENT_ID` environment variable (explicit override)
|
|
98
|
+
* with `THINKBROWSE_AGENT_ID` as a legacy fallback
|
|
99
|
+
* 2. `agentId` from `~/.thinkrun/agent.json` (persistent, created by `agent-init`
|
|
100
|
+
* or auto-created on first use)
|
|
101
|
+
* 3. Legacy ephemeral fallback derived from `process.ppid` only when the caller
|
|
102
|
+
* explicitly disables persistence
|
|
103
|
+
*
|
|
104
|
+
* By default the CLI auto-creates and persists a stable local agent identity on
|
|
105
|
+
* first use so the no-explicit-ID path still has durable same-controller continuity.
|
|
106
|
+
*/
|
|
107
|
+
export function resolveAgentId(options) {
|
|
108
|
+
const envId = process.env['THINKRUN_AGENT_ID'] ?? process.env['THINKBROWSE_AGENT_ID'];
|
|
109
|
+
if (envId && typeof envId === 'string' && envId.length > 0) {
|
|
110
|
+
return envId;
|
|
111
|
+
}
|
|
112
|
+
const saved = loadAgentIdentity();
|
|
113
|
+
if (saved?.agentId) {
|
|
114
|
+
return saved.agentId;
|
|
115
|
+
}
|
|
116
|
+
if (options?.persistIfMissing === false) {
|
|
117
|
+
return 'agt_' + process.ppid.toString(16).padStart(12, '0');
|
|
118
|
+
}
|
|
119
|
+
const generated = generateAgentId();
|
|
120
|
+
try {
|
|
121
|
+
saveAgentIdentity({
|
|
122
|
+
agentId: generated,
|
|
123
|
+
createdAt: new Date().toISOString(),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Persistence failed, so fall back to the legacy deterministic shell-based
|
|
128
|
+
// identity rather than inventing a fresh controller on every invocation.
|
|
129
|
+
return 'agt_' + process.ppid.toString(16).padStart(12, '0');
|
|
130
|
+
}
|
|
131
|
+
return generated;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=agent-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-identity.js","sourceRoot":"","sources":["../../../src/session/agent-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAgBjC,iFAAiF;AAEjF,SAAS,UAAU;IACjB,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,OAAO,CAAC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O,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IACpC,IAAI,CAAC;QACH,iBAAiB,CAAC;YAChB,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;QAC3E,yEAAyE;QACzE,OAAO,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in CLI session persistence helpers.
|
|
3
|
+
*
|
|
4
|
+
* When a ThinkRun API key is configured, local-mode commands can
|
|
5
|
+
* optionally register a session document in the cloud activity feed so
|
|
6
|
+
* that screenshots and other actions appear in the UI alongside cloud
|
|
7
|
+
* and extension sessions.
|
|
8
|
+
*
|
|
9
|
+
* ALL exported functions are fire-and-forget — they never throw and
|
|
10
|
+
* never block the caller. The sync is a best-effort side-channel; if
|
|
11
|
+
* the cloud API is unreachable the CLI continues to function normally.
|
|
12
|
+
*
|
|
13
|
+
* File written to disk: `~/.thinkrun/local-session-{tabId}.json`
|
|
14
|
+
* (same directory as working-location.json; THINKRUN_LOCK_DIR for
|
|
15
|
+
* test isolation).
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Read the persisted cloud sessionId for a given local tabId.
|
|
19
|
+
* Returns undefined if no session file exists or it is malformed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readCliSessionId(tabId: string): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Call POST /api/sessions/local-init to register a CLI session in the
|
|
24
|
+
* cloud activity feed. Persists the returned sessionId to disk.
|
|
25
|
+
*
|
|
26
|
+
* @returns The sessionId on success, undefined on any failure.
|
|
27
|
+
*/
|
|
28
|
+
export declare function initCliSession(tabId: string, fetchFn?: typeof fetch): Promise<string | undefined>;
|
|
29
|
+
/** Action types accepted by the /local-sync/action endpoint. */
|
|
30
|
+
export type BrowserActionType = 'navigate' | 'click' | 'type' | 'fill' | 'press' | 'scroll' | 'hover' | 'select' | 'wait' | 'wait_for_text' | 'extract' | 'evaluate' | 'go-back' | 'go-forward';
|
|
31
|
+
/**
|
|
32
|
+
* Fire-and-forget: POST a browser action to the cloud session action log.
|
|
33
|
+
* Never throws, never blocks the caller.
|
|
34
|
+
*
|
|
35
|
+
* @param sessionId The cloud session ID returned by initCliSession.
|
|
36
|
+
* @param type Action type — must be in ALLOWED_ACTION_TYPES on the server.
|
|
37
|
+
* @param details Arbitrary key-value pairs describing the action (url, selector, etc.)
|
|
38
|
+
* @param fetchFn Injectable fetch for testing.
|
|
39
|
+
*/
|
|
40
|
+
export declare function syncBrowserAction(sessionId: string, type: BrowserActionType, details: Record<string, unknown>, fetchFn?: typeof fetch): void;
|
|
41
|
+
/**
|
|
42
|
+
* Fire-and-forget: POST a screenshot action to the cloud session.
|
|
43
|
+
* Never throws, never blocks the caller.
|
|
44
|
+
*/
|
|
45
|
+
export declare function syncScreenshotAction(sessionId: string, artifactBase64: string, artifactMimeType: string, caption: string, fetchFn?: typeof fetch): void;
|
|
46
|
+
/**
|
|
47
|
+
* Fire-and-forget: PATCH /api/sessions/:sessionId/local-close, then
|
|
48
|
+
* clean up the persisted session file.
|
|
49
|
+
* Never throws, never blocks the caller.
|
|
50
|
+
*
|
|
51
|
+
* The session file is deleted BEFORE the HTTP call to prevent TOCTOU
|
|
52
|
+
* races with a concurrent closeCliSessionSync (e.g. Ctrl-C fires while
|
|
53
|
+
* stopSession is already in flight).
|
|
54
|
+
*/
|
|
55
|
+
export declare function closeCliSession(tabId: string, status: 'completed' | 'failed', fetchFn?: typeof fetch): void;
|
|
56
|
+
/** Injectable spawnSync type for testing. */
|
|
57
|
+
export type SpawnSyncFn = (cmd: string, args: string[], opts: object) => unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Synchronous version of closeCliSession for use in process exit handlers
|
|
60
|
+
* where async operations are not guaranteed to run to completion.
|
|
61
|
+
*
|
|
62
|
+
* Uses `curl` via spawnSync (-K - to read config from stdin) so the HTTP
|
|
63
|
+
* request completes before the process exits and the API key never appears
|
|
64
|
+
* in `ps aux` / /proc/<pid>/cmdline.
|
|
65
|
+
*
|
|
66
|
+
* The session file is deleted BEFORE the HTTP request to prevent TOCTOU
|
|
67
|
+
* races with a concurrent async closeCliSession call.
|
|
68
|
+
*
|
|
69
|
+
* @param spawnFn — injectable for testing; defaults to node:child_process spawnSync
|
|
70
|
+
*/
|
|
71
|
+
export declare function closeCliSessionSync(tabId: string, status: 'completed' | 'failed', spawnFn?: SpawnSyncFn): void;
|
|
72
|
+
//# sourceMappingURL=cli-session-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-session-sync.d.ts","sourceRoot":"","sources":["../../../src/session/cli-session-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA+CH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASlE;AAcD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,OAAO,KAAwB,GACvC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAqB7B;AAED,gEAAgE;AAChE,MAAM,MAAM,iBAAiB,GACzB,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAChD,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,eAAe,GAAG,SAAS,GACpE,UAAU,GAAG,SA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