@jmanuelcorral/bond-app 0.1.4 → 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 (78) hide show
  1. package/README.md +241 -7
  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 +8 -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 +316 -330
  11. package/app/mods/bond-agents/model.js +400 -6
  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 +8 -0
  16. package/app/mods/bond-board/main.js +1054 -366
  17. package/app/mods/bond-board/model.js +138 -17
  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 +8 -0
  30. package/app/mods/bond-settings/main.js +1645 -87
  31. package/app/mods/bond-settings/mod.json +1 -1
  32. package/app/mods/bond-settings/pi-models.js +144 -0
  33. package/app/mods/bond-status/api.js +35 -0
  34. package/app/mods/bond-status/brand.js +53 -2
  35. package/app/mods/bond-status/config.js +8 -0
  36. package/app/mods/bond-status/main.js +37 -15
  37. package/app/mods/bond-status/model.js +19 -1
  38. package/app/mods/bond-tabs/brand.js +53 -2
  39. package/app/mods/bond-tabs/main.js +45 -3
  40. package/app/mods/bond-titlebar/brand.js +53 -2
  41. package/app/mods/bond-titlebar/main.js +115 -55
  42. package/app/mods/bond-titlebar/version.js +3 -0
  43. package/app/themes/bond-dark.json +5 -5
  44. package/app/themes/bond-light.json +5 -5
  45. package/package.json +1 -1
  46. package/runner/Dockerfile +58 -15
  47. package/runner/SPIKE-BOND.md +89 -0
  48. package/runner/build-config/.none +0 -0
  49. package/runner/build-creds/.none +0 -0
  50. package/runner/config.example/README.md +27 -0
  51. package/runner/config.example/pi/models.json +22 -0
  52. package/runner/credentials.example.env +27 -0
  53. package/runner/entrypoint.sh +16 -0
  54. package/runner/setup.sh +927 -0
  55. package/runner/versions.env +61 -0
  56. package/scripts/app-install.ts +64 -1
  57. package/src/cli.ts +53 -3
  58. package/src/config.ts +8 -0
  59. package/src/core/agy-login.ts +682 -0
  60. package/src/core/delivery.ts +3 -1
  61. package/src/core/hub-session.ts +9 -7
  62. package/src/core/orchestrator.ts +1186 -168
  63. package/src/core/repo-host.ts +60 -0
  64. package/src/core/setup.ts +239 -0
  65. package/src/core/watchdog.ts +6 -6
  66. package/src/db/database.ts +55 -1
  67. package/src/db/settings-repo.ts +440 -7
  68. package/src/db/ticket-repo.ts +73 -17
  69. package/src/index.ts +4 -4
  70. package/src/runner/azure-devops-client.ts +163 -0
  71. package/src/runner/docker-client.ts +84 -5
  72. package/src/runner/github-client.ts +146 -0
  73. package/src/runner/hc-client.ts +40 -5
  74. package/src/runner/image-builder.ts +268 -10
  75. package/src/runner/jira-client.ts +368 -0
  76. package/src/runner/tool-catalog.ts +84 -0
  77. package/src/server/app.ts +585 -9
  78. package/src/types.ts +168 -1
