@codeledger/engine 0.7.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.
Files changed (129) hide show
  1. package/dist/ccs/index.d.ts +11 -0
  2. package/dist/ccs/index.d.ts.map +1 -0
  3. package/dist/ccs/index.js +10 -0
  4. package/dist/ccs/index.js.map +1 -0
  5. package/dist/ccs/score.d.ts +61 -0
  6. package/dist/ccs/score.d.ts.map +1 -0
  7. package/dist/ccs/score.js +250 -0
  8. package/dist/ccs/score.js.map +1 -0
  9. package/dist/ecl/index.d.ts +9 -0
  10. package/dist/ecl/index.d.ts.map +1 -0
  11. package/dist/ecl/index.js +9 -0
  12. package/dist/ecl/index.js.map +1 -0
  13. package/dist/ecl/ledger.d.ts +84 -0
  14. package/dist/ecl/ledger.d.ts.map +1 -0
  15. package/dist/ecl/ledger.js +235 -0
  16. package/dist/ecl/ledger.js.map +1 -0
  17. package/dist/index.d.ts +54 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +56 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/iole/expansion-ladder.d.ts +51 -0
  22. package/dist/iole/expansion-ladder.d.ts.map +1 -0
  23. package/dist/iole/expansion-ladder.js +153 -0
  24. package/dist/iole/expansion-ladder.js.map +1 -0
  25. package/dist/iole/failure-vector.d.ts +21 -0
  26. package/dist/iole/failure-vector.d.ts.map +1 -0
  27. package/dist/iole/failure-vector.js +156 -0
  28. package/dist/iole/failure-vector.js.map +1 -0
  29. package/dist/iole/index.d.ts +19 -0
  30. package/dist/iole/index.d.ts.map +1 -0
  31. package/dist/iole/index.js +17 -0
  32. package/dist/iole/index.js.map +1 -0
  33. package/dist/iole/intent-decomposition.d.ts +33 -0
  34. package/dist/iole/intent-decomposition.d.ts.map +1 -0
  35. package/dist/iole/intent-decomposition.js +252 -0
  36. package/dist/iole/intent-decomposition.js.map +1 -0
  37. package/dist/iole/intent-signature.d.ts +37 -0
  38. package/dist/iole/intent-signature.d.ts.map +1 -0
  39. package/dist/iole/intent-signature.js +112 -0
  40. package/dist/iole/intent-signature.js.map +1 -0
  41. package/dist/iole/outcome-score.d.ts +25 -0
  42. package/dist/iole/outcome-score.d.ts.map +1 -0
  43. package/dist/iole/outcome-score.js +128 -0
  44. package/dist/iole/outcome-score.js.map +1 -0
  45. package/dist/isc/index.d.ts +8 -0
  46. package/dist/isc/index.d.ts.map +1 -0
  47. package/dist/isc/index.js +8 -0
  48. package/dist/isc/index.js.map +1 -0
  49. package/dist/isc/score.d.ts +27 -0
  50. package/dist/isc/score.d.ts.map +1 -0
  51. package/dist/isc/score.js +347 -0
  52. package/dist/isc/score.js.map +1 -0
  53. package/dist/license/index.d.ts +14 -0
  54. package/dist/license/index.d.ts.map +1 -0
  55. package/dist/license/index.js +11 -0
  56. package/dist/license/index.js.map +1 -0
  57. package/dist/license/parse.d.ts +42 -0
  58. package/dist/license/parse.d.ts.map +1 -0
  59. package/dist/license/parse.js +106 -0
  60. package/dist/license/parse.js.map +1 -0
  61. package/dist/license/publicKey.d.ts +37 -0
  62. package/dist/license/publicKey.d.ts.map +1 -0
  63. package/dist/license/publicKey.js +48 -0
  64. package/dist/license/publicKey.js.map +1 -0
  65. package/dist/license/verify.d.ts +33 -0
  66. package/dist/license/verify.d.ts.map +1 -0
  67. package/dist/license/verify.js +82 -0
  68. package/dist/license/verify.js.map +1 -0
  69. package/dist/orchestrator/index.d.ts +10 -0
  70. package/dist/orchestrator/index.d.ts.map +1 -0
  71. package/dist/orchestrator/index.js +10 -0
  72. package/dist/orchestrator/index.js.map +1 -0
  73. package/dist/orchestrator/orchestrator.d.ts +44 -0
  74. package/dist/orchestrator/orchestrator.d.ts.map +1 -0
  75. package/dist/orchestrator/orchestrator.js +182 -0
  76. package/dist/orchestrator/orchestrator.js.map +1 -0
  77. package/dist/policy-sim/index.d.ts +8 -0
  78. package/dist/policy-sim/index.d.ts.map +1 -0
  79. package/dist/policy-sim/index.js +8 -0
  80. package/dist/policy-sim/index.js.map +1 -0
  81. package/dist/policy-sim/simulate.d.ts +18 -0
  82. package/dist/policy-sim/simulate.d.ts.map +1 -0
  83. package/dist/policy-sim/simulate.js +61 -0
  84. package/dist/policy-sim/simulate.js.map +1 -0
  85. package/dist/provenance/graph.d.ts +42 -0
  86. package/dist/provenance/graph.d.ts.map +1 -0
  87. package/dist/provenance/graph.js +139 -0
  88. package/dist/provenance/graph.js.map +1 -0
  89. package/dist/provenance/index.d.ts +8 -0
  90. package/dist/provenance/index.d.ts.map +1 -0
  91. package/dist/provenance/index.js +8 -0
  92. package/dist/provenance/index.js.map +1 -0
  93. package/dist/sce/index.d.ts +15 -0
  94. package/dist/sce/index.d.ts.map +1 -0
  95. package/dist/sce/index.js +14 -0
  96. package/dist/sce/index.js.map +1 -0
  97. package/dist/sce/slice-builder.d.ts +35 -0
  98. package/dist/sce/slice-builder.d.ts.map +1 -0
  99. package/dist/sce/slice-builder.js +198 -0
  100. package/dist/sce/slice-builder.js.map +1 -0
  101. package/dist/sce/symbol-graph.d.ts +21 -0
  102. package/dist/sce/symbol-graph.d.ts.map +1 -0
  103. package/dist/sce/symbol-graph.js +187 -0
  104. package/dist/sce/symbol-graph.js.map +1 -0
  105. package/dist/team-ledger/index.d.ts +8 -0
  106. package/dist/team-ledger/index.d.ts.map +1 -0
  107. package/dist/team-ledger/index.js +8 -0
  108. package/dist/team-ledger/index.js.map +1 -0
  109. package/dist/team-ledger/ledger.d.ts +48 -0
  110. package/dist/team-ledger/ledger.d.ts.map +1 -0
  111. package/dist/team-ledger/ledger.js +208 -0
  112. package/dist/team-ledger/ledger.js.map +1 -0
  113. package/dist/team-metrics/index.d.ts +8 -0
  114. package/dist/team-metrics/index.d.ts.map +1 -0
  115. package/dist/team-metrics/index.js +8 -0
  116. package/dist/team-metrics/index.js.map +1 -0
  117. package/dist/team-metrics/metrics.d.ts +42 -0
  118. package/dist/team-metrics/metrics.d.ts.map +1 -0
  119. package/dist/team-metrics/metrics.js +156 -0
  120. package/dist/team-metrics/metrics.js.map +1 -0
  121. package/dist/team-policy/index.d.ts +8 -0
  122. package/dist/team-policy/index.d.ts.map +1 -0
  123. package/dist/team-policy/index.js +8 -0
  124. package/dist/team-policy/index.js.map +1 -0
  125. package/dist/team-policy/policy.d.ts +35 -0
  126. package/dist/team-policy/policy.d.ts.map +1 -0
  127. package/dist/team-policy/policy.js +100 -0
  128. package/dist/team-policy/policy.js.map +1 -0
  129. package/package.json +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicKey.js","sourceRoot":"","sources":["../../src/license/publicKey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAqB;IACjD;QACE,KAAK,EAAE,OAAO;QACd,SAAS,EAAE,SAAS;QACpB,GAAG,EAAE;YACH,4BAA4B;YAC5B,8DAA8D;YAC9D,0BAA0B;SAC3B,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,UAAU,EAAE,sBAAsB;KACnC;CACF,CAAC;AAEF,qEAAqE;AACrE,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,iBAAiB;SAC7B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;SAC3B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAE,CAAC;AACpB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * License signature verification — Ed25519 digital signature check.
