@jmanuelcorral/bond-app 0.1.5 → 0.1.6

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 (70) hide show
  1. package/README.md +211 -17
  2. package/app/brand/TOKENS.md +5 -5
  3. package/app/layouts/bond.json +10 -14
  4. package/app/mods/bond-agents/api.js +35 -0
  5. package/app/mods/bond-agents/branch.svg +1 -0
  6. package/app/mods/bond-agents/brand.js +53 -2
  7. package/app/mods/bond-agents/config.js +4 -0
  8. package/app/mods/bond-agents/eye-off.svg +1 -0
  9. package/app/mods/bond-agents/eye.svg +1 -0
  10. package/app/mods/bond-agents/main.js +308 -327
  11. package/app/mods/bond-agents/model.js +354 -5
  12. package/app/mods/bond-board/api.js +35 -0
  13. package/app/mods/bond-board/branch.svg +1 -0
  14. package/app/mods/bond-board/brand.js +53 -2
  15. package/app/mods/bond-board/config.js +4 -0
  16. package/app/mods/bond-board/main.js +686 -444
  17. package/app/mods/bond-board/model.js +99 -25
  18. package/app/mods/bond-pane/close.svg +1 -0
  19. package/app/mods/bond-pane/hide.svg +1 -0
  20. package/app/mods/bond-pane/main.js +103 -0
  21. package/app/mods/bond-pane/mod.json +1 -0
  22. package/app/mods/bond-pane/model.js +18 -0
  23. package/app/mods/bond-pane/split-down.svg +1 -0
  24. package/app/mods/bond-pane/split-right.svg +1 -0
  25. package/app/mods/bond-pane/unzoom.svg +1 -0
  26. package/app/mods/bond-pane/zoom.svg +1 -0
  27. package/app/mods/bond-settings/api.js +35 -0
  28. package/app/mods/bond-settings/brand.js +53 -2
  29. package/app/mods/bond-settings/config.js +4 -0
  30. package/app/mods/bond-settings/main.js +1159 -278
  31. package/app/mods/bond-settings/mod.json +1 -1
  32. package/app/mods/bond-status/api.js +35 -0
  33. package/app/mods/bond-status/brand.js +53 -2
  34. package/app/mods/bond-status/config.js +4 -0
  35. package/app/mods/bond-status/main.js +37 -15
  36. package/app/mods/bond-status/model.js +19 -1
  37. package/app/mods/bond-tabs/brand.js +53 -2
  38. package/app/mods/bond-tabs/main.js +45 -3
  39. package/app/mods/bond-titlebar/brand.js +53 -2
  40. package/app/mods/bond-titlebar/main.js +85 -29
  41. package/app/mods/bond-titlebar/version.js +3 -0
  42. package/app/themes/bond-dark.json +5 -5
  43. package/app/themes/bond-light.json +5 -5
  44. package/package.json +1 -1
  45. package/runner/Dockerfile +16 -2
  46. package/runner/SPIKE-BOND.md +6 -2
  47. package/runner/entrypoint.sh +16 -0
  48. package/runner/setup.sh +439 -8
  49. package/runner/versions.env +32 -1
  50. package/scripts/app-install.ts +60 -1
  51. package/src/cli.ts +53 -3
  52. package/src/core/agy-login.ts +682 -0
  53. package/src/core/delivery.ts +3 -1
  54. package/src/core/orchestrator.ts +736 -78
  55. package/src/core/repo-host.ts +60 -0
  56. package/src/core/setup.ts +62 -1
  57. package/src/core/watchdog.ts +6 -6
  58. package/src/db/database.ts +41 -1
  59. package/src/db/settings-repo.ts +332 -7
  60. package/src/db/ticket-repo.ts +46 -20
  61. package/src/index.ts +4 -4
  62. package/src/runner/azure-devops-client.ts +163 -0
  63. package/src/runner/docker-client.ts +59 -9
  64. package/src/runner/github-client.ts +30 -3
  65. package/src/runner/hc-client.ts +33 -5
  66. package/src/runner/image-builder.ts +123 -5
  67. package/src/runner/jira-client.ts +368 -0
  68. package/src/runner/tool-catalog.ts +84 -0
  69. package/src/server/app.ts +377 -5
  70. package/src/types.ts +129 -2
package/src/cli.ts CHANGED
@@ -15,6 +15,7 @@ import { spawn, execFileSync } from 'node:child_process';
15
15
  import { fileURLToPath } from 'node:url';
16
16
 
17
17
  import { bootstrap } from './index.ts';
18
+ import type { ServerHooks } from './server/app.ts';
18
19
  import { MIN_HC_VERSION, MIN_HERDR_APP_VERSION } from './runner/hc-client.ts';
