@farmslot/adapter-web 0.19.36 → 0.19.37

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/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ All notable changes to `@farmslot/adapter-web` are tracked here.
6
6
 
7
7
  - Active-development baseline; add user-facing changes here before release or package publication.
8
8
 
9
+ ## 0.19.37 - 2026-11-30
10
+
11
+ - Without a named account, the web-dapp launch keeps the browser's current account, else the fixture's first one, instead of assuming `dev1`.
12
+
9
13
  ## 0.19.36 - 2026-11-26
10
14
 
11
15
  - Recover Web DApp launches when the saved browser has lost its app tab or shows an error page, using the existing profile and network protections.
@@ -20,6 +20,26 @@ export function webDappOnlyLaunchFlags(options: Record<string, string | boolean>
20
20
  * @returns {Record<string, unknown>}
21
21
  */
22
22
  export function parseWebDappLauncherOutput(output: string): Record<string, unknown>;
23
+ /**
24
+ * The account the public launch passes: explicit, else TERMINAL_ACCOUNT, else none (current or first fixture account).
25
+ * @param {Record<string, unknown>} [options]
26
+ * @param {NodeJS.ProcessEnv} [env]
27
+ * @returns {string}
28
+ */
29
+ export function webDappLaunchAccount(options?: Record<string, unknown>, env?: NodeJS.ProcessEnv): string;
30
+ /**
31
+ * The launcher argv the public launch runs (before optional flags).
32
+ * @param {{ target: string, cdpPort: string, appPort: string, options?: Record<string, unknown>, signerModule?: string }} launch
33
+ * @param {NodeJS.ProcessEnv} [env]
34
+ * @returns {string[]}
35
+ */
36
+ export function webDappLaunchArgv({ target, cdpPort, appPort, options, signerModule }: {
37
+ target: string;
38
+ cdpPort: string;
39
+ appPort: string;
40
+ options?: Record<string, unknown>;
41
+ signerModule?: string;
42
+ }, env?: NodeJS.ProcessEnv): string[];
23
43
  export function webDappAppPort(): number | undefined;
24
44
  export function webDappCdpPort(): number | undefined;
25
45
  /**
@@ -43,7 +43,7 @@ export function resolveAccountAddress(input: any, env?: NodeJS.ProcessEnv): Prom
43
43
  address: any;
44
44
  }>;
45
45
  export const SIGNER_MODES: readonly string[];
46
- export const DEFAULT_ACCOUNT: "dev1";
46
+ export const DEFAULT_ACCOUNT: "";
47
47
  export const DERIVED_ACCOUNTS_ENV: "RECIPE_WALLET_DERIVED_ACCOUNTS";
48
48
  import { POLICY_ENV } from './policy.mjs';
49
49
  import { webDappAdapterId } from './policy.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farmslot/adapter-web",
3
- "version": "0.19.36",
3
+ "version": "0.19.37",
4
4
  "description": "Web platform adapter for Farmslot recipes: resolve and launch an isolated Chromium, own its CDP port, load unpacked extensions, and keep macOS focus.",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -88,8 +88,8 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@farmslot/adapter-sdk": "0.31.4",
91
- "@farmslot/protocol": "0.92.1",
92
- "@farmslot/recipe-runner": "0.52.5",
91
+ "@farmslot/protocol": "0.92.6",
92
+ "@farmslot/recipe-runner": "0.52.8",
93
93
  "ws": "^8.18.0"
94
94
  },
95
95
  "devDependencies": {
@@ -212,6 +212,44 @@ function portFromEnv(...names) {
212
212
  return undefined;
213
213
  }
214
214
 
215
+ /**
216
+ * The account the public launch passes: explicit, else TERMINAL_ACCOUNT, else none (current or first fixture account).
217
+ * @param {Record<string, unknown>} [options]
218
+ * @param {NodeJS.ProcessEnv} [env]
219
+ * @returns {string}
220
+ */
221
+ export function webDappLaunchAccount(options = {}, env = process.env) {
222
+ const explicit = typeof options.account === 'string' ? options.account : undefined;
223
+ return explicit ?? env.TERMINAL_ACCOUNT ?? '';
224
+ }
225
+
226
+ /**
227
+ * The launcher argv the public launch runs (before optional flags).
228
+ * @param {{ target: string, cdpPort: string, appPort: string, options?: Record<string, unknown>, signerModule?: string }} launch
229
+ * @param {NodeJS.ProcessEnv} [env]
230
+ * @returns {string[]}
231
+ */
232
+ export function webDappLaunchArgv(
233
+ { target, cdpPort, appPort, options = {}, signerModule },
234
+ env = process.env,
235
+ ) {
236
+ const signer = typeof options.signer === 'string' ? options.signer : undefined;
237
+ return [
238
+ webDappLeafPath('launch'),
239
+ '--target',
240
+ target,
241
+ '--cdp-port',
242
+ cdpPort,
243
+ '--app-port',
244
+ appPort,
245
+ '--signer',
246
+ signer ?? env.TERMINAL_SIGNER ?? defaultSigner(signerModule),
247
+ '--account',
248
+ webDappLaunchAccount(options, env),
249
+ '--json',
250
+ ];
251
+ }
252
+
215
253
  export function webDappAppPort() {
216
254
  return portFromEnv('TERMINAL_APP_PORT', 'RECIPE_WATCHER_PORT', 'WATCHER_PORT');
217
255
  }
@@ -486,20 +524,7 @@ export function createWebDappAdapter(factoryOptions = {}) {
486
524
  `${cli} launch --adapter ${adapterId} --cdp-port <port> --watcher-port <app port>`,
487
525
  );
488
526
  }
