opencode-swarm 7.170.2 → 7.171.1

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 (90) hide show
  1. package/binaries/win32-arm64/swarm-sandbox-runner.exe +0 -0
  2. package/binaries/win32-x64/swarm-sandbox-runner.exe +0 -0
  3. package/dist/background/delegation-lifecycle.d.ts +5 -0
  4. package/dist/cli/{coder-settlement-rrm3ngsa.js → coder-settlement-vxpmxk46.js} +7 -7
  5. package/dist/cli/{config-doctor-rnfyv55m.js → config-doctor-vwy3c9g9.js} +2 -2
  6. package/dist/cli/{core-b161yfjy.js → core-2znms60v.js} +1 -1
  7. package/dist/cli/{curation-policy-tg84dnnd.js → curation-policy-fakrpw5t.js} +4 -4
  8. package/dist/cli/{curator-drift-3ssjr0nx.js → curator-drift-r9r8gepb.js} +2 -2
  9. package/dist/cli/{curator-dfcpzqwr.js → curator-kc80aj6d.js} +32 -32
  10. package/dist/cli/{curator-llm-factory-cjrh0sa3.js → curator-llm-factory-exke3rag.js} +32 -32
  11. package/dist/cli/{evidence-summary-service-7jfq6dax.js → evidence-summary-service-g3gr1pfs.js} +13 -13
  12. package/dist/cli/{gate-evidence-0e70dqjg.js → gate-evidence-8mwsj2b7.js} +4 -4
  13. package/dist/cli/{guardrail-explain-a40pmzzc.js → guardrail-explain-pkbjswtd.js} +33 -33
  14. package/dist/cli/{guardrail-log-71wvwyd0.js → guardrail-log-qx1tpeda.js} +6 -6
  15. package/dist/cli/{guardrail-reset-znw5636e.js → guardrail-reset-v91p8ca6.js} +32 -32
  16. package/dist/cli/{hive-promoter-pznn5yfn.js → hive-promoter-02vxb018.js} +32 -32
  17. package/dist/cli/{index-zr6ev5kt.js → index-0caqxnby.js} +1 -1
  18. package/dist/cli/{index-7pgzjj3z.js → index-2j0pd6sj.js} +32 -32
  19. package/dist/cli/{index-4say55ww.js → index-3jcp3zb6.js} +1 -1
  20. package/dist/cli/{index-2q6qj0vw.js → index-3jwamrzw.js} +3 -3
  21. package/dist/cli/{index-j1tjd6aq.js → index-3zzyxs7q.js} +5 -5
  22. package/dist/cli/{index-9g3c0w22.js → index-4rq1d5k5.js} +2 -1
  23. package/dist/cli/{index-g2sc35qk.js → index-4sf357vj.js} +3 -3
  24. package/dist/cli/{index-x067zyvp.js → index-5134766r.js} +6 -6
  25. package/dist/cli/{index-we9jztxd.js → index-5vgd9st3.js} +6 -6
  26. package/dist/cli/{index-p6zt0qm1.js → index-6k5aq7b9.js} +2 -2
  27. package/dist/cli/{index-z4ewmn1h.js → index-6mjtptnb.js} +1 -1
  28. package/dist/cli/{index-dbg2g834.js → index-7pae558g.js} +6 -6
  29. package/dist/cli/{index-70avfxnw.js → index-7qqwx64h.js} +5 -5
  30. package/dist/cli/{index-45x6meqp.js → index-8nbzfbjg.js} +5 -5
  31. package/dist/cli/{index-g0q47r3r.js → index-95e3a9en.js} +1 -1
  32. package/dist/cli/{index-4m9hfbhe.js → index-9cp6bhx9.js} +3 -3
  33. package/dist/cli/{index-7sz2rkx3.js → index-9dz2ee2g.js} +74 -52
  34. package/dist/cli/{index-br3mvbsa.js → index-aa2eyfvr.js} +2 -2
  35. package/dist/cli/{index-1kt9xbrt.js → index-cdee25pp.js} +2 -2
  36. package/dist/cli/{index-efkxjmdb.js → index-d5pk5b95.js} +2 -2
  37. package/dist/cli/{index-d1sdve0x.js → index-d6bs0p6d.js} +7 -7
  38. package/dist/cli/{index-3q7bb7qz.js → index-dr1ym009.js} +9 -9
  39. package/dist/cli/{index-a0vggadp.js → index-er6sk4e6.js} +1 -1
  40. package/dist/cli/{index-sf32ny5w.js → index-evxd1art.js} +1 -1
  41. package/dist/cli/{index-bernkwgf.js → index-g6nen3gt.js} +1 -1
  42. package/dist/cli/{index-cgpwjctj.js → index-kb66he4e.js} +1 -1
  43. package/dist/cli/{index-29gnavqx.js → index-m1j1rth6.js} +1 -1
  44. package/dist/cli/{index-5y7kqjyt.js → index-nfs78aqj.js} +1 -1
  45. package/dist/cli/{index-9vxaf499.js → index-rdjmbeex.js} +1 -1
  46. package/dist/cli/{index-gs4m1dxw.js → index-rkj71ej6.js} +3 -3
  47. package/dist/cli/{index-24pamt0h.js → index-s7h6txsk.js} +2 -2
  48. package/dist/cli/{index-8v2k9xqv.js → index-vs7b2pqm.js} +4 -4
  49. package/dist/cli/{index-19xctk9g.js → index-wn9gf91x.js} +1 -1
  50. package/dist/cli/{index-7htmxmjp.js → index-xefajbqv.js} +2734 -1698
  51. package/dist/cli/{index-w79t20a6.js → index-xm0131fx.js} +5 -5
  52. package/dist/cli/{index-dvbf6fpn.js → index-yqbnsmmv.js} +39 -0
  53. package/dist/cli/{index-7a180w76.js → index-ztxh3nmf.js} +34 -34
  54. package/dist/cli/index.js +32 -32
  55. package/dist/cli/{knowledge-escalator-95gqgg8e.js → knowledge-escalator-4j6xgcvj.js} +10 -10
  56. package/dist/cli/{knowledge-events-hcx770h3.js → knowledge-events-5ax1g356.js} +8 -8
  57. package/dist/cli/{knowledge-link-twmzh8cf.js → knowledge-link-vh9pfnb9.js} +3 -3
  58. package/dist/cli/{knowledge-store-ppmrqs41.js → knowledge-store-2nrtfb5x.js} +4 -4
  59. package/dist/cli/{knowledge-validator-63rfvqmw.js → knowledge-validator-efcax8g9.js} +6 -6
  60. package/dist/cli/{pending-delegations-dqdetx92.js → pending-delegations-29qj2kya.js} +9 -9
  61. package/dist/cli/{pr-subscriptions-z9t7f7m0.js → pr-subscriptions-t51vcrvd.js} +9 -9
  62. package/dist/cli/{pr-workflow-gate-wqrcb5m8.js → pr-workflow-gate-03367gvd.js} +32 -32
  63. package/dist/cli/{runner-2r5j33tm.js → runner-8m8qhngm.js} +4 -4
  64. package/dist/cli/{scan-cursor-xzmmf7r4.js → scan-cursor-nhxpv6tj.js} +5 -5
  65. package/dist/cli/{schema-6bn7mj29.js → schema-ht5hmsce.js} +1 -1
  66. package/dist/cli/{scope-persistence-wyg0rb07.js → scope-persistence-6qebaksv.js} +13 -13
  67. package/dist/cli/{skill-generator-kwnwapfn.js → skill-generator-tfm4kawf.js} +12 -12
  68. package/dist/cli/{snapshot-coordination-init-ajvmd1z6.js → snapshot-coordination-init-zgfjjv9p.js} +32 -32
  69. package/dist/cli/{telemetry-yst95z2f.js → telemetry-0mz37v3h.js} +1 -1
  70. package/dist/cli/{worktree-collision-ownership-dm6nq9yw.js → worktree-collision-ownership-6mgm8p9g.js} +9 -9
  71. package/dist/cli/{worktree-isolation-b10h20sv.js → worktree-isolation-02rr7t21.js} +32 -32
  72. package/dist/commands/dataset.d.ts +20 -0
  73. package/dist/commands/registry.d.ts +39 -0
  74. package/dist/db/observability-event-store.d.ts +17 -1
  75. package/dist/index.js +356 -338
  76. package/dist/observability/catalog.d.ts +3 -3
  77. package/dist/observability/index.d.ts +1 -1
  78. package/dist/observability/observe.d.ts +6 -0
  79. package/dist/pr-review/reducer.d.ts +18 -10
  80. package/dist/pr-review/types.d.ts +43 -47
  81. package/dist/telemetry.d.ts +23 -3
  82. package/dist/tools/repo-map.d.ts +5 -0
  83. package/dist/training/capture.d.ts +37 -0
  84. package/dist/training/consent.d.ts +96 -0
  85. package/dist/training/disk.d.ts +16 -0
  86. package/dist/training/exporter.d.ts +88 -0
  87. package/dist/training/paths.d.ts +20 -0
  88. package/dist/training/redact.d.ts +29 -0
  89. package/dist/training/vault.d.ts +177 -0
  90. package/package.json +2 -1
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The event catalog (issue #2029).
3
3
  *
4
- * Exactly 61 entries, matching the `TelemetryEvent` union at
4
+ * Exactly 62 entries, matching the `TelemetryEvent` union at
5
5
  * `src/telemetry.ts:20-172`. Thirty-eight predate the #2029 contract; the 39th is
6
6
  * `agent_conflict_detected` (previously emitted through a force-cast past the
7
7
  * type system), the 40th is `close_archive_result` (issue #2030 — the
@@ -29,7 +29,7 @@
29
29
  * (issue #2046 item 9 — canonical council attempt / accepted-transition
30
30
  * observations joined to the lifecycle correlation system via the
31
31
  * server-derived `councilRoundId`). The 60th is
32
- * `context_source_attribution` and the 61st is `verdict_row_pipe_recovery`
32
+ * `context_source_attribution` and the 61st is `verdict_row_pipe_recovery` and the 62nd is `training_vault_health`
33
33
  * (issue #2482 — D3: honest savings attribution with the omit-when-unknown
34
34
  * rule, and the #2184 verdict-row pipe-recovery fidelity class in the event
35
35
  * lifecycle). These late
@@ -88,7 +88,7 @@ export interface CatalogEntry {
88
88
  /**
89
89
  * Whether an event of this kind must carry `trace.parentSpanId`.
90
90
  *
91
- * `false` for all 61 entries today, and that is a truthful statement about
91
+ * `false` for all 62 entries today, and that is a truthful statement about
92
92
  * the current system rather than a placeholder: no producer supplies a
93
93
  * parent span, so `createObservation` never sets one. Setting this to `true`
94
94
  * for a kind whose producer cannot supply a parent would make every
@@ -50,7 +50,7 @@ export type { TraceAndSpanId } from './ids.js';
50
50
  export { newEventId, newSpanId, pseudonymousRef, SPAN_ID_HEX_LENGTH, TRACE_ID_HEX_LENGTH, } from './ids.js';
51
51
  export { adaptLegacyTelemetryPayload, extractOutcome, extractWorkflowIds, KNOWN_TELEMETRY_KEYS, LEGACY_ADAPTER_RULES, NON_OBJECT_PAYLOAD_MARKER, } from './legacy.js';
52
52
  export type { InitObservabilityInput } from './observe.js';
53
- export { createObservation, initObservability, resetObservabilityForTesting, toLegacyTelemetryLine, } from './observe.js';
53
+ export { canonicalLineContent, createObservation, initObservability, resetObservabilityForTesting, toLegacyTelemetryLine, } from './observe.js';
54
54
  export { mappingForEntry, OPENINFERENCE_ATTRIBUTES, OPENINFERENCE_MAPPING_VERSION, OTEL_GENAI_ATTRIBUTES, OTEL_GENAI_MAPPING_VERSION, } from './otel-mapping.js';
55
55
  export type { RelationshipValidationResult } from './relationships.js';
56
56
  export { RELATIONSHIP_VIOLATION_CODES, validateEventRelationships, } from './relationships.js';
@@ -101,6 +101,12 @@ export declare function createObservation(kind: string, data: unknown): Observab
101
101
  * those inputs.
102
102
  */
103
103
  export declare function toLegacyTelemetryLine(event: ObservabilityEvent): Record<string, unknown>;
104
+ /**
105
+ * The exact JSONL line content `emit()` writes, without the EOL. Single
106
+ * definition so the writer (src/telemetry.ts) and the observability store's
107
+ * content-derived `line_hash` correlation (issue #2487) can never drift apart.
108
+ */
109
+ export declare function canonicalLineContent(event: ObservabilityEvent): string;
104
110
  /**
105
111
  * Reset all four module-scoped variables.
106
112
  *
@@ -1,24 +1,30 @@
1
1
  /**
2
- * PR-review transition authority (issue #2385).
2
+ * PR-review transition authority (issues #2385, #2512).
3
3
  *
4
4
  * Pure `(state, event) -> { state, effects }` reducer over the closed
5
5
  * `PrReviewEvent` union. Rule computation is delegated to the focused
6
6
  * boundary modules (`circuit.ts`, `completion.ts` via its settlement inputs,
7
7
  * `critic-routing.ts`, `lifecycle.ts`); this module owns transition
8
8
  * composition and the explicit rejection of every invalid transition class
9
- * named by issue #2385:
9
+ * named by issue #2385 that is reducer-observable:
10
10
  *
11
- * - observer deadline / client absence → terminal child failure
12
- * - raw transcript / parser failure → provider circuit signal
13
- * - one lane → multiple circuit samples (delegated to circuit.ts's
14
- * distinct-`(generation, batch, lane)` scan; asserted by property tests)
15
11
  * - unresolved/live lane → terminal coverage report
16
- * - partial/no coverage → approval
12
+ * - partial coverage → approval; zero coverage → anything but INCOMPLETE
17
13
  * - ordinary MEDIUM → critic without typed high-impact/vulnerability evidence
18
14
  * (enforced where critic inventory is composed, via critic-routing.ts)
19
- * - stale/foreign authorization → reviewer or publication access
15
+ * - stale/foreign authorization → armed-recovery transition
20
16
  * - late old-generation result → current-state mutation
21
- * - structured receipt → downgrade by later transcript parsing
17
+ *
18
+ * Rules that depend on facts this pure boundary cannot observe live at
19
+ * richer executors and are NOT reducer events (issue #2512 wire-or-retire
20
+ * census; see docs/pr-review-transition-authority.md): observer-deadline /
21
+ * client-absence / parser / stale-sweep evidence classification
22
+ * (`classifyPrReviewCircuitSignal`), structured-receipt downgrade protection
23
+ * (`validateExactStructuredReceiptCoverage`), operator lane cancellation
24
+ * (`collectOnce` cancel_pending), publication arming/settlement
25
+ * (`completePrWorkflow` + `allowedPrReviewReportVerdicts`), and reviewer
26
+ * re-entry consumption (`reservePrReviewReentryAuthorizationAgainstBinding` —
27
+ * a pure reducer cannot independently observe a concurrent storage mutation).
22
28
  *
23
29
  * The owning gate and `dispatch-lanes` are orchestration adapters: they build
24
30
  * events from real I/O, apply the returned state, and map typed rejections to
@@ -30,7 +36,9 @@
30
36
  * `pending-delegations.ts`; `emit_diagnostic` describes the collect
31
37
  * observer's bounded diagnostics channel; `block_dispatch` describes the
32
38
  * circuit-open admission refusal. No effect kind is emitted without a real
33
- * executor (reviewer finding 1, issue #2385 Phase 8b).
39
+ * executor (reviewer finding 1, issue #2385 Phase 8b), and no event member is
40
+ * declared without a production construction site (issue #2512; enforced by
41
+ * tests/unit/pr-review/reducer-adapter-authority.test.ts).
34
42
  *
35
43
  * Probe outcomes other than an admission rollback are processed by the
36
44
  * machine on the NEXT staged admission: the gate feeds the recorded probe's
@@ -78,7 +78,7 @@ export type PrReviewEffect = {
78
78
  replay?: boolean;
79
79
  } | {
80
80
  kind: 'emit_diagnostic';
81
- source: 'collection_observer' | 'legacy_transcript_adapter';
81
+ source: 'collection_observer';
82
82
  code: string;
83
83
  boundedDetail?: string | undefined;
84
84
  } | {
@@ -104,11 +104,38 @@ export type PrReviewCircuitProbeOutcome = {
104
104
  } | {
105
105
  result: 'rolled_back_admission';
106
106
  };
107
+ /**
108
+ * A settled critic receipt: a critic verdict that terminates its assigned
109
+ * coverage obligation (issue #2512). UPHELD, DOWNGRADED, and DISPROVED each
110
+ * satisfy the critic coverage their finding was assigned; NEEDS_MORE_EVIDENCE
111
+ * is deliberately nonterminal and is not representable here. The digest is the
112
+ * authoritative reviewer verdict row the critic claim was bound to at
113
+ * composition time (`reviewerVerdictRowDigest`; composition rejects unbound
114
+ * claims), so a receipt can only be built from the current authoritative
115
+ * reviewer rows.
116
+ */
117
+ export interface PrReviewCriticSettledReceipt {
118
+ findingId: string;
119
+ status: 'UPHELD' | 'DOWNGRADED' | 'DISPROVED';
120
+ reviewerRowDigest: string;
121
+ }
122
+ /**
123
+ * The closed event vocabulary for the PR-review transition authority
124
+ * (`reducer.ts`), issue #2512's registered-path contract: every declared event
125
+ * member has a production construction site (see
126
+ * docs/pr-review-transition-authority.md for the wire-or-retire table). Events
127
+ * whose production authority lives at a richer executor boundary — transcript
128
+ * downgrade protection (`validateExactStructuredReceiptCoverage`), provider
129
+ * terminal evidence classification (`classifyPrReviewCircuitSignal`),
130
+ * operator lane cancellation (`collectOnce` cancel_pending), publication
131
+ * arming/settlement (`completePrWorkflow`), and reviewer re-entry consumption
132
+ * (`reservePrReviewReentryAuthorizationAgainstBinding`) — are deliberately
133
+ * RETIRED from this union rather than declared without a dispatch site.
134
+ */
107
135
  export type PrReviewEvent = {
108
136
  type: 'base_admission_requested';
109
137
  batchId: string;
110
138
  lanes: PrReviewBaseDispatchLane[];
111
- depthTier: 'S' | 'M' | 'L';
112
139
  maxBatches: number;
113
140
  validatedAt: string;
114
141
  } | {
@@ -128,34 +155,6 @@ export type PrReviewEvent = {
128
155
  semanticEnvelopeDigest: string;
129
156
  outcome: 'CLEAN' | 'FINDINGS' | 'INCOMPLETE';
130
157
  existingReceiptDigest?: string | undefined;
131
- } | {
132
- type: 'transcript_evidence_presented';
133
- batchId: string;
134
- laneId: string;
135
- laneHasStructuredReceipt: boolean;
136
- } | {
137
- type: 'provider_terminal_observed';
138
- batchId: string;
139
- laneId: string;
140
- generation: number;
141
- evidence: {
142
- source: 'typed_terminal_error_class';
143
- category: string;
144
- kind: string;
145
- } | {
146
- source: 'observer_deadline';
147
- } | {
148
- source: 'client_unavailable';
149
- } | {
150
- source: 'parser_or_transcript';
151
- } | {
152
- source: 'stale_observation';
153
- };
154
- } | {
155
- type: 'lane_cancelled';
156
- batchId: string;
157
- laneId: string;
158
- generation: number;
159
158
  } | {
160
159
  type: 'circuit_advance_requested';
161
160
  nowMs: number;
@@ -187,29 +186,26 @@ export type PrReviewEvent = {
187
186
  } | {
188
187
  type: 'critic_result_recorded';
189
188
  criticRequiredFindingIds: readonly string[];
190
- criticConfirmedFindingIds: readonly string[];
191
- } | {
192
- type: 'publication_armed';
193
- coverageKind: PrReviewTerminalCoverageKind;
194
- verdict: PrReviewReportVerdict;
195
- } | {
196
- type: 'publication_published';
197
- binding: PrReviewAuthorizationBinding;
189
+ criticSettledReceipts: readonly PrReviewCriticSettledReceipt[];
198
190
  } | {
199
191
  type: 'armed_recovery_requested';
200
192
  binding: PrReviewAuthorizationBinding;
201
193
  dimensionsToCancel: PrReviewBaseDimensionId[];
202
194
  nowIso: string;
203
- } | {
204
- type: 'reviewer_authorization_consumed';
205
- binding: PrReviewAuthorizationBinding;
206
- expectedRole: 'reviewer' | 'test_engineer';
207
- role: 'reviewer' | 'test_engineer';
195
+ /** The operator's sanitized reason; the transition persists it verbatim. */
196
+ reason: string;
208
197
  };
209
198
  /**
210
- * The exact-identity binding an armed recovery, publication, or re-entry
211
- * authorization must carry (issue #2383/#2385). Stale or foreign values are
212
- * rejected with `stale_foreign_authorization`.
199
+ * The exact-identity binding an armed recovery authorization must carry
200
+ * (issues #2383/#2385/#2512). Stale or foreign values are rejected with
201
+ * `stale_foreign_authorization`.
202
+ *
203
+ * Authority split (issue #2512): the reducer validates the fields the workflow
204
+ * state itself carries — `sessionID`, `workflowInstanceId`, `prHeadSha`, and
205
+ * `generation` (`bindingRejection` in reducer.ts). `revisionDigest` is only
206
+ * observable by the executor that resolved it (the armed publication record or
207
+ * the live binding context), so it is validated THERE — never here; a pure
208
+ * reducer cannot independently observe a concurrent storage mutation.
213
209
  */
214
210
  export interface PrReviewAuthorizationBinding {
215
211
  sessionID: string;
@@ -218,7 +214,7 @@ export interface PrReviewAuthorizationBinding {
218
214
  revisionDigest?: string;
219
215
  generation: number;
220
216
  }
221
- export type PrReviewTransitionRejectionCode = 'observer_deadline_not_terminal_evidence' | 'client_absence_not_terminal_evidence' | 'parser_failure_not_provider_signal' | 'stale_observation_not_provider_signal' | 'live_lane_blocks_coverage' | 'partial_coverage_cannot_approve' | 'no_coverage_cannot_approve' | 'critic_required_unfulfilled' | 'stale_foreign_authorization' | 'stale_generation_result' | 'receipt_cannot_be_downgraded' | 'duplicate_conflicting_result' | 'base_batch_limit_reached' | 'rollback_preconditions_failed' | 'lane_not_stale_eligible' | 'unknown_event';
217
+ export type PrReviewTransitionRejectionCode = 'live_lane_blocks_coverage' | 'partial_coverage_cannot_approve' | 'no_coverage_requires_incomplete' | 'critic_required_unfulfilled' | 'stale_foreign_authorization' | 'stale_generation_result' | 'duplicate_conflicting_result' | 'base_batch_limit_reached' | 'rollback_preconditions_failed' | 'unknown_event';
222
218
  export interface PrReviewTransitionRejection {
223
219
  code: PrReviewTransitionRejectionCode;
224
220
  detail: string;
@@ -1,5 +1,5 @@
1
1
  import type { ObservabilityEvent } from './observability/envelope.js';
2
- import { createObservation, toLegacyTelemetryLine } from './observability/index.js';
2
+ import { canonicalLineContent, createObservation, toLegacyTelemetryLine } from './observability/index.js';
3
3
  import type { DelegationCostFields } from './services/cost-accounting.js';
4
4
  export type TelemetryEvent = 'session_started' | 'session_ended' | 'agent_activated' | 'delegation_begin' | 'delegation_end' | 'delegation_cost_correction' | 'delegation_cost_binding' | 'delegation_cost_join' | 'task_state_changed' | 'gate_passed' | 'gate_failed' | 'gate_parse_error' | 'reviewer_gate_decision' | 'phase_changed' | 'budget_updated' | 'context_pruned' | 'retrieval_routed' | 'model_fallback'
5
5
  /**
@@ -33,7 +33,7 @@ export type TelemetryEvent = 'session_started' | 'session_ended' | 'agent_activa
33
33
  * `prm_hard_stop` TRIGGER emitted by `src/prm/escalation.ts`. A trigger with
34
34
  * no matching delivery means the containment never reached the agent.
35
35
  */
36
- | 'prm_hard_stop_delivered' | 'agent_conflict_detected' | 'close_archive_result' | 'knowledge_receipt_transition' | 'knowledge_maintenance' | 'residue_health' | 'context_telemetry_health' | 'skill_usage_health' | 'core_events_health' | 'shell_audit_health' | 'trajectory_health' | 'learning_health_alarm' | 'pr_subscription_health' | 'council_attempt' | 'council_round_transition' | 'council_attempt_unscoped' | 'context_source_attribution' | 'verdict_row_pipe_recovery';
36
+ | 'prm_hard_stop_delivered' | 'agent_conflict_detected' | 'close_archive_result' | 'knowledge_receipt_transition' | 'knowledge_maintenance' | 'residue_health' | 'context_telemetry_health' | 'skill_usage_health' | 'core_events_health' | 'shell_audit_health' | 'trajectory_health' | 'learning_health_alarm' | 'pr_subscription_health' | 'council_attempt' | 'council_round_transition' | 'council_attempt_unscoped' | 'context_source_attribution' | 'verdict_row_pipe_recovery' | 'training_vault_health';
37
37
  /** Stable classification for how a reviewer-gate decision was established. */
38
38
  export type ReviewerGateEvidenceKind = 'genuine' | 'fallback' | 'data_quality' | 'block';
39
39
  /**
@@ -50,7 +50,14 @@ export type TelemetryListener = (event: TelemetryEvent, data: Record<string, unk
50
50
  * two-argument listener stays assignable. The SQLite observability sink
51
51
  * (`src/db/observability-event-store.ts`) is the canonical consumer.
52
52
  */
53
- canonical?: ObservabilityEvent) => void;
53
+ canonical?: ObservabilityEvent,
54
+ /**
55
+ * The canonical JSONL line content for `canonical` (no trailing EOL),
56
+ * stringified exactly once by `emit()` and handed to listeners so the
57
+ * sink's line-hash path never re-stringifies the same envelope (issue
58
+ * #2487 review PRR-005).
59
+ */
60
+ canonicalContent?: string) => void;
54
61
  export declare function startHeartbeatTracking(): void;
55
62
  export declare function getLastHeartbeat(sessionId: string): number | undefined;
56
63
  export declare function stopHeartbeatTracking(): void;
@@ -293,6 +300,18 @@ export declare const telemetry: {
293
300
  * contract's no-content-in-metrics rule. Enables PR 16 to alarm and PR 20 to
294
301
  * report without leaking workspace layout or capsule contents.
295
302
  */
303
+ /**
304
+ * Training vault health (issue #2486). Emitted on capture-stop transitions
305
+ * (quota/disk/consent), quarantine aggregates, and withdrawals for the
306
+ * consented training-content vault. Bounded payload: the pseudonymous
307
+ * project ref, a reason enum, and a count — no vault content, no raw
308
+ * paths, matching the observability contract's no-content rule.
309
+ */
310
+ trainingVaultHealth(data: {
311
+ project_ref: string;
312
+ reason: "quota_bytes" | "quota_records" | "disk_floor" | "consent_missing" | "withdrawal_executed";
313
+ count: number;
314
+ }): void;
296
315
  contextTelemetryHealth(data: {
297
316
  trigger: "compaction" | "close";
298
317
  accepted_count: number;
@@ -498,4 +517,5 @@ export declare const _internals: {
498
517
  heartbeatListenerCount: () => number;
499
518
  createObservation: typeof createObservation;
500
519
  toLegacyTelemetryLine: typeof toLegacyTelemetryLine;
520
+ canonicalLineContent: typeof canonicalLineContent;
501
521
  };
@@ -87,6 +87,11 @@ export declare const _internals: {
87
87
  oldest_age_ms: number;
88
88
  grammar_counts: Record<string, number>;
89
89
  }): void;
90
+ trainingVaultHealth(data: {
91
+ project_ref: string;
92
+ reason: "quota_bytes" | "quota_records" | "disk_floor" | "consent_missing" | "withdrawal_executed";
93
+ count: number;
94
+ }): void;
90
95
  contextTelemetryHealth(data: {
91
96
  trigger: "compaction" | "close";
92
97
  accepted_count: number;
@@ -0,0 +1,37 @@
1
+ import { type TrainingConsent } from './consent';
2
+ import { appendTrainingVaultRecord, buildTrainingVaultRecord } from './vault';
3
+ interface MessageLike {
4
+ info?: {
5
+ role?: string;
6
+ id?: string;
7
+ sessionID?: string;
8
+ };
9
+ parts?: Array<{
10
+ type?: string;
11
+ text?: string;
12
+ }>;
13
+ }
14
+ interface ToolExecutionLike {
15
+ tool: string;
16
+ sessionID?: string;
17
+ input?: unknown;
18
+ output?: unknown;
19
+ error?: unknown;
20
+ }
21
+ export interface TrainingCaptureObserver {
22
+ observeMessages(output: {
23
+ messages?: MessageLike[];
24
+ }): Promise<void>;
25
+ observeToolExecution(event: ToolExecutionLike): Promise<void>;
26
+ }
27
+ export declare const _internals: {
28
+ appendRecord: typeof appendTrainingVaultRecord;
29
+ readConsent: (directory: string) => TrainingConsent | null;
30
+ buildRecord: typeof buildTrainingVaultRecord;
31
+ };
32
+ /**
33
+ * Create the observer. Pure construction — no filesystem access until the
34
+ * first observation (which itself only reads when a message actually arrives).
35
+ */
36
+ export declare function createTrainingCaptureObserver(directory: string): TrainingCaptureObserver;
37
+ export {};
@@ -0,0 +1,96 @@
1
+ import { z } from 'zod';
2
+ export declare const TRAINING_CONSENT_SCHEMA_VERSION = 1;
3
+ /** Version of the consent TERMS presented to the human (bump when terms change). */
4
+ export declare const TRAINING_CONSENT_CURRENT_VERSION = 1;
5
+ /** Hard per-project vault maxima (source contract #2050 §6). Lower is allowed; higher is not. */
6
+ export declare const TRAINING_QUOTA_CEILINGS: {
7
+ readonly maxBytes: 1073741824;
8
+ readonly maxRecords: 250000;
9
+ readonly retentionDays: 30;
10
+ };
11
+ /** Hard per-project export maxima. */
12
+ export declare const TRAINING_EXPORT_QUOTA_CEILINGS: {
13
+ readonly maxBytes: 1073741824;
14
+ readonly maxExports: 20;
15
+ readonly retentionDays: 30;
16
+ };
17
+ export declare const TrainingProjectBindingSchema: z.ZodObject<{
18
+ rootDigest: z.ZodString;
19
+ projectRef: z.ZodString;
20
+ }, z.core.$strict>;
21
+ export declare const TrainingConsentSchema: z.ZodObject<{
22
+ schema_version: z.ZodLiteral<1>;
23
+ consent_id: z.ZodString;
24
+ state: z.ZodEnum<{
25
+ granted: "granted";
26
+ withdrawn: "withdrawn";
27
+ }>;
28
+ consent_version: z.ZodLiteral<1>;
29
+ granted_at: z.ZodString;
30
+ withdrawn_at: z.ZodOptional<z.ZodString>;
31
+ expires_at: z.ZodString;
32
+ purpose: z.ZodString;
33
+ content_classes: z.ZodArray<z.ZodString>;
34
+ quotas: z.ZodObject<{
35
+ maxBytes: z.ZodNumber;
36
+ maxRecords: z.ZodNumber;
37
+ retentionDays: z.ZodNumber;
38
+ }, z.core.$strip>;
39
+ redaction_version: z.ZodLiteral<1>;
40
+ project_binding: z.ZodObject<{
41
+ rootDigest: z.ZodString;
42
+ projectRef: z.ZodString;
43
+ }, z.core.$strict>;
44
+ }, z.core.$strict>;
45
+ export type TrainingConsent = z.infer<typeof TrainingConsentSchema>;
46
+ export interface GrantTrainingConsentInput {
47
+ quotas?: Partial<{
48
+ maxBytes: number;
49
+ maxRecords: number;
50
+ retentionDays: number;
51
+ }>;
52
+ expiresAt?: string;
53
+ now?: Date;
54
+ }
55
+ /**
56
+ * The project identity a consent is bound to. `rootDigest` pins the canonical
57
+ * absolute root (clone/copy produces a different digest); `projectRef` reuses
58
+ * the observability lineage pseudonym so vault records correlate with the
59
+ * metadata-only event stream without carrying raw paths.
60
+ */
61
+ export declare function computeProjectBinding(directory: string): {
62
+ rootDigest: string;
63
+ projectRef: string;
64
+ };
65
+ /**
66
+ * Write a new granted consent record (atomically). A prior record — granted or
67
+ * withdrawn — is replaced; each grant carries a fresh consent_id so vault
68
+ * records remain attributable to the exact grant they were captured under.
69
+ */
70
+ export declare function grantTrainingConsent(directory: string, input?: GrantTrainingConsentInput): TrainingConsent;
71
+ /**
72
+ * Mark the consent withdrawn. Capture stops immediately (every observation
73
+ * re-reads the active consent); physical content deletion is the withdraw
74
+ * command's confirmed step, not this write.
75
+ */
76
+ export declare function revokeTrainingConsent(directory: string, options?: {
77
+ now?: Date;
78
+ }): void;
79
+ /**
80
+ * The capture-gating consent read. Fail-closed: missing file, malformed JSON,
81
+ * schema mismatch, `state !== 'granted'`, expiry, or a project binding issued
82
+ * for a different canonical root all return null.
83
+ */
84
+ export declare function readActiveTrainingConsent(directory: string, options?: {
85
+ now?: Date;
86
+ }): TrainingConsent | null;
87
+ /**
88
+ * Read a granted, project-bound consent WITHOUT the wall-clock expiry check.
89
+ * The capture observer uses `readActiveTrainingConsent` (expiry-aware); the
90
+ * vault's append gate instead validates that the consent was active AT THE
91
+ * RECORD'S captured_at, so a record legitimately captured before expiry still
92
+ * lands while any capture attempted under an expired grant is refused.
93
+ */
94
+ export declare function readGrantedTrainingConsent(directory: string): TrainingConsent | null;
95
+ /** Read the raw consent state for status reporting (never throws). */
96
+ export declare function readTrainingConsentState(directory: string): 'granted' | 'withdrawn' | 'absent';
@@ -0,0 +1,16 @@
1
+ /** Hard free-space floor: max(2 GiB, 10% of the volume size). */
2
+ export declare const TRAINING_DISK_FLOOR_BYTES = 2147483648;
3
+ export interface DiskFloorCheck {
4
+ ok: boolean;
5
+ freeBytes?: number;
6
+ floorBytes: number;
7
+ reason?: 'disk_floor';
8
+ }
9
+ /**
10
+ * Check the free-space floor for the volume holding the training tree.
11
+ * The reported `floorBytes` is the guaranteed constant floor; the ok/not-ok
12
+ * decision uses the stricter of that floor and 10% of the volume size.
13
+ * Never throws: an unprobeable volume reports ok with the byte caps as the
14
+ * remaining bound (see module doc).
15
+ */
16
+ export declare function checkTrainingDiskFloor(directory: string): DiskFloorCheck;
@@ -0,0 +1,88 @@
1
+ import { z } from 'zod';
2
+ import { listTrainingTombstones, type TrainingVaultRecord } from './vault';
3
+ export declare const TRAINING_EXPORT_SCHEMA_VERSION = 1;
4
+ export declare const TrainingExportFiltersSchema: z.ZodObject<{
5
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
6
+ user_message: "user_message";
7
+ assistant_message: "assistant_message";
8
+ tool_call: "tool_call";
9
+ tool_result: "tool_result";
10
+ }>>>;
11
+ sessionId: z.ZodOptional<z.ZodString>;
12
+ taskId: z.ZodOptional<z.ZodString>;
13
+ since: z.ZodOptional<z.ZodString>;
14
+ validationRatio: z.ZodOptional<z.ZodNumber>;
15
+ }, z.core.$strict>;
16
+ export type TrainingExportFilters = z.infer<typeof TrainingExportFiltersSchema>;
17
+ export interface ExportPreview {
18
+ exportId: string;
19
+ recordCount: number;
20
+ estimatedBytes: number;
21
+ destination: string;
22
+ split: {
23
+ train: number;
24
+ validation: number;
25
+ };
26
+ quarantinedExcluded: number;
27
+ expiredExcluded: number;
28
+ requiresConfirm: true;
29
+ }
30
+ export interface ExportExecution {
31
+ written: boolean;
32
+ exportId?: string;
33
+ destination?: string;
34
+ reason?: 'token_mismatch' | 'token_expired' | 'scope_changed' | 'empty' | 'export_quota' | 'export_revoked';
35
+ }
36
+ export type ExportFiles = Record<'records.jsonl' | 'train.jsonl' | 'validation.jsonl' | 'manifest.json', string>;
37
+ export interface ExportBundle {
38
+ exportId: string;
39
+ files: ExportFiles;
40
+ }
41
+ interface PendingOpRecord {
42
+ schema_version: 1;
43
+ kind: 'export' | 'withdraw' | 'consent';
44
+ scope_digest: string;
45
+ confirm_token: string;
46
+ created_at: number;
47
+ }
48
+ /**
49
+ * Build the deterministic export bundle. The export id hashes the schema
50
+ * versions, the canonical filters, and each included record's id + consent id
51
+ * (so an identical re-export of identical content under the same consent is
52
+ * idempotent, while a fresh consent cycle yields a fresh id).
53
+ */
54
+ export declare function buildTrainingExportBundle(records: TrainingVaultRecord[], filters?: TrainingExportFilters, options?: {
55
+ quarantinedExcluded?: number;
56
+ expiredExcluded?: number;
57
+ }): ExportBundle;
58
+ /** Side-effect-free export preview: no files written, no token issued. */
59
+ export declare function previewTrainingExport(directory: string, filters?: TrainingExportFilters): ExportPreview;
60
+ export declare function consumeTrainingPendingOp(directory: string): void;
61
+ /** Arm the single pending-op slot and return the 24-hex confirmation token. */
62
+ export declare function issueTrainingConfirmToken(directory: string, scope: {
63
+ kind: 'export' | 'withdraw' | 'consent';
64
+ digest: string;
65
+ }): string;
66
+ type TokenCheck = {
67
+ ok: true;
68
+ record: PendingOpRecord;
69
+ } | {
70
+ ok: false;
71
+ reason: 'token_mismatch' | 'token_expired';
72
+ };
73
+ export declare function checkTrainingConfirmToken(directory: string, kind: 'export' | 'withdraw' | 'consent', token: string): TokenCheck;
74
+ declare function countExportDirs(directory: string): number;
75
+ export declare const _internals: {
76
+ countExportDirs: typeof countExportDirs;
77
+ listTombstones: typeof listTrainingTombstones;
78
+ };
79
+ /**
80
+ * Execute the confirmed export: consumes the token (single use), re-derives
81
+ * the CURRENT scope digest from the vault + filters, writes the bundle
82
+ * atomically under `<root>/exports/<exportId>/`. Identical re-exports are
83
+ * idempotent (same destination, same bytes).
84
+ */
85
+ export declare function executeTrainingExport(directory: string, filters: TrainingExportFilters | undefined, options: {
86
+ confirmToken: string;
87
+ }): ExportExecution;
88
+ export {};
@@ -0,0 +1,20 @@
1
+ /** Root directory name of the governed training tree, relative to `.swarm/`. */
2
+ export declare const TRAINING_ROOT_NAME = ".swarm/training/v1";
3
+ /** Resolved absolute root of the training tree for a project directory. */
4
+ export declare function trainingRootDir(directory: string): string;
5
+ /** `<root>/vault/records.jsonl` — the append-only vault record store. */
6
+ export declare function trainingVaultRecordsPath(directory: string): string;
7
+ /** `<root>/vault/quarantine.jsonl` — journal of quarantined corrupt lines. */
8
+ export declare function trainingQuarantinePath(directory: string): string;
9
+ /** `<root>/consent.json` — the durable, separately-consented grant record. */
10
+ export declare function trainingConsentPath(directory: string): string;
11
+ /** `<root>/tombstones.jsonl` — append-only withdrawal tombstones (never pruned). */
12
+ export declare function trainingTombstonesPath(directory: string): string;
13
+ /** `<root>/health.json` — bounded capture-health state (stop reasons, counters). */
14
+ export declare function trainingHealthPath(directory: string): string;
15
+ /** `<root>/exports` — contained dataset export bundles (`<exports>/<exportId>/`). */
16
+ export declare function trainingExportsDir(directory: string): string;
17
+ /** `<root>/pending-op.json` — single-slot confirmation token store. */
18
+ export declare function trainingPendingOpPath(directory: string): string;
19
+ /** Directory portion of a resolved training path (for mkdir before writes). */
20
+ export declare function parentDirOf(filePath: string): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Issue #2486: capture-time defense-in-depth redaction for training content.
3
+ *
4
+ * Mirrors the URL / credential-pattern classes of
5
+ * `sanitizeFailureEvidenceDisplay` (`src/failures/invocation-failure.ts`)
6
+ * WITHOUT that function's 512-byte display bounding — vault records keep the
7
+ * contracted 4096-char content budget. This is defense-in-depth, not a
8
+ * security boundary (same honest framing as #2369): the human consenting to
9
+ * capture is trusting the redactor class, and the recorded
10
+ * `redaction.version` pins which revision produced each stored record.
11
+ */
12
+ /** Bumped when the pattern set changes; recorded on every vault record.
13
+ * v1's pattern set was extended pre-release (quoted-JSON credential shapes,
14
+ * scheme-prefixed tokens) before any v1 record shipped, so the first released
15
+ * revision covers the full set and no migration surface exists. */
16
+ export declare const TRAINING_REDACTION_VERSION = 1;
17
+ export interface RedactionResult {
18
+ content: string;
19
+ applied: boolean;
20
+ redactions: number;
21
+ }
22
+ /**
23
+ * Redact URL and credential patterns from already-bounded capture content
24
+ * (callers bound FIRST — a placeholder can be longer than the span it
25
+ * replaces, and truncating after redaction would collapse distinct inputs
26
+ * onto one identity). Pure; never throws (on internal failure the content is
27
+ * withheld rather than stored raw).
28
+ */
29
+ export declare function redactTrainingContent(content: string): RedactionResult;