@cat-factory/contracts 0.163.0 → 0.164.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.
Files changed (41) hide show
  1. package/dist/execution.d.ts +48 -0
  2. package/dist/execution.d.ts.map +1 -1
  3. package/dist/execution.js +11 -0
  4. package/dist/execution.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/routes/agent-runs.d.ts +30 -0
  10. package/dist/routes/agent-runs.d.ts.map +1 -1
  11. package/dist/routes/execution.d.ts +120 -0
  12. package/dist/routes/execution.d.ts.map +1 -1
  13. package/dist/routes/human-review.d.ts +15 -0
  14. package/dist/routes/human-review.d.ts.map +1 -1
  15. package/dist/routes/human-test.d.ts +75 -0
  16. package/dist/routes/human-test.d.ts.map +1 -1
  17. package/dist/routes/index.d.ts +1 -0
  18. package/dist/routes/index.d.ts.map +1 -1
  19. package/dist/routes/index.js +1 -0
  20. package/dist/routes/index.js.map +1 -1
  21. package/dist/routes/runners.d.ts +10 -0
  22. package/dist/routes/runners.d.ts.map +1 -1
  23. package/dist/routes/validation-checks.d.ts +175 -0
  24. package/dist/routes/validation-checks.d.ts.map +1 -0
  25. package/dist/routes/validation-checks.js +40 -0
  26. package/dist/routes/validation-checks.js.map +1 -0
  27. package/dist/routes/visual-confirm.d.ts +45 -0
  28. package/dist/routes/visual-confirm.d.ts.map +1 -1
  29. package/dist/routes/workspaces.d.ts +30 -0
  30. package/dist/routes/workspaces.d.ts.map +1 -1
  31. package/dist/runners.d.ts +90 -0
  32. package/dist/runners.d.ts.map +1 -1
  33. package/dist/runners.js +9 -0
  34. package/dist/runners.js.map +1 -1
  35. package/dist/snapshot.d.ts +15 -0
  36. package/dist/snapshot.d.ts.map +1 -1
  37. package/dist/validation-checks.d.ts +123 -0
  38. package/dist/validation-checks.d.ts.map +1 -0
  39. package/dist/validation-checks.js +118 -0
  40. package/dist/validation-checks.js.map +1 -0
  41. package/package.json +1 -1
