@undefineds.co/linx 0.2.17 → 0.2.18

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.
Files changed (117) hide show
  1. package/README.md +3 -6
  2. package/dist/generated/version.js +1 -1
  3. package/dist/generated/version.js.map +1 -1
  4. package/dist/index.js +256 -143
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/account-api.js +1 -1
  7. package/dist/lib/account-api.js.map +1 -1
  8. package/dist/lib/account-session.js +1 -1
  9. package/dist/lib/account-session.js.map +1 -1
  10. package/dist/lib/ai-command.js +186 -367
  11. package/dist/lib/ai-command.js.map +1 -1
  12. package/dist/lib/chat-api.js +177 -19
  13. package/dist/lib/chat-api.js.map +1 -1
  14. package/dist/lib/codex-plugin/bridge.js.map +1 -1
  15. package/dist/lib/codex-plugin/codex-native-proxy.js.map +1 -1
  16. package/dist/lib/codex-plugin/index.js.map +1 -1
  17. package/dist/lib/codex-plugin/runner.js.map +1 -1
  18. package/dist/lib/credentials-store.js +7 -1
  19. package/dist/lib/credentials-store.js.map +1 -1
  20. package/dist/lib/default-model.js +1 -0
  21. package/dist/lib/default-model.js.map +1 -1
  22. package/dist/lib/login-command.js +33 -10
  23. package/dist/lib/login-command.js.map +1 -1
  24. package/dist/lib/models.js +2 -27
  25. package/dist/lib/models.js.map +1 -1
  26. package/dist/lib/node-warning-filter.js +34 -0
  27. package/dist/lib/node-warning-filter.js.map +1 -0
  28. package/dist/lib/oidc-auth.js +130 -18
  29. package/dist/lib/oidc-auth.js.map +1 -1
  30. package/dist/lib/oidc-session-storage.js.map +1 -1
  31. package/dist/lib/pi-adapter/auth.js +47 -11
  32. package/dist/lib/pi-adapter/auth.js.map +1 -1
  33. package/dist/lib/pi-adapter/branding.js +764 -76
  34. package/dist/lib/pi-adapter/branding.js.map +1 -1
  35. package/dist/lib/pi-adapter/index.js.map +1 -1
  36. package/dist/lib/pi-adapter/interactive.js +179 -5
  37. package/dist/lib/pi-adapter/interactive.js.map +1 -1
  38. package/dist/lib/pi-adapter/pod-approval.js +8 -0
  39. package/dist/lib/pi-adapter/pod-approval.js.map +1 -0
  40. package/dist/lib/pi-adapter/pod-mirror-mapping.js +189 -0
  41. package/dist/lib/pi-adapter/pod-mirror-mapping.js.map +1 -0
  42. package/dist/lib/pi-adapter/pod-mirror.js +416 -0
  43. package/dist/lib/pi-adapter/pod-mirror.js.map +1 -0
  44. package/dist/lib/pi-adapter/pod-tools.js +104 -0
  45. package/dist/lib/pi-adapter/pod-tools.js.map +1 -0
  46. package/dist/lib/pi-adapter/runtime.js +327 -28
  47. package/dist/lib/pi-adapter/runtime.js.map +1 -1
  48. package/dist/lib/pi-adapter/session.js +608 -0
  49. package/dist/lib/pi-adapter/session.js.map +1 -0
  50. package/dist/lib/pi-adapter/stream.js +154 -4
  51. package/dist/lib/pi-adapter/stream.js.map +1 -1
  52. package/dist/lib/pi-adapter/theme.js.map +1 -1
  53. package/dist/lib/pi-adapter/web-fetch.js +154 -0
  54. package/dist/lib/pi-adapter/web-fetch.js.map +1 -0
  55. package/dist/lib/pod-chat-store.js +40 -30
  56. package/dist/lib/pod-chat-store.js.map +1 -1
  57. package/dist/lib/pod-data-session.js +110 -0
  58. package/dist/lib/pod-data-session.js.map +1 -0
  59. package/dist/lib/profile-identity.js +16 -60
  60. package/dist/lib/profile-identity.js.map +1 -1
  61. package/dist/lib/prompt.js.map +1 -1
  62. package/dist/lib/runtime-target.js +1 -1
  63. package/dist/lib/runtime-target.js.map +1 -1
  64. package/dist/lib/solid-auth.js.map +1 -1
  65. package/dist/lib/thread-utils.js.map +1 -1
  66. package/dist/lib/watch/archive.js +1 -1
  67. package/dist/lib/watch/archive.js.map +1 -1
  68. package/dist/lib/watch/auth.js +1 -1
  69. package/dist/lib/watch/auth.js.map +1 -1
  70. package/dist/lib/watch/codex-composer.js.map +1 -1
  71. package/dist/lib/watch/codex-footer.js.map +1 -1
  72. package/dist/lib/watch/codex-overlay.js.map +1 -1
  73. package/dist/lib/watch/codex-request-form.js +1 -1
  74. package/dist/lib/watch/codex-request-form.js.map +1 -1
  75. package/dist/lib/watch/codex-request-input.js.map +1 -1
  76. package/dist/lib/watch/display.js.map +1 -1
  77. package/dist/lib/watch/format.js.map +1 -1
  78. package/dist/lib/watch/hooks/claude.js +4 -0
  79. package/dist/lib/watch/hooks/claude.js.map +1 -1
  80. package/dist/lib/watch/hooks/codebuddy.js +4 -0
  81. package/dist/lib/watch/hooks/codebuddy.js.map +1 -1
  82. package/dist/lib/watch/hooks/codex.js +4 -0
  83. package/dist/lib/watch/hooks/codex.js.map +1 -1
  84. package/dist/lib/watch/hooks/index.js.map +1 -1
  85. package/dist/lib/watch/hooks/shared.js +0 -1
  86. package/dist/lib/watch/hooks/shared.js.map +1 -1
  87. package/dist/lib/watch/index.js.map +1 -1
  88. package/dist/lib/watch/pod-ai.js +29 -37
  89. package/dist/lib/watch/pod-ai.js.map +1 -1
  90. package/dist/lib/watch/pod-approval.js +822 -220
  91. package/dist/lib/watch/pod-approval.js.map +1 -1
  92. package/dist/lib/watch/pod-persistence.js +214 -106
  93. package/dist/lib/watch/pod-persistence.js.map +1 -1
  94. package/dist/lib/watch/runner.js +243 -38
  95. package/dist/lib/watch/runner.js.map +1 -1
  96. package/dist/lib/watch/secretary.js +238 -0
  97. package/dist/lib/watch/secretary.js.map +1 -0
  98. package/dist/lib/watch/types.js.map +1 -1
  99. package/dist/watch-cli.js +8 -34
  100. package/dist/watch-cli.js.map +1 -1
  101. package/package.json +3 -9
  102. package/vendor/agent-runtime/dist/acp.d.ts +27 -0
  103. package/vendor/agent-runtime/dist/acp.js +86 -0
  104. package/vendor/agent-runtime/dist/companion-model.d.ts +7 -0
  105. package/vendor/agent-runtime/dist/companion-model.js +12 -0
  106. package/vendor/agent-runtime/dist/index.d.ts +3 -0
  107. package/vendor/agent-runtime/dist/index.js +3 -0
  108. package/vendor/agent-runtime/dist/turn-controller.d.ts +69 -0
  109. package/vendor/agent-runtime/dist/turn-controller.js +129 -0
  110. package/vendor/agent-runtime/package.json +11 -0
  111. package/vendor/client/dist/client/index.d.ts +0 -118
  112. package/vendor/client/dist/client/index.js +0 -260
  113. package/vendor/client/dist/index.d.ts +0 -1
  114. package/vendor/client/dist/index.js +0 -1
  115. package/vendor/client/dist/watch/index.d.ts +0 -226
  116. package/vendor/client/dist/watch/index.js +0 -1114
  117. package/vendor/client/package.json +0 -9
