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

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 (125) hide show
  1. package/README.md +22 -2
  2. package/docs/contracts.md +309 -35
  3. package/docs/release-notes/0.1.0-alpha.35.md +27 -0
  4. package/docs/release-notes/0.1.0-alpha.36.md +26 -0
  5. package/docs/release-notes/0.1.0-alpha.37.md +40 -0
  6. package/docs/standalone.md +20 -0
  7. package/docs/toolchains.md +57 -2
  8. package/docs/upgrade.md +143 -0
  9. package/lib/agents/cli-adapter.d.ts +10 -1
  10. package/lib/agents/cli-adapter.js +38 -7
  11. package/lib/agents/schemas.d.ts +84 -2
  12. package/lib/agents/schemas.js +49 -1
  13. package/lib/agents/usage.d.ts +9 -0
  14. package/lib/agents/usage.js +22 -1
  15. package/lib/cli.js +149 -1
  16. package/lib/contracts/cli.d.ts +1544 -171
  17. package/lib/contracts/cli.js +233 -2
  18. package/lib/contracts/diagnosis.d.ts +10 -4
  19. package/lib/contracts/diagnosis.js +4 -0
  20. package/lib/contracts/errors.d.ts +9 -1
  21. package/lib/contracts/errors.js +8 -0
  22. package/lib/contracts/events.d.ts +468 -60
  23. package/lib/contracts/events.js +79 -0
  24. package/lib/contracts/execution.d.ts +301 -50
  25. package/lib/contracts/execution.js +60 -0
  26. package/lib/contracts/failure.d.ts +20 -3
  27. package/lib/contracts/failure.js +14 -2
  28. package/lib/contracts/handoff.d.ts +79 -20
  29. package/lib/contracts/handoff.js +42 -1
  30. package/lib/contracts/index.d.ts +1 -0
  31. package/lib/contracts/index.js +1 -0
  32. package/lib/contracts/input-state.d.ts +13 -0
  33. package/lib/contracts/input-state.js +32 -0
  34. package/lib/contracts/input.d.ts +442 -0
  35. package/lib/contracts/input.js +321 -0
  36. package/lib/contracts/planning.d.ts +4 -0
  37. package/lib/contracts/policy.d.ts +17 -2
  38. package/lib/contracts/policy.js +31 -2
  39. package/lib/contracts/ports.d.ts +64 -2
  40. package/lib/contracts/project.d.ts +127 -0
  41. package/lib/contracts/project.js +99 -0
  42. package/lib/contracts/published.d.ts +631 -92
  43. package/lib/contracts/published.js +4 -1
  44. package/lib/contracts/repair-policy.d.ts +30 -1
  45. package/lib/contracts/repair-policy.js +52 -0
  46. package/lib/contracts/report.d.ts +55 -21
  47. package/lib/contracts/report.js +33 -2
  48. package/lib/contracts/result.d.ts +28 -24
  49. package/lib/contracts/review.d.ts +47 -8
  50. package/lib/contracts/review.js +21 -1
  51. package/lib/control/harness.d.ts +2555 -51
  52. package/lib/control/harness.js +112 -6
  53. package/lib/control/recovery.d.ts +2 -2
  54. package/lib/control/report.js +1 -0
  55. package/lib/control/status.d.ts +30 -22
  56. package/lib/control/status.js +11 -1
  57. package/lib/control/workflow.d.ts +8 -8
  58. package/lib/engine/budget.d.ts +86 -3
  59. package/lib/engine/budget.js +45 -10
  60. package/lib/engine/classify.js +1 -1
  61. package/lib/engine/engine.d.ts +3091 -83
  62. package/lib/engine/engine.js +1209 -101
  63. package/lib/engine/failure.d.ts +1 -1
  64. package/lib/engine/failure.js +1 -1
  65. package/lib/engine/input-policy.d.ts +68 -0
  66. package/lib/engine/input-policy.js +285 -0
  67. package/lib/engine/input-requests.d.ts +64 -0
  68. package/lib/engine/input-requests.js +187 -0
  69. package/lib/engine/measured.d.ts +6 -1
  70. package/lib/engine/measured.js +12 -1
  71. package/lib/engine/prompt.d.ts +4 -2
  72. package/lib/engine/prompt.js +13 -1
  73. package/lib/engine/property-recovery.js +4 -0
  74. package/lib/engine/repair.d.ts +2 -0
  75. package/lib/engine/repair.js +13 -4
  76. package/lib/engine/reuse.js +2 -0
  77. package/lib/engine/runner.d.ts +33 -4
  78. package/lib/engine/runner.js +275 -23
  79. package/lib/environment/lifecycle.d.ts +8 -0
  80. package/lib/environment/lifecycle.js +15 -2
  81. package/lib/explain/state.d.ts +16 -2
  82. package/lib/explain/state.js +262 -79
  83. package/lib/handoff/markdown.js +10 -0
  84. package/lib/handoff/pack.js +42 -1
  85. package/lib/index.d.ts +11 -1
  86. package/lib/index.js +11 -1
  87. package/lib/init/inspect.d.ts +34 -0
  88. package/lib/init/inspect.js +292 -0
  89. package/lib/init/project.js +14 -31
  90. package/lib/integrations/connector/commands.d.ts +12 -12
  91. package/lib/integrations/connector/config.d.ts +4 -4
  92. package/lib/integrations/connector/delivery.d.ts +1 -1
  93. package/lib/integrations/relay-v2/protocol.d.ts +4 -4
  94. package/lib/profiles/resolve.d.ts +2 -1
  95. package/lib/projections/enums.d.ts +1 -1
  96. package/lib/projections/enums.js +4 -0
  97. package/lib/projections/index.d.ts +1 -0
  98. package/lib/projections/index.js +1 -0
  99. package/lib/projections/input.d.ts +17 -0
  100. package/lib/projections/input.js +28 -0
  101. package/lib/projections/stop.d.ts +42 -1
  102. package/lib/projections/stop.js +117 -6
  103. package/lib/report/compute.d.ts +4 -1
  104. package/lib/report/compute.js +26 -0
  105. package/lib/report/document.js +2 -1
  106. package/lib/storage/document.d.ts +68 -28
  107. package/lib/testing/index.d.ts +1 -1
  108. package/lib/testing/index.js +1 -1
  109. package/lib/testing/store-contract.d.ts +8 -1
  110. package/lib/testing/store-contract.js +194 -1
  111. package/lib/verification/confirm.d.ts +3 -3
  112. package/lib/verification/corpus.d.ts +9 -9
  113. package/lib/verification/gates.d.ts +119 -0
  114. package/lib/verification/gates.js +311 -4
  115. package/package.json +1 -1
  116. package/schemas/execution-document.schema.json +141 -0
  117. package/schemas/execution-policy.schema.json +26 -0
  118. package/schemas/handoff-pack.schema.json +155 -4
  119. package/schemas/input-request.schema.json +665 -0
  120. package/schemas/project-facts.schema.json +393 -0
  121. package/schemas/result-envelope.schema.json +2 -0
  122. package/schemas/run-event.schema.json +628 -0
  123. package/schemas/run-result.schema.json +2 -0
  124. package/schemas/stop-diagnosis.schema.json +7 -1
  125. package/schemas/value-report.schema.json +79 -7