19
20
  import { install, parseInstallArgs, removeLauncher } from '../scripts/app-install.ts';
20
21
 
@@ -209,9 +210,34 @@ export async function queryStatus(opts: StatusOptions): Promise<StatusResult> {
209
210
  };
210
211
  }
211
212
 
213
+ /**
214
+ * «Reiniciar orquestador»: start this same command again, detached, with the same argv,
215
+ * execArgv and environment (so RUNNER_IMAGE, --port and --data-dir survive). Its output
216
+ * goes to <data dir>/orchestrator.log: the terminal that started us may be gone.
217
+ */
218
+ export function relaunchSelf(dataDir: string, spawnFn: typeof spawn = spawn): number | undefined {
219
+ fs.mkdirSync(dataDir, { recursive: true });
220
+ const logPath = path.join(dataDir, 'orchestrator.log');
221
+ const fd = fs.openSync(logPath, 'a', 0o600);
222
+ try {
223
+ const child = spawnFn(process.execPath, [...process.execArgv, ...process.argv.slice(1)], {
224
+ detached: true,
225
+ stdio: ['ignore', fd, fd],
226
+ env: process.env,
227
+ cwd: process.cwd(),
228
+ });
229
+ child.unref();
230
+ console.log(`[bond-app] Restarting in the background (pid ${child.pid}); log: ${logPath}`);
231
+ return child.pid;
232
+ } finally {
233
+ fs.closeSync(fd);
234
+ }
235
+ }
236
+
212
237
  export async function handleStart(
213
238
  args: string[],
214
- bootstrapFn: (overrides?: any) => Promise<{ server: any; orchestrator: any; port: number }> = bootstrap
239
+ bootstrapFn: (overrides?: any, hooks?: ServerHooks) => Promise<{ server: any; orchestrator: any; port: number }> = bootstrap,
240
+ relaunchFn: (dataDir: string) => unknown = relaunchSelf
215
241
  ): Promise<number> {
216
242
  const overrides: Record<string, any> = {};
217
243
  for (let i = 0; i < args.length; i++) {
@@ -238,6 +264,7 @@ export async function handleStart(
238
264
 
239
265
  return new Promise<number>((resolve, reject) => {
240
266
  let shuttingDown = false;
267
+ let restartRequested = false;
241
268
  let serverInstance: any = null;
242
269
  let orchestratorInstance: any = null;
243
270
  let bootstrapPromise: Promise<{ server: any; orchestrator: any }> | null = null;
@@ -263,7 +290,11 @@ export async function handleStart(
263
290
  }
264
291
  try {
265
292
  if (serverInstance) {
266
- await new Promise<void>((r) => serverInstance.close(() => r()));
293
+ await new Promise<void>((r) => {
294
+ serverInstance.close(() => r());
295
+ // Keep-alive connections (the mods poll) would hold close() open.
296
+ serverInstance.closeAllConnections?.();
297
+ });
267
298
  }
268
299
  } catch (err: any) {
269
300
  console.warn(`[bond-app] Error closing HTTP server: ${err?.message || err}`);
@@ -276,6 +307,19 @@ export async function handleStart(
276
307
  console.warn(`[bond-app] Error stopping orchestrator: ${err?.message || err}`);
277
308
  }
278
309
  console.log('[bond-app] Orchestrator stopped cleanly.');
310
+ if (restartRequested) {
311
+ const dataDir = orchestratorInstance?.config?.dataDir
312
+ || overrides.dataDir
313
+ || process.env.BOND_APP_DATA_DIR
314
+ || path.join(os.homedir(), '.bond-app');
315
+ try {
316
+ relaunchFn(dataDir);
317
+ } catch (err: any) {
318
+ console.error(`[bond-app] Could not restart: ${err?.message || err}`);
319
+ resolve(1);
320
+ return;
321
+ }
322
+ }
279
323
  resolve(0);
280
324
  };
281
325
 
@@ -285,7 +329,13 @@ export async function handleStart(
285
329
  process.once('SIGINT', sigintHandler);
286
330
  process.once('SIGTERM', sigtermHandler);
287
331
 
288
- bootstrapPromise = bootstrapFn(overrides);
332
+ const hooks: ServerHooks = {
333
+ onRestart: () => {
334
+ restartRequested = true;
335
+ void shutdown('restart request');
336
+ },
337
+ };
338
+ bootstrapPromise = bootstrapFn(overrides, hooks);
289
339
  bootstrapPromise
290
340
  .then(({ server, orchestrator }) => {
291
341
  serverInstance = server;