@@ -0,0 +1,61 @@
1
+ # runner/versions.env — pins por agente para runner/setup.sh (leído vía VERSIONS_FILE).
2
+ # Cambiar un pin aquí cambia lo que setup.sh instala; el manifiesto /opt/runner-agents
3
+ # registra la versión real resultante de la instalación.
4
+ #
5
+ # Los pines de npm se fijan a versiones concretas (D-C). `agy` se instala con el
6
+ # instalador oficial de Google, que siempre sirve la última versión publicada
7
+ # (checksum sha512 verificado); no admite pin: AGY_VERSION es informativo y la
8
+ # versión real queda en el manifiesto. El binario de agy se autoactualiza en
9
+ # cada ejecución (comportamiento oficial del fabricante).
10
+
11
+ PI_VERSION=1.5.1
12
+ CLAUDE_VERSION=2.1.328
13
+ CODEX_VERSION=0.170.0
14
+ COPILOT_VERSION=1.0.114
15
+ AGY_VERSION=latest
16
+
17
+ # supi (sugerencias de prompt para pi): se instala solo cuando pi está en --agents
18
+ # (D-J del plan de la imagen). El config inyectado por run (~/.pi/agent/supi/config.json)
19
+ # es inerte sin este paquete.
20
+ SUPI_VERSION=11.0.1
21
+
22
+ # bond (el harness que lanza el agente, D-G): instalado por setup.sh con --with-bond
23
+ # (D-H: versión fijada; package npm con scope @jmanuelcorral/bond). El pin mínimo es
24
+ # 1.16.4: antes de esa versión bond no tiene comando `tui` (spike runner/SPIKE-BOND.md).
25
+ BOND_VERSION=1.16.7
26
+
27
+ # gh y azure-cli salen de los repos apt oficiales (GitHub y Microsoft); se dejan
28
+ # en «latest» del repo. AZURE_CLI_VERSION admite el pin «2.xx.y» (sufijo ~bookworm
29
+ # añadido por el script); vacío = última del repo.
30
+ AZURE_CLI_VERSION=
31
+
32
+ # --- Herramientas de developer (plan bond-app-ajustes-imagen P2: setup.sh --tools) -------
33
+ # Lo que sale de apt (Debian bookworm) va sin pin: lo fija la base de la imagen. Lo que se
34
+ # descarga lleva versión y sha256 (de los ficheros de checksums oficiales de cada proyecto,
35
+ # salvo delta, que no los publica: sha256 tomado al fijar la versión). Cambiar una versión
36
+ # exige su checksum. oh-my-zsh y sus plugins se clonan en un commit fijado (git lo verifica).
37
+ YQ_VERSION=v4.54.3
38
+ YQ_SHA256=129534601871538efe0ba4c5e62a34fb1d5f469bcb975c4fddeb467d82974973
39
+ AST_GREP_VERSION=0.51.3
40
+ DELTA_VERSION=0.22.0
41
+ DELTA_SHA256=109eac8927a80a7801e025901dcee8d56aa50a8de1805a111d98b5d6dbe5d647
42
+ STARSHIP_VERSION=v1.27.0
43
+ STARSHIP_SHA256=10c8eb4cb3b761d9bf59ea828444c2dab36c900b7d69a69e08814b286969df89
44
+ OHMYZSH_COMMIT=6c31a91a3e82b4055b36cc088c2f27f81119ba60
45
+ ZSH_AUTOSUGGESTIONS_COMMIT=e52ee8ca55bcc56a17c828767a3f98f22a68d4eb
46
+ ZSH_SYNTAX_HIGHLIGHTING_COMMIT=db085e4661f6aafd24e5acb5b2e17e4dd5dddf3e
47
+ UV_VERSION=0.13.9
48
+ UV_SHA256=a7fbaff2b9a271d85c1bdb540941090fd1ce011797b4abeb48e4dcd39c2471d5
49
+ GO_VERSION=1.27.4
50
+ GO_SHA256=7226736c2339719cda28fbf3a54d71aa63bcefe376e98cef00034268dab24840
51
+ RUSTUP_VERSION=1.29.3
52
+ RUSTUP_SHA256=b1c8cb14e30889e7e2999e6b69e62d9e9b9ffc0f4df8180564d306d9680e6c55
53
+ PNPM_VERSION=12.23.0
54
+ YARN_VERSION=4.19.0
55
+ BUN_VERSION=1.4.5
56
+ BUN_SHA256=94559b3b528995a49452f9f2404cec74f2efd7d06e0a000a8cd214b02c3666eb
57
+ KUBECTL_VERSION=v1.37.2
58
+ KUBECTL_SHA256=c04487523e7aa7d1493f7808174c899db93d7a9cf57531420cd76b9bd415f8f4
59
+ DEVCONTAINERS_CLI_VERSION=0.91.0
60
+ TERRAFORM_VERSION=1.17.2
61
+ TERRAFORM_SHA256=e6f16b2f0b137ee5729caa8c4e79a3bae4ee261acd198a1fcfa8584a6296605b
@@ -122,6 +122,60 @@ function validateApi(api: string): void {
122
122
  }
123
123
  }
124
124
 