@@ -1,24 +1,46 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { homedir } from 'node:os';
3
3
  import { basename, join } from 'node:path';
4
+ import { readFileSync } from 'node:fs';
4
5
  import { LINX_HOME_DIRNAME } from '@undefineds.co/models/client';
5
- import { keyHint, rawKeyHint } from '@mariozechner/pi-coding-agent';
6
+ import { keyHint, LoginDialogComponent, rawKeyHint } from '@mariozechner/pi-coding-agent';
6
7
  import { Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from '@mariozechner/pi-tui';
7
8
  import { loadCredentials } from '../credentials-store.js';
8
9
  import { extractUsernameFromWebId, resolveProfileDisplayName } from '../profile-identity.js';
9
- import { LINX_CLI_VERSION } from '../../generated/version.js';
10
10
  export const LINX_AGENT_DIR = join(homedir(), LINX_HOME_DIRNAME, 'agent');
11
11
  export const LINX_UPDATE_PACKAGE_NAME = '@undefineds.co/linx';
12
12
  export const LINX_CHANGELOG_URL = 'https://github.com/undefineds-co/linx-cli/releases';
13
+ export const LINX_CLI_VERSION = readLinxCliVersion();
14
+ const LINX_AUTH_LOGIN_IN_PROGRESS = Symbol.for('linx.tui.authLoginInProgress');
15
+ const LINX_AUTH_LOGIN_ON_INIT = Symbol.for('linx.tui.authLoginOnInit');
16
+ const LINX_AUTH_PENDING_RETRY = Symbol.for('linx.tui.authPendingRetry');
17
+ const LINX_AUTH_LOGIN_SCHEDULED = Symbol.for('linx.tui.authLoginScheduled');
18
+ const LINX_AUTH_REPORTING_ERROR = Symbol.for('linx.tui.authReportingError');
13
19
  const LINX_UPDATE_IN_PROGRESS = Symbol.for('linx.tui.updateInProgress');
14
- const LINX_UPDATE_RUNNER = Symbol.for('linx.tui.updateRunner');
20
+ const LINX_PROVIDER_ID = 'undefineds';
21
+ const AUTH_OPTION_BROWSER = 'Authorize in browser';
22
+ const AUTH_OPTION_API_KEY = 'Enter API key';
23
+ const AUTH_OPTION_EXIT = 'Exit';
24
+ const UPDATE_OPTION_INSTALL = 'Install update and restart';
25
+ const UPDATE_OPTION_CHANGELOG = 'Open changelog';
26
+ const UPDATE_OPTION_LATER = 'Later';
15
27
  export function applyLinxInteractiveBranding(interactive) {
16
28
  patchTerminalTitle(interactive);
17
29
  patchVersionCheck(interactive);
18
30
  patchUpdateNotification(interactive);
19
- patchUpdateCommand(interactive);
31
+ patchNativeOAuthSelectors(interactive);
32
+ patchLoginCommand(interactive);
33
+ patchAuthExpiredSessionEvents(interactive);
34
+ patchAuthExpiredLoginPrompt(interactive);
20
35
  patchHeader(interactive);
21
36
  }
37
+ export function requestLinxCloudLogin(interactive, reason = 'manual') {
38
+ if (!interactive.isInitialized) {
39
+ interactive[LINX_AUTH_LOGIN_ON_INIT] = reason;
40
+ return;
41
+ }
42
+ void startLinxCloudLogin(interactive, { reason });
43
+ }
22
44
  function patchTerminalTitle(interactive) {
23
45
  const original = interactive.updateTerminalTitle?.bind(interactive);
24
46
  interactive.updateTerminalTitle = function patchedUpdateTerminalTitle() {
@@ -43,7 +65,7 @@ function patchVersionCheck(interactive) {
43
65
  }
44
66
  const body = await response.json();
45
67
  const latest = typeof body.version === 'string' ? body.version.trim() : '';
46
- if (!latest || !isNewerVersion(latest, LINX_CLI_VERSION)) {
68
+ if (!latest || !isVersionNewer(latest, LINX_CLI_VERSION)) {
47
69
  return undefined;
48
70
  }
49
71
  return latest;
@@ -55,45 +77,109 @@ function patchVersionCheck(interactive) {
55
77
  }
56
78
  function patchUpdateNotification(interactive) {
57
79
  interactive.showNewVersionNotification = function patchedShowNewVersionNotification(newVersion) {
58
- const lines = [
59
- '\x1b[1m\x1b[33mLinX Update Available\x1b[39m\x1b[22m',
60
- `\x1b[2mNew version ${newVersion} is available. \x1b[22m\x1b[36mType /update to install now.\x1b[39m`,
61
- `\x1b[2mManual install: \x1b[22m\x1b[36mnpm install -g ${LINX_UPDATE_PACKAGE_NAME}@latest\x1b[39m`,
62
- `\x1b[2mChangelog: \x1b[22m\x1b[36m${LINX_CHANGELOG_URL}\x1b[39m`,
63
- ];
64
- this.chatContainer?.addChild?.(new Text(lines.join('\n'), 1, 0));
65
- this.ui?.requestRender?.();
80
+ void showLinxUpdateSelector(this, newVersion);
66
81
  };
67
82
  }
68
- function isNewerVersion(candidate, current) {
69
- const candidateParts = parseSemverCore(candidate);
70
- const currentParts = parseSemverCore(current);
71
- if (!candidateParts || !currentParts) {
72
- return candidate !== current;
83
+ async function showLinxUpdateSelector(interactive, newVersion) {
84
+ if (interactive[LINX_UPDATE_IN_PROGRESS]) {
85
+ return;
73
86
  }
74
- for (let index = 0; index < 3; index += 1) {
75
- if (candidateParts[index] > currentParts[index]) {
76
- return true;
87
+ interactive[LINX_UPDATE_IN_PROGRESS] = true;
88
+ try {
89
+ const title = [
90
+ 'LinX update available',
91
+ `Current ${LINX_CLI_VERSION} -> latest ${newVersion}`,
92
+ 'Choose how to handle this update.',
93
+ ].join('\n');
94
+ const options = [UPDATE_OPTION_INSTALL, UPDATE_OPTION_CHANGELOG, UPDATE_OPTION_LATER];
95
+ const selected = typeof interactive.showExtensionSelector === 'function'
96
+ ? await interactive.showExtensionSelector(title, options)
97
+ : undefined;
98
+ if (selected === UPDATE_OPTION_INSTALL) {
99
+ await installLinxUpdateAndRestart(interactive, newVersion);
100
+ return;
77
101
  }
78
- if (candidateParts[index] < currentParts[index]) {
79
- return false;
102
+ if (selected === UPDATE_OPTION_CHANGELOG) {
103
+ openExternalUrl(LINX_CHANGELOG_URL, interactive);
104
+ interactive.showStatus?.(`Opened LinX changelog for ${newVersion}.`);
105
+ return;
80
106
  }
107
+ if (!selected) {
108
+ showLinxUpdateFallback(interactive, newVersion);
109
+ return;
110
+ }
111
+ interactive.showStatus?.(`Skipped LinX ${newVersion} for now.`);
112
+ }
113
+ finally {
114
+ interactive[LINX_UPDATE_IN_PROGRESS] = false;
81
115
  }
82
- return false;
83
116
  }
84
- function parseSemverCore(version) {
85
- const match = version.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/);
86
- if (!match) {
87
- return null;
117
+ async function installLinxUpdateAndRestart(interactive, newVersion) {
118
+ interactive.showStatus?.(`Installing LinX ${newVersion}...`);
119
+ interactive.ui?.requestRender?.();
120
+ try {
121
+ await runNpmInstallLatest();
88
122
  }
89
- return [Number(match[1]), Number(match[2]), Number(match[3])];
123
+ catch (error) {
124
+ const message = error instanceof Error ? error.message : String(error);
125
+ interactive.showError?.(`LinX update failed: ${message}`);
126
+ return;
127
+ }
128
+ interactive.showStatus?.(`LinX ${newVersion} installed. Restarting...`);
129
+ interactive.ui?.requestRender?.();
130
+ restartCurrentProcess(interactive);
90
131
  }
91
- function patchUpdateCommand(interactive) {
132
+ function runNpmInstallLatest() {
133
+ const npmCommand = process.env.npm_execpath || 'npm';
134
+ const args = ['install', '-g', '--omit=peer', `${LINX_UPDATE_PACKAGE_NAME}@latest`];
135
+ return new Promise((resolve, reject) => {
136
+ const child = spawn(npmCommand, args, {
137
+ stdio: ['ignore', 'pipe', 'pipe'],
138
+ shell: false,
139
+ });
140
+ let stderr = '';
141
+ child.stderr?.on('data', (chunk) => {
142
+ stderr += chunk.toString();
143
+ });
144
+ child.on('error', reject);
145
+ child.on('close', (code) => {
146
+ if (code === 0) {
147
+ resolve();
148
+ return;
149
+ }
150
+ reject(new Error(stderr.trim() || `npm install exited with code ${code ?? 'unknown'}`));
151
+ });
152
+ });
153
+ }
154
+ function restartCurrentProcess(interactive) {
155
+ const child = spawn(process.execPath, process.argv.slice(1), {
156
+ cwd: process.cwd(),
157
+ env: process.env,
158
+ stdio: 'inherit',
159
+ detached: false,
160
+ });
161
+ child.on('error', (error) => {
162
+ interactive.showError?.(`LinX restart failed: ${error.message}`);
163
+ });
164
+ interactive.stop?.();
165
+ setTimeout(() => process.exit(0), 50);
166
+ }
167
+ function showLinxUpdateFallback(interactive, newVersion) {
168
+ const lines = [
169
+ '\x1b[1m\x1b[33mLinX update available\x1b[39m\x1b[22m',
170
+ `\x1b[2mCurrent ${LINX_CLI_VERSION} -> latest ${newVersion}\x1b[22m`,
171
+ `\x1b[2mRun \x1b[22m\x1b[36mnpm install -g ${LINX_UPDATE_PACKAGE_NAME}@latest\x1b[39m\x1b[2m if this terminal cannot show the update selector.\x1b[22m`,
172
+ `\x1b[2mChangelog: \x1b[22m\x1b[36m${LINX_CHANGELOG_URL}\x1b[39m`,
173
+ ];
174
+ interactive.chatContainer?.addChild?.(new Text(lines.join('\n'), 1, 0));
175
+ interactive.ui?.requestRender?.();
176
+ }
177
+ function patchLoginCommand(interactive) {
92
178
  const originalSetup = interactive.setupEditorSubmitHandler?.bind(interactive);
93
179
  if (typeof originalSetup !== 'function') {
94
180
  return;
95
181
  }
96
- interactive.setupEditorSubmitHandler = function patchedSetupEditorSubmitHandler() {
182
+ interactive.setupEditorSubmitHandler = function patchedLinxLoginSetupEditorSubmitHandler() {
97
183
  originalSetup();
98
184
  const originalSubmit = this.defaultEditor?.onSubmit?.bind(this.defaultEditor);
99
185
  if (typeof originalSubmit !== 'function') {
@@ -101,77 +187,632 @@ function patchUpdateCommand(interactive) {
101
187
  }
102
188
  this.defaultEditor.onSubmit = async (text) => {
103
189
  const command = text.trim();
104
- if (command === '/update' || command === '/update linx') {
190
+ if (command === '/login') {
105
191
  this.editor?.setText?.('');
106
- await runLinxUpdateFromTui(this);
192
+ await startLinxCloudLogin(this);
107
193
  return;
108
194
  }
109
195
  await originalSubmit(text);
110
196
  };
111
197
  };
112
198
  }
113
- async function runLinxUpdateFromTui(interactive) {
114
- if (interactive[LINX_UPDATE_IN_PROGRESS]) {
115
- interactive.showStatus?.('LinX update is already running');
199
+ function patchNativeOAuthSelectors(interactive) {
200
+ interactive.showOAuthSelector = async function patchedLinxOAuthSelector(mode = 'login') {
201
+ if (mode === 'logout') {
202
+ const authStorage = this.session?.modelRegistry?.authStorage;
203
+ authStorage?.logout?.(LINX_PROVIDER_ID);
204
+ authStorage?.setRuntimeApiKey?.(LINX_PROVIDER_ID, '');
205
+ await refreshLinxAuthState(this);
206
+ this.showStatus?.('Logged out of LinX Cloud.');
207
+ return;
208
+ }
209
+ await startLinxCloudLogin(this, { reason: 'manual' });
210
+ };
211
+ interactive.showLoginDialog = async function patchedLinxLoginDialog(providerId) {
212
+ if (!providerId || providerId === LINX_PROVIDER_ID) {
213
+ await startLinxCloudLogin(this, { reason: 'manual' });
214
+ return;
215
+ }
216
+ this.showStatus?.('LinX only supports LinX Cloud authentication in this TUI.');
217
+ await startLinxCloudLogin(this, { reason: 'manual' });
218
+ };
219
+ }
220
+ function patchAuthExpiredSessionEvents(interactive) {
221
+ const originalHandleEvent = interactive.handleEvent?.bind(interactive);
222
+ if (typeof originalHandleEvent !== 'function') {
116
223
  return;
117
224
  }
118
- interactive[LINX_UPDATE_IN_PROGRESS] = true;
119
- const packageSpec = `${LINX_UPDATE_PACKAGE_NAME}@latest`;
120
- const npmCommand = process.env.npm_execpath && !process.env.npm_execpath.endsWith('npx-cli.js')
121
- ? process.execPath
122
- : 'npm';
123
- const args = npmCommand === process.execPath
124
- ? [process.env.npm_execpath, 'install', '-g', packageSpec]
125
- : ['install', '-g', packageSpec];
225
+ interactive.handleEvent = async function patchedHandleEvent(event) {
226
+ if (eventHasLinxAuthExpiredError(event)) {
227
+ prepareLinxAuthExpiredRetry(this);
228
+ suppressLinxAuthExpiredAssistantError(this);
229
+ scheduleLinxCloudLogin(this, 'expired');
230
+ return undefined;
231
+ }
232
+ const result = await originalHandleEvent(event);
233
+ return result;
234
+ };
235
+ }
236
+ function patchAuthExpiredLoginPrompt(interactive) {
237
+ const originalShowError = interactive.showError?.bind(interactive);
238
+ if (typeof originalShowError !== 'function') {
239
+ return;
240
+ }
241
+ interactive.showError = function patchedShowError(errorMessage) {
242
+ const text = typeof errorMessage === 'string' ? errorMessage : String(errorMessage);
243
+ if (!isLinxAuthExpiredError(text)) {
244
+ return originalShowError(errorMessage);
245
+ }
246
+ scheduleLinxCloudLogin(this, 'expired');
247
+ return undefined;
248
+ };
249
+ }
250
+ function isLinxAuthExpiredError(text) {
251
+ const normalized = stripAnsi(text).toLowerCase();
252
+ return normalized.includes('linx cloud login expired')
253
+ || normalized.includes('invalid solid token')
254
+ || (normalized.includes('chat request failed (401)') && normalized.includes('unauthorized'));
255
+ }
256
+ function eventHasLinxAuthExpiredError(event) {
257
+ if (!isRecord(event)) {
258
+ return false;
259
+ }
260
+ const message = isRecord(event.message) ? event.message : undefined;
261
+ const errorMessage = typeof message?.errorMessage === 'string' ? message.errorMessage : '';
262
+ const error = isRecord(event.error) ? event.error : undefined;
263
+ const nestedErrorMessage = typeof error?.errorMessage === 'string' ? error.errorMessage : '';
264
+ return isLinxAuthExpiredError(`${errorMessage}\n${nestedErrorMessage}`);
265
+ }
266
+ async function startLinxCloudLogin(interactive, options = {}) {
267
+ if (interactive[LINX_AUTH_LOGIN_IN_PROGRESS]) {
268
+ return;
269
+ }
270
+ interactive[LINX_AUTH_LOGIN_IN_PROGRESS] = true;
126
271
  try {
127
- interactive.showStatus?.(`Installing LinX update: ${packageSpec}`);
128
- interactive.ui?.requestRender?.();
129
- interactive.ui?.stop?.();
130
- const runner = resolveUpdateRunner(interactive);
131
- const result = await runner(npmCommand, args);
132
- interactive.ui?.start?.();
133
- if (result.exitCode === 0) {
134
- interactive.showStatus?.('LinX updated. Restart linx to use the new version.');
272
+ const authStorage = interactive.session?.modelRegistry?.authStorage;
273
+ if (!authStorage) {
274
+ prefillLoginCommand(interactive);
275
+ return;
276
+ }
277
+ const reason = options.reason ?? 'manual';
278
+ const selected = await selectLinxAuthMethod(interactive, reason);
279
+ if (!selected) {
280
+ interactive.showStatus?.('LinX Cloud authorization cancelled.');
135
281
  return;
136
282
  }
137
- const detail = result.signal ? `signal ${result.signal}` : `exit code ${result.exitCode}`;
138
- interactive.showError?.(`LinX update failed with ${detail}`);
283
+ if (selected === AUTH_OPTION_BROWSER) {
284
+ if (typeof authStorage.login !== 'function') {
285
+ prefillLoginCommand(interactive);
286
+ return;
287
+ }
288
+ await runLinxCloudBrowserLogin(interactive, authStorage, reason);
289
+ await refreshLinxAuthState(interactive);
290
+ await finishLinxAuthSuccess(interactive, reason, 'Browser authorization complete.');
291
+ return;
292
+ }
293
+ if (selected === AUTH_OPTION_API_KEY) {
294
+ await promptForLinxApiKey(interactive, reason);
295
+ return;
296
+ }
297
+ if (selected === AUTH_OPTION_EXIT) {
298
+ if (reason === 'startup') {
299
+ interactive.stop?.();
300
+ }
301
+ else {
302
+ interactive.showStatus?.('LinX Cloud authorization cancelled.');
303
+ }
304
+ }
139
305
  }
140
306
  catch (error) {
141
- interactive.ui?.start?.();
142
307
  const message = error instanceof Error ? error.message : String(error);
143
- interactive.showError?.(`LinX update failed: ${message}`);
308
+ reportLinxLoginError(interactive, message);
144
309
  }
145
310
  finally {
146
- interactive[LINX_UPDATE_IN_PROGRESS] = false;
147
- interactive.ui?.requestRender?.();
311
+ interactive[LINX_AUTH_LOGIN_IN_PROGRESS] = false;
312
+ }
313
+ }
314
+ function scheduleLinxCloudLogin(interactive, reason) {
315
+ if (interactive[LINX_AUTH_LOGIN_IN_PROGRESS] || interactive[LINX_AUTH_LOGIN_SCHEDULED]) {
316
+ return;
148
317
  }
318
+ interactive[LINX_AUTH_LOGIN_SCHEDULED] = true;
319
+ setTimeout(() => {
320
+ interactive[LINX_AUTH_LOGIN_SCHEDULED] = false;
321
+ void startLinxCloudLogin(interactive, { reason });
322
+ }, 0);
149
323
  }
150
- function resolveUpdateRunner(interactive) {
151
- return typeof interactive[LINX_UPDATE_RUNNER] === 'function'
152
- ? interactive[LINX_UPDATE_RUNNER]
153
- : spawnInstall;
324
+ function reportLinxLoginError(interactive, message) {
325
+ const rendered = normalizeLinxLoginError(message);
326
+ if (interactive[LINX_AUTH_REPORTING_ERROR]) {
327
+ interactive.showStatus?.(rendered);
328
+ return;
329
+ }
330
+ interactive[LINX_AUTH_REPORTING_ERROR] = true;
331
+ try {
332
+ if (typeof interactive.showError === 'function') {
333
+ interactive.showError(rendered);
334
+ }
335
+ else {
336
+ interactive.showStatus?.(rendered);
337
+ }
338
+ }
339
+ finally {
340
+ interactive[LINX_AUTH_REPORTING_ERROR] = false;
341
+ }
342
+ }
343
+ function normalizeLinxLoginError(message) {
344
+ const oidcCallbackError = /^OIDC callback returned\b/i.test(message);
345
+ if (oidcCallbackError) {
346
+ return `LinX Cloud login failed: ${message}`;
347
+ }
348
+ if (/server_error/i.test(message)) {
349
+ return `LinX Cloud login failed: the identity server rejected this browser login. ${message}`;
350
+ }
351
+ return `LinX Cloud login failed: ${message}`;
352
+ }
353
+ async function selectLinxAuthMethod(interactive, reason) {
354
+ const title = buildLinxAuthPromptTitle(reason, resolveRuntimeProviderLabel(interactive));
355
+ const options = [AUTH_OPTION_BROWSER, AUTH_OPTION_API_KEY, AUTH_OPTION_EXIT];
356
+ if (typeof interactive.showExtensionSelector === 'function') {
357
+ return await interactive.showExtensionSelector(title, options);
358
+ }
359
+ showLinxAuthFallback(interactive, title, options);
360
+ return undefined;
361
+ }
362
+ function buildLinxAuthPromptTitle(reason, providerLabel) {
363
+ if (reason === 'startup') {
364
+ return [
365
+ 'LinX Cloud login required',
366
+ `Connect to ${providerLabel} before using LinX TUI.`,
367
+ 'Choose a sign-in method.',
368
+ ].join('\n');
369
+ }
370
+ if (reason === 'expired') {
371
+ return [
372
+ 'LinX Cloud login expired',
373
+ 'Your current Solid token was rejected by LinX Cloud.',
374
+ 'Re-authorize or provide an API key, then retry your message.',
375
+ ].join('\n');
376
+ }
377
+ return [
378
+ 'LinX Cloud authorization',
379
+ `Choose how LinX should authenticate with ${providerLabel}.`,
380
+ ].join('\n');
381
+ }
382
+ function showLinxAuthFallback(interactive, title, options) {
383
+ interactive.chatContainer?.addChild?.(new Text([
384
+ `\x1b[1m${title}\x1b[22m`,
385
+ '',
386
+ ...options.map((option) => `- ${option}`),
387
+ '',
388
+ 'This terminal build cannot render the LinX auth selector. Run `linx login` in another shell.',
389
+ ].join('\n'), 1, 0));
390
+ interactive.ui?.requestRender?.();
391
+ }
392
+ async function promptForLinxApiKey(interactive, reason) {
393
+ if (typeof interactive.showExtensionInput !== 'function') {
394
+ interactive.showError?.('This terminal build cannot collect an API key inside the TUI.');
395
+ return;
396
+ }
397
+ const apiKey = await interactive.showExtensionInput([
398
+ reason === 'expired' ? 'Enter LinX Cloud API key' : 'Use LinX Cloud API key',
399
+ 'Paste a key for this TUI session. Press Escape to cancel.',
400
+ ].join('\n'), 'linx API key');
401
+ const trimmed = typeof apiKey === 'string' ? apiKey.trim() : '';
402
+ if (!trimmed) {
403
+ interactive.showStatus?.('LinX Cloud API key entry cancelled.');
404
+ return;
405
+ }
406
+ const authStorage = interactive.session?.modelRegistry?.authStorage;
407
+ authStorage?.setRuntimeApiKey?.(LINX_PROVIDER_ID, trimmed);
408
+ authStorage?.set?.(LINX_PROVIDER_ID, { type: 'api_key', key: trimmed });
409
+ await refreshLinxAuthState(interactive);
410
+ await finishLinxAuthSuccess(interactive, reason, 'API key saved for this TUI session.');
411
+ }
412
+ async function finishLinxAuthSuccess(interactive, reason, detail) {
413
+ const prefix = authStatusPrefix(reason);
414
+ const retryStarted = await retryPendingLinxAuthTurn(interactive, reason);
415
+ if (retryStarted) {
416
+ interactive.showStatus?.(`${prefix} ${detail} Retrying your message...`);
417
+ return;
418
+ }
419
+ const suffix = reason === 'expired' ? ' Retry your message.' : '';
420
+ interactive.showStatus?.(`${prefix} ${detail}${suffix}`);
421
+ }
422
+ function prepareLinxAuthExpiredRetry(interactive) {
423
+ if (interactive[LINX_AUTH_PENDING_RETRY]) {
424
+ return;
425
+ }
426
+ const session = interactive.session;
427
+ const sessionManager = session?.sessionManager;
428
+ const leafId = typeof sessionManager?.getLeafId === 'function'
429
+ ? sessionManager.getLeafId()
430
+ : undefined;
431
+ const leafEntry = leafId && typeof sessionManager?.getEntry === 'function'
432
+ ? sessionManager.getEntry(leafId)
433
+ : undefined;
434
+ const leafMessage = leafEntry?.type === 'message' ? leafEntry.message : undefined;
435
+ const userEntry = findLastUserMessageEntry(sessionManager, leafId);
436
+ const promptText = extractUserMessageText(userEntry?.message)
437
+ ?? extractUserMessageText(leafMessage)
438
+ ?? findLastUserMessageText(session?.state?.messages);
439
+ const pending = {
440
+ continueFromId: userEntry?.id ?? (leafMessage?.role === 'user' ? leafId : undefined),
441
+ promptText,
442
+ promptParentId: userEntry?.parentId ?? (leafMessage?.role === 'user' ? leafEntry.parentId : undefined),
443
+ };
444
+ interactive[LINX_AUTH_PENDING_RETRY] = pending;
445
+ // AgentSession persists the assistant error after TUI subscribers run. Restore
446
+ // the active branch on the next tick so "continue" never resumes from the
447
+ // failed auth assistant message if the user cancels or login fails.
448
+ setTimeout(() => {
449
+ if (interactive[LINX_AUTH_PENDING_RETRY] === pending) {
450
+ restoreLinxRetryBranch(interactive.session, pending.continueFromId);
451
+ }
452
+ }, 0);
453
+ }
454
+ function suppressLinxAuthExpiredAssistantError(interactive) {
455
+ const streamingComponent = interactive.streamingComponent;
456
+ if (streamingComponent) {
457
+ interactive.chatContainer?.removeChild?.(streamingComponent);
458
+ }
459
+ interactive.streamingComponent = undefined;
460
+ interactive.streamingMessage = undefined;
461
+ interactive.footer?.invalidate?.();
462
+ interactive.ui?.requestRender?.();
154
463
  }
155
- function spawnInstall(command, args) {
464
+ async function retryPendingLinxAuthTurn(interactive, reason) {
465
+ if (reason !== 'expired') {
466
+ return false;
467
+ }
468
+ const pending = interactive[LINX_AUTH_PENDING_RETRY];
469
+ if (!pending) {
470
+ return false;
471
+ }
472
+ interactive[LINX_AUTH_PENDING_RETRY] = undefined;
473
+ const session = interactive.session;
474
+ const sessionManager = session?.sessionManager;
475
+ if (!session || !sessionManager) {
476
+ return false;
477
+ }
478
+ await session.agent?.waitForIdle?.();
479
+ try {
480
+ restoreLinxRetryBranch(session, pending.continueFromId);
481
+ if (typeof session.agent?.continue === 'function') {
482
+ startLinxContinuation(interactive, session, pending);
483
+ return true;
484
+ }
485
+ }
486
+ catch (error) {
487
+ if (!pending.promptText) {
488
+ throw error;
489
+ }
490
+ }
491
+ if (!pending.promptText || typeof session.prompt !== 'function') {
492
+ return false;
493
+ }
494
+ restoreLinxRetryBranch(session, pending.promptParentId);
495
+ const promptResult = session.prompt(pending.promptText);
496
+ if (isPromiseLike(promptResult)) {
497
+ promptResult.catch((error) => {
498
+ const message = error instanceof Error ? error.message : String(error);
499
+ interactive.showError?.(`LinX Cloud retry failed: ${message}`);
500
+ });
501
+ }
502
+ return true;
503
+ }
504
+ function startLinxContinuation(interactive, session, pending) {
505
+ try {
506
+ const result = session.agent.continue();
507
+ if (isPromiseLike(result)) {
508
+ result.catch((error) => {
509
+ void retryLinxPromptFallback(interactive, session, pending, error);
510
+ });
511
+ }
512
+ }
513
+ catch (error) {
514
+ void retryLinxPromptFallback(interactive, session, pending, error);
515
+ }
516
+ }
517
+ async function retryLinxPromptFallback(interactive, session, pending, cause) {
518
+ if (!pending.promptText || typeof session?.prompt !== 'function') {
519
+ const message = cause instanceof Error ? cause.message : String(cause);
520
+ interactive.showError?.(`LinX Cloud retry failed: ${message}`);
521
+ return;
522
+ }
523
+ try {
524
+ restoreLinxRetryBranch(session, pending.promptParentId);
525
+ await session.prompt(pending.promptText);
526
+ }
527
+ catch (error) {
528
+ const message = error instanceof Error ? error.message : String(error);
529
+ interactive.showError?.(`LinX Cloud retry failed: ${message}`);
530
+ }
531
+ }
532
+ function restoreLinxRetryBranch(session, leafId) {
533
+ const sessionManager = session?.sessionManager;
534
+ if (!sessionManager) {
535
+ return;
536
+ }
537
+ if (typeof leafId === 'string' && leafId) {
538
+ sessionManager.branch?.(leafId);
539
+ }
540
+ else if (leafId === null) {
541
+ sessionManager.resetLeaf?.();
542
+ }
543
+ const context = sessionManager.buildSessionContext?.();
544
+ if (context?.messages && session.agent?.state) {
545
+ session.agent.state.messages = context.messages;
546
+ }
547
+ }
548
+ function findLastUserMessageText(messages) {
549
+ if (!Array.isArray(messages)) {
550
+ return undefined;
551
+ }
552
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
553
+ const text = extractUserMessageText(messages[index]);
554
+ if (text) {
555
+ return text;
556
+ }
557
+ }
558
+ return undefined;
559
+ }
560
+ function findLastUserMessageEntry(sessionManager, leafId) {
561
+ const branch = typeof sessionManager?.getBranch === 'function' && typeof leafId === 'string'
562
+ ? sessionManager.getBranch(leafId)
563
+ : undefined;
564
+ const entries = Array.isArray(branch) && branch.length > 0
565
+ ? branch
566
+ : typeof sessionManager?.getEntries === 'function'
567
+ ? sessionManager.getEntries()
568
+ : [];
569
+ if (!Array.isArray(entries)) {
570
+ return undefined;
571
+ }
572
+ for (let index = entries.length - 1; index >= 0; index -= 1) {
573
+ const entry = entries[index];
574
+ if (isRecord(entry)
575
+ && entry.type === 'message'
576
+ && typeof entry.id === 'string'
577
+ && isRecord(entry.message)
578
+ && entry.message.role === 'user') {
579
+ return {
580
+ id: entry.id,
581
+ parentId: normalizeParentId(entry.parentId),
582
+ message: entry.message,
583
+ };
584
+ }
585
+ }
586
+ return undefined;
587
+ }
588
+ function normalizeParentId(parentId) {
589
+ if (typeof parentId === 'string') {
590
+ return parentId;
591
+ }
592
+ if (parentId === null) {
593
+ return null;
594
+ }
595
+ return undefined;
596
+ }
597
+ function extractUserMessageText(message) {
598
+ if (!isRecord(message) || message.role !== 'user') {
599
+ return undefined;
600
+ }
601
+ const content = message.content;
602
+ if (typeof content === 'string') {
603
+ return content.trim() || undefined;
604
+ }
605
+ if (!Array.isArray(content)) {
606
+ return undefined;
607
+ }
608
+ const text = content
609
+ .filter((entry) => (isRecord(entry) && entry.type === 'text' && typeof entry.text === 'string'))
610
+ .map((entry) => entry.text)
611
+ .join('')
612
+ .trim();
613
+ return text || undefined;
614
+ }
615
+ async function refreshLinxAuthState(interactive) {
616
+ interactive.session?.modelRegistry?.refresh?.();
617
+ await interactive.updateAvailableProviderCount?.();
618
+ interactive.ui?.requestRender?.();
619
+ }
620
+ function authStatusPrefix(reason) {
621
+ if (reason === 'expired') {
622
+ return 'LinX Cloud login refreshed.';
623
+ }
624
+ if (reason === 'startup') {
625
+ return 'LinX Cloud connected.';
626
+ }
627
+ return 'LinX Cloud authorization updated.';
628
+ }
629
+ async function runLinxCloudLogin(interactive, authStorage, reason) {
630
+ await authStorage.login(LINX_PROVIDER_ID, {
631
+ forceFresh: true,
632
+ onAuth(info) {
633
+ showLinxLoginUrl(interactive, info);
634
+ openLoginUrl(info.url, interactive);
635
+ if (info.instructions) {
636
+ interactive.showStatus?.(info.instructions);
637
+ }
638
+ },
639
+ onProgress(message) {
640
+ interactive.showStatus?.(message);
641
+ interactive.ui?.requestRender?.();
642
+ },
643
+ onManualCodeInput(signal) {
644
+ return promptForLinxManualRedirectUrl(interactive, signal);
645
+ },
646
+ });
647
+ syncRuntimeCredential(interactive);
648
+ }
649
+ async function runLinxCloudBrowserLogin(interactive, authStorage, reason) {
650
+ if (canRenderLinxLoginDialog(interactive)) {
651
+ await runLinxCloudLoginDialog(interactive, authStorage, reason);
652
+ return;
653
+ }
654
+ await runLinxCloudLogin(interactive, authStorage, reason);
655
+ }
656
+ function canRenderLinxLoginDialog(interactive) {
657
+ return Boolean(interactive.ui
658
+ && typeof interactive.editorContainer?.clear === 'function'
659
+ && typeof interactive.editorContainer?.addChild === 'function'
660
+ && interactive.editor);
661
+ }
662
+ async function runLinxCloudLoginDialog(interactive, authStorage, reason) {
663
+ const dialog = new LoginDialogComponent(interactive.ui, LINX_PROVIDER_ID, () => undefined);
664
+ const restoreEditor = () => {
665
+ interactive.editorContainer.clear();
666
+ interactive.editorContainer.addChild(interactive.editor);
667
+ interactive.ui?.setFocus?.(interactive.editor);
668
+ interactive.ui?.requestRender?.();
669
+ };
670
+ interactive.editorContainer.clear();
671
+ interactive.editorContainer.addChild(dialog);
672
+ interactive.ui?.setFocus?.(dialog);
673
+ interactive.ui?.requestRender?.();
674
+ let manualRedirectResolve;
675
+ let manualRedirectReject;
676
+ const manualRedirectPromise = new Promise((resolve, reject) => {
677
+ manualRedirectResolve = resolve;
678
+ manualRedirectReject = reject;
679
+ });
680
+ try {
681
+ await authStorage.login(LINX_PROVIDER_ID, {
682
+ forceFresh: true,
683
+ onAuth(info) {
684
+ dialog.showAuth(info.url, info.instructions);
685
+ dialog.showManualInput('Paste redirect URL below, or complete login in browser:')
686
+ .then((value) => {
687
+ if (value && manualRedirectResolve) {
688
+ manualRedirectResolve(value);
689
+ manualRedirectResolve = undefined;
690
+ manualRedirectReject = undefined;
691
+ }
692
+ })
693
+ .catch((error) => {
694
+ if (manualRedirectReject) {
695
+ manualRedirectReject(error);
696
+ manualRedirectResolve = undefined;
697
+ manualRedirectReject = undefined;
698
+ }
699
+ });
700
+ },
701
+ onProgress(message) {
702
+ dialog.showProgress(message);
703
+ },
704
+ onManualCodeInput(signal) {
705
+ return waitForLinxDialogManualRedirect(manualRedirectPromise, signal);
706
+ },
707
+ signal: dialog.signal,
708
+ });
709
+ syncRuntimeCredential(interactive);
710
+ }
711
+ finally {
712
+ restoreEditor();
713
+ }
714
+ }
715
+ function waitForLinxDialogManualRedirect(manualRedirectPromise, signal) {
716
+ if (!signal) {
717
+ return manualRedirectPromise;
718
+ }
719
+ if (signal.aborted) {
720
+ return Promise.resolve('');
721
+ }
156
722
  return new Promise((resolve, reject) => {
157
- const child = spawn(command, args, {
158
- stdio: 'inherit',
159
- shell: process.platform === 'win32',
723
+ const onAbort = () => resolve('');
724
+ signal.addEventListener('abort', onAbort, { once: true });
725
+ manualRedirectPromise
726
+ .then((value) => {
727
+ signal.removeEventListener('abort', onAbort);
728
+ resolve(value);
729
+ })
730
+ .catch((error) => {
731
+ signal.removeEventListener('abort', onAbort);
732
+ reject(error);
160
733
  });
161
- child.once('error', reject);
162
- child.once('close', (exitCode, signal) => resolve({ exitCode, signal }));
163
734
  });
164
735
  }
736
+ async function promptForLinxManualRedirectUrl(interactive, signal) {
737
+ if (typeof interactive.showExtensionInput !== 'function') {
738
+ throw new Error('Manual redirect paste is not available in this terminal. Run `linx login` in another shell if the browser callback is blocked.');
739
+ }
740
+ const redirect = await interactive.showExtensionInput([
741
+ 'Paste final redirect URL',
742
+ 'If the browser cannot return to this terminal, paste the full callback URL below.',
743
+ ].join('\n'), 'http://127.0.0.1:PORT/auth/callback?code=...&state=...&iss=...', signal ? { signal } : undefined);
744
+ const trimmed = typeof redirect === 'string' ? redirect.trim() : '';
745
+ if (!trimmed) {
746
+ throw new Error('Login cancelled');
747
+ }
748
+ return trimmed;
749
+ }
750
+ function syncRuntimeCredential(interactive) {
751
+ const authStorage = interactive.session?.modelRegistry?.authStorage;
752
+ const credential = authStorage?.get?.(LINX_PROVIDER_ID);
753
+ if (credential?.type === 'oauth' && typeof credential.access === 'string' && credential.access) {
754
+ authStorage.setRuntimeApiKey?.(LINX_PROVIDER_ID, credential.access);
755
+ return;
756
+ }
757
+ if (credential?.type === 'api_key' && typeof credential.key === 'string' && credential.key) {
758
+ authStorage.setRuntimeApiKey?.(LINX_PROVIDER_ID, credential.key);
759
+ }
760
+ }
761
+ function showLinxLoginUrl(interactive, info) {
762
+ const lines = [
763
+ '\x1b[1mLinX Cloud authorization\x1b[22m',
764
+ 'Complete consent in the browser, then return here.',
765
+ '',
766
+ `\x1b[36m${info.url}\x1b[39m`,
767
+ ];
768
+ if (info.instructions) {
769
+ lines.push('', `\x1b[2m${info.instructions}\x1b[22m`);
770
+ }
771
+ interactive.chatContainer?.addChild?.(new Text(lines.join('\n'), 1, 0));
772
+ interactive.ui?.requestRender?.();
773
+ }
774
+ function openLoginUrl(url, interactive) {
775
+ openExternalUrl(url, interactive);
776
+ }
777
+ function openExternalUrl(url, interactive) {
778
+ if (typeof interactive.openExternal === 'function') {
779
+ interactive.openExternal(url);
780
+ return;
781
+ }
782
+ const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
783
+ const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
784
+ const child = spawn(command, args, {
785
+ detached: true,
786
+ stdio: 'ignore',
787
+ shell: false,
788
+ });
789
+ child.unref();
790
+ }
791
+ function prefillLoginCommand(interactive) {
792
+ interactive.editor?.setText?.('/login');
793
+ interactive.ui?.setFocus?.(interactive.editor);
794
+ interactive.ui?.requestRender?.();
795
+ }
165
796
  function patchHeader(interactive) {
166
- const originalInit = interactive.init.bind(interactive);
797
+ const originalInit = interactive.init?.bind(interactive);
798
+ if (typeof originalInit !== 'function') {
799
+ return;
800
+ }
167
801
  interactive.init = async function patchedInit() {
168
802
  await originalInit();
803
+ if (this[LINX_AUTH_LOGIN_ON_INIT]) {
804
+ const reason = typeof this[LINX_AUTH_LOGIN_ON_INIT] === 'string'
805
+ ? this[LINX_AUTH_LOGIN_ON_INIT]
806
+ : 'startup';
807
+ this[LINX_AUTH_LOGIN_ON_INIT] = false;
808
+ queueMicrotask(() => startLinxCloudLogin(this, { reason }));
809
+ }
169
810
  const quietStartup = this.options?.verbose ? false : this.settingsManager?.getQuietStartup?.();
170
811
  if (quietStartup) {
171
812
  return;
172
813
  }
173
814
  let profileDisplayName = null;
174
- const replacement = new LinxWelcomeCard(() => buildHeaderState(this, profileDisplayName));
815
+ const replacement = new LinxWelcomeCard(() => buildLinxWelcomeCardState(this, profileDisplayName));
175
816
  const currentHeader = this.customHeader ?? this.builtInHeader;
176
817
  const index = this.headerContainer?.children?.indexOf?.(currentHeader) ?? -1;
177
818
  if (index >= 0) {
@@ -227,13 +868,13 @@ class LinxWelcomeCard {
227
868
  ];
228
869
  }
229
870
  }
230
- function buildHeaderState(interactive, profileDisplayName = null) {
871
+ export function buildLinxWelcomeCardState(interactive, profileDisplayName = null) {
231
872
  const credentials = loadCredentials();
232
873
  const webId = credentials?.webId ?? 'not logged in';
233
874
  const workspace = interactive?.sessionManager?.getCwd?.() || process.cwd();
234
875
  const sessionId = interactive?.sessionManager?.getSessionId?.();
235
876
  const sessionName = interactive?.sessionManager?.getSessionName?.();
236
- const session = sessionName && sessionId ? `${sessionName} (${shortSessionId(sessionId)})` : shortSessionId(sessionId);
877
+ const session = sessionName && sessionId ? `${sessionName} (${formatSessionId(sessionId)})` : formatSessionId(sessionId);
237
878
  const model = interactive?.session?.model?.id ?? 'unknown-model';
238
879
  return {
239
880
  webId,
@@ -246,7 +887,7 @@ function buildHeaderState(interactive, profileDisplayName = null) {
246
887
  keyHint('tui.input.submit', 'send'),
247
888
  keyHint('app.model.select', 'model'),
248
889
  rawKeyHint('/login', 'auth'),
249
- rawKeyHint('/help', 'help'),
890
+ rawKeyHint('/hotkeys', 'keymap'),
250
891
  ].join(' \x1b[2m·\x1b[22m '),
251
892
  };
252
893
  }
@@ -264,11 +905,11 @@ function wrapAndPad(line, width) {
264
905
  ? wrapped.map((entry) => padLine(entry, width))
265
906
  : [padLine('', width)];
266
907
  }
267
- function shortSessionId(sessionId) {
908
+ function formatSessionId(sessionId) {
268
909
  if (typeof sessionId !== 'string' || !sessionId.trim()) {
269
910
  return 'new session';
270
911
  }
271
- return sessionId.length > 12 ? sessionId.slice(0, 12) : sessionId;
912
+ return sessionId.trim();
272
913
  }
273
914
  function padLine(line, width) {
274
915
  const visible = visibleWidth(line);
@@ -277,12 +918,50 @@ function padLine(line, width) {
277
918
  }
278
919
  return `${line}${' '.repeat(width - visible)}`;
279
920
  }
921
+ function readLinxCliVersion() {
922
+ try {
923
+ const raw = readFileSync(new URL('../../../package.json', import.meta.url), 'utf-8');
924
+ const pkg = JSON.parse(raw);
925
+ return typeof pkg.version === 'string' && pkg.version.trim() ? pkg.version.trim() : '0.1.0';
926
+ }
927
+ catch {
928
+ return '0.1.0';
929
+ }
930
+ }
931
+ export function isVersionNewer(candidate, current) {
932
+ const candidateVersion = parseSemverLike(candidate);
933
+ const currentVersion = parseSemverLike(current);
934
+ if (!candidateVersion || !currentVersion) {
935
+ return candidate !== current;
936
+ }
937
+ for (const key of ['major', 'minor', 'patch']) {
938
+ if (candidateVersion[key] > currentVersion[key]) {
939
+ return true;
940
+ }
941
+ if (candidateVersion[key] < currentVersion[key]) {
942
+ return false;
943
+ }
944
+ }
945
+ return !candidateVersion.prerelease && currentVersion.prerelease;
946
+ }
947
+ function parseSemverLike(version) {
948
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.+)?$/.exec(version.trim());
949
+ if (!match) {
950
+ return null;
951
+ }
952
+ return {
953
+ major: Number(match[1]),
954
+ minor: Number(match[2]),
955
+ patch: Number(match[3]),
956
+ prerelease: Boolean(match[4]),
957
+ };
958
+ }
280
959
  function resolveRuntimeProviderLabel(interactive) {
281
960
  const bridge = interactive?.runtimeHost?.linxAuthBridge ?? interactive?.linxAuthBridge;
282
961
  if (bridge?.providerLabel) {
283
962
  return bridge.providerLabel;
284
963
  }
285
- return 'undefineds(cloud)';
964
+ return 'undefineds';
286
965
  }
287
966
  async function suppressPodStatusOutput(operation) {
288
967
  if (process.env.LINX_TUI_SHOW_POD_STATUS === '1') {
@@ -327,4 +1006,13 @@ function stripPodStatusLines(input) {
327
1006
  .replace(new RegExp(String.raw `Using WebID:\s*${urlPattern}[ \t]*(?:\r?\n)?`, 'g'), '')
328
1007
  .replace(/Successfully connected to Solid Pod[ \t]*(?:\r?\n)?/g, '');
329
1008
  }
1009
+ function isRecord(value) {
1010
+ return typeof value === 'object' && value !== null;
1011
+ }
1012
+ function stripAnsi(text) {
1013
+ return text.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '');
1014
+ }
1015
+ function isPromiseLike(value) {
1016
+ return isRecord(value) && typeof value.then === 'function';
1017
+ }
330
1018
  //# sourceMappingURL=branding.js.map