a2acalling 0.6.13 → 0.6.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "a2acalling",
3
- "version": "0.6.13",
3
+ "version": "0.6.14",
4
4
  "description": "Agent-to-agent calling for OpenClaw - A2A agent communication",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -15,12 +15,18 @@
15
15
  // so the full onboarding completes unattended: port selection, hostname
16
16
  // detection, server start, and disclosure prompt output.
17
17
  //
18
- // 2. stdout stderr. npm suppresses lifecycle script stdout (piped to its
19
- // internal log buffer). stderr passes through to the caller. By mapping
20
- // the child's stdout to fd 2 (stderr), the entire onboarding walkthrough
21
- // is visible to the installing agent or terminal — banner, port selection,
22
- // server start confirmation, and the disclosure prompt all come through.
23
- // stdin is piped with no input so prompts auto-accept defaults.
18
+ // 2. Bypassing npm's output capture. npm v7+ pipes lifecycle script stdout
19
+ // AND stderr to an internal buffer, only showing them on failure. This
20
+ // means normal console.log/console.error from postinstall is invisible.
21
+ // To make onboarding output visible:
22
+ //
23
+ // a) Run quickstart with piped stdio, capturing all its output.
24
+ // b) Save the output to a2a-onboarding.txt in the config dir (reliable
25
+ // fallback — agents can always read this file).
26
+ // c) Try /dev/tty (interactive terminals — bypasses npm entirely).
27
+ // d) Try /proc/$PPID/fd/2 (Linux — writes directly to npm's stderr fd,
28
+ // which IS the caller's stderr, bypassing npm's pipe buffer).
29
+ // e) Last resort: process.stderr.write (npm may still buffer this).
24
30
  //
25
31
  // 3. Never fail the install. If quickstart can't launch (e.g. missing node
26
32
  // binary edge case), we print a hint and exit 0. A broken postinstall
@@ -35,16 +41,17 @@ if (process.env.CI || process.env.CONTINUOUS_INTEGRATION) process.exit(0);
35
41
  if (process.env.DOCKER) process.exit(0);
36
42
  if (process.env.npm_config_global !== 'true') process.exit(0);
37
43
 
44
+ const fs = require('fs');
38
45
  const path = require('path');
39
46
  const { spawnSync } = require('child_process');
40
47
 
41
48
  const initCwd = process.env.INIT_CWD || process.env.HOME || process.cwd();
42
49
  const cliPath = path.join(__dirname, '..', 'bin', 'cli.js');
43
50
 
44
- // Launch quickstart with stdout→stderr so npm doesn't swallow the output.
51
+ // Run quickstart with piped stdio so we capture all its output.
45
52
  // stdin is piped (empty) so all prompts auto-accept their defaults.
46
53
  const result = spawnSync(process.execPath, [cliPath, 'quickstart'], {
47
- stdio: ['pipe', 2, 2],
54
+ stdio: ['pipe', 'pipe', 'pipe'],
48
55
  cwd: initCwd,
49
56
  env: {
50
57
  ...process.env,
@@ -53,10 +60,58 @@ const result = spawnSync(process.execPath, [cliPath, 'quickstart'], {
53
60
  });
54
61
 
55
62
  if (result.error) {
56
- console.error('\nCould not auto-launch onboarding.');
57
- console.error(`Reason: ${result.error.message}`);
58
- console.error('\nRun manually: a2a quickstart\n');
63
+ process.stderr.write('\nCould not auto-launch onboarding.\n');
64
+ process.stderr.write(`Reason: ${result.error.message}\n`);
65
+ process.stderr.write('\nRun manually: a2a quickstart\n\n');
59
66
  process.exit(0); // don't fail the install
60
67
  }
61
68
 
69
+ const output = (result.stdout || '').toString() + (result.stderr || '').toString();
70
+
71
+ // ── Always save to file (reliable fallback) ──────────────────────────────
72
+ // Agents can read this after install regardless of output visibility.
73
+ try {
74
+ const configDir = process.env.A2A_CONFIG_DIR
75
+ || path.join(process.env.HOME || '/root', '.config', 'openclaw');
76
+ if (fs.existsSync(configDir)) {
77
+ fs.writeFileSync(path.join(configDir, 'a2a-onboarding.txt'), output);
78
+ }
79
+ } catch (_) {}
80
+
81
+ // ── Make output visible to the caller ────────────────────────────────────
82
+ // npm pipes BOTH stdout and stderr of lifecycle scripts (v7+), so writing
83
+ // to our own fds goes into npm's buffer. We need to bypass npm entirely.
84
+
85
+ function tryWrite(output) {
86
+ // Strategy 1: /dev/tty — interactive terminals.
87
+ // npm runs postinstall with piped stdio, but /dev/tty talks directly to
88
+ // the user's terminal. Works for humans, not for agents.
89
+ try {
90
+ const fd = fs.openSync('/dev/tty', 'w');
91
+ fs.writeSync(fd, output);
92
+ fs.closeSync(fd);
93
+ return true;
94
+ } catch (_) {}
95
+
96
+ // Strategy 2: /proc/$PPID/fd/2 — Linux, write to npm's stderr directly.
97
+ // npm's stderr IS the caller's stderr (the agent's output stream).
98
+ // This bypasses npm's pipe buffer because we open the fd independently.
99
+ try {
100
+ const fd = fs.openSync(`/proc/${process.ppid}/fd/2`, 'w');
101
+ fs.writeSync(fd, output);
102
+ fs.closeSync(fd);
103
+ return true;
104
+ } catch (_) {}
105
+
106
+ // Strategy 3: process.stderr — last resort, npm may still buffer this.
107
+ try {
108
+ process.stderr.write(output);
109
+ return true;
110
+ } catch (_) {}
111
+
112
+ return false;
113
+ }
114
+
115
+ tryWrite(output);
116
+
62
117
  process.exit(result.status || 0);