@@ -6,6 +6,7 @@ import { contextPinSchema, contextSnapshotSchema } from "./context.js";
6
6
  import { deliveryStateSchema, gateArtifactFilesSchema, jointActiveSchema, jointFailedSchema, jointPassedSchema, } from "./result.js";
7
7
  import { findingStatuses, reviewRecordSchema, reviewRoundSchema } from "./review.js";
8
8
  import { contractDocumentSchema, spikeSchema } from "./checks.js";
9
+ import { INPUT_LIMITS, inputPolicySchema, inputRequestSchema, recordedAssumptionSchema, } from "./input.js";
9
10
  /**
10
11
  * Нейтральная модель исполнения — то, что ExecutionStore обязан хранить
11
12
  * транзакционно. Формы совпадают с записями задач и попыток DevContour
@@ -40,6 +41,14 @@ export const failureKinds = [
40
41
  * controller остановил его. Действие — повтор или правка среды, не кода.
41
42
  */
42
43
  'stalled',
44
+ /**
45
+ * Исполнителю не хватило окна контекста модели внутри попытки: runtime
46
+ * сам сообщил, что запрос больше окна (claude: `terminal_reason`
47
+ * `prompt_too_long` или `blocking_limit`). Успешное автоматическое сжатие
48
+ * контекста отказом не является. Попытка засчитывается: задача не
49
+ * помещается в попытку — её нужно разделить или сократить контекст.
50
+ */
51
+ 'context-exhausted',
43
52
  'stale-base',
44
53
  'empty-result',
45
54
  /** Исполнитель сообщил `completed: false`: работа не доделана, черновик сохранён. */
@@ -57,9 +66,25 @@ export const failureKinds = [
57
66
  * сделанной механически нет: решение — за ведущим, не повтор.
58
67
  */
59
68
  'needs-lead',
69
+ /**
70
+ * Исполнитель остановился с вопросом, серьёзность которого не ниже порога
71
+ * закреплённой `inputPolicy`: запрос записан в `input-requests` той же
72
+ * транзакцией, черновик сохранён. Попытка засчитана; автоматического
73
+ * повтора нет — продолжение только после ответа и `applyInput`.
74
+ */
75
+ 'needs-input',
60
76
  'unknown',
61
77
  ];
62
78
  export const failureKindSchema = z.enum(failureKinds);
79
+ /**
80
+ * Какой предел окна контекста сообщил runtime у отказа `context-exhausted`:
81
+ * `prompt-too-long` — запрос отклонён (claude `terminal_reason:
82
+ * prompt_too_long`, уже одна реплика больше окна; повтор только удлинит
83
+ * подсказку), `blocking-limit` — ход остановлен у предела окна (claude
84
+ * `blocking_limit`).
85
+ */
86
+ export const contextLimits = ['prompt-too-long', 'blocking-limit'];
87
+ export const contextLimitSchema = z.enum(contextLimits);
63
88
  /**
64
89
  * Живость исполняющейся попытки по периодическому обходу controller
65
90
  * (`stallSweep` политики): `active` — движение было недавно, `quiet` — нет
@@ -428,6 +453,8 @@ export const attemptStateSchema = z.strictObject({
428
453
  /** Отказ окружения: исполнителю не дали работать, попытка не засчитана. */
429
454
  blocked: z.boolean().optional(),
430
455
  failureKind: failureKindSchema.optional(),