@@ -0,0 +1,118 @@
1
+ import * as v from 'valibot';
2
+ // ---------------------------------------------------------------------------
3
+ // Pre-PR validation checks.
4
+ //
5
+ // A service declares shell commands (install / lint / test / build) that the
6
+ // executor-harness runs against the CHECKOUT after the coding agent settles and
7
+ // BEFORE the PR is opened. A failing command's captured output is handed back to
8
+ // the agent as its next instruction, and the loop repeats until the commands pass
9
+ // or the attempt budget is spent — a programmatic exit condition, computed by the
10
+ // harness, never self-reported by the model. Only a passing checkout opens a PR;
11
+ // an exhausted budget FAILS the step with the last captured output.
12
+ //
13
+ // Config is per SERVICE FRAME (resolved up the frame chain), mirroring the
14
+ // `test_secrets` / `release_health_configs` shape, and travels to the container IN
15
+ // THE JOB BODY (containers have no DB access). See
16
+ // docs/initiatives/pre-pr-validation.md.
17
+ // ---------------------------------------------------------------------------
18
+ /** A short operator-facing label for a check (`lint`, `unit tests`, `build`). */
19
+ const validationCheckLabelSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80));
20
+ /**
21
+ * The shell command a check runs, executed as `sh -c <command>` in the checkout (the
22
+ * service directory for a monorepo service). Runs INSIDE the sandboxed run container —
23
+ * the same trust boundary as the coding agent — so there is no host/backend execution.
24
+ */
25
+ const validationCommandSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(2000));
26
+ /** One configured validation check: what to run and what to call it. */
27
+ export const validationCheckSchema = v.object({
28
+ label: validationCheckLabelSchema,
29
+ command: validationCommandSchema,
30
+ });
31
+ /**
32
+ * How many times the harness may re-run the agent against failing checks before giving up.
33
+ * Bounded so a wedged service can't burn a container indefinitely. `1` = run the checks once
34
+ * and fail on the first red (no repair round).
35
+ *
36
+ * MIRRORED in the executor-harness (`executor-harness/src/job.ts`), which clamps the same field
37
+ * off the job body but takes no dependency on this package. Change both together: the harness
38
+ * silently capping a budget this schema accepts would be invisible from either side.
39
+ */
40
+ export const VALIDATION_DEFAULT_MAX_ATTEMPTS = 3;
41
+ export const VALIDATION_MAX_ATTEMPTS_CEILING = 10;
42
+ const validationMaxAttemptsSchema = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(VALIDATION_MAX_ATTEMPTS_CEILING));
43
+ /** At most this many checks per service — the loop runs them in order, so the list stays short. */
44
+ export const VALIDATION_MAX_CHECKS = 10;
45
+ /** Set/replace a service's validation checks. An empty list clears the config. */
46
+ export const upsertServiceValidationConfigSchema = v.pipe(v.object({
47
+ checks: v.array(validationCheckSchema),
48
+ /** Repair-round budget; omitted ⇒ {@link VALIDATION_DEFAULT_MAX_ATTEMPTS}. */
49
+ maxAttempts: v.optional(validationMaxAttemptsSchema),
50
+ }), v.check((o) => new Set(o.checks.map((c) => c.label)).size === o.checks.length, 'validation check labels must be unique within a service'), v.check((o) => o.checks.length <= VALIDATION_MAX_CHECKS, `at most ${VALIDATION_MAX_CHECKS} validation checks per service`));
51
+ /** What `GET .../validation-checks` returns for one service frame. */
52
+ export const serviceValidationConfigSchema = v.object({
53
+ /** The service-frame block these checks belong to. */
54
+ blockId: v.string(),
55
+ checks: v.array(validationCheckSchema),
56
+ maxAttempts: v.number(),
57
+ });
58
+ /**
59
+ * The RESOLVED checks a dispatch carries: the frame-chain walk's result, folded onto the
60
+ * agent run context and forwarded on the coding job body. `null`/absent ⇒ the service
61
+ * configured none, so the harness runs its existing (unvalidated) path unchanged.
62
+ */
63
+ export const resolvedValidationChecksSchema = v.object({
64
+ checks: v.array(validationCheckSchema),
65
+ maxAttempts: v.number(),
66
+ });
67
+ // ---- The harness-produced report ------------------------------------------
68
+ /** One command's outcome in a validation attempt. */
69
+ export const validationCheckOutcomeSchema = v.object({
70
+ label: v.fallback(v.string(), 'check'),
71
+ command: v.fallback(v.string(), ''),
72
+ /** Exit code (0 = pass); 124 on watchdog timeout, 127 on spawn failure, 130 on abort. */
73
+ exitCode: v.fallback(v.number(), 1),
74
+ passed: v.fallback(v.boolean(), false),
75
+ /** Bounded, secret-scrubbed tail of the command's combined stdout+stderr. */
76
+ outputTail: v.fallback(v.optional(v.string()), undefined),
77
+ /** Wall-clock of the command, ms. */
78
+ durationMs: v.fallback(v.optional(v.number()), undefined),
79
+ /** Set when the command was killed by the per-command watchdog. */
80
+ timedOut: v.fallback(v.optional(v.boolean()), undefined),
81
+ });
82
+ /**
83
+ * The harness-computed report of a run's pre-PR validation: whether the LAST attempt's
84
+ * commands all passed, how many attempts were spent, and each command's outcome in that
85
+ * attempt. Produced by the executor-harness (it runs the commands and reads the exit codes)
86
+ * and carried back on the runner view/result → {@link AgentRunResult.validationReport}; the
87
+ * engine records it on the step. Lenient (`v.fallback`) so a malformed field degrades rather
88
+ * than discarding the whole report.
89
+ */
90
+ export const validationReportSchema = v.object({
91
+ /** Whether every command in the latest attempt exited 0 (⇒ the PR was allowed to open). */
92
+ passed: v.fallback(v.boolean(), false),
93
+ /** How many agent+check rounds ran (1 = the checks passed/failed on the first pass). */
94
+ attempts: v.fallback(v.number(), 1),
95
+ /** The budget the loop ran under, so the UI can show "3 / 3 attempts". */
96
+ maxAttempts: v.fallback(v.number(), VALIDATION_DEFAULT_MAX_ATTEMPTS),
97
+ /** Per-command outcomes of the LATEST attempt, in configured order. */
98
+ outcomes: v.fallback(v.array(validationCheckOutcomeSchema), []),
99
+ /** Epoch ms the latest attempt finished. */
100
+ at: v.fallback(v.optional(v.number()), undefined),
101
+ });
102
+ /** Parse-or-throw a harness validation report (lenient — malformed fields degrade to defaults). */
103
+ export function parseValidationReport(value) {
104
+ return v.parse(validationReportSchema, value);
105
+ }
106
+ /**
107
+ * The one-line human summary of a failed validation report, used as the step's failure detail
108
+ * when the attempt budget is spent. Names the failing checks + their exit codes so the run
109
+ * detail is actionable without opening the report.
110
+ */
111
+ export function summarizeValidationFailure(report) {
112
+ const failed = report.outcomes.filter((o) => !o.passed);
113
+ const names = failed.map((o) => `${o.label} (exit ${o.exitCode})`).join(', ');
114
+ return (`Pre-PR validation failed after ${report.attempts} of ${report.maxAttempts} attempt(s)` +
115
+ (names ? `: ${names}` : '') +
116
+ '. No pull request was opened.');
117
+ }
118
+ //# sourceMappingURL=validation-checks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-checks.js","sourceRoot":"","sources":["../src/validation-checks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,8EAA8E;AAC9E,4BAA4B;AAC5B,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,iFAAiF;AACjF,kFAAkF;AAClF,kFAAkF;AAClF,iFAAiF;AACjF,oEAAoE;AACpE,EAAE;AACF,2EAA2E;AAC3E,mFAAmF;AACnF,mDAAmD;AACnD,yCAAyC;AACzC,8EAA8E;AAE9E,iFAAiF;AACjF,MAAM,0BAA0B,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAA;AAEhG;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;AAE/F,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,0BAA0B;IACjC,OAAO,EAAE,uBAAuB;CACjC,CAAC,CAAA;AAGF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAA;AAChD,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAA;AAEjD,MAAM,2BAA2B,GAAG,CAAC,CAAC,IAAI,CACxC,CAAC,CAAC,MAAM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,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,+BAA+B,CAAC;IACpE,uEAAuE;IACvE,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,4BAA4B,CAAC,EAAE,EAAE,CAAC;IAC/D,4CAA4C;IAC5C,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,CAAC;CAClD,CAAC,CAAA;AAGF,mGAAmG;AACnG,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,OAAO,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAwB;IACjE,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IACvD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7E,OAAO,CACL,kCAAkC,MAAM,CAAC,QAAQ,OAAO,MAAM,CAAC,WAAW,aAAa;QACvF,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,+BAA+B,CAChC,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cat-factory/contracts",
3
- "version": "0.163.0",
3
+ "version": "0.164.0",
4
4
  "description": "Valibot wire contract shared between the Agent Architecture Board frontend and backend.",
5
5
  "repository": {
6
6
  "type": "git",