125
+ /**
126
+ * The layout bond-app installed may hold `bond-runterm` blocks that the Agents panel used
127
+ * to write in PANELES before it became native splits (plan bond-app-pestanas-paneles E2).
128
+ * Without them, re-serialised as the mod did (JSON, 2 spaces, with or without the final
129
+ * newline), it is still our copy: these are the hashes that prove it.
130
+ */
131
+ export function layoutHashes(file: string): string[] {
132
+ const hashes = [sha256(file)];
133
+ try {
134
+ const text = fs.readFileSync(file, 'utf8');
135
+ // Only a layout that carries those blocks: any other edit, even whitespace, is the person's.
136
+ if (!text.includes('"bond-runterm"')) return hashes;
137
+ const doc = JSON.parse(text);
138
+ const strip = (n: { children?: unknown[] }) => {
139
+ if (n && Array.isArray(n.children)) {
140
+ n.children = n.children.filter((c) => (c as { id?: string })?.id !== 'bond-runterm');
141
+ n.children.forEach((c) => strip(c as { children?: unknown[] }));
142
+ }
143
+ };
144
+ strip(doc);
145
+ const out = JSON.stringify(doc, null, 2);
146
+ for (const text of [out, `${out}\n`]) hashes.push(crypto.createHash('sha256').update(text).digest('hex'));
147
+ } catch {
148
+ // Not JSON: only its own hash.
149
+ }
150
+ return hashes;
151
+ }
152
+
153
+ /** bond-app's version (package.json), for the title bar chip. */
154
+ export function appVersion(): string {
155
+ try {
156
+ const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')) as { version?: unknown };
157
+ return typeof pkg.version === 'string' && pkg.version ? pkg.version : 'dev';
158
+ } catch {
159
+ return 'dev';
160
+ }
161
+ }
162
+
163
+ function versionJs(version: string): string {
164
+ return [
165
+ '// Written by `npm run app:install` (bond-app) from package.json.',
166
+ `export const VERSION = ${JSON.stringify(version)};`,
167
+ '',
168
+ ].join('\n');
169
+ }
170
+
171
+ /** The command that starts the orchestrator these mods talk to (same node, same bin). */
172
+ export function startArgv(api: string, tokenFile: string | null): string[] {
173
+ const url = new URL(api);
174
+ const argv = [process.execPath, path.join(repoRoot, 'bin', 'bond-app.js'), 'start', '--port', url.port || '80'];
175
+ if (tokenFile) argv.push('--data-dir', path.dirname(path.resolve(tokenFile)));
176
+ return argv;
177
+ }
178
+
125
179
  function configJs(api: string, tokenFile: string | null): string {
126
180
  return [
127
181
  '// Written by `npm run app:install` (bond-app). The token itself is never written here:',
@@ -129,6 +183,12 @@ function configJs(api: string, tokenFile: string | null): string {
129
183
  'export const CONFIG = {',
130
184
  ` api: ${JSON.stringify(api.replace(/\/+$/, ''))},`,
131
185
  ` tokenFile: ${JSON.stringify(tokenFile)},`,
186
+ ' // Gasto/costes fuera por defecto (decisión 2026-11-19): el orquestador sigue',
187
+ ' // registrando cost_usd, pero la UI no lo muestra hasta que una configuración',
188
+ ' // en Ajustes lo active. Entonces esto será el valor de esa configuración.',
189
+ ' costs: false,',
190
+ ' // How to start the orchestrator (Ajustes «Arrancar orquestador»).',
191
+ ` start: ${JSON.stringify(startArgv(api, tokenFile))},`,
132
192
  '};',
133
193
  '',
134
194
  ].join('\n');
@@ -198,7 +258,9 @@ export function install(opts: InstallOptions): InstallResult {
198
258
  }
199
259
  }
200
260
  for (const [dest, key] of [[layoutDest, 'layout_sha256'], [previewDest, 'preview_sha256']] as const) {
201
- if (fs.existsSync(dest) && !opts.force && previous?.[key] !== sha256(dest)) {
261
+ if (!fs.existsSync(dest) || opts.force) continue;
262
+ const ours = key === 'layout_sha256' ? layoutHashes(dest) : [sha256(dest)];
263
+ if (!ours.includes(previous?.[key] ?? '')) {
202
264
  throw new Error(`${dest} exists and is not the copy bond-app installed (edited, or someone else's): use --force to replace it`);
203
265
  }
204
266
  }
@@ -242,6 +304,7 @@ export function install(opts: InstallOptions): InstallResult {
242
304
  for (const f of fs.readdirSync(path.join(appDir, 'brand')).filter((n) => n.endsWith('.svg'))) {
243
305
  fs.copyFileSync(path.join(appDir, 'brand', f), path.join(dest, 'brand', f));
244
306
  }
307
+ fs.writeFileSync(path.join(dest, 'version.js'), versionJs(appVersion()));
245
308
  }
246
309
  // Only mods that talk to the API carry a config.js (bond-titlebar doesn't).
247
310
  if (fs.existsSync(path.join(modsSrc, name, 'config.js'))) {
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;
package/src/config.ts CHANGED
@@ -26,6 +26,13 @@ export interface AppConfig {
26
26
  * e.g. '["bash"]' for a stub session without a paid agent.
27
27
  */
28
28
  agentCommand: string[] | null;
29
+ /**
30
+ * D-G (image plan): how a run launches its agent. `bond` (default): `bond tui --agent X`
31
+ * inside the container - bond is the harness (skills, AGENTS.md, sync, decisions, the
32
+ * status bar). `pi`: the bare agent CLI. A `bond` run falls back to the bare launcher
33
+ * when the image has no usable bond or the repo is not a bond repo.
34
+ */
35
+ runnerLauncher: 'bond' | 'pi';
29
36
  /** P4 criterion 3: verification failures in a row before the run goes to `blocked`. */
30
37
  maxVerifyFailures: number;
31
38
  /** P4: time limit of each verify command. */
@@ -133,6 +140,7 @@ export function loadConfig(overrides: Partial<AppConfig> = {}): AppConfig {
133
140
  memory: process.env.BOND_APP_MEMORY || '2g',
134
141
  pidsLimit: parseInt(process.env.BOND_APP_PIDS_LIMIT || '200', 10),
135
142
  agentCommand: parseAgentCommand(process.env.BOND_APP_AGENT_COMMAND),
143
+ runnerLauncher: process.env.RUNNER_LAUNCHER === 'pi' ? 'pi' : 'bond',
136
144
  maxVerifyFailures: Math.max(1, parseInt(process.env.BOND_APP_MAX_VERIFY_FAILURES || '3', 10) || 3),
137
145
  verifyTimeoutMs: 10 * 60 * 1000,
138
146
  analysisCommand: parseAnalysisCommand(process.env.BOND_APP_ANALYSIS_COMMAND),