@jmanuelcorral/bond-app 0.1.6 → 0.2.0
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/README.md +78 -15
- package/app/mods/bond-agents/main.js +3 -3
- package/app/mods/bond-agents/model.js +24 -2
- package/app/mods/bond-board/main.js +327 -18
- package/app/mods/bond-board/model.js +74 -6
- package/app/mods/bond-settings/main.js +66 -3
- package/package.json +1 -1
- package/runner/versions.env +1 -1
- package/scripts/app-install.ts +262 -26
- package/src/cli.ts +512 -21
- package/src/config.ts +15 -3
- package/src/core/agy-login.ts +2 -1
- package/src/core/delivery.ts +122 -5
- package/src/core/doctor.ts +748 -0
- package/src/core/hub-session.ts +108 -91
- package/src/core/hub.ts +40 -8
- package/src/core/orchestrator.ts +755 -119
- package/src/core/paths.ts +107 -0
- package/src/core/permissions.ts +143 -0
- package/src/core/pr-source.ts +147 -0
- package/src/core/service-windows.ts +180 -0
- package/src/core/service.ts +861 -0
- package/src/core/setup-install.ts +1380 -0
- package/src/db/database.ts +13 -6
- package/src/db/ticket-repo.ts +29 -7
- package/src/runner/azure-devops-client.ts +113 -3
- package/src/runner/docker-client.ts +34 -0
- package/src/runner/github-client.ts +118 -0
- package/src/server/app.ts +94 -7
- package/src/types.ts +11 -0
|
@@ -110,7 +110,7 @@ export const SECTIONS = [
|
|
|
110
110
|
{ id: "image", label: "Imagen" },
|
|
111
111
|
{ id: "advanced", label: "Avanzado" },
|
|
112
112
|
];
|
|
113
|
-
export const WIZARD_STEPS = ["agents", "github", "image"];
|
|
113
|
+
export const WIZARD_STEPS = ["agents", "github", "integrations", "image"];
|
|
114
114
|
|
|
115
115
|
/** Agents whose tickets block without a credential (their login is driven here). */
|
|
116
116
|
const BLOCKING = new Set(["agy", "claude"]);
|
|
@@ -286,11 +286,15 @@ export default class BondSettings extends View {
|
|
|
286
286
|
this.setup = null; // W-P2 «Configuración»: el agregado de GET /setup
|
|
287
287
|
this.conn = null; // «Orquestador»: { state, detail } de diagnose()
|
|
288
288
|
this.connBusy = null; // "reconnect" | "restart" | "start" mientras dura la acción
|
|
289
|
+
this.doctor = null; // GET /doctor: informe de doctor sin secretos
|
|
290
|
+
this.doctorBusy = false;
|
|
291
|
+
this.doctorError = null;
|
|
292
|
+
this.doctorLoaded = false;
|
|
289
293
|
// Every piece of progress lives in the orchestrator (selection, credentials, gh), so
|
|
290
294
|
// Esc never loses anything: the dialog reopens showing the real state (D-W2).
|
|
291
295
|
this.wizSelection = null; // the selection while its PUT /setup is in flight
|
|
292
296
|
this.rbBusy = false;
|
|
293
|
-
// Wizard: steps 1..
|
|
297
|
+
// Wizard: steps 1..4 over WIZARD_STEPS; settings: the asked section, else the first
|
|
294
298
|
// one with something pending once the state arrives (null until then).
|
|
295
299
|
this.step = Math.min(WIZARD_STEPS.length, Math.max(1, Number(p.step) || 1));
|
|
296
300
|
this.section = SECTIONS.some((x) => x.id === p.section) ? p.section : null;
|
|
@@ -310,6 +314,10 @@ export default class BondSettings extends View {
|
|
|
310
314
|
// Re-reads everything the dialog shows (the aggregate, the credential dates, gh), so a
|
|
311
315
|
// credential saved in its own dialog on top shows up here without reopening.
|
|
312
316
|
load(cx) {
|
|
317
|
+
if (!this.doctorLoaded) {
|
|
318
|
+
this.doctorLoaded = true;
|
|
319
|
+
this.loadDoctor(cx);
|
|
320
|
+
}
|
|
313
321
|
cx.spawn(async (cx) => {
|
|
314
322
|
if (!this.connBusy) this.conn = await diagnose();
|
|
315
323
|
try {
|
|
@@ -344,6 +352,24 @@ export default class BondSettings extends View {
|
|
|
344
352
|
});
|
|
345
353
|
}
|
|
346
354
|
|
|
355
|
+
loadDoctor(cx) {
|
|
356
|
+
if (this.doctorBusy) return;
|
|
357
|
+
this.doctorBusy = true;
|
|
358
|
+
this.doctorError = null;
|
|
359
|
+
cx.notify();
|
|
360
|
+
cx.spawn(async (cx) => {
|
|
361
|
+
try {
|
|
362
|
+
this.doctor = (await api("/doctor")) ?? null;
|
|
363
|
+
this.doctorError = null;
|
|
364
|
+
} catch (e) {
|
|
365
|
+
this.doctorError = String(e?.message ?? e);
|
|
366
|
+
} finally {
|
|
367
|
+
this.doctorBusy = false;
|
|
368
|
+
}
|
|
369
|
+
cx.notify();
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
347
373
|
// D20: the host's gh session, without its token (`gh auth status --json` never prints it).
|
|
348
374
|
async ghSession() {
|
|
349
375
|
try {
|
|
@@ -1232,6 +1258,14 @@ export default class BondSettings extends View {
|
|
|
1232
1258
|
.child(this.note("Reconstruir trae las versiones fijadas de bond, hc, los agentes y las herramientas. No toca las credenciales."));
|
|
1233
1259
|
}
|
|
1234
1260
|
|
|
1261
|
+
integrationsWizardSection() {
|
|
1262
|
+
return v_flex().id("wiz-integrations").gap(18)
|
|
1263
|
+
.child(this.note("Paso opcional: configura Azure DevOps y/o Jira si tus tickets trabajan con ellos, o pulsa Saltar / Siguiente para hacerlo más tarde en Ajustes."))
|
|
1264
|
+
.child(this.azureSection())
|
|
1265
|
+
.child(div().h(1).bg(theme().border))
|
|
1266
|
+
.child(this.jiraSection());
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1235
1269
|
advancedSection() {
|
|
1236
1270
|
const t = theme();
|
|
1237
1271
|
const s = this.setup;
|
|
@@ -1244,6 +1278,7 @@ export default class BondSettings extends View {
|
|
|
1244
1278
|
.child(row("API", apiUrl()))
|
|
1245
1279
|
.child(row("Asistente", s ? (s.setup_done ? "terminado" : "sin terminar") : "—"))
|
|
1246
1280
|
.child(row("Credenciales", "En el orquestador, 0600; llegan a cada run por stdin.")))
|
|
1281
|
+
.child(this.doctorBlock())
|
|
1247
1282
|
.child(this.favoritesBlock())
|
|
1248
1283
|
.child(h_flex().child(this.button("wiz-reopen", "Abrir el asistente", false, (cx) => {
|
|
1249
1284
|
this.view = "wizard";
|
|
@@ -1253,6 +1288,31 @@ export default class BondSettings extends View {
|
|
|
1253
1288
|
})));
|
|
1254
1289
|
}
|
|
1255
1290
|
|
|
1291
|
+
doctorBlock() {
|
|
1292
|
+
const t = theme();
|
|
1293
|
+
const d = this.doctor;
|
|
1294
|
+
const iconFor = (status) => (status === "ok" ? "✓" : status === "warn" ? "!" : "✗");
|
|
1295
|
+
const toneFor = (status) => (status === "ok" ? "ok" : status === "warn" ? "waiting" : "error");
|
|
1296
|
+
const summaryText = d?.summary
|
|
1297
|
+
? `${d.platform ?? ""} · ${d.summary.ok ?? 0} bien · ${d.summary.warn ?? 0} avisos · ${d.summary.fail ?? 0} fallos`
|
|
1298
|
+
: null;
|
|
1299
|
+
return v_flex().id("doctor-block").gap(8)
|
|
1300
|
+
.child(h_flex().gap(8).items_center()
|
|
1301
|
+
.child(div().flex_1().text_size(UI.text.body).font_semibold().text_color(t.foreground).child("Estado de la instalación"))
|
|
1302
|
+
.child(this.button("doctor-refresh", this.doctorBusy ? "Actualizando…" : "Actualizar", false, (cx) => this.loadDoctor(cx))))
|
|
1303
|
+
.when(Boolean(summaryText), (el) => el.child(div().id("doctor-summary").text_size(UI.text.small).text_color(t.muted).child(summaryText)))
|
|
1304
|
+
.when(Boolean(this.doctorError), (el) => el.child(div().id("doctor-error").text_size(UI.text.small).text_color(t.blocked).child(this.doctorError)))
|
|
1305
|
+
.when(!d && !this.doctorError, (el) => el.child(this.note(this.doctorBusy ? "Comprobando…" : "Sin datos de diagnóstico.")))
|
|
1306
|
+
.when(Boolean(d?.checks?.length), (el) => el.child(v_flex().gap(6).children(d.checks.map((c) =>
|
|
1307
|
+
v_flex().id(`doctor-check-${c.id}`).gap(2).p(8).rounded(UI.radius).border_1().border_color(t.border).bg(t.background)
|
|
1308
|
+
.child(h_flex().gap(8).items_center()
|
|
1309
|
+
.child(div().w(14).flex_none().text_size(UI.text.small).font_semibold().text_color(this.tone(t, toneFor(c.status))).child(iconFor(c.status)))
|
|
1310
|
+
.child(div().flex_1().min_w(0).text_size(UI.text.small).font_semibold().text_color(t.foreground).child(c.name))
|
|
1311
|
+
.child(div().flex_none().text_size(UI.text.tiny).text_color(this.tone(t, toneFor(c.status))).child(c.status)))
|
|
1312
|
+
.child(div().pl(22).text_size(UI.text.small).text_color(t.muted).child(c.detail))
|
|
1313
|
+
.when(Boolean(c.fix), (fixEl) => fixEl.child(div().id(`doctor-fix-${c.id}`).pl(22).text_size(UI.text.tiny).text_color(t.dim).child(`Solución: ${c.fix}`)))))));
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1256
1316
|
/** The ★ repos of the new-ticket dialog («Dónde»): listed here to remove them. */
|
|
1257
1317
|
favoritesBlock() {
|
|
1258
1318
|
const t = theme();
|
|
@@ -1325,9 +1385,10 @@ export default class BondSettings extends View {
|
|
|
1325
1385
|
const wizard = this.view === "wizard";
|
|
1326
1386
|
const current = this.currentSection();
|
|
1327
1387
|
const marks = sectionMarks({ conn: this.conn, setup: this.setup, creds: this.creds, jira: this.jira });
|
|
1388
|
+
const WIZARD_LABELS = { integrations: "Azure DevOps y Jira" };
|
|
1328
1389
|
const nav = wizard
|
|
1329
1390
|
? WIZARD_STEPS.map((id, i) => {
|
|
1330
|
-
const label = SECTIONS.find((x) => x.id === id).label;
|
|
1391
|
+
const label = WIZARD_LABELS[id] ?? SECTIONS.find((x) => x.id === id).label;
|
|
1331
1392
|
const mark = i + 1 < this.step ? { mark: "✓", tone: "ok" } : marks[id] ?? null;
|
|
1332
1393
|
return this.navItem(id, `${i + 1} ${label}`, current === id, mark, (cx) => this.goTo(cx, id));
|
|
1333
1394
|
})
|
|
@@ -1338,12 +1399,14 @@ export default class BondSettings extends View {
|
|
|
1338
1399
|
github: () => this.githubSection(),
|
|
1339
1400
|
azure: () => this.azureSection(),
|
|
1340
1401
|
jira: () => this.jiraSection(),
|
|
1402
|
+
integrations: () => this.integrationsWizardSection(),
|
|
1341
1403
|
image: () => this.imageSection(),
|
|
1342
1404
|
advanced: () => this.advancedSection(),
|
|
1343
1405
|
}[current]();
|
|
1344
1406
|
const actions = [];
|
|
1345
1407
|
if (wizard) {
|
|
1346
1408
|
if (this.step > 1) actions.push(this.button("wiz-back", "Atrás", false, (cx) => this.wizBack(cx)));
|
|
1409
|
+
if (current === "integrations") actions.push(this.button("wiz-skip", "Saltar", false, (cx) => this.wizNext(cx)));
|
|
1347
1410
|
actions.push(this.step < WIZARD_STEPS.length
|
|
1348
1411
|
? this.button("wiz-next", "Siguiente", true, (cx) => this.wizNext(cx))
|
|
1349
1412
|
: this.button("wiz-finish", this.busy ? "Guardando…" : "Finalizar", true, (cx) => this.wizFinish(cx)));
|
package/package.json
CHANGED
package/runner/versions.env
CHANGED
|
@@ -22,7 +22,7 @@ SUPI_VERSION=11.0.1
|
|
|
22
22
|
# bond (el harness que lanza el agente, D-G): instalado por setup.sh con --with-bond
|
|
23
23
|
# (D-H: versión fijada; package npm con scope @jmanuelcorral/bond). El pin mínimo es
|
|
24
24
|
# 1.16.4: antes de esa versión bond no tiene comando `tui` (spike runner/SPIKE-BOND.md).
|
|
25
|
-
BOND_VERSION=1.16.
|
|
25
|
+
BOND_VERSION=1.16.8
|
|
26
26
|
|
|
27
27
|
# gh y azure-cli salen de los repos apt oficiales (GitHub y Microsoft); se dejan
|
|
28
28
|
# en «latest» del repo. AZURE_CLI_VERSION admite el pin «2.xx.y» (sufijo ~bookworm
|
package/scripts/app-install.ts
CHANGED
|
@@ -23,12 +23,17 @@
|
|
|
23
23
|
* on each installed mod), --skip-version-check, --force, --launcher, --remove-launcher.
|
|
24
24
|
*/
|
|
25
25
|
import fs from 'node:fs';
|
|
26
|
-
import os from 'node:os';
|
|
27
26
|
import path from 'node:path';
|
|
28
27
|
import crypto from 'node:crypto';
|
|
29
28
|
import { execFileSync } from 'node:child_process';
|
|
30
29
|
import { fileURLToPath } from 'node:url';
|
|
31
30
|
import { MIN_HC_VERSION, MIN_HERDR_APP_VERSION, compareVersions } from '../src/runner/hc-client.ts';
|
|
31
|
+
import {
|
|
32
|
+
defaultDataDir,
|
|
33
|
+
defaultHerdrAppHome,
|
|
34
|
+
defaultLauncherDataHome,
|
|
35
|
+
windowsStartMenuShortcutPath,
|
|
36
|
+
} from '../src/core/paths.ts';
|
|
32
37
|
|
|
33
38
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
34
39
|
const appDir = path.join(repoRoot, 'app');
|
|
@@ -44,10 +49,14 @@ export interface InstallOptions {
|
|
|
44
49
|
skipVersionCheck: boolean;
|
|
45
50
|
force: boolean;
|
|
46
51
|
launcher: boolean;
|
|
47
|
-
/** Where the launcher goes ($XDG_DATA_HOME
|
|
52
|
+
/** Where the launcher goes ($XDG_DATA_HOME / ~/.local/share on POSIX, %APPDATA% on Windows). */
|
|
48
53
|
dataHome: string;
|
|
49
54
|
/** --home or HERDR_APP_HOME given: the launcher passes it on to herdr-app. */
|
|
50
55
|
customHome: boolean;
|
|
56
|
+
/** Target platform override (for testing). */
|
|
57
|
+
platform?: NodeJS.Platform;
|
|
58
|
+
/** Injectable command runner (for testing Windows PowerShell shortcut creation). */
|
|
59
|
+
runCommand?: (cmd: string, args: string[]) => void;
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
export interface InstallResult {
|
|
@@ -76,9 +85,9 @@ export function parseInstallArgs(argv: string[]): InstallOptions {
|
|
|
76
85
|
};
|
|
77
86
|
const port = process.env.BOND_APP_PORT || '3000';
|
|
78
87
|
const homeArg = get('--home') || process.env.HERDR_APP_HOME || null;
|
|
79
|
-
const dataDir = process.env.BOND_APP_DATA_DIR
|
|
88
|
+
const dataDir = process.env.BOND_APP_DATA_DIR ? defaultDataDir() : null;
|
|
80
89
|
return {
|
|
81
|
-
home: homeArg ||
|
|
90
|
+
home: homeArg || defaultHerdrAppHome(),
|
|
82
91
|
api: get('--api') || `http://127.0.0.1:${port}/api/v1`,
|
|
83
92
|
tokenFile: get('--token-file') || (dataDir ? path.join(dataDir, 'token') : null),
|
|
84
93
|
check: argv.includes('--check'),
|
|
@@ -91,8 +100,7 @@ export function parseInstallArgs(argv: string[]): InstallOptions {
|
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
function dataHome(): string {
|
|
94
|
-
|
|
95
|
-
return xdg && path.isAbsolute(xdg) ? xdg : path.join(os.homedir(), '.local', 'share');
|
|
103
|
+
return defaultLauncherDataHome();
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
function versionOf(cmd: string): string | null {
|
|
@@ -274,7 +282,8 @@ export function install(opts: InstallOptions): InstallResult {
|
|
|
274
282
|
throw new Error(`${dest} exists and is not the copy bond-app installed (edited, or someone else's): use --force to replace it`);
|
|
275
283
|
}
|
|
276
284
|
}
|
|
277
|
-
|
|
285
|
+
const platform = opts.platform ?? process.platform;
|
|
286
|
+
if (opts.launcher) checkLauncher(opts.dataHome, opts.force, platform);
|
|
278
287
|
|
|
279
288
|
fs.mkdirSync(modsDest, { recursive: true });
|
|
280
289
|
fs.mkdirSync(layoutsDest, { recursive: true });
|
|
@@ -331,9 +340,101 @@ export function install(opts: InstallOptions): InstallResult {
|
|
|
331
340
|
return { home: opts.home, mods: modNames, layout: layoutDest, versions, checked, themes: themeNames, launcher };
|
|
332
341
|
}
|
|
333
342
|
|
|
343
|
+
export interface AppIntegrationCheckResult {
|
|
344
|
+
installed: boolean;
|
|
345
|
+
upToDate: boolean;
|
|
346
|
+
missing: string[];
|
|
347
|
+
outdated: string[];
|
|
348
|
+
foreign: string[];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Read-only check of layout, mods and themes in `home` against the copies in `app/`.
|
|
353
|
+
* Never writes or modifies files in `home`.
|
|
354
|
+
*/
|
|
355
|
+
export function checkAppInstalled(home: string): AppIntegrationCheckResult {
|
|
356
|
+
const modsSrc = path.join(appDir, 'mods');
|
|
357
|
+
const modNames = fs.readdirSync(modsSrc).filter((n) => n.startsWith('bond-')).sort();
|
|
358
|
+
const modsDest = path.join(home, 'mods');
|
|
359
|
+
const layoutsDest = path.join(home, 'layouts');
|
|
360
|
+
const themesSrc = path.join(appDir, 'themes');
|
|
361
|
+
const themesDest = path.join(home, 'themes');
|
|
362
|
+
const themeNames = fs.readdirSync(themesSrc).filter((n) => n.endsWith('.json')).sort();
|
|
363
|
+
|
|
364
|
+
const missing: string[] = [];
|
|
365
|
+
const outdated: string[] = [];
|
|
366
|
+
const foreign: string[] = [];
|
|
367
|
+
|
|
368
|
+
const layoutSrc = path.join(appDir, 'layouts', `${LAYOUT}.json`);
|
|
369
|
+
const layoutDest = path.join(layoutsDest, `${LAYOUT}.json`);
|
|
370
|
+
if (!fs.existsSync(layoutDest)) {
|
|
371
|
+
missing.push(`layout:${LAYOUT}`);
|
|
372
|
+
} else if (!layoutHashes(layoutDest).includes(sha256(layoutSrc))) {
|
|
373
|
+
outdated.push(`layout:${LAYOUT}`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
for (const name of themeNames) {
|
|
377
|
+
const dest = path.join(themesDest, name);
|
|
378
|
+
if (!fs.existsSync(dest)) {
|
|
379
|
+
missing.push(`theme:${name}`);
|
|
380
|
+
} else if (sha256(dest) !== sha256(path.join(themesSrc, name))) {
|
|
381
|
+
outdated.push(`theme:${name}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const expectedVersion = appVersion();
|
|
386
|
+
for (const name of modNames) {
|
|
387
|
+
const srcMod = path.join(modsSrc, name);
|
|
388
|
+
const destMod = path.join(modsDest, name);
|
|
389
|
+
if (!fs.existsSync(destMod)) {
|
|
390
|
+
missing.push(`mod:${name}`);
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (!readMarker(destMod)) {
|
|
394
|
+
foreign.push(`mod:${name}`);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (name === 'bond-titlebar') {
|
|
398
|
+
const verFile = path.join(destMod, 'version.js');
|
|
399
|
+
if (!fs.existsSync(verFile) || fs.readFileSync(verFile, 'utf8') !== versionJs(expectedVersion)) {
|
|
400
|
+
outdated.push(`mod:${name}`);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (!dirFilesMatch(srcMod, destMod)) {
|
|
405
|
+
outdated.push(`mod:${name}`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const installed = missing.length === 0;
|
|
410
|
+
const upToDate = installed && outdated.length === 0 && foreign.length === 0;
|
|
411
|
+
return { installed, upToDate, missing, outdated, foreign };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function dirFilesMatch(src: string, dest: string): boolean {
|
|
415
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
416
|
+
if (SKIP.has(entry.name) || entry.name === 'config.js') continue;
|
|
417
|
+
const from = path.join(src, entry.name);
|
|
418
|
+
const to = path.join(dest, entry.name);
|
|
419
|
+
if (entry.isDirectory()) {
|
|
420
|
+
if (!fs.existsSync(to) || !dirFilesMatch(from, to)) return false;
|
|
421
|
+
} else if (entry.isFile()) {
|
|
422
|
+
if (!fs.existsSync(to) || sha256(from) !== sha256(to)) return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
|
|
334
428
|
// ---- P6: the opt-in «bond» desktop launcher ----
|
|
335
429
|
|
|
336
|
-
export function launcherPaths(dataDir: string): LauncherPaths {
|
|
430
|
+
export function launcherPaths(dataDir: string, platform: NodeJS.Platform = process.platform): LauncherPaths {
|
|
431
|
+
if (platform === 'win32') {
|
|
432
|
+
return {
|
|
433
|
+
desktop: windowsStartMenuShortcutPath({ env: { APPDATA: dataDir } }),
|
|
434
|
+
icon: path.join(dataDir, 'bond-app', 'bond-app.svg'),
|
|
435
|
+
script: path.join(dataDir, 'bond-app', 'bond-launch.cmd'),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
337
438
|
return {
|
|
338
439
|
desktop: path.join(dataDir, 'applications', 'bond-app.desktop'),
|
|
339
440
|
icon: path.join(dataDir, 'icons', 'hicolor', 'scalable', 'apps', 'bond-app.svg'),
|
|
@@ -392,11 +493,15 @@ function ours(file: string, manifest: Record<string, string>, dataDir?: string):
|
|
|
392
493
|
* a symlink at any of our paths or their intermediate directories, or a file there that is not
|
|
393
494
|
* the copy bond-app wrote (someone else's, or edited: --force replaces an edited one).
|
|
394
495
|
*/
|
|
395
|
-
function checkLauncher(dataDir: string, force: boolean): void {
|
|
396
|
-
if (
|
|
496
|
+
function checkLauncher(dataDir: string, force: boolean, platform: NodeJS.Platform = process.platform): void {
|
|
497
|
+
if (platform === 'win32') {
|
|
498
|
+
if (/[\r\n\0]/.test(dataDir)) {
|
|
499
|
+
throw new Error(`the Windows data dir '${dataDir}' contains invalid control characters: not writing a launcher there`);
|
|
500
|
+
}
|
|
501
|
+
} else if (!/^[A-Za-z0-9/._ -]+$/.test(dataDir)) {
|
|
397
502
|
throw new Error(`the XDG data dir '${dataDir}' has characters a .desktop file would need escaped: not writing a launcher there`);
|
|
398
503
|
}
|
|
399
|
-
const p = launcherPaths(dataDir);
|
|
504
|
+
const p = launcherPaths(dataDir, platform);
|
|
400
505
|
const manifest = readManifest(dataDir);
|
|
401
506
|
const filesToCheck = [p.desktop, p.icon, p.script, manifestPath(dataDir)];
|
|
402
507
|
const checkedDirs = new Set<string>();
|
|
@@ -417,18 +522,19 @@ function checkLauncher(dataDir: string, force: boolean): void {
|
|
|
417
522
|
}
|
|
418
523
|
|
|
419
524
|
/** herdr-app's absolute path on PATH, so the launcher works from a desktop session's PATH. */
|
|
420
|
-
function herdrAppPath(): string {
|
|
525
|
+
function herdrAppPath(platform: NodeJS.Platform = process.platform): string {
|
|
526
|
+
const exe = platform === 'win32' ? 'herdr-app.exe' : 'herdr-app';
|
|
421
527
|
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
|
|
422
528
|
if (!path.isAbsolute(dir)) continue; // a relative entry would resolve against the session's cwd
|
|
423
|
-
const candidate = path.join(dir,
|
|
529
|
+
const candidate = path.join(dir, exe);
|
|
424
530
|
try {
|
|
425
|
-
fs.accessSync(candidate, fs.constants.X_OK);
|
|
531
|
+
fs.accessSync(candidate, platform === 'win32' ? fs.constants.F_OK : fs.constants.X_OK);
|
|
426
532
|
return candidate;
|
|
427
533
|
} catch {
|
|
428
534
|
// next
|
|
429
535
|
}
|
|
430
536
|
}
|
|
431
|
-
return
|
|
537
|
+
return exe;
|
|
432
538
|
}
|
|
433
539
|
|
|
434
540
|
/** Single-quote for sh. */
|
|
@@ -473,24 +579,141 @@ function desktopEntry(p: LauncherPaths): string {
|
|
|
473
579
|
].join('\n');
|
|
474
580
|
}
|
|
475
581
|
|
|
582
|
+
function psQuote(value: string): string {
|
|
583
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function windowsLaunchScript(herdrApp: string, home: string | null): string {
|
|
587
|
+
return [
|
|
588
|
+
'@echo off',
|
|
589
|
+
'setlocal',
|
|
590
|
+
`if not defined HERDR_APP set "HERDR_APP=${herdrApp}"`,
|
|
591
|
+
...(home ? [`set "HERDR_APP_HOME=${home}"`] : []),
|
|
592
|
+
'"%HERDR_APP%" status >nul 2>&1',
|
|
593
|
+
'if errorlevel 1 (',
|
|
594
|
+
' start "" "%HERDR_APP%"',
|
|
595
|
+
' for /l %%i in (1,1,50) do (',
|
|
596
|
+
' "%HERDR_APP%" status >nul 2>&1 && goto :switch',
|
|
597
|
+
' powershell -NoProfile -Command "Start-Sleep -Milliseconds 200" >nul 2>&1',
|
|
598
|
+
' )',
|
|
599
|
+
')',
|
|
600
|
+
':switch',
|
|
601
|
+
'"%HERDR_APP%" do layout.switch --name bond',
|
|
602
|
+
'',
|
|
603
|
+
].join('\r\n');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function buildWindowsShortcutPs(lnkPath: string, targetPath: string): string {
|
|
607
|
+
return [
|
|
608
|
+
'$ws = New-Object -ComObject WScript.Shell',
|
|
609
|
+
`$s = $ws.CreateShortcut(${psQuote(lnkPath)})`,
|
|
610
|
+
`$s.TargetPath = ${psQuote(targetPath)}`,
|
|
611
|
+
`$s.WorkingDirectory = ${psQuote(path.dirname(targetPath))}`,
|
|
612
|
+
'$s.WindowStyle = 7',
|
|
613
|
+
"$s.Description = 'bond-app: tickets en hub-contenedores con agentes de código (herdr-app, layout bond)'",
|
|
614
|
+
'$s.Save()',
|
|
615
|
+
].join('; ');
|
|
616
|
+
}
|
|
617
|
+
|
|
476
618
|
function writeLauncher(opts: InstallOptions): LauncherPaths {
|
|
477
|
-
const
|
|
619
|
+
const platform = opts.platform ?? process.platform;
|
|
620
|
+
const p = launcherPaths(opts.dataHome, platform);
|
|
478
621
|
for (const f of [p.desktop, p.icon, p.script]) fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
479
622
|
fs.copyFileSync(path.join(appDir, 'brand', 'bond-app.svg'), p.icon);
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
623
|
+
const herdrBin = herdrAppPath(platform);
|
|
624
|
+
if (platform === 'win32') {
|
|
625
|
+
fs.writeFileSync(p.script, windowsLaunchScript(herdrBin, opts.customHome ? opts.home : null), 'utf8');
|
|
626
|
+
const psScript = buildWindowsShortcutPs(p.desktop, p.script);
|
|
627
|
+
const run = opts.runCommand ?? ((cmd: string, args: string[]) => execFileSync(cmd, args, { stdio: 'pipe', timeout: 15_000 }));
|
|
628
|
+
run('powershell', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', psScript]);
|
|
629
|
+
} else {
|
|
630
|
+
fs.writeFileSync(p.script, launchScript(herdrBin, opts.customHome ? opts.home : null), { mode: 0o755 });
|
|
631
|
+
fs.chmodSync(p.script, 0o755);
|
|
632
|
+
fs.writeFileSync(p.desktop, desktopEntry(p));
|
|
633
|
+
}
|
|
634
|
+
const files = Object.fromEntries(
|
|
635
|
+
[p.desktop, p.icon, p.script].filter((f) => fs.existsSync(f)).map((f) => [f, sha256(f)])
|
|
636
|
+
);
|
|
484
637
|
fs.writeFileSync(manifestPath(opts.dataHome), JSON.stringify({ installed_by: 'bond-app', files }, null, 2) + '\n');
|
|
485
638
|
return p;
|
|
486
639
|
}
|
|
487
640
|
|
|
641
|
+
/**
|
|
642
|
+
* Remove layout, mods and themes that bond-app installed in `home`.
|
|
643
|
+
* Never removes foreign mods, edited layouts, or themes not matching bond-app's marker.
|
|
644
|
+
*/
|
|
645
|
+
export function removeApp(home: string): { removed: string[]; kept: string[] } {
|
|
646
|
+
const modsSrc = path.join(appDir, 'mods');
|
|
647
|
+
const modsDest = path.join(home, 'mods');
|
|
648
|
+
const layoutsDest = path.join(home, 'layouts');
|
|
649
|
+
const themesSrc = path.join(appDir, 'themes');
|
|
650
|
+
const themesDest = path.join(home, 'themes');
|
|
651
|
+
|
|
652
|
+
const srcModNames = fs.existsSync(modsSrc)
|
|
653
|
+
? fs.readdirSync(modsSrc).filter((n) => n.startsWith('bond-')).sort()
|
|
654
|
+
: [];
|
|
655
|
+
const destModNames = fs.existsSync(modsDest)
|
|
656
|
+
? fs.readdirSync(modsDest).filter((n) => n.startsWith('bond-')).sort()
|
|
657
|
+
: [];
|
|
658
|
+
const modNames = [...new Set([...srcModNames, ...destModNames])].sort();
|
|
659
|
+
|
|
660
|
+
const previous = modNames.map((n) => readMarker(path.join(modsDest, n))).find((m) => m) ?? null;
|
|
661
|
+
|
|
662
|
+
const removed: string[] = [];
|
|
663
|
+
const kept: string[] = [];
|
|
664
|
+
|
|
665
|
+
for (const name of modNames) {
|
|
666
|
+
const dest = path.join(modsDest, name);
|
|
667
|
+
if (!fs.existsSync(dest) && !isSymlink(dest)) continue;
|
|
668
|
+
if (!isSymlink(dest) && readMarker(dest)) {
|
|
669
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
670
|
+
removed.push(dest);
|
|
671
|
+
} else {
|
|
672
|
+
kept.push(dest);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const layoutDest = path.join(layoutsDest, `${LAYOUT}.json`);
|
|
677
|
+
const previewDest = path.join(layoutsDest, `${LAYOUT}.svg`);
|
|
678
|
+
for (const [dest, key] of [[layoutDest, 'layout_sha256'], [previewDest, 'preview_sha256']] as const) {
|
|
679
|
+
if (!fs.existsSync(dest) && !isSymlink(dest)) continue;
|
|
680
|
+
if (!isSymlink(dest) && previous?.[key]) {
|
|
681
|
+
const ours = key === 'layout_sha256' ? layoutHashes(dest) : [sha256(dest)];
|
|
682
|
+
if (ours.includes(previous[key]!)) {
|
|
683
|
+
fs.rmSync(dest);
|
|
684
|
+
removed.push(dest);
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
kept.push(dest);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const srcThemeNames = fs.existsSync(themesSrc)
|
|
692
|
+
? fs.readdirSync(themesSrc).filter((n) => n.endsWith('.json'))
|
|
693
|
+
: [];
|
|
694
|
+
const markerThemeNames = Object.keys(previous?.themes_sha256 ?? {});
|
|
695
|
+
const themeNames = [...new Set([...srcThemeNames, ...markerThemeNames])].sort();
|
|
696
|
+
for (const name of themeNames) {
|
|
697
|
+
const dest = path.join(themesDest, name);
|
|
698
|
+
if (!fs.existsSync(dest) && !isSymlink(dest)) continue;
|
|
699
|
+
if (!isSymlink(dest) && previous?.themes_sha256?.[name] === sha256(dest)) {
|
|
700
|
+
fs.rmSync(dest);
|
|
701
|
+
removed.push(dest);
|
|
702
|
+
} else {
|
|
703
|
+
kept.push(dest);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return { removed, kept };
|
|
708
|
+
}
|
|
709
|
+
|
|
488
710
|
/**
|
|
489
711
|
* Remove what --launcher wrote: only the exact copies in its manifest. An edited or foreign
|
|
490
712
|
* file stays (and is listed in `kept`).
|
|
491
713
|
*/
|
|
492
|
-
export function removeLauncher(dataDir: string): { removed: string[]; kept: string[] } {
|
|
493
|
-
const
|
|
714
|
+
export function removeLauncher(dataDir: string, opts: { platform?: NodeJS.Platform } = {}): { removed: string[]; kept: string[] } {
|
|
715
|
+
const platform = opts.platform ?? process.platform;
|
|
716
|
+
const p = launcherPaths(dataDir, platform);
|
|
494
717
|
const manifest = readManifest(dataDir);
|
|
495
718
|
const removed: string[] = [];
|
|
496
719
|
const kept: string[] = [];
|
|
@@ -514,10 +737,23 @@ export function removeLauncher(dataDir: string): { removed: string[]; kept: stri
|
|
|
514
737
|
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
515
738
|
try {
|
|
516
739
|
const argv = process.argv.slice(2);
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if (
|
|
740
|
+
const wantsRemove = argv.includes('--remove');
|
|
741
|
+
const wantsRemoveLauncher = argv.includes('--remove-launcher');
|
|
742
|
+
if (wantsRemove || wantsRemoveLauncher) {
|
|
743
|
+
if (wantsRemove) {
|
|
744
|
+
const homeArg = (() => {
|
|
745
|
+
const i = argv.indexOf('--home');
|
|
746
|
+
return i !== -1 && argv[i + 1] ? argv[i + 1] : null;
|
|
747
|
+
})() || process.env.HERDR_APP_HOME || defaultHerdrAppHome();
|
|
748
|
+
const { removed, kept } = removeApp(homeArg);
|
|
749
|
+
console.log(removed.length ? `bond-app: app integration removed:\n ${removed.join('\n ')}` : 'bond-app: no bond-app integration to remove');
|
|
750
|
+
if (kept.length) console.log(` kept (edited, or not bond-app's):\n ${kept.join('\n ')}`);
|
|
751
|
+
}
|
|
752
|
+
if (wantsRemoveLauncher) {
|
|
753
|
+
const { removed, kept } = removeLauncher(dataHome());
|
|
754
|
+
console.log(removed.length ? `bond-app: launcher removed:\n ${removed.join('\n ')}` : 'bond-app: no bond launcher to remove');
|
|
755
|
+
if (kept.length) console.log(` kept (edited, or not bond-app's):\n ${kept.join('\n ')}`);
|
|
756
|
+
}
|
|
521
757
|
process.exit(0);
|
|
522
758
|
}
|
|
523
759
|
const res = install(parseInstallArgs(argv));
|