489
- const args = [
490
- webDappLeafPath('launch'),
491
- '--target',
492
- target,
493
- '--cdp-port',
494
- cdpPort,
495
- '--app-port',
496
- appPort,
497
- '--signer',
498
- str(options, 'signer') ?? process.env.TERMINAL_SIGNER ?? defaultSigner(signerModule),
499
- '--account',
500
- str(options, 'account') ?? process.env.TERMINAL_ACCOUNT ?? 'dev1',
501
- '--json',
502
- ];
527
+ const args = webDappLaunchArgv({ target, cdpPort, appPort, options, signerModule });
503
528
  if (signerModule) args.push('--signer-module', signerModule);
504
529
  if (flag(options, 'freshProfile')) args.push('--fresh-profile');
505
530
  if (flag(options, 'headless')) args.push('--headless');
@@ -609,7 +634,7 @@ export function createWebDappAdapter(factoryOptions = {}) {
609
634
  appPort: webDappAppPort(),
610
635
  cdpPort: webDappCdpPort(),
611
636
  signer: process.env.TERMINAL_SIGNER || defaultSigner(signerModule),
612
- account: process.env.TERMINAL_ACCOUNT || 'dev1',
637
+ account: process.env.TERMINAL_ACCOUNT || '',
613
638
  probeBrowser: resolveBrowser,
614
639
  });
