@gitgov/core 2.2.0 → 2.3.0

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.
@@ -0,0 +1,1207 @@
1
+ import { R as RecordStore } from './record_store-BXKWqon5.js';
2
+
3
+ /**
4
+ * This file was automatically generated from actor_record_schema.json.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
6
+ * and run 'pnpm compile:types' to regenerate this file.
7
+ */
8
+ /**
9
+ * Canonical schema for actor records as defined in actor_protocol.md
10
+ */
11
+ interface ActorRecord {
12
+ /**
13
+ * Unique, human-readable identifier for the actor.
14
+ */
15
+ id: string;
16
+ /**
17
+ * The type of actor.
18
+ */
19
+ type: 'human' | 'agent';
20
+ /**
21
+ * The name of the actor to be used in user interfaces.
22
+ */
23
+ displayName: string;
24
+ /**
25
+ * The Ed25519 public key (base64 encoded, 44 characters) for verifying the actor's signatures.
26
+ */
27
+ publicKey: string;
28
+ /**
29
+ * List of capacity roles defining the actor's skills and permissions. Uses hierarchical format with colons.
30
+ *
31
+ * @minItems 1
32
+ */
33
+ roles: [string, ...string[]];
34
+ /**
35
+ * Optional. The lifecycle status of the actor. Defaults to 'active' if not specified.
36
+ */
37
+ status?: 'active' | 'revoked';
38
+ /**
39
+ * Optional. The ID of the actor that replaces this one.
40
+ */
41
+ supersededBy?: string;
42
+ /**
43
+ * An optional field for additional, non-canonical metadata.
44
+ */
45
+ metadata?: {};
46
+ }
47
+
48
+ /**
49
+ * This file was automatically generated from agent_record_schema.json.
50
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
51
+ * and run 'pnpm compile:types' to regenerate this file.
52
+ */
53
+ /**
54
+ * Canonical schema for agent operational manifests.
55
+ */
56
+ interface AgentRecord<TMetadata = object> {
57
+ /**
58
+ * Unique identifier for the agent, linking to an ActorRecord.
59
+ */
60
+ id: string;
61
+ status?: 'active' | 'archived';
62
+ /**
63
+ * Optional list of triggers that activate the agent.
64
+ * Additional fields are allowed and depend on trigger type:
65
+ * - webhook triggers: 'event' (event identifier), 'filter' (condition)
66
+ * - scheduled triggers: 'cron' (cron expression)
67
+ * - manual triggers: 'command' (example CLI command)
68
+ *
69
+ */
70
+ triggers?: {
71
+ /**
72
+ * Type of trigger that activates the agent
73
+ */
74
+ type: 'manual' | 'webhook' | 'scheduled';
75
+ [k: string]: unknown | undefined;
76
+ }[];
77
+ knowledge_dependencies?: string[];
78
+ prompt_engine_requirements?: {
79
+ roles?: string[];
80
+ skills?: string[];
81
+ };
82
+ /**
83
+ * Optional framework-specific or deployment-specific metadata for agent extensions.
84
+ * Common use cases: framework identification (langchain, google-adk), deployment info (provider, image, region),
85
+ * cost tracking (cost_per_invocation, currency), tool capabilities, maintainer info.
86
+ * This field does NOT affect agent execution - it is purely informational.
87
+ *
88
+ */
89
+ metadata?: TMetadata;
90
+ engine: {
91
+ type: 'local';
92
+ /**
93
+ * Runtime environment (typescript, python, etc.)
94
+ */
95
+ runtime?: string;
96
+ /**
97
+ * Path to the agent entry file
98
+ */
99
+ entrypoint?: string;
100
+ /**
101
+ * Function name to invoke
102
+ */
103
+ function?: string;
104
+ } | {
105
+ type: 'api';
106
+ /**
107
+ * HTTP endpoint for the agent
108
+ */
109
+ url: string;
110
+ method?: 'POST' | 'GET' | 'PUT';
111
+ /**
112
+ * Authentication configuration for API requests
113
+ */
114
+ auth?: {
115
+ /**
116
+ * Authentication type. 'actor-signature' uses the agent's ActorRecord keypair to sign requests.
117
+ */
118
+ type?: 'bearer' | 'oauth' | 'api-key' | 'actor-signature';
119
+ /**
120
+ * Reference to secret in Secret Manager (for bearer/api-key/oauth auth types)
121
+ */
122
+ secret_key?: string;
123
+ /**
124
+ * Direct token value (not recommended for production, use secret_key instead)
125
+ */
126
+ token?: string;
127
+ [k: string]: unknown | undefined;
128
+ };
129
+ } | {
130
+ type: 'mcp';
131
+ /**
132
+ * MCP server endpoint
133
+ */
134
+ url: string;
135
+ /**
136
+ * Name of the MCP tool to invoke. If not specified, defaults to agentId without 'agent:' prefix.
137
+ */
138
+ tool?: string;
139
+ /**
140
+ * Authentication configuration for MCP server
141
+ */
142
+ auth?: {
143
+ /**
144
+ * Authentication type. 'actor-signature' uses the agent's ActorRecord keypair to sign requests.
145
+ */
146
+ type?: 'bearer' | 'oauth' | 'api-key' | 'actor-signature';
147
+ /**
148
+ * Reference to secret in Secret Manager (for bearer/api-key/oauth auth types)
149
+ */
150
+ secret_key?: string;
151
+ /**
152
+ * Direct token value (not recommended for production, use secret_key instead)
153
+ */
154
+ token?: string;
155
+ [k: string]: unknown | undefined;
156
+ };
157
+ } | {
158
+ type: 'custom';
159
+ /**
160
+ * Custom protocol identifier (e.g., 'a2a', 'grpc')
161
+ */
162
+ protocol?: string;
163
+ /**
164
+ * Protocol-specific configuration
165
+ */
166
+ config?: {};
167
+ };
168
+ }
169
+
170
+ /**
171
+ * This file was automatically generated from changelog_record_schema.json.
172
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
173
+ * and run 'pnpm compile:types' to regenerate this file.
174
+ */
175
+ /**
176
+ * Canonical schema for changelog records - aggregates N tasks into 1 release note
177
+ */
178
+ interface ChangelogRecord {
179
+ /**
180
+ * Unique identifier for the changelog entry
181
+ */
182
+ id: string;
183
+ /**
184
+ * Executive title of the deliverable
185
+ */
186
+ title: string;
187
+ /**
188
+ * Detailed description of the value delivered, including key decisions and impact
189
+ */
190
+ description: string;
191
+ /**
192
+ * IDs of tasks that compose this deliverable (minimum 1 required)
193
+ *
194
+ * @minItems 1
195
+ */
196
+ relatedTasks: [string, ...string[]];
197
+ /**
198
+ * Unix timestamp in seconds when the deliverable was completed
199
+ */
200
+ completedAt: number;
201
+ /**
202
+ * Optional IDs of cycles related to this deliverable
203
+ */
204
+ relatedCycles?: string[];
205
+ /**
206
+ * Optional IDs of key execution records related to this work
207
+ */
208
+ relatedExecutions?: string[];
209
+ /**
210
+ * Optional version or release identifier (e.g., 'v1.0.0', 'sprint-24')
211
+ */
212
+ version?: string;
213
+ /**
214
+ * Optional tags for categorization (e.g., 'feature:auth', 'bugfix', 'security')
215
+ */
216
+ tags?: string[];
217
+ /**
218
+ * Optional list of git commit hashes related to this deliverable
219
+ */
220
+ commits?: string[];
221
+ /**
222
+ * Optional list of main files that were created or modified
223
+ */
224
+ files?: string[];
225
+ /**
226
+ * Optional additional context, decisions, or learnings
227
+ */
228
+ notes?: string;
229
+ }
230
+
231
+ /**
232
+ * This file was automatically generated from cycle_record_schema.json.
233
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
234
+ * and run 'pnpm compile:types' to regenerate this file.
235
+ */
236
+ /**
237
+ * Canonical schema for cycle records - strategic grouping of work
238
+ */
239
+ interface CycleRecord {
240
+ /**
241
+ * Unique identifier for the cycle (10 timestamp + 1 dash + 5 'cycle' + 1 dash + max 50 slug = 67 max)
242
+ */
243
+ id: string;
244
+ /**
245
+ * Human-readable title for the cycle (e.g., 'Sprint 24', 'Auth v2.0', 'Q4 2025')
246
+ */
247
+ title: string;
248
+ /**
249
+ * The lifecycle status of the cycle
250
+ */
251
+ status: 'planning' | 'active' | 'completed' | 'archived';
252
+ /**
253
+ * Optional array of Task IDs that belong to this cycle. Can be empty for cycles that only contain child cycles. (10 timestamp + 1 dash + 4 'task' + 1 dash + max 50 slug = 66 max)
254
+ */
255
+ taskIds?: string[];
256
+ /**
257
+ * Optional array of Cycle IDs that are children of this cycle, allowing for hierarchies (e.g., Q1 containing Sprint 1, Sprint 2, Sprint 3). (10 timestamp + 1 dash + 5 'cycle' + 1 dash + max 50 slug = 67 max)
258
+ */
259
+ childCycleIds?: string[];
260
+ /**
261
+ * Optional list of key:value tags for categorization (e.g., 'roadmap:q4', 'team:alpha', 'okr:growth').
262
+ */
263
+ tags?: string[];
264
+ /**
265
+ * Optional description of the cycle's goals, objectives, and context
266
+ */
267
+ notes?: string;
268
+ }
269
+
270
+ /**
271
+ * This file was automatically generated from execution_record_schema.json.
272
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
273
+ * and run 'pnpm compile:types' to regenerate this file.
274
+ */
275
+ /**
276
+ * Canonical schema for execution log records - the universal event stream
277
+ */
278
+ interface ExecutionRecord<TMetadata = object> {
279
+ /**
280
+ * Unique identifier for the execution log entry (10 timestamp + 1 dash + 4 'exec' + 1 dash + max 50 slug = 66 max)
281
+ */
282
+ id: string;
283
+ /**
284
+ * ID of the parent task this execution belongs to (10 timestamp + 1 dash + 4 'task' + 1 dash + max 50 slug = 66 max)
285
+ */
286
+ taskId: string;
287
+ /**
288
+ * Semantic classification of the execution event
289
+ */
290
+ type: 'analysis' | 'progress' | 'blocker' | 'completion' | 'info' | 'correction';
291
+ /**
292
+ * Human-readable title for the execution (used to generate ID)
293
+ */
294
+ title: string;
295
+ /**
296
+ * The tangible, verifiable output or result of the execution.
297
+ * This is the "WHAT" - evidence of work or event summary.
298
+ *
299
+ */
300
+ result: string;
301
+ /**
302
+ * Optional narrative, context and decisions behind the execution.
303
+ * This is the "HOW" and "WHY" - the story behind the result.
304
+ *
305
+ */
306
+ notes?: string;
307
+ /**
308
+ * Optional list of typed references to relevant commits, files, PRs, or external documents.
309
+ * Should use typed prefixes for clarity and trazabilidad (see execution_protocol_appendix.md):
310
+ * - commit: Git commit SHA
311
+ * - pr: Pull Request number
312
+ * - file: File path (relative to repo root)
313
+ * - url: External URL
314
+ * - issue: GitHub Issue number
315
+ * - task: TaskRecord ID
316
+ * - exec: ExecutionRecord ID (for corrections or dependencies)
317
+ * - changelog: ChangelogRecord ID
318
+ *
319
+ */
320
+ references?: string[];
321
+ /**
322
+ * Optional structured data for machine consumption.
323
+ * Use this field for data that needs to be programmatically processed (e.g., audit findings,
324
+ * performance metrics, scan results). This complements result (human-readable WHAT) and
325
+ * notes (narrative HOW/WHY) by providing structured, queryable data.
326
+ * Common use cases: audit findings arrays, performance metrics, tool outputs, scan summaries.
327
+ *
328
+ */
329
+ metadata?: TMetadata;
330
+ }
331
+
332
+ /**
333
+ * This file was automatically generated from feedback_record_schema.json.
334
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
335
+ * and run 'pnpm compile:types' to regenerate this file.
336
+ */
337
+ /**
338
+ * Canonical schema for feedback records - structured conversation about work
339
+ */
340
+ interface FeedbackRecord<TMetadata = object> {
341
+ /**
342
+ * Unique identifier for the feedback entry
343
+ */
344
+ id: string;
345
+ /**
346
+ * The type of entity this feedback refers to
347
+ */
348
+ entityType: 'task' | 'execution' | 'changelog' | 'feedback' | 'cycle';
349
+ /**
350
+ * The ID of the entity this feedback refers to.
351
+ * Must match the pattern for its entityType:
352
+ * - task: ^\d{10}-task-[a-z0-9-]{1,50}$
353
+ * - execution: ^\d{10}-exec-[a-z0-9-]{1,50}$
354
+ * - changelog: ^\d{10}-changelog-[a-z0-9-]{1,50}$
355
+ * - feedback: ^\d{10}-feedback-[a-z0-9-]{1,50}$
356
+ * - cycle: ^\d{10}-cycle-[a-z0-9-]{1,50}$
357
+ *
358
+ */
359
+ entityId: string;
360
+ /**
361
+ * The semantic intent of the feedback
362
+ */
363
+ type: 'blocking' | 'suggestion' | 'question' | 'approval' | 'clarification' | 'assignment';
364
+ /**
365
+ * The lifecycle status of the feedback.
366
+ * Note: FeedbackRecords are immutable. To change status, create a new feedback
367
+ * that references this one using entityType: "feedback" and resolvesFeedbackId.
368
+ *
369
+ */
370
+ status: 'open' | 'acknowledged' | 'resolved' | 'wontfix';
371
+ /**
372
+ * The content of the feedback. Reduced from 10000 to 5000 chars for practical use.
373
+ */
374
+ content: string;
375
+ /**
376
+ * Optional. The Actor ID responsible for addressing the feedback (e.g., 'human:maria', 'agent:camilo:cursor')
377
+ */
378
+ assignee?: string;
379
+ /**
380
+ * Optional. The ID of another feedback record that this one resolves or responds to
381
+ */
382
+ resolvesFeedbackId?: string;
383
+ /**
384
+ * Optional structured data for machine consumption.
385
+ * Use this field for domain-specific data that needs to be programmatically processed.
386
+ * Common use cases: waiver details (fingerprint, ruleId, file, line), approval context, assignment metadata.
387
+ *
388
+ */
389
+ metadata?: TMetadata;
390
+ }
391
+
392
+ /**
393
+ * This file was automatically generated from task_record_schema.json.
394
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
395
+ * and run 'pnpm compile:types' to regenerate this file.
396
+ */
397
+ /**
398
+ * Canonical schema for task records as defined in task_protocol.md
399
+ */
400
+ interface TaskRecord {
401
+ /**
402
+ * Unique identifier for the task (10 timestamp + 1 dash + 4 'task' + 1 dash + max 50 slug = 66 max)
403
+ */
404
+ id: string;
405
+ /**
406
+ * A brief, human-readable title for the task. Used to generate the ID slug.
407
+ */
408
+ title: string;
409
+ /**
410
+ * Optional. The IDs of the strategic cycles this task belongs to. (10 timestamp + 1 dash + 5 'cycle' + 1 dash + max 50 slug = 67 max)
411
+ */
412
+ cycleIds?: string[];
413
+ /**
414
+ * Current state of the task in the institutional flow
415
+ */
416
+ status: 'draft' | 'review' | 'ready' | 'active' | 'done' | 'archived' | 'paused' | 'discarded';
417
+ /**
418
+ * Strategic or tactical priority level
419
+ */
420
+ priority: 'low' | 'medium' | 'high' | 'critical';
421
+ /**
422
+ * Functional, technical or strategic summary of the objective
423
+ */
424
+ description: string;
425
+ /**
426
+ * Optional. List of key:value tags for categorization and role suggestion (e.g., 'skill:react', 'role:agent:developer').
427
+ */
428
+ tags?: string[];
429
+ /**
430
+ * Valid links or files, when mentioned
431
+ */
432
+ references?: string[];
433
+ /**
434
+ * Additional comments, decisions made or added context
435
+ */
436
+ notes?: string;
437
+ }
438
+
439
+ /**
440
+ * This file was automatically generated from embedded_metadata_schema.json.
441
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source schema,
442
+ * and run 'pnpm compile:types' to regenerate this file.
443
+ */
444
+ /**
445
+ * Canonical schema for the wrapper structure of all GitGovernance records.
446
+ */
447
+ type EmbeddedMetadataRecord$1 = {
448
+ header: {
449
+ /**
450
+ * Version of the embedded metadata format.
451
+ */
452
+ version: '1.0';
453
+ /**
454
+ * The type of the record contained in the payload.
455
+ */
456
+ type: 'actor' | 'agent' | 'task' | 'execution' | 'changelog' | 'feedback' | 'cycle' | 'custom';
457
+ /**
458
+ * Optional URL to a custom schema for the payload.
459
+ */
460
+ schemaUrl?: string;
461
+ /**
462
+ * Optional SHA-256 checksum of the custom schema.
463
+ */
464
+ schemaChecksum?: string;
465
+ /**
466
+ * SHA-256 checksum of the canonically serialized payload.
467
+ */
468
+ payloadChecksum: string;
469
+ /**
470
+ * An array of one or more signature objects.
471
+ *
472
+ * @minItems 1
473
+ */
474
+ signatures: [
475
+ {
476
+ /**
477
+ * The Actor ID of the signer (must match ActorRecord.id pattern).
478
+ */
479
+ keyId: string;
480
+ /**
481
+ * The context role of the signature (e.g., 'author', 'reviewer', 'auditor', or 'custom:*').
482
+ */
483
+ role: string;
484
+ /**
485
+ * Human-readable note from the signer. Part of the signature digest.
486
+ */
487
+ notes: string;
488
+ /**
489
+ * The Ed25519 signature (base64 encoded, 88 chars with padding) of the signature digest.
490
+ */
491
+ signature: string;
492
+ /**
493
+ * Unix timestamp of the signature.
494
+ */
495
+ timestamp: number;
496
+ },
497
+ ...{
498
+ /**
499
+ * The Actor ID of the signer (must match ActorRecord.id pattern).
500
+ */
501
+ keyId: string;
502
+ /**
503
+ * The context role of the signature (e.g., 'author', 'reviewer', 'auditor', or 'custom:*').
504
+ */
505
+ role: string;
506
+ /**
507
+ * Human-readable note from the signer. Part of the signature digest.
508
+ */
509
+ notes: string;
510
+ /**
511
+ * The Ed25519 signature (base64 encoded, 88 chars with padding) of the signature digest.
512
+ */
513
+ signature: string;
514
+ /**
515
+ * Unix timestamp of the signature.
516
+ */
517
+ timestamp: number;
518
+ }[]
519
+ ];
520
+ };
521
+ /**
522
+ * The specific record data, validated against the schema defined by header.type.
523
+ */
524
+ payload: {};
525
+ } & {
526
+ [k: string]: unknown | undefined;
527
+ };
528
+
529
+ /**
530
+ * Extract Signature type from the auto-generated base type.
531
+ * This is hardcoded solution but avoids duplication and uses the generated type as source of truth.
532
+ */
533
+ type Signature = EmbeddedMetadataRecord$1['header']['signatures'][0];
534
+ /**
535
+ * Extract Header type from the auto-generated base type.
536
+ * This is the complete header structure for EmbeddedMetadata.
537
+ */
538
+ type EmbeddedMetadataHeader = EmbeddedMetadataRecord$1['header'];
539
+ /**
540
+ * Generic version of EmbeddedMetadataRecord that accepts any payload type T.
541
+ * This extends the auto-generated base type but makes the payload generic.
542
+ * We need to explicitly preserve the header structure due to the index signature in the base type.
543
+ */
544
+ type EmbeddedMetadataRecord<T extends GitGovRecordPayload> = {
545
+ header: EmbeddedMetadataHeader;
546
+ payload: T;
547
+ };
548
+
549
+ /**
550
+ * A custom record type for testing purposes.
551
+ */
552
+ type CustomRecord = {
553
+ type: 'custom';
554
+ data: unknown;
555
+ };
556
+ /**
557
+ * Defines the possible 'type' values for any record in the system.
558
+ */
559
+ type GitGovRecordType = "actor" | "agent" | "cycle" | "task" | "execution" | "changelog" | "feedback" | "custom";
560
+ /**
561
+ * The canonical payload for any GitGovernance record.
562
+ */
563
+ type GitGovRecordPayload = ActorRecord | AgentRecord | CycleRecord | TaskRecord | ExecutionRecord | ChangelogRecord | FeedbackRecord | CustomRecord;
564
+ /**
565
+ * The canonical type for any record in GitGovernance, wrapping a payload with metadata.
566
+ */
567
+ type GitGovRecord = EmbeddedMetadataRecord<GitGovRecordPayload>;
568
+ /**
569
+ * Specific GitGov record types with full metadata (header + payload).
570
+ * These types provide clean, type-safe access to records with their signatures and checksums.
571
+ *
572
+ * @example
573
+ * const taskRecord: GitGovTaskRecord = await taskStore.read(taskId);
574
+ * const authorId = taskRecord.header.signatures[0].keyId;
575
+ */
576
+ type GitGovTaskRecord = EmbeddedMetadataRecord<TaskRecord>;
577
+ type GitGovCycleRecord = EmbeddedMetadataRecord<CycleRecord>;
578
+ type GitGovFeedbackRecord = EmbeddedMetadataRecord<FeedbackRecord>;
579
+ type GitGovExecutionRecord = EmbeddedMetadataRecord<ExecutionRecord>;
580
+ type GitGovChangelogRecord = EmbeddedMetadataRecord<ChangelogRecord>;
581
+ type GitGovActorRecord = EmbeddedMetadataRecord<ActorRecord>;
582
+ type GitGovAgentRecord = EmbeddedMetadataRecord<AgentRecord>;
583
+ type ActorPayload = Partial<ActorRecord>;
584
+ type AgentPayload = Partial<AgentRecord>;
585
+ type CyclePayload = Partial<CycleRecord>;
586
+ type TaskPayload = Partial<TaskRecord>;
587
+ type ExecutionPayload = Partial<ExecutionRecord>;
588
+ type ChangelogPayload = Partial<ChangelogRecord>;
589
+ type FeedbackPayload = Partial<FeedbackRecord>;
590
+ /**
591
+ * Base class for all GitGovernance-specific errors.
592
+ * Centralized here as it's used across multiple modules (schemas, validation, etc.)
593
+ */
594
+ declare class GitGovError extends Error {
595
+ readonly code: string;
596
+ constructor(message: string, code: string);
597
+ }
598
+
599
+ /**
600
+ * RecordStores - Typed container for all stores
601
+ *
602
+ * Allows injecting multiple stores to modules that need them.
603
+ * Keys correspond to directory names in .gitgov/
604
+ *
605
+ * All stores are OPTIONAL.
606
+ * Reason: LintModule.lint(stores) can receive only relevant stores.
607
+ * Example: To validate only tasks, pass { tasks: taskStore }.
608
+ * The module iterates over Object.entries(stores) and skips undefined.
609
+ */
610
+ type RecordStores = {
611
+ actors?: RecordStore<GitGovActorRecord>;
612
+ agents?: RecordStore<GitGovAgentRecord>;
613
+ tasks?: RecordStore<GitGovTaskRecord>;
614
+ cycles?: RecordStore<GitGovCycleRecord>;
615
+ executions?: RecordStore<GitGovExecutionRecord>;
616
+ feedbacks?: RecordStore<GitGovFeedbackRecord>;
617
+ changelogs?: RecordStore<GitGovChangelogRecord>;
618
+ };
619
+
620
+ /**
621
+ * RecordMetrics Dependencies - Facade + Dependency Injection Pattern
622
+ */
623
+ type RecordMetricsDependencies = {
624
+ stores: Required<Pick<RecordStores, 'tasks' | 'cycles' | 'feedbacks' | 'executions' | 'actors'>>;
625
+ };
626
+ type SystemStatus = {
627
+ tasks: {
628
+ total: number;
629
+ byStatus: Record<string, number>;
630
+ byPriority: Record<string, number>;
631
+ };
632
+ cycles: {
633
+ total: number;
634
+ active: number;
635
+ completed: number;
636
+ };
637
+ health: {
638
+ overallScore: number;
639
+ blockedTasks: number;
640
+ staleTasks: number;
641
+ };
642
+ };
643
+ type TaskHealthReport = {
644
+ taskId: string;
645
+ healthScore: number;
646
+ timeInCurrentStage: number;
647
+ stalenessIndex: number;
648
+ blockingFeedbacks: number;
649
+ lastActivity: number;
650
+ recommendations: string[];
651
+ };
652
+ type ProductivityMetrics = {
653
+ throughput: number;
654
+ leadTime: number;
655
+ cycleTime: number;
656
+ tasksCompleted7d: number;
657
+ averageCompletionTime: number;
658
+ };
659
+ type CollaborationMetrics = {
660
+ activeAgents: number;
661
+ totalAgents: number;
662
+ agentUtilization: number;
663
+ humanAgentRatio: number;
664
+ collaborationIndex: number;
665
+ };
666
+ /**
667
+ * RecordMetrics Interface - The System Analyst
668
+ */
669
+ interface IRecordMetrics {
670
+ getSystemStatus(): Promise<SystemStatus>;
671
+ getTaskHealth(taskId: string): Promise<TaskHealthReport>;
672
+ getProductivityMetrics(): Promise<ProductivityMetrics>;
673
+ getCollaborationMetrics(): Promise<CollaborationMetrics>;
674
+ calculateTimeInCurrentStage(task: TaskRecord): number;
675
+ calculateStalenessIndex(tasks: TaskRecord[]): number;
676
+ calculateBlockingFeedbackAge(feedback: FeedbackRecord[]): number;
677
+ calculateHealth(tasks: TaskRecord[]): number;
678
+ calculateBacklogDistribution(tasks: TaskRecord[]): Record<string, number>;
679
+ calculateTasksCreatedToday(tasks: TaskRecord[]): number;
680
+ calculateThroughput(tasks: TaskRecord[]): number;
681
+ calculateLeadTime(tasks: TaskRecord[]): number;
682
+ calculateCycleTime(tasks: TaskRecord[]): number;
683
+ calculateActiveAgents(actors: ActorRecord[], executions: ExecutionRecord[]): number;
684
+ }
685
+
686
+ /**
687
+ * RecordMetrics - The System Analyst
688
+ *
689
+ * Implements Facade + Dependency Injection Pattern for testeable and configurable orchestration.
690
+ * Acts as Mediator between analytics system and multi-store data sources.
691
+ */
692
+ declare class RecordMetrics implements IRecordMetrics {
693
+ private stores;
694
+ constructor(dependencies: RecordMetricsDependencies);
695
+ /**
696
+ * [EARS-A1] Gets aggregated system status using Tier 1 metrics.
697
+ */
698
+ getSystemStatus(): Promise<SystemStatus>;
699
+ /**
700
+ * [EARS-A2] Gets task health analysis using Tier 1 metrics.
701
+ */
702
+ getTaskHealth(taskId: string): Promise<TaskHealthReport>;
703
+ /**
704
+ * [EARS-E1] Gets productivity metrics using Tier 2 calculations.
705
+ */
706
+ getProductivityMetrics(): Promise<ProductivityMetrics>;
707
+ /**
708
+ * [EARS-E2] Gets collaboration metrics with agent activity analysis.
709
+ */
710
+ getCollaborationMetrics(): Promise<CollaborationMetrics>;
711
+ /**
712
+ * [EARS-B1] Calculates exact days since last state change.
713
+ */
714
+ calculateTimeInCurrentStage(task: TaskRecord): number;
715
+ /**
716
+ * [EARS-B2] Calculates days since last ExecutionRecord.
717
+ */
718
+ calculateStalenessIndex(tasks: TaskRecord[]): number;
719
+ /**
720
+ * [EARS-B3] Calculates days of oldest active blocking feedback.
721
+ */
722
+ calculateBlockingFeedbackAge(feedback: FeedbackRecord[]): number;
723
+ /**
724
+ * [EARS-B4] Calculates health percentage using improved protocol formula.
725
+ */
726
+ calculateHealth(tasks: TaskRecord[]): number;
727
+ /**
728
+ * [EARS-B5] Returns status distribution with percentages.
729
+ */
730
+ calculateBacklogDistribution(tasks: TaskRecord[]): Record<string, number>;
731
+ /**
732
+ * [EARS-B6] Counts tasks created in last 24 hours.
733
+ */
734
+ calculateTasksCreatedToday(tasks: TaskRecord[]): number;
735
+ /**
736
+ * [EARS-D1] Counts tasks moved to 'done' in last 7 days.
737
+ */
738
+ calculateThroughput(tasks: TaskRecord[]): number;
739
+ /**
740
+ * [EARS-D2] Calculates average done-draft time for lead time.
741
+ */
742
+ calculateLeadTime(tasks: TaskRecord[]): number;
743
+ /**
744
+ * [EARS-D3] Calculates average done-active time for cycle time.
745
+ */
746
+ calculateCycleTime(tasks: TaskRecord[]): number;
747
+ /**
748
+ * [EARS-D4] Counts unique agents with executions in 24h.
749
+ */
750
+ calculateActiveAgents(actors: ActorRecord[], executions: ExecutionRecord[]): number;
751
+ /**
752
+ * Extracts timestamp from ID (format: {timestamp}-{type}-{slug})
753
+ */
754
+ private getTimestampFromId;
755
+ /**
756
+ * Counts tasks by status
757
+ */
758
+ private countTasksByStatus;
759
+ /**
760
+ * Counts tasks by priority
761
+ */
762
+ private countTasksByPriority;
763
+ /**
764
+ * [EARS-C3] Throws NotImplementedError for Tier 3 functions.
765
+ */
766
+ calculateQuality(_tasks: TaskRecord[]): number;
767
+ calculateReworkRate(_tasks: TaskRecord[]): number;
768
+ calculateCompletionRate(_tasks: TaskRecord[]): number;
769
+ calculateAuditScoreDistribution(_tasks: TaskRecord[]): Record<string, number>;
770
+ calculateEpicPromotionRate(_tasks: TaskRecord[]): number;
771
+ calculateTaskRefinementRate(_tasks: TaskRecord[]): number;
772
+ calculatePlanningAccuracy(_tasks: TaskRecord[]): number;
773
+ calculateDependencyDiscoveryRate(_tasks: TaskRecord[]): number;
774
+ calculateCostBurnRate(): number;
775
+ calculateTokenConsumption(): number;
776
+ calculateTokenConsumptionByAgent(): Record<string, number>;
777
+ calculateAiAccuracyRate(): number;
778
+ calculateAgentExecutionTime(): number;
779
+ }
780
+
781
+ /**
782
+ * Event Bus types for GitGovernance event-driven architecture
783
+ */
784
+ /**
785
+ * Event metadata for ordering and debugging
786
+ */
787
+ type EventMetadata = {
788
+ /** Unique event identifier */
789
+ eventId: string;
790
+ /** Event creation timestamp */
791
+ timestamp: number;
792
+ /** Event processing timestamp (set by handlers) */
793
+ processedAt?: number;
794
+ /** Source adapter that emitted the event */
795
+ sourceAdapter: string;
796
+ /** Sequence number for ordering (optional) */
797
+ sequenceNumber?: number;
798
+ };
799
+ /**
800
+ * Base event structure
801
+ */
802
+ type BaseEvent = {
803
+ /** Event type identifier */
804
+ type: string;
805
+ /** Event timestamp */
806
+ timestamp: number;
807
+ /** Event payload */
808
+ payload: unknown;
809
+ /** Source that emitted the event */
810
+ source: string;
811
+ /** Event metadata for ordering and debugging */
812
+ metadata?: EventMetadata;
813
+ };
814
+
815
+ type TaskCreatedEvent = BaseEvent & {
816
+ type: 'task.created';
817
+ payload: {
818
+ taskId: string;
819
+ triggeredBy: string;
820
+ };
821
+ };
822
+ type TaskStatusChangedEvent = BaseEvent & {
823
+ type: 'task.status.changed';
824
+ payload: {
825
+ taskId: string;
826
+ oldStatus: TaskRecord['status'];
827
+ newStatus: TaskRecord['status'];
828
+ triggeredBy: string;
829
+ reason?: string;
830
+ };
831
+ };
832
+
833
+ type CycleCreatedEvent = BaseEvent & {
834
+ type: 'cycle.created';
835
+ payload: {
836
+ cycleId: string;
837
+ triggeredBy: string;
838
+ };
839
+ };
840
+ type CycleStatusChangedEvent = BaseEvent & {
841
+ type: 'cycle.status.changed';
842
+ payload: {
843
+ cycleId: string;
844
+ oldStatus: CycleRecord['status'];
845
+ newStatus: CycleRecord['status'];
846
+ triggeredBy: string;
847
+ };
848
+ };
849
+
850
+ type ExecutionCreatedEvent = BaseEvent & {
851
+ type: 'execution.created';
852
+ payload: Pick<ExecutionRecord, 'taskId' | 'type' | 'title'> & {
853
+ executionId: string;
854
+ triggeredBy: string;
855
+ isFirstExecution: boolean;
856
+ };
857
+ };
858
+
859
+ type FeedbackCreatedEvent = BaseEvent & {
860
+ type: 'feedback.created';
861
+ payload: Pick<FeedbackRecord, 'entityType' | 'entityId' | 'type' | 'status' | 'content' | 'assignee' | 'resolvesFeedbackId'> & {
862
+ feedbackId: string;
863
+ triggeredBy: string;
864
+ };
865
+ };
866
+
867
+ type ChangelogCreatedEvent = BaseEvent & {
868
+ type: 'changelog.created';
869
+ payload: Pick<ChangelogRecord, 'relatedTasks' | 'title' | 'version'> & {
870
+ changelogId: string;
871
+ };
872
+ };
873
+
874
+ type ActorCreatedEvent = BaseEvent & {
875
+ type: 'identity.actor.created';
876
+ payload: Pick<ActorRecord, 'type' | 'publicKey' | 'roles'> & {
877
+ actorId: string;
878
+ isBootstrap: boolean;
879
+ };
880
+ };
881
+ type ActorRevokedEvent = BaseEvent & {
882
+ type: 'identity.actor.revoked';
883
+ payload: Pick<ActorRecord, 'supersededBy'> & {
884
+ actorId: string;
885
+ revokedBy: string;
886
+ revocationReason: 'compromised' | 'rotation' | 'manual';
887
+ };
888
+ };
889
+ type AgentRegisteredEvent = BaseEvent & {
890
+ type: 'identity.agent.registered';
891
+ payload: Pick<AgentRecord, 'engine'> & {
892
+ agentId: string;
893
+ correspondingActorId: string;
894
+ };
895
+ };
896
+ /**
897
+ * System events
898
+ */
899
+ type SystemDailyTickEvent = BaseEvent & {
900
+ type: 'system.daily_tick';
901
+ payload: {
902
+ date: string;
903
+ };
904
+ };
905
+ /**
906
+ * Union type of all possible events
907
+ */
908
+ type GitGovEvent = TaskCreatedEvent | TaskStatusChangedEvent | CycleCreatedEvent | CycleStatusChangedEvent | ExecutionCreatedEvent | FeedbackCreatedEvent | ChangelogCreatedEvent | ActorCreatedEvent | ActorRevokedEvent | AgentRegisteredEvent | SystemDailyTickEvent;
909
+ /**
910
+ * Event handler function type
911
+ */
912
+ type EventHandler<T extends BaseEvent = BaseEvent> = (event: T) => void | Promise<void>;
913
+ /**
914
+ * Event subscription
915
+ */
916
+ type EventSubscription = {
917
+ /** Unique subscription ID */
918
+ id: string;
919
+ /** Event type being subscribed to */
920
+ eventType: string;
921
+ /** Handler function */
922
+ handler: EventHandler;
923
+ /** Subscription metadata */
924
+ metadata?: {
925
+ subscriberName?: string;
926
+ createdAt: number;
927
+ };
928
+ };
929
+ /**
930
+ * Activity Event for RecordProjector activity tracking
931
+ * Uses discriminated unions for type-safe metadata per event type
932
+ */
933
+ type ActivityEvent = {
934
+ timestamp: number;
935
+ type: "task_created";
936
+ entityId: string;
937
+ entityTitle: string;
938
+ actorId?: string;
939
+ metadata?: {
940
+ priority?: string;
941
+ status?: string;
942
+ };
943
+ } | {
944
+ timestamp: number;
945
+ type: "cycle_created";
946
+ entityId: string;
947
+ entityTitle: string;
948
+ actorId?: string;
949
+ metadata?: {
950
+ status?: string;
951
+ };
952
+ } | {
953
+ timestamp: number;
954
+ type: "feedback_created";
955
+ entityId: string;
956
+ entityTitle: string;
957
+ actorId?: string;
958
+ metadata?: {
959
+ type?: string;
960
+ assignee?: string;
961
+ resolution?: string;
962
+ };
963
+ } | {
964
+ timestamp: number;
965
+ type: "changelog_created";
966
+ entityId: string;
967
+ entityTitle: string;
968
+ actorId?: string;
969
+ metadata?: {
970
+ version?: string;
971
+ };
972
+ } | {
973
+ timestamp: number;
974
+ type: "execution_created";
975
+ entityId: string;
976
+ entityTitle: string;
977
+ actorId?: string;
978
+ metadata?: {
979
+ executionType?: string;
980
+ taskId?: string;
981
+ };
982
+ } | {
983
+ timestamp: number;
984
+ type: "actor_created";
985
+ entityId: string;
986
+ entityTitle: string;
987
+ actorId?: string;
988
+ metadata?: {
989
+ type?: string;
990
+ };
991
+ } | {
992
+ timestamp: number;
993
+ type: "agent_registered";
994
+ entityId: string;
995
+ entityTitle: string;
996
+ actorId?: string;
997
+ metadata?: Record<string, never>;
998
+ };
999
+
1000
+ /**
1001
+ * Collection of all records with full GitGov metadata (headers + payloads).
1002
+ * This allows access to signatures, checksums, and other metadata for enrichment.
1003
+ *
1004
+ * @see GitGovTaskRecord - Full record type with header.signatures for author/lastModifier extraction
1005
+ */
1006
+ type AllRecords = {
1007
+ tasks: GitGovTaskRecord[];
1008
+ cycles: GitGovCycleRecord[];
1009
+ feedback: GitGovFeedbackRecord[];
1010
+ executions: GitGovExecutionRecord[];
1011
+ changelogs: GitGovChangelogRecord[];
1012
+ actors: GitGovActorRecord[];
1013
+ };
1014
+ /**
1015
+ * System-wide derived states for dashboard analytics and filtering.
1016
+ * Calculated by calculateDerivedStates() during index generation.
1017
+ *
1018
+ * @see derived_data_protocol.md for calculation algorithms
1019
+ */
1020
+ type DerivedStates = {
1021
+ stalledTasks: string[];
1022
+ atRiskTasks: string[];
1023
+ needsClarificationTasks: string[];
1024
+ blockedByDependencyTasks: string[];
1025
+ };
1026
+ /**
1027
+ * Optimized version of DerivedStates using Sets for O(1) lookup performance.
1028
+ * Used internally by enrichTaskRecord() to efficiently check task membership.
1029
+ *
1030
+ * Conversion from DerivedStates (arrays) to DerivedStateSets (Sets) happens once
1031
+ * in generateIndex() before processing multiple tasks, avoiding repeated O(n) lookups.
1032
+ */
1033
+ type DerivedStateSets = {
1034
+ stalledTasks: Set<string>;
1035
+ atRiskTasks: Set<string>;
1036
+ needsClarificationTasks: Set<string>;
1037
+ blockedByDependencyTasks: Set<string>;
1038
+ };
1039
+ /**
1040
+ * Enhanced Task Record with complete intelligence layer.
1041
+ * Calculated by enrichTaskRecord() with relationships, metrics, and derived states.
1042
+ *
1043
+ * @see record_projection.md Section 3.6 - EnrichedTaskRecord Specification (EARS 25-48)
1044
+ */
1045
+ type EnrichedTaskRecord = TaskRecord & {
1046
+ derivedState: {
1047
+ isStalled: boolean;
1048
+ isAtRisk: boolean;
1049
+ needsClarification: boolean;
1050
+ isBlockedByDependency: boolean;
1051
+ healthScore: number;
1052
+ timeInCurrentStage: number;
1053
+ };
1054
+ relationships: {
1055
+ author?: {
1056
+ actorId: string;
1057
+ timestamp: number;
1058
+ };
1059
+ lastModifier?: {
1060
+ actorId: string;
1061
+ timestamp: number;
1062
+ };
1063
+ assignedTo: Array<{
1064
+ actorId: string;
1065
+ assignedAt?: number;
1066
+ }>;
1067
+ dependsOn: string[];
1068
+ blockedBy: string[];
1069
+ cycles: Array<{
1070
+ id: string;
1071
+ title: string;
1072
+ }>;
1073
+ };
1074
+ metrics: {
1075
+ executionCount: number;
1076
+ blockingFeedbackCount: number;
1077
+ openQuestionCount: number;
1078
+ timeToResolution?: number;
1079
+ };
1080
+ release: {
1081
+ isReleased: boolean;
1082
+ lastReleaseVersion?: string;
1083
+ };
1084
+ lastUpdated: number;
1085
+ lastActivityType: 'task_modified' | 'feedback_received' | 'execution_added' | 'changelog_created' | 'task_created';
1086
+ recentActivity?: string;
1087
+ };
1088
+ /**
1089
+ * IndexData - Complete cached index structure.
1090
+ * Generated by generateIndex() and consumed by CLI/Dashboard.
1091
+ */
1092
+ type IndexData = {
1093
+ metadata: {
1094
+ generatedAt: string;
1095
+ lastCommitHash: string;
1096
+ integrityStatus: 'valid' | 'warnings' | 'errors';
1097
+ recordCounts: Record<string, number>;
1098
+ generationTime: number;
1099
+ };
1100
+ metrics: SystemStatus & ProductivityMetrics & CollaborationMetrics;
1101
+ derivedStates: DerivedStates;
1102
+ activityHistory: ActivityEvent[];
1103
+ tasks: GitGovTaskRecord[];
1104
+ enrichedTasks: EnrichedTaskRecord[];
1105
+ cycles: GitGovCycleRecord[];
1106
+ actors: GitGovActorRecord[];
1107
+ feedback: GitGovFeedbackRecord[];
1108
+ };
1109
+ /**
1110
+ * Integrity validation error types.
1111
+ */
1112
+ type IntegrityError = {
1113
+ type: 'schema_violation' | 'checksum_failure' | 'signature_invalid';
1114
+ recordId: string;
1115
+ message: string;
1116
+ };
1117
+ /**
1118
+ * Integrity validation warning types.
1119
+ */
1120
+ type IntegrityWarning = {
1121
+ type: 'missing_reference' | 'deprecated_field' | 'performance_issue';
1122
+ recordId: string;
1123
+ message: string;
1124
+ };
1125
+ /**
1126
+ * Result of validateIntegrity() operation.
1127
+ */
1128
+ type IntegrityReport = {
1129
+ status: 'valid' | 'warnings' | 'errors';
1130
+ recordsScanned: number;
1131
+ errorsFound: IntegrityError[];
1132
+ warningsFound: IntegrityWarning[];
1133
+ validationTime: number;
1134
+ checksumFailures: number;
1135
+ signatureFailures: number;
1136
+ };
1137
+ /**
1138
+ * Result of generateIndex() operation.
1139
+ */
1140
+ type IndexGenerationReport = {
1141
+ success: boolean;
1142
+ recordsProcessed: number;
1143
+ metricsCalculated: number;
1144
+ derivedStatesApplied: number;
1145
+ generationTime: number;
1146
+ errors: string[];
1147
+ performance: {
1148
+ readTime: number;
1149
+ calculationTime: number;
1150
+ writeTime: number;
1151
+ };
1152
+ };
1153
+ /**
1154
+ * Context for projection operations.
1155
+ * Provides metadata about the projection target.
1156
+ */
1157
+ type ProjectionContext = {
1158
+ repoIdentifier?: string;
1159
+ lastCommitHash?: string;
1160
+ };
1161
+ /**
1162
+ * IRecordProjection - Driver pattern for projection output.
1163
+ *
1164
+ * Abstracts where IndexData is persisted. Implementations:
1165
+ * - FsRecordProjection: writes to .gitgov/index.json (CLI)
1166
+ * - MemoryRecordProjection: in-memory Map (tests)
1167
+ * - PrismaRecordProjection: stores as JSON blob via Prisma-compatible client (SaaS)
1168
+ */
1169
+ interface IRecordProjection {
1170
+ persist(data: IndexData, context: ProjectionContext): Promise<void>;
1171
+ read(context: ProjectionContext): Promise<IndexData | null>;
1172
+ exists(context: ProjectionContext): Promise<boolean>;
1173
+ clear(context: ProjectionContext): Promise<void>;
1174
+ }
1175
+ /**
1176
+ * RecordProjector Dependencies - Facade + Dependency Injection Pattern.
1177
+ *
1178
+ * @see record_projection.md Section 2 - Architecture
1179
+ */
1180
+ type RecordProjectorDependencies = {
1181
+ recordMetrics: RecordMetrics;
1182
+ stores: Required<Pick<RecordStores, 'tasks' | 'cycles' | 'feedbacks' | 'executions' | 'changelogs' | 'actors'>>;
1183
+ sink?: IRecordProjection;
1184
+ };
1185
+ /**
1186
+ * RecordProjector Interface - The Projection Engine.
1187
+ */
1188
+ interface IRecordProjector {
1189
+ generateIndex(): Promise<IndexGenerationReport>;
1190
+ computeProjection(opts?: {
1191
+ lastCommitHash?: string;
1192
+ }): Promise<IndexData>;
1193
+ getIndexData(): Promise<IndexData | null>;
1194
+ validateIntegrity(): Promise<IntegrityReport>;
1195
+ calculateDerivedStates(allRecords: AllRecords): Promise<DerivedStates>;
1196
+ calculateActivityHistory(allRecords: AllRecords): Promise<ActivityEvent[]>;
1197
+ calculateLastUpdated(task: GitGovTaskRecord, relatedRecords: AllRecords): Promise<{
1198
+ lastUpdated: number;
1199
+ lastActivityType: EnrichedTaskRecord['lastActivityType'];
1200
+ recentActivity: string;
1201
+ }>;
1202
+ enrichTaskRecord(task: GitGovTaskRecord, relatedRecords: AllRecords, derivedStateSets: DerivedStateSets): Promise<EnrichedTaskRecord>;
1203
+ isIndexUpToDate(): Promise<boolean>;
1204
+ invalidateCache(): Promise<void>;
1205
+ }
1206
+
1207
+ export { type FeedbackCreatedEvent as $, type ActorPayload as A, type ProductivityMetrics as B, type ChangelogPayload as C, RecordMetrics as D, type EmbeddedMetadataHeader as E, type FeedbackPayload as F, type GitGovRecord as G, type RecordMetricsDependencies as H, type IRecordProjector as I, type SystemStatus as J, type TaskHealthReport as K, type ActivityEvent as L, type ActorCreatedEvent as M, type ActorRevokedEvent as N, type AgentRegisteredEvent as O, type ProjectionContext as P, type BaseEvent as Q, type RecordStores as R, type Signature as S, type TaskPayload as T, type ChangelogCreatedEvent as U, type CycleCreatedEvent as V, type CycleStatusChangedEvent as W, type EventHandler as X, type EventMetadata as Y, type EventSubscription as Z, type ExecutionCreatedEvent as _, type IRecordProjection as a, type GitGovEvent as a0, type SystemDailyTickEvent as a1, type TaskCreatedEvent as a2, type TaskStatusChangedEvent as a3, type RecordProjectorDependencies as a4, type IndexGenerationReport as a5, type IntegrityReport as a6, type AllRecords as a7, type DerivedStates as a8, type EnrichedTaskRecord as a9, type DerivedStateSets as aa, type IntegrityError as ab, type IntegrityWarning as ac, type IndexData as b, type ActorRecord as c, type AgentPayload as d, type AgentRecord as e, type ChangelogRecord as f, type CustomRecord as g, type CyclePayload as h, type CycleRecord as i, type EmbeddedMetadataRecord as j, type ExecutionPayload as k, type ExecutionRecord as l, type FeedbackRecord as m, type GitGovActorRecord as n, type GitGovAgentRecord as o, type GitGovChangelogRecord as p, type GitGovCycleRecord as q, GitGovError as r, type GitGovExecutionRecord as s, type GitGovFeedbackRecord as t, type GitGovRecordPayload as u, type GitGovRecordType as v, type GitGovTaskRecord as w, type TaskRecord as x, type CollaborationMetrics as y, type IRecordMetrics as z };