456
+ /** Предел окна контекста — только у отказа `context-exhausted`. */
457
+ contextLimit: contextLimitSchema.optional(),
431
458
  failureFingerprint: z.string().optional(),
432
459
  /** Gates, которые попытка обязана пройти в обеих фазах (раскрытая область). */
433
460
  requiredGates: z.array(idSchema).optional(),
@@ -469,6 +496,25 @@ export const attemptStateSchema = z.strictObject({
469
496
  .optional(),
470
497
  partial: partialDraftSchema.optional(),
471
498
  continuedFrom: continuationSchema.optional(),
499
+ /**
500
+ * Политика вопросов исполнителя, закреплённая при выдаче: смена порога
501
+ * действует со следующей попытки. Нет у попыток прежних версий.
502
+ */
503
+ inputPolicy: inputPolicySchema.optional(),
504
+ /** Развилки, решённые исполнителем, с оценкой controller (не больше 20). */
505
+ assumptions: z.array(recordedAssumptionSchema).max(INPUT_LIMITS.assumptions).optional(),
506
+ /**
507
+ * Ответ на вопрос, с которым выдана попытка: запрос, точный ответ и
508
+ * основание продолжения. Связывается при claim, только если применённое
509
+ * основание совпало с основанием выдачи.
510
+ */
511
+ input: z
512
+ .strictObject({
513
+ requestId: z.string().min(1).max(200),
514
+ answerDigest: digestSchema,
515
+ targetDigest: digestSchema,
516
+ })
517
+ .optional(),
472
518
  callsRecorded: z.literal(true).optional(),
473
519
  dispatch: z
474
520
  .strictObject({
@@ -514,6 +560,12 @@ export const attemptStateSchema = z.strictObject({
514
560
  ref: z.string().min(1).max(300),
515
561
  revision: z.string().min(1).max(200),
516
562
  }),
563
+ /**
564
+ * Действующий снимок контекста на момент выдачи (`null` — без
565
+ * контекста): runner загружает именно его. Нет — хост не связывает
566
+ * согласование с контекстом (или попытка прежней версии).
567
+ */
568
+ contextDigest: digestSchema.nullable().optional(),
517
569
  })
518
570
  .optional(),
519
571
  /**
@@ -1012,6 +1064,14 @@ export const localSchemas = {
1012
1064
  * передаются следующей попытке.
1013
1065
  */
1014
1066
  reproductions: reproductionRegistrySchema,
1067
+ /**
1068
+ * Вопросы исполнителей и ответы на них (`InputRequest`) по владельцу —
1069
+ * репозиторию поручения. Вопрос и основание неизменяемы, ответы только
1070
+ * дополняются, `version` — CAS записи: это правила движка (все записи —
1071
+ * через его операции); хранилище хранит запись целиком, как записана, и
1072
+ * отдаёт её в списке без владельца с `owner` и `key` (`executionStoreContract`).
1073
+ */
1074
+ 'input-requests': inputRequestSchema,
1015
1075
  };
1016
1076
  /* ------------------------------------------------------------------ */
1017
1077
  /* Документ standalone */
@@ -1,5 +1,6 @@
1
- import type { FailureKind } from './execution.ts';
1
+ import type { ContextLimit, FailureKind } from './execution.ts';
2
2
  import type { EnvironmentCause } from './events.ts';
3
+ import type { InputOutcome } from './input.ts';
3
4
  /** Отказ окружения до начала работы: попытка не засчитывается. */
4
5
  export declare class BlockedError extends Error {
5
6
  name: string;
@@ -25,6 +26,14 @@ export declare class TaskFailure extends Error {
25
26
  } | undefined;
26
27
  /** Причина отказа окружения, известная в точке обнаружения (`attempt.diagnosed`). */
27
28
  readonly diagnosis?: EnvironmentCause | undefined;
29
+ /** Предел окна контекста у отказа `context-exhausted`, сообщённый runtime. */
30
+ readonly contextLimit?: ContextLimit | undefined;
31
+ /**
32
+ * Вопрос, допущения и неблокирующие запросы из ответа writer
33
+ * (`needs-input`, `unfinished`): движок записывает их в той же
34
+ * транзакции, что и отказ.
35
+ */
36
+ readonly input?: InputOutcome | undefined;
28
37
  constructor(kind: FailureKind, message: string,
29
38
  /**
30
39
  * Свойства, с которыми связан отказ: `bound` — объявленные задачей
@@ -43,7 +52,15 @@ export declare class TaskFailure extends Error {
43
52
  }[];
44
53
  } | undefined,
45
54
  /** Причина отказа окружения, известная в точке обнаружения (`attempt.diagnosed`). */
46
- diagnosis?: EnvironmentCause | undefined);
55
+ diagnosis?: EnvironmentCause | undefined,
56
+ /** Предел окна контекста у отказа `context-exhausted`, сообщённый runtime. */
57
+ contextLimit?: ContextLimit | undefined,
58
+ /**
59
+ * Вопрос, допущения и неблокирующие запросы из ответа writer
60
+ * (`needs-input`, `unfinished`): движок записывает их в той же
61
+ * транзакции, что и отказ.
62
+ */
63
+ input?: InputOutcome | undefined);
47
64
  }
48
65
  /**
49
66
  * Отпечаток отказа: одинаковые сбои должны совпадать, разные — расходиться.
@@ -54,4 +71,4 @@ export declare class TaskFailure extends Error {
54
71
  * повторов не сработал бы ни разу.
55
72
  */
