@jmanuelcorral/bond-app 0.3.3 → 0.3.4
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 +1 -1
- package/src/core/agy-login.ts +33 -0
- package/src/core/diagnose.ts +5 -0
package/package.json
CHANGED
package/src/core/agy-login.ts
CHANGED
|
@@ -399,6 +399,8 @@ export class AgyLoginManager {
|
|
|
399
399
|
/** Port the callback listener uses (tests pick a free one). */
|
|
400
400
|
private callbackPort?: number;
|
|
401
401
|
public inMemoryToken: string | null = null;
|
|
402
|
+
/** The agent's last screen, for the trace of a failed login. */
|
|
403
|
+
private lastPane = '';
|
|
402
404
|
|
|
403
405
|
constructor(options: AgyLoginManagerOptions) {
|
|
404
406
|
this.driver = options.driver || new DefaultAgyLoginDriver();
|
|
@@ -463,6 +465,8 @@ export class AgyLoginManager {
|
|
|
463
465
|
this.activeContainerName = containerName;
|
|
464
466
|
this.activeSessionName = sessionName;
|
|
465
467
|
this.state = { status: 'starting' };
|
|
468
|
+
this.lastPane = '';
|
|
469
|
+
this.trace('start', `imagen ${this.runnerImage}, contenedor ${containerName}, máquina ${process.platform}/${process.arch}`);
|
|
466
470
|
|
|
467
471
|
this.timeoutTimer = setTimeout(async () => {
|
|
468
472
|
if (this.state.status !== 'success' && this.state.status !== 'idle') {
|
|
@@ -505,6 +509,7 @@ export class AgyLoginManager {
|
|
|
505
509
|
|
|
506
510
|
try {
|
|
507
511
|
const pane = await this.driver.captureTmuxPane(sessionName);
|
|
512
|
+
if (pane) this.lastPane = pane;
|
|
508
513
|
if (first) {
|
|
509
514
|
first = false;
|
|
510
515
|
await this.spec.onPane(pane, (keys, literal) => this.driver.sendTmuxKeys(sessionName, keys, literal), true);
|
|
@@ -526,6 +531,7 @@ export class AgyLoginManager {
|
|
|
526
531
|
...(found.user_code ? { user_code: found.user_code } : {}),
|
|
527
532
|
...(this.spec.device ? { device: true } : {}),
|
|
528
533
|
};
|
|
534
|
+
this.trace('url', `${(/^https?:\/\/([^/?#]+)/.exec(found.url) ?? [])[1] ?? '?'}${found.user_code ? ' (código de dispositivo)' : ''}`);
|
|
529
535
|
// Device flow: nothing to paste back; watch for the result right away.
|
|
530
536
|
if (this.spec.device) await this.startTokenFileWatcher(containerName, sessionName);
|
|
531
537
|
// Loopback return (codex): catch it here so nothing has to be pasted.
|
|
@@ -654,6 +660,7 @@ export class AgyLoginManager {
|
|
|
654
660
|
|
|
655
661
|
try {
|
|
656
662
|
const pane = this.spec.agent === 'agy' ? '' : await this.driver.captureTmuxPane(sessionName);
|
|
663
|
+
if (pane) this.lastPane = pane;
|
|
657
664
|
let result: { content: string; email?: string } | null;
|
|
658
665
|
try {
|
|
659
666
|
result = await this.spec.collect(
|
|
@@ -692,6 +699,7 @@ export class AgyLoginManager {
|
|
|
692
699
|
status: 'success',
|
|
693
700
|
email: result.email,
|
|
694
701
|
};
|
|
702
|
+
this.trace('success');
|
|
695
703
|
} catch {}
|
|
696
704
|
};
|
|
697
705
|
|
|
@@ -737,7 +745,32 @@ export class AgyLoginManager {
|
|
|
737
745
|
return result;
|
|
738
746
|
}
|
|
739
747
|
|
|
748
|
+
/**
|
|
749
|
+
* The login's trace for `bond-app diagnose` (issue: logins timing out on a Mac with no clue):
|
|
750
|
+
* <dataDir>/login-<agent>.log, 0600, appended. On a failure, the end of the agent's screen,
|
|
751
|
+
* without OAuth codes, tokens or keys. Never throws.
|
|
752
|
+
*/
|
|
753
|
+
private trace(event: string, detail = '', withPane = false): void {
|
|
754
|
+
if (!this.dataDir || this.dataDir === ':memory:') return;
|
|
755
|
+
try {
|
|
756
|
+
const lines = [`${new Date().toISOString()} ${this.spec.agent} ${event}${detail ? `: ${detail}` : ''}`];
|
|
757
|
+
if (withPane && this.lastPane) {
|
|
758
|
+
const screen = this.lastPane
|
|
759
|
+
.replace(/\x1b\[[0-9;?]*[a-zA-Z]|\x1b\][^\x07]*\x07/g, '')
|
|
760
|
+
.split('\n').slice(-60).join('\n')
|
|
761
|
+
.replace(/([?&](?:code|token|access_token|id_token|refresh_token)=)[^&\s]+/gi, '$1***')
|
|
762
|
+
.replace(/\b(?:sk-|gh[pousr]_|github_pat_|ya29\.)[A-Za-z0-9._-]{12,}/g, '***')
|
|
763
|
+
.replace(/\beyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g, '***');
|
|
764
|
+
lines.push('--- pantalla del agente (final) ---', screen, '---');
|
|
765
|
+
}
|
|
766
|
+
const file = path.join(this.dataDir, `login-${this.spec.agent}.log`);
|
|
767
|
+
fs.appendFileSync(file, lines.join('\n') + '\n', { mode: 0o600 });
|
|
768
|
+
restrictPathSync(file, 0o600);
|
|
769
|
+
} catch {}
|
|
770
|
+
}
|
|
771
|
+
|
|
740
772
|
private async handleError(message: string): Promise<void> {
|
|
773
|
+
this.trace('error', message, true);
|
|
741
774
|
await this.cleanupResources();
|
|
742
775
|
this.state = {
|
|
743
776
|
status: 'error',
|
package/src/core/diagnose.ts
CHANGED
|
@@ -224,6 +224,7 @@ export async function collectDiagnosis(o: DiagnoseOptions): Promise<Diagnosis> {
|
|
|
224
224
|
`bond ${await cmd('bond', ['--version'])}`,
|
|
225
225
|
`hc ${await cmd('hc', ['--version'])}`,
|
|
226
226
|
`herdr-app ${await cmd('herdr-app', ['--version'])}`,
|
|
227
|
+
`tmux ${await cmd('tmux', ['-V'])}`,
|
|
227
228
|
'',
|
|
228
229
|
'## docker version',
|
|
229
230
|
await cmd('docker', ['version']),
|
|
@@ -247,6 +248,10 @@ export async function collectDiagnosis(o: DiagnoseOptions): Promise<Diagnosis> {
|
|
|
247
248
|
if (o.service.unitPath) add(`service/${path.basename(o.service.unitPath)}`, tailFile(o.service.unitPath, 64 * 1024));
|
|
248
249
|
}
|
|
249
250
|
add('runs.json', runsSummary(o.dataDir));
|
|
251
|
+
// The agents' logins (Ajustes): each attempt, and the end of the screen when one failed.
|
|
252
|
+
try {
|
|
253
|
+
for (const f of fs.readdirSync(o.dataDir).filter((n) => /^login-[a-z]+\.log$/.test(n))) add(`logins/${f}`, tailFile(path.join(o.dataDir, f), 256 * 1024));
|
|
254
|
+
} catch {}
|
|
250
255
|
const installed = path.join(o.herdrAppHome, 'installed.json');
|
|
251
256
|
add('herdr-app/installed.json', tailFile(installed, 64 * 1024));
|
|
252
257
|
|