@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,60 @@
1
+ import { validateGitHubUrl } from '../types.ts';
2
+
3
+ /**
4
+ * Plan bond-app-azure-jira P1: where a ticket's repo lives. GitHub (as always) or Azure
5
+ * Repos (Azure DevOps). Hubs and repo lists stay GitHub only; a single-repo ticket may be
6
+ * either.
7
+ */
8
+ export type RepoHost = 'github' | 'azure';
9
+
10
+ export interface AzureRepoRef {
11
+ /** https://dev.azure.com/<org> (the API and git root). */
12
+ orgUrl: string;
13
+ org: string;
14
+ project: string;
15
+ repo: string;
16
+ }
17
+
18
+ const NAME = '[A-Za-z0-9][A-Za-z0-9_.-]{0,99}';
19
+ // Projects and repos may carry spaces (URL-encoded as %20) and a few other characters.
20
+ const SEG = "[A-Za-z0-9_.~%'()+-]{1,200}";
21
+ const DEV_AZURE = new RegExp(`^https://(?:${NAME}@)?dev\\.azure\\.com/(${NAME})/(${SEG})/_git/(${SEG}?)/?$`);
22
+ const VISUALSTUDIO = new RegExp(`^https://(?:${NAME}@)?(${NAME})\\.visualstudio\\.com/(?:DefaultCollection/)?(${SEG})/_git/(${SEG}?)/?$`);
23
+
24
+ /**
25
+ * An Azure Repos clone URL, in either the dev.azure.com form or the older
26
+ * <org>.visualstudio.com one, with or without the `<user>@` git adds. Null otherwise.
27
+ */
28
+ export function parseAzureRepoUrl(url: string): AzureRepoRef | null {
29
+ const u = String(url ?? '').trim();
30
+ const m = DEV_AZURE.exec(u) ?? VISUALSTUDIO.exec(u);
31
+ if (!m) return null;
32
+ const [, org, project, repoRaw] = m;
33
+ const repo = repoRaw.replace(/\.git$/, '');
34
+ if (!repo || project.includes('..') || repo.includes('..')) return null;
35
+ return { orgUrl: `https://dev.azure.com/${org}`, org, project, repo };
36
+ }
37
+
38
+ /** The canonical clone URL of an Azure repo (dev.azure.com, no user part). */
39
+ export function azureRepoUrl(ref: AzureRepoRef): string {
40
+ return `${ref.orgUrl}/${ref.project}/_git/${ref.repo}`;
41
+ }
42
+
43
+ export function repoHostOf(url: string): RepoHost | null {
44
+ if (validateGitHubUrl(url)) return 'github';
45
+ if (parseAzureRepoUrl(url)) return 'azure';
46
+ return null;
47
+ }
48
+
49
+ /** A repo a single-repo ticket can work on: GitHub or Azure Repos. */
50
+ export function validateRepoUrl(url: string): boolean {
51
+ return repoHostOf(url) !== null;
52
+ }
53
+
54
+ /** «owner/repo» or «org/project/repo», for messages and the delete preview. */
55
+ export function repoLabel(url: string): string {
56
+ const az = parseAzureRepoUrl(url);
57
+ if (az) return `${az.org}/${decodeURIComponent(az.project)}/${decodeURIComponent(az.repo)}`;
58
+ const gh = /github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/.exec(url);
59
+ return gh ? `${gh[1]}/${gh[2]}` : url;
60
+ }
@@ -0,0 +1,239 @@
1
+ import {
2
+ SETUP_AGENTS,
3
+ type AgentCredentialSummary,
4
+ type GitHubCredentialSummary,
5
+ type RunnerImageInfo,
6
+ type SetupState,
7
+ } from '../types.ts';
8
+ import { TOOL_CATALOG } from '../runner/tool-catalog.ts';
9
+
10
+ /**
11
+ * W-P1 (wizard): the aggregate the orchestrator serves at GET/PUT /api/v1/setup.
12
+ * Pure functions here so the calculation of `complete` is unit-testable without HTTP
13
+ * or docker; the orchestrator gathers the inputs and calls buildSetupState.
14
+ */
15
+
16
+ /**
17
+ * Parse the /opt/runner-agents manifest written by runner/setup.sh: comment lines
18
+ * start with '#'; one agent per line as `agent=<name> version=<v> config_sha256=<h|none>
19
+ * credentials=<yes|no>`. Returns the agent names in manifest order.
20
+ */
21
+ export function parseRunnerManifest(manifest: string): string[] {
22
+ const agents: string[] = [];
23
+ for (const line of manifest.split('\n')) {
24
+ const trimmed = line.trim();
25
+ if (!trimmed || trimmed.startsWith('#')) continue;
26
+ const match = trimmed.match(/^agent=([A-Za-z0-9_.-]+)(\s|$)/);
27
+ if (match) agents.push(match[1]);
28
+ }
29
+ return agents;
30
+ }
31
+
32
+ /**
33
+ * Plan bond-app-ajustes-imagen P2: the developer tool groups (`group=<id> installed=yes`)
34
+ * and extra apt packages (`apt_extra=a,b`) a manifest records. An image built before the
35
+ * catalog has neither: no tools.
36
+ */
37
+ export function parseRunnerManifestTools(manifest: string): { tools: string[]; apt_extra: string[] } {
38
+ const tools: string[] = [];
39
+ let aptExtra: string[] = [];
40
+ for (const line of manifest.split('\n')) {
41
+ const trimmed = line.trim();
42
+ const group = trimmed.match(/^group=([A-Za-z0-9_.-]+)(\s|$)/);
43
+ if (group) tools.push(group[1]);
44
+ const apt = trimmed.match(/^apt_extra=(\S+)$/);
45
+ if (apt) aptExtra = apt[1].split(',').filter(Boolean);
46
+ }
47
+ return { tools, apt_extra: aptExtra };
48
+ }
49
+
50
+ /** What the image lacks against the selection (agents and tool groups) and what it has extra. */
51
+ export function imageDrift(
52
+ image: RunnerImageInfo,
53
+ selection: { agents_selected: string[]; tools_selected: string[]; apt_extra: string[] },
54
+ recipe?: string
55
+ ): { stale: boolean; missing_agents: string[]; missing_tools: string[]; extra_tools: string[]; apt_changed: boolean; recipe_changed: boolean } {
56
+ if (!image.present) return { stale: false, missing_agents: [], missing_tools: [], extra_tools: [], apt_changed: false, recipe_changed: false };
57
+ const agents = image.agents ?? [];
58
+ const tools = image.tools ?? [];
59
+ const missing_agents = agents.length ? selection.agents_selected.filter((a) => !agents.includes(a)) : [];
60
+ const missing_tools = selection.tools_selected.filter((t) => !tools.includes(t));
61
+ const extra_tools = tools.filter((t) => !selection.tools_selected.includes(t));
62
+ const have = [...(image.apt_extra ?? [])].sort().join(',');
63
+ const want = [...selection.apt_extra].sort().join(',');
64
+ const apt_changed = have !== want;
65
+ // Only when the current recipe is known: an image without the label is older than it.
66
+ const recipe_changed = Boolean(recipe) && image.recipe !== recipe;
67
+ return {
68
+ stale: missing_agents.length > 0 || missing_tools.length > 0 || extra_tools.length > 0 || apt_changed || recipe_changed,
69
+ missing_agents,
70
+ missing_tools,
71
+ extra_tools,
72
+ apt_changed,
73
+ recipe_changed,
74
+ };
75
+ }
76
+
77
+ export interface SetupStateInputs {
78
+ setup_done: boolean;
79
+ agents_selected: string[];
80
+ /** Credential summaries (any agents); the aggregate keeps the SETUP_AGENTS ones. */
81
+ credentials: AgentCredentialSummary[];
82
+ github: GitHubCredentialSummary;
83
+ image: RunnerImageInfo;
84
+ /** W-P4: the suggestions model (supi) stored in the setup state; null = «sin sugerencias». */
85
+ suggestions_model?: string | null;
86
+ /** D-M1: the default working model for pi; null = provider baked default. */
87
+ default_model?: string | null;
88
+ /** P3: full model ids configured for pi (provider/id). */
89
+ models?: string[];
90
+ /** Plan bond-app-ajustes-imagen P2: chosen tool groups and extra apt packages. */
91
+ tools_selected?: string[];
92
+ apt_extra?: string[];
93
+ /** Fingerprint of the current runner recipe (runnerRecipeHash); compared with the image's. */
94
+ recipe?: string;
95
+ }
96
+
97
+ /**
98
+ * `complete` answers «can a run actually start here?»: a GitHub credential, at least one
99
+ * agent with a stored credential, and the runner image present. setup_done is an explicit
100
+ * flag only (the wizard's «Finalizar»), never part of the calculation.
101
+ */
102
+ export function buildSetupState(inputs: SetupStateInputs): SetupState {
103
+ const configuredByAgent = new Map(inputs.credentials.map((c) => [c.agent, c.configured]));
104
+ const agents = SETUP_AGENTS.map((agent) => ({
105
+ agent,
106
+ configured: configuredByAgent.get(agent) ?? false,
107
+ }));
108
+ const anyAgentConfigured = agents.some((a) => a.configured);
109
+ const githubConfigured = inputs.github.configured;
110
+
111
+ return {
112
+ complete: githubConfigured && anyAgentConfigured && inputs.image.present,
113
+ setup_done: inputs.setup_done,
114
+ agents_selected: inputs.agents_selected,
115
+ agents,
116
+ github: {
117
+ configured: githubConfigured,
118
+ ...(inputs.github.login !== undefined ? { login: inputs.github.login } : {}),
119
+ },
120
+ image: {
121
+ ...inputs.image,
122
+ ...imageDrift(inputs.image, {
123
+ agents_selected: inputs.agents_selected,
124
+ tools_selected: inputs.tools_selected ?? [],
125
+ apt_extra: inputs.apt_extra ?? [],
126
+ }, inputs.recipe),
127
+ },
128
+ tools_selected: inputs.tools_selected ?? [],
129
+ apt_extra: inputs.apt_extra ?? [],
130
+ catalog: TOOL_CATALOG.map((g) => ({ ...g })),
131
+ suggestions_model: inputs.suggestions_model ?? null,
132
+ default_model: inputs.default_model ?? null,
133
+ models: inputs.models ?? [],
134
+ };
135
+ }
136
+
137
+ // --- W-P4: model list proxied from the provider -----------------------------------------
138
+
139
+ /** Timeout of the provider GET {base}/models proxy (plan W-P4: ~5 s). */
140
+ export const PROVIDER_MODELS_TIMEOUT_MS = 5000;
141
+
142
+ /** Upper bound of ids returned by the proxy; a provider listing thousands gets the first ones. */
143
+ export const PROVIDER_MODELS_MAX = 500;
144
+
145
+ /** The proxy failed (bad base_url, unreachable provider, bad response). The message never
146
+ * carries the API key; the base URL is not echoed either (it may embed credentials). */
147
+ export class ProviderModelsError extends Error {}
148
+
149
+ const PROVIDER_URL_RE = /^(https?:\/\/)([^\s/@]+)(\/[^\s]*)?$/i;
150
+
151
+ /**
152
+ * Same normalization the builder dialog uses (app/mods/bond-settings/pi-models.js):
153
+ * http(s) with host; no path (or "/") gets "/v1" — where Ollama, LM Studio, vLLM and
154
+ * friends serve —; a path is kept as entered, minus a trailing slash. Returns null if
155
+ * the text is not an http(s) URL.
156
+ */
157
+ export function normalizeProviderBase(raw: string): string | null {
158
+ const url = String(raw ?? '').trim();
159
+ const m = PROVIDER_URL_RE.exec(url);
160
+ if (!m || !m[2]) return null;
161
+ const [, scheme, host, path] = m;
162
+ if (!path || path === '/') return `${scheme}${host}/v1`;
163
+ return url.endsWith('/') ? url.slice(0, -1) : url;
164
+ }
165
+
166
+ /**
167
+ * Sanitize a provider's /models answer into a deduped list of non-empty ids. Accepts the
168
+ * OpenAI-compatible shapes seen in the wild: {data:[{id}]}, {models:[{id|name}]}, or a
169
+ * bare array of strings/objects. Non-strings without id/name are dropped.
170
+ */
171
+ export function sanitizeModelIds(doc: unknown): string[] {
172
+ const record = doc as Record<string, unknown> | null;
173
+ const arr = Array.isArray(doc)
174
+ ? doc
175
+ : Array.isArray(record?.data)
176
+ ? (record!.data as unknown[])
177
+ : Array.isArray(record?.models)
178
+ ? (record!.models as unknown[])
179
+ : [];
180
+ const out: string[] = [];
181
+ const seen = new Set<string>();
182
+ for (const item of arr) {
183
+ let id = '';
184
+ if (typeof item === 'string') id = item;
185
+ else if (item && typeof item === 'object') {
186
+ const rec = item as Record<string, unknown>;
187
+ id = typeof rec.id === 'string' ? rec.id : typeof rec.name === 'string' ? rec.name : '';
188
+ }
189
+ id = id.trim();
190
+ if (!id || seen.has(id)) continue;
191
+ seen.add(id);
192
+ out.push(id);
193
+ if (out.length >= PROVIDER_MODELS_MAX) break;
194
+ }
195
+ return out;
196
+ }
197
+
198
+ /**
199
+ * W-P4: ask an OpenAI-compatible provider for its model ids (GET {base}/models). The
200
+ * optional API key travels only as this request's Bearer header; it is never logged and
201
+ * never appears in an error message (the proxy runs in the orchestrator, so the browser
202
+ * never sees the key either). Throws ProviderModelsError with a short, safe message.
203
+ */
204
+ export async function listProviderModels(opts: {
205
+ baseUrl: string;
206
+ apiKey?: string;
207
+ timeoutMs?: number;
208
+ }): Promise<string[]> {
209
+ const base = normalizeProviderBase(opts.baseUrl);
210
+ if (!base) throw new ProviderModelsError("'base_url' must be an http(s) URL");
211
+ const timeoutMs = opts.timeoutMs ?? PROVIDER_MODELS_TIMEOUT_MS;
212
+ const key = opts.apiKey?.trim() ?? '';
213
+ let res: Response;
214
+ try {
215
+ res = await fetch(`${base}/models`, {
216
+ signal: AbortSignal.timeout(timeoutMs),
217
+ headers: {
218
+ Accept: 'application/json',
219
+ ...(key ? { Authorization: `Bearer ${key}` } : {}),
220
+ },
221
+ });
222
+ } catch (err) {
223
+ const name = (err as Error)?.name ?? '';
224
+ if (name === 'TimeoutError' || name === 'AbortError') {
225
+ throw new ProviderModelsError('the provider timed out');
226
+ }
227
+ throw new ProviderModelsError('could not reach the provider');
228
+ }
229
+ if (!res.ok) throw new ProviderModelsError(`the provider answered HTTP ${res.status}`);
230
+ let doc: unknown;
231
+ try {
232
+ doc = await res.json();
233
+ } catch {
234
+ throw new ProviderModelsError('the provider answer was not JSON');
235
+ }
236
+ const models = sanitizeModelIds(doc);
237
+ if (models.length === 0) throw new ProviderModelsError('the provider returned no models');
238
+ return models;
239
+ }
@@ -71,14 +71,13 @@ export class Watchdog {
71
71
  return true;
72
72
  }
