@atolis-hq/wake 0.4.88 → 0.4.90

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 (29) hide show
  1. package/dist/src/bootstrap/analytics-reports.d.ts +2 -1
  2. package/dist/src/bootstrap/analytics-reports.js +5 -3
  3. package/dist/src/bootstrap/composition-root.d.ts +2 -0
  4. package/dist/src/bootstrap/composition-root.js +5 -1
  5. package/dist/src/bootstrap/run-repository-lookup.d.ts +4 -0
  6. package/dist/src/bootstrap/run-repository-lookup.js +59 -0
  7. package/dist/src/bootstrap/surface-api-applications.js +1 -1
  8. package/dist/src/bootstrap/version.js +1 -1
  9. package/dist/src/execution/application/run-duration.d.ts +10 -0
  10. package/dist/src/execution/application/run-duration.js +70 -0
  11. package/dist/src/execution/application/run-reports.d.ts +10 -6
  12. package/dist/src/execution/application/run-reports.js +45 -25
  13. package/dist/src/execution/contracts/run-report-value.d.ts +3 -0
  14. package/dist/src/execution/contracts/run-report-value.js +2 -0
  15. package/dist/src/integrations/github/contracts/external-key.d.ts +2 -0
  16. package/dist/src/integrations/github/contracts/external-key.js +10 -0
  17. package/dist/src/integrations/github/index.d.ts +1 -0
  18. package/dist/src/integrations/github/index.js +1 -0
  19. package/dist/src/kernel/contracts/reports.d.ts +20 -1
  20. package/dist/src/resources/contracts/views.d.ts +1 -0
  21. package/dist/src/resources/domain/repository-candidate.d.ts +3 -0
  22. package/dist/src/resources/domain/repository-candidate.js +13 -0
  23. package/dist/src/resources/index.d.ts +1 -0
  24. package/dist/src/resources/index.js +1 -0
  25. package/dist/src/surfaces/api/contracts/observability.d.ts +1 -1
  26. package/dist/src/surfaces/web-assets/assets/index-B0jIss24.js +1192 -0
  27. package/dist/src/surfaces/web-assets/index.html +1 -1
  28. package/package.json +1 -1
  29. package/dist/src/surfaces/web-assets/assets/index-D4-8tZ5f.js +0 -1192
@@ -1,6 +1,7 @@
1
1
  import type { EventJournal } from '@atolis-hq/eventing';
2
2
  import { type ReportWindowId } from '../kernel/index.js';
