devcontour-harness 0.1.0-alpha.31 → 0.1.0-alpha.34

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 (55) hide show
  1. package/README.md +22 -3
  2. package/docs/architecture.md +12 -0
  3. package/docs/compatibility.md +21 -18
  4. package/docs/contracts.md +135 -13
  5. package/docs/release-notes/0.1.0-alpha.32.md +33 -0
  6. package/docs/release-notes/0.1.0-alpha.33.md +29 -0
  7. package/docs/release-notes/0.1.0-alpha.34.md +32 -0
  8. package/docs/upgrade.md +137 -0
  9. package/lib/cli.js +2 -2
  10. package/lib/contracts/cli.d.ts +295 -5
  11. package/lib/contracts/events.d.ts +350 -4
  12. package/lib/contracts/events.js +63 -2
  13. package/lib/contracts/failure.d.ts +6 -1
  14. package/lib/contracts/failure.js +5 -1
  15. package/lib/contracts/handoff.d.ts +8 -0
  16. package/lib/contracts/handoff.js +17 -3
  17. package/lib/contracts/published.d.ts +177 -3
  18. package/lib/contracts/report.d.ts +116 -2
  19. package/lib/contracts/report.js +61 -3
  20. package/lib/control/base-move.d.ts +7 -2
  21. package/lib/control/base-move.js +14 -1
  22. package/lib/control/harness.d.ts +44 -8
  23. package/lib/control/harness.js +8 -96
  24. package/lib/control/status.d.ts +235 -0
  25. package/lib/control/status.js +101 -0
  26. package/lib/engine/budget.d.ts +78 -0
  27. package/lib/engine/budget.js +13 -2
  28. package/lib/engine/classify.d.ts +14 -1
  29. package/lib/engine/classify.js +34 -0
  30. package/lib/engine/engine.d.ts +17 -5
  31. package/lib/engine/engine.js +75 -5
  32. package/lib/engine/runner.js +4 -5
  33. package/lib/environment/isolation.d.ts +67 -3
  34. package/lib/environment/isolation.js +148 -5
  35. package/lib/environment/lifecycle.js +1 -1
  36. package/lib/explain/state.d.ts +25 -4
  37. package/lib/explain/state.js +29 -0
  38. package/lib/handoff/index.d.ts +1 -1
  39. package/lib/handoff/markdown.js +4 -2
  40. package/lib/handoff/pack.d.ts +38 -8
  41. package/lib/handoff/pack.js +57 -18
  42. package/lib/index.d.ts +18 -3
  43. package/lib/index.js +18 -2
  44. package/lib/integrations/connector/testing.js +1 -1
  45. package/lib/projections/next.d.ts +3 -1
  46. package/lib/projections/next.js +4 -1
  47. package/lib/projections/stop.d.ts +11 -0
  48. package/lib/projections/stop.js +44 -15
  49. package/lib/report/compute.js +228 -21
  50. package/lib/report/document.js +31 -7
  51. package/lib/verification/gates.js +20 -4
  52. package/package.json +1 -1
  53. package/schemas/handoff-pack.schema.json +6 -0
  54. package/schemas/run-event.schema.json +319 -0
  55. package/schemas/value-report.schema.json +235 -3
@@ -49,6 +49,13 @@ export const HANDOFF_LIMITS = {
49
49
  };
50
50
  /** Предел сериализованного пакета (JSON, UTF-8). */
51
51
  export const HANDOFF_MAX_BYTES = 256 * 1024;
52
+ /**
53
+ * Наименьший предел, который хост может задать пакету (`maxBytes` у
54
+ * `handoffPack`): ниже него не помещается даже обычный минимальный пакет.
55
+ * Это не гарантия: записи, которые не отбрасываются (сводка, очередь, идущие
56
+ * попытки, задания, следующий шаг), могут не уложиться и в больший предел.
57
+ */
58
+ export const HANDOFF_MIN_BYTES = 4 * 1024;
52
59
  /** Строка, усечённая до `n` знаков с «…». */
53
60
  const clipped = (n) => z.string().max(n + 1);
54
61
  const text = clipped(HANDOFF_LIMITS.text);