615
640
  return report.checks.map((item) => ({
@@ -75,6 +75,7 @@ import {
75
75
  loadWalletFixture,
76
76
  resolveSigner,
77
77
  walletAccount,
78
+ walletAccounts,
78
79
  webDappPolicy,
79
80
  webDappRuntimeDir,
80
81
  } from './lib/runtime.mjs';
@@ -94,7 +95,7 @@ function usage() {
94
95
 
95
96
  export function parseLaunchArgs(argv, env = process.env) {
96
97
  const args = {
97
- account: 'dev1',
98
+ account: '',
98
99
  'fresh-profile': false,
99
100
  headless: false,
100
101
  headful: false,
@@ -538,7 +539,18 @@ export async function launchWebDappBrowser(
538
539
 
539
540
  const { fixture } = await loadWalletFixture(target, env);
540
541
  // --account is an account name or address; the browser runs under its name.
541
- const selected = walletAccount(fixture, args.account, target, env);
542
+ // Without one, keep the browser's current account (else the fixture's first).
543
+ // Only a live browser's record names the current account; a stale record does not.
544
+ const recorded = readStateFile(stateFile);
545
+ const browserLive = Boolean(recorded) && ownsProcess('browser', recorded.browserPid, runtime);
546
+ const current = !args.account && browserLive ? recorded.account : undefined;
547
+ // The current account by its recorded name when that name still holds its address (aliases share one).
548
+ const sameAccount = (candidate) =>
549
+ candidate.name === current?.name &&
550
+ candidate.address.toLowerCase() === String(current?.address ?? '').toLowerCase();
551
+ const selected =
552
+ (current && walletAccounts(fixture, target, env).find(sameAccount)) ??
553
+ walletAccount(fixture, args.account || current?.address, target, env);
542
554
  const account = {
543
555
  name: selected.name,
544
556
  address: selected.address,
@@ -546,9 +558,9 @@ export async function launchWebDappBrowser(
546
558
  index: selected.index,
547
559
  };
548
560
 
549
- const previous = readStateFile(stateFile);
561
+ const previous = recorded;
550
562
  const reusable =
551
- previous &&
563
+ browserLive &&
552
564
  !args['fresh-profile'] &&
553
565
  previous.signer === signer &&
554
566
  previous.cdpPort === cdpPort &&
@@ -559,7 +571,6 @@ export async function launchWebDappBrowser(
559
571
  Boolean(previous.browser?.outerSeatbelt) === blindBrowser.direct &&
560
572
  (previous.network ?? 'testnet') === network &&
561
573
  previous.networkEnforcement?.fingerprint === enforcementFingerprint &&
562
- ownsProcess('browser', previous.browserPid, runtime) &&
563
574
  ownsProcess('wallet-host', previous.hostPid, runtime);
564
575
  if (
565
576
  reusable &&
@@ -632,7 +643,7 @@ export async function launchWebDappBrowser(
632
643
  target,
633
644
  runtime,
634
645
  profile,
635
- account: account.name,
646
+ account: account.address,
636
647
  fixture,
637
648
  env,
638
649
  freshProfile,
@@ -744,7 +755,7 @@ export async function launchWebDappBrowser(
744
755
  '--target',
745
756
  target,
746
757
  '--account',
747
- account.name,
758
+ account.address,
748
759
  '--start-chain',
749
760
  String(args['start-chain'] ?? policy.startChain),
750
761
  '--network',
@@ -247,7 +247,7 @@ export async function webDappReadiness({
247
247
  cdpPort,
248
248
  // As defaultSigner: extension only when the host gave an extension signer.
249
249
  signer = signers?.extension ? 'extension' : 'injected',
250
- account = 'dev1',
250
+ account = '',
251
251
  env = process.env,
252
252
  probeBrowser = undefined,
253
253
  }) {
@@ -304,7 +304,11 @@ export async function webDappReadiness({
304
304
  const { file, fixture } = await loadWalletFixture(target, env);
305
305
  const { address } = walletAccount(fixture, account, target, env);
306
306
  checks.push(
307
- check('wallet-fixture', true, `${path.basename(file)}: account ${account} -> ${address}`),
307
+ check(
308
+ 'wallet-fixture',
309
+ true,
310
+ `${path.basename(file)}: account ${account || '(first)'} -> ${address}`,
311
+ ),
308
312
  );
309
313
  } catch (error) {
310
314
  checks.push(check('wallet-fixture', false, error.message.split('\n')[0]));
@@ -14,7 +14,9 @@ import { loadViemAccounts } from './viem.mjs';
14
14
  export { POLICY_ENV, webDappAdapterId, webDappPolicy };
15
15
 
16
16
  export const SIGNER_MODES = Object.freeze(['extension', 'injected']);
17
- export const DEFAULT_ACCOUNT = 'dev1';
17
+ // No account named: the browser's current account, else the fixture's first one.
18
+ // Fixture account names differ between people, so none is assumed.
19
+ export const DEFAULT_ACCOUNT = '';
18
20
 
19
21
  // The checkout's canonical path: a symlinked or /tmp-vs-/private/tmp spelling
20
22
  // of the same slot must name the same runtime dir, profile and pid owners.
@@ -246,8 +248,9 @@ export function walletAccounts(fixture, projectRoot, env = process.env) {
246
248
  const count = entry.type === 'mnemonic' ? mnemonicCount(entry) : 1;
247
249
  for (let index = 0; index < count; index += 1) {
248
250
  const account = viemAccountFromEntry(entry, projectRoot, index);
251
+ const name = derivedName(entry, index, count);
249
252
  accounts.push({
250
- name: derivedName(entry, index, count),
253
+ name,
251
254
  address: account.address,
252
255
  secret: entry.name,
253
256
  index,
@@ -296,11 +299,11 @@ export function walletAccounts(fixture, projectRoot, env = process.env) {
296
299
  export function walletAccount(fixture, selector, projectRoot, env = process.env) {
297
300
  const accounts = walletAccounts(fixture, projectRoot, env);
298
301
  const wanted = String(selector ?? '').trim();
299
- const found =
300
- accounts.find((account) => account.name === wanted) ??
301
- (/^0x[0-9a-fA-F]{40}$/u.test(wanted)
302
- ? accounts.find((account) => account.address.toLowerCase() === wanted.toLowerCase())
303
- : undefined);
302
+ if (!wanted && accounts.length > 0) return accounts[0];
303
+ // An address selects by address, never by an entry that happens to be named like it.
304
+ const found = /^0x[0-9a-fA-F]{40}$/u.test(wanted)
305
+ ? accounts.find((account) => account.address.toLowerCase() === wanted.toLowerCase())
306
+ : accounts.find((account) => account.name === wanted);
304
307
  if (!found) {
305
308
  const names = accounts.map((account) => account.name).join(', ');
306
309
  throw new Error(`wallet fixture has no account named "${wanted}". Available: ${names}.`);
@@ -321,8 +324,20 @@ export async function resolveAccountAddress(input, env = process.env) {
321
324
  return { name: null, address: raw.trim() };
322
325
  }
323
326
  const projectRoot = input.context?.projectRoot;
324
- const browserState = projectRoot ? await readBrowserState(projectRoot) : null;
325
- const name = accountName(input, browserState);
326
- const account = await fixtureAccount(projectRoot, name, env);
327
- return { name, address: account.address };
327
+ const explicit = String(input.node?.account_name ?? input.node?.account ?? '').trim();
328
+ let browserState = null;
329
+ if (!explicit && projectRoot) {
330
+ const recorded = await readBrowserState(projectRoot);
331
+ // Only a running browser's record names the current account (lazy import: processes.mjs imports this module).
332
+ const { ownsProcess } = await import('./processes.mjs');
333
+ if (recorded && ownsProcess('browser', recorded.browserPid, webDappRuntimeDir(projectRoot))) {
334
+ browserState = recorded;
335
+ }
336
+ }
337
+ if (browserState?.account?.address) {
338
+ return { name: browserState.account.name ?? null, address: browserState.account.address };
339
+ }
340
+ const { fixture } = await loadWalletFixture(projectRoot, env);
341
+ const selected = walletAccount(fixture, accountName(input, browserState), projectRoot, env);
342
+ return { name: selected.name, address: selected.address };
328
343
  }
@@ -45,7 +45,7 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me
45
45
  ),
46
46
  cdpPort: num(value('--cdp-port') ?? process.env.RECIPE_CDP_PORT ?? process.env.CDP_PORT),
47
47
  signer: value('--signer') ?? process.env.TERMINAL_SIGNER ?? defaultSigner(signerModule),
48
- account: value('--account') ?? process.env.TERMINAL_ACCOUNT ?? 'dev1',
48
+ account: value('--account') ?? process.env.TERMINAL_ACCOUNT ?? '',
49
49
  probeBrowser: resolveBrowser,
50
50
  });
51
51
  if (argv.includes('--json')) {