3
- export declare function createAnalyticsReports(journal: EventJournal, now: () => string): {
3
+ import type { ResourceRepositoryIdentityResolver } from '../resources/index.js';
4
+ export declare function createAnalyticsReports(journal: EventJournal, now: () => string, resolveIdentity?: ResourceRepositoryIdentityResolver): {
4
5
  catalogue: () => {
5
6
  id: string;
6
7
  title: string;
@@ -1,13 +1,15 @@
1
- import { createRunBreakdownReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
1
+ import { createRunBreakdownReport, createRunDurationReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
2
2
  import { reportWindow } from '../kernel/index.js';
3
3
  import { createWorkThroughputReport, queryWorkCompletionSummary } from '../orchestration/index.js';
4
+ import { createRunRepositoryLookup } from './run-repository-lookup.js';
4
5
  import { sampledMeta } from './surface-api-metadata.js';
5
- export function createAnalyticsReports(journal, now) {
6
+ export function createAnalyticsReports(journal, now, resolveIdentity) {
6
7
  const definitions = [
7
8
  createRunOutcomesReport(journal),
8
- createRunBreakdownReport(journal),
9
+ createRunBreakdownReport(journal, createRunRepositoryLookup(journal, resolveIdentity)),
9
10
  createRunUsageReport(journal),
10
11
  createWorkThroughputReport(journal),
12
+ createRunDurationReport(journal),
11
13
  ];
12
14
  return {
13
15
  catalogue: () => definitions.map(({ id, title }) => ({ id, title })),
@@ -80,7 +80,9 @@ export interface CompositionRoot {
80
80
  readonly runnerPipeline: RunnerPipeline;
81
81
  readonly requestImmediatePoll: (adapter: string) => void;
82
82
  readonly resolveResourceLink: ResourceLinkResolver;
83
+ readonly resolveResourceRepositoryIdentity: (externalKey: Parameters<ResourceLinkResolver>[0]) => string | undefined;
83
84
  }
85
+ export declare function resolveResourceRepositoryIdentity(externalKey: Parameters<ResourceLinkResolver>[0]): string | undefined;
84
86
  export declare function createDiagnosticRoot(wakeRoot: string): Promise<{
85
87
  providers: readonly ProviderInstance[];
86
88
  providerFailures: readonly ProviderCompositionFailure[];
@@ -4,7 +4,7 @@ import { ArtifactContextService, FileArtifactMcpSessionStore, FileArtifactStore,
4
4
  import { DispatchPolicy, createActivationScheduler, createActivationSchedulerSubscriber, createControlPlaneService, createDurableRunnerIneligibility, createRunnerControlService, } from '../control-plane/index.js';
5
5
  import { createConversationService } from '../conversations/index.js';
6
6
  import { ExecutionCancellationReason, GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, createLocalProcessInspector, createRunnerMemoryProfileDecorator, } from '../execution/index.js';
7
- import { createGitHubAgentContextReader, gitHubProviderDefinition, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
7
+ import { createGitHubAgentContextReader, gitHubProviderDefinition, gitHubRepositoryIdentity, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
8
8
  import { SystemClock, UlidIdGenerator } from '../kernel/index.js';
9
9
  import { compileWorkflow, createAgentActivityClassifier, createOrchestrationService, } from '../orchestration/index.js';
10
10
  import { createResourceLookup, createResourceService, resourceId, } from '../resources/index.js';
@@ -24,6 +24,9 @@ import { createRunnerRegistry } from './runner-registry.js';
24
24
  import { createTranscriptRetention } from './transcript-retention.js';
25
25
  import { ProcessorTriggerCheckpointStore } from './trigger-checkpoint-store.js';
26
26
  import { createUpdateMaintenanceLease, } from './update-maintenance-lease.js';
27
+ export function resolveResourceRepositoryIdentity(externalKey) {
28
+ return externalKey.adapter === 'github' ? gitHubRepositoryIdentity(externalKey.key) : undefined;
29
+ }
27
30
  const resourceLinkResolvers = {
28
31
  github: resolveGitHubResourceUrl,
29
32
  };
@@ -272,6 +275,7 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
272
275
  processorRuntime,
273
276
  advanceOnce,
274
277
  resolveResourceLink,
278
+ resolveResourceRepositoryIdentity,
275
279
  ...runtime,
276
280
  };
277
281
  }
@@ -0,0 +1,4 @@
1
+ import { type EventJournal } from '@atolis-hq/eventing';
2
+ import type { RunRepositoryLookup } from '../execution/index.js';
3
+ import { type ResourceRepositoryIdentityResolver } from '../resources/index.js';
4
+ export declare function createRunRepositoryLookup(journal: EventJournal, resolveIdentity?: ResourceRepositoryIdentityResolver): RunRepositoryLookup;
@@ -0,0 +1,59 @@
1
+ import { scanJournal, yieldScan } from '@atolis-hq/eventing';
2
+ import { OrchestrationEventType, selectWorkflowOrchestrationEvent, } from '../orchestration/index.js';
3
+ import { BuiltInResourceKind, repositoryCandidate, resourceCorrelationProjection, resourceProjection, selectResourceEvent, } from '../resources/index.js';
4
+ export function createRunRepositoryLookup(journal, resolveIdentity) {
5
+ return async (query) => {
6
+ const workByWorkflow = new Map();
7
+ const resources = new Map();
8
+ const correlations = new Map();
9
+ for await (const event of scanJournal(journal, query.signal)) {
10
+ const workflow = selectWorkflowOrchestrationEvent(event);
11
+ if (workflow?.event.eventType === OrchestrationEventType.InstanceStarted)
12
+ workByWorkflow.set(workflow.stream.id, workflow.event.payload.workItemId);
13
+ const resource = selectResourceEvent(event);
14
+ if (resource === null)
15
+ continue;
16
+ const id = resource.stream.id;
17
+ resources.set(id, resourceProjection.project(resources.get(id) ?? null, event));
18
+ correlations.set(id, resourceCorrelationProjection.project(correlations.get(id) ?? [], event));
19
+ }
20
+ const byWork = await groupCandidates(resources, correlations, query.signal);
21
+ let processed = 0;
22
+ const identities = new Map();
23
+ for (const [work, candidates] of byWork) {
24
+ if (processed++ % 100 === 0)
25
+ await yieldScan(query.signal);
26
+ identities.set(work, candidateIdentity(candidates, resolveIdentity));
27
+ }
28
+ return (run) => {
29
+ const work = workByWorkflow.get(run.workflowInstanceId);
30
+ return work === undefined ? undefined : identities.get(work);
31
+ };
32
+ };
33
+ }
34
+ async function groupCandidates(resources, correlations, signal) {
35
+ const byWork = new Map();
36
+ let processed = 0;
37
+ for (const [id, links] of correlations) {
38
+ if (processed++ % 100 === 0)
39
+ await yieldScan(signal);
40
+ signal?.throwIfAborted();
41
+ const resource = resources.get(id);
42
+ if (resource == null)
43
+ continue;
44
+ for (const link of links) {
45
+ const candidates = byWork.get(link.workItemId) ?? [];
46
+ candidates.push(resource);
47
+ byWork.set(link.workItemId, candidates);
48
+ }
49
+ }
50
+ return byWork;
51
+ }
52
+ function candidateIdentity(candidates, resolveIdentity) {
53
+ const resource = repositoryCandidate(candidates);
54
+ if (resource === undefined)
55
+ return undefined;
56
+ if (resource.kind === BuiltInResourceKind.Repository)
57
+ return resource.externalKey.key || undefined;
58
+ return resolveIdentity?.(resource.externalKey);
59
+ }
@@ -190,7 +190,7 @@ async function recentEvents(journal, beforeGlobalPosition, limit, include) {
190
190
  }
191
191
  function createObservabilityApplications(root, now) {
192
192
  return {
193
- reports: createAnalyticsReports(root.journal, now),
193
+ reports: createAnalyticsReports(root.journal, now, root.resolveResourceRepositoryIdentity),
194
194
  async metrics(query = { days: 7 }) {
195
195
  const collectedAt = now();
196
196
  const stored = await root.projections.read(analyticsProjection.name, 'global');
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
124
124
  return `g${headHash.slice(0, 7)}`;
125
125
  return '0.1.0-dev';
126
126
  }
127
- export const wakeVersion = "v0.4.88";
127
+ export const wakeVersion = "v0.4.90";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -0,0 +1,10 @@
1
+ import { type DurationReport, type ReportDescriptor, type ReportQuery, type TimeSeriesReport } from '../../kernel/index.js';
2
+ import type { RunView } from '../contracts/views.js';
3
+ export declare function collectDurations(query: ReportQuery, buckets: TimeSeriesReport['buckets'], dimensions: readonly {
4
+ readonly id: string;
5
+ readonly title: string;
6
+ readonly value: (run: RunView) => string | undefined;
7
+ }[], durationDescriptor: ReportDescriptor): {
8
+ add(run: RunView, bucketIndex: number): void;
9
+ report(): Promise<DurationReport>;
10
+ };
@@ -0,0 +1,70 @@
1
+ import { yieldScan } from '@atolis-hq/eventing';
2
+ import { median, } from '../../kernel/index.js';
3
+ import { RunReportValue } from '../contracts/run-report-value.js';
4
+ function runDuration(run) {
5
+ if (run.finishedAt === undefined)
6
+ return null;
7
+ const duration = Date.parse(run.finishedAt) - Date.parse(run.startedAt);
8
+ return Number.isFinite(duration) && duration >= 0 ? duration : null;
9
+ }
10
+ export function collectDurations(query, buckets, dimensions, durationDescriptor) {
11
+ const durations = [];
12
+ const durationBuckets = buckets.map(() => []);
13
+ const durationGroups = dimensions.slice(0, 2).map(() => new Map());
14
+ return {
15
+ add(run, bucketIndex) {
16
+ const duration = runDuration(run);
17
+ if (duration !== null) {
18
+ durations.push(duration);
19
+ durationBuckets[bucketIndex].push(duration);
20
+ dimensions.slice(0, 2).forEach((dimension, index) => {
21
+ const value = dimension.value(run) ?? RunReportValue.Unknown;
22
+ const groups = durationGroups[index];
23
+ const values = groups.get(value) ?? [];
24
+ values.push(duration);
25
+ groups.set(value, values);
26
+ });
27
+ }
28
+ },
29
+ async report() {
30
+ const statistics = async (values) => {
31
+ let sum = 0;
32
+ for (const [index, value] of values.entries()) {
33
+ if (index % 1024 === 0)
34
+ await yieldScan(query.signal);
35
+ sum += value;
36
+ }
37
+ return {
38
+ count: values.length,
39
+ medianMs: await median(values, () => yieldScan(query.signal)),
40
+ averageMs: values.length === 0 ? null : sum / values.length,
41
+ };
42
+ };
43
+ const groups = [];
44
+ for (const [index, dimension] of dimensions.slice(0, 2).entries()) {
45
+ const rows = [];
46
+ for (const [value, values] of durationGroups[index]) {
47
+ await yieldScan(query.signal);
48
+ rows.push({ value, ...(await statistics(values)) });
49
+ }
50
+ rows.sort((a, b) => b.count - a.count || (a.value < b.value ? -1 : a.value > b.value ? 1 : 0));
51
+ groups.push({ id: dimension.id, title: dimension.title, rows });
52
+ }
53
+ const durationSeries = [];
54
+ for (const [index, bucket] of buckets.entries()) {
55
+ durationSeries.push({
56
+ from: bucket.from,
57
+ to: bucket.to,
58
+ ...(await statistics(durationBuckets[index])),
59
+ });
60
+ }
61
+ return {
62
+ report: durationDescriptor,
63
+ window: query.window,
64
+ statistics: await statistics(durations),
65
+ groups,
66
+ buckets: durationSeries,
67
+ };
68
+ },
69
+ };
70
+ }
@@ -1,11 +1,13 @@
1
1
  import { type EventJournal } from '@atolis-hq/eventing';
2
- import { type BreakdownReport, type ReportDefinition, type ReportQuery, type TimeSeriesReport, type ValueOf } from '../../kernel/index.js';
2
+ import { type BreakdownReport, type DurationReport, type ReportDefinition, type ReportQuery, type TimeSeriesReport, type ValueOf } from '../../kernel/index.js';
3
3
  import type { RunView } from '../contracts/views.js';
4
4
  export declare const RunReportId: {
5
+ readonly Duration: "run-duration";
5
6
  readonly Outcomes: "run-outcomes-over-time";
6
7
  readonly Usage: "token-and-cost-usage";
7
8
  readonly Breakdown: "run-breakdowns-by-dimension";
8
9
  };
10
+ export declare function createRunDurationReport(journal: EventJournal): ReportDefinition;
9
11
  export declare const RunUsageMeasure: {
10
12
  readonly Tokens: "total-tokens";
11
13
  readonly CostUsd: "total-cost-usd";
@@ -16,11 +18,12 @@ export declare const RunReportDimension: {
16
18
  readonly Stage: "run-stage";
17
19
  readonly Runner: "run-runner";
18
20
  readonly Model: "run-model";
21
+ readonly Repository: "run-repository";
22
+ readonly RunnerPool: "run-runner-pool";
19
23
  };
20
- export declare const RunReportValue: {
21
- readonly Unknown: "unknown";
22
- };
23
- export declare function createRunBreakdownReport(journal: EventJournal): ReportDefinition;
24
+ export { RunReportValue } from '../contracts/run-report-value.js';
25
+ export type RunRepositoryLookup = (query: ReportQuery) => Promise<(run: RunView) => string | undefined>;
26
+ export declare function createRunBreakdownReport(journal: EventJournal, repositories?: RunRepositoryLookup): ReportDefinition;
24
27
  export declare const RunReportOutcome: {
25
28
  readonly Completed: "completed";
26
29
  readonly Blocked: "blocked";
@@ -40,7 +43,8 @@ export interface RunSummary {
40
43
  }
41
44
  export declare function runReportOutcome(run: RunView): RunReportOutcome;
42
45
  export declare function createRunOutcomesReport(journal: EventJournal): ReportDefinition;
43
- export declare function queryRunAnalytics(journal: EventJournal, query: ReportQuery): Promise<{
46
+ export declare function queryRunAnalytics(journal: EventJournal, query: ReportQuery, repositories?: RunRepositoryLookup): Promise<{
47
+ duration: DurationReport;
44
48
  report: TimeSeriesReport;
45
49
  breakdown: BreakdownReport;
46
50
  usage: TimeSeriesReport;
@@ -1,15 +1,25 @@
1
1
  import { scanJournal, yieldScan } from '@atolis-hq/eventing';
2
2
  import { ActivityOutcomeKind } from '../../activities/index.js';
3
- import { defineClosedVocabulary, median, } from '../../kernel/index.js';
3
+ import { defineClosedVocabulary, } from '../../kernel/index.js';
4
4
  import { selectRunExecutionEvent } from '../contracts/events.js';
5
+ import { RunReportValue } from '../contracts/run-report-value.js';
5
6
  import { agentTokenUsage } from '../contracts/runner.js';
6
7
  import { RunStatus } from '../contracts/vocabulary.js';
7
8
  import { foldRunEvent } from '../domain/run.js';
9
+ import { collectDurations } from './run-duration.js';
8
10
  export const RunReportId = defineClosedVocabulary({
11
+ Duration: 'run-duration',
9
12
  Outcomes: 'run-outcomes-over-time',
10
13
  Usage: 'token-and-cost-usage',
11
14
  Breakdown: 'run-breakdowns-by-dimension',
12
15
  });
16
+ const durationDescriptor = { id: RunReportId.Duration, title: 'Run duration' };
17
+ export function createRunDurationReport(journal) {
18
+ return {
19
+ ...durationDescriptor,
20
+ query: async (query) => (await queryRunAnalytics(journal, query)).duration,
21
+ };
22
+ }
13
23
  export const RunUsageMeasure = defineClosedVocabulary({
14
24
  Tokens: 'total-tokens',
15
25
  CostUsd: 'total-cost-usd',
@@ -30,19 +40,31 @@ export const RunReportDimension = defineClosedVocabulary({
30
40
  Stage: 'run-stage',
31
41
  Runner: 'run-runner',
32
42
  Model: 'run-model',
43
+ Repository: 'run-repository',
44
+ RunnerPool: 'run-runner-pool',
33
45
  });
34
- export const RunReportValue = defineClosedVocabulary({ Unknown: 'unknown' });
46
+ export { RunReportValue } from '../contracts/run-report-value.js';
35
47
  const dimensions = [
36
48
  { id: RunReportDimension.Action, title: 'Action', value: (run) => run.activity },
37
49
  { id: RunReportDimension.Stage, title: 'Stage', value: (run) => run.stage },
38
50
  { id: RunReportDimension.Runner, title: 'Runner', value: (run) => run.runner?.name },
39
51
  { id: RunReportDimension.Model, title: 'Model', value: (run) => run.runner?.model },
52
+ {
53
+ id: RunReportDimension.Repository,
54
+ title: 'Repository',
55
+ value: (_run) => undefined,
56
+ },
57
+ {
58
+ id: RunReportDimension.RunnerPool,
59
+ title: 'Runner pool',
60
+ value: (run) => run.runner?.pool,
61
+ },
40
62
  ];
41
- export function createRunBreakdownReport(journal) {
63
+ export function createRunBreakdownReport(journal, repositories) {
42
64
  return {
43
65
  id: RunReportId.Breakdown,
44
66
  title: 'Run breakdowns by dimension',
45
- query: async (query) => (await queryRunAnalytics(journal, query)).breakdown,
67
+ query: async (query) => (await queryRunAnalytics(journal, query, repositories)).breakdown,
46
68
  };
47
69
  }
48
70
  export const RunReportOutcome = defineClosedVocabulary({
@@ -85,23 +107,22 @@ export function createRunOutcomesReport(journal) {
85
107
  query: async (query) => (await queryRunAnalytics(journal, query)).report,
86
108
  };
87
109
  }
88
- export async function queryRunAnalytics(journal, query) {
89
- const grouped = await readRuns(journal, query);
110
+ export async function queryRunAnalytics(journal, query, repositories) {
111
+ const repositoryForRun = await repositories?.(query);
90
112
  const from = Date.parse(query.window.from);
91
113
  const to = Date.parse(query.window.to);
92
114
  const first = Math.floor(from / query.window.bucketMs) * query.window.bucketMs;
93
- const zero = () => Object.fromEntries(series.map(({ id }) => [id, 0]));
94
115
  const buckets = outcomeBuckets(first, to, query.window.bucketMs);
95
116
  const usageBuckets = buckets.map(({ from, to }) => ({
96
117
  from,
97
118
  to,
98
119
  values: { [RunUsageMeasure.Tokens]: 0, [RunUsageMeasure.CostUsd]: 0 },
99
120
  }));
100
- const totals = zero();
101
- const durations = [];
121
+ const totals = Object.fromEntries(series.map(({ id }) => [id, 0]));
122
+ const durationData = collectDurations(query, buckets, dimensions, durationDescriptor);
102
123
  const counts = dimensions.map(() => new Map());
103
124
  let runs = 0, totalTokens = 0, totalCostUsd = 0, processed = 0;
104
- for (const run of grouped.values()) {
125
+ for (const run of (await readRuns(journal, query)).values()) {
105
126
  if (processed++ % 100 === 0)
106
127
  await yieldScan(query.signal);
107
128
  const start = Date.parse(run.startedAt);
@@ -111,11 +132,7 @@ export async function queryRunAnalytics(journal, query) {
111
132
  totals[outcome]++;
112
133
  buckets[Math.floor((start - first) / query.window.bucketMs)].values[outcome]++;
113
134
  runs++;
114
- dimensions.forEach((dimension, index) => {
115
- const value = dimension.value(run) ?? RunReportValue.Unknown;
116
- const groups = counts[index];
117
- groups.set(value, (groups.get(value) ?? 0) + 1);
118
- });
135
+ countDimensions(run, counts, repositoryForRun);
119
136
  const usage = agentTokenUsage(run.agent?.metadata);
120
137
  const tokens = finiteOrZero(usage.tokens);
121
138
  const cost = finiteOrZero(usage.costUsd);
@@ -124,12 +141,12 @@ export async function queryRunAnalytics(journal, query) {
124
141
  const bucket = usageBuckets[Math.floor((start - first) / query.window.bucketMs)];
125
142
  bucket.values[RunUsageMeasure.Tokens] += tokens;
126
143
  bucket.values[RunUsageMeasure.CostUsd] += cost;
127
- const duration = runDuration(run);
128
- if (duration !== null)
129
- durations.push(duration);
144
+ durationData.add(run, Math.floor((start - first) / query.window.bucketMs));
130
145
  }
146
+ const duration = await durationData.report();
131
147
  query.signal?.throwIfAborted();
132
148
  return {
149
+ duration,
133
150
  report: {
134
151
  report: { id: RunReportId.Outcomes, title: 'Run outcomes over time' },
135
152
  window: query.window,
@@ -152,19 +169,13 @@ export async function queryRunAnalytics(journal, query) {
152
169
  failed: totals[RunReportOutcome.Failed],
153
170
  totalTokens,
154
171
  totalCostUsd,
155
- medianRunDurationMs: await median(durations, () => yieldScan(query.signal)),
172
+ medianRunDurationMs: duration.statistics.medianMs,
156
173
  },
157
174
  };
158
175
  }
159
176
  function finiteOrZero(value) {
160
177
  return Number.isFinite(value) ? value : 0;
161
178
  }
162
- function runDuration(run) {
163
- if (run.finishedAt === undefined)
164
- return null;
165
- const duration = Date.parse(run.finishedAt) - Date.parse(run.startedAt);
166
- return Number.isFinite(duration) && duration >= 0 ? duration : null;
167
- }
168
179
  async function readRuns(journal, query) {
169
180
  const grouped = new Map();
170
181
  for await (const event of scanJournal(journal, query.signal)) {
@@ -199,3 +210,12 @@ function outcomeBuckets(first, to, bucketMs) {
199
210
  });
200
211
  return buckets;
201
212
  }
213
+ function countDimensions(run, counts, repositoryForRun) {
214
+ dimensions.forEach((dimension, index) => {
215
+ const value = (dimension.id === RunReportDimension.Repository
216
+ ? repositoryForRun?.(run)
217
+ : dimension.value(run)) ?? RunReportValue.Unknown;
218
+ const groups = counts[index];
219
+ groups.set(value, (groups.get(value) ?? 0) + 1);
220
+ });
221
+ }
@@ -0,0 +1,3 @@
1
+ export declare const RunReportValue: {
2
+ readonly Unknown: "unknown";
3
+ };
@@ -0,0 +1,2 @@
1
+ import { defineClosedVocabulary } from '../../kernel/index.js';
2
+ export const RunReportValue = defineClosedVocabulary({ Unknown: 'unknown' });
@@ -5,4 +5,6 @@ interface GitHubResourceLocator {
5
5
  }
6
6
  export declare function formatGitHubResourceKey(locator: GitHubResourceLocator): string;
7
7
  export declare function parseGitHubResourceKey(key: string): GitHubResourceLocator;
8
+ /** Resolve only provider-owned issue/PR keys; malformed historical keys remain unknown. */
9
+ export declare function gitHubRepositoryIdentity(key: string): string | undefined;
8
10
  export {};
@@ -17,3 +17,13 @@ export function parseGitHubResourceKey(key) {
17
17
  throw new Error(`Invalid GitHub resource key: ${key}: ${parsed.error.issues.map((issue) => issue.message).join('; ')}`, { cause: parsed.error });
18
18
  return { owner: matched[1], repo: matched[2], number: parsed.data };
19
19
  }
20
+ /** Resolve only provider-owned issue/PR keys; malformed historical keys remain unknown. */
21
+ export function gitHubRepositoryIdentity(key) {
22
+ try {
23
+ const locator = parseGitHubResourceKey(key);
24
+ return `${locator.owner}/${locator.repo}`;
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
@@ -34,3 +34,4 @@ export * from './infrastructure/source.js';
34
34
  export * from './infrastructure/webhook.js';
35
35
  export * from './infrastructure/webhook-state.js';
36
36
  export * from './provider.js';
37
+ export { gitHubRepositoryIdentity } from './contracts/external-key.js';
@@ -34,3 +34,4 @@ export * from './infrastructure/source.js';
34
34
  export * from './infrastructure/webhook.js';
35
35
  export * from './infrastructure/webhook-state.js';
36
36
  export * from './provider.js';
37
+ export { gitHubRepositoryIdentity } from './contracts/external-key.js';
@@ -53,7 +53,26 @@ export interface BreakdownReport {
53
53
  }[];
54
54
  })[];
55
55
  }
56
- export type AnalyticsReport = TimeSeriesReport | BreakdownReport;
56
+ export interface DurationStatistics {
57
+ readonly count: number;
58
+ readonly medianMs: number | null;
59
+ readonly averageMs: number | null;
60
+ }
61
+ export interface DurationReport {
62
+ readonly report: ReportDescriptor;
63
+ readonly window: ReportWindow;
64
+ readonly statistics: DurationStatistics;
65
+ readonly groups: readonly (ReportDescriptor & {
66
+ readonly rows: readonly (DurationStatistics & {
67
+ readonly value: string;
68
+ })[];
69
+ })[];
70
+ readonly buckets: readonly (DurationStatistics & {
71
+ readonly from: string;
72
+ readonly to: string;
73
+ })[];
74
+ }
75
+ export type AnalyticsReport = TimeSeriesReport | BreakdownReport | DurationReport;
57
76
  export interface ReportDefinition extends ReportDescriptor {
58
77
  query(query: ReportQuery): Promise<AnalyticsReport>;
59
78
  }
@@ -33,3 +33,4 @@ export interface ResourceCorrelationView {
33
33
  readonly provenance: ResourceCorrelationProvenance;
34
34
  readonly establishedByEventId: string;
35
35
  }
36
+ export type ResourceRepositoryIdentityResolver = (externalKey: ExternalResourceKey) => string | undefined;
@@ -0,0 +1,3 @@
1
+ import type { ResourceView } from '../contracts/views.js';
2
+ /** Match workspace kind precedence, with stable identity ordering within a kind. */
3
+ export declare function repositoryCandidate(resources: readonly ResourceView[]): ResourceView | undefined;
@@ -0,0 +1,13 @@
1
+ import { BuiltInResourceKind } from '../contracts/vocabulary.js';
2
+ /** Match workspace kind precedence, with stable identity ordering within a kind. */
3
+ export function repositoryCandidate(resources) {
4
+ const kinds = [
5
+ BuiltInResourceKind.Repository,
6
+ BuiltInResourceKind.PullRequest,
7
+ BuiltInResourceKind.Issue,
8
+ ];
9
+ return resources
10
+ .filter((resource) => kinds.includes(resource.kind))
11
+ .sort((a, b) => kinds.indexOf(a.kind) - kinds.indexOf(b.kind) ||
12
+ (a.resourceId < b.resourceId ? -1 : a.resourceId > b.resourceId ? 1 : 0))[0];
13
+ }
@@ -13,3 +13,4 @@ export * from './contracts/views.js';
13
13
  export * from './contracts/vocabulary.js';
14
14
  export * from './domain/correlation.js';
15
15
  export * from './domain/resource.js';
16
+ export * from './domain/repository-candidate.js';
@@ -13,3 +13,4 @@ export * from './contracts/views.js';
13
13
  export * from './contracts/vocabulary.js';
14
14
  export * from './domain/correlation.js';
15
15
  export * from './domain/resource.js';
16
+ export * from './domain/repository-candidate.js';
@@ -10,7 +10,7 @@ export interface MetricsResponse {
10
10
  readonly values: Readonly<Record<string, number>>;
11
11
  }
12
12
  export { ReportWindowId } from '../../../kernel/index.js';
13
- export type { AnalyticsReport, ReportWindowId as AnalyticsReportWindowId, BreakdownReport, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
13
+ export type { AnalyticsReport, ReportWindowId as AnalyticsReportWindowId, BreakdownReport, DurationReport, DurationStatistics, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
14
14
  export interface AnalyticsSummaryResponse {
15
15
  readonly window: ReportWindow;
16
16
  readonly runs: number;