73
73
 
74
- // 2. Queued timeout check (M-D, P3 criterion 4): timeout measured strictly from created_at
75
- if (run.state === 'queued') {
74
+ // 2. Queued timeout check (M-D, P3 criterion 4): timeout measured strictly from created_at.
75
+ // timeout_minutes <= 0 means no timeout at all: a queued run is never terminated by
76
+ // the watchdog; it stays queued until budget or an explicit action ends it.
77
+ if (run.state === 'queued' && ticket.timeout_minutes > 0) {
76
78
  const queuedAt = new Date(run.created_at).getTime();
77
79
  const queuedElapsedMs = Date.now() - queuedAt;
78
- const maxQueuedMs =
79
- ticket.timeout_minutes > 0
80
- ? Math.min(ticket.timeout_minutes * 60 * 1000, 120_000)
81
- : 120_000;
80
+ const maxQueuedMs = Math.min(ticket.timeout_minutes * 60 * 1000, 120_000);
82
81
  if (queuedElapsedMs > maxQueuedMs) {
83
82
  await this.terminateViaOrchestrator(run.id, 'timeout');
84
83
  return true;
@@ -87,6 +86,7 @@ export class Watchdog {
87
86
 
88
87
  // 3. Execution timeout check (Criterion 4, P7)
89
88
  // Wall-clock timeout counts only time in running/verifying/analyzing (pause it in waiting, blocked and finished).
89
+ // timeout_minutes <= 0 disables it entirely.
90
90
  if (
91
91
  run.started_at &&
92
92
  ticket.timeout_minutes > 0 &&
@@ -37,7 +37,7 @@ export function initDatabase(dbPath: string): DatabaseSync {
37
37
  base_branch TEXT NOT NULL DEFAULT 'main',
38
38
  target_branch TEXT NOT NULL,
39
39
  budget_usd REAL NOT NULL DEFAULT 1.0,
40
- timeout_minutes INTEGER NOT NULL DEFAULT 20,
40
+ timeout_minutes INTEGER NOT NULL DEFAULT 0,
41
41
  agent TEXT NOT NULL DEFAULT 'pi',
42
42
  model TEXT,
43
43
  prompt TEXT,
@@ -49,6 +49,8 @@ export function initDatabase(dbPath: string): DatabaseSync {
49
49
  repos TEXT,
50
50
  repo_agents TEXT,
51
51
  team_engine TEXT DEFAULT 'hc',
52
+ bondify INTEGER NOT NULL DEFAULT 1,
53
+ docker INTEGER NOT NULL DEFAULT 0,
52
54
  status TEXT NOT NULL DEFAULT 'ready',
53
55
  created_at TEXT NOT NULL,
54
56
  updated_at TEXT NOT NULL
@@ -103,6 +105,36 @@ export function initDatabase(dbPath: string): DatabaseSync {
103
105
  updated_at TEXT NOT NULL
104
106
  );
105
107
 
108
+ -- Plan bond-app-azure-jira P1: the Azure DevOps PAT for Azure Repos (clone, push, PR).
109
+ -- One row; never returned by the API. agents_enabled: it also reaches the run's agents.
110
+ CREATE TABLE IF NOT EXISTS azure_devops_credential (
111
+ id INTEGER PRIMARY KEY CHECK (id = 1),
112
+ org_url TEXT NOT NULL,
113
+ pat TEXT NOT NULL,
114
+ account TEXT,
115
+ agents_enabled INTEGER NOT NULL DEFAULT 1,
116
+ updated_at TEXT NOT NULL
117
+ );
118
+
119
+ -- Plan bond-app-azure-jira (P2): Jira Cloud credential (email + API token)
120
+ CREATE TABLE IF NOT EXISTS jira_credential (
121
+ id INTEGER PRIMARY KEY CHECK (id = 1),
122
+ site TEXT NOT NULL,
123
+ email TEXT NOT NULL,
124
+ token TEXT NOT NULL,
125
+ agents_enabled INTEGER NOT NULL DEFAULT 1,
126
+ account_name TEXT,
127
+ updated_at TEXT NOT NULL
128
+ );
129
+
130
+ -- W-P1 (wizard): key/value store for the orchestrator's own setup state
131
+ -- (agents_selected, setup_done). Small strings only; never credentials.
132
+ CREATE TABLE IF NOT EXISTS app_settings (
133
+ key TEXT PRIMARY KEY,
134
+ value TEXT NOT NULL,
135
+ updated_at TEXT NOT NULL
136
+ );
137
+
106
138
  CREATE INDEX IF NOT EXISTS idx_runs_ticket_id ON runs(ticket_id);
107
139
  CREATE INDEX IF NOT EXISTS idx_runs_state ON runs(state);
108
140
  CREATE INDEX IF NOT EXISTS idx_events_run_id ON events(run_id);
@@ -166,6 +198,28 @@ export function initDatabase(dbPath: string): DatabaseSync {
166
198
  } else {
167
199
  db.exec("UPDATE tickets SET team_engine = 'herdr' WHERE team_engine IS NULL;");
168
200
  }
201
+ // P4 (D-U): bondify (auto-bondify non-bondified repos on run start; default true = 1).
202
+ if (!ticketCols.some((c) => c.name === 'bondify')) {
203
+ db.exec('ALTER TABLE tickets ADD COLUMN bondify INTEGER DEFAULT 1;');
204
+ db.exec('UPDATE tickets SET bondify = 1 WHERE bondify IS NULL;');
205
+ }
206
+ // Plan bond-app-ajustes-imagen P4: «Docker en el run» (privileged container + dockerd); off.
207
+ if (!ticketCols.some((c) => c.name === 'docker')) {
208
+ db.exec('ALTER TABLE tickets ADD COLUMN docker INTEGER NOT NULL DEFAULT 0;');
209
+ }
210
+
211
+ // Plan bond-app-azure-jira P2: Jira Cloud credential table for pre-existing databases
212
+ db.exec(`
213
+ CREATE TABLE IF NOT EXISTS jira_credential (
214
+ id INTEGER PRIMARY KEY CHECK (id = 1),
215
+ site TEXT NOT NULL,
216
+ email TEXT NOT NULL,
217
+ token TEXT NOT NULL,
218
+ agents_enabled INTEGER NOT NULL DEFAULT 1,
219
+ account_name TEXT,
220
+ updated_at TEXT NOT NULL
221
+ );
222
+ `);
169
223
 
170
224
  return db;
171
225
  }