pi-agent-browser-native 0.2.24 → 0.2.26

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.
@@ -47,10 +47,22 @@ const LAUNCH_SCOPED_FLAG_DEFINITIONS = [
47
47
  flag: "--init-script",
48
48
  reason: "registers page init scripts before the upstream browser session is launched",
49
49
  },
50
+ {
51
+ flag: "--device",
52
+ reason: "selects the provider device for the upstream launch",
53
+ },
50
54
  {
51
55
  flag: "--profile",
52
56
  reason: "selects Chrome profile state for the upstream launch",
53
57
  },
58
+ {
59
+ flag: "--provider",
60
+ reason: "selects the upstream browser provider for the launch",
61
+ },
62
+ {
63
+ flag: "-p",
64
+ reason: "selects the upstream browser provider for the launch",
65
+ },
54
66
  {
55
67
  flag: "--session-name",
56
68
  reason: "selects upstream saved auth/session state for the launch",
@@ -92,7 +104,7 @@ const BROWSER_PROMPT_PATTERNS = [
92
104
  /\b(?:browse|click|fill|login|navigate|open|visit)\b.*\b(?:https?:\/\/\S+|page|site|tab|url|web(?:site| page)?)\b/i,
93
105
  ];
94
106
  const INSPECTION_FLAGS = new Set(["--help", "-h", "--version", "-V"]);
95
- const SENSITIVE_VALUE_FLAGS = new Set(["--headers", "--password", "--proxy"]);
107
+ const SENSITIVE_VALUE_FLAGS = new Set(["--body", "--headers", "--password", "--proxy"]);
96
108
  const GLOBAL_VALUE_FLAGS_ALLOWING_DASH_VALUE = new Set(["--args"]);
97
109
  const GLOBAL_BOOLEAN_FLAGS_WITH_OPTIONAL_VALUES = new Set([
98
110
  "--allow-file-access",
@@ -115,7 +127,7 @@ const SENSITIVE_QUERY_PARAM_PATTERN =
115
127
  const SENSITIVE_FIELD_NAME_PATTERN =
116
128
  /^(?:access(?:_|-)?token|api(?:_|-)?key|auth(?:orization)?|bearer|client(?:_|-)?secret|cookie|id(?:_|-)?token|pass(?:word)?|proxy(?:_|-)?authorization|refresh(?:_|-)?token|secret|session(?:_|-)?id|set(?:_|-)?cookie|sig(?:nature)?|token|x(?:_|-)?api(?:_|-)?key)$/i;
117
129
 
118
- const GLOBAL_FLAGS_WITH_VALUES = new Set([
130
+ const VALUE_FLAGS = new Set([
119
131
  "--session",
120
132
  "--cdp",
121
133
  "--config",
@@ -146,6 +158,29 @@ const GLOBAL_FLAGS_WITH_VALUES = new Set([
146
158
  "--confirm-actions",
147
159
  "--max-output",
148
160
  "--model",
161
+ "--baseline",
162
+ "--body",
163
+ "--categories",
164
+ "--curl",
165
+ "--depth",
166
+ "-d",
167
+ "--domain",
168
+ "--expires",
169
+ "--filter",
170
+ "--fn",
171
+ "--label",
172
+ "--load",
173
+ "--name",
174
+ "--path",
175
+ "--resource-type",
176
+ "--sameSite",
177
+ "--selector",
178
+ "-s",
179
+ "--text",
180
+ "--timeout",
181
+ "--url",
182
+ "--username",
183
+ "--password",
149
184
  ]);
150
185
  const DEFAULT_HEADLESS_COMPAT_USER_AGENT_BY_PLATFORM: Partial<Record<NodeJS.Platform, string>> = {
151
186
  darwin: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",
@@ -440,7 +475,7 @@ export function redactInvocationArgs(args: string[]): string[] {
440
475
  continue;
441
476
  }
442
477
 
443
- redacted.push(redactUrlToken(token));
478
+ redacted.push(redactSensitiveText(redactUrlToken(token)));
444
479
  }
445
480
 
446
481
  const commandStartIndex = findCommandStartIndex(args);
@@ -452,6 +487,20 @@ export function redactInvocationArgs(args: string[]): string[] {
452
487
  }
453
488
  }
454
489
 
490
+ if (commandStartIndex !== undefined && args[commandStartIndex] === "cookies" && args[commandStartIndex + 1] === "set" && redacted[commandStartIndex + 3] !== undefined) {
491
+ redacted[commandStartIndex + 3] = "[REDACTED]";
492
+ }
493
+
494
+ if (
495
+ commandStartIndex !== undefined
496
+ && args[commandStartIndex] === "storage"
497
+ && ["local", "session"].includes(args[commandStartIndex + 1] ?? "")
498
+ && args[commandStartIndex + 2] === "set"
499
+ && redacted[commandStartIndex + 4] !== undefined
500
+ ) {
501
+ redacted[commandStartIndex + 4] = "[REDACTED]";
502
+ }
503
+
455
504
  return redacted;
456
505
  }
457
506
 
@@ -467,6 +516,10 @@ export function isPlainTextInspectionArgs(args: string[]): boolean {
467
516
  return args.some((token) => INSPECTION_FLAGS.has(token));
468
517
  }
469
518
 
519
+ function isStatelessInspectionCommand(commandInfo: CommandInfo): boolean {
520
+ return commandInfo.command === "skills" && ["list", "get", "path"].includes(commandInfo.subcommand ?? "");
521
+ }
522
+
470
523
  export function hasUsableBraveApiKey(apiKey: string | null | undefined = process.env[BRAVE_API_KEY_ENV]): boolean {
471
524
  return typeof apiKey === "string" && apiKey.trim().length > 0;
472
525
  }
@@ -596,9 +649,14 @@ export function restoreManagedSessionStateFromBranch(
596
649
 
597
650
  const messageIsError = typeof message.isError === "boolean" ? message.isError : undefined;
598
651
  const exitCode = typeof details.exitCode === "number" ? details.exitCode : undefined;
599
- const succeeded = messageIsError === undefined ? exitCode === undefined || exitCode === 0 : !messageIsError;
652
+ const outcome = typeof details.managedSessionOutcome === "object" && details.managedSessionOutcome !== null ? details.managedSessionOutcome as Record<string, unknown> : undefined;
653
+ const outcomeStatus = typeof outcome?.status === "string" ? outcome.status : undefined;
654
+ const outcomeCurrentSessionName = typeof outcome?.currentSessionName === "string" ? outcome.currentSessionName : undefined;
655
+ const outcomeActiveAfter = outcome?.activeAfter === true;
656
+ const outcomeRepresentsActiveCurrentSession = outcomeActiveAfter && outcomeCurrentSessionName === managedSessionName && (outcomeStatus === "created" || outcomeStatus === "replaced" || outcomeStatus === "unchanged");
657
+ const succeeded = outcomeRepresentsActiveCurrentSession ? true : messageIsError === undefined ? exitCode === undefined || exitCode === 0 : !messageIsError;
600
658
  const command = typeof details.command === "string" ? details.command : parseCommandInfo(args).command;
601
- if (succeeded && sessionMode === "fresh") {
659
+ if ((succeeded || outcomeRepresentsActiveCurrentSession) && sessionMode === "fresh") {
602
660
  freshSessionOrdinal += 1;
603
661
  }
604
662
  const staleCompletion = succeeded && command !== "close" && restoreRank < activeRestoreRank;
@@ -693,7 +751,7 @@ function getInvalidValueFlagDetails(args: string[]): InvalidValueFlagDetails | u
693
751
  continue;
694
752
  }
695
753
  const normalizedToken = token.split("=", 1)[0] ?? token;
696
- if (!GLOBAL_FLAGS_WITH_VALUES.has(normalizedToken)) {
754
+ if (!VALUE_FLAGS.has(normalizedToken)) {
697
755
  continue;
698
756
  }
699
757
  if (token.includes("=")) {
@@ -861,10 +919,23 @@ export function extractExplicitSessionName(args: string[]): string | undefined {
861
919
  return undefined;
862
920
  }
863
921
 
922
+ function hasLaunchScopedFlagToken(args: string[], flag: string): boolean {
923
+ const commandStartIndex = findCommandStartIndex(args);
924
+ const command = commandStartIndex === undefined ? undefined : args[commandStartIndex];
925
+ return args.some((token, index) => {
926
+ if (token !== flag && !token.startsWith(`${flag}=`)) return false;
927
+ if (flag === "--auto-connect") return isBooleanFlagEnabled(args, flag);
928
+ if (flag === "--state" && command === "wait" && commandStartIndex !== undefined && index > commandStartIndex) {
929
+ return false;
930
+ }
931
+ return true;
932
+ });
933
+ }
934
+
864
935
  export function getStartupScopedFlags(args: string[]): string[] {
865
936
  return LAUNCH_SCOPED_FLAG_DEFINITIONS
866
937
  .map((definition) => definition.flag)
867
- .filter((flag) => flag === "--auto-connect" ? isBooleanFlagEnabled(args, flag) : hasFlagToken(args, flag));
938
+ .filter((flag) => hasLaunchScopedFlagToken(args, flag));
868
939
  }
869
940
 
870
941
  export function hasLaunchScopedTabCorrectionFlag(args: string[]): boolean {
@@ -923,6 +994,7 @@ export function buildExecutionPlan(
923
994
  const startupScopedFlags = getStartupScopedFlags(args);
924
995
  const plainTextInspection = isPlainTextInspectionArgs(args);
925
996
  const commandInfo = parseCommandInfo(args);
997
+ const statelessInspection = plainTextInspection || isStatelessInspectionCommand(commandInfo);
926
998
  const effectiveArgs = plainTextInspection ? [...args] : args.includes("--json") ? [] : ["--json"];
927
999
  if (invalidValueFlag) {
928
1000
  return {
@@ -956,7 +1028,7 @@ export function buildExecutionPlan(
956
1028
  let usedImplicitSession = false;
957
1029
  let validationError: string | undefined;
958
1030
 
959
- if (!explicitSessionName && options.sessionMode === "auto") {
1031
+ if (!explicitSessionName && options.sessionMode === "auto" && !statelessInspection) {
960
1032
  if (options.managedSessionActive && startupScopedFlags.length > 0) {
961
1033
  recoveryHint = {
962
1034
  exampleArgs: args,
@@ -975,7 +1047,7 @@ export function buildExecutionPlan(
975
1047
  sessionName = options.managedSessionName;
976
1048
  usedImplicitSession = true;
977
1049
  }
978
- } else if (shouldCreateFreshManagedSession) {
1050
+ } else if (shouldCreateFreshManagedSession && !statelessInspection) {
979
1051
  effectiveArgs.push("--session", options.freshSessionName);
980
1052
  managedSessionName = options.freshSessionName;
981
1053
  sessionName = options.freshSessionName;
@@ -1080,7 +1152,7 @@ function findCommandStartIndex(args: string[]): number | undefined {
1080
1152
  }
1081
1153
  if (token.startsWith("-")) {
1082
1154
  const normalizedToken = token.split("=", 1)[0] ?? token;
1083
- if (GLOBAL_FLAGS_WITH_VALUES.has(normalizedToken) && !token.includes("=")) {
1155
+ if (VALUE_FLAGS.has(normalizedToken) && !token.includes("=")) {
1084
1156
  index += 1;
1085
1157
  } else if (
1086
1158
  GLOBAL_BOOLEAN_FLAGS_WITH_OPTIONAL_VALUES.has(normalizedToken) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-browser-native",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "pi extension that exposes agent-browser as a native tool for browser automation",
5
5
  "type": "module",
6
6
  "author": "Mitch Fultz (https://github.com/fitchmultz)",
@@ -40,6 +40,7 @@
40
40
  "docs/COMMAND_REFERENCE.md",
41
41
  "docs/RELEASE.md",
42
42
  "docs/REQUIREMENTS.md",
43
+ "docs/SUPPORT_MATRIX.md",
43
44
  "docs/TOOL_CONTRACT.md"
44
45
  ],
45
46
  "pi": {
@@ -66,9 +67,10 @@
66
67
  "scripts": {
67
68
  "docs": "node ./scripts/project.mjs docs",
68
69
  "doctor": "node ./scripts/doctor.mjs",
70
+ "benchmark:agent-browser": "node ./scripts/agent-browser-efficiency-benchmark.mjs",
69
71
  "test": "tsx --test test/**/*.test.ts",
70
72
  "verify": "node ./scripts/project.mjs verify",
71
- "prepublishOnly": "npm run verify && npm pack --dry-run"
73
+ "prepublishOnly": "npm run verify -- release && npm pack --dry-run"
72
74
  },
73
75
  "packageManager": "npm@11.14.0"
74
76
  }