56
73
  export declare function failureFingerprint(kind: FailureKind, message: string): string;
57
- export { MAX_NEUTRAL_FAILURES, repairPolicy, type RepairRule } from './repair-policy.ts';
74
+ export { MAX_NEUTRAL_FAILURES, lastContextLimit, repairPolicy, repairRepeats, type RepairRule, } from './repair-policy.ts';
@@ -8,6 +8,8 @@ export class TaskFailure extends Error {
8
8
  kind;
9
9
  properties;
10
10
  diagnosis;
11
+ contextLimit;
12
+ input;
11
13
  constructor(kind, message,
12
14
  /**
13
15
  * Свойства, с которыми связан отказ: `bound` — объявленные задачей
@@ -18,11 +20,21 @@ export class TaskFailure extends Error {
18
20
  */
19
21
  properties,
20
22
  /** Причина отказа окружения, известная в точке обнаружения (`attempt.diagnosed`). */
21
- diagnosis) {
23
+ diagnosis,
24
+ /** Предел окна контекста у отказа `context-exhausted`, сообщённый runtime. */
25
+ contextLimit,
26
+ /**
27
+ * Вопрос, допущения и неблокирующие запросы из ответа writer
28
+ * (`needs-input`, `unfinished`): движок записывает их в той же
29
+ * транзакции, что и отказ.
30
+ */
31
+ input) {
22
32
  super(message);
23
33
  this.kind = kind;
24
34
  this.properties = properties;
25
35
  this.diagnosis = diagnosis;
36
+ this.contextLimit = contextLimit;
37
+ this.input = input;
26
38
  this.name = 'TaskFailure';
27
39
  }
28
40
  }
@@ -56,4 +68,4 @@ export function failureFingerprint(kind, message) {
56
68
  .digest('hex')
57
69
  .slice(0, 16);
58
70
  }
