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
@@ -106,9 +106,12 @@ const flatUsage = (usage) => usage && typeof usage === 'object' && !Array.isArra
106
106
  * учитывалась неполной. Здесь каждая строка разбирается сразу; хранятся
107
107
  * только поля телеметрии — последнее событие `result`, события
108
108
  * `turn.completed` и первая сообщённая модель, — а не текст вывода.
109
+ * У claude также — `terminal_reason` и `num_turns` последнего `result` (по
110
+ * ним адаптер узнаёт нехватку окна контекста) и число автоматических и ручных сжатий
111
+ * контекста (`system`/`compact_boundary`): успешное сжатие не отказ.
109
112
  */
110
113
  export function usageStream(runtime) {
111
- let partial = '', overflow = false, malformed = false, model = null, result;
114
+ let partial = '', overflow = false, malformed = false, model = null, result, terminalReason, numTurns, compactions = 0;
112
115
  const turns = [];
113
116
  const line = (text) => {
114
117
  if (!text.trim())
@@ -127,6 +130,12 @@ export function usageStream(runtime) {
127
130
  }
128
131
  const e = event;
129
132
  model ??= eventModel(e);
133
+ if (runtime === 'claude' && e.type === 'system' && e.subtype === 'compact_boundary')
134
+ compactions++;
135
+ if (runtime === 'claude' && e.type === 'result')
136
+ terminalReason = typeof e.terminal_reason === 'string' ? e.terminal_reason : undefined;
137
+ if (runtime === 'claude' && e.type === 'result')
138
+ numTurns = typeof e.num_turns === 'number' ? e.num_turns : undefined;
130
139
  if (runtime === 'claude' && e.type === 'result')
131
140
  result = JSON.stringify({
132
141
  type: e.type,
@@ -185,5 +194,17 @@ export function usageStream(runtime) {
185
194
  return parseUsage(runtime, [...turns, ...(result ? [result] : [])].join('\n'), completed && !malformed);
186
195
  },
187
196
  model: () => model,
197
+ /** `terminal_reason` последнего `result` claude; нет — runtime не сообщил. */
198
+ terminalReason: () => {
199
+ flush();
200
+ return terminalReason;
201
+ },
202
+ /** `num_turns` последнего `result` claude; нет — runtime не сообщил. */
203
+ numTurns: () => {
204
+ flush();
205
+ return numTurns;
206
+ },
207
+ /** Сколько раз runtime сжал контекст за вызов (`compact_boundary`). */
208
+ compactions: () => compactions,
188
209
  };
189
210
  }
package/lib/cli.js CHANGED
@@ -4,7 +4,7 @@ import { existsSync, lstatSync, readFileSync, readdirSync, writeFileSync, mkdirS
4
4
  import { basename, dirname, join, resolve } from 'node:path';
5
5
  import { parseArgs } from 'node:util';
6
6
  import { z } from 'zod';
7
- import { API_VERSION, HarnessError, authorSchema, cliCommands, cliDataSchemas, contractViolation, contextSnapshotSchema, contractDocumentSchema, errorCodes, executionPolicySchema, exitCodeOf, exitCodes, } from "./contracts/index.js";
7
+ import { API_VERSION, HarnessError, authorSchema, cliCommands, cliDataSchemas, contractViolation, contextSnapshotSchema, contractDocumentSchema, digestSchema, errorCodes, executionPolicySchema, exitCodeOf, exitCodes, } from "./contracts/index.js";
8
8
  import { HARNESS_VERSION } from "./package.js";
9
9
  import { validateInputs } from "./validate.js";
10
10
  import { Harness } from "./control/harness.js";
@@ -26,6 +26,7 @@ import { collectReportInput } from "./control/report.js";
26
26
  import { writeReportFile } from "./control/report-file.js";
27
27
  import { valueReport, reportHtml, reportMarkdown } from "./report/index.js";
28
28
  import { handoffMarkdown, handoffPack } from "./handoff/index.js";
29
+ import { inputStateOf } from "./projections/input.js";
29
30
  const usage = `harness ${HARNESS_VERSION}
30
31
 
31
32
  Использование: harness <команда> [параметры]
@@ -223,6 +224,16 @@ const options = {
223
224
  format: { type: 'string' },
224
225
  'no-titles': { type: 'boolean' },
225
226
  intent: { type: 'string', multiple: true },
227
+ request: { type: 'string' },
228
+ text: { type: 'string' },
229
+ option: { type: 'string' },
230
+ kind: { type: 'string' },
231
+ actor: { type: 'string' },
232
+ 'request-version': { type: 'string' },
233
+ 'context-digest': { type: 'string' },
234
+ answer: { type: 'string' },
235
+ target: { type: 'string' },
236
+ successor: { type: 'string' },
226
237
  };
227
238
  /** Новые флаги H1 допустимы только у своих команд; прежние команды их не принимают. */
228
239
  const flagOwners = {
@@ -242,6 +253,24 @@ const flagOwners = {
242
253
  format: ['report', 'handoff'],
243
254
  'no-titles': ['report'],
244
255
  intent: ['handoff'],
256
+ request: [
257
+ 'input-show',
258
+ 'input-answer',
259
+ 'input-context',
260
+ 'input-target',
261
+ 'input-apply',
262
+ 'input-cancel',
263
+ 'input-supersede',
264
+ ],
265
+ text: ['input-answer'],
266
+ option: ['input-answer'],
267
+ kind: ['input-answer'],
268
+ actor: ['input-answer'],
269
+ 'request-version': ['input-answer', 'input-apply', 'input-cancel', 'input-supersede'],
270
+ 'context-digest': ['input-target', 'input-apply'],
271
+ answer: ['input-apply'],
272
+ target: ['input-apply'],
273
+ successor: ['input-supersede'],
245
274
  };
246
275
  /** Явное человеческое представление успешного ответа (`--human`). */
247
276
  const presenters = {
@@ -710,6 +739,125 @@ async function run(argv) {
710
739
  : undefined, b && v.state ? { baseDir: b.baseDir } : undefined),
711
740
  };
712
741
  }
742
+ case 'input-list':
743
+ case 'input-show':
744
+ case 'input-target': {
745
+ const h = open(need('state'), binding(need('state')), 'state');
746
+ try {
747
+ if (command === 'input-show')
748
+ return { command, data: h.inputRequest(need('request')) };
749
+ if (command === 'input-target') {
750
+ const { request, target, problems } = h.proposeTarget(need('request'), parseWith(digestSchema, need('context-digest'), 'context-digest'));
751
+ return {
752
+ command,
753
+ data: { requestId: request.id, ...optional('target', target), problems },
754
+ };
755
+ }
756
+ return {
757
+ command,
758
+ data: {
759
+ requests: h.inputRequests(v.work ? { workId: v.work } : {}).map((r) => ({
760
+ id: r.id,
761
+ workId: r.workId,
762
+ kind: r.kind,
763
+ blocking: r.blocking,
764
+ lifecycle: r.lifecycle,
765
+ ...optional('state', inputStateOf(r)),
766
+ severity: r.effectiveSeverity,
767
+ version: r.version,
768
+ answers: r.answers.length,
769
+ createdAt: r.createdAt,
770
+ })),
771
+ },
772
+ };
773
+ }
774
+ finally {
775
+ h.close();
776
+ }
777
+ }
778
+ case 'input-answer':
779
+ case 'input-context':
780
+ case 'input-apply':
781
+ case 'input-cancel':
782
+ case 'input-supersede': {
783
+ const b = binding(need('state'));
784
+ const h = open(need('state'), b, false);
785
+ const version = () => {
786
+ const n = Number(need('request-version'));
787
+ if (!Number.isSafeInteger(n) || n < 1)
788
+ throw new HarnessError('INVALID_INPUT', '--request-version: целое ≥ 1');
789
+ return n;
790
+ };
791
+ try {
792
+ const id = need('request');
793
+ if (command === 'input-answer') {
794
+ const kind = parseWith(z.enum(['clarification', 'requirement-change']), v.kind ?? 'clarification', 'kind');
795
+ const actor = parseWith(z.enum(['operator', 'lead']), v.actor ?? 'operator', 'actor');
796
+ return {
797
+ command,
798
+ data: h.answerInput(id, {
799
+ text: need('text'),
800
+ ...optional('optionId', v.option),
801
+ kind,
802
+ actor: { kind: actor },
803
+ }, version()),
804
+ };
805
+ }
806
+ if (command === 'input-context') {
807
+ const out = resolve(need('out'));
808
+ const { requestId, answerDigest, digest, snapshot } = h.inputContext(id);
809
+ writeFileSync(out, JSON.stringify(snapshot, null, 2) + '\n');
810
+ return { command, data: { requestId, answerDigest, digest, out } };
811
+ }
812
+ if (command === 'input-apply') {
813
+ const result = h.applyInput(id, {
814
+ answerDigest: parseWith(digestSchema, need('answer'), 'answer'),
815
+ expectedVersion: version(),
816
+ contextDigest: parseWith(digestSchema, need('context-digest'), 'context-digest'),
817
+ targetDigest: parseWith(digestSchema, need('target'), 'target'),
818
+ actor: b.policy.approvalMode,
819
+ ...(v.reset ? { reset: { reason: need('reason') } } : {}),
820
+ });
821
+ return {
822
+ command,
823
+ data: {
824
+ requestId: id,
825
+ applied: result.applied,
826
+ changed: result.changed,
827
+ lifecycle: result.request.lifecycle,
828
+ ...('work' in result && result.work
829
+ ? {
830
+ work: {
831
+ id: result.work.id,
832
+ status: result.work.status,
833
+ attempt: result.work.attempt,
834
+ },
835
+ }
836
+ : {}),
837
+ ...('active' in result && result.active ? { active: result.active } : {}),
838
+ ...('joint' in result && result.joint ? { joint: true } : {}),
839
+ ...('blocker' in result && result.blocker ? { blocker: result.blocker } : {}),
840
+ },
841
+ ...(result.applied ? {} : { code: exitCodes.refused }),
842
+ };
843
+ }
844
+ const closed = command === 'input-cancel'
845
+ ? h.cancelInput(id, { by: 'operator', reason: need('reason') }, version())
846
+ : h.supersedeInput(id, { by: 'operator', reason: need('reason'), successor: need('successor') }, version());
847
+ return {
848
+ command,
849
+ data: {
850
+ requestId: id,
851
+ lifecycle: closed.request.lifecycle,
852
+ version: closed.request.version,
853
+ changed: closed.changed,
854
+ },
855
+ };
856
+ }
857
+ finally {
858
+ h.close();
859
+ }
860
+ }
713
861
  }
714
862
  }
715
863
  const argv = process.argv.slice(2);