@@ -229,7 +236,8 @@ export const handoffPackSchema = z.strictObject({
229
236
  * сообщённое runtime, `estimatedUsd` — оценка по тарифу; `complete: false`
230
237
  * — расход известен не полностью (вызовы без стоимости, незавершённые,
231
238
  * брошенные, попытки без учёта), сумма — нижняя граница, `remaining*` —
232
- * `null`. Бюджеты поручений в пределах и без расхода не перечисляются.
239
+ * `null`. Бюджеты поручений в пределах и без расхода не перечисляются, как
240
+ * и поручений, весь расход которых — вызовы о их группе (`truncated.budgetsShared`).
233
241
  * Нет поля — бюджеты не заданы.
234
242
  */
235
243
  budgets: z
@@ -271,10 +279,14 @@ export const handoffPackSchema = z.strictObject({
271
279
  /**
272
280
  * Сколько записей каждого списка не вошло в пакет (по пределу числа или
273
281
  * размера). `budgets` — строки бюджетов сверх предела, `budgetsWithin` —
274
- * бюджеты поручений в пределах и без расхода (не показаны намеренно);
282
+ * бюджеты поручений в пределах и без расхода (не показаны намеренно),
283
+ * `budgetsShared` — бюджеты поручений, весь расход которых — вызовы о их
284
+ * группе (ревью и проверка плана): этот расход один и уже есть в строках
285
+ * группы и total, а не повторяется у каждого поручения;
275
286
  * `intentions` — сколько намерений усечено по `intentionChars`,
276
287
  * `intentionsDropped` — отброшено ради предела размера; `bySize` — пакет
277
- * урезан до `HANDOFF_MAX_BYTES`.
288
+ * урезан до предела размера (`HANDOFF_MAX_BYTES` или меньший `maxBytes`
289
+ * хоста).
278
290
  */
279
291
  truncated: z.strictObject({
280
292
  works: count,
@@ -283,6 +295,8 @@ export const handoffPackSchema = z.strictObject({
283
295
  unfinished: count,
284
296
  budgets: count,
285
297
  budgetsWithin: count,
298
+ // Пакеты прежних версий поля не знают: при разборе — 0.
299
+ budgetsShared: count.default(0),
286
300
  repairs: count,
287
301
  intentions: count,
288
302
  intentionsDropped: count,
@@ -1651,7 +1651,7 @@ export declare const publishedSchemas: {
1651
1651
  workId: z.ZodOptional<z.ZodString>;
1652
1652
  runId: z.ZodOptional<z.ZodString>;
1653
1653
  attempt: z.ZodOptional<z.ZodNumber>;
1654
- type: z.ZodLiteral<"graph.registered" | "graph.reviewed" | "graph.approved" | "work.ready" | "work.held" | "attempt.claimed" | "attempt.phase" | "attempt.gate" | "attempt.review" | "attempt.stage" | "attempt.liveness" | "attempt.failed" | "attempt.expired" | "attempt.cancelled" | "attempt.recovered" | "work.accepted" | "work.blocked" | "control.paused" | "control.resumed" | "controller.acquired" | "controller.released" | "budget.blocked" | "corpus.adopted" | "work.recovery" | "joint.started" | "joint.liveness" | "joint.finished" | "policy.applied" | "policy.reconfigure" | "delivery.pending" | "delivery.delivered" | "delivery.failed" | "delivery.conflict" | "delivery.uncertain">;
1654
+ type: z.ZodLiteral<"graph.registered" | "graph.reviewed" | "graph.approved" | "work.ready" | "work.held" | "attempt.claimed" | "attempt.phase" | "attempt.gate" | "attempt.review" | "attempt.stage" | "attempt.liveness" | "attempt.failed" | "attempt.diagnosed" | "attempt.expired" | "attempt.cancelled" | "attempt.recovered" | "work.accepted" | "work.retried" | "work.cancelled" | "work.blocked" | "control.paused" | "control.resumed" | "controller.acquired" | "base.moved" | "controller.released" | "budget.blocked" | "corpus.adopted" | "work.recovery" | "joint.started" | "joint.liveness" | "joint.finished" | "policy.applied" | "policy.reconfigure" | "delivery.pending" | "delivery.delivered" | "delivery.failed" | "delivery.conflict" | "delivery.uncertain">;
1655
1655
  payload: z.ZodObject<{
1656
1656
  digest: z.ZodString;
1657
1657
  orders: z.ZodNumber;
@@ -1813,6 +1813,42 @@ export declare const publishedSchemas: {
1813
1813
  }>;
1814
1814
  message: z.ZodString;
1815
1815
  blocked: z.ZodBoolean;
1816
+ }, z.core.$strict> | z.ZodObject<{
1817
+ failureKind: z.ZodEnum<{
1818
+ gate: "gate";
1819
+ unknown: "unknown";
1820
+ review: "review";
1821
+ cancelled: "cancelled";
1822
+ environment: "environment";
1823
+ timeout: "timeout";
1824
+ "provider-auth": "provider-auth";
1825
+ stalled: "stalled";
1826
+ "stale-base": "stale-base";
1827
+ "empty-result": "empty-result";
1828
+ unfinished: "unfinished";
1829
+ "scope-violation": "scope-violation";
1830
+ "review-protocol": "review-protocol";
1831
+ merge: "merge";
1832
+ budget: "budget";
1833
+ "needs-lead": "needs-lead";
1834
+ }>;
1835
+ cause: z.ZodEnum<{
1836
+ preflight: "preflight";
1837
+ transport: "transport";
1838
+ none: "none";
1839
+ other: "other";
1840
+ "provider-auth": "provider-auth";
1841
+ stalled: "stalled";
1842
+ shutdown: "shutdown";
1843
+ "sandbox-launch": "sandbox-launch";
1844
+ "sandbox-network": "sandbox-network";
1845
+ "sandbox-filesystem": "sandbox-filesystem";
1846
+ "sandbox-policy": "sandbox-policy";
1847
+ "dependency-network": "dependency-network";
1848
+ "provider-limit": "provider-limit";
1849
+ "lease-expired": "lease-expired";
1850
+ }>;
1851
+ counted: z.ZodBoolean;
1816
1852
  }, z.core.$strict> | z.ZodObject<{
1817
1853
  leaseUntil: z.ZodNumber;
1818
1854
  }, z.core.$strict> | z.ZodObject<{
@@ -1824,6 +1860,22 @@ export declare const publishedSchemas: {
1824
1860
  }, z.core.$strict> | z.ZodObject<{
1825
1861
  resultSha: z.ZodString;
1826
1862
  integrationSha: z.ZodString;
1863
+ }, z.core.$strict> | z.ZodObject<{
1864
+ by: z.ZodEnum<{
1865
+ operator: "operator";
1866
+ recovery: "recovery";
1867
+ host: "host";
1868
+ }>;
1869
+ reset: z.ZodBoolean;
1870
+ spent: z.ZodOptional<z.ZodNumber>;
1871
+ reasonLength: z.ZodOptional<z.ZodNumber>;
1872
+ }, z.core.$strict> | z.ZodObject<{
1873
+ by: z.ZodEnum<{
1874
+ operator: "operator";
1875
+ graph: "graph";
1876
+ host: "host";
1877
+ }>;
1878
+ hadAttempt: z.ZodBoolean;
1827
1879
  }, z.core.$strict> | z.ZodObject<{
1828
1880
  code: z.ZodString;
1829
1881
  message: z.ZodString;
@@ -1863,6 +1915,12 @@ export declare const publishedSchemas: {
1863
1915
  }>;
1864
1916
  }, z.core.$strict> | z.ZodObject<{
1865
1917
  owner: z.ZodString;
1918
+ }, z.core.$strict> | z.ZodObject<{
1919
+ by: z.ZodEnum<{
1920
+ operator: "operator";
1921
+ controller: "controller";
1922
+ host: "host";
1923
+ }>;
1866
1924
  }, z.core.$strict> | z.ZodObject<{
1867
1925
  owner: z.ZodString;
1868
1926
  }, z.core.$strict> | z.ZodObject<{
@@ -2005,7 +2063,7 @@ export declare const publishedSchemas: {
2005
2063
  workId: z.ZodOptional<z.ZodString>;
2006
2064
  runId: z.ZodOptional<z.ZodString>;
2007
2065
  attempt: z.ZodOptional<z.ZodNumber>;
2008
- type: z.ZodLiteral<"graph.registered" | "graph.reviewed" | "graph.approved" | "work.ready" | "work.held" | "attempt.claimed" | "attempt.phase" | "attempt.gate" | "attempt.review" | "attempt.stage" | "attempt.liveness" | "attempt.failed" | "attempt.expired" | "attempt.cancelled" | "attempt.recovered" | "work.accepted" | "work.blocked" | "control.paused" | "control.resumed" | "controller.acquired" | "controller.released" | "budget.blocked" | "corpus.adopted" | "work.recovery" | "joint.started" | "joint.liveness" | "joint.finished" | "policy.applied" | "policy.reconfigure" | "delivery.pending" | "delivery.delivered" | "delivery.failed" | "delivery.conflict" | "delivery.uncertain">;
2066
+ type: z.ZodLiteral<"graph.registered" | "graph.reviewed" | "graph.approved" | "work.ready" | "work.held" | "attempt.claimed" | "attempt.phase" | "attempt.gate" | "attempt.review" | "attempt.stage" | "attempt.liveness" | "attempt.failed" | "attempt.diagnosed" | "attempt.expired" | "attempt.cancelled" | "attempt.recovered" | "work.accepted" | "work.retried" | "work.cancelled" | "work.blocked" | "control.paused" | "control.resumed" | "controller.acquired" | "base.moved" | "controller.released" | "budget.blocked" | "corpus.adopted" | "work.recovery" | "joint.started" | "joint.liveness" | "joint.finished" | "policy.applied" | "policy.reconfigure" | "delivery.pending" | "delivery.delivered" | "delivery.failed" | "delivery.conflict" | "delivery.uncertain">;
2009
2067
  payload: z.ZodObject<{
2010
2068
  digest: z.ZodString;
2011
2069
  orders: z.ZodNumber;
@@ -2167,6 +2225,42 @@ export declare const publishedSchemas: {
2167
2225
  }>;
2168
2226
  message: z.ZodString;
2169
2227
  blocked: z.ZodBoolean;
2228
+ }, z.core.$strict> | z.ZodObject<{
2229
+ failureKind: z.ZodEnum<{
2230
+ gate: "gate";
2231
+ unknown: "unknown";
2232
+ review: "review";
2233
+ cancelled: "cancelled";
2234
+ environment: "environment";
2235
+ timeout: "timeout";
2236
+ "provider-auth": "provider-auth";
2237
+ stalled: "stalled";
2238
+ "stale-base": "stale-base";
2239
+ "empty-result": "empty-result";
2240
+ unfinished: "unfinished";
2241
+ "scope-violation": "scope-violation";
2242
+ "review-protocol": "review-protocol";
2243
+ merge: "merge";
2244
+ budget: "budget";
2245
+ "needs-lead": "needs-lead";
2246
+ }>;
2247
+ cause: z.ZodEnum<{
2248
+ preflight: "preflight";
2249
+ transport: "transport";
2250
+ none: "none";
2251
+ other: "other";
2252
+ "provider-auth": "provider-auth";
2253
+ stalled: "stalled";
2254
+ shutdown: "shutdown";
2255
+ "sandbox-launch": "sandbox-launch";
2256
+ "sandbox-network": "sandbox-network";
2257
+ "sandbox-filesystem": "sandbox-filesystem";
2258
+ "sandbox-policy": "sandbox-policy";
2259
+ "dependency-network": "dependency-network";
2260
+ "provider-limit": "provider-limit";
2261
+ "lease-expired": "lease-expired";
2262
+ }>;
2263
+ counted: z.ZodBoolean;
2170
2264
  }, z.core.$strict> | z.ZodObject<{
2171
2265
  leaseUntil: z.ZodNumber;
2172
2266
  }, z.core.$strict> | z.ZodObject<{
@@ -2178,6 +2272,22 @@ export declare const publishedSchemas: {
2178
2272
  }, z.core.$strict> | z.ZodObject<{
2179
2273
  resultSha: z.ZodString;
2180
2274
  integrationSha: z.ZodString;
2275
+ }, z.core.$strict> | z.ZodObject<{
2276
+ by: z.ZodEnum<{
2277
+ operator: "operator";
2278
+ recovery: "recovery";
2279
+ host: "host";
2280
+ }>;
2281
+ reset: z.ZodBoolean;
2282
+ spent: z.ZodOptional<z.ZodNumber>;
2283
+ reasonLength: z.ZodOptional<z.ZodNumber>;
2284
+ }, z.core.$strict> | z.ZodObject<{
2285
+ by: z.ZodEnum<{
2286
+ operator: "operator";
2287
+ graph: "graph";
2288
+ host: "host";
2289
+ }>;
2290
+ hadAttempt: z.ZodBoolean;
2181
2291
  }, z.core.$strict> | z.ZodObject<{
2182
2292
  code: z.ZodString;
2183
2293
  message: z.ZodString;
@@ -2217,6 +2327,12 @@ export declare const publishedSchemas: {
2217
2327
  }>;
2218
2328
  }, z.core.$strict> | z.ZodObject<{
2219
2329
  owner: z.ZodString;
2330
+ }, z.core.$strict> | z.ZodObject<{
2331
+ by: z.ZodEnum<{
2332
+ operator: "operator";
2333
+ controller: "controller";
2334
+ host: "host";
2335
+ }>;
2220
2336
  }, z.core.$strict> | z.ZodObject<{
2221
2337
  owner: z.ZodString;
2222
2338
  }, z.core.$strict> | z.ZodObject<{
@@ -4173,6 +4289,36 @@ export declare const publishedSchemas: {
4173
4289
  retries: z.ZodNullable<z.ZodNumber>;
4174
4290
  resets: z.ZodNullable<z.ZodNumber>;
4175
4291
  baseMoves: z.ZodNullable<z.ZodNumber>;
4292
+ recorded: z.ZodNullable<z.ZodObject<{
4293
+ from: z.ZodISODateTime;
4294
+ bound: z.ZodEnum<{
4295
+ exact: "exact";
4296
+ lower: "lower";
4297
+ }>;
4298
+ retries: z.ZodObject<{
4299
+ operator: z.ZodNumber;
4300
+ recovery: z.ZodNumber;
4301
+ host: z.ZodNumber;
4302
+ }, z.core.$strict>;
4303
+ resets: z.ZodObject<{
4304
+ operator: z.ZodNumber;
4305
+ recovery: z.ZodNumber;
4306
+ host: z.ZodNumber;
4307
+ }, z.core.$strict>;
4308
+ cancellations: z.ZodObject<{
4309
+ operator: z.ZodNumber;
4310
+ graph: z.ZodNumber;
4311
+ host: z.ZodNumber;
4312
+ }, z.core.$strict>;
4313
+ cancelledWithoutAttempt: z.ZodNumber;
4314
+ baseMoves: z.ZodObject<{
4315
+ operator: z.ZodNumber;
4316
+ controller: z.ZodNumber;
4317
+ host: z.ZodNumber;
4318
+ }, z.core.$strict>;
4319
+ baseMovesBound: z.ZodLiteral<"lower">;
4320
+ gaps: z.ZodNumber;
4321
+ }, z.core.$strict>>;
4176
4322
  }, z.core.$strict>;
4177
4323
  approvals: z.ZodObject<{
4178
4324
  operator: z.ZodNumber;
@@ -4411,7 +4557,34 @@ export declare const publishedSchemas: {
4411
4557
  }, z.core.$strict>;
4412
4558
  setupCheckFailures: z.ZodNumber;
4413
4559
  timeLimit: z.ZodNumber;
4414
- causes: z.ZodNull;
4560
+ causes: z.ZodNullable<z.ZodObject<{
4561
+ rows: z.ZodArray<z.ZodObject<{
4562
+ cause: z.ZodEnum<{
4563
+ preflight: "preflight";
4564
+ transport: "transport";
4565
+ none: "none";
4566
+ other: "other";
4567
+ "provider-auth": "provider-auth";
4568
+ stalled: "stalled";
4569
+ shutdown: "shutdown";
4570
+ "sandbox-launch": "sandbox-launch";
4571
+ "sandbox-network": "sandbox-network";
4572
+ "sandbox-filesystem": "sandbox-filesystem";
4573
+ "sandbox-policy": "sandbox-policy";
4574
+ "dependency-network": "dependency-network";
4575
+ "provider-limit": "provider-limit";
4576
+ "lease-expired": "lease-expired";
4577
+ }>;
4578
+ count: z.ZodNumber;
4579
+ counted: z.ZodNumber;
4580
+ }, z.core.$strict>>;
4581
+ diagnosed: z.ZodNumber;
4582
+ undiagnosed: z.ZodNumber;
4583
+ bound: z.ZodEnum<{
4584
+ exact: "exact";
4585
+ lower: "lower";
4586
+ }>;
4587
+ }, z.core.$strict>>;
4415
4588
  neutral: z.ZodObject<{
4416
4589
  costBound: z.ZodEnum<{
4417
4590
  exact: "exact";
@@ -5147,6 +5320,7 @@ export declare const publishedSchemas: {
5147
5320
  unfinished: z.ZodNumber;
5148
5321
  budgets: z.ZodNumber;
5149
5322
  budgetsWithin: z.ZodNumber;
5323
+ budgetsShared: z.ZodDefault<z.ZodNumber>;
5150
5324
  repairs: z.ZodNumber;
5151
5325
  intentions: z.ZodNumber;
5152
5326
  intentionsDropped: z.ZodNumber;
@@ -258,6 +258,36 @@ export declare const valueReportSchema: z.ZodObject<{
258
258
  retries: z.ZodNullable<z.ZodNumber>;
259
259
  resets: z.ZodNullable<z.ZodNumber>;
260
260
  baseMoves: z.ZodNullable<z.ZodNumber>;
261
+ recorded: z.ZodNullable<z.ZodObject<{
262
+ from: z.ZodISODateTime;
263
+ bound: z.ZodEnum<{
264
+ exact: "exact";
265
+ lower: "lower";
266
+ }>;
267
+ retries: z.ZodObject<{
268
+ operator: z.ZodNumber;
269
+ recovery: z.ZodNumber;
270
+ host: z.ZodNumber;
271
+ }, z.core.$strict>;
272
+ resets: z.ZodObject<{
273
+ operator: z.ZodNumber;
274
+ recovery: z.ZodNumber;
275
+ host: z.ZodNumber;
276
+ }, z.core.$strict>;
277
+ cancellations: z.ZodObject<{
278
+ operator: z.ZodNumber;
279
+ graph: z.ZodNumber;
280
+ host: z.ZodNumber;
281
+ }, z.core.$strict>;
282
+ cancelledWithoutAttempt: z.ZodNumber;
283
+ baseMoves: z.ZodObject<{
284
+ operator: z.ZodNumber;
285
+ controller: z.ZodNumber;
286
+ host: z.ZodNumber;
287
+ }, z.core.$strict>;
288
+ baseMovesBound: z.ZodLiteral<"lower">;
289
+ gaps: z.ZodNumber;
290
+ }, z.core.$strict>>;
261
291
  }, z.core.$strict>;
262
292
  approvals: z.ZodObject<{
263
293
  operator: z.ZodNumber;
@@ -496,7 +526,34 @@ export declare const valueReportSchema: z.ZodObject<{
496
526
  }, z.core.$strict>;
497
527
  setupCheckFailures: z.ZodNumber;
498
528
  timeLimit: z.ZodNumber;
499
- causes: z.ZodNull;
529
+ causes: z.ZodNullable<z.ZodObject<{
530
+ rows: z.ZodArray<z.ZodObject<{
531
+ cause: z.ZodEnum<{
532
+ preflight: "preflight";
533
+ transport: "transport";
534
+ none: "none";
535
+ other: "other";
536
+ "provider-auth": "provider-auth";
537
+ stalled: "stalled";
538
+ shutdown: "shutdown";
539
+ "sandbox-launch": "sandbox-launch";
540
+ "sandbox-network": "sandbox-network";
541
+ "sandbox-filesystem": "sandbox-filesystem";
542
+ "sandbox-policy": "sandbox-policy";
543
+ "dependency-network": "dependency-network";
544
+ "provider-limit": "provider-limit";
545
+ "lease-expired": "lease-expired";
546
+ }>;
547
+ count: z.ZodNumber;
548
+ counted: z.ZodNumber;
549
+ }, z.core.$strict>>;
550
+ diagnosed: z.ZodNumber;
551
+ undiagnosed: z.ZodNumber;
552
+ bound: z.ZodEnum<{
553
+ exact: "exact";
554
+ lower: "lower";
555
+ }>;
556
+ }, z.core.$strict>>;
500
557
  neutral: z.ZodObject<{
501
558
  costBound: z.ZodEnum<{
502
559
  exact: "exact";
@@ -803,6 +860,36 @@ export declare const reportDataSchema: z.ZodUnion<readonly [z.ZodObject<{
803
860
  retries: z.ZodNullable<z.ZodNumber>;
804
861
  resets: z.ZodNullable<z.ZodNumber>;
805
862
  baseMoves: z.ZodNullable<z.ZodNumber>;
863
+ recorded: z.ZodNullable<z.ZodObject<{
864
+ from: z.ZodISODateTime;
865
+ bound: z.ZodEnum<{
866
+ exact: "exact";
867
+ lower: "lower";
868
+ }>;
869
+ retries: z.ZodObject<{
870
+ operator: z.ZodNumber;
871
+ recovery: z.ZodNumber;
872
+ host: z.ZodNumber;
873
+ }, z.core.$strict>;
874
+ resets: z.ZodObject<{
875
+ operator: z.ZodNumber;
876
+ recovery: z.ZodNumber;
877
+ host: z.ZodNumber;
878
+ }, z.core.$strict>;
879
+ cancellations: z.ZodObject<{
880
+ operator: z.ZodNumber;
881
+ graph: z.ZodNumber;
882
+ host: z.ZodNumber;
883
+ }, z.core.$strict>;
884
+ cancelledWithoutAttempt: z.ZodNumber;
885
+ baseMoves: z.ZodObject<{
886
+ operator: z.ZodNumber;
887
+ controller: z.ZodNumber;
888
+ host: z.ZodNumber;
889
+ }, z.core.$strict>;
890
+ baseMovesBound: z.ZodLiteral<"lower">;
891
+ gaps: z.ZodNumber;
892
+ }, z.core.$strict>>;
806
893
  }, z.core.$strict>;
807
894
  approvals: z.ZodObject<{
808
895
  operator: z.ZodNumber;
@@ -1041,7 +1128,34 @@ export declare const reportDataSchema: z.ZodUnion<readonly [z.ZodObject<{
1041
1128
  }, z.core.$strict>;
1042
1129
  setupCheckFailures: z.ZodNumber;
1043
1130
  timeLimit: z.ZodNumber;
1044
- causes: z.ZodNull;
1131
+ causes: z.ZodNullable<z.ZodObject<{
1132
+ rows: z.ZodArray<z.ZodObject<{
1133
+ cause: z.ZodEnum<{
1134
+ preflight: "preflight";
1135
+ transport: "transport";
1136
+ none: "none";
1137
+ other: "other";
1138
+ "provider-auth": "provider-auth";
1139
+ stalled: "stalled";
1140
+ shutdown: "shutdown";
1141
+ "sandbox-launch": "sandbox-launch";
1142
+ "sandbox-network": "sandbox-network";
1143
+ "sandbox-filesystem": "sandbox-filesystem";
1144
+ "sandbox-policy": "sandbox-policy";
1145
+ "dependency-network": "dependency-network";
1146
+ "provider-limit": "provider-limit";
1147
+ "lease-expired": "lease-expired";
1148
+ }>;
1149
+ count: z.ZodNumber;
1150
+ counted: z.ZodNumber;
1151
+ }, z.core.$strict>>;
1152
+ diagnosed: z.ZodNumber;
1153
+ undiagnosed: z.ZodNumber;
1154
+ bound: z.ZodEnum<{
1155
+ exact: "exact";
1156
+ lower: "lower";
1157
+ }>;
1158
+ }, z.core.$strict>>;
1045
1159
  neutral: z.ZodObject<{
1046
1160
  costBound: z.ZodEnum<{
1047
1161
  exact: "exact";
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { baseMoveActors, cancelActors, environmentCauses, retryActors } from "./events.js";
2
3
  import { failureKindSchema, pauseReasons } from "./execution.js";
3
4
  import { isoTimeSchema } from "./primitives.js";
4
5
  /**
@@ -101,6 +102,8 @@ const evidenceRefSchema = z.strictObject({
101
102
  blocking: count.nullable(),
102
103
  });
103
104
  const countRow = (key) => z.strictObject({ key, count });
105
+ /** Число по каждому актёру перечня. */
106
+ const actorCounts = (actors) => z.strictObject(Object.fromEntries(actors.map((a) => [a, count])));
104
107
  const weekRowSchema = z.strictObject({
105
108
  kind: z.literal('week'),
106
109
  week,
@@ -258,9 +261,41 @@ export const valueReportSchema = z.strictObject({
258
261
  /** Удержания и отмены попыток: актёр не записан, к действиям человека не относятся. */
259
262
  holds: count,
260
263
  cancelledAttempts: count,
264
+ /**
265
+ * Повторы и сбросы в окне по событиям — только точные: `null`, если
266
+ * событий вмешательств нет или запись не покрывает окно (числа по
267
+ * актёрам — в `recorded`). `baseMoves` — всегда `null`: сдвиг базы вне
268
+ * `fencedRefMove` не записывается, его число — нижняя граница.
269
+ */
261
270
  retries: count.nullable(),
262
271
  resets: count.nullable(),
263
272
  baseMoves: count.nullable(),
273
+ /**
274
+ * Актёры вмешательств из событий `work.retried`, `work.cancelled`,
275
+ * `base.moved`; `null` — таких событий в журнале нет (записаны до
276
+ * версии, которая их пишет). `from` — первое такое событие; `bound:
277
+ * lower` — в окне есть активность раньше него.
278
+ */
279
+ recorded: z
280
+ .strictObject({
281
+ from: isoTimeSchema,
282
+ bound: z.enum(['exact', 'lower']),
283
+ retries: actorCounts(retryActors),
284
+ resets: actorCounts(retryActors),
285
+ cancellations: actorCounts(cancelActors),
286
+ /** Отмены поручений без активной попытки (их `attempt.cancelled` нет). */
287
+ cancelledWithoutAttempt: count,
288
+ baseMoves: actorCounts(baseMoveActors),
289
+ /** Сдвиги базы — всегда нижняя граница: перенос вне `fencedRefMove` не пишется. */
290
+ baseMovesBound: z.literal('lower'),
291
+ /**
292
+ * Поручения окна с новой попыткой после отказа или отмены без
293
+ * записанного повтора (между ними работала версия без событий):
294
+ * пробел записи, `bound: lower`.
295
+ */
296
+ gaps: count,
297
+ })
298
+ .nullable(),
264
299
  }),
265
300
  approvals: z.strictObject({
266
301
  operator: count,
@@ -363,8 +398,31 @@ export const valueReportSchema = z.strictObject({
363
398
  /** Отказы `defect` только в gates подготовки: возможно, тоже окружение (сеть, реестр). */
364
399
  setupCheckFailures: count,
365
400
  timeLimit: count,
366
- /** Подпричина отказа окружения ещё не записывается. */
367
- causes: z.null(),
401
+ /**
402
+ * Подпричины отказов окружения по `attempt.diagnosed`; `null` — таких
403
+ * событий в журнале нет. `undiagnosed` — отказы окружения окна без
404
+ * события (записаны раньше): тогда `bound: lower`.
405
+ */
406
+ causes: z
407
+ .strictObject({
408
+ rows: z
409
+ .array(z.strictObject({
410
+ cause: z.enum(environmentCauses),
411
+ count,
412
+ /** Из них засчитаны в предел попыток. */
413
+ counted: count,
414
+ }))
415
+ .max(environmentCauses.length),
416
+ diagnosed: count,
417
+ undiagnosed: count,
418
+ bound: z.enum(['exact', 'lower']),
419
+ })
420
+ .nullable(),
421
+ /**
422
+ * Цена отказов окружения: попытки корзины `environment` — и зависания
423
+ * (`stalled`), хотя они засчитаны в предел попыток; `blocked` — из них
424
+ * отказы до работы.
425
+ */
368
426
  neutral: z.strictObject({
369
427
  costBound: z.enum(reportBounds),
370
428
  attempts: count,
@@ -388,7 +446,7 @@ export const valueReportSchema = z.strictObject({
388
446
  limitations: z
389
447
  .array(z.strictObject({ id: z.string().min(1).max(60), text: sentence }))
390
448
  .min(1)
391
- .max(30),
449
+ .max(40),
392
450
  });
393
451
  /** `harness report --out`: отчёт записан в файл, в ответе — куда и сколько. */
394
452
  export const reportFileSchema = z.strictObject({
@@ -1,4 +1,4 @@
1
- import type { ExecutionPolicy, ExecutionStore, ExecutionView } from '../contracts/index.ts';
1
+ import { type BaseMoveActor, type ExecutionPolicy, type ExecutionStore, type ExecutionView } from '../contracts/index.ts';
2
2
  /** Сдвиг ref: репозиторий, ref, новое и ожидаемое прежнее значение. */
3
3
  export type RefMove = (repoPath: string, target: string, to: string, from: string) => void | Promise<void>;
4
4
  /**
@@ -8,7 +8,12 @@ export type RefMove = (repoPath: string, target: string, to: string, from: strin
8
8
  * исполняется чужой код: hook `reference-transaction`, ждущий ту же базу,
9
9
  * ждал бы её, а она — его; срок Git ограничен, зависший Git не держит базу.
10
10
  */
11
- export declare function fencedRefMove(store: ExecutionStore, fence: (view: ExecutionView) => void, timeoutMs?: number): RefMove;
11
+ /**
12
+ * Сдвиг записывается событием `base.moved` в той же транзакции: отказ
13
+ * проверки или Git отменяет и событие. `by` — кто сдвигает: controller
14
+ * (перемотка очереди) или оператор; хост, не назвавший актёра, — `host`.
15
+ */
16
+ export declare function fencedRefMove(store: ExecutionStore, fence: (view: ExecutionView) => void, timeoutMs?: number, by?: BaseMoveActor): RefMove;
12
17
  export declare namespace fencedRefMove {
13
18
  var timeoutMs: number;
14
19
  }
@@ -1,6 +1,8 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { mkdir } from 'node:fs/promises';
3
3
  import { dirname, isAbsolute, join, resolve } from 'node:path';
4
+ import { z } from 'zod';
5
+ import { HarnessError, baseMoveActors, } from "../contracts/index.js";
4
6
  import { git, hostGitArgs } from "../environment/process.js";
5
7
  import { checkoutPath, chooseCheckoutRoot } from "../environment/checkout-root.js";
6
8
  import { credentialPaths } from "../environment/isolation.js";
@@ -11,7 +13,17 @@ import { credentialPaths } from "../environment/isolation.js";
11
13
  * исполняется чужой код: hook `reference-transaction`, ждущий ту же базу,
12
14
  * ждал бы её, а она — его; срок Git ограничен, зависший Git не держит базу.
13
15
  */
14
- export function fencedRefMove(store, fence, timeoutMs = fencedRefMove.timeoutMs) {
16
+ /**
17
+ * Сдвиг записывается событием `base.moved` в той же транзакции: отказ
18
+ * проверки или Git отменяет и событие. `by` — кто сдвигает: controller
19
+ * (перемотка очереди) или оператор; хост, не назвавший актёра, — `host`.
20
+ */
21
+ export function fencedRefMove(store, fence, timeoutMs = fencedRefMove.timeoutMs, by = 'host') {
22
+ // Актёр проверяется до любого сдвига: недопустимое значение — отказ без git update-ref.
23
+ const parsed = z.enum(baseMoveActors).safeParse(by);
24
+ if (!parsed.success)
25
+ throw new HarnessError('INVALID_INPUT', `Недопустимый актёр сдвига базы: ${String(by).slice(0, 60)}`);
26
+ const actor = parsed.data;
15
27
  return (repoPath, target, to, from) => store.transact('base.moved', (tx) => {
16
28
  fence(tx);
17
29
  execFileSync('git', hostGitArgs(repoPath, ['update-ref', target, to, from]), {
@@ -19,6 +31,7 @@ export function fencedRefMove(store, fence, timeoutMs = fencedRefMove.timeoutMs)
19
31
  timeout: timeoutMs,
20
32
  stdio: 'pipe',
21
33
  });
34
+ tx.emit({ type: 'base.moved', payload: { by: actor } });
22
35
  });
23
36
  }
24
37
  /** Предел git update-ref внутри транзакции; конечный и короче lease. */