troxy-cli 1.3.0 → 1.3.1

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": "troxy-cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {
package/src/auth.js CHANGED
@@ -68,6 +68,10 @@ function loadConfig() {
68
68
  }
69
69
 
70
70
  function _openBrowser(url) {
71
+ const isHeadless = process.platform === 'linux'
72
+ && !process.env.DISPLAY
73
+ && !process.env.WAYLAND_DISPLAY;
74
+ if (isHeadless) return;
71
75
  const cmd = process.platform === 'darwin' ? `open "${url}"`
72
76
  : process.platform === 'win32' ? `start "" "${url}"`
73
77
  : `xdg-open "${url}"`;
@@ -85,10 +89,16 @@ export async function runLogin() {
85
89
  process.exit(1);
86
90
  }
87
91
 
88
- // 2. Open browser
89
- console.log('\n Opening browser to complete login...');
90
- console.log(` If it didn't open, visit:\n ${session.url}\n`);
91
- _openBrowser(session.url);
92
+ // 2. Open browser (or print URL on headless servers)
93
+ const isHeadless = process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY;
94
+ if (isHeadless) {
95
+ console.log('\n Open this URL in your browser to get a login code:\n');
96
+ console.log(` ${session.url}\n`);
97
+ } else {
98
+ console.log('\n Opening browser to complete login...');
99
+ console.log(` If it didn't open, visit:\n ${session.url}\n`);
100
+ _openBrowser(session.url);
101
+ }
92
102
 
93
103
  // 3. Prompt for the code shown in the browser
94
104
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
package/src/policies.js CHANGED
@@ -126,9 +126,11 @@ export async function runPolicies([sub, ...args], flags) {
126
126
  }
127
127
  }
128
128
 
129
+ const _isAny = x => !x.field || x.field === 'any' || x.operator === 'any';
130
+
129
131
  function _condSummary(p) {
130
- const c = p.conditions || [];
131
- const o = p.or_conditions || [];
132
+ const c = (p.conditions || []).filter(x => !_isAny(x));
133
+ const o = (p.or_conditions || []).filter(row => (row.conditions || []).some(x => !_isAny(x)));
132
134
  const total = c.length + o.length;
133
135
  if (total === 0) return 'always';
134
136
  return `${total} condition${total > 1 ? 's' : ''}`;
@@ -138,13 +140,15 @@ function _condDetail(p) {
138
140
  const c = p.conditions || [];
139
141
  const or = p.or_conditions || [];
140
142
  const parts = [];
141
- if (c.length) {
142
- parts.push(c.map(x => `${x.field} ${x.operator} ${x.value || ''}${x.value2 ? '–'+x.value2 : ''}`).join(' AND '));
143
+ const real = c.filter(x => !_isAny(x));
144
+ if (real.length) {
145
+ parts.push(real.map(x => `${x.field} ${x.operator} ${x.value || ''}${x.value2 ? '–'+x.value2 : ''}`).join(' AND '));
143
146
  }
144
147
  if (or.length) {
145
148
  or.forEach(row => {
146
- const conds = (row.conditions || []).map(x => `${x.field} ${x.operator} ${x.value || ''}`).join(' AND ');
147
- parts.push(`${row.action}${conds ? ' if ' + conds : ''}`);
149
+ const realConds = (row.conditions || []).filter(x => !_isAny(x));
150
+ const conds = realConds.map(x => `${x.field} ${x.operator} ${x.value || ''}`).join(' AND ');
151
+ parts.push(`${row.action || ''}${conds ? ' if ' + conds : ''}`);
148
152
  });
149
153
  }
150
154
  return parts.length ? parts.join('\n ') : 'none (always matches)';