opencode-swarm 7.158.1 → 7.159.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 (84) hide show
  1. package/README.md +4 -2
  2. package/dist/cli/{coder-settlement-nrtcjr0h.js → coder-settlement-d89tqam8.js} +9 -9
  3. package/dist/cli/{config-doctor-hs0x10ty.js → config-doctor-8zawz3qh.js} +2 -2
  4. package/dist/cli/{core-a42bexs1.js → core-pp64ys5v.js} +1 -1
  5. package/dist/cli/{curation-policy-vn3m5nq2.js → curation-policy-2gq8307w.js} +6 -6
  6. package/dist/cli/{curator-llm-factory-21vqqvn3.js → curator-llm-factory-m3yw6sn5.js} +30 -30
  7. package/dist/cli/{curator-yawrnk3t.js → curator-mpqpbr0r.js} +30 -30
  8. package/dist/cli/{evidence-summary-service-kmc92b95.js → evidence-summary-service-qaq1eba9.js} +12 -12
  9. package/dist/cli/{gate-evidence-6tzhdxb2.js → gate-evidence-r0c71n04.js} +6 -6
  10. package/dist/cli/{guardrail-explain-7xrdp18c.js → guardrail-explain-5z64w3ah.js} +31 -31
  11. package/dist/cli/{guardrail-log-f16sdc3p.js → guardrail-log-f9nf687y.js} +5 -5
  12. package/dist/cli/{guardrail-reset-0ks08s0t.js → guardrail-reset-yjwk20rb.js} +30 -30
  13. package/dist/cli/{hive-promoter-d661k3qq.js → hive-promoter-zjtgbh4w.js} +30 -30
  14. package/dist/cli/{index-nwkr6tvv.js → index-0zerbq1v.js} +1 -1
  15. package/dist/cli/{index-mc9qgkwd.js → index-1qpagg2t.js} +3 -3
  16. package/dist/cli/{index-tc14d2zy.js → index-29wav1x0.js} +4 -4
  17. package/dist/cli/{index-ygxb3jw4.js → index-2z00wqvb.js} +3 -3
  18. package/dist/cli/{index-4wy9kzjg.js → index-36sgq7n9.js} +32 -32
  19. package/dist/cli/{index-xzhk2hav.js → index-3rcqxbwt.js} +1 -1
  20. package/dist/cli/{index-6x9jq0cd.js → index-3scbg6n2.js} +2 -2
  21. package/dist/cli/{index-zy60xd05.js → index-4k9pqbxw.js} +2 -2
  22. package/dist/cli/{index-mfv7mfgg.js → index-4nc9npx5.js} +2 -2
  23. package/dist/cli/{index-pfnj5pvs.js → index-54pkyasv.js} +1 -1
  24. package/dist/cli/{index-86vvhe8m.js → index-60mzwj91.js} +15 -1
  25. package/dist/cli/{index-8fqb0ynp.js → index-6z53bew2.js} +1 -1
  26. package/dist/cli/{index-jz216dhj.js → index-7yg4ypyg.js} +26 -2
  27. package/dist/cli/{index-ac8rwjsg.js → index-86dvzyac.js} +785 -235
  28. package/dist/cli/{index-tppnfxkm.js → index-8819vcke.js} +4 -4
  29. package/dist/cli/{index-ff8xjr1c.js → index-9fphcxes.js} +2 -2
  30. package/dist/cli/{index-hrrzxz3q.js → index-9yxyc1gb.js} +6 -6
  31. package/dist/cli/{index-zcmwwp1x.js → index-a5w29k1t.js} +1 -1
  32. package/dist/cli/{index-xagq35tf.js → index-av3gnekk.js} +1 -1
  33. package/dist/cli/{index-xscjecyq.js → index-bea260ta.js} +6 -6
  34. package/dist/cli/{index-dr2tfawg.js → index-bz7ayg01.js} +5 -5
  35. package/dist/cli/{index-7qvfkgyk.js → index-f3yphmk6.js} +7 -7
  36. package/dist/cli/{index-5zgf140g.js → index-g6d8xam2.js} +1 -1
  37. package/dist/cli/{index-azx50qge.js → index-gkw7kq6z.js} +5 -5
  38. package/dist/cli/{index-203fqkqk.js → index-k6y6btb6.js} +3 -3
  39. package/dist/cli/{index-h1g8w4v0.js → index-prknc0xn.js} +129 -44
  40. package/dist/cli/{index-z54qw70y.js → index-tvz43tea.js} +1 -1
  41. package/dist/cli/{index-h52hs4e9.js → index-v3jy0tc6.js} +2 -2
  42. package/dist/cli/{index-t8g88esk.js → index-ve3v09kq.js} +1 -1
  43. package/dist/cli/{index-mt6qjp4c.js → index-wae55z9w.js} +81 -72
  44. package/dist/cli/{index-nphnjeh8.js → index-wttqayp1.js} +2 -2
  45. package/dist/cli/{index-5erwyk1b.js → index-yw26j0q7.js} +7 -7
  46. package/dist/cli/{index-2j07670d.js → index-zmc8mm7v.js} +4 -4
  47. package/dist/cli/{index-7s1hmrfh.js → index-zxkv8x5n.js} +2 -2
  48. package/dist/cli/index.js +38 -46
  49. package/dist/cli/{knowledge-escalator-9py5r6c9.js → knowledge-escalator-585m4927.js} +11 -11
  50. package/dist/cli/{knowledge-events-vcbece74.js → knowledge-events-ssegqfmy.js} +9 -9
  51. package/dist/cli/{knowledge-link-cj2abbae.js → knowledge-link-a9fafeb3.js} +5 -5
  52. package/dist/cli/{knowledge-store-0rdfjv20.js → knowledge-store-nznky6cv.js} +6 -6
  53. package/dist/cli/{knowledge-validator-nwjnjgf5.js → knowledge-validator-3byea8gp.js} +8 -8
  54. package/dist/cli/{pending-delegations-ht1vgaze.js → pending-delegations-qrjq3s29.js} +3 -3
  55. package/dist/cli/{pr-review-reentry-authorization-857b9rvv.js → pr-review-reentry-authorization-w8ja0m2p.js} +30 -30
  56. package/dist/cli/{pr-subscriptions-j9j70bmd.js → pr-subscriptions-fvmey1x6.js} +4 -4
  57. package/dist/cli/{runner-sj5sf36c.js → runner-atbehryj.js} +6 -6
  58. package/dist/cli/{scan-cursor-59yj7tp9.js → scan-cursor-kv9scb2v.js} +7 -7
  59. package/dist/cli/{schema-8a7fyp87.js → schema-a7f88yc3.js} +1 -1
  60. package/dist/cli/{scope-persistence-prdxtcr3.js → scope-persistence-x6de46s4.js} +8 -8
  61. package/dist/cli/{skill-generator-v2jkgp63.js → skill-generator-vwcrfrw3.js} +13 -13
  62. package/dist/cli/{telemetry-r8e8zey7.js → telemetry-3rh94wv3.js} +1 -1
  63. package/dist/cli/{worktree-collision-ownership-6x03w8h7.js → worktree-collision-ownership-7kf9mm5z.js} +5 -5
  64. package/dist/cli/{worktree-isolation-s0setq2a.js → worktree-isolation-6zh5bxrd.js} +30 -30
  65. package/dist/commands/close.d.ts +2 -0
  66. package/dist/config/loader.d.ts +3 -0
  67. package/dist/config/project-init.d.ts +11 -7
  68. package/dist/config/schema.d.ts +21 -0
  69. package/dist/evaluation/contracts.d.ts +5 -5
  70. package/dist/evaluation/ephemeral-agent-dispatcher.d.ts +2 -0
  71. package/dist/evaluation/model-dispatcher.d.ts +2 -2
  72. package/dist/index.js +478 -475
  73. package/dist/observability/catalog.d.ts +5 -3
  74. package/dist/review/contracts.d.ts +2 -1
  75. package/dist/review/evidence.d.ts +12 -0
  76. package/dist/services/cost-accounting.d.ts +100 -0
  77. package/dist/services/status-service.d.ts +12 -0
  78. package/dist/telemetry.d.ts +1 -1
  79. package/dist/tools/repo-graph/query.d.ts +1 -0
  80. package/dist/tools/repo-graph/symbol-query.d.ts +47 -0
  81. package/dist/tools/repo-graph/types.d.ts +267 -1
  82. package/dist/tools/repo-graph.d.ts +3 -1
  83. package/opencode-swarm.schema.json +5200 -0
  84. package/package.json +4 -2
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The event catalog (issue #2029).
3
3
  *
4
- * Exactly 51 entries, matching the `TelemetryEvent` union at
4
+ * Exactly 54 entries, matching the `TelemetryEvent` union at
5
5
  * `src/telemetry.ts:15-131`. 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
@@ -22,7 +22,9 @@
22
22
  * the bounded `trajectory_health` storage audit for the issue-#2041
23
23
  * `.swarm/trajectories/` PRM session store, and the 51st is the bounded
24
24
  * `pr_subscription_health` storage audit for the issue-#2042
25
- * `.swarm/pr-monitor/` PR-monitor subscription checkpoint store. These late
25
+ * `.swarm/pr-monitor/` subscription checkpoint store. The 52nd is
26
+ * `delegation_cost_correction`, the 53rd is `delegation_cost_binding`, and the
27
+ * 54th is `delegation_cost_join`. These late
26
28
  * additions are instances
27
29
  * of the defect class this contract exists to close: an event kind entering
28
30
  * the stream with no registration.
@@ -78,7 +80,7 @@ export interface CatalogEntry {
78
80
  /**
79
81
  * Whether an event of this kind must carry `trace.parentSpanId`.
80
82
  *
81
- * `false` for all 51 entries today, and that is a truthful statement about
83
+ * `false` for all 54 entries today, and that is a truthful statement about
82
84
  * the current system rather than a placeholder: no producer supplies a
83
85
  * parent span, so `createObservation` never sets one. Setting this to `true`
84
86
  * for a kind whose producer cannot supply a parent would make every
@@ -1,5 +1,6 @@
1
1
  import type { OpencodeClient } from '@opencode-ai/sdk';
2
2
  import { type EphemeralAgentDispatchResult } from '../evaluation/ephemeral-agent-dispatcher.js';
3
+ import type { PricingConfig } from '../services/cost-accounting.js';
3
4
  import type { ModelOverride } from '../utils/model-dispatch-fallback.js';
4
5
  export type ReviewDispatchRequest = {
5
6
  directory: string;
@@ -26,4 +27,4 @@ export interface ReviewModelDispatcher {
26
27
  * The returned dispatcher is instance-local and safe to inject into hooks and
27
28
  * tools; it does not read or mutate module-level client state.
28
29
  */
29
- export declare function createReviewModelDispatcher(client: OpencodeClient): ReviewModelDispatcher;
30
+ export declare function createReviewModelDispatcher(client: OpencodeClient, pricing?: PricingConfig): ReviewModelDispatcher;
@@ -1,7 +1,10 @@
1
+ import * as fs from 'node:fs';
1
2
  import { type FindingValidation, type ReviewFinding } from '../agents/agent-output-schema.js';
2
3
  import type { Plan } from '../config/plan-schema.js';
3
4
  import type { AutoReviewConfig } from '../config/schema.js';
4
5
  import { type ReviewFindingSeverity, type ReviewReceipt } from '../hooks/review-receipt.js';
6
+ import type { CostEvidence, CostEvidenceReason, CostEvidenceStatus } from '../services/cost-accounting.js';
7
+ import { bunWrite } from '../utils/bun-compat.js';
5
8
  import type { ReviewDiffCompleteness, ReviewDiffManifest, ReviewDiffSelector } from './diff-source.js';
6
9
  export interface AutoReviewEvidenceFinding extends ReviewFinding {
7
10
  finding_id: string;
@@ -64,6 +67,10 @@ export interface AutoReviewEvidence {
64
67
  tokens_cache: number;
65
68
  cost_usd: number | null;
66
69
  cost_source: 'reported' | 'estimated' | 'unavailable';
70
+ /** Bounded per-dispatch provenance; scalar totals remain compatibility projections. */
71
+ cost_evidence: CostEvidence[];
72
+ evidence_status: CostEvidenceStatus;
73
+ evidence_reason?: CostEvidenceReason;
67
74
  };
68
75
  }
69
76
  export declare function computeAutoReviewManifestHash(manifest: Omit<AutoReviewScopeManifest, 'hash'>): string;
@@ -72,6 +79,11 @@ export interface PersistAutoReviewEvidenceOptions {
72
79
  /** Rebuild the exact reviewed scope immediately before the atomic rename. */
73
80
  verifyCurrent?: () => Promise<boolean>;
74
81
  }
82
+ /** Dependency seam for failure-path tests; production defaults stay unchanged. */
83
+ export declare const _internals: {
84
+ bunWrite: typeof bunWrite;
85
+ renameSync: typeof fs.renameSync;
86
+ };
75
87
  export declare function persistAutoReviewEvidence(directory: string, evidence: AutoReviewEvidence, options?: PersistAutoReviewEvidenceOptions): Promise<string>;
76
88
  export declare function readAutoReviewEvidenceForPhase(directory: string, phase: number): AutoReviewEvidence | null;
77
89
  export declare function isAutoReviewEvidence(value: unknown): value is AutoReviewEvidence;
@@ -1,4 +1,33 @@
1
1
  export type CostSource = 'reported' | 'estimated' | 'unavailable';
2
+ export type CostEvidenceKind = 'provider_reported' | 'normalized_estimate';
3
+ export type CostEvidenceStatus = 'complete' | 'inconclusive';
4
+ export type CostCurrency = 'USD' | 'unknown' | (string & {});
5
+ export type CostEvidenceReason = 'authoritative' | 'missing_cost' | 'invalid_number' | 'pricing_missing' | 'unsupported_currency' | 'conflict' | 'unbilled' | 'join_miss' | 'legacy' | 'unreadable' | 'partial';
6
+ /** Fixed, non-provider-controlled paths accepted by the evidence adapter. */
7
+ export type CostEvidenceSourcePath = 'assistant.cost' | 'step-finish.cost' | 'response.info.cost' | 'response.cost' | 'legacy.cost' | 'pricing.model';
8
+ export type CostEvidence = {
9
+ kind: CostEvidenceKind;
10
+ amount_usd: number | null;
11
+ currency: CostCurrency;
12
+ source_path: CostEvidenceSourcePath;
13
+ reason: CostEvidenceReason;
14
+ usage: TokenUsage;
15
+ model?: string;
16
+ pricing_version?: string;
17
+ pricing_effective_at?: string;
18
+ billing_basis?: string;
19
+ /** A bounded canonical digest is useful to correction producers. */
20
+ digest?: string;
21
+ };
22
+ export type CostCandidate = {
23
+ kind: CostEvidenceKind;
24
+ amount: number | null;
25
+ currency: CostCurrency;
26
+ source_path: CostEvidenceSourcePath;
27
+ usage: TokenUsage;
28
+ model?: string;
29
+ reason?: CostEvidenceReason;
30
+ };
2
31
  export type ModelPricing = {
3
32
  input_per_million: number;
4
33
  output_per_million: number;
@@ -7,6 +36,14 @@ export type ModelPricing = {
7
36
  };
8
37
  export type PricingConfig = {
9
38
  models?: Record<string, ModelPricing>;
39
+ /** Currency of normalized table rows. Defaults to USD for compatibility. */
40
+ currency?: string;
41
+ version?: string;
42
+ effective_at?: string;
43
+ billing_basis?: string;
44
+ /** Explicit provider declarations; reported currency is never inferred. */
45
+ reported_cost_currency?: Record<string, string>;
46
+ subscription_unbilled?: boolean;
10
47
  };
11
48
  export type TokenUsage = {
12
49
  tokens_input: number;
@@ -17,6 +54,15 @@ export type TokenUsage = {
17
54
  export type DelegationCostFields = TokenUsage & {
18
55
  cost_usd: number | null;
19
56
  cost_source: CostSource;
57
+ cost_evidence?: CostEvidence[];
58
+ evidence_status?: CostEvidenceStatus;
59
+ evidence_reason?: CostEvidenceReason;
60
+ record_id?: string;
61
+ identity_fingerprint?: string;
62
+ child_session_digest?: string;
63
+ parent_session_digest?: string;
64
+ version?: number;
65
+ currency?: CostCurrency;
20
66
  model?: string;
21
67
  gate?: string;
22
68
  retry_index?: number;
@@ -27,6 +73,7 @@ export type DelegationCostInput = {
27
73
  gate?: string;
28
74
  retry_index?: number;
29
75
  pricing?: PricingConfig;
76
+ reported_cost_currency?: string;
30
77
  };
31
78
  export type CostSummary = {
32
79
  total_cost_usd: number;
@@ -46,6 +93,16 @@ export type CostSummary = {
46
93
  delegations: number;
47
94
  cost_usd: number;
48
95
  }>;
96
+ total_legacy_usd: number;
97
+ conflict_count: number;
98
+ legacy_count: number;
99
+ join_miss_count: number;
100
+ telemetry_error_count: number;
101
+ accepted_corrections: number;
102
+ rejected_corrections: number;
103
+ duplicate_corrections: number;
104
+ evidence_status: CostEvidenceStatus;
105
+ currencies: string[];
49
106
  };
50
107
  export type CostSummaryRow = {
51
108
  name: string;
@@ -59,7 +116,50 @@ export type CostSummaryRow = {
59
116
  };
60
117
  export declare const BUNDLED_MODEL_PRICING: Record<string, ModelPricing>;
61
118
  export declare function buildDelegationCostFields(input?: DelegationCostInput): DelegationCostFields;
119
+ /**
120
+ * Extract only the pinned SDK shapes. The old generic traversal was
121
+ * intentionally removed: a wrapper's default cost must not shadow a child
122
+ * AssistantMessage/StepFinishPart report.
123
+ */
124
+ export declare function extractCostEvidence(raw: unknown, input?: Pick<DelegationCostInput, 'model' | 'pricing' | 'reported_cost_currency'>): CostEvidence[];
125
+ export type CostProjection = {
126
+ cost_usd: number | null;
127
+ cost_source: CostSource;
128
+ evidence_status: CostEvidenceStatus;
129
+ reason: CostEvidenceReason;
130
+ currency: CostCurrency;
131
+ };
132
+ /** Project additive evidence to the legacy scalar fields. Unknown is never zero. */
133
+ export declare function projectCostEvidence(evidence: readonly CostEvidence[]): CostProjection;
134
+ export declare function isCostEvidenceComplete(evidence: readonly CostEvidence[] | undefined): boolean;
62
135
  export declare function summarizeTelemetryCosts(directory: string): CostSummary;
136
+ export type CostFoldStats = {
137
+ conflict_count: number;
138
+ join_miss_count: number;
139
+ telemetry_error_count: number;
140
+ accepted_corrections: number;
141
+ rejected_corrections: number;
142
+ duplicate_corrections: number;
143
+ };
144
+ export type FoldedCostTelemetry = {
145
+ events: Record<string, unknown>[];
146
+ stats: CostFoldStats;
147
+ versions: Record<string, number>;
148
+ };
149
+ /**
150
+ * Fold append-only cost corrections into one effective delegation snapshot.
151
+ * Corrections are buffered and replayed in version order so telemetry arrival
152
+ * order cannot permanently discard a valid correction. Invalid/orphan
153
+ * corrections remain diagnostics and can never create a row.
154
+ */
155
+ export declare function foldTelemetryEvents(events: readonly Record<string, unknown>[]): FoldedCostTelemetry;
156
+ export declare function isCostUpgrade(current: readonly CostEvidence[], next: readonly CostEvidence[]): boolean;
63
157
  export declare function readTelemetryEvents(directory: string): Record<string, unknown>[];
158
+ /**
159
+ * Bounded asynchronous telemetry reader for live recovery paths. The status
160
+ * service and offline summaries retain the atomic synchronous snapshot above;
161
+ * recovery must not block event delivery on a full-file synchronous read.
162
+ */
163
+ export declare function readTelemetryEventsAsync(directory: string): Promise<Record<string, unknown>[]>;
64
164
  export declare function estimateCostUsd(usage: TokenUsage, model?: string, pricing?: PricingConfig): number | null;
65
165
  export declare function roundUsd(value: number): number;
@@ -4,6 +4,7 @@ import { loadFullAutoRunState } from '../full-auto/state';
4
4
  import { type RecentEscalation } from '../hooks/knowledge-escalator';
5
5
  import { getActiveFullAutoSessionID, hasActiveFullAuto, hasActiveLeanTurbo } from '../state';
6
6
  import { loadLeanTurboRunState } from '../turbo/lean/state';
7
+ import { summarizeTelemetryCosts } from './cost-accounting.js';
7
8
  /**
8
9
  * Dependency-injection seam for status-service.
9
10
  * Allows tests to intercept Lean Turbo state queries without mock.module leakage.
@@ -14,6 +15,7 @@ export declare const _internals: {
14
15
  hasActiveFullAuto: typeof hasActiveFullAuto;
15
16
  getActiveFullAutoSessionID: typeof getActiveFullAutoSessionID;
16
17
  loadFullAutoRunState: typeof loadFullAutoRunState;
18
+ summarizeTelemetryCosts: typeof summarizeTelemetryCosts;
17
19
  };
18
20
  /**
19
21
  * Structured status data returned by the status service.
@@ -175,6 +177,16 @@ export interface StatusData {
175
177
  * stores surface as typed uncertainty, never partially-trusted counts.
176
178
  */
177
179
  backgroundWork?: BackgroundWorkStatus;
180
+ /** Issue #2043: compatibility total plus provenance completeness. */
181
+ costs?: {
182
+ totalCostUsd: number;
183
+ delegations: number;
184
+ unavailableDelegations: number;
185
+ evidenceStatus: 'complete' | 'inconclusive';
186
+ conflictCount: number;
187
+ joinMissCount: number;
188
+ telemetryErrorCount: number;
189
+ };
178
190
  }
179
191
  /** Issue #2104: opt-in background-work status snapshot for /swarm status. */
180
192
  export interface BackgroundWorkStatus {
@@ -1,6 +1,6 @@
1
1
  import { createObservation, toLegacyTelemetryLine } from './observability/index.js';
2
2
  import type { DelegationCostFields } from './services/cost-accounting.js';
3
- export type TelemetryEvent = 'session_started' | 'session_ended' | 'agent_activated' | 'delegation_begin' | 'delegation_end' | 'task_state_changed' | 'gate_passed' | 'gate_failed' | 'gate_parse_error' | 'reviewer_gate_decision' | 'phase_changed' | 'budget_updated' | 'context_pruned' | 'model_fallback'
3
+ 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' | 'model_fallback'
4
4
  /**
5
5
  * Issue #2271 bug 4 — a configured agent model id was POSITIVELY confirmed
6
6
  * unresolvable against the live provider catalog (distinct from a runtime
@@ -52,6 +52,7 @@ export declare function getLocalizationContext(graph: RepoGraph, filePath: strin
52
52
  maxDeps?: number;
53
53
  maxDepth?: number;
54
54
  }): LocalizationBlock;
55
+ export declare function extractSignatureText(lines: string[], startLine: number): string;
55
56
  export declare function getContextPack(graph: RepoGraph, file: string, symbol: string, options?: {
56
57
  maxDepth?: number;
57
58
  maxTokens?: number;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * KG-14 expanded graph query functions (issue #1535).
3
+ *
4
+ * Symbol-level, impact, diff, and explainability queries over the persisted
5
+ * repo graph. Every function is stateless and read-only: inputs are validated
6
+ * by the `repo_map` tool layer (`src/tools/repo-map.ts`); this module assumes
7
+ * well-formed arguments and focuses on bounded, workspace-relative,
8
+ * provenance-bearing output.
9
+ *
10
+ * Bounding contract: every list-shaped output is capped (default caps below
11
+ * or the caller's `topN`), every result carries a `budget {returned, dropped}`
12
+ * envelope, and paths in results are workspace-relative with forward slashes.
13
+ */
14
+ import type { DiffContextResult, GraphExplainResult, GraphSymbolKind, GraphSymbolVisibility, ImpactConeResult, RepoGraph, SymbolContextResult, SymbolSearchResult } from './types';
15
+ export declare function searchSymbols(graph: RepoGraph, options: {
16
+ query: string;
17
+ kind?: GraphSymbolKind;
18
+ language?: string;
19
+ file?: string;
20
+ visibility?: GraphSymbolVisibility;
21
+ topN?: number;
22
+ }): SymbolSearchResult;
23
+ export declare function getSymbolContext(graph: RepoGraph, options: {
24
+ file?: string;
25
+ symbol?: string;
26
+ symbolId?: string;
27
+ includeSource?: boolean;
28
+ topN?: number;
29
+ }): SymbolContextResult;
30
+ export declare function getImpactCone(graph: RepoGraph, options: {
31
+ file: string;
32
+ symbol?: string;
33
+ maxDepth?: number;
34
+ topN?: number;
35
+ }): ImpactConeResult;
36
+ export declare function getDiffContext(graph: RepoGraph, options: {
37
+ files?: string[];
38
+ diff?: string;
39
+ maxDepth?: number;
40
+ topN?: number;
41
+ }): DiffContextResult;
42
+ export declare function explainGraphEntry(graph: RepoGraph, options: {
43
+ file: string;
44
+ symbol?: string;
45
+ line?: number;
46
+ topN?: number;
47
+ }): GraphExplainResult;
@@ -47,8 +47,15 @@ export declare const REPO_GRAPH_FILENAME = "repo-graph.json";
47
47
  * 1.5.0 adds an optional graph-level `repoRootId` plus additive SymbolEdge v2
48
48
  * identity, kind, confidence, resolution, and evidence fields. Legacy 1.2.0
49
49
  * four-coordinate symbol edges remain readable and are normalized in memory.
50
+ *
51
+ * 1.6.0 adds the optional per-node `exportKinds` map (declaration kind per
52
+ * symbol, keyed exactly like `exportRanges`), powering the KG-14 declaration-
53
+ * kind query axis (`symbol_search` kind filter, `symbol_context` identity).
54
+ * The field is optional, so 1.0.0–1.5.0 graphs still load; queries surface
55
+ * `kind: null` hits and a `kindSupported: false` degradation note instead of
56
+ * failing (issue #1535).
50
57
  */
51
- export declare const GRAPH_SCHEMA_VERSION = "1.5.0";
58
+ export declare const GRAPH_SCHEMA_VERSION = "1.6.0";
52
59
  /**
53
60
  * Default per-file source-size ceiling shared by graph construction and
54
61
  * query-time source reads. The builder treats this as the default value of
@@ -160,6 +167,17 @@ export interface GraphNode {
160
167
  startLine: number;
161
168
  endLine: number;
162
169
  }>;
170
+ /**
171
+ * Declaration kind per symbol, keyed by symbol name (schema >= 1.6.0;
172
+ * optional, so older graphs load unchanged). Keys are assigned in the same
173
+ * builder loop and under the same widening + duplicate-name policies as
174
+ * `exportRanges`, but ONLY at real declaration sites — re-export bindings
175
+ * add an `exportRanges` entry without a kind (the symbol is declared
176
+ * elsewhere), so `exportKinds` is a subset of `exportRanges` keys.
177
+ * Absent entries read as `kind: null` (old graph, regex-fallback scan, or
178
+ * re-exported binding).
179
+ */
180
+ exportKinds?: Record<string, GraphSymbolKind>;
163
181
  /** Imported module specifiers */
164
182
  imports: string[];
165
183
  /** Language/extension of the file */
@@ -246,6 +264,26 @@ export type SymbolEdgeKind = (typeof SYMBOL_EDGE_KIND_VALUES)[number];
246
264
  export declare const SYMBOL_EDGE_RESOLUTION_VALUES: readonly ["exact", "import_binding", "same_file_scope", "unique_name", "type_resolved", "lsp", "scip", "heuristic", "unresolved"];
247
265
  export type SymbolEdgeResolution = (typeof SYMBOL_EDGE_RESOLUTION_VALUES)[number];
248
266
  export type SymbolIdentityKind = 'symbol' | 'module';
267
+ /**
268
+ * Declaration kind of a symbol — WHAT the symbol is (function, class, …).
269
+ * Mirrors `FileSymbolFacts['defs'][number]['kind']` from
270
+ * `src/lang/symbol-graph.ts` and is persisted per node via
271
+ * `GraphNode.exportKinds` (schema >= 1.6.0).
272
+ *
273
+ * This is the DECLARATION axis and is deliberately distinct from
274
+ * {@link SymbolEdgeKind}, the RELATIONSHIP axis (CALLS/REFERENCES/…) that
275
+ * describes how two symbols connect. A symbol never referenced cross-file has
276
+ * no symbol edge but still has a declaration kind.
277
+ */
278
+ export declare const GRAPH_SYMBOL_KIND_VALUES: readonly ["function", "class", "const", "type", "interface", "enum", "method"];
279
+ export type GraphSymbolKind = (typeof GRAPH_SYMBOL_KIND_VALUES)[number];
280
+ /**
281
+ * Visibility tier derived at query time from persisted fields: a symbol in
282
+ * `GraphNode.exports` is `exported` (public module surface); a symbol that
283
+ * only exists in `exportRanges` (widened-grammar member defs) is
284
+ * `module-local`.
285
+ */
286
+ export type GraphSymbolVisibility = 'exported' | 'module-local';
249
287
  export interface SymbolEdgeEvidence {
250
288
  /** Workspace-relative source path; source text itself is never persisted. */
251
289
  file: string;
@@ -443,6 +481,202 @@ export interface DeadExportsResult {
443
481
  /** Human-readable note describing scope and limitations of the result. */
444
482
  note: string;
445
483
  }
484
+ /** One symbol hit from `symbol_search`, with declaration metadata. */
485
+ export interface SymbolHit {
486
+ /** Workspace-relative file path. */
487
+ file: string;
488
+ symbol: string;
489
+ /** Declaration kind; `null` on graphs predating schema 1.6.0 (no exportKinds). */
490
+ kind: GraphSymbolKind | null;
491
+ visibility: GraphSymbolVisibility;
492
+ language: string;
493
+ /** 1-based definition line; 0 when no line is known. */
494
+ line: number;
495
+ exported: boolean;
496
+ /** Which match tier produced this hit (results are tier-ordered). */
497
+ match: 'exact' | 'prefix' | 'substring' | 'subsequence';
498
+ }
499
+ export interface SymbolSearchResult {
500
+ query: string;
501
+ hits: SymbolHit[];
502
+ count: number;
503
+ budget: {
504
+ returned: number;
505
+ dropped: number;
506
+ };
507
+ /** False when the graph predates schema 1.6.0, so `kind` filters/hits degrade. */
508
+ kindSupported: boolean;
509
+ /** Present (non-empty) only when a filter or scan could not be fully applied. */
510
+ warnings: string[];
511
+ }
512
+ /**
513
+ * One symbol-level edge inside an impact cone. `relationshipKind`,
514
+ * `confidence`, and `resolution` come from the underlying `SymbolEdge` and
515
+ * are `null` for legacy (pre-1.5.0) edges.
516
+ */
517
+ export interface ConeEntry {
518
+ /** Workspace-relative file path. */
519
+ file: string;
520
+ symbol: string;
521
+ direction: 'caller' | 'callee';
522
+ /** 1 = direct neighbor of the target. */
523
+ depth: number;
524
+ relationshipKind: SymbolEdgeKind | null;
525
+ confidence: number | null;
526
+ resolution: SymbolEdgeResolution | null;
527
+ }
528
+ /** Focused definition-first context for one symbol. */
529
+ export interface SymbolContextResult {
530
+ found: boolean;
531
+ identity: {
532
+ file: string;
533
+ symbol: string;
534
+ symbolId: string | null;
535
+ kind: GraphSymbolKind | null;
536
+ visibility: GraphSymbolVisibility;
537
+ language: string;
538
+ startLine: number;
539
+ endLine: number | null;
540
+ } | null;
541
+ signature?: string;
542
+ source?: {
543
+ text: string;
544
+ mode: 'full' | 'signature' | 'summary';
545
+ hash: string;
546
+ startLine: number;
547
+ endLine: number;
548
+ };
549
+ callers: ConeEntry[];
550
+ callees: ConeEntry[];
551
+ /** Present only when resolution scanned stable IDs to match `symbolId`. */
552
+ symbolIdScan?: {
553
+ computed: number;
554
+ capped: boolean;
555
+ };
556
+ budget: {
557
+ callersReturned: number;
558
+ calleesReturned: number;
559
+ dropped: number;
560
+ };
561
+ warnings: string[];
562
+ note?: string;
563
+ }
564
+ /** Structured impact cone for a file or file+symbol target. */
565
+ export interface ImpactConeResult {
566
+ target: {
567
+ file: string;
568
+ symbol: string | null;
569
+ };
570
+ /** Symbol-level entries (empty when no symbol was given or the graph has no symbolEdges). */
571
+ entries: ConeEntry[];
572
+ /** File-level blast radius for the same target and depth — risk semantics identical to `blast_radius`. */
573
+ fileImpact: BlastRadiusResult;
574
+ risk: BlastRadiusResult['riskLevel'];
575
+ /** Fixed-vocabulary notes with counts (transitive spread, hubs, low-confidence edges, tests, boundaries). */
576
+ riskNotes: string[];
577
+ /** Cone files carrying the `test_file` role. */
578
+ tests: string[];
579
+ routes: Array<{
580
+ file: string;
581
+ fact: RouteFact;
582
+ }>;
583
+ dataFacts: Array<{
584
+ file: string;
585
+ fact: DataOperationFact;
586
+ }>;
587
+ securityFacts: Array<{
588
+ file: string;
589
+ fact: SecurityFact;
590
+ }>;
591
+ boundaries: Array<{
592
+ name: string;
593
+ files: string[];
594
+ }>;
595
+ budget: {
596
+ entriesReturned: number;
597
+ dropped: number;
598
+ };
599
+ truncated: boolean;
600
+ warnings: string[];
601
+ }
602
+ /** One changed symbol mapped from a diff hunk (or listed file-level). */
603
+ export interface DiffSymbolChange {
604
+ symbol: string;
605
+ kind: GraphSymbolKind | null;
606
+ startLine: number;
607
+ endLine: number;
608
+ /** Hunk-mode: changed graph lines that intersect the symbol span (bounded). */
609
+ changedLines: number[];
610
+ }
611
+ export interface DiffFileSummary {
612
+ /** Workspace-relative file path. */
613
+ file: string;
614
+ /** False when the changed file is not present in the graph (e.g. deleted or unscanned). */
615
+ known: boolean;
616
+ symbols: DiffSymbolChange[];
617
+ note?: string;
618
+ }
619
+ export interface DiffContextResult {
620
+ /** `hunk` when a diff text was parsed with line ranges; `file` when only file names were given. */
621
+ granularity: 'hunk' | 'file';
622
+ files: DiffFileSummary[];
623
+ impact: {
624
+ files: string[];
625
+ tests: string[];
626
+ risk: BlastRadiusResult['riskLevel'];
627
+ notes: string[];
628
+ };
629
+ budget: {
630
+ returned: number;
631
+ dropped: number;
632
+ };
633
+ truncated: boolean;
634
+ warnings: string[];
635
+ }
636
+ /**
637
+ * One reason a file/symbol/span is graph-relevant: its definition, the
638
+ * symbol edges that connect it, or file-level import relationships.
639
+ */
640
+ export interface ExplainReason {
641
+ type: 'definition' | 'referenced_by' | 'references' | 'imported_by' | 'imports';
642
+ /** Workspace-relative file path of the OTHER side of the relationship (or the definition file). */
643
+ file: string;
644
+ symbol?: string;
645
+ kind: GraphSymbolKind | null;
646
+ relationshipKind?: SymbolEdgeKind;
647
+ /** Undefined for definition/import reasons; `null`-able inside evidence-bearing edges is avoided by omitting. */
648
+ confidence?: number;
649
+ resolution?: SymbolEdgeResolution;
650
+ evidence?: SymbolEdgeEvidence[];
651
+ }
652
+ export interface GraphExplainResult {
653
+ target: {
654
+ file: string;
655
+ symbol: string | null;
656
+ line: number | null;
657
+ };
658
+ fileKnown: boolean;
659
+ /** When `line` was given: the symbol whose span contains it (smallest span wins). */
660
+ resolvedSpan?: {
661
+ symbol: string;
662
+ startLine: number;
663
+ endLine: number;
664
+ };
665
+ definition?: {
666
+ file: string;
667
+ symbol: string;
668
+ kind: GraphSymbolKind | null;
669
+ visibility: GraphSymbolVisibility;
670
+ startLine: number;
671
+ endLine: number | null;
672
+ };
673
+ reasons: ExplainReason[];
674
+ budget: {
675
+ returned: number;
676
+ dropped: number;
677
+ };
678
+ warnings: string[];
679
+ }
446
680
  export interface GraphExtractionFailure {
447
681
  file: string;
448
682
  language: string;
@@ -509,6 +743,38 @@ export interface GraphHealthResult {
509
743
  walkTruncationReason: 'budget' | 'cap' | null;
510
744
  incrementalFallbacks: number;
511
745
  notes: string[];
746
+ /**
747
+ * KG-14 additive summaries (issue #1535). Optional on the interface so
748
+ * external constructors stay source-compatible; `getGraphHealth` always
749
+ * populates them (zero-valued when the underlying data is absent).
750
+ */
751
+ /** Symbol-edge population summary (legacy edges counted under `withV2Fields: false`). */
752
+ symbolEdgeSummary?: {
753
+ total: number;
754
+ withV2Fields: number;
755
+ lowConfidence: number;
756
+ unresolved: number;
757
+ };
758
+ /** Resolution-attribution histogram over symbol edges (includes `unrecorded`). */
759
+ resolutionBreakdown?: Record<string, number>;
760
+ /**
761
+ * Stale composition from the freshness probe; `null` when no probe was
762
+ * supplied. `probeTruncated` is `FreshnessProbe.truncated` — the freshness
763
+ * WALK hitting its budget — and is deliberately a different signal from
764
+ * build-time `walkTruncated` above (the graph BUILD walk).
765
+ */
766
+ staleSummary?: {
767
+ changed: number;
768
+ removed: number;
769
+ probeTruncated: boolean;
770
+ } | null;
771
+ /** Extraction-failure histogram keyed by failure reason. */
772
+ extractionFailureSummary?: Record<string, number>;
773
+ /** How many nodes carry schema 1.6.0 `exportKinds` data. */
774
+ kindCoverage?: {
775
+ nodesWithKinds: number;
776
+ nodesTotal: number;
777
+ };
512
778
  }
513
779
  /** Authoritative states returned by the bounded repository freshness probe. */
514
780
  export type FreshnessProbeState = 'clean' | 'drifted' | 'no-fingerprint' | 'inconclusive';
@@ -11,6 +11,7 @@
11
11
  * storage.ts — safe load and save to .swarm/repo-graph.json
12
12
  * builder.ts — workspace scanning and full-graph construction
13
13
  * incremental.ts — incremental updates for changed files
14
+ * symbol-query.ts — KG-14 symbol/impact/diff/explain queries (issue #1535)
14
15
  *
15
16
  * All existing imports of this module continue to work unchanged.
16
17
  */
@@ -26,6 +27,7 @@ export { extractFileOntology } from './repo-graph/ontology';
26
27
  export type { DeadExportsOptions } from './repo-graph/query';
27
28
  export { buildOntologyPreflightPacket, getBlastRadius, getCallers, getContextPack, getDeadExports, getDependencies, getFileOntology, getGraphHealth, getGraphNode, getImporters, getKeyFiles, getLocalizationContext, getPackageBoundaries, getSymbolConsumers, isGraphFresh, resetQueryCache, } from './repo-graph/query';
28
29
  export { getGraphPath, loadGraph, loadGraphSync, loadOrCreateGraph, saveGraph, saveIfDirty, } from './repo-graph/storage';
29
- export type { AskHit, AskOptions, AskResult, BlastRadiusResult, BuildWorkspaceGraphOptions, CallerReference, ContextPackCoverage, ContextPackResult, ContextPackSnippet, ContextPackSourceMode, ContextPackSpan, ConventionFact, DataOperationFact, DeadExportCandidate, DeadExportsResult, FileOntology, FileReference, FileRole, FreshnessProbeState, GraphEdge, GraphExtractionFailure, GraphExtractorInputWitness, GraphHealthResult, GraphNode, GraphUnresolvedImport, LocalizationBlock, OntologyFinding, PackageBoundarySummary, RepoGraph, RepoGraphDiagnostics, RouteFact, RouteMethod, SecurityFact, SymbolEdge, SymbolEdgeEvidence, SymbolEdgeKind, SymbolEdgeResolution, SymbolIdentityKind, SymbolReference, } from './repo-graph/types';
30
+ export { explainGraphEntry, getDiffContext, getImpactCone, getSymbolContext, searchSymbols, } from './repo-graph/symbol-query';
31
+ export type { AskHit, AskOptions, AskResult, BlastRadiusResult, BuildWorkspaceGraphOptions, CallerReference, ConeEntry, ContextPackCoverage, ContextPackResult, ContextPackSnippet, ContextPackSourceMode, ContextPackSpan, ConventionFact, DataOperationFact, DeadExportCandidate, DeadExportsResult, DiffContextResult, DiffFileSummary, DiffSymbolChange, ExplainReason, FileOntology, FileReference, FileRole, FreshnessProbeState, GraphEdge, GraphExplainResult, GraphExtractionFailure, GraphExtractorInputWitness, GraphHealthResult, GraphNode, GraphSymbolKind, GraphSymbolVisibility, GraphUnresolvedImport, ImpactConeResult, LocalizationBlock, OntologyFinding, PackageBoundarySummary, RepoGraph, RepoGraphDiagnostics, RouteFact, RouteMethod, SecurityFact, SymbolContextResult, SymbolEdge, SymbolEdgeEvidence, SymbolEdgeKind, SymbolEdgeResolution, SymbolHit, SymbolIdentityKind, SymbolReference, SymbolSearchResult, } from './repo-graph/types';
30
32
  export { createEmptyGraph, DEFAULT_MAX_SOURCE_BYTES, GRAPH_SCHEMA_VERSION, inferPackageBoundary, isSchemaVersionAtLeast, normalizeGraphPath, REPO_GRAPH_FILENAME, updateGraphMetadata, } from './repo-graph/types';
31
33
  export { validateGraphEdge, validateGraphNode, validateWorkspace, } from './repo-graph/validation';