3
+ *
4
+ * Verifies that a signed license was issued by the CodeLedger license
5
+ * authority using the embedded public key. All verification is local
6
+ * and deterministic — no network calls.
7
+ */
8
+ import type { ParsedSignedLicense, LicensePayload } from './parse.js';
9
+ export interface VerifySuccess {
10
+ valid: true;
11
+ payload: LicensePayload;
12
+ }
13
+ export interface VerifyFailure {
14
+ valid: false;
15
+ reason: string;
16
+ }
17
+ export type VerifyResult = VerifySuccess | VerifyFailure;
18
+ /**
19
+ * Verify the Ed25519 signature on a parsed signed license.
20
+ *
21
+ * Tries all known public keys (supporting key rotation). If any key
22
+ * produces a valid signature, verification passes.
23
+ */
24
+ export declare function verifySignature(license: ParsedSignedLicense): boolean;
25
+ /**
26
+ * Validate business-logic claims in a license payload.
27
+ */
28
+ export declare function validateClaims(payload: LicensePayload): VerifyResult;
29
+ /**
30
+ * Full verification: signature check + claims validation.
31
+ */
32
+ export declare function verifySignedLicense(license: ParsedSignedLicense): VerifyResult;
33
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/license/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMtE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,IAAI,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,aAAa,CAAC;AAIzD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CA4BrE;AAID;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CA4BpE;AAID;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAQ9E"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * License signature verification — Ed25519 digital signature check.
3
+ *
4
+ * Verifies that a signed license was issued by the CodeLedger license
5
+ * authority using the embedded public key. All verification is local
6
+ * and deterministic — no network calls.
7
+ */
8
+ import { createPublicKey, verify } from 'node:crypto';
9
+ import { base64urlToBuffer } from './parse.js';
10
+ import { KNOWN_PUBLIC_KEYS } from './publicKey.js';
11
+ // ── Signature verification ─────────────────────────────────────────────────
12
+ /**
13
+ * Verify the Ed25519 signature on a parsed signed license.
14
+ *
15
+ * Tries all known public keys (supporting key rotation). If any key
16
+ * produces a valid signature, verification passes.
17
+ */
18
+ export function verifySignature(license) {
19
+ const signatureBuffer = base64urlToBuffer(license.signatureRaw);
20
+ const payloadBuffer = Buffer.from(license.payloadRaw, 'utf-8');
21
+ // Try all known keys (supports rotation)
22
+ for (const keyEntry of KNOWN_PUBLIC_KEYS) {
23
+ try {
24
+ const publicKey = createPublicKey({
25
+ key: keyEntry.pem,
26
+ format: 'pem',
27
+ type: 'spki',
28
+ });
29
+ const isValid = verify(null, // Ed25519 does not use a separate hash algorithm
30
+ payloadBuffer, publicKey, signatureBuffer);
31
+ if (isValid)
32
+ return true;
33
+ }
34
+ catch {
35
+ // Key may be malformed or incompatible — skip and try next
36
+ continue;
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+ // ── Claims validation ──────────────────────────────────────────────────────
42
+ /**
43
+ * Validate business-logic claims in a license payload.
44
+ */
45
+ export function validateClaims(payload) {
46
+ // Plan must be "pro"
47
+ if (payload.plan !== 'pro') {
48
+ return { valid: false, reason: `Unsupported plan: "${payload.plan}".` };
49
+ }
50
+ // Must include team + enterprise features
51
+ if (!payload.features.includes('team') || !payload.features.includes('enterprise')) {
52
+ return { valid: false, reason: 'License is missing required feature claims (team, enterprise).' };
53
+ }
54
+ // licenseId must exist
55
+ if (!payload.licenseId) {
56
+ return { valid: false, reason: 'License is missing a license ID.' };
57
+ }
58
+ // Check expiry
59
+ if (payload.expiresAt) {
60
+ const expiryDate = new Date(payload.expiresAt);
61
+ if (isNaN(expiryDate.getTime())) {
62
+ return { valid: false, reason: 'License has an invalid expiry date.' };
63
+ }
64
+ if (expiryDate.getTime() < Date.now()) {
65
+ return { valid: false, reason: `License expired on ${payload.expiresAt}.` };
66
+ }
67
+ }
68
+ return { valid: true, payload };
69
+ }
70
+ // ── Full verification pipeline ─────────────────────────────────────────────
71
+ /**
72
+ * Full verification: signature check + claims validation.
73
+ */
74
+ export function verifySignedLicense(license) {
75
+ // Step 1: Verify cryptographic signature
76
+ if (!verifySignature(license)) {
77
+ return { valid: false, reason: 'Invalid license signature. Please check your key.' };
78
+ }
79
+ // Step 2: Validate business claims
80
+ return validateClaims(license.payload);
81
+ }
82
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/license/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAgBnD,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,MAAM,eAAe,GAAG,iBAAiB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAChE,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE/D,yCAAyC;IACzC,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;QACzC,IAAI,CAAC;YACH,MAAM,SAAS,GAA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AAE,KAAK,EAAE,MAAM,EAAE,qCAAqC,EAAE,CAAC;QACzE,CAAC;QACD,IAAI,UAAU,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YACtC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,sBAAsB,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;QAC9E,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC;AAED,8EAA8E;AAE9E;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA4B;IAC9D,yCAAyC;IACzC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,mDAAmD,EAAE,CAAC;IACvF,CAAC;IAED,mCAAmC;IACnC,OAAO,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Multi-Agent Orchestration Primitives
3
+ *
4
+ * Evolves conflict detection into coordination:
5
+ * - File reservation (claim/release)
6
+ * - Task partitioning (deterministic file assignment)
7
+ * - Dependency ordering (wait until dependency completes)
8
+ */
9
+ export { claimFile, releaseFile, releaseAllForAgent, checkReservation, loadOrchestrationState, saveOrchestrationState, partitionFiles, orchestrationPath, ORCHESTRATION_FILE, } from './orchestrator.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/orchestrator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Multi-Agent Orchestration Primitives
3
+ *
4
+ * Evolves conflict detection into coordination:
5
+ * - File reservation (claim/release)
6
+ * - Task partitioning (deterministic file assignment)
7
+ * - Dependency ordering (wait until dependency completes)
8
+ */
9
+ export { claimFile, releaseFile, releaseAllForAgent, checkReservation, loadOrchestrationState, saveOrchestrationState, partitionFiles, orchestrationPath, ORCHESTRATION_FILE, } from './orchestrator.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/orchestrator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Multi-Agent Orchestration — Implementation
3
+ *
4
+ * Storage: .codeledger/orchestration.json
5
+ *
6
+ * Capabilities:
7
+ * 1. File reservation: Agent A claims file, Agent B warned or blocked
8
+ * 2. Task partitioning: Assign files to agents deterministically
9
+ * 3. Dependency ordering: Agent B waits until Agent A completes dependency
10
+ */
11
+ import type { FileReservation, TaskPartition, ReservationResult, OrchestrationState } from '@codeledger/types';
12
+ export declare const ORCHESTRATION_FILE = "orchestration.json";
13
+ export declare function orchestrationPath(repoRoot: string): string;
14
+ export declare function loadOrchestrationState(repoRoot: string): OrchestrationState;
15
+ export declare function saveOrchestrationState(repoRoot: string, state: OrchestrationState): void;
16
+ /**
17
+ * Attempt to claim a file reservation for an agent.
18
+ *
19
+ * If the file is already reserved by another active agent and the
20
+ * reservation hasn't expired, the claim is denied.
21
+ */
22
+ export declare function claimFile(repoRoot: string, file: string, agentId: string, expiryMs?: number): ReservationResult;
23
+ /**
24
+ * Release a file reservation held by an agent.
25
+ */
26
+ export declare function releaseFile(repoRoot: string, file: string, agentId: string): boolean;
27
+ /**
28
+ * Release all reservations held by a specific agent.
29
+ */
30
+ export declare function releaseAllForAgent(repoRoot: string, agentId: string): number;
31
+ /**
32
+ * Check if a file is reserved and by whom.
33
+ */
34
+ export declare function checkReservation(repoRoot: string, file: string): FileReservation | null;
35
+ /**
36
+ * Partition files across agents deterministically.
37
+ *
38
+ * Uses round-robin assignment based on sorted file paths.
39
+ * The depGraph parameter maps each file to its dependencies; if file B
40
+ * depends on file A and they're in different partitions, a dependency
41
+ * edge is recorded.
42
+ */
43
+ export declare function partitionFiles(files: string[], agentIds: string[], depGraph: Map<string, string[]>): TaskPartition[];
44
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAI3B,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAKvD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAID,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAoB3E;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAKxF;AAID;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAA0B,GACnC,iBAAiB,CAuCnB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAUpF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAO5E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,eAAe,GAAG,IAAI,CAgBxB;AAID;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EAAE,EACf,QAAQ,EAAE,MAAM,EAAE,EAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAC9B,aAAa,EAAE,CAwCjB"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Multi-Agent Orchestration — Implementation
3
+ *
4
+ * Storage: .codeledger/orchestration.json
5
+ *
6
+ * Capabilities:
7
+ * 1. File reservation: Agent A claims file, Agent B warned or blocked
8
+ * 2. Task partitioning: Assign files to agents deterministically
9
+ * 3. Dependency ordering: Agent B waits until Agent A completes dependency
10
+ */
11
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
12
+ import { join, dirname } from 'path';
13
+ // ─── Constants ────────────────────────────────────────────────────────────────
14
+ export const ORCHESTRATION_FILE = 'orchestration.json';
15
+ const DEFAULT_EXPIRY_MS = 30 * 60 * 1000; // 30 minutes
16
+ // ─── Paths ────────────────────────────────────────────────────────────────────
17
+ export function orchestrationPath(repoRoot) {
18
+ return join(repoRoot, '.codeledger', ORCHESTRATION_FILE);
19
+ }
20
+ // ─── State Management ─────────────────────────────────────────────────────────
21
+ export function loadOrchestrationState(repoRoot) {
22
+ const path = orchestrationPath(repoRoot);
23
+ if (!existsSync(path)) {
24
+ return {
25
+ reservations: [],
26
+ partitions: [],
27
+ dependencyOrder: [],
28
+ updatedAt: Date.now(),
29
+ };
30
+ }
31
+ try {
32
+ return JSON.parse(readFileSync(path, 'utf-8'));
33
+ }
34
+ catch {
35
+ return {
36
+ reservations: [],
37
+ partitions: [],
38
+ dependencyOrder: [],
39
+ updatedAt: Date.now(),
40
+ };
41
+ }
42
+ }
43
+ export function saveOrchestrationState(repoRoot, state) {
44
+ const path = orchestrationPath(repoRoot);
45
+ ensureDir(dirname(path));
46
+ state.updatedAt = Date.now();
47
+ writeFileSync(path, JSON.stringify(state, null, 2), 'utf-8');
48
+ }
49
+ // ─── File Reservation ─────────────────────────────────────────────────────────
50
+ /**
51
+ * Attempt to claim a file reservation for an agent.
52
+ *
53
+ * If the file is already reserved by another active agent and the
54
+ * reservation hasn't expired, the claim is denied.
55
+ */
56
+ export function claimFile(repoRoot, file, agentId, expiryMs = DEFAULT_EXPIRY_MS) {
57
+ const state = loadOrchestrationState(repoRoot);
58
+ const now = Date.now();
59
+ // Clean expired reservations
60
+ state.reservations = state.reservations.filter((r) => r.expiresAt === 0 || r.expiresAt > now);
61
+ // Check if file is already reserved
62
+ const existing = state.reservations.find((r) => r.file === file);
63
+ if (existing && existing.agentId !== agentId) {
64
+ return {
65
+ granted: false,
66
+ heldBy: existing.agentId,
67
+ heldSince: existing.claimedAt,
68
+ };
69
+ }
70
+ // Grant or refresh the reservation
71
+ if (existing && existing.agentId === agentId) {
72
+ existing.claimedAt = now;
73
+ existing.expiresAt = expiryMs > 0 ? now + expiryMs : 0;
74
+ existing.active = true;
75
+ saveOrchestrationState(repoRoot, state);
76
+ return { granted: true, reservation: existing };
77
+ }
78
+ const reservation = {
79
+ file,
80
+ agentId,
81
+ claimedAt: now,
82
+ expiresAt: expiryMs > 0 ? now + expiryMs : 0,
83
+ active: true,
84
+ };
85
+ state.reservations.push(reservation);
86
+ saveOrchestrationState(repoRoot, state);
87
+ return { granted: true, reservation };
88
+ }
89
+ /**
90
+ * Release a file reservation held by an agent.
91
+ */
92
+ export function releaseFile(repoRoot, file, agentId) {
93
+ const state = loadOrchestrationState(repoRoot);
94
+ const idx = state.reservations.findIndex((r) => r.file === file && r.agentId === agentId);
95
+ if (idx === -1)
96
+ return false;
97
+ state.reservations.splice(idx, 1);
98
+ saveOrchestrationState(repoRoot, state);
99
+ return true;
100
+ }
101
+ /**
102
+ * Release all reservations held by a specific agent.
103
+ */
104
+ export function releaseAllForAgent(repoRoot, agentId) {
105
+ const state = loadOrchestrationState(repoRoot);
106
+ const before = state.reservations.length;
107
+ state.reservations = state.reservations.filter((r) => r.agentId !== agentId);
108
+ const released = before - state.reservations.length;
109
+ if (released > 0)
110
+ saveOrchestrationState(repoRoot, state);
111
+ return released;
112
+ }
113
+ /**
114
+ * Check if a file is reserved and by whom.
115
+ */
116
+ export function checkReservation(repoRoot, file) {
117
+ const state = loadOrchestrationState(repoRoot);
118
+ const now = Date.now();
119
+ const reservation = state.reservations.find((r) => r.file === file);
120
+ if (!reservation)
121
+ return null;
122
+ // Check expiry
123
+ if (reservation.expiresAt > 0 && reservation.expiresAt <= now) {
124
+ // Expired — remove it
125
+ state.reservations = state.reservations.filter((r) => r.file !== file);
126
+ saveOrchestrationState(repoRoot, state);
127
+ return null;
128
+ }
129
+ return reservation;
130
+ }
131
+ // ─── Task Partitioning ────────────────────────────────────────────────────────
132
+ /**
133
+ * Partition files across agents deterministically.
134
+ *
135
+ * Uses round-robin assignment based on sorted file paths.
136
+ * The depGraph parameter maps each file to its dependencies; if file B
137
+ * depends on file A and they're in different partitions, a dependency
138
+ * edge is recorded.
139
+ */
140
+ export function partitionFiles(files, agentIds, depGraph) {
141
+ if (agentIds.length === 0)
142
+ return [];
143
+ const sorted = [...files].sort();
144
+ const partitions = new Map();
145
+ for (const agentId of agentIds) {
146
+ partitions.set(agentId, { agentId, files: [], dependsOn: [] });
147
+ }
148
+ // Round-robin assignment
149
+ for (let i = 0; i < sorted.length; i++) {
150
+ const agentId = agentIds[i % agentIds.length];
151
+ partitions.get(agentId).files.push(sorted[i]);
152
+ }
153
+ // Compute dependency edges between partitions
154
+ const fileToAgent = new Map();
155
+ for (const [agentId, partition] of partitions) {
156
+ for (const f of partition.files) {
157
+ fileToAgent.set(f, agentId);
158
+ }
159
+ }
160
+ for (const [file, deps] of depGraph) {
161
+ const ownerAgent = fileToAgent.get(file);
162
+ if (!ownerAgent)
163
+ continue;
164
+ for (const dep of deps) {
165
+ const depAgent = fileToAgent.get(dep);
166
+ if (depAgent && depAgent !== ownerAgent) {
167
+ const partition = partitions.get(ownerAgent);
168
+ if (!partition.dependsOn.includes(depAgent)) {
169
+ partition.dependsOn.push(depAgent);
170
+ }
171
+ }
172
+ }
173
+ }
174
+ return Array.from(partitions.values());
175
+ }
176
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
177
+ function ensureDir(dir) {
178
+ if (!existsSync(dir)) {
179
+ mkdirSync(dir, { recursive: true });
180
+ }
181
+ }
182
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAQrC,iFAAiF;AAEjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AACvD,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAEvD,iFAAiF;AAEjF,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,OAAO,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAC3D,CAAC;AAED,iFAAiF;AAEjF,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,MAAM,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO;YACL,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,eAAe,EAAE,EAAE;YACnB,SAAS,EAAE,IAAI,CAAC,GAAG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IAAI,UAAU,EAAE,CAAC;QAC9C,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YAChC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU;YAAE,SAAS;QAE1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtC,IAAI,QAAQ,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;gBACxC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;gBAC9C,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC5C,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,iFAAiF;AAEjF,SAAS,SAAS,CAAC,GAAW;IAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Policy Simulation Engine
3
+ *
4
+ * Allows safe rollout of governance rules by simulating policy
5
+ * evaluation against historical ledger data.
6
+ */
7
+ export { simulatePolicy, } from './simulate.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy-sim/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,GACf,MAAM,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Policy Simulation Engine
3
+ *
4
+ * Allows safe rollout of governance rules by simulating policy
5
+ * evaluation against historical ledger data.
6
+ */
7
+ export { simulatePolicy, } from './simulate.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policy-sim/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,GACf,MAAM,eAAe,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Policy Simulation — Implementation
3
+ *
4
+ * Runs validation across past ledger entries and recent commits
5
+ * to predict impact of governance rules before enforcing them.
6
+ *
7
+ * Output: would-block rate, top violations, scope analysis.
8
+ */
9
+ import type { PolicySimulationResult, TeamPolicyConfig, EclLiteEntry } from '@codeledger/types';
10
+ /**
11
+ * Simulate a team policy against historical ECL-Lite entries.
12
+ *
13
+ * For each entry, reconstructs the task (from intentCategory) and
14
+ * evaluates the policy against the entry's file list. Reports how
15
+ * many entries would be blocked or warned.
16
+ */
17
+ export declare function simulatePolicy(policy: TeamPolicyConfig, entries: EclLiteEntry[], scope?: 'team' | 'org'): PolicySimulationResult;
18
+ //# sourceMappingURL=simulate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/policy-sim/simulate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EAEb,MAAM,mBAAmB,CAAC;AAK3B;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,YAAY,EAAE,EACvB,KAAK,GAAE,MAAM,GAAG,KAAc,GAC7B,sBAAsB,CA8CxB"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Policy Simulation — Implementation
3
+ *
4
+ * Runs validation across past ledger entries and recent commits
5
+ * to predict impact of governance rules before enforcing them.
6
+ *
7
+ * Output: would-block rate, top violations, scope analysis.
8
+ */
9
+ import { evaluateTeamPolicy } from '../team-policy/index.js';
10
+ // ─── Public API ───────────────────────────────────────────────────────────────
11
+ /**
12
+ * Simulate a team policy against historical ECL-Lite entries.
13
+ *
14
+ * For each entry, reconstructs the task (from intentCategory) and
15
+ * evaluates the policy against the entry's file list. Reports how
16
+ * many entries would be blocked or warned.
17
+ */
18
+ export function simulatePolicy(policy, entries, scope = 'team') {
19
+ const now = Date.now();
20
+ let blockedCount = 0;
21
+ let warnedCount = 0;
22
+ const violationCounts = new Map();
23
+ for (const entry of entries) {
24
+ // Reconstruct a pseudo-task from the intent category
25
+ const pseudoTask = entry.intentCategory ?? 'general_task';
26
+ const evaluation = evaluateTeamPolicy(policy, pseudoTask, entry.files);
27
+ if (!evaluation.passed) {
28
+ blockedCount++;
29
+ }
30
+ for (const violation of evaluation.violatedRules) {
31
+ if (violation.enforcement === 'block') {
32
+ const key = `missing:${violation.rule}`;
33
+ violationCounts.set(key, (violationCounts.get(key) ?? 0) + 1);
34
+ }
35
+ else {
36
+ warnedCount++;
37
+ const key = `warn:${violation.rule}`;
38
+ violationCounts.set(key, (violationCounts.get(key) ?? 0) + 1);
39
+ }
40
+ }
41
+ }
42
+ // Build top violations sorted by count
43
+ const topViolations = Array.from(violationCounts.entries())
44
+ .map(([reason, count]) => ({
45
+ reason,
46
+ count,
47
+ percentage: entries.length > 0 ? (count / entries.length) * 100 : 0,
48
+ }))
49
+ .sort((a, b) => b.count - a.count)
50
+ .slice(0, 10);
51
+ return {
52
+ totalEntries: entries.length,
53
+ blockedCount,
54
+ warnedCount,
55
+ blockRate: entries.length > 0 ? blockedCount / entries.length : 0,
56
+ topViolations,
57
+ scope,
58
+ simulatedAt: new Date(now).toISOString(),
59
+ };
60
+ }
61
+ //# sourceMappingURL=simulate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate.js","sourceRoot":"","sources":["../../src/policy-sim/simulate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,iFAAiF;AAEjF;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAwB,EACxB,OAAuB,EACvB,QAAwB,MAAM;IAE9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,qDAAqD;QACrD,MAAM,UAAU,GAAG,KAAK,CAAC,cAAc,IAAI,cAAc,CAAC;QAC1D,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAEvE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YACvB,YAAY,EAAE,CAAC;QACjB,CAAC;QAED,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;YACjD,IAAI,SAAS,CAAC,WAAW,KAAK,OAAO,EAAE,CAAC;gBACtC,MAAM,GAAG,GAAG,WAAW,SAAS,CAAC,IAAI,EAAE,CAAC;gBACxC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAChE,CAAC;iBAAM,CAAC;gBACN,WAAW,EAAE,CAAC;gBACd,MAAM,GAAG,GAAG,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;gBACrC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;IACH,CAAC;IAED,uCAAuC;IACvC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;SACxD,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QACzB,MAAM;QACN,KAAK;QACL,UAAU,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;KACpE,CAAC,CAAC;SACF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;SACjC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEhB,OAAO;QACL,YAAY,EAAE,OAAO,CAAC,MAAM;QAC5B,YAAY;QACZ,WAAW;QACX,SAAS,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACjE,aAAa;QACb,KAAK;QACL,WAAW,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAiB;KACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Context Provenance Graph — Implementation
3
+ *
4
+ * Storage: .codeledger/provenance/
5
+ * - nodes.jsonl (append-only node records)
6
+ * - edges.jsonl (append-only edge records)
7
+ *
8
+ * Node types: task, intent, bundle, file, edit, commit, outcome
9
+ * Edge types: GENERATED_CONTEXT, INCLUDED_FILE, MODIFIED_FILE,
10
+ * PRODUCED_OUTCOME, DERIVED_INTENT, COMMITTED_CHANGE
11
+ *
12
+ * Provides traceTask() for causal chain extraction:
13
+ * "Auth bug fix → bundle (8 files) → edits (3 files) → commit → tests passed"
14
+ */
15
+ import type { ProvenanceNode, ProvenanceEdge, ProvenanceGraph, ProvenanceTrace } from '@codeledger/types';
16
+ export declare const PROVENANCE_DIR = "provenance";
17
+ export declare function provenancePath(repoRoot: string): string;
18
+ /**
19
+ * Add a node to the provenance graph.
20
+ * Creates the directory structure if it doesn't exist.
21
+ */
22
+ export declare function addNode(repoRoot: string, node: ProvenanceNode): void;
23
+ /**
24
+ * Add an edge to the provenance graph.
25
+ */
26
+ export declare function addEdge(repoRoot: string, edge: ProvenanceEdge): void;
27
+ /**
28
+ * Load the full provenance graph from disk.
29
+ */
30
+ export declare function loadGraph(repoRoot: string): ProvenanceGraph;
31
+ /**
32
+ * Trace the causal chain for a given task.
33
+ *
34
+ * Walks the graph from the task node through bundles, files, edits,
35
+ * commits, and outcomes — producing an ordered causal chain.
36
+ */
37
+ export declare function traceTask(repoRoot: string, taskId: string): ProvenanceTrace | null;
38
+ /**
39
+ * Export the graph as a JSON object (for --format graph in audit-export).
40
+ */
41
+ export declare function exportGraph(repoRoot: string): ProvenanceGraph;
42
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/provenance/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAI3B,eAAO,MAAM,cAAc,eAAe,CAAC;AAM3C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAYD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAIpE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAIpE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAK3D;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAsDlF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAE7D"}