@cat-factory/executor-harness 1.106.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.
@@ -0,0 +1,207 @@
1
+ import { mkdir, stat, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { CONTEXT_DIR, excludeContextDir } from './pi.js';
4
+ // ---------------------------------------------------------------------------
5
+ // The TRANSFER half of every image manifest: download the images the backend resolved for this job
6
+ // into a subdirectory of `.cat-context/`, and report what did not land.
7
+ //
8
+ // Shared by both manifests (the capture references and the design pictures) because the transfer is
9
+ // the same in every respect that matters here: the same download seam, the same per-image and
10
+ // whole-pass budgets, the same idempotence over a checkout an agent flow re-enters once per repair
11
+ // round, and the same rule that a miss is NAMED rather than silently absent. What differs is what
12
+ // the files mean, which is why each caller owns its own directory and its own prompt block.
13
+ //
14
+ // The harness MATERIALISES and never decides: which artifact belongs to which view, and what each
15
+ // file is called, are backend answers that ride the job body.
16
+ // ---------------------------------------------------------------------------
17
+ /** Per-image ceiling, matching the platform's own upload ceiling (16 MiB). */
18
+ const MAX_IMAGE_BYTES = 16 * 1024 * 1024;
19
+ /** Per-image request timeout. */
20
+ const REQUEST_TIMEOUT_MS = 20_000;
21
+ /**
22
+ * Wall-clock ceiling on the WHOLE pass.
23
+ *
24
+ * Downloading is activity-silent from the watchdog's point of view (no agent stream, no output),
25
+ * and `JOB_INACTIVITY_MS` (10 min) is what kills a job that stops producing. Rather than heartbeat
26
+ * a transfer that should take seconds, the pass is bounded far below that: a slow or wedged blob
27
+ * backend costs the run its images (stated to the agent) instead of costing it the run.
28
+ *
29
+ * Bounds ONE pass, and a job with both manifests runs two. That is deliberate: the alternative is a
30
+ * shared budget in which whichever manifest is delivered first can starve the other, which would
31
+ * make a capture's references depend on how many design pictures the same task happens to hold.
32
+ */
33
+ const TOTAL_BUDGET_MS = 90_000;
34
+ /** How many images are fetched at once. Small on purpose: this is a shared blob backend. */
35
+ const CONCURRENCY = 4;
36
+ /** The cause reported for a view the backend resolved but never sent this job a file for. */
37
+ const OMITTED_REASON = 'not sent to this container (image limit)';
38
+ /**
39
+ * Download a manifest's images into `<checkout>/.cat-context/<subdir>/` and report what landed.
40
+ *
41
+ * IDEMPOTENT, and that is load-bearing rather than an optimisation: an agent flow re-enters its
42
+ * workspace once per repair round, so this pass runs several times over one checkout. A file
43
+ * already on disk is counted and never re-fetched, which keeps a later round from spending the
44
+ * budget again AND from reporting an image as absent that pass 1 successfully delivered. A view
45
+ * that MISSED is retried, since the next round is a fresh chance at whatever was transiently down.
46
+ *
47
+ * Never throws: images are an aid, not a precondition for running, so a backend outage degrades the
48
+ * run to its textual context rather than failing it. Every miss is carried out on
49
+ * {@link ContextImageOutcome.missing} so the caller can say so in the prompt, which is the
50
+ * difference between an image the platform failed to hand over and a screen that does not exist.
51
+ */
52
+ export async function materializeContextImages(cwd, subdir, spec, options = {}) {
53
+ const dir = join(cwd, CONTEXT_DIR, subdir);
54
+ const outcome = {
55
+ written: [],
56
+ // The backend's own dropped views are missing before a single byte is fetched, and for a cause
57
+ // no transfer could have changed.
58
+ missing: spec.omitted.map((view) => ({ view, reason: OMITTED_REASON })),
59
+ dir: `${CONTEXT_DIR}/${subdir}`,
60
+ };
61
+ try {
62
+ await mkdir(dir, { recursive: true });
63
+ }
64
+ catch (error) {
65
+ // Nowhere to write: report every image as missed rather than half of them, since none of them
66
+ // can land and the cause is the same for all.
67
+ for (const file of spec.files)
68
+ outcome.missing.push({ view: file.view, reason: describe(error) });
69
+ return sortByManifest(outcome, spec);
70
+ }
71
+ const deadline = Date.now() + TOTAL_BUDGET_MS;
72
+ const queue = [...spec.files];
73
+ const workers = Array.from({ length: Math.min(CONCURRENCY, queue.length) }, async () => {
74
+ for (;;) {
75
+ const file = queue.shift();
76
+ if (!file)
77
+ return;
78
+ // An earlier pass over this same checkout already delivered it. Checked before the budget so
79
+ // a fully-delivered set costs one stat per file and no network at all, however long an
80
+ // earlier round took.
81
+ if (await alreadyOnDisk(dir, file.fileName)) {
82
+ outcome.written.push({ fileName: file.fileName, view: file.view });
83
+ continue;
84
+ }
85
+ if (Date.now() >= deadline) {
86
+ outcome.missing.push({ view: file.view, reason: 'image download budget exhausted' });
87
+ continue;
88
+ }
89
+ const failure = await downloadOne(dir, spec, file, options);
90
+ if (failure)
91
+ outcome.missing.push({ view: file.view, reason: failure });
92
+ else
93
+ outcome.written.push({ fileName: file.fileName, view: file.view });
94
+ }
95
+ });
96
+ await Promise.all(workers);
97
+ // Even a partial set must not reach the agent's PR (same rule as every other context file).
98
+ await excludeContextDir(cwd);
99
+ return sortByManifest(outcome, spec);
100
+ }
101
+ /**
102
+ * Order both lists the way the BACKEND composed the set (its own gallery order) rather than the
103
+ * order the transfers happened to finish in, so the list the agent reads is stable across rounds.
104
+ * The dropped views trail the sent ones, having no position in the manifest to sort by.
105
+ */
106
+ function sortByManifest(outcome, spec) {
107
+ const rank = new Map(spec.files.map((file, index) => [file.view, index]));
108
+ const at = (view) => rank.get(view) ?? Number.MAX_SAFE_INTEGER;
109
+ outcome.written.sort((a, b) => at(a.view) - at(b.view));
110
+ outcome.missing.sort((a, b) => at(a.view) - at(b.view));
111
+ return outcome;
112
+ }
113
+ /**
114
+ * Whether a previous pass over this checkout already wrote this image.
115
+ *
116
+ * Non-empty is the test, not mere existence: a zero-length file is what a half-written transfer
117
+ * leaves behind, and treating it as delivered would hand the agent a blank image it reads as a
118
+ * design with nothing on the screen (the same case {@link downloadOne} refuses to write).
119
+ */
120
+ async function alreadyOnDisk(dir, fileName) {
121
+ try {
122
+ return (await stat(join(dir, fileName))).size > 0;
123
+ }
124
+ catch {
125
+ // silent-catch-ok: absence is the ordinary answer here (first pass over the checkout), and any
126
+ // other stat failure is answered the same way — by attempting the download.
127
+ return false;
128
+ }
129
+ }
130
+ /** Fetch and write one image, answering a failure reason or undefined on success. */
131
+ async function downloadOne(dir, spec, file, options) {
132
+ const fetchImpl = options.fetchImpl ?? fetch;
133
+ const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
134
+ const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
135
+ try {
136
+ const response = await fetchImpl(`${spec.url}/${encodeURIComponent(file.artifactId)}`, {
137
+ headers: { authorization: `Bearer ${spec.token}` },
138
+ signal,
139
+ });
140
+ if (!response.ok)
141
+ return `HTTP ${response.status}`;
142
+ const bytes = await readBounded(response, MAX_IMAGE_BYTES);
143
+ if (bytes === 'too-large')
144
+ return 'image exceeds size limit';
145
+ // A zero-length body is a miss, not a file: written out it would be an image the agent opens,
146
+ // finds empty, and reads as a design with nothing on the screen.
147
+ if (!bytes.byteLength)
148
+ return 'empty response';
149
+ await writeFile(join(dir, file.fileName), bytes);
150
+ return undefined;
151
+ }
152
+ catch (error) {
153
+ return describe(error);
154
+ }
155
+ }
156
+ /**
157
+ * Read a response body, refusing one that goes past `limit` WITHOUT buffering all of it first.
158
+ *
159
+ * The ceiling has to bound the transfer and not just the write. Buffering the whole body and then
160
+ * measuring it means an oversized (or endless) response is already resident, times the pass's
161
+ * concurrency, by the time it is rejected — which is the container's memory, in a run whose whole
162
+ * point is that it has not started working yet. So the declared length is refused up front where
163
+ * it is honest, and the stream is counted as it arrives and cancelled the moment it crosses the
164
+ * line, which is what makes a chunked or lying body cost no more than a truthful one.
165
+ */
166
+ async function readBounded(response, limit) {
167
+ const declared = Number(response.headers.get('content-length'));
168
+ if (Number.isFinite(declared) && declared > limit)
169
+ return 'too-large';
170
+ const body = response.body;
171
+ if (!body) {
172
+ // No stream to count (a mocked or already-buffered response): fall back to measuring after the
173
+ // fact, which is sound because there is nothing left to stop arriving.
174
+ const bytes = new Uint8Array(await response.arrayBuffer());
175
+ return bytes.byteLength > limit ? 'too-large' : bytes;
176
+ }
177
+ const reader = body.getReader();
178
+ const chunks = [];
179
+ let total = 0;
180
+ try {
181
+ for (;;) {
182
+ const { done, value } = await reader.read();
183
+ if (done)
184
+ break;
185
+ total += value.byteLength;
186
+ if (total > limit) {
187
+ await reader.cancel();
188
+ return 'too-large';
189
+ }
190
+ chunks.push(value);
191
+ }
192
+ }
193
+ finally {
194
+ reader.releaseLock();
195
+ }
196
+ const bytes = new Uint8Array(total);
197
+ let offset = 0;
198
+ for (const chunk of chunks) {
199
+ bytes.set(chunk, offset);
200
+ offset += chunk.byteLength;
201
+ }
202
+ return bytes;
203
+ }
204
+ /** A one-line cause for a failed transfer (never the token, which only rides a header). */
205
+ function describe(error) {
206
+ return error instanceof Error ? error.message : String(error);
207
+ }
@@ -25,12 +25,12 @@ export interface ContextFileSpec {
25
25
  * container would let a harness image the deployment has not rolled out yet rename every view a
26
26
  * run reports, and the pairing would come apart with nothing failing.
27
27
  */
28
- export interface ReferenceScreenshotsSpec {
28
+ export interface ImageManifestSpec {
29
29
  /** Base URL of the reference download route; the artifact id is appended as a path segment. */
30
30
  url: string;
31
31
  /** The run's container session token (the same one the LLM proxy is called with). */
32
32
  token: string;
33
- files: ReferenceScreenshotSpec[];
33
+ files: ImageFileSpec[];
34
34
  /**
35
35
  * View names the task holds a reference for that this job was NOT sent a file for, because the
36
36
  * set was capped. Stated to the agent beside the transfers that failed: from where it stands
@@ -43,8 +43,8 @@ export interface ReferenceScreenshotsSpec {
43
43
  */
44
44
  omitted: string[];
45
45
  }
46
- /** One reference image in a {@link ReferenceScreenshotsSpec}. `fileName` is sanitised on parse. */
47
- export interface ReferenceScreenshotSpec {
46
+ /** One reference image in a {@link ImageManifestSpec}. `fileName` is sanitised on parse. */
47
+ export interface ImageFileSpec {
48
48
  artifactId: string;
49
49
  fileName: string;
50
50
  view: string;
@@ -58,12 +58,14 @@ export declare function sanitizeContextFileName(value: unknown): string | undefi
58
58
  /** Parse the linked-context files, dropping any malformed/unsafe entry. */
59
59
  export declare function parseContextFiles(value: unknown): ContextFileSpec[];
60
60
  /**
61
- * Parse the reference-design manifest, or undefined when absent/unusable.
61
+ * Parse one image manifest (the capture set or the design pictures), or undefined when
62
+ * absent/unusable.
62
63
  *
63
- * The whole manifest is dropped when its transport half is unusable (no absolute http(s) URL, no
64
- * token): every file would fail the same way, and one stated cause beats N identical ones. An
65
- * individual entry is dropped only when it cannot name a file safely: the same basename
66
- * sanitisation every context file gets, so a hostile `fileName` can neither escape the directory
67
- * nor clobber a repo file.
64
+ * ONE parser for both, because the wire shape and every rule over it are the same: only the job
65
+ * body FIELD and what the harness does with the files afterwards differ. The whole manifest is
66
+ * dropped when its transport half is unusable (no absolute http(s) URL, no token): every file
67
+ * would fail the same way, and one stated cause beats N identical ones. An individual entry is
68
+ * dropped only when it cannot name a file safely: the same basename sanitisation every context
69
+ * file gets, so a hostile `fileName` can neither escape the directory nor clobber a repo file.
68
70
  */
69
- export declare function parseReferenceScreenshots(value: unknown): ReferenceScreenshotsSpec | undefined;
71
+ export declare function parseImageManifest(value: unknown): ImageManifestSpec | undefined;
@@ -48,26 +48,33 @@ export function parseContextFiles(value) {
48
48
  return files;
49
49
  }
50
50
  /**
51
- * How many reference images one job may be handed. The backend caps the set it sends well below
52
- * this, so this is the harness's own backstop against a malformed or hostile body turning the
53
- * pre-run setup into an unbounded download, never the ceiling a real run meets.
51
+ * How many images one job may be handed PER MANIFEST. The backend caps each set it sends well
52
+ * below this, so this is the harness's own backstop against a malformed or hostile body turning
53
+ * the pre-run setup into an unbounded download, never the ceiling a real run meets.
54
+ *
55
+ * One number for both manifests on purpose: the two real ceilings are the BACKEND's, chosen where
56
+ * the reason for each is known (transfer time for a capture, input tokens for an attachment). A
57
+ * second backstop here would only encode those reasons a second time, in the one place that
58
+ * cannot see either.
54
59
  *
55
60
  * Hitting it is REPORTED rather than silently obeyed: an entry past the ceiling is dropped from
56
61
  * `files` and its view named on `omitted`, so an agent facing a truncated set is still told which
57
- * views to capture. A cap that shortened the list and said nothing would be indistinguishable, on
58
- * disk and in the prompt, from a design that simply has no such screen.
62
+ * views it is not being shown. A cap that shortened the list and said nothing would be
63
+ * indistinguishable, on disk and in the prompt, from a design that simply has no such screen.
59
64
  */
60
- const MAX_REFERENCE_SCREENSHOTS = 40;
65
+ const MAX_MANIFEST_IMAGES = 40;
61
66
  /**
62
- * Parse the reference-design manifest, or undefined when absent/unusable.
67
+ * Parse one image manifest (the capture set or the design pictures), or undefined when
68
+ * absent/unusable.
63
69
  *
64
- * The whole manifest is dropped when its transport half is unusable (no absolute http(s) URL, no
65
- * token): every file would fail the same way, and one stated cause beats N identical ones. An
66
- * individual entry is dropped only when it cannot name a file safely: the same basename
67
- * sanitisation every context file gets, so a hostile `fileName` can neither escape the directory
68
- * nor clobber a repo file.
70
+ * ONE parser for both, because the wire shape and every rule over it are the same: only the job
71
+ * body FIELD and what the harness does with the files afterwards differ. The whole manifest is
72
+ * dropped when its transport half is unusable (no absolute http(s) URL, no token): every file
73
+ * would fail the same way, and one stated cause beats N identical ones. An individual entry is
74
+ * dropped only when it cannot name a file safely: the same basename sanitisation every context
75
+ * file gets, so a hostile `fileName` can neither escape the directory nor clobber a repo file.
69
76
  */
70
- export function parseReferenceScreenshots(value) {
77
+ export function parseImageManifest(value) {
71
78
  if (typeof value !== 'object' || value === null)
72
79
  return undefined;
73
80
  const o = value;
@@ -97,7 +104,7 @@ export function parseReferenceScreenshots(value) {
97
104
  // Past the backstop the entry is NAMED, not dropped: it stays a view the agent must capture.
98
105
  // Checked here rather than at the top of the loop so a malformed entry is refused on its own
99
106
  // terms (it names no usable view to report) instead of being counted against the ceiling.
100
- if (files.length >= MAX_REFERENCE_SCREENSHOTS) {
107
+ if (files.length >= MAX_MANIFEST_IMAGES) {
101
108
  omitted.push(view);
102
109
  continue;
103
110
  }
@@ -0,0 +1,40 @@
1
+ import type { ImageManifestSpec } from './job.js';
2
+ import type { Logger } from './logger.js';
3
+ import { type ContextImageOutcome } from './context-images.js';
4
+ /** Subdirectory of {@link CONTEXT_DIR} the design pictures are written to. */
5
+ export declare const DESIGN_RENDER_SUBDIR = "design-renders";
6
+ /** The relative directory the design pictures are written to (what the prompt names). */
7
+ export declare const DESIGN_RENDER_DIR = ".cat-context/design-renders";
8
+ /** Download this job's design pictures. See {@link materializeContextImages}. */
9
+ export declare function materializeDesignImages(cwd: string, spec: ImageManifestSpec, options?: {
10
+ signal?: AbortSignal;
11
+ fetchImpl?: typeof fetch;
12
+ }): Promise<ContextImageOutcome>;
13
+ /**
14
+ * Download the design pictures and answer the CORRECTION to the prompt's own list, or '' when
15
+ * everything the backend named is on disk.
16
+ *
17
+ * Silence on success is the difference from the capture delivery, and it is deliberate. The
18
+ * backend's prompt already names every picture and its view, because it is the side that knows
19
+ * which views exist and how they were delivered; repeating the list here would give the agent two
20
+ * lists of the same files, differing only when something went wrong, with nothing saying which one
21
+ * is current.
22
+ *
23
+ * So this speaks only when the container's truth DIVERGES from what the prompt promised. That
24
+ * divergence has to be stated: an agent told to open a file that is not there re-reads the path,
25
+ * lists the directory and eventually decides the design is missing something, when the honest
26
+ * answer is that this one picture did not transfer and the rest are exactly as described.
27
+ */
28
+ export declare function deliverDesignImages(cwd: string, spec: ImageManifestSpec | undefined, options: {
29
+ signal?: AbortSignal;
30
+ log: Logger;
31
+ fetchImpl?: typeof fetch;
32
+ }): Promise<string>;
33
+ /**
34
+ * The prompt correction: the views whose picture is NOT in this container, with the cause.
35
+ *
36
+ * Empty whenever the transfer matched the prompt, including the case where the manifest was empty
37
+ * to begin with. The agent is told to carry on from the textual design description rather than to
38
+ * ask for the file, because nothing in the run can deliver it after this point.
39
+ */
40
+ export declare function designImageGuidance(outcome: ContextImageOutcome): string;
@@ -0,0 +1,68 @@
1
+ import { CONTEXT_DIR } from './pi.js';
2
+ import { materializeContextImages } from './context-images.js';
3
+ // ---------------------------------------------------------------------------
4
+ // DESIGN PICTURES on disk for a BUILDING kind: what the screen is supposed to look like, in
5
+ // `.cat-context/design-renders/`, for an agent CLI that can read an image into its turn.
6
+ //
7
+ // The other use of the same artifacts the capture path delivers, and the reason each has its own
8
+ // directory: a tester reading these six would take them for the complete list of views to capture,
9
+ // and a builder reading the tester's twenty-four would spend its context on screens it was never
10
+ // asked to touch.
11
+ //
12
+ // The agent is told about these files by the BACKEND's prompt, which is the half that knows which
13
+ // views the platform holds and whether this model can be shown them at all. What this module adds
14
+ // is the container's own half of the truth: which of those files actually landed here.
15
+ // ---------------------------------------------------------------------------
16
+ /** Subdirectory of {@link CONTEXT_DIR} the design pictures are written to. */
17
+ export const DESIGN_RENDER_SUBDIR = 'design-renders';
18
+ /** The relative directory the design pictures are written to (what the prompt names). */
19
+ export const DESIGN_RENDER_DIR = `${CONTEXT_DIR}/${DESIGN_RENDER_SUBDIR}`;
20
+ /** Download this job's design pictures. See {@link materializeContextImages}. */
21
+ export function materializeDesignImages(cwd, spec, options = {}) {
22
+ return materializeContextImages(cwd, DESIGN_RENDER_SUBDIR, spec, options);
23
+ }
24
+ /**
25
+ * Download the design pictures and answer the CORRECTION to the prompt's own list, or '' when
26
+ * everything the backend named is on disk.
27
+ *
28
+ * Silence on success is the difference from the capture delivery, and it is deliberate. The
29
+ * backend's prompt already names every picture and its view, because it is the side that knows
30
+ * which views exist and how they were delivered; repeating the list here would give the agent two
31
+ * lists of the same files, differing only when something went wrong, with nothing saying which one
32
+ * is current.
33
+ *
34
+ * So this speaks only when the container's truth DIVERGES from what the prompt promised. That
35
+ * divergence has to be stated: an agent told to open a file that is not there re-reads the path,
36
+ * lists the directory and eventually decides the design is missing something, when the honest
37
+ * answer is that this one picture did not transfer and the rest are exactly as described.
38
+ */
39
+ export async function deliverDesignImages(cwd, spec, options) {
40
+ if (!spec)
41
+ return '';
42
+ const outcome = await materializeDesignImages(cwd, spec, options);
43
+ if (outcome.missing.length) {
44
+ options.log.warn('agent: some design pictures are not on disk', {
45
+ written: outcome.written.length,
46
+ missing: outcome.missing.length,
47
+ reasons: outcome.missing.map((file) => file.reason).slice(0, 5),
48
+ });
49
+ }
50
+ return designImageGuidance(outcome);
51
+ }
52
+ /**
53
+ * The prompt correction: the views whose picture is NOT in this container, with the cause.
54
+ *
55
+ * Empty whenever the transfer matched the prompt, including the case where the manifest was empty
56
+ * to begin with. The agent is told to carry on from the textual design description rather than to
57
+ * ask for the file, because nothing in the run can deliver it after this point.
58
+ */
59
+ export function designImageGuidance(outcome) {
60
+ if (!outcome.missing.length)
61
+ return '';
62
+ return `
63
+
64
+ ## Design pictures: correction
65
+ These views were listed above as pictures, and are NOT in this container. Work from the textual
66
+ design description for them; there is nothing to open and nothing that can fetch them now:
67
+ ${outcome.missing.map((file) => `- ${file.view}: NOT on disk (${file.reason})`).join('\n')}`;
68
+ }
@@ -0,0 +1,28 @@
1
+ import type { ImageManifestSpec } from './job.js';
2
+ import type { Logger } from './logger.js';
3
+ /** The manifests a job may carry, as they sit on any agent-running spec. */
4
+ export interface JobImageSpecs {
5
+ referenceScreenshots?: ImageManifestSpec;
6
+ designImages?: ImageManifestSpec;
7
+ }
8
+ /**
9
+ * Deliver both manifests into the checkout and answer the prompt text they contribute.
10
+ *
11
+ * The two blocks are CONCATENATED rather than kept apart because they say the same kind of thing
12
+ * (what this container actually holds, against what the run was told it would), and the agent reads
13
+ * one context. Either half is empty when its manifest is absent or when nothing needs saying, so a
14
+ * job with one manifest is byte-identical to what it produced before the other existed.
15
+ *
16
+ * Runs once per PASS, not once per job: a coding flow re-enters its workspace for every repair
17
+ * round. That is safe because each delivery is idempotent over the checkout (a file already on disk
18
+ * is counted, never re-fetched), so a later round costs a stat per image and cannot report a view an
19
+ * earlier round successfully delivered as absent. A view that MISSED is retried, which is the
20
+ * behaviour worth having: the next round is a fresh chance at a blob backend that was briefly down.
21
+ */
22
+ export declare function deliverJobImages(spec: JobImageSpecs & {
23
+ dir: string;
24
+ }, options: {
25
+ signal?: AbortSignal;
26
+ log: Logger;
27
+ fetchImpl?: typeof fetch;
28
+ }): Promise<string>;
@@ -0,0 +1,21 @@
1
+ import { deliverDesignImages } from './design-images.js';
2
+ import { deliverReferenceScreenshots } from './reference-screenshots.js';
3
+ /**
4
+ * Deliver both manifests into the checkout and answer the prompt text they contribute.
5
+ *
6
+ * The two blocks are CONCATENATED rather than kept apart because they say the same kind of thing
7
+ * (what this container actually holds, against what the run was told it would), and the agent reads
8
+ * one context. Either half is empty when its manifest is absent or when nothing needs saying, so a
9
+ * job with one manifest is byte-identical to what it produced before the other existed.
10
+ *
11
+ * Runs once per PASS, not once per job: a coding flow re-enters its workspace for every repair
12
+ * round. That is safe because each delivery is idempotent over the checkout (a file already on disk
13
+ * is counted, never re-fetched), so a later round costs a stat per image and cannot report a view an
14
+ * earlier round successfully delivered as absent. A view that MISSED is retried, which is the
15
+ * behaviour worth having: the next round is a fresh chance at a blob backend that was briefly down.
16
+ */
17
+ export async function deliverJobImages(spec, options) {
18
+ const references = await deliverReferenceScreenshots(spec.dir, spec.referenceScreenshots, options);
19
+ const designs = await deliverDesignImages(spec.dir, spec.designImages, options);
20
+ return `${references}${designs}`;
21
+ }
package/dist/job.d.ts CHANGED
@@ -8,10 +8,10 @@ import { type ReproductionReport, type ReproductionSpec } from './reproduction-p
8
8
  import { type DependencyInstallSpec } from './dependency-install.js';
9
9
  import { type McpServerSpec, type SkillResourceSpec, type SkillSpec } from './agent-capabilities.js';
10
10
  import { type TestSecretSpec } from './job-env.js';
11
- import { type ContextFileSpec, type ReferenceScreenshotSpec, type ReferenceScreenshotsSpec } from './context-manifests.js';
11
+ import { type ContextFileSpec, type ImageFileSpec, type ImageManifestSpec } from './context-manifests.js';
12
12
  export type { TestSecretSpec };
13
13
  export type { McpServerSpec, SkillResourceSpec, SkillSpec };
14
- export type { ContextFileSpec, ReferenceScreenshotSpec, ReferenceScreenshotsSpec };
14
+ export type { ContextFileSpec, ImageFileSpec, ImageManifestSpec };
15
15
  /**
16
16
  * Per-job auth fields, shared across every job shape. The Pi harness carries the
17
17
  * proxy base URL + a model-locked session token; the subscription harnesses
@@ -86,8 +86,13 @@ export interface PrSpec {
86
86
  */
87
87
  export interface PeerRepoSpec {
88
88
  repo: RepoSpec;
89
- /** The involved service frame this repo resolved from, echoed back on the peer PR. */
90
- frameId?: string;
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
@@ -320,11 +325,23 @@ export interface AgentJob extends HarnessAuthFields {
320
325
  contextFiles?: ContextFileSpec[];
321
326
  /**
322
327
  * The task's reference design images, downloaded into `.cat-context/reference-screenshots/`
323
- * before the agent runs (see {@link ReferenceScreenshotsSpec}). Sent only for a kind that
328
+ * before the agent runs (see {@link ImageManifestSpec}). Sent only for a kind that
324
329
  * CAPTURES views and only when the task actually has references, so absent is the normal case
325
330
  * and means the agent names its own views.
326
331
  */
327
- referenceScreenshots?: ReferenceScreenshotsSpec;
332
+ referenceScreenshots?: ImageManifestSpec;
333
+ /**
334
+ * The PICTURES of the task's designs, for a kind that builds or plans a screen. Downloaded into
335
+ * `.cat-context/design-renders/` before the run; the agent's prompt (composed by the backend)
336
+ * names each file and its view, and the agent opens them with its own image-reading tool.
337
+ *
338
+ * The same wire shape and the same download seam as {@link AgentJob.referenceScreenshots}, and a
339
+ * separate field with a separate directory because the two are opposite instructions: that one
340
+ * names the views to CAPTURE, this one is the design to BUILD. Sent only when the backend
341
+ * decided this harness can read an image at all, so absent is the normal case and means the run
342
+ * works from the textual design description (its prompt says which).
343
+ */
344
+ designImages?: ImageManifestSpec;
328
345
  /**
329
346
  * Private package-registry auth (npm private orgs, GitHub Packages), rendered into
330
347
  * `~/.npmrc` before the run so the checkout's installs — the agent's own and the
@@ -581,10 +598,14 @@ export interface AgentResult {
581
598
  * repo the run actually changed (service-connections phase 3). Beside the own-service
582
599
  * `prUrl`/`branch`; the backend lifts these onto the block's `peerPullRequests`. Absent for
583
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.
584
605
  */
585
606
  peerPullRequests?: {
586
607
  repo: string;
587
- frameId?: string;
608
+ frameIds?: string[];
588
609
  prUrl: string;
589
610
  branch: string;
590
611
  }[];
package/dist/job.js CHANGED
@@ -3,7 +3,7 @@ import { parseReproductionSpec, } from './reproduction-proof.js';
3
3
  import { parseDependencyInstallSpec } from './dependency-install.js';
4
4
  import { parseMcpServerSpecs, parseSkillSpecs, } from './agent-capabilities.js';
5
5
  import { parseInfraEnv, parseSecretEnvPairs, str } from './job-env.js';
6
- import { parseContextFiles, parseReferenceScreenshots, } from './context-manifests.js';
6
+ import { parseContextFiles, parseImageManifest, } from './context-manifests.js';
7
7
  /** A positive finite integer, or undefined for any other input (silently ignored). */
8
8
  function posInt(value) {
9
9
  return typeof value === 'number' && Number.isFinite(value) && value > 0
@@ -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 (typeof e.frameId === 'string' && e.frameId)
173
- spec.frameId = e.frameId;
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) {
@@ -478,7 +481,8 @@ export function parseAgentJob(input) {
478
481
  referenceBranches: parseReferenceBranches(o.referenceBranches),
479
482
  bootstrap: parseAgentBootstrapSpec(o.bootstrap),
480
483
  contextFiles: parseContextFiles(o.contextFiles),
481
- referenceScreenshots: parseReferenceScreenshots(o.referenceScreenshots),
484
+ referenceScreenshots: parseImageManifest(o.referenceScreenshots),
485
+ designImages: parseImageManifest(o.designImages),
482
486
  packageRegistries: parsePackageRegistries(o.packageRegistries),
483
487
  skills: parseSkillSpecs(o.skills),
484
488
  mcpServers: parseMcpServerSpecs(o.mcpServers),
@@ -545,7 +549,7 @@ function parseAgentPrSpec(raw) {
545
549
  * literal doesn't blow the complexity budget; behaviour is byte-identical (spread order preserved).
546
550
  */
547
551
  function assembleAgentJob(o, mode, agentField, parts) {
548
- const { output, pr, infra, peerRepos, referenceRepos, referenceBranches, bootstrap, contextFiles, referenceScreenshots, packageRegistries, skills, mcpServers, testSecrets, guardLimits, validation, validationChecks, reproduction, dependencyInstall, reviewPrNumber, generatorSecrets, } = parts;
552
+ const { output, pr, infra, peerRepos, referenceRepos, referenceBranches, bootstrap, contextFiles, referenceScreenshots, designImages, packageRegistries, skills, mcpServers, testSecrets, guardLimits, validation, validationChecks, reproduction, dependencyInstall, reviewPrNumber, generatorSecrets, } = parts;
549
553
  const repo = (o.repo ?? {});
550
554
  return {
551
555
  jobId: str(o.jobId, 'jobId'),
@@ -562,6 +566,7 @@ function assembleAgentJob(o, mode, agentField, parts) {
562
566
  ...(output ? { output } : {}),
563
567
  ...(contextFiles.length ? { contextFiles } : {}),
564
568
  ...(referenceScreenshots ? { referenceScreenshots } : {}),
569
+ ...(designImages ? { designImages } : {}),
565
570
  ...(packageRegistries.length ? { packageRegistries } : {}),
566
571
  ...(skills ? { skills } : {}),
567
572
  ...(mcpServers ? { mcpServers } : {}),
@@ -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>;