59
- export { MAX_NEUTRAL_FAILURES, repairPolicy } from "./repair-policy.js";
71
+ export { MAX_NEUTRAL_FAILURES, lastContextLimit, repairPolicy, repairRepeats, } from "./repair-policy.js";
@@ -38,6 +38,10 @@ export declare const HANDOFF_LIMITS: {
38
38
  /** Намерения агента и знаков в каждом. */
39
39
  readonly intentions: 20;
40
40
  readonly intentionChars: 1000;
41
+ /** Вопросы исполнителя (открытые запросы), вопросы первыми. */
42
+ readonly inputs: 10;
43
+ /** Знаков ответа в пакете (`answer.excerpt`). */
44
+ readonly answerChars: 500;
41
45
  /** Предел строки факта из хранилища. */
42
46
  readonly text: 300;
43
47
  /** Предел идентификатора, имени стадии, владельца из хранилища. */
@@ -70,10 +74,10 @@ export declare const handoffPackSchema: z.ZodObject<{
70
74
  cancelled: z.ZodNumber;
71
75
  byStatus: z.ZodArray<z.ZodObject<{
72
76
  status: z.ZodEnum<{
73
- ready: "ready";
74
- failed: "failed";
75
77
  cancelled: "cancelled";
76
78
  draft: "draft";
79
+ ready: "ready";
80
+ failed: "failed";
77
81
  running: "running";
78
82
  verifying: "verifying";
79
83
  reviewing: "reviewing";
@@ -86,8 +90,8 @@ export declare const handoffPackSchema: z.ZodObject<{
86
90
  queue: z.ZodObject<{
87
91
  paused: z.ZodBoolean;
88
92
  reason: z.ZodOptional<z.ZodEnum<{
89
- runtime: "runtime";
90
93
  operator: "operator";
94
+ runtime: "runtime";
91
95
  shutdown: "shutdown";
92
96
  "base-check": "base-check";
93
97
  reconfigure: "reconfigure";
@@ -104,6 +108,7 @@ export declare const handoffPackSchema: z.ZodObject<{
104
108
  timeout: "timeout";
105
109
  "provider-auth": "provider-auth";
106
110
  stalled: "stalled";
111
+ "context-exhausted": "context-exhausted";
107
112
  "stale-base": "stale-base";
108
113
  "empty-result": "empty-result";
109
114
  unfinished: "unfinished";
@@ -112,6 +117,7 @@ export declare const handoffPackSchema: z.ZodObject<{
112
117
  merge: "merge";
113
118
  budget: "budget";
114
119
  "needs-lead": "needs-lead";
120
+ "needs-input": "needs-input";
115
121
  }>>>;
116
122
  liftedByRun: z.ZodOptional<z.ZodLiteral<true>>;
117
123
  code: z.ZodOptional<z.ZodEnum<{
@@ -138,6 +144,8 @@ export declare const handoffPackSchema: z.ZodObject<{
138
144
  BUDGET_EXHAUSTED: "BUDGET_EXHAUSTED";
139
145
  BUDGET_UNKNOWN: "BUDGET_UNKNOWN";
140
146
  ATTEMPTS_EXHAUSTED: "ATTEMPTS_EXHAUSTED";
147
+ CONTEXT_EXHAUSTED: "CONTEXT_EXHAUSTED";
148
+ INPUT_REQUIRED: "INPUT_REQUIRED";
141
149
  REVISION_CONFLICT: "REVISION_CONFLICT";
142
150
  CANCELLED: "CANCELLED";
143
151
  NOT_FOUND: "NOT_FOUND";
@@ -152,8 +160,8 @@ export declare const handoffPackSchema: z.ZodObject<{
152
160
  INTERNAL: "INTERNAL";
153
161
  }>>;
154
162
  actor: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
155
- controller: "controller";
156
163
  lead: "lead";
164
+ controller: "controller";
157
165
  user: "user";
158
166
  }>>>;
159
167
  action: z.ZodOptional<z.ZodEnum<{
@@ -170,6 +178,8 @@ export declare const handoffPackSchema: z.ZodObject<{
170
178
  "resume-queue": "resume-queue";
171
179
  "fix-environment": "fix-environment";
172
180
  "fix-access": "fix-access";
181
+ "answer-input": "answer-input";
182
+ "apply-input": "apply-input";
173
183
  }>>;
174
184
  }, z.core.$strict>;
175
185
  controller: z.ZodOptional<z.ZodObject<{
@@ -183,10 +193,10 @@ export declare const handoffPackSchema: z.ZodObject<{
183
193
  runId: z.ZodString;
184
194
  attempt: z.ZodNumber;
185
195
  phase: z.ZodEnum<{
186
- ready: "ready";
187
- failed: "failed";
188
196
  cancelled: "cancelled";
189
197
  draft: "draft";
198
+ ready: "ready";
199
+ failed: "failed";
190
200
  running: "running";
191
201
  verifying: "verifying";
192
202
  reviewing: "reviewing";
@@ -218,10 +228,10 @@ export declare const handoffPackSchema: z.ZodObject<{
218
228
  workId: z.ZodString;
219
229
  attempt: z.ZodNumber;
220
230
  phase: z.ZodEnum<{
221
- ready: "ready";
222
- failed: "failed";
223
231
  cancelled: "cancelled";
224
232
  draft: "draft";
233
+ ready: "ready";
234
+ failed: "failed";
225
235
  running: "running";
226
236
  verifying: "verifying";
227
237
  reviewing: "reviewing";
@@ -238,10 +248,10 @@ export declare const handoffPackSchema: z.ZodObject<{
238
248
  graphId: z.ZodString;
239
249
  title: z.ZodString;
240
250
  status: z.ZodEnum<{
241
- ready: "ready";
242
- failed: "failed";
243
251
  cancelled: "cancelled";
244
252
  draft: "draft";
253
+ ready: "ready";
254
+ failed: "failed";
245
255
  running: "running";
246
256
  verifying: "verifying";
247
257
  reviewing: "reviewing";
@@ -258,6 +268,7 @@ export declare const handoffPackSchema: z.ZodObject<{
258
268
  timeout: "timeout";
259
269
  "provider-auth": "provider-auth";
260
270
  stalled: "stalled";
271
+ "context-exhausted": "context-exhausted";
261
272
  "stale-base": "stale-base";
262
273
  "empty-result": "empty-result";
263
274
  unfinished: "unfinished";
@@ -266,6 +277,7 @@ export declare const handoffPackSchema: z.ZodObject<{
266
277
  merge: "merge";
267
278
  budget: "budget";
268
279
  "needs-lead": "needs-lead";
280
+ "needs-input": "needs-input";
269
281
  }>>;
270
282
  failure: z.ZodOptional<z.ZodString>;
271
283
  hold: z.ZodOptional<z.ZodObject<{
@@ -303,6 +315,8 @@ export declare const handoffPackSchema: z.ZodObject<{
303
315
  BUDGET_EXHAUSTED: "BUDGET_EXHAUSTED";
304
316
  BUDGET_UNKNOWN: "BUDGET_UNKNOWN";
305
317
  ATTEMPTS_EXHAUSTED: "ATTEMPTS_EXHAUSTED";
318
+ CONTEXT_EXHAUSTED: "CONTEXT_EXHAUSTED";
319
+ INPUT_REQUIRED: "INPUT_REQUIRED";
306
320
  REVISION_CONFLICT: "REVISION_CONFLICT";
307
321
  CANCELLED: "CANCELLED";
308
322
  NOT_FOUND: "NOT_FOUND";
@@ -321,8 +335,8 @@ export declare const handoffPackSchema: z.ZodObject<{
321
335
  blockersTruncated: z.ZodOptional<z.ZodNumber>;
322
336
  next: z.ZodObject<{
323
337
  actor: z.ZodNullable<z.ZodEnum<{
324
- controller: "controller";
325
338
  lead: "lead";
339
+ controller: "controller";
326
340
  user: "user";
327
341
  }>>;
328
342
  action: z.ZodEnum<{
@@ -339,10 +353,12 @@ export declare const handoffPackSchema: z.ZodObject<{
339
353
  "resume-queue": "resume-queue";
340
354
  "fix-environment": "fix-environment";
341
355
  "fix-access": "fix-access";
356
+ "answer-input": "answer-input";
357
+ "apply-input": "apply-input";
342
358
  }>;
343
359
  step: z.ZodOptional<z.ZodEnum<{
344
- accepted: "accepted";
345
360
  cancelled: "cancelled";
361
+ accepted: "accepted";
346
362
  "recovery-awaiting-lead": "recovery-awaiting-lead";
347
363
  "recovery-analyzing": "recovery-analyzing";
348
364
  "recovery-applying": "recovery-applying";
@@ -391,6 +407,8 @@ export declare const handoffPackSchema: z.ZodObject<{
391
407
  BUDGET_EXHAUSTED: "BUDGET_EXHAUSTED";
392
408
  BUDGET_UNKNOWN: "BUDGET_UNKNOWN";
393
409
  ATTEMPTS_EXHAUSTED: "ATTEMPTS_EXHAUSTED";
410
+ CONTEXT_EXHAUSTED: "CONTEXT_EXHAUSTED";
411
+ INPUT_REQUIRED: "INPUT_REQUIRED";
394
412
  REVISION_CONFLICT: "REVISION_CONFLICT";
395
413
  CANCELLED: "CANCELLED";
396
414
  NOT_FOUND: "NOT_FOUND";
@@ -413,6 +431,7 @@ export declare const handoffPackSchema: z.ZodObject<{
413
431
  timeout: "timeout";
414
432
  "provider-auth": "provider-auth";
415
433
  stalled: "stalled";
434
+ "context-exhausted": "context-exhausted";
416
435
  "stale-base": "stale-base";
417
436
  "empty-result": "empty-result";
418
437
  unfinished: "unfinished";
@@ -421,6 +440,7 @@ export declare const handoffPackSchema: z.ZodObject<{
421
440
  merge: "merge";
422
441
  budget: "budget";
423
442
  "needs-lead": "needs-lead";
443
+ "needs-input": "needs-input";
424
444
  "runtime-missing": "runtime-missing";
425
445
  "controller-busy": "controller-busy";
426
446
  "operator-pause": "operator-pause";
@@ -429,16 +449,16 @@ export declare const handoffPackSchema: z.ZodObject<{
429
449
  }>;
430
450
  phase: z.ZodEnum<{
431
451
  gates: "gates";
432
- preflight: "preflight";
433
452
  review: "review";
453
+ preflight: "preflight";
434
454
  integration: "integration";
435
455
  delivery: "delivery";
436
456
  claim: "claim";
437
457
  implementation: "implementation";
438
458
  }>;
439
459
  actor: z.ZodNullable<z.ZodEnum<{
440
- controller: "controller";
441
460
  lead: "lead";
461
+ controller: "controller";
442
462
  user: "user";
443
463
  }>>;
444
464
  action: z.ZodEnum<{
@@ -455,6 +475,8 @@ export declare const handoffPackSchema: z.ZodObject<{
455
475
  "resume-queue": "resume-queue";
456
476
  "fix-environment": "fix-environment";
457
477
  "fix-access": "fix-access";
478
+ "answer-input": "answer-input";
479
+ "apply-input": "apply-input";
458
480
  }>;
459
481
  retryPlanned: z.ZodBoolean;
460
482
  message: z.ZodString;
@@ -478,10 +500,10 @@ export declare const handoffPackSchema: z.ZodObject<{
478
500
  runId: z.ZodString;
479
501
  workId: z.ZodString;
480
502
  workStatus: z.ZodOptional<z.ZodEnum<{
481
- ready: "ready";
482
- failed: "failed";
483
503
  cancelled: "cancelled";
484
504
  draft: "draft";
505
+ ready: "ready";
506
+ failed: "failed";
485
507
  running: "running";
486
508
  verifying: "verifying";
487
509
  reviewing: "reviewing";
@@ -494,10 +516,10 @@ export declare const handoffPackSchema: z.ZodObject<{
494
516
  expired: "expired";
495
517
  }>;
496
518
  phase: z.ZodEnum<{
497
- ready: "ready";
498
- failed: "failed";
499
519
  cancelled: "cancelled";
500
520
  draft: "draft";
521
+ ready: "ready";
522
+ failed: "failed";
501
523
  running: "running";
502
524
  verifying: "verifying";
503
525
  reviewing: "reviewing";
@@ -514,6 +536,7 @@ export declare const handoffPackSchema: z.ZodObject<{
514
536
  timeout: "timeout";
515
537
  "provider-auth": "provider-auth";
516
538
  stalled: "stalled";
539
+ "context-exhausted": "context-exhausted";
517
540
  "stale-base": "stale-base";
518
541
  "empty-result": "empty-result";
519
542
  unfinished: "unfinished";
@@ -522,6 +545,7 @@ export declare const handoffPackSchema: z.ZodObject<{
522
545
  merge: "merge";
523
546
  budget: "budget";
524
547
  "needs-lead": "needs-lead";
548
+ "needs-input": "needs-input";
525
549
  }>>;
526
550
  code: z.ZodEnum<{
527
551
  INVALID_INPUT: "INVALID_INPUT";
@@ -547,6 +571,8 @@ export declare const handoffPackSchema: z.ZodObject<{
547
571
  BUDGET_EXHAUSTED: "BUDGET_EXHAUSTED";
548
572
  BUDGET_UNKNOWN: "BUDGET_UNKNOWN";
549
573
  ATTEMPTS_EXHAUSTED: "ATTEMPTS_EXHAUSTED";
574
+ CONTEXT_EXHAUSTED: "CONTEXT_EXHAUSTED";
575
+ INPUT_REQUIRED: "INPUT_REQUIRED";
550
576
  REVISION_CONFLICT: "REVISION_CONFLICT";
551
577
  CANCELLED: "CANCELLED";
552
578
  NOT_FOUND: "NOT_FOUND";
@@ -600,10 +626,38 @@ export declare const handoffPackSchema: z.ZodObject<{
600
626
  used: z.ZodNumber;
601
627
  budget: z.ZodNumber;
602
628
  }, z.core.$strict>>;
629
+ inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
630
+ requestId: z.ZodString;
631
+ workId: z.ZodString;
632
+ kind: z.ZodEnum<{
633
+ question: "question";
634
+ "follow-up": "follow-up";
635
+ }>;
636
+ state: z.ZodEnum<{
637
+ "awaiting-answer": "awaiting-answer";
638
+ "answered-not-applied": "answered-not-applied";
639
+ "applied-awaiting-claim": "applied-awaiting-claim";
640
+ "carry-stale": "carry-stale";
641
+ }>;
642
+ severity: z.ZodNumber;
643
+ question: z.ZodString;
644
+ options: z.ZodArray<z.ZodString>;
645
+ answer: z.ZodOptional<z.ZodObject<{
646
+ revision: z.ZodNumber;
647
+ digest: z.ZodString;
648
+ excerpt: z.ZodString;
649
+ }, z.core.$strict>>;
650
+ origin: z.ZodObject<{
651
+ graphDigest: z.ZodString;
652
+ orderDigest: z.ZodString;
653
+ contextDigest: z.ZodNullable<z.ZodString>;
654
+ }, z.core.$strict>;
655
+ targetDigest: z.ZodOptional<z.ZodString>;
656
+ }, z.core.$strict>>>;
603
657
  next: z.ZodObject<{
604
658
  actor: z.ZodNullable<z.ZodEnum<{
605
- controller: "controller";
606
659
  lead: "lead";
660
+ controller: "controller";
607
661
  user: "user";
608
662
  }>>;
609
663
  action: z.ZodEnum<{
@@ -620,10 +674,12 @@ export declare const handoffPackSchema: z.ZodObject<{
620
674
  "resume-queue": "resume-queue";
621
675
  "fix-environment": "fix-environment";
622
676
  "fix-access": "fix-access";
677
+ "answer-input": "answer-input";
678
+ "apply-input": "apply-input";
623
679
  }>;
624
680
  step: z.ZodOptional<z.ZodEnum<{
625
- accepted: "accepted";
626
681
  cancelled: "cancelled";
682
+ accepted: "accepted";
627
683
  "recovery-awaiting-lead": "recovery-awaiting-lead";
628
684
  "recovery-analyzing": "recovery-analyzing";
629
685
  "recovery-applying": "recovery-applying";
@@ -670,6 +726,8 @@ export declare const handoffPackSchema: z.ZodObject<{
670
726
  BUDGET_EXHAUSTED: "BUDGET_EXHAUSTED";
671
727
  BUDGET_UNKNOWN: "BUDGET_UNKNOWN";
672
728
  ATTEMPTS_EXHAUSTED: "ATTEMPTS_EXHAUSTED";
729
+ CONTEXT_EXHAUSTED: "CONTEXT_EXHAUSTED";
730
+ INPUT_REQUIRED: "INPUT_REQUIRED";
673
731
  REVISION_CONFLICT: "REVISION_CONFLICT";
674
732
  CANCELLED: "CANCELLED";
675
733
  NOT_FOUND: "NOT_FOUND";
@@ -694,6 +752,7 @@ export declare const handoffPackSchema: z.ZodObject<{
694
752
  budgetsWithin: z.ZodNumber;
695
753
  budgetsShared: z.ZodDefault<z.ZodNumber>;
696
754
  repairs: z.ZodNumber;
755
+ inputs: z.ZodDefault<z.ZodNumber>;
697
756
  intentions: z.ZodNumber;
698
757
  intentionsDropped: z.ZodNumber;
699
758
  bySize: z.ZodBoolean;
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { diagnosisActions, diagnosisActors, diagnosisCauses, diagnosisPhases, } from "./diagnosis.js";
3
3
  import { errorCodes } from "./errors.js";
4
4
  import { failureKindSchema, pauseReasons, workStatusSchema } from "./execution.js";
5
- import { idSchema, isoTimeSchema } from "./primitives.js";
5
+ import { digestSchema, idSchema, isoTimeSchema } from "./primitives.js";
6
6
  /**
7
7
  * Пакет передачи контекста (`harness handoff`, `handoffPack`): состояние доски
8
8
  * для следующей сессии ведущего агента, собранное из хранилища, а не из
@@ -42,6 +42,10 @@ export const HANDOFF_LIMITS = {
42
42
  /** Намерения агента и знаков в каждом. */
43
43
  intentions: 20,
44
44
  intentionChars: 1000,
45
+ /** Вопросы исполнителя (открытые запросы), вопросы первыми. */
46
+ inputs: 10,
47
+ /** Знаков ответа в пакете (`answer.excerpt`). */
48
+ answerChars: 500,
45
49
  /** Предел строки факта из хранилища. */
46
50
  text: 300,
47
51
  /** Предел идентификатора, имени стадии, владельца из хранилища. */
@@ -272,6 +276,41 @@ export const handoffPackSchema = z.strictObject({
272
276
  budget: count,
273
277
  }))
274
278
  .max(HANDOFF_LIMITS.repairs),
279
+ /**
280
+ * Открытые вопросы исполнителя (H02): вопрос — усечённый, варианты — ID,
281
+ * ответ — версия, digest и начало текста, основания — digests. Нет поля —
282
+ * пакет прежней версии.
283
+ */
284
+ inputs: z
285
+ .array(z.strictObject({
286
+ requestId: name,
287
+ workId: idSchema,
288
+ kind: z.enum(['question', 'follow-up']),
289
+ state: z.enum([
290
+ 'awaiting-answer',
291
+ 'answered-not-applied',
292
+ 'applied-awaiting-claim',
293
+ 'carry-stale',
294
+ ]),
295
+ severity: z.number().int().min(1).max(10),
296
+ question: text,
297
+ options: z.array(name).max(6),
298
+ answer: z
299
+ .strictObject({
300
+ revision: z.number().int().positive(),
301
+ digest: digestSchema,
302
+ excerpt: clipped(HANDOFF_LIMITS.answerChars),
303
+ })
304
+ .optional(),
305
+ origin: z.strictObject({
306
+ graphDigest: digestSchema,
307
+ orderDigest: digestSchema,
308
+ contextDigest: digestSchema.nullable(),
309
+ }),
310
+ targetDigest: digestSchema.optional(),
311
+ }))
312
+ .max(HANDOFF_LIMITS.inputs)
313
+ .optional(),
275
314
  /** Следующий шаг доски: первое решение lead/user, иначе ход controller. */
276
315
  next: nextSchema.extend({ workId: idSchema.optional(), code: errorCodeSchema.optional() }),
277
316
  /** Намерения агента — единственный текст не из хранилища. */
@@ -298,6 +337,8 @@ export const handoffPackSchema = z.strictObject({
298
337
  // Пакеты прежних версий поля не знают: при разборе — 0.
299
338
  budgetsShared: count.default(0),
300
339
  repairs: count,
340
+ // Пакеты прежних версий поля не знают: при разборе — 0.
341
+ inputs: count.default(0),
301
342
  intentions: count,
302
343
  intentionsDropped: count,
303
344
  bySize: z.boolean(),
@@ -8,6 +8,7 @@ export * from './context.ts';
8
8
  export * from './result.ts';
9
9
  export * from './events.ts';
10
10
  export * from './execution.ts';
11
+ export * from './input.ts';
11
12
  export * from './review.ts';
12
13
  export * from './checks.ts';
13
14
  export * from './profiles.ts';
@@ -8,6 +8,7 @@ export * from "./context.js";
8
8
  export * from "./result.js";
9
9
  export * from "./events.js";
10
10
  export * from "./execution.js";
11
+ export * from "./input.js";
11
12
  export * from "./review.js";
12
13
  export * from "./checks.js";
13
14
  export * from "./profiles.js";
@@ -0,0 +1,13 @@
1
+ import type { InputRequest } from './input.ts';
2
+ /**
3
+ * Где вопрос: ждёт ответа (`awaiting-answer`), ответ записан, но не применён
4
+ * (`answered-not-applied`), применён и ждёт выдачи попытки или её первого
5
+ * вызова (`applied-awaiting-claim`), передан исполнителю началом вызова
6
+ * (`delivered`); перенесённый ответ заменённого вопроса устарел до выдачи
7
+ * (`carry-stale`: перенести снова или снять). Закрытые запросы иначе
8
+ * состояния не имеют.
9
+ */
10
+ export declare const inputStates: readonly ["awaiting-answer", "answered-not-applied", "applied-awaiting-claim", "delivered", "carry-stale"];
11
+ export type InputState = (typeof inputStates)[number];
12
+ export type RequestLike = Pick<InputRequest, 'id' | 'kind' | 'lifecycle' | 'delivered' | 'version' | 'effectiveSeverity' | 'createdAt'> & Partial<Pick<InputRequest, 'stale' | 'target'>>;
13
+ export declare function inputStateOf(r: Pick<RequestLike, 'lifecycle' | 'delivered' | 'stale' | 'target'>): InputState | undefined;
@@ -0,0 +1,32 @@
1
+ // Состояние вопроса исполнителя по записи запроса — без node:*, zod и
2
+ // движка. Общий лист договоров: его импортируют и проекции, и отчёт (оба
3
+ // годятся для браузерного бандла), чтобы правило было одно.
4
+ /**
5
+ * Где вопрос: ждёт ответа (`awaiting-answer`), ответ записан, но не применён
6
+ * (`answered-not-applied`), применён и ждёт выдачи попытки или её первого
7
+ * вызова (`applied-awaiting-claim`), передан исполнителю началом вызова
8
+ * (`delivered`); перенесённый ответ заменённого вопроса устарел до выдачи
9
+ * (`carry-stale`: перенести снова или снять). Закрытые запросы иначе
10
+ * состояния не имеют.
11
+ */
12
+ export const inputStates = [
13
+ 'awaiting-answer',
14
+ 'answered-not-applied',
15
+ 'applied-awaiting-claim',
16
+ 'delivered',
17
+ 'carry-stale',
18
+ ];
19
+ export function inputStateOf(r) {
20
+ switch (r.lifecycle) {
21
+ case 'pending':
22
+ return 'awaiting-answer';
23
+ case 'answered':
24
+ return 'answered-not-applied';
25
+ case 'applied':
26
+ return r.delivered ? 'delivered' : 'applied-awaiting-claim';
27
+ case 'superseded':
28
+ return r.stale && !r.target ? 'carry-stale' : undefined;
29
+ default:
30
+ return undefined;
31
+ }
32
+ }