@cat-factory/executor-harness 1.108.0 → 1.110.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/dist/agent.js +2 -1
- package/dist/coding-agent.d.ts +2 -16
- package/dist/coding-agent.js +2 -372
- package/dist/job.d.ts +12 -3
- package/dist/job.js +5 -2
- package/dist/multi-repo-coding.d.ts +16 -0
- package/dist/multi-repo-coding.js +379 -0
- package/package.json +4 -4
- package/src/agent.ts +2 -1
- package/src/coding-agent.ts +2 -454
- package/src/job.ts +16 -4
- package/src/multi-repo-coding.ts +483 -0
package/dist/agent.js
CHANGED
|
@@ -10,7 +10,8 @@ import { cloneRepo, commitAll, conflictDiff, fetchPullRequestHead, fetchReferenc
|
|
|
10
10
|
import { inferVcsProvider, openPullRequest } from './vcs-api.js';
|
|
11
11
|
import { applyPrDescription } from './pr-description.js';
|
|
12
12
|
import { makeDirClaimer } from './checkout-dir.js';
|
|
13
|
-
import { noChangesReason, runCodingAgent
|
|
13
|
+
import { noChangesReason, runCodingAgent } from './coding-agent.js';
|
|
14
|
+
import { runMultiRepoCoding } from './multi-repo-coding.js';
|
|
14
15
|
import { validationFailureMessage } from './validation-checks.js';
|
|
15
16
|
import { prepopulateDependencies, withDependencyNote } from './dependency-install.js';
|
|
16
17
|
import { agentCapabilities, mergeEffort } from './agent-shared.js';
|
package/dist/coding-agent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HarnessAuthFields, ImageManifestSpec, RepoSpec, SkillSpec, McpServerSpec } from './job.js';
|
|
2
2
|
import type { HarnessCallMetric } from './pi.js';
|
|
3
3
|
import type { PiRunStats } from './pi-reduction.js';
|
|
4
4
|
import { type EffortReport } from './effort.js';
|
|
@@ -148,7 +148,7 @@ export interface CodingAgentOutcome {
|
|
|
148
148
|
effortReport?: EffortReport;
|
|
149
149
|
/**
|
|
150
150
|
* The agent-authored PR description, lifted from its sentinel file (absent when it wrote none).
|
|
151
|
-
* The PR-opening caller folds it over the dispatch-time title/body via
|
|
151
|
+
* The PR-opening caller folds it over the dispatch-time title/body via `applyPrDescription`;
|
|
152
152
|
* absent means the fallback text, unchanged.
|
|
153
153
|
*/
|
|
154
154
|
prDescription?: AgentPrDescription;
|
|
@@ -234,20 +234,6 @@ export declare function runRalphValidation(repoDir: string, cwd: string, validat
|
|
|
234
234
|
iteration?: number;
|
|
235
235
|
headSha?: string;
|
|
236
236
|
}>;
|
|
237
|
-
/**
|
|
238
|
-
* Multi-repo coding (service-connections phase 3): clone the primary repo AND every connected
|
|
239
|
-
* peer repo as SIBLING checkouts under one workspace root, run the agent ONCE with its cwd at
|
|
240
|
-
* that root (so it makes the cross-service change coherently across all of them), then commit +
|
|
241
|
-
* push each repo that actually changed and open one PR per dirty repo. The task's own-service PR
|
|
242
|
-
* is reported as `prUrl`/`branch`; the peer PRs as `peerPullRequests`.
|
|
243
|
-
*
|
|
244
|
-
* Deliberately simpler than the single-repo {@link runCodingAgent} for the first cut: NO mid-run
|
|
245
|
-
* checkpoint pushes (an evicted multi-repo run re-clones on retry — the deterministic work branch
|
|
246
|
-
* still lets it resume any commits it managed to push at the end), NO warm-pool persistent
|
|
247
|
-
* checkout (always ephemeral), and NO follow-up sentinel streaming. It reuses the SAME dir-scoped
|
|
248
|
-
* git helpers, so the per-repo clone/commit/push/PR mechanics match the single-repo path exactly.
|
|
249
|
-
*/
|
|
250
|
-
export declare function runMultiRepoCoding(job: AgentJob, opts?: RunOptions): Promise<AgentResult>;
|
|
251
237
|
/**
|
|
252
238
|
* The "no changes" reason both coding agents report: a caller-supplied lead phrase
|
|
253
239
|
* plus the shared "never acted" cause and a credential-scrubbed tail of Pi's stderr.
|
package/dist/coding-agent.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { mkdir } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { runCapturedCommand } from './captured-command.js';
|
|
4
|
-
import { makeDirClaimer } from './checkout-dir.js';
|
|
5
4
|
import { branchAheadOfBase, changedFilesSinceBase, branchHasCommitsSince, cloneExistingBranch, cloneRepo, commitTrackedEdits, createBranch, excludeFromGit, fetchReferenceBranches, headCommit, listUntrackedFiles, prepareExistingCheckout, pushBranch, refreshFromBaseIfClean, remoteBranchExists, } from './git.js';
|
|
6
|
-
import { openPullRequest } from './vcs-api.js';
|
|
7
5
|
import { FOLLOW_UPS_FILENAME, FollowUpTailer } from './follow-ups.js';
|
|
8
6
|
import { EFFORT_REPORT_FILE } from './effort.js';
|
|
9
|
-
import {
|
|
10
|
-
import { acquireRepoCheckout, agentNeverActed, agentOutputTail, runAgentInWorkspace,
|
|
7
|
+
import { PR_DESCRIPTION_FILE, readPrDescription, } from './pr-description.js';
|
|
8
|
+
import { acquireRepoCheckout, agentNeverActed, agentOutputTail, runAgentInWorkspace, } from './pi-workspace.js';
|
|
11
9
|
import { log } from './logger.js';
|
|
12
10
|
import { runValidationLoop, } from './validation-checks.js';
|
|
13
11
|
import { runReproductionLoop, } from './reproduction-proof.js';
|
|
@@ -681,374 +679,6 @@ export async function runRalphValidation(repoDir, cwd, validation, logger, opts)
|
|
|
681
679
|
...(headSha ? { headSha } : {}),
|
|
682
680
|
};
|
|
683
681
|
}
|
|
684
|
-
/**
|
|
685
|
-
* Multi-repo coding (service-connections phase 3): clone the primary repo AND every connected
|
|
686
|
-
* peer repo as SIBLING checkouts under one workspace root, run the agent ONCE with its cwd at
|
|
687
|
-
* that root (so it makes the cross-service change coherently across all of them), then commit +
|
|
688
|
-
* push each repo that actually changed and open one PR per dirty repo. The task's own-service PR
|
|
689
|
-
* is reported as `prUrl`/`branch`; the peer PRs as `peerPullRequests`.
|
|
690
|
-
*
|
|
691
|
-
* Deliberately simpler than the single-repo {@link runCodingAgent} for the first cut: NO mid-run
|
|
692
|
-
* checkpoint pushes (an evicted multi-repo run re-clones on retry — the deterministic work branch
|
|
693
|
-
* still lets it resume any commits it managed to push at the end), NO warm-pool persistent
|
|
694
|
-
* checkout (always ephemeral), and NO follow-up sentinel streaming. It reuses the SAME dir-scoped
|
|
695
|
-
* git helpers, so the per-repo clone/commit/push/PR mechanics match the single-repo path exactly.
|
|
696
|
-
*/
|
|
697
|
-
export async function runMultiRepoCoding(job, opts = {}) {
|
|
698
|
-
const logger = (opts.log ?? log).child({ kind: 'multi-repo', jobId: job.jobId });
|
|
699
|
-
const peers = job.peerRepos ?? [];
|
|
700
|
-
const references = job.referenceRepos ?? [];
|
|
701
|
-
const primaryWorkBranch = job.pushBranch ?? job.newBranch ?? job.branch;
|
|
702
|
-
// Assign the sibling directory per repo via the shared deterministic allocator
|
|
703
|
-
// (`owner__name__digest`, matching the backend prompt's `siblingCheckoutDir`), shared with the
|
|
704
|
-
// read-only explore fan-out.
|
|
705
|
-
const claimDir = makeDirClaimer();
|
|
706
|
-
const legs = [
|
|
707
|
-
{
|
|
708
|
-
repo: job.repo,
|
|
709
|
-
dirName: claimDir(job.repo),
|
|
710
|
-
dir: '',
|
|
711
|
-
cloneBranch: job.branch,
|
|
712
|
-
workBranch: primaryWorkBranch,
|
|
713
|
-
ghToken: job.ghToken,
|
|
714
|
-
...(job.pr ? { pr: job.pr } : {}),
|
|
715
|
-
primary: true,
|
|
716
|
-
baseSha: '',
|
|
717
|
-
resumed: false,
|
|
718
|
-
},
|
|
719
|
-
...peers.map((peer) => ({
|
|
720
|
-
repo: peer.repo,
|
|
721
|
-
dirName: claimDir(peer.repo),
|
|
722
|
-
dir: '',
|
|
723
|
-
cloneBranch: peer.repo.baseBranch,
|
|
724
|
-
// Coding peers always carry `newBranch` (the backend sets the shared work branch);
|
|
725
|
-
// fall back to the primary's for the type (read-only peers never reach this path).
|
|
726
|
-
workBranch: peer.newBranch ?? primaryWorkBranch,
|
|
727
|
-
ghToken: peer.ghToken ?? job.ghToken,
|
|
728
|
-
...(peer.pr ? { pr: peer.pr } : {}),
|
|
729
|
-
...(peer.frameId ? { frameId: peer.frameId } : {}),
|
|
730
|
-
primary: false,
|
|
731
|
-
baseSha: '',
|
|
732
|
-
resumed: false,
|
|
733
|
-
})),
|
|
734
|
-
// Read-only reference repos (doc-writer): cloned as siblings the agent reads but never writes.
|
|
735
|
-
// `workBranch` is set to the base only to satisfy the type — a read-only leg never branches or
|
|
736
|
-
// pushes (guarded by `readOnly` in both the clone and push phases below).
|
|
737
|
-
...references.map((reference) => ({
|
|
738
|
-
repo: reference.repo,
|
|
739
|
-
dirName: claimDir(reference.repo),
|
|
740
|
-
dir: '',
|
|
741
|
-
cloneBranch: reference.repo.baseBranch,
|
|
742
|
-
workBranch: reference.repo.baseBranch,
|
|
743
|
-
ghToken: reference.ghToken ?? job.ghToken,
|
|
744
|
-
primary: false,
|
|
745
|
-
readOnly: true,
|
|
746
|
-
baseSha: '',
|
|
747
|
-
resumed: false,
|
|
748
|
-
})),
|
|
749
|
-
];
|
|
750
|
-
return withWorkspace('multi', async (root) => {
|
|
751
|
-
// Clone (or resume) every sibling checkout under the workspace root and fetch the primary's
|
|
752
|
-
// reference branches. Mutates each leg's `dir`/`resumed`/`baseSha` in place.
|
|
753
|
-
await prepareMultiRepoCheckouts(root, legs, job, logger, opts);
|
|
754
|
-
// DEPENDENCY PREPOPULATION for the PRIMARY leg, exactly as the read-only multi-repo fan-out
|
|
755
|
-
// does it. The install is declared on ONE service frame (the primary repo's), so it runs in
|
|
756
|
-
// that leg's checkout and is never fanned out across peers, whose own frames declare configs
|
|
757
|
-
// this dispatch never resolved — running a `pnpm install` inside a Go checkout is not a
|
|
758
|
-
// degraded outcome, it is a wrong one. A cross-repo implementer needs its dependencies for
|
|
759
|
-
// the same reason a cross-repo investigator does; the note names the sibling directory
|
|
760
|
-
// because the agent itself stands at the workspace root.
|
|
761
|
-
//
|
|
762
|
-
// At the leg's checkout ROOT, not a `serviceDirectory` subtree: this layout applies no
|
|
763
|
-
// service-directory scoping anywhere (the agent runs at the root and the prompt explains the
|
|
764
|
-
// sibling checkouts), and a root install is the one that resolves a monorepo workspace whole.
|
|
765
|
-
const primaryLeg = legs.find((leg) => leg.primary);
|
|
766
|
-
const dependencyNote = primaryLeg
|
|
767
|
-
? await prepopulateDependencies({
|
|
768
|
-
spec: job.dependencyInstall,
|
|
769
|
-
installDir: primaryLeg.dir,
|
|
770
|
-
repoDir: primaryLeg.dir,
|
|
771
|
-
agentDir: root,
|
|
772
|
-
logger,
|
|
773
|
-
opts,
|
|
774
|
-
})
|
|
775
|
-
: undefined;
|
|
776
|
-
// THE REPOS' OWN PR TEMPLATES: one per leg that will actually open a pull request, each named
|
|
777
|
-
// by its sibling directory so the agent knows which checkout's briefing takes which shape —
|
|
778
|
-
// the repos in a workspace need not share a template, or ship one at all. A read-only
|
|
779
|
-
// reference leg is excluded by construction: it carries no `pr`, so nothing publishes for it.
|
|
780
|
-
const prTemplate = await resolvePrTemplateNote({
|
|
781
|
-
targets: legs
|
|
782
|
-
.filter((leg) => leg.pr)
|
|
783
|
-
.map((leg) => ({
|
|
784
|
-
repoDir: leg.dir,
|
|
785
|
-
repoLabel: leg.dirName,
|
|
786
|
-
...(leg.repo.provider ? { provider: leg.repo.provider } : {}),
|
|
787
|
-
})),
|
|
788
|
-
logger,
|
|
789
|
-
});
|
|
790
|
-
// Run the agent ONCE with its cwd at the workspace root, so it sees every sibling checkout
|
|
791
|
-
// and can change them coherently. No monorepo/service-directory scoping — the multi-repo
|
|
792
|
-
// note + the backend system-prompt section explain the layout.
|
|
793
|
-
opts.onPhase?.('agent');
|
|
794
|
-
logger.info('multi-repo: running agent', { repos: legs.map((l) => l.dirName) });
|
|
795
|
-
const { summary, stats, stderrTail, usage, callMetrics, effortReport } = await runAgentInWorkspace({
|
|
796
|
-
dir: root,
|
|
797
|
-
systemPrompt: job.systemPrompt,
|
|
798
|
-
userPrompt: withDependencyNote(withPrTemplateNote(job.userPrompt, prTemplate.note), dependencyNote),
|
|
799
|
-
model: job.model,
|
|
800
|
-
harness: job.harness,
|
|
801
|
-
subscriptionToken: job.subscriptionToken,
|
|
802
|
-
subscriptionBaseUrl: job.subscriptionBaseUrl,
|
|
803
|
-
ambientAuth: job.ambientAuth,
|
|
804
|
-
proxyBaseUrl: job.proxyBaseUrl,
|
|
805
|
-
proxyPhasePath: job.proxyPhasePath,
|
|
806
|
-
sessionToken: job.sessionToken,
|
|
807
|
-
webToolsGuidance: job.webToolsGuidance,
|
|
808
|
-
webSearchProxy: job.webSearch,
|
|
809
|
-
guardLimits: job.guardLimits,
|
|
810
|
-
...(job.contextFiles ? { contextFiles: job.contextFiles } : {}),
|
|
811
|
-
// Skills + tool servers apply to a multi-repo run exactly as to a single-repo one: they
|
|
812
|
-
// are properties of the AGENT KIND, not of the checkout layout.
|
|
813
|
-
...(job.skills?.length ? { skills: job.skills } : {}),
|
|
814
|
-
...(job.mcpServers?.length ? { mcpServers: job.mcpServers } : {}),
|
|
815
|
-
...(job.referenceScreenshots ? { referenceScreenshots: job.referenceScreenshots } : {}),
|
|
816
|
-
...(job.designImages ? { designImages: job.designImages } : {}),
|
|
817
|
-
multiRepo: true,
|
|
818
|
-
}, opts);
|
|
819
|
-
// Commit forgotten tracked edits, then push + open a PR for each repo the run actually changed.
|
|
820
|
-
const { primaryPushed, primaryPrUrl, peerPullRequests } = await pushMultiRepoLegs(legs, job, logger, opts, root, prTemplate);
|
|
821
|
-
const anyWork = primaryPushed || peerPullRequests.length > 0;
|
|
822
|
-
if (!anyWork) {
|
|
823
|
-
// Nothing changed in ANY repo. For the implementer this is a failure (as in the
|
|
824
|
-
// single-repo path); a caller that tolerates a no-op (never the implementer today)
|
|
825
|
-
// gets a clean non-event.
|
|
826
|
-
if (job.noChangesIsError === false) {
|
|
827
|
-
return {
|
|
828
|
-
pushed: false,
|
|
829
|
-
branch: primaryWorkBranch,
|
|
830
|
-
summary,
|
|
831
|
-
stats,
|
|
832
|
-
...(usage ? { usage } : {}),
|
|
833
|
-
...(callMetrics ? { callMetrics } : {}),
|
|
834
|
-
...(effortReport ? { effortReport } : {}),
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
return {
|
|
838
|
-
pushed: false,
|
|
839
|
-
branch: primaryWorkBranch,
|
|
840
|
-
summary,
|
|
841
|
-
stats,
|
|
842
|
-
error: noChangesReason('the agent produced no file changes in any repository', stats, stderrTail),
|
|
843
|
-
failureCause: 'no-changes',
|
|
844
|
-
...(usage ? { usage } : {}),
|
|
845
|
-
...(callMetrics ? { callMetrics } : {}),
|
|
846
|
-
...(effortReport ? { effortReport } : {}),
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
logger.info('multi-repo: complete', {
|
|
850
|
-
primaryPushed,
|
|
851
|
-
primaryPrUrl: primaryPrUrl ?? null,
|
|
852
|
-
peers: peerPullRequests.length,
|
|
853
|
-
});
|
|
854
|
-
return {
|
|
855
|
-
pushed: primaryPushed,
|
|
856
|
-
...(primaryPrUrl ? { prUrl: primaryPrUrl } : {}),
|
|
857
|
-
branch: primaryWorkBranch,
|
|
858
|
-
...(peerPullRequests.length ? { peerPullRequests } : {}),
|
|
859
|
-
summary,
|
|
860
|
-
stats,
|
|
861
|
-
...(usage ? { usage } : {}),
|
|
862
|
-
...(callMetrics ? { callMetrics } : {}),
|
|
863
|
-
...(effortReport ? { effortReport } : {}),
|
|
864
|
-
};
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
/**
|
|
868
|
-
* Clone phase for {@link runMultiRepoCoding}: every repo into its sibling dir under the workspace
|
|
869
|
-
* root. Resume an existing remote work branch (an evicted retry) rather than branching off base
|
|
870
|
-
* again, then fetch the primary repo's reference branches. Mutates each leg's `dir`/`resumed`/
|
|
871
|
-
* `baseSha` in place. Extracted so the multi-repo body stays small.
|
|
872
|
-
*/
|
|
873
|
-
async function prepareMultiRepoCheckouts(root, legs, job, logger, opts) {
|
|
874
|
-
const { signal } = opts;
|
|
875
|
-
opts.onPhase?.('clone');
|
|
876
|
-
for (const leg of legs) {
|
|
877
|
-
const dir = join(root, leg.dirName);
|
|
878
|
-
await mkdir(dir, { recursive: true });
|
|
879
|
-
// A read-only reference leg: clone its base branch for the agent to read, and stop there —
|
|
880
|
-
// no work branch, no resume, no base-refresh. It is skipped in the push phase, so it can
|
|
881
|
-
// never be written to. (Kept in the loop so it lands in the same workspace root as siblings.)
|
|
882
|
-
if (leg.readOnly) {
|
|
883
|
-
logger.info('multi-repo: cloning read-only reference', {
|
|
884
|
-
repo: leg.dirName,
|
|
885
|
-
cloneBranch: leg.cloneBranch,
|
|
886
|
-
});
|
|
887
|
-
await cloneRepo({
|
|
888
|
-
repo: { ...leg.repo, baseBranch: leg.cloneBranch },
|
|
889
|
-
ghToken: leg.ghToken,
|
|
890
|
-
dir,
|
|
891
|
-
signal,
|
|
892
|
-
});
|
|
893
|
-
leg.dir = dir;
|
|
894
|
-
continue;
|
|
895
|
-
}
|
|
896
|
-
leg.resumed = await remoteBranchExists(leg.repo.cloneUrl, leg.workBranch, leg.ghToken, signal);
|
|
897
|
-
if (leg.resumed) {
|
|
898
|
-
logger.info('multi-repo: resuming existing branch', {
|
|
899
|
-
repo: leg.dirName,
|
|
900
|
-
branch: leg.workBranch,
|
|
901
|
-
});
|
|
902
|
-
await cloneExistingBranch({
|
|
903
|
-
cloneUrl: leg.repo.cloneUrl,
|
|
904
|
-
branch: leg.workBranch,
|
|
905
|
-
ghToken: leg.ghToken,
|
|
906
|
-
dir,
|
|
907
|
-
signal,
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
else {
|
|
911
|
-
logger.info('multi-repo: cloning', { repo: leg.dirName, cloneBranch: leg.cloneBranch });
|
|
912
|
-
await cloneRepo({
|
|
913
|
-
repo: { ...leg.repo, baseBranch: leg.cloneBranch },
|
|
914
|
-
ghToken: leg.ghToken,
|
|
915
|
-
dir,
|
|
916
|
-
signal,
|
|
917
|
-
});
|
|
918
|
-
await createBranch(dir, leg.workBranch, signal);
|
|
919
|
-
}
|
|
920
|
-
leg.dir = dir;
|
|
921
|
-
// Exclude the agent-authored PR-description sentinel locally (as the single-repo path does)
|
|
922
|
-
// so the agent's own `git add` can never stage the briefing into the PR it describes.
|
|
923
|
-
await excludeFromGit(dir, PR_DESCRIPTION_FILE, signal);
|
|
924
|
-
// The branch tip before the agent runs. Captured BEFORE the resume base refresh below so
|
|
925
|
-
// that refresh's merge commit counts as advancement and is pushed (as in the single-repo
|
|
926
|
-
// path). A fresh leg produced work iff its branch advances past this; a resumed leg already
|
|
927
|
-
// carries prior work.
|
|
928
|
-
leg.baseSha = await headCommit(dir, signal);
|
|
929
|
-
// A resumed branch was cut from an OLDER base; merge the latest base in when the two merge
|
|
930
|
-
// cleanly so the agent works against current base and the peer/own PRs stay current. On a
|
|
931
|
-
// conflict this is a best-effort no-op (the merge gate handles a conflicting PR downstream),
|
|
932
|
-
// mirroring the single-repo {@link runCodingAgent} resume refresh.
|
|
933
|
-
if (leg.resumed) {
|
|
934
|
-
const refreshed = await refreshFromBaseIfClean(dir, leg.cloneBranch, leg.ghToken, signal).catch(() => false);
|
|
935
|
-
if (!refreshed) {
|
|
936
|
-
logger.info('multi-repo: resume base refresh skipped (conflict or error)', {
|
|
937
|
-
repo: leg.dirName,
|
|
938
|
-
base: leg.cloneBranch,
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
// Reference branches attach to the PRIMARY repo, so fetch them into the primary sibling
|
|
944
|
-
// checkout's `origin/<b>` refs (best-effort per branch). The backend's reference-branches
|
|
945
|
-
// prompt section names the primary repo's directory to run the read commands in.
|
|
946
|
-
if (job.referenceBranches?.length) {
|
|
947
|
-
const primaryLeg = legs.find((l) => l.primary);
|
|
948
|
-
if (primaryLeg?.dir) {
|
|
949
|
-
const fetched = await fetchReferenceBranches({
|
|
950
|
-
dir: primaryLeg.dir,
|
|
951
|
-
branches: job.referenceBranches,
|
|
952
|
-
ghToken: primaryLeg.ghToken,
|
|
953
|
-
signal,
|
|
954
|
-
onSkip: (branch, reason) => logger.warn('multi-repo: reference branch fetch skipped', { branch, reason }),
|
|
955
|
-
});
|
|
956
|
-
logger.info('multi-repo: fetched reference branches', {
|
|
957
|
-
requested: job.referenceBranches.length,
|
|
958
|
-
fetched: fetched.length,
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Push phase for {@link runMultiRepoCoding}: commit forgotten tracked edits, then push + open a PR
|
|
965
|
-
* for each repo the run actually changed (a repo the agent left untouched is skipped — no branch,
|
|
966
|
-
* no PR; a read-only reference leg is never committed or pushed). Extracted so the multi-repo body
|
|
967
|
-
* stays small; returns the primary's push/PR state plus the peer PRs.
|
|
968
|
-
*/
|
|
969
|
-
async function pushMultiRepoLegs(legs, job, logger, opts,
|
|
970
|
-
/** The workspace root the agent ran in — the fallback probe for the primary's briefing. */
|
|
971
|
-
root,
|
|
972
|
-
/** Which legs' briefings are filled templates — see the `titleFromHeading` read below. */
|
|
973
|
-
prTemplate) {
|
|
974
|
-
const { signal } = opts;
|
|
975
|
-
opts.onPhase?.('push');
|
|
976
|
-
let primaryPushed = false;
|
|
977
|
-
let primaryPrUrl;
|
|
978
|
-
const peerPullRequests = [];
|
|
979
|
-
for (const leg of legs) {
|
|
980
|
-
// A read-only reference leg is never committed or pushed — the third layer of the read-only
|
|
981
|
-
// guarantee (the spec carries no branch/PR, and the clone phase gave it no work branch).
|
|
982
|
-
if (leg.readOnly)
|
|
983
|
-
continue;
|
|
984
|
-
// Lift (and remove) the agent-authored PR description for THIS repo's PR before anything
|
|
985
|
-
// else touches the checkout — each sibling checkout carries its own briefing for its own PR.
|
|
986
|
-
// The agent's cwd here is the WORKSPACE ROOT rather than any one checkout, so an agent that
|
|
987
|
-
// read the prompt loosely may well have written a single briefing there instead. Fall back
|
|
988
|
-
// to it for the PRIMARY leg only: at the root there is nothing to say which repo it
|
|
989
|
-
// describes, and the primary is the one the run is actually about.
|
|
990
|
-
//
|
|
991
|
-
// Per-leg `titleFromHeading`: only a leg whose OWN repo ships a template has repo-authored
|
|
992
|
-
// headings in its sentinel, and the legs of a workspace need not agree about that — so this
|
|
993
|
-
// is keyed on the leg, never on whether the run found any template at all.
|
|
994
|
-
const readOptions = { titleFromHeading: !prTemplate.templated.has(leg.dir) };
|
|
995
|
-
const agentPrDescription = (await readPrDescription(leg.dir, readOptions)) ??
|
|
996
|
-
(leg.primary ? await readPrDescription(root, readOptions) : undefined);
|
|
997
|
-
await commitTrackedEdits(leg.dir, job.commitMessage ?? leg.pr?.title ?? 'Agent changes', signal);
|
|
998
|
-
const advanced = await branchHasCommitsSince(leg.dir, leg.baseSha, signal);
|
|
999
|
-
let hasWork = advanced || leg.resumed;
|
|
1000
|
-
if (leg.resumed && !advanced) {
|
|
1001
|
-
const ahead = await branchAheadOfBase(leg.dir, leg.repo.baseBranch, leg.ghToken, signal);
|
|
1002
|
-
if (ahead === false)
|
|
1003
|
-
hasWork = false;
|
|
1004
|
-
}
|
|
1005
|
-
const leftover = await listUntrackedFiles(leg.dir, signal);
|
|
1006
|
-
if (leftover.length > 0) {
|
|
1007
|
-
logger.warn('multi-repo: uncommitted new files left behind (not pushed)', {
|
|
1008
|
-
repo: leg.dirName,
|
|
1009
|
-
count: leftover.length,
|
|
1010
|
-
files: leftover.slice(0, 20),
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
if (!hasWork) {
|
|
1014
|
-
logger.info('multi-repo: no changes for repo', { repo: leg.dirName });
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
await pushBranch(leg.dir, leg.workBranch, leg.ghToken, signal);
|
|
1018
|
-
let prUrl = null;
|
|
1019
|
-
if (leg.pr) {
|
|
1020
|
-
prUrl = await openPullRequest({
|
|
1021
|
-
owner: leg.repo.owner,
|
|
1022
|
-
name: leg.repo.name,
|
|
1023
|
-
ghToken: leg.ghToken,
|
|
1024
|
-
head: leg.workBranch,
|
|
1025
|
-
base: leg.repo.baseBranch,
|
|
1026
|
-
pr: applyPrDescription(leg.pr, agentPrDescription),
|
|
1027
|
-
// See the single-repo call site: refresh a resumed leg's already-open PR, but only
|
|
1028
|
-
// when the text is the agent's own briefing rather than the dispatch-time fallback.
|
|
1029
|
-
...(agentPrDescription ? { refreshExisting: true } : {}),
|
|
1030
|
-
apiBase: job.githubApiBase,
|
|
1031
|
-
cloneUrl: leg.repo.cloneUrl,
|
|
1032
|
-
...(leg.repo.provider ? { provider: leg.repo.provider } : {}),
|
|
1033
|
-
signal,
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
if (leg.primary) {
|
|
1037
|
-
primaryPushed = true;
|
|
1038
|
-
if (prUrl)
|
|
1039
|
-
primaryPrUrl = prUrl;
|
|
1040
|
-
}
|
|
1041
|
-
else if (prUrl) {
|
|
1042
|
-
peerPullRequests.push({
|
|
1043
|
-
repo: `${leg.repo.owner}/${leg.repo.name}`,
|
|
1044
|
-
...(leg.frameId ? { frameId: leg.frameId } : {}),
|
|
1045
|
-
prUrl,
|
|
1046
|
-
branch: leg.workBranch,
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
return { primaryPushed, primaryPrUrl, peerPullRequests };
|
|
1051
|
-
}
|
|
1052
682
|
/**
|
|
1053
683
|
* The "no changes" reason both coding agents report: a caller-supplied lead phrase
|
|
1054
684
|
* plus the shared "never acted" cause and a credential-scrubbed tail of Pi's stderr.
|
package/dist/job.d.ts
CHANGED
|
@@ -86,8 +86,13 @@ export interface PrSpec {
|
|
|
86
86
|
*/
|
|
87
87
|
export interface PeerRepoSpec {
|
|
88
88
|
repo: RepoSpec;
|
|
89
|
-
/**
|
|
90
|
-
|
|
89
|
+
/**
|
|
90
|
+
* The involved service frames this repo resolved from, echoed back on the peer PR verbatim.
|
|
91
|
+
* More than one when the peer is a monorepo hosting several of the run's involved services:
|
|
92
|
+
* they share this ONE checkout, its work branch and its pull request. Opaque to the harness,
|
|
93
|
+
* which decides no frame attribution of its own.
|
|
94
|
+
*/
|
|
95
|
+
frameIds?: string[];
|
|
91
96
|
/**
|
|
92
97
|
* The work branch to create off the peer's base and push (the shared `cat-factory/<block>`).
|
|
93
98
|
* Present for a COING fan-out (coder / ci-fixer). Absent for a READ-ONLY explore fan-out
|
|
@@ -593,10 +598,14 @@ export interface AgentResult {
|
|
|
593
598
|
* repo the run actually changed (service-connections phase 3). Beside the own-service
|
|
594
599
|
* `prUrl`/`branch`; the backend lifts these onto the block's `peerPullRequests`. Absent for
|
|
595
600
|
* a single-repo run.
|
|
601
|
+
*
|
|
602
|
+
* `frameIds` is the dispatch's own attribution echoed back untouched (see
|
|
603
|
+
* {@link PeerRepoSpec.frameIds}): one entry per repo, carrying every involved frame that
|
|
604
|
+
* repo hosts.
|
|
596
605
|
*/
|
|
597
606
|
peerPullRequests?: {
|
|
598
607
|
repo: string;
|
|
599
|
-
|
|
608
|
+
frameIds?: string[];
|
|
600
609
|
prUrl: string;
|
|
601
610
|
branch: string;
|
|
602
611
|
}[];
|
package/dist/job.js
CHANGED
|
@@ -169,8 +169,11 @@ function parsePeerRepos(value) {
|
|
|
169
169
|
if (e.cloneBranch !== undefined) {
|
|
170
170
|
spec.cloneBranch = str(e.cloneBranch, `peerRepos[${i}].cloneBranch`);
|
|
171
171
|
}
|
|
172
|
-
if (
|
|
173
|
-
|
|
172
|
+
if (Array.isArray(e.frameIds)) {
|
|
173
|
+
const frameIds = e.frameIds.filter((f) => typeof f === 'string' && !!f);
|
|
174
|
+
if (frameIds.length)
|
|
175
|
+
spec.frameIds = frameIds;
|
|
176
|
+
}
|
|
174
177
|
if (typeof e.ghToken === 'string' && e.ghToken)
|
|
175
178
|
spec.ghToken = e.ghToken;
|
|
176
179
|
if (typeof e.pr === 'object' && e.pr !== null) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentJob, AgentResult } from './job.js';
|
|
2
|
+
import type { RunOptions } from './runner.js';
|
|
3
|
+
/**
|
|
4
|
+
* Multi-repo coding (service-connections phase 3): clone the primary repo AND every connected
|
|
5
|
+
* peer repo as SIBLING checkouts under one workspace root, run the agent ONCE with its cwd at
|
|
6
|
+
* that root (so it makes the cross-service change coherently across all of them), then commit +
|
|
7
|
+
* push each repo that actually changed and open one PR per dirty repo. The task's own-service PR
|
|
8
|
+
* is reported as `prUrl`/`branch`; the peer PRs as `peerPullRequests`.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately simpler than the single-repo {@link runCodingAgent} for the first cut: NO mid-run
|
|
11
|
+
* checkpoint pushes (an evicted multi-repo run re-clones on retry — the deterministic work branch
|
|
12
|
+
* still lets it resume any commits it managed to push at the end), NO warm-pool persistent
|
|
13
|
+
* checkout (always ephemeral), and NO follow-up sentinel streaming. It reuses the SAME dir-scoped
|
|
14
|
+
* git helpers, so the per-repo clone/commit/push/PR mechanics match the single-repo path exactly.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runMultiRepoCoding(job: AgentJob, opts?: RunOptions): Promise<AgentResult>;
|