@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
package/src/core/hub-session.ts
CHANGED
|
@@ -24,7 +24,24 @@ import {
|
|
|
24
24
|
type HubProbe,
|
|
25
25
|
type HubToml,
|
|
26
26
|
} from './hub.ts';
|
|
27
|
-
import { isValidAgent, validateBranchName,
|
|
27
|
+
import { isValidAgent, validateBranchName, type HubAnalysisRepo, type HubFix, type Ticket } from '../types.ts';
|
|
28
|
+
import { validateRepoUrl } from './repo-host.ts';
|
|
29
|
+
|
|
30
|
+
export type TokenForRepo = string | ((url: string) => string | null | undefined);
|
|
31
|
+
|
|
32
|
+
function resolveRepoToken(token: TokenForRepo, url: string): string | null {
|
|
33
|
+
const t = typeof token === 'function' ? token(url) : token;
|
|
34
|
+
return t ? t : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Files `bond sync` / `bond hub sync` writes (agent config, catalog copies, the manifest and
|
|
39
|
+
* the generated blocks of AGENTS.md / CLAUDE.md): changes there come from bond, not the user.
|
|
40
|
+
*/
|
|
41
|
+
export function isBondGeneratedPath(p: string): boolean {
|
|
42
|
+
return /^(\.agents|\.claude|\.pi|\.codex|\.github\/copilot)\//.test(p)
|
|
43
|
+
|| ['AGENTS.md', 'CLAUDE.md', '.mcp.json', 'opencode.json', '.bond/manifest.json', '.bond/hub.local.toml'].includes(p);
|
|
44
|
+
}
|
|
28
45
|
|
|
29
46
|
export class HubMountError extends Error {
|
|
30
47
|
constructor(message: string) {
|
|
@@ -116,44 +133,65 @@ export class HubSession {
|
|
|
116
133
|
await this.mustRunner(['mkdir', '-p', CLONES_DIR], 'mkdir');
|
|
117
134
|
}
|
|
118
135
|
|
|
119
|
-
async readHubToml(): Promise<HubToml> {
|
|
136
|
+
async readHubToml(hubRemoteUrl?: string | null): Promise<HubToml> {
|
|
120
137
|
const res = await this.runner(['cat', `${HUB_DIR}/hub.toml`]);
|
|
121
138
|
if (res.exitCode !== 0) throw new HubMountError('the hub has no hub.toml: it is not a bond hub');
|
|
139
|
+
let remoteUrl = hubRemoteUrl ?? null;
|
|
140
|
+
if (!remoteUrl) {
|
|
141
|
+
const origin = await this.runner(['git', '-C', HUB_DIR, 'remote', 'get-url', 'origin']);
|
|
142
|
+
if (origin.exitCode === 0 && origin.stdout.trim()) remoteUrl = origin.stdout.trim();
|
|
143
|
+
}
|
|
122
144
|
try {
|
|
123
|
-
return parseHubToml(res.stdout);
|
|
145
|
+
return parseHubToml(res.stdout, remoteUrl);
|
|
124
146
|
} catch (err) {
|
|
125
147
|
throw new HubMountError((err as HubTomlError).message);
|
|
126
148
|
}
|
|
127
149
|
}
|
|
128
150
|
|
|
129
151
|
/**
|
|
130
|
-
* Clone an existing hub on its base and mount its repos. Repos without a
|
|
131
|
-
* that the token cannot read, are left out
|
|
132
|
-
* gaps): the mount itself only fails if the
|
|
152
|
+
* Clone an existing hub on its base and mount its repos. Repos without a supported url,
|
|
153
|
+
* without a credential for their host/org, or that the token cannot read, are left out
|
|
154
|
+
* and reported (the analysis turns them into gaps): the mount itself only fails if the
|
|
155
|
+
* hub cannot be cloned or read. When `targetBranch` is given (D5, ticket from PR),
|
|
156
|
+
* creates a local branch from `origin/<targetBranch>` in the hub and in every repo where
|
|
157
|
+
* that remote branch exists, without moving off their base.
|
|
133
158
|
*/
|
|
134
|
-
async mountExisting(hubUrl: string, hubBase: string, token: string): Promise<MountResult> {
|
|
135
|
-
const
|
|
159
|
+
async mountExisting(hubUrl: string, hubBase: string, token: TokenForRepo, targetBranch?: string): Promise<MountResult> {
|
|
160
|
+
const hubToken = resolveRepoToken(token, hubUrl);
|
|
161
|
+
if (!hubToken) throw new HubMountError(`the hub ${hubUrl} has no credential`);
|
|
162
|
+
const err = await this.clone(hubUrl, HUB_DIR, hubToken);
|
|
136
163
|
if (err) throw new HubMountError(`the hub ${hubUrl} could not be cloned: ${err}`);
|
|
137
164
|
const hasBase = await this.runner(['git', '-C', HUB_DIR, 'rev-parse', '--verify', '--quiet', `refs/remotes/origin/${hubBase}`]);
|
|
138
165
|
if (hasBase.exitCode !== 0) throw new HubMountError(`the hub has no base branch '${hubBase}'`);
|
|
139
166
|
await this.mustRunner(['git', '-C', HUB_DIR, 'checkout', '-q', '-B', hubBase, `origin/${hubBase}`], 'hub checkout');
|
|
140
|
-
|
|
141
|
-
|
|
167
|
+
if (targetBranch && targetBranch !== hubBase) {
|
|
168
|
+
const hasTarget = await this.runner(['git', '-C', HUB_DIR, 'rev-parse', '--verify', '--quiet', `refs/remotes/origin/${targetBranch}`]);
|
|
169
|
+
if (hasTarget.exitCode === 0) {
|
|
170
|
+
await this.mustRunner(['git', '-C', HUB_DIR, 'branch', '-f', targetBranch, `origin/${targetBranch}`], 'hub branch');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const hub = await this.readHubToml(hubUrl);
|
|
174
|
+
return this.mountRepos(hub, token, undefined, targetBranch);
|
|
142
175
|
}
|
|
143
176
|
|
|
144
177
|
/** Clone each repo of hub.toml and put it where hub.toml says. */
|
|
145
|
-
async mountRepos(hub: HubToml, token:
|
|
178
|
+
async mountRepos(hub: HubToml, token: TokenForRepo, only?: Set<string>, targetBranch?: string): Promise<MountResult> {
|
|
146
179
|
const inaccessible: Record<string, string> = {};
|
|
147
180
|
const missingBases: string[] = [];
|
|
148
181
|
const sources: Array<{ name: string; source: string }> = [];
|
|
149
182
|
for (const r of hub.repos) {
|
|
150
|
-
if (r.link === 'symlink' && r.url &&
|
|
183
|
+
if (r.link === 'symlink' && r.url && validateRepoUrl(r.url)) {
|
|
151
184
|
sources.push({ name: r.name, source: `${CLONES_DIR}/${r.name}` });
|
|
152
185
|
}
|
|
153
186
|
if (only && !only.has(r.name)) continue;
|
|
154
|
-
if (!r.url || !
|
|
187
|
+
if (!r.url || !validateRepoUrl(r.url)) continue;
|
|
188
|
+
const repoToken = resolveRepoToken(token, r.url);
|
|
189
|
+
if (!repoToken) {
|
|
190
|
+
inaccessible[r.name] = 'sin credencial para este host u organización';
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
155
193
|
const clonePath = `${CLONES_DIR}/${r.name}`;
|
|
156
|
-
const failure = await this.clone(r.url, clonePath,
|
|
194
|
+
const failure = await this.clone(r.url, clonePath, repoToken);
|
|
157
195
|
if (failure) {
|
|
158
196
|
inaccessible[r.name] = failure;
|
|
159
197
|
continue;
|
|
@@ -164,6 +202,12 @@ export class HubSession {
|
|
|
164
202
|
} else {
|
|
165
203
|
await this.mustRunner(['git', '-C', clonePath, 'checkout', '-q', '-B', r.base, `origin/${r.base}`], `checkout of ${r.name}`);
|
|
166
204
|
}
|
|
205
|
+
if (targetBranch && targetBranch !== r.base) {
|
|
206
|
+
const hasTarget = await this.runner(['git', '-C', clonePath, 'rev-parse', '--verify', '--quiet', `refs/remotes/origin/${targetBranch}`]);
|
|
207
|
+
if (hasTarget.exitCode === 0) {
|
|
208
|
+
await this.mustRunner(['git', '-C', clonePath, 'branch', '-f', targetBranch, `origin/${targetBranch}`], `branch of ${r.name}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
167
211
|
if (r.link !== 'symlink') {
|
|
168
212
|
await this.placeSubmodule(r.path, clonePath, r.name);
|
|
169
213
|
}
|
|
@@ -203,7 +247,7 @@ export class HubSession {
|
|
|
203
247
|
* Create a hub from the ticket's repos: each one cloned and added as a symlink with its
|
|
204
248
|
* url (from origin) and base in hub.toml, and the hub's first commit made by bond.
|
|
205
249
|
*/
|
|
206
|
-
async createHub(ticket: Ticket, token:
|
|
250
|
+
async createHub(ticket: Ticket, token: TokenForRepo): Promise<MountResult> {
|
|
207
251
|
const inaccessible: Record<string, string> = {};
|
|
208
252
|
const missingBases: string[] = [];
|
|
209
253
|
await this.mustRunner(['mkdir', '-p', HUB_DIR], 'mkdir');
|
|
@@ -212,7 +256,12 @@ export class HubSession {
|
|
|
212
256
|
for (const r of ticket.repos) {
|
|
213
257
|
const name = repoNameFromUrl(r.url);
|
|
214
258
|
const clonePath = `${CLONES_DIR}/${name}`;
|
|
215
|
-
const
|
|
259
|
+
const repoToken = resolveRepoToken(token, r.url);
|
|
260
|
+
if (!repoToken) {
|
|
261
|
+
inaccessible[name] = 'sin credencial para este host u organización';
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const failure = await this.clone(r.url, clonePath, repoToken);
|
|
216
265
|
if (failure) {
|
|
217
266
|
inaccessible[name] = failure;
|
|
218
267
|
continue;
|
|
@@ -274,6 +323,15 @@ export class HubSession {
|
|
|
274
323
|
} catch {
|
|
275
324
|
return { failures: [`bond hub check gave no JSON (exit ${res.exitCode}): ${firstLine(res.stderr)}`], warnings };
|
|
276
325
|
}
|
|
326
|
+
// What the run's own `bond hub sync` rewrites when the image's bond is newer than the
|
|
327
|
+
// one the hub was synced with: agent config and catalog copies, not the user's work.
|
|
328
|
+
const hubOnlyGenerated = async (): Promise<boolean> => {
|
|
329
|
+
const st = await this.runner(['git', '-C', HUB_DIR, 'status', '--porcelain', '--untracked-files=all']);
|
|
330
|
+
if (st.exitCode !== 0) return false;
|
|
331
|
+
const paths = st.stdout.split('\n').map((l) => l.slice(3).trim()).filter(Boolean)
|
|
332
|
+
.map((p) => (p.includes(' -> ') ? p.split(' -> ')[1] : p).replace(/^"|"$/g, ''));
|
|
333
|
+
return paths.length > 0 && paths.every(isBondGeneratedPath);
|
|
334
|
+
};
|
|
277
335
|
for (const repo of parsed.repos ?? []) {
|
|
278
336
|
for (const c of repo.checks ?? []) {
|
|
279
337
|
if (c.level !== 'fail') continue;
|
|
@@ -282,6 +340,12 @@ export class HubSession {
|
|
|
282
340
|
// The hub itself starts no agent.
|
|
283
341
|
if (c.check === 'agentes' && (repo.path === '.' || !agentesFailureMatters(c.detail, teamAgent(String(repo.repo))))) {
|
|
284
342
|
warnings.push(`bond hub check: ${text}`);
|
|
343
|
+
} else if (c.check === 'config') {
|
|
344
|
+
// Agent config bond would regenerate (`bond sync`): drift between bond versions,
|
|
345
|
+
// not a reason to stop the run.
|
|
346
|
+
warnings.push(`bond hub check: ${text} (config generada por bond; no impide trabajar)`);
|
|
347
|
+
} else if (c.check === 'cambios' && repo.path === '.' && (await hubOnlyGenerated())) {
|
|
348
|
+
warnings.push(`bond hub check: ${text} (solo ficheros que genera bond al sincronizar el hub en el run)`);
|
|
285
349
|
} else {
|
|
286
350
|
failures.push(text);
|
|
287
351
|
}
|
|
@@ -334,7 +398,7 @@ export class HubSession {
|
|
|
334
398
|
* «Aprobar arreglos»: apply the fixes on the hub's run branch and commit them. Each fix
|
|
335
399
|
* that cannot be applied is returned with its reason; the rest are committed.
|
|
336
400
|
*/
|
|
337
|
-
async applyFixes(fixes: HubFix[], branch: string, token:
|
|
401
|
+
async applyFixes(fixes: HubFix[], branch: string, token: TokenForRepo): Promise<{ applied: string[]; failed: string[] }> {
|
|
338
402
|
await this.checkoutBranch(branch);
|
|
339
403
|
const applied: string[] = [];
|
|
340
404
|
const failed: string[] = [];
|
|
@@ -360,7 +424,8 @@ export class HubSession {
|
|
|
360
424
|
const existing = await this.runner(['git', '-C', clonePath, 'remote', 'get-url', 'origin']);
|
|
361
425
|
const sameRepo = existing.exitCode === 0 && existing.stdout.trim().toLowerCase().replace(/\.git$/, '') === fix.url.toLowerCase().replace(/\.git$/, '');
|
|
362
426
|
if (!sameRepo) {
|
|
363
|
-
const
|
|
427
|
+
const repoToken = resolveRepoToken(token, fix.url);
|
|
428
|
+
const failure = repoToken ? await this.clone(fix.url, clonePath, repoToken) : 'sin credencial para este host u organización';
|
|
364
429
|
if (failure) {
|
|
365
430
|
failed.push(`${fix.name}: ${failure}`);
|
|
366
431
|
continue;
|
|
@@ -688,24 +753,32 @@ export class HubSession {
|
|
|
688
753
|
'}"'
|
|
689
754
|
], 15_000);
|
|
690
755
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
756
|
+
// Decision 2026-11-25 (usuario): a hub run opens ONE session, the hub leader (gru), not a
|
|
757
|
+
// team. Opening repo agents spends tokens; the leader does it with `bond team` only if
|
|
758
|
+
// the person asks. The leader gets the story, the hub's repos and which of them already
|
|
759
|
+
// have the run branch (a ticket from a PR: D5 created it from origin), and works on the
|
|
760
|
+
// repos from the hub itself (`git switch <branch>` in a repo before touching it).
|
|
694
761
|
const story = [ticket.title, ticket.story ?? '', ticket.description ?? '', ticket.prompt ?? '']
|
|
695
762
|
.filter((s) => s.trim())
|
|
696
763
|
.join('\n\n');
|
|
764
|
+
const repoLines: string[] = [];
|
|
765
|
+
for (const r of repos) {
|
|
766
|
+
const has = await this.runner(['git', '-C', `${HUB_DIR}/${r.path}`, 'rev-parse', '--verify', '--quiet', `refs/heads/${branch}`]);
|
|
767
|
+
repoLines.push(has.exitCode === 0
|
|
768
|
+
? `- ${r.name} (${r.path}): ya tiene la rama ${branch} (del remoto); \`git -C ${r.path} switch ${branch}\` antes de tocarlo.`
|
|
769
|
+
: `- ${r.name} (${r.path}): sin la rama; si hay que cambiarlo, \`git -C ${r.path} switch -c ${branch} origin/${r.base}\`.`);
|
|
770
|
+
}
|
|
697
771
|
const repoList = repos.map((r) => r.name).join(',');
|
|
698
|
-
const teamCmd = `bond team ${shq(branch)} --repos ${repoList} --engine hc --no-table`;
|
|
699
772
|
const promptText = [
|
|
700
|
-
`
|
|
701
|
-
`
|
|
702
|
-
`
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
773
|
+
`Eres gru, el agente principal de este run, en la raíz del hub (${HUB_DIR}). Trabajas solo: no hay otros agentes abiertos.`,
|
|
774
|
+
`Historia del ticket:\n${story}`,
|
|
775
|
+
`Rama del run: ${branch}. Repos del hub:\n${repoLines.join('\n')}`,
|
|
776
|
+
[
|
|
777
|
+
'Cómo trabajar:',
|
|
778
|
+
'1. Lee la historia y el código de los repos implicados y trabaja tú desde el hub. Al acabar, deja los cambios commiteados en la rama del run de cada repo que toques; bond-app entrega desde ahí (push y PR por repo).',
|
|
779
|
+
`2. No abras agentes por repo por tu cuenta: cuestan tokens. Si la tarea lo pide, propónselo a la persona y, solo si te lo pide, ábrelos con \`bond team ${shq(branch)} --repos <repos> --engine hc --no-table\` (repos de: ${repoList}) y repártelos con \`bond team prompt\`.`,
|
|
780
|
+
'3. Informa aquí de lo que haces y pregunta lo que no esté claro.',
|
|
781
|
+
].join('\n'),
|
|
709
782
|
].join('\n\n');
|
|
710
783
|
|
|
711
784
|
const promptPath = '/home/runner/.bond/orchestrator-prompt.txt';
|
|
@@ -727,67 +800,11 @@ export class HubSession {
|
|
|
727
800
|
if (!MODEL_RE.test(effectiveModel)) throw new HubMountError(`Invalid model '${effectiveModel}'`);
|
|
728
801
|
modelArg = `--model ${shq(effectiveModel)} `;
|
|
729
802
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
HUB_DIR,
|
|
735
|
-
'hub-leader',
|
|
736
|
-
{ 'herdr.space': 's1', 'herdr.tab': 't1' }
|
|
737
|
-
);
|
|
803
|
+
// Its own tab (no herdr.tab label: t1 is the bond-init shell's), named gru like the
|
|
804
|
+
// main agent of a single-repo run, and signing its decisions as <kind>/gru (bond 1.16.8).
|
|
805
|
+
const leaderShellCmd = `cd ${HUB_DIR} && export BOND_TEAM_ENGINE=hc BOND_TEAM_NO_TABLE=1 BOND_AGENT=${shq(`${agentCmd}/gru`)} && exec ${agentCmd} ${modelArg}"$(cat ${promptPath})"`;
|
|
806
|
+
const terminal = await hc.startTerminal(machine, ['sh', '-c', leaderShellCmd], HUB_DIR, 'gru');
|
|
738
807
|
opts.onTerminal?.(terminal);
|
|
739
|
-
|
|
740
|
-
const teamDeadline = Date.now() + waitMs;
|
|
741
|
-
let opened = false;
|
|
742
|
-
while (Date.now() < teamDeadline) {
|
|
743
|
-
if (await this.teamOpen(branch, repos.length, 'hc', hc, machine)) {
|
|
744
|
-
opened = true;
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
if (Date.now() - (teamDeadline - waitMs) > 10_000) {
|
|
748
|
-
try {
|
|
749
|
-
const leader = await hc.getTerminal(terminal);
|
|
750
|
-
const isWaiting =
|
|
751
|
-
leader.status === 'blocked' ||
|
|
752
|
-
leader.status === 'waiting' ||
|
|
753
|
-
((leader.status === 'idle' || leader.status === 'done') && (leader.turn ?? 0) > 0);
|
|
754
|
-
if (isWaiting) {
|
|
755
|
-
break;
|
|
756
|
-
}
|
|
757
|
-
} catch {}
|
|
758
|
-
}
|
|
759
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
760
|
-
}
|
|
761
|
-
if (!opened) {
|
|
762
|
-
// P1 criterion 6 (M-3 de P7): if leader is currently executing bond team, wait for it
|
|
763
|
-
if (await this.isTeamCommandRunning()) {
|
|
764
|
-
const teamEnd = Date.now() + Math.min(waitMs, 60_000);
|
|
765
|
-
while (Date.now() < teamEnd && (await this.isTeamCommandRunning())) {
|
|
766
|
-
if (await this.teamOpen(branch, repos.length, 'hc', hc, machine)) {
|
|
767
|
-
opened = true;
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
if (!opened && !(await this.teamOpen(branch, repos.length, 'hc', hc, machine))) {
|
|
774
|
-
if (!(await this.isTeamCommandRunning())) {
|
|
775
|
-
const fallbackCmd = `cd ${HUB_DIR} && BOND_TEAM_NO_TABLE=1 BOND_TEAM_ENGINE=hc BOND_TEAM_LABELS='herdr.space=s1,herdr.tab=t1' bond team ${shq(branch)} --repos ${repoList} --engine hc --no-table --yes </dev/null`;
|
|
776
|
-
await this.runner(['sh', '-c', fallbackCmd], 60_000);
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// P1 criterion 6: wait for any running bond team to complete before restoring default agents
|
|
782
|
-
if (await this.isTeamCommandRunning()) {
|
|
783
|
-
const restEnd = Date.now() + 30_000;
|
|
784
|
-
while (Date.now() < restEnd && (await this.isTeamCommandRunning())) {
|
|
785
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
for (const r of agents.keys()) await this.restoreDefaultAgent(r.path);
|
|
790
|
-
|
|
791
808
|
return terminal;
|
|
792
809
|
}
|
|
793
810
|
}
|
package/src/core/hub.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* answer, and the text edits «Aprobar arreglos» makes. The orchestrator does the I/O.
|
|
5
5
|
*/
|
|
6
6
|
import { validateBranchName, validateGitHubUrl, isValidAgent } from '../types.ts';
|
|
7
|
+
import { azureRepoUrl, parseAzureRepoUrl, repoHostOf, validateRepoUrl } from './repo-host.ts';
|
|
7
8
|
export { NAME_RE, NAME_RE as REPO_NAME_RE };
|
|
8
9
|
import type { HubAnalysis, HubAnalysisRepo, HubGap, Ticket } from '../types.ts';
|
|
9
10
|
|
|
@@ -42,13 +43,43 @@ function unquote(raw: string): string | null {
|
|
|
42
43
|
return m[1].replace(/\\(["\\])/g, '$1');
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a `hub.toml` repo URL against the hub's remote URL when it is relative (`./` or
|
|
48
|
+
* `../`), the way `git submodule` resolves relative URLs.
|
|
49
|
+
*/
|
|
50
|
+
export function resolveHubRepoUrl(url: string, hubRemoteUrl?: string | null): string {
|
|
51
|
+
const raw = url.trim();
|
|
52
|
+
if (!raw.startsWith('./') && !raw.startsWith('../')) {
|
|
53
|
+
const az = parseAzureRepoUrl(raw);
|
|
54
|
+
return az ? azureRepoUrl(az) : raw;
|
|
55
|
+
}
|
|
56
|
+
if (!hubRemoteUrl) return raw;
|
|
57
|
+
const azBase = parseAzureRepoUrl(hubRemoteUrl);
|
|
58
|
+
const base = azBase ? azureRepoUrl(azBase) : hubRemoteUrl.trim();
|
|
59
|
+
if (!validateRepoUrl(base)) return raw;
|
|
60
|
+
try {
|
|
61
|
+
const baseWithSlash = base.replace(/\/+$/, '') + '/';
|
|
62
|
+
const resolvedUrl = new URL(raw, baseWithSlash);
|
|
63
|
+
if (resolvedUrl.origin !== new URL(baseWithSlash).origin) return raw;
|
|
64
|
+
let resolved = resolvedUrl.toString().replace(/\/+$/, '');
|
|
65
|
+
const azResolved = parseAzureRepoUrl(resolved);
|
|
66
|
+
if (azResolved) return azureRepoUrl(azResolved);
|
|
67
|
+
if (validateGitHubUrl(base) && base.endsWith('.git') && !resolved.endsWith('.git') && validateGitHubUrl(`${resolved}.git`)) {
|
|
68
|
+
resolved = `${resolved}.git`;
|
|
69
|
+
}
|
|
70
|
+
return resolved;
|
|
71
|
+
} catch {
|
|
72
|
+
return raw;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
45
76
|
/**
|
|
46
77
|
* Read the subset of TOML that `bond hub` writes: top-level `name`/`base` and one
|
|
47
78
|
* `[repos.<name>]` table per repo with string keys (url, path, base, link, agent,
|
|
48
79
|
* description). Anything else is ignored; an unsafe name or path is an error, since the
|
|
49
80
|
* orchestrator builds paths from them.
|
|
50
81
|
*/
|
|
51
|
-
export function parseHubToml(text: string): HubToml {
|
|
82
|
+
export function parseHubToml(text: string, hubRemoteUrl?: string | null): HubToml {
|
|
52
83
|
let name = '';
|
|
53
84
|
let base = 'main';
|
|
54
85
|
const repos: HubAnalysisRepo[] = [];
|
|
@@ -63,7 +94,7 @@ export function parseHubToml(text: string): HubToml {
|
|
|
63
94
|
const repo: HubAnalysisRepo = {
|
|
64
95
|
name: currentName,
|
|
65
96
|
path,
|
|
66
|
-
url: current.url ? current.url : null,
|
|
97
|
+
url: current.url ? resolveHubRepoUrl(current.url, hubRemoteUrl) : null,
|
|
67
98
|
base: repoBase,
|
|
68
99
|
link: current.link || 'submodule',
|
|
69
100
|
};
|
|
@@ -123,9 +154,9 @@ export function githubParts(url: string): { owner: string; repo: string } | null
|
|
|
123
154
|
return m ? { owner: m[1], repo: m[2] } : null;
|
|
124
155
|
}
|
|
125
156
|
|
|
126
|
-
/** A hub repo name from a GitHub URL, safe for paths. */
|
|
157
|
+
/** A hub repo name from a GitHub or Azure Repos URL, safe for paths. */
|
|
127
158
|
export function repoNameFromUrl(url: string): string {
|
|
128
|
-
const name = githubParts(url)?.repo ?? '';
|
|
159
|
+
const name = githubParts(url)?.repo ?? parseAzureRepoUrl(url)?.repo ?? '';
|
|
129
160
|
if (!NAME_RE.test(name)) throw new HubTomlError(`Cannot name a repo from '${url}'`);
|
|
130
161
|
return name;
|
|
131
162
|
}
|
|
@@ -168,22 +199,23 @@ export function fixedGaps(probe: HubProbe): HubGap[] {
|
|
|
168
199
|
});
|
|
169
200
|
continue;
|
|
170
201
|
}
|
|
171
|
-
if (!
|
|
202
|
+
if (!validateRepoUrl(r.url)) {
|
|
172
203
|
gaps.push({
|
|
173
204
|
id: id(),
|
|
174
205
|
kind: 'unsupported_url',
|
|
175
206
|
repo: r.name,
|
|
176
|
-
message: `'${r.name}' apunta a '${r.url}': bond-app solo monta repos de
|
|
207
|
+
message: `'${r.name}' apunta a '${r.url}': bond-app solo monta repos de GitHub o Azure Repos (el token no sale a otros hosts)`,
|
|
177
208
|
fix: null,
|
|
178
209
|
});
|
|
179
210
|
continue;
|
|
180
211
|
}
|
|
181
212
|
if (probe.inaccessible[r.name]) {
|
|
213
|
+
const hostName = repoHostOf(r.url) === 'azure' ? 'Azure DevOps' : 'GitHub';
|
|
182
214
|
gaps.push({
|
|
183
215
|
id: id(),
|
|
184
216
|
kind: 'repo_inaccessible',
|
|
185
217
|
repo: r.name,
|
|
186
|
-
message: `'${r.name}' (${r.url}) no se pudo montar con tu credencial de
|
|
218
|
+
message: `'${r.name}' (${r.url}) no se pudo montar con tu credencial de ${hostName}: ${probe.inaccessible[r.name]}`,
|
|
187
219
|
fix: null,
|
|
188
220
|
});
|
|
189
221
|
continue;
|
|
@@ -358,7 +390,7 @@ export function agentGaps(answer: AgentAnswer, hub: HubToml, startId: number): H
|
|
|
358
390
|
|
|
359
391
|
/** Put `url = "<url>"` in the `[repos.<name>]` table of hub.toml (replacing one there). */
|
|
360
392
|
export function setRepoUrlInHubToml(text: string, name: string, url: string): string {
|
|
361
|
-
if (!
|
|
393
|
+
if (!validateRepoUrl(url)) throw new HubTomlError(`Invalid url '${url}'`);
|
|
362
394
|
const lines = text.split('\n');
|
|
363
395
|
const header = lines.findIndex((l) => l.trim() === `[repos.${name}]` || l.trim() === `[repos."${name}"]`);
|
|
364
396
|
if (header < 0) throw new HubTomlError(`hub.toml has no [repos.${name}]`);
|