@cat-factory/executor-harness 1.102.0 → 1.104.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 +27 -0
- package/dist/agent-shared.d.ts +7 -5
- package/dist/agent-shared.js +6 -4
- package/dist/coding-agent.d.ts +9 -1
- package/dist/coding-agent.js +4 -0
- package/dist/context-manifests.d.ts +69 -0
- package/dist/context-manifests.js +110 -0
- package/dist/job.d.ts +9 -12
- package/dist/job.js +4 -40
- package/dist/pi-workspace.d.ts +7 -1
- package/dist/pi-workspace.js +18 -1
- package/dist/pi.d.ts +20 -0
- package/dist/pi.js +21 -13
- package/dist/reference-screenshots.d.ts +71 -0
- package/dist/reference-screenshots.js +261 -0
- package/package.json +4 -4
- package/src/agent-shared.ts +14 -5
- package/src/coding-agent.ts +13 -0
- package/src/context-manifests.ts +156 -0
- package/src/job.ts +22 -48
- package/src/pi-workspace.ts +25 -2
- package/src/pi.ts +29 -11
- package/src/reference-screenshots.ts +295 -0
package/README.md
CHANGED
|
@@ -115,6 +115,31 @@ Bootstrap differs at the ends: it may start from an empty dir, and **resets
|
|
|
115
115
|
history to one commit and force-pushes** the default branch instead of opening a
|
|
116
116
|
PR. Blueprint **commits onto a branch** (no history reset) and returns the tree.
|
|
117
117
|
|
|
118
|
+
### Reference designs
|
|
119
|
+
|
|
120
|
+
A job body for a kind that CAPTURES views (the UI tester, or a deployment's own browser-driven kind)
|
|
121
|
+
may carry `referenceScreenshots`: the reference images the platform holds for the task, as
|
|
122
|
+
`{ url, token, files: [{ artifactId, fileName, view }], omitted: [view] }`. The harness downloads
|
|
123
|
+
each into `.cat-context/reference-screenshots/` before the agent's first turn and lists them, by view
|
|
124
|
+
name, at the end of the agent's context.
|
|
125
|
+
|
|
126
|
+
Only identities travel in the body (a design frame is a full-page PNG), and the bytes come back
|
|
127
|
+
from the backend over the SAME container session token the run already holds for the LLM proxy, so
|
|
128
|
+
this needs no extra credential. The FILE NAMES are the backend's, never derived here: the name is
|
|
129
|
+
how the agent learns the view name, and the platform pairs its capture against that name later.
|
|
130
|
+
|
|
131
|
+
`omitted` carries the views the backend's cap dropped. They are stated to the agent beside the
|
|
132
|
+
transfers that failed, since from where it stands both are a view to capture with nothing to compare
|
|
133
|
+
against. This parser keeps a higher backstop of its own against a body claiming more files than any
|
|
134
|
+
real set has, and an entry past it joins `omitted` rather than vanishing: a cap that shortened the
|
|
135
|
+
list and said nothing would be indistinguishable, on disk and in the prompt, from a design that has
|
|
136
|
+
no such screen.
|
|
137
|
+
|
|
138
|
+
The pass is IDEMPOTENT over the checkout, which matters because a coding flow re-enters its
|
|
139
|
+
workspace once per repair round: a non-empty file already on disk is counted and never re-fetched,
|
|
140
|
+
and only a view that MISSED is retried. The per-image ceiling is enforced against the declared
|
|
141
|
+
length and against the stream as it arrives, so an oversized body is refused rather than buffered.
|
|
142
|
+
|
|
118
143
|
### Skills and tool servers
|
|
119
144
|
|
|
120
145
|
A job body may carry `skills[]` (procedural playbooks) and `mcpServers[]` (MCP tool servers): the
|
|
@@ -213,6 +238,7 @@ Kimi / DeepSeek) and meters spend. The provider key never enters the container.
|
|
|
213
238
|
| `src/runner.ts` | `JobRegistry`: async job lifecycle, idempotent on `jobId`, progress tracking, and the three per-job watchdogs (max-duration, inactivity, tool-silence). |
|
|
214
239
|
| `src/jsonl-stream.ts` | The BOUNDS on a child CLI's streams, shared by both runners: `JsonlLineReader` frames its JSONL stdout while refusing to buffer a runaway record, `BoundedTail` keeps a capped tail of raw output for failure quoting. Both watchdog timers and the poll endpoints share one event loop with this parsing, so an unbounded buffer here is how a container stops answering polls with no watchdog having fired. |
|
|
215
240
|
| `src/job.ts` | Request types + validators for the job specs. |
|
|
241
|
+
| `src/context-manifests.ts` | The two manifests of FILES the backend stages into the checkout: the linked-context documents and the reference design images. Their shapes plus the defensive parse of each, sharing the basename rule that keeps a body-supplied name from escaping the directory or clobbering a repo file. Both stay job body fields, so `job.ts` remains the import site. |
|
|
216
242
|
| `src/pi.ts` | Pi provider config, non-interactive run, JSON-line event + todo-progress parsing, global `AGENTS.md` guidance. |
|
|
217
243
|
| `src/pi-reduction.ts` | Reducing a Pi event stream to what the run PRODUCED (summary, stats, diagnostics, terminal failure), FOLDED as records stream rather than over a retained array — memory is O(largest record), not O(records). The array-taking entry points offline tooling uses are defined in terms of the same reducer. |
|
|
218
244
|
| `src/tool-silence.ts` | The tool-silence watchdog (F13) and the `ToolProgressWindow` an agent stream opens, beats and closes. Separate from the phase marker on purpose: a window is only meaningful while something able to reset it is running. |
|
|
@@ -229,6 +255,7 @@ Kimi / DeepSeek) and meters spend. The provider key never enters the container.
|
|
|
229
255
|
| `src/validation-checks.ts` | Pre-PR validation: runs the job's check commands in the checkout (bounded, secret-scrubbed capture, per-command watchdog) and drives the retry-until-green loop that gates the PR. Generic: keyed off the job body, never the agent kind. |
|
|
230
256
|
| `src/reproduction-proof.ts` | Bugfix reproduction proof: runs the job's declared reproduction command against two symmetric fresh worktrees (the pre-fix tree and the final tree) and computes red-then-green from the exit codes, with a repair loop that never fails the run. Generic: keyed off the job body, never the agent kind. |
|
|
231
257
|
| `src/agent-capabilities.ts` | The agent CAPABILITIES a job body carries: the run's `skills` (a `SKILL.md` payload + resources) and its `mcpServers` (tool servers): with their defensive parsing and the per-CLI config writers (`--mcp-config` JSON for claude-code, `[mcp_servers.*]` TOML for Codex). Backend-authored data the harness only MATERIALISES: adding a skill or a tool server is a backend registration, never a harness change. |
|
|
258
|
+
| `src/reference-screenshots.ts` | The task's REFERENCE DESIGN images: downloads the manifest a capturing job body carries into `.cat-context/reference-screenshots/` (on the run's own container session token) and composes the prompt block naming each file's view. Best-effort, time-bounded and IDEMPOTENT over the checkout, so a repair round re-costs a stat rather than a transfer. A reference that is not on disk is NAMED to the agent, whether a transfer failed or the backend's cap dropped the view, because on disk an absent file and a screen the design does not have are the same thing. Backend-authored throughout, including the file names. |
|
|
232
259
|
| `src/bootstrap-mode.ts` | The repo-bootstrap MODE: clone-a-reference-or-scaffold → run the agent → refuse to push an empty tree → reinit + force-push to the pre-created target repo. |
|
|
233
260
|
| `src/agent-shared.ts` | The few helpers every agent MODE shares (effort-report folding, the capability fields forwarded to `runAgentInWorkspace`). |
|
|
234
261
|
| `src/logger.ts` | Structured logging. |
|
package/dist/agent-shared.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentJob, AgentResult, McpServerSpec, SkillSpec } from './job.js';
|
|
1
|
+
import type { AgentJob, AgentResult, McpServerSpec, ReferenceScreenshotsSpec, SkillSpec } from './job.js';
|
|
2
2
|
import type { EffortReport } from './effort.js';
|
|
3
3
|
/**
|
|
4
4
|
* Fold an agent's effort self-assessment (lifted from its sentinel file by `runAgentInWorkspace`)
|
|
@@ -7,12 +7,14 @@ import type { EffortReport } from './effort.js';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function mergeEffort(result: AgentResult, effortReport: EffortReport | undefined): AgentResult;
|
|
9
9
|
/**
|
|
10
|
-
* The agent-capability fields (skills
|
|
11
|
-
* {@link runAgentInWorkspace}. One helper rather than a per-flow spread, so a flow
|
|
12
|
-
* be the one that drops a kind's declared playbook
|
|
13
|
-
* (the agent simply works without it) and would only show
|
|
10
|
+
* The agent-capability fields (skills, tool servers, reference designs) every agent-running flow
|
|
11
|
+
* forwards to {@link runAgentInWorkspace}. One helper rather than a per-flow spread, so a flow
|
|
12
|
+
* cannot silently be the one that drops a kind's declared playbook, tool server or reference
|
|
13
|
+
* gallery: the failure mode is invisible (the agent simply works without it) and would only show
|
|
14
|
+
* up as degraded output.
|
|
14
15
|
*/
|
|
15
16
|
export declare function agentCapabilities(job: AgentJob): {
|
|
16
17
|
skills?: SkillSpec[];
|
|
17
18
|
mcpServers?: McpServerSpec[];
|
|
19
|
+
referenceScreenshots?: ReferenceScreenshotsSpec;
|
|
18
20
|
};
|
package/dist/agent-shared.js
CHANGED
|
@@ -10,14 +10,16 @@ export function mergeEffort(result, effortReport) {
|
|
|
10
10
|
return effortReport ? { ...result, effortReport } : result;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* The agent-capability fields (skills
|
|
14
|
-
* {@link runAgentInWorkspace}. One helper rather than a per-flow spread, so a flow
|
|
15
|
-
* be the one that drops a kind's declared playbook
|
|
16
|
-
* (the agent simply works without it) and would only show
|
|
13
|
+
* The agent-capability fields (skills, tool servers, reference designs) every agent-running flow
|
|
14
|
+
* forwards to {@link runAgentInWorkspace}. One helper rather than a per-flow spread, so a flow
|
|
15
|
+
* cannot silently be the one that drops a kind's declared playbook, tool server or reference
|
|
16
|
+
* gallery: the failure mode is invisible (the agent simply works without it) and would only show
|
|
17
|
+
* up as degraded output.
|
|
17
18
|
*/
|
|
18
19
|
export function agentCapabilities(job) {
|
|
19
20
|
return {
|
|
20
21
|
...(job.skills?.length ? { skills: job.skills } : {}),
|
|
21
22
|
...(job.mcpServers?.length ? { mcpServers: job.mcpServers } : {}),
|
|
23
|
+
...(job.referenceScreenshots ? { referenceScreenshots: job.referenceScreenshots } : {}),
|
|
22
24
|
};
|
|
23
25
|
}
|
package/dist/coding-agent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentJob, AgentResult, HarnessAuthFields, RepoSpec, SkillSpec, McpServerSpec } from './job.js';
|
|
1
|
+
import type { AgentJob, AgentResult, HarnessAuthFields, ReferenceScreenshotsSpec, 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';
|
|
@@ -112,6 +112,14 @@ export interface CodingAgentSpec extends HarnessAuthFields {
|
|
|
112
112
|
* has already dropped anything this harness cannot serve. Absent ⇒ built-in tools only.
|
|
113
113
|
*/
|
|
114
114
|
mcpServers?: McpServerSpec[];
|
|
115
|
+
/**
|
|
116
|
+
* The task's reference design images, downloaded into `.cat-context/reference-screenshots/`
|
|
117
|
+
* before the agent's first turn. Carried on the coding path as well as the explore one because
|
|
118
|
+
* what earns a run its references is the KIND's declared `ui` image, and a deployment's own
|
|
119
|
+
* UI-facing kind may well be a coding one, and nothing here switches on which built-in it is.
|
|
120
|
+
* Absent ⇒ none (the normal case).
|
|
121
|
+
*/
|
|
122
|
+
referenceScreenshots?: ReferenceScreenshotsSpec;
|
|
115
123
|
}
|
|
116
124
|
/** The outcome of a coding agent run, before each caller maps it to its own result shape. */
|
|
117
125
|
export interface CodingAgentOutcome {
|
package/dist/coding-agent.js
CHANGED
|
@@ -209,6 +209,9 @@ export async function runCodingAgent(spec, opts = {}) {
|
|
|
209
209
|
guardLimits: spec.guardLimits,
|
|
210
210
|
...(spec.skills?.length ? { skills: spec.skills } : {}),
|
|
211
211
|
...(spec.mcpServers?.length ? { mcpServers: spec.mcpServers } : {}),
|
|
212
|
+
...(spec.referenceScreenshots
|
|
213
|
+
? { referenceScreenshots: spec.referenceScreenshots }
|
|
214
|
+
: {}),
|
|
212
215
|
}, opts);
|
|
213
216
|
let outcome;
|
|
214
217
|
try {
|
|
@@ -808,6 +811,7 @@ export async function runMultiRepoCoding(job, opts = {}) {
|
|
|
808
811
|
// are properties of the AGENT KIND, not of the checkout layout.
|
|
809
812
|
...(job.skills?.length ? { skills: job.skills } : {}),
|
|
810
813
|
...(job.mcpServers?.length ? { mcpServers: job.mcpServers } : {}),
|
|
814
|
+
...(job.referenceScreenshots ? { referenceScreenshots: job.referenceScreenshots } : {}),
|
|
811
815
|
multiRepo: true,
|
|
812
816
|
}, opts);
|
|
813
817
|
// Commit forgotten tracked edits, then push + open a PR for each repo the run actually changed.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A linked-context file the backend prepared (requirements / RFC / PRD / tracker issue)
|
|
3
|
+
* for the harness to materialise under CONTEXT_DIR in the checkout, so the agent can read
|
|
4
|
+
* it on demand. The harness can't reach Jira/GitHub itself, so all such context is fetched
|
|
5
|
+
* and shipped here up front. `path` is sanitised to a safe basename on parse.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextFileSpec {
|
|
8
|
+
path: string;
|
|
9
|
+
title: string;
|
|
10
|
+
url: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The REFERENCE DESIGN IMAGES the backend holds for this task, for the harness to download into
|
|
15
|
+
* `.cat-context/reference-screenshots/` before the agent runs: the directory a UI tester's prompt
|
|
16
|
+
* names and, until now, nothing wrote.
|
|
17
|
+
*
|
|
18
|
+
* A manifest rather than the bytes: a design frame is a full-page PNG, and a job body is JSON
|
|
19
|
+
* that crosses every transport and is persisted with the dispatch. The bytes come back over the
|
|
20
|
+
* SAME container session token the run already holds (`GET ${url}/<artifactId>`), so this needs
|
|
21
|
+
* no extra credential and no publicly reachable URL.
|
|
22
|
+
*
|
|
23
|
+
* `view` is what the backend's gate pairs on, and `fileName` is the name the BACKEND chose for it,
|
|
24
|
+
* never derived here. The file name is how the agent learns the view name, so deriving it in the
|
|
25
|
+
* container would let a harness image the deployment has not rolled out yet rename every view a
|
|
26
|
+
* run reports, and the pairing would come apart with nothing failing.
|
|
27
|
+
*/
|
|
28
|
+
export interface ReferenceScreenshotsSpec {
|
|
29
|
+
/** Base URL of the reference download route; the artifact id is appended as a path segment. */
|
|
30
|
+
url: string;
|
|
31
|
+
/** The run's container session token (the same one the LLM proxy is called with). */
|
|
32
|
+
token: string;
|
|
33
|
+
files: ReferenceScreenshotSpec[];
|
|
34
|
+
/**
|
|
35
|
+
* View names the task holds a reference for that this job was NOT sent a file for, because the
|
|
36
|
+
* set was capped. Stated to the agent beside the transfers that failed: from where it stands
|
|
37
|
+
* both are a view to capture with no image to compare against.
|
|
38
|
+
*
|
|
39
|
+
* Two producers, and they mean the same thing here: the BACKEND's own ceiling (the number that
|
|
40
|
+
* should ever actually bind, chosen where the precedence between an upload and a design frame
|
|
41
|
+
* is known), and this parser's backstop against a body claiming more files than any real set
|
|
42
|
+
* has. A drop with no entry here is the bug this field exists to prevent.
|
|
43
|
+
*/
|
|
44
|
+
omitted: string[];
|
|
45
|
+
}
|
|
46
|
+
/** One reference image in a {@link ReferenceScreenshotsSpec}. `fileName` is sanitised on parse. */
|
|
47
|
+
export interface ReferenceScreenshotSpec {
|
|
48
|
+
artifactId: string;
|
|
49
|
+
fileName: string;
|
|
50
|
+
view: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sanitise a body-supplied context filename to a safe basename within CONTEXT_DIR:
|
|
54
|
+
* strip any directory part, allow only `[A-Za-z0-9._-]`, and reject empties / dotfiles
|
|
55
|
+
* / `..` so a hostile value can't escape the directory or clobber repo files.
|
|
56
|
+
*/
|
|
57
|
+
export declare function sanitizeContextFileName(value: unknown): string | undefined;
|
|
58
|
+
/** Parse the linked-context files, dropping any malformed/unsafe entry. */
|
|
59
|
+
export declare function parseContextFiles(value: unknown): ContextFileSpec[];
|
|
60
|
+
/**
|
|
61
|
+
* Parse the reference-design manifest, or undefined when absent/unusable.
|
|
62
|
+
*
|
|
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.
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseReferenceScreenshots(value: unknown): ReferenceScreenshotsSpec | undefined;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// The two manifests of FILES the backend stages into a checkout before the agent's first turn:
|
|
3
|
+
// the linked-context documents it materialises under CONTEXT_DIR, and the reference design images
|
|
4
|
+
// it has the harness download beside them.
|
|
5
|
+
//
|
|
6
|
+
// One module because they are the same kind of thing parsed the same defensive way, and because
|
|
7
|
+
// they share the basename rule below: both name files the container writes into a directory it
|
|
8
|
+
// then points the agent at, so both are held to a value that cannot escape it or clobber a repo
|
|
9
|
+
// file. Split out of `job.ts`, which parses everything else a job body carries.
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Sanitise a body-supplied context filename to a safe basename within CONTEXT_DIR:
|
|
13
|
+
* strip any directory part, allow only `[A-Za-z0-9._-]`, and reject empties / dotfiles
|
|
14
|
+
* / `..` so a hostile value can't escape the directory or clobber repo files.
|
|
15
|
+
*/
|
|
16
|
+
export function sanitizeContextFileName(value) {
|
|
17
|
+
if (typeof value !== 'string')
|
|
18
|
+
return undefined;
|
|
19
|
+
const base = value.replace(/\\/g, '/').split('/').pop() ?? '';
|
|
20
|
+
const cleaned = base.replace(/[^A-Za-z0-9._-]/g, '');
|
|
21
|
+
if (!cleaned || cleaned === '.' || cleaned === '..' || cleaned.startsWith('.'))
|
|
22
|
+
return undefined;
|
|
23
|
+
return cleaned;
|
|
24
|
+
}
|
|
25
|
+
/** Parse the linked-context files, dropping any malformed/unsafe entry. */
|
|
26
|
+
export function parseContextFiles(value) {
|
|
27
|
+
if (!Array.isArray(value))
|
|
28
|
+
return [];
|
|
29
|
+
const files = [];
|
|
30
|
+
const used = new Set();
|
|
31
|
+
for (const entry of value) {
|
|
32
|
+
if (typeof entry !== 'object' || entry === null)
|
|
33
|
+
continue;
|
|
34
|
+
const e = entry;
|
|
35
|
+
const path = sanitizeContextFileName(e.path);
|
|
36
|
+
if (!path || used.has(path))
|
|
37
|
+
continue;
|
|
38
|
+
if (typeof e.content !== 'string')
|
|
39
|
+
continue;
|
|
40
|
+
used.add(path);
|
|
41
|
+
files.push({
|
|
42
|
+
path,
|
|
43
|
+
title: typeof e.title === 'string' ? e.title : path,
|
|
44
|
+
url: typeof e.url === 'string' ? e.url : '',
|
|
45
|
+
content: e.content,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return files;
|
|
49
|
+
}
|
|
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.
|
|
54
|
+
*
|
|
55
|
+
* Hitting it is REPORTED rather than silently obeyed: an entry past the ceiling is dropped from
|
|
56
|
+
* `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.
|
|
59
|
+
*/
|
|
60
|
+
const MAX_REFERENCE_SCREENSHOTS = 40;
|
|
61
|
+
/**
|
|
62
|
+
* Parse the reference-design manifest, or undefined when absent/unusable.
|
|
63
|
+
*
|
|
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.
|
|
69
|
+
*/
|
|
70
|
+
export function parseReferenceScreenshots(value) {
|
|
71
|
+
if (typeof value !== 'object' || value === null)
|
|
72
|
+
return undefined;
|
|
73
|
+
const o = value;
|
|
74
|
+
const url = typeof o.url === 'string' ? o.url.trim() : '';
|
|
75
|
+
const token = typeof o.token === 'string' ? o.token : '';
|
|
76
|
+
if (!url || !token || !/^https?:\/\//i.test(url))
|
|
77
|
+
return undefined;
|
|
78
|
+
if (!Array.isArray(o.files))
|
|
79
|
+
return undefined;
|
|
80
|
+
const files = [];
|
|
81
|
+
// The backend's own dropped views come first; anything this parser drops joins them below.
|
|
82
|
+
const omitted = Array.isArray(o.omitted)
|
|
83
|
+
? o.omitted.filter((view) => typeof view === 'string' && view.length > 0)
|
|
84
|
+
: [];
|
|
85
|
+
const used = new Set();
|
|
86
|
+
for (const entry of o.files) {
|
|
87
|
+
if (typeof entry !== 'object' || entry === null)
|
|
88
|
+
continue;
|
|
89
|
+
const e = entry;
|
|
90
|
+
const fileName = sanitizeContextFileName(e.fileName);
|
|
91
|
+
const artifactId = typeof e.artifactId === 'string' ? e.artifactId.trim() : '';
|
|
92
|
+
// The id becomes a path segment on the download URL, so it is held to the shape the platform
|
|
93
|
+
// mints rather than encoded and hoped for: anything else cannot be a real artifact anyway.
|
|
94
|
+
if (!fileName || used.has(fileName) || !/^[A-Za-z0-9_-]{1,64}$/.test(artifactId))
|
|
95
|
+
continue;
|
|
96
|
+
const view = typeof e.view === 'string' ? e.view : fileName;
|
|
97
|
+
// Past the backstop the entry is NAMED, not dropped: it stays a view the agent must capture.
|
|
98
|
+
// Checked here rather than at the top of the loop so a malformed entry is refused on its own
|
|
99
|
+
// terms (it names no usable view to report) instead of being counted against the ceiling.
|
|
100
|
+
if (files.length >= MAX_REFERENCE_SCREENSHOTS) {
|
|
101
|
+
omitted.push(view);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
used.add(fileName);
|
|
105
|
+
files.push({ artifactId, fileName, view });
|
|
106
|
+
}
|
|
107
|
+
if (!files.length && !omitted.length)
|
|
108
|
+
return undefined;
|
|
109
|
+
return { url: url.replace(/\/+$/, ''), token, files, omitted };
|
|
110
|
+
}
|
package/dist/job.d.ts
CHANGED
|
@@ -8,8 +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
12
|
export type { TestSecretSpec };
|
|
12
13
|
export type { McpServerSpec, SkillResourceSpec, SkillSpec };
|
|
14
|
+
export type { ContextFileSpec, ReferenceScreenshotSpec, ReferenceScreenshotsSpec };
|
|
13
15
|
/**
|
|
14
16
|
* Per-job auth fields, shared across every job shape. The Pi harness carries the
|
|
15
17
|
* proxy base URL + a model-locked session token; the subscription harnesses
|
|
@@ -229,18 +231,6 @@ export interface AgentBootstrapSpec {
|
|
|
229
231
|
/** Scaffold from an empty directory instead of cloning `job.repo` (no reference). */
|
|
230
232
|
fromScratch?: boolean;
|
|
231
233
|
}
|
|
232
|
-
/**
|
|
233
|
-
* A linked-context file the backend prepared (requirements / RFC / PRD / tracker issue)
|
|
234
|
-
* for the harness to materialise under CONTEXT_DIR in the checkout, so the agent can read
|
|
235
|
-
* it on demand. The harness can't reach Jira/GitHub itself, so all such context is fetched
|
|
236
|
-
* and shipped here up front. `path` is sanitised to a safe basename on parse.
|
|
237
|
-
*/
|
|
238
|
-
export interface ContextFileSpec {
|
|
239
|
-
path: string;
|
|
240
|
-
title: string;
|
|
241
|
-
url: string;
|
|
242
|
-
content: string;
|
|
243
|
-
}
|
|
244
234
|
/** How an explore agent's reply is consumed. */
|
|
245
235
|
export interface AgentOutputSpec {
|
|
246
236
|
/** `prose` keeps the reply text; `structured` parses (and optionally repairs) it to JSON. */
|
|
@@ -328,6 +318,13 @@ export interface AgentJob extends HarnessAuthFields {
|
|
|
328
318
|
* The agent reads them on demand; they are kept out of any commit. Absent ⇒ none.
|
|
329
319
|
*/
|
|
330
320
|
contextFiles?: ContextFileSpec[];
|
|
321
|
+
/**
|
|
322
|
+
* 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
|
|
324
|
+
* CAPTURES views and only when the task actually has references, so absent is the normal case
|
|
325
|
+
* and means the agent names its own views.
|
|
326
|
+
*/
|
|
327
|
+
referenceScreenshots?: ReferenceScreenshotsSpec;
|
|
331
328
|
/**
|
|
332
329
|
* Private package-registry auth (npm private orgs, GitHub Packages), rendered into
|
|
333
330
|
* `~/.npmrc` before the run so the checkout's installs — the agent's own and the
|
package/dist/job.js
CHANGED
|
@@ -3,6 +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
7
|
/** A positive finite integer, or undefined for any other input (silently ignored). */
|
|
7
8
|
function posInt(value) {
|
|
8
9
|
return typeof value === 'number' && Number.isFinite(value) && value > 0
|
|
@@ -350,45 +351,6 @@ function parseAgentBootstrapSpec(value) {
|
|
|
350
351
|
...(o.fromScratch === true ? { fromScratch: true } : {}),
|
|
351
352
|
};
|
|
352
353
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Sanitise a body-supplied context filename to a safe basename within CONTEXT_DIR:
|
|
355
|
-
* strip any directory part, allow only `[A-Za-z0-9._-]`, and reject empties / dotfiles
|
|
356
|
-
* / `..` so a hostile value can't escape the directory or clobber repo files.
|
|
357
|
-
*/
|
|
358
|
-
function sanitizeContextFileName(value) {
|
|
359
|
-
if (typeof value !== 'string')
|
|
360
|
-
return undefined;
|
|
361
|
-
const base = value.replace(/\\/g, '/').split('/').pop() ?? '';
|
|
362
|
-
const cleaned = base.replace(/[^A-Za-z0-9._-]/g, '');
|
|
363
|
-
if (!cleaned || cleaned === '.' || cleaned === '..' || cleaned.startsWith('.'))
|
|
364
|
-
return undefined;
|
|
365
|
-
return cleaned;
|
|
366
|
-
}
|
|
367
|
-
/** Parse the linked-context files, dropping any malformed/unsafe entry. */
|
|
368
|
-
function parseContextFiles(value) {
|
|
369
|
-
if (!Array.isArray(value))
|
|
370
|
-
return [];
|
|
371
|
-
const files = [];
|
|
372
|
-
const used = new Set();
|
|
373
|
-
for (const entry of value) {
|
|
374
|
-
if (typeof entry !== 'object' || entry === null)
|
|
375
|
-
continue;
|
|
376
|
-
const e = entry;
|
|
377
|
-
const path = sanitizeContextFileName(e.path);
|
|
378
|
-
if (!path || used.has(path))
|
|
379
|
-
continue;
|
|
380
|
-
if (typeof e.content !== 'string')
|
|
381
|
-
continue;
|
|
382
|
-
used.add(path);
|
|
383
|
-
files.push({
|
|
384
|
-
path,
|
|
385
|
-
title: typeof e.title === 'string' ? e.title : path,
|
|
386
|
-
url: typeof e.url === 'string' ? e.url : '',
|
|
387
|
-
content: e.content,
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
return files;
|
|
391
|
-
}
|
|
392
354
|
/** Parse the explore-mode infra stand-up spec, or undefined when absent/unrecognised. */
|
|
393
355
|
function parseAgentInfraSpec(value) {
|
|
394
356
|
if (typeof value !== 'object' || value === null)
|
|
@@ -516,6 +478,7 @@ export function parseAgentJob(input) {
|
|
|
516
478
|
referenceBranches: parseReferenceBranches(o.referenceBranches),
|
|
517
479
|
bootstrap: parseAgentBootstrapSpec(o.bootstrap),
|
|
518
480
|
contextFiles: parseContextFiles(o.contextFiles),
|
|
481
|
+
referenceScreenshots: parseReferenceScreenshots(o.referenceScreenshots),
|
|
519
482
|
packageRegistries: parsePackageRegistries(o.packageRegistries),
|
|
520
483
|
skills: parseSkillSpecs(o.skills),
|
|
521
484
|
mcpServers: parseMcpServerSpecs(o.mcpServers),
|
|
@@ -582,7 +545,7 @@ function parseAgentPrSpec(raw) {
|
|
|
582
545
|
* literal doesn't blow the complexity budget; behaviour is byte-identical (spread order preserved).
|
|
583
546
|
*/
|
|
584
547
|
function assembleAgentJob(o, mode, agentField, parts) {
|
|
585
|
-
const { output, pr, infra, peerRepos, referenceRepos, referenceBranches, bootstrap, contextFiles, packageRegistries, skills, mcpServers, testSecrets, guardLimits, validation, validationChecks, reproduction, dependencyInstall, reviewPrNumber, generatorSecrets, } = parts;
|
|
548
|
+
const { output, pr, infra, peerRepos, referenceRepos, referenceBranches, bootstrap, contextFiles, referenceScreenshots, packageRegistries, skills, mcpServers, testSecrets, guardLimits, validation, validationChecks, reproduction, dependencyInstall, reviewPrNumber, generatorSecrets, } = parts;
|
|
586
549
|
const repo = (o.repo ?? {});
|
|
587
550
|
return {
|
|
588
551
|
jobId: str(o.jobId, 'jobId'),
|
|
@@ -598,6 +561,7 @@ function assembleAgentJob(o, mode, agentField, parts) {
|
|
|
598
561
|
...(bootstrap ? { bootstrap } : {}),
|
|
599
562
|
...(output ? { output } : {}),
|
|
600
563
|
...(contextFiles.length ? { contextFiles } : {}),
|
|
564
|
+
...(referenceScreenshots ? { referenceScreenshots } : {}),
|
|
601
565
|
...(packageRegistries.length ? { packageRegistries } : {}),
|
|
602
566
|
...(skills ? { skills } : {}),
|
|
603
567
|
...(mcpServers ? { mcpServers } : {}),
|
package/dist/pi-workspace.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RepoSpec } from './job.js';
|
|
1
|
+
import type { RepoSpec, ReferenceScreenshotsSpec } from './job.js';
|
|
2
2
|
import type { McpServerSpec, SkillSpec } from './agent-capabilities.js';
|
|
3
3
|
import { type ContextFileInfo, type PiRunOutcome } from './pi.js';
|
|
4
4
|
import type { PiRunStats, RunDiagnostics } from './pi-reduction.js';
|
|
@@ -105,6 +105,12 @@ export interface AgentRunSpec {
|
|
|
105
105
|
* from AGENTS.md, so the agent reads them on demand. Absent ⇒ none.
|
|
106
106
|
*/
|
|
107
107
|
contextFiles?: ContextFileInfo[];
|
|
108
|
+
/**
|
|
109
|
+
* The task's reference design images. Downloaded into `.cat-context/reference-screenshots/`
|
|
110
|
+
* before the run and named in the agent's prompt, so a capturing agent can compare against them
|
|
111
|
+
* and use their view names. Absent ⇒ nothing is downloaded and nothing is said.
|
|
112
|
+
*/
|
|
113
|
+
referenceScreenshots?: ReferenceScreenshotsSpec;
|
|
108
114
|
/**
|
|
109
115
|
* The skills to make available for this run — a `skill` step's picked skill and/or the playbooks
|
|
110
116
|
* the running agent kind declares. Installed HARNESS-AWARE: the claude-code runner writes them
|
package/dist/pi-workspace.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, mkdtemp, readdir, rm, stat } from 'node:fs/promises';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { deliverReferenceScreenshots } from './reference-screenshots.js';
|
|
4
5
|
import { readEffortReport } from './effort.js';
|
|
5
6
|
import { log } from './logger.js';
|
|
6
7
|
import { CONTEXT_DIR, materializeContextFiles, materializeSkillResources, phasedProxyBaseUrl, runPi, webSearchConfigFromEnv, webSearchProxyEnv, writeAgentsContext, writePiModelsConfig, writeWebToolsConfig, } from './pi.js';
|
|
@@ -142,6 +143,21 @@ export async function runAgentInWorkspace(spec, opts = {}) {
|
|
|
142
143
|
// harness paths; kept out of the agent's commits via a local git exclude entry.
|
|
143
144
|
const contextFiles = spec.contextFiles ?? [];
|
|
144
145
|
await materializeContextFiles(spec.dir, contextFiles);
|
|
146
|
+
// The task's reference designs, fetched into `.cat-context/reference-screenshots/` for the kinds
|
|
147
|
+
// that capture views. Delivered here (beside the linked context, before either harness path
|
|
148
|
+
// branches) so the Pi and subscription runs are handed the SAME directory and the SAME view
|
|
149
|
+
// names; a per-path copy is how one of them would end up silently without it.
|
|
150
|
+
//
|
|
151
|
+
// This runs once per PASS, not once per job: a coding flow re-enters its workspace for every
|
|
152
|
+
// repair round. That is safe because the delivery is idempotent over the checkout (a file
|
|
153
|
+
// already on disk is counted, never re-fetched), so a later round costs a stat per reference and
|
|
154
|
+
// cannot report a view an earlier round successfully delivered as absent. A view that MISSED is
|
|
155
|
+
// retried, which is the behaviour worth having: the next round is a fresh chance at a blob
|
|
156
|
+
// backend that was briefly down.
|
|
157
|
+
const referenceGuidance = await deliverReferenceScreenshots(spec.dir, spec.referenceScreenshots, {
|
|
158
|
+
...(opts.signal ? { signal: opts.signal } : {}),
|
|
159
|
+
log: opts.log ?? log,
|
|
160
|
+
});
|
|
145
161
|
// Skills: claude-code installs them natively into its ISOLATED config dir, so it reads from
|
|
146
162
|
// there. Everything else reads the checkout, so materialise each skill's resources under
|
|
147
163
|
// `.cat-context/skill/<name>/` (their instructions are folded into the prompt by the backend) —
|
|
@@ -164,7 +180,7 @@ export async function runAgentInWorkspace(spec, opts = {}) {
|
|
|
164
180
|
const subOutcome = await runSubscriptionHarness(spec.harness, {
|
|
165
181
|
cwd: spec.dir,
|
|
166
182
|
model: spec.model,
|
|
167
|
-
systemPrompt: subscriptionSystemPrompt(spec.systemPrompt, contextFiles)
|
|
183
|
+
systemPrompt: `${subscriptionSystemPrompt(spec.systemPrompt, contextFiles)}${referenceGuidance}`,
|
|
168
184
|
userPrompt: spec.userPrompt,
|
|
169
185
|
...(spec.subscriptionToken ? { subscriptionToken: spec.subscriptionToken } : {}),
|
|
170
186
|
subscriptionBaseUrl: spec.subscriptionBaseUrl,
|
|
@@ -235,6 +251,7 @@ export async function runAgentInWorkspace(spec, opts = {}) {
|
|
|
235
251
|
serviceDirectory: spec.serviceDirectory,
|
|
236
252
|
contextFiles,
|
|
237
253
|
hasBlueprints,
|
|
254
|
+
...(referenceGuidance ? { referenceGuidance } : {}),
|
|
238
255
|
...(spec.multiRepo ? { multiRepo: true } : {}),
|
|
239
256
|
});
|
|
240
257
|
// Pi's calls are metered server-side by the LLM proxy, which sees only an HTTP request — so
|
package/dist/pi.d.ts
CHANGED
|
@@ -71,6 +71,13 @@ export declare function writeAgentsContext(systemPrompt: string, opts?: {
|
|
|
71
71
|
* every turn) pointing at files that don't exist. Absent/false ⇒ the note is omitted.
|
|
72
72
|
*/
|
|
73
73
|
hasBlueprints?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The reference-design block composed by `referenceScreenshotGuidance`: which files the run
|
|
76
|
+
* was handed and which it could not fetch. Composed by the caller (it is the only side that
|
|
77
|
+
* knows what actually landed on disk) and appended verbatim. Absent/'' ⇒ nothing is said,
|
|
78
|
+
* which is the normal case: only a capturing kind is sent references at all.
|
|
79
|
+
*/
|
|
80
|
+
referenceGuidance?: string;
|
|
74
81
|
}): Promise<void>;
|
|
75
82
|
/** Directory in the checkout where linked-context files are materialised (see CONTEXT_DIR in agents). */
|
|
76
83
|
export declare const CONTEXT_DIR = ".cat-context";
|
|
@@ -88,6 +95,19 @@ export interface ContextFileInfo {
|
|
|
88
95
|
* (a scaffold-from-scratch checkout has no `.git` yet — the files just stay untracked).
|
|
89
96
|
*/
|
|
90
97
|
export declare function materializeContextFiles(cwd: string, files: ContextFileInfo[]): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Add the LOCAL git exclude entry for {@link CONTEXT_DIR}, so nothing the harness materialises
|
|
100
|
+
* there can be committed into the agent's PR by a `git add -A`.
|
|
101
|
+
*
|
|
102
|
+
* The exclude pattern has no leading slash, so it matches `.cat-context/` at any depth, covering
|
|
103
|
+
* the monorepo case where cwd is a service subdirectory below the repo root. Best-effort: a
|
|
104
|
+
* scaffold-from-scratch checkout has no `.git` yet, and the files then simply stay untracked.
|
|
105
|
+
*
|
|
106
|
+
* One helper rather than a copy per materialiser: every writer into that directory owes the same
|
|
107
|
+
* exclude, and a new one that forgot it would leak the platform's own files into a customer's
|
|
108
|
+
* repository with nothing failing.
|
|
109
|
+
*/
|
|
110
|
+
export declare function excludeContextDir(cwd: string): Promise<void>;
|
|
91
111
|
/** Subdirectory of {@link CONTEXT_DIR} where a skill's resources are materialised, per skill. */
|
|
92
112
|
export declare const SKILL_CONTEXT_SUBDIR = "skill";
|
|
93
113
|
/**
|
package/dist/pi.js
CHANGED
|
@@ -197,7 +197,11 @@ export async function writeAgentsContext(systemPrompt, opts = {}) {
|
|
|
197
197
|
// (see the note above `writeAgentsContext`): it comes solely from the backend `spec-aware`
|
|
198
198
|
// trait, so a spec-aware run no longer carries it twice.
|
|
199
199
|
const blueprint = opts.hasBlueprints ? BLUEPRINT_GUIDANCE : '';
|
|
200
|
-
|
|
200
|
+
// The reference designs the harness downloaded for a capturing kind, listed with their view
|
|
201
|
+
// names (and the ones that could not be fetched). Last, beside the linked-context list it is the
|
|
202
|
+
// sibling of: both point the agent at files already on disk.
|
|
203
|
+
const references = opts.referenceGuidance ?? '';
|
|
204
|
+
await writeFile(join(dir, 'AGENTS.md'), `${systemPrompt}${blueprint}${TODO_GUIDANCE}${monorepo}${multiRepo}${webTools}${context}${references}`, 'utf8');
|
|
201
205
|
}
|
|
202
206
|
/** The MULTI-REPO mechanics note appended to AGENTS.md when a run spans sibling checkouts. */
|
|
203
207
|
const MULTI_REPO_GUIDANCE = `
|
|
@@ -247,9 +251,21 @@ export async function materializeContextFiles(cwd, files) {
|
|
|
247
251
|
await mkdir(dir, { recursive: true });
|
|
248
252
|
for (const f of files)
|
|
249
253
|
await writeFile(join(dir, f.path), f.content, 'utf8');
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
254
|
+
await excludeContextDir(cwd);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Add the LOCAL git exclude entry for {@link CONTEXT_DIR}, so nothing the harness materialises
|
|
258
|
+
* there can be committed into the agent's PR by a `git add -A`.
|
|
259
|
+
*
|
|
260
|
+
* The exclude pattern has no leading slash, so it matches `.cat-context/` at any depth, covering
|
|
261
|
+
* the monorepo case where cwd is a service subdirectory below the repo root. Best-effort: a
|
|
262
|
+
* scaffold-from-scratch checkout has no `.git` yet, and the files then simply stay untracked.
|
|
263
|
+
*
|
|
264
|
+
* One helper rather than a copy per materialiser: every writer into that directory owes the same
|
|
265
|
+
* exclude, and a new one that forgot it would leak the platform's own files into a customer's
|
|
266
|
+
* repository with nothing failing.
|
|
267
|
+
*/
|
|
268
|
+
export async function excludeContextDir(cwd) {
|
|
253
269
|
const gitRoot = await findGitRoot(cwd);
|
|
254
270
|
if (!gitRoot)
|
|
255
271
|
return;
|
|
@@ -289,15 +305,7 @@ export async function materializeSkillResources(cwd, skills) {
|
|
|
289
305
|
await writeFile(dest, r.content, 'utf8');
|
|
290
306
|
}
|
|
291
307
|
}
|
|
292
|
-
|
|
293
|
-
if (!gitRoot)
|
|
294
|
-
return;
|
|
295
|
-
try {
|
|
296
|
-
await appendFile(join(gitRoot, '.git', 'info', 'exclude'), `\n${CONTEXT_DIR}/\n`, 'utf8');
|
|
297
|
-
}
|
|
298
|
-
catch {
|
|
299
|
-
// No writable .git/info; the files simply stay untracked.
|
|
300
|
-
}
|
|
308
|
+
await excludeContextDir(cwd);
|
|
301
309
|
}
|
|
302
310
|
/** Walk up from `dir` (bounded) to the directory containing a `.git` folder, or null. */
|
|
303
311
|
async function findGitRoot(dir) {
|