@triedotdev/mcp 1.0.165 → 1.0.166
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.
- package/dist/{chunk-RQ6QZBIN.js → chunk-2Z3TQNNK.js} +2 -2
- package/dist/{chunk-CDG2GVBP.js → chunk-HOGKPDZA.js} +48 -26
- package/dist/chunk-HOGKPDZA.js.map +1 -0
- package/dist/{chunk-WRYQHVPD.js → chunk-JEZ7XJQN.js} +2 -2
- package/dist/{chunk-M7HMBZ3R.js → chunk-JNUOW2JS.js} +6 -6
- package/dist/{chunk-5LRDF2WB.js → chunk-LG5CBK6A.js} +3 -3
- package/dist/{chunk-YAL3SUBG.js → chunk-MVVPJ73K.js} +5 -2
- package/dist/chunk-MVVPJ73K.js.map +1 -0
- package/dist/{chunk-SS2O3MTC.js → chunk-S36IO3EE.js} +3 -3
- package/dist/{chunk-IPNPHPNN.js → chunk-TQOO6A4G.js} +2 -2
- package/dist/{chunk-IS5UBN2R.js → chunk-UXRW2YSP.js} +6 -6
- package/dist/{chunk-HC5P6FZD.js → chunk-ZKKKLRZZ.js} +4 -4
- package/dist/cli/main.js +6 -6
- package/dist/cli/yolo-daemon.js +9 -9
- package/dist/{fast-analyzer-54AHLVO5.js → fast-analyzer-NJQO3TFD.js} +3 -3
- package/dist/{goal-manager-563BNILQ.js → goal-manager-DVX24UPZ.js} +4 -4
- package/dist/{goal-validator-FJEDIYU7.js → goal-validator-6Y5CDEMJ.js} +4 -4
- package/dist/{hypothesis-4KC7XRBZ.js → hypothesis-UKPGOYY2.js} +4 -4
- package/dist/index.js +10 -10
- package/dist/{issue-store-FOS4T736.js → issue-store-UZAPI5DU.js} +3 -3
- package/dist/{ledger-EDLPF6SB.js → ledger-CNFCJKHX.js} +2 -2
- package/dist/server/mcp-server.js +10 -10
- package/dist/{trie-agent-TM6ATSNR.js → trie-agent-6SWUHCVO.js} +7 -7
- package/package.json +1 -1
- package/dist/chunk-CDG2GVBP.js.map +0 -1
- package/dist/chunk-YAL3SUBG.js.map +0 -1
- /package/dist/{chunk-RQ6QZBIN.js.map → chunk-2Z3TQNNK.js.map} +0 -0
- /package/dist/{chunk-WRYQHVPD.js.map → chunk-JEZ7XJQN.js.map} +0 -0
- /package/dist/{chunk-M7HMBZ3R.js.map → chunk-JNUOW2JS.js.map} +0 -0
- /package/dist/{chunk-5LRDF2WB.js.map → chunk-LG5CBK6A.js.map} +0 -0
- /package/dist/{chunk-SS2O3MTC.js.map → chunk-S36IO3EE.js.map} +0 -0
- /package/dist/{chunk-IPNPHPNN.js.map → chunk-TQOO6A4G.js.map} +0 -0
- /package/dist/{chunk-IS5UBN2R.js.map → chunk-UXRW2YSP.js.map} +0 -0
- /package/dist/{chunk-HC5P6FZD.js.map → chunk-ZKKKLRZZ.js.map} +0 -0
- /package/dist/{fast-analyzer-54AHLVO5.js.map → fast-analyzer-NJQO3TFD.js.map} +0 -0
- /package/dist/{goal-manager-563BNILQ.js.map → goal-manager-DVX24UPZ.js.map} +0 -0
- /package/dist/{goal-validator-FJEDIYU7.js.map → goal-validator-6Y5CDEMJ.js.map} +0 -0
- /package/dist/{hypothesis-4KC7XRBZ.js.map → hypothesis-UKPGOYY2.js.map} +0 -0
- /package/dist/{issue-store-FOS4T736.js.map → issue-store-UZAPI5DU.js.map} +0 -0
- /package/dist/{ledger-EDLPF6SB.js.map → ledger-CNFCJKHX.js.map} +0 -0
- /package/dist/{trie-agent-TM6ATSNR.js.map → trie-agent-6SWUHCVO.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/memory/ledger.ts","../src/utils/file-lock.ts","../src/agent/git.ts","../src/utils/command-runner.ts","../src/utils/audit-logger.ts","../src/memory/crypto-keys.ts","../src/memory/git-integration.ts"],"sourcesContent":["import { createHash } from 'crypto';\nimport { mkdir, readFile, writeFile, stat, unlink } from 'fs/promises';\nimport { existsSync } from 'fs';\nimport { createGzip, createGunzip } from 'zlib';\nimport { pipeline } from 'stream/promises';\nimport { createReadStream, createWriteStream } from 'fs';\nimport { join } from 'path';\nimport { atomicWriteJSON } from '../utils/atomic-write.js';\nimport { withFileLock } from '../utils/file-lock.js';\nimport { getWorkingDirectory, getTrieDirectory } from '../utils/workspace.js';\nimport { getLastCommit, isGitRepo } from '../agent/git.js';\nimport type { StoredIssue } from './issue-store.js';\nimport { signHash, verifyHashSignature, hasSigningKey, type SignatureData } from './crypto-keys.js';\nimport { autoCommitLedger, ensureKeysIgnored } from './git-integration.js';\n\nconst LEDGER_FILENAME = 'ledger.json';\nconst SHARED_LEDGER_DIR = '.trie-shared';\nconst MANIFEST_FILENAME = 'ledger-manifest.json';\nconst SYNC_STATE_FILENAME = 'ledger-sync.json';\nconst GENESIS_HASH = '0'.repeat(64);\nconst LEDGER_VERSION = 2; // Increased for sync support\n\nexport interface LedgerEntry {\n id: string;\n hash: string;\n severity: string;\n file: string;\n agent: string;\n timestamp: string;\n status?: 'active' | 'corrected' | 'false-positive';\n correctedBy?: string; // Entry ID that corrects this\n correction?: string; // Reason for correction\n correctionTimestamp?: string; // When the correction was made\n // Digital signature fields\n signature?: string; // Ed25519 signature of entry hash\n publicKey?: string; // Public key that signed this\n signedAt?: string; // When the entry was signed\n signatureAlgorithm?: 'Ed25519';\n}\n\nexport interface LedgerBlock {\n version: number;\n date: string;\n entries: LedgerEntry[];\n previousHash: string;\n merkleRoot: string;\n blockHash: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface LedgerVerificationResult {\n valid: boolean;\n error?: string;\n}\n\n// Enhanced interfaces for sync functionality\nexport interface SyncableLedgerBlock extends LedgerBlock {\n author: string; // Developer who created block\n gitCommit?: string; // Associated git commit hash\n chainHeight: number; // Block position in chain\n syncedAt?: string; // When block was synced\n conflictResolved?: boolean; // If block resolved conflicts\n}\n\nexport interface CompressedBlock {\n date: string;\n compressedData: string; // gzipped JSON\n originalSize: number;\n compressedSize: number;\n compressionRatio: number;\n entryCount: number;\n blockHash: string;\n author: string;\n}\n\nexport interface LedgerManifest {\n version: number;\n created: string;\n lastSync: string;\n totalBlocks: number;\n totalEntries: number;\n activeBlocks: string[]; // Recent block filenames\n archivedBlocks: string[]; // Archived block filenames\n index: {\n byDate: Record<string, string>; // date → block location\n byAuthor: Record<string, string[]>; // author → block locations\n bySeverity: Record<string, number>; // severity → count\n };\n compressionConfig: {\n enabled: boolean;\n archiveAfterDays: number;\n compressionLevel: number;\n maxHotStorageSize: number; // bytes\n };\n}\n\nexport interface LedgerSyncState {\n lastSyncTimestamp: string;\n lastSyncCommit?: string;\n conflicts: ChainConflict[];\n localChanges: boolean;\n sharedChanges: boolean;\n}\n\n/**\n * Wrapper format for optimistic concurrency control\n * The contentHash allows detection of concurrent modifications\n */\nexport interface LedgerFile {\n _format: 'ledger-v2';\n _contentHash: string; // SHA-256 of JSON.stringify(blocks)\n _lastModified: string;\n blocks: LedgerBlock[];\n}\n\n/**\n * Error thrown when optimistic concurrency check fails\n */\nexport class ConcurrentModificationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ConcurrentModificationError';\n }\n}\n\nexport interface ChainConflict {\n type: 'divergent_chain' | 'duplicate_entry' | 'hash_mismatch';\n description: string;\n localBlock?: SyncableLedgerBlock;\n remoteBlock?: SyncableLedgerBlock;\n resolution?: 'local' | 'remote' | 'merge' | 'manual';\n}\n\nexport interface ChainMergeResult {\n mergedChain: SyncableLedgerBlock[];\n conflicts: ChainConflict[];\n resolutionStrategy: 'longest' | 'timestamp' | 'manual';\n stats: {\n localBlocks: number;\n remoteBlocks: number;\n mergedBlocks: number;\n duplicatesRemoved: number;\n };\n}\n\n/**\n * Sign a ledger entry with Ed25519\n * \n * Signs the entry hash to prove authenticity and detect tampering.\n * Creates or uses existing signing key from .trie/keys/\n */\nexport async function signLedgerEntry(entry: LedgerEntry, workDir?: string): Promise<LedgerEntry> {\n try {\n const signatureData = await signHash(entry.hash, workDir);\n \n return {\n ...entry,\n signature: signatureData.signature,\n publicKey: signatureData.publicKey,\n signedAt: signatureData.signedAt,\n signatureAlgorithm: 'Ed25519'\n };\n } catch (error) {\n console.error('Failed to sign ledger entry:', error);\n // Return unsigned entry if signing fails\n return entry;\n }\n}\n\n/**\n * Verify a ledger entry signature\n * \n * Returns true if signature is valid, false otherwise.\n * Unsigned entries return true (for backward compatibility).\n */\nexport async function verifyLedgerEntry(entry: LedgerEntry): Promise<boolean> {\n // Unsigned entries are considered valid (backward compatibility)\n if (!entry.signature || !entry.publicKey) {\n return true;\n }\n \n // Check algorithm\n if (entry.signatureAlgorithm !== 'Ed25519') {\n console.error('Unsupported signature algorithm:', entry.signatureAlgorithm);\n return false;\n }\n \n const signatureData: SignatureData = {\n signature: entry.signature,\n publicKey: entry.publicKey,\n algorithm: 'Ed25519',\n signedAt: entry.signedAt || ''\n };\n \n return await verifyHashSignature(entry.hash, signatureData);\n}\n\n/**\n * Verify all entries in a block\n */\nexport async function verifyBlockSignatures(block: LedgerBlock): Promise<{ valid: boolean; invalidEntries: string[] }> {\n const invalidEntries: string[] = [];\n \n for (const entry of block.entries) {\n const isValid = await verifyLedgerEntry(entry);\n if (!isValid) {\n invalidEntries.push(entry.id);\n }\n }\n \n return {\n valid: invalidEntries.length === 0,\n invalidEntries\n };\n}\n\nexport async function appendIssuesToLedger(\n issues: StoredIssue[],\n workDir?: string,\n author?: string\n): Promise<SyncableLedgerBlock | null> {\n if (issues.length === 0) return null;\n\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const memoryDir = join(getTrieDirectory(projectDir), 'memory');\n await mkdir(memoryDir, { recursive: true });\n\n const ledgerPath = join(memoryDir, LEDGER_FILENAME);\n\n // Use file locking to prevent concurrent write conflicts\n return withFileLock(ledgerPath, async () => {\n // Get git info for author attribution\n const isRepo = await isGitRepo(projectDir);\n const lastCommit = isRepo ? await getLastCommit(projectDir) : null;\n const blockAuthor = author || lastCommit?.author || 'unknown';\n\n const blocks = await loadLedger(projectDir) as SyncableLedgerBlock[];\n const today = new Date().toISOString().slice(0, 10);\n const now = new Date().toISOString();\n\n // Create entries and sign them if signing key exists\n const shouldSign = hasSigningKey(projectDir);\n let entries: LedgerEntry[] = issues.map(issue => ({\n id: issue.id,\n hash: issue.hash,\n severity: issue.severity,\n file: issue.file,\n agent: issue.agent,\n timestamp: issue.timestamp,\n status: 'active' as const,\n }));\n \n // Sign all entries if key exists\n if (shouldSign) {\n entries = await Promise.all(entries.map(entry => signLedgerEntry(entry, projectDir)));\n }\n\n const previousBlock = blocks[blocks.length - 1];\n const block = previousBlock && previousBlock.date === today\n ? previousBlock\n : createSyncableBlock(today, now, previousBlock?.blockHash ?? GENESIS_HASH, blockAuthor, lastCommit?.hash, blocks.length);\n\n if (block !== previousBlock) {\n blocks.push(block);\n }\n\n block.entries = [...block.entries, ...entries];\n block.merkleRoot = computeMerkleRoot(block.entries.map(entry => entry.hash));\n block.blockHash = computeBlockHash(block.previousHash, block.merkleRoot, block.date, block.version);\n block.updatedAt = now;\n\n // Use internal save since lock is already held\n await saveLedgerInternal(blocks, projectDir);\n \n // Level 2: Auto-commit to git (if enabled)\n if (await isGitRepo(projectDir)) {\n // Ensure signing keys are in .gitignore\n await ensureKeysIgnored(projectDir);\n \n // Auto-commit ledger changes\n const commitMessage = `ledger: append ${entries.length} ${entries.length === 1 ? 'entry' : 'entries'}`;\n await autoCommitLedger(projectDir, commitMessage);\n }\n \n return block;\n }, { timeout: 15000 }); // 15s timeout for ledger operations\n}\n\nexport async function verifyLedger(workDir?: string): Promise<LedgerVerificationResult> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const blocks = await loadLedger(projectDir);\n\n if (blocks.length === 0) {\n return { valid: true };\n }\n\n for (let i = 0; i < blocks.length; i += 1) {\n const block = blocks[i];\n if (!block) {\n return { valid: false, error: `Block ${i} missing` };\n }\n const expectedPreviousHash = i === 0\n ? GENESIS_HASH\n : blocks[i - 1]?.blockHash;\n\n if (!expectedPreviousHash) {\n return { valid: false, error: `Block ${i} missing previous block` };\n }\n\n if (block.previousHash !== expectedPreviousHash) {\n return { valid: false, error: `Block ${i} previous hash mismatch` };\n }\n\n const computedMerkleRoot = computeMerkleRoot(block.entries.map(entry => entry.hash));\n if (block.merkleRoot !== computedMerkleRoot) {\n return { valid: false, error: `Block ${i} merkle root mismatch` };\n }\n\n const computedBlockHash = computeBlockHash(block.previousHash, block.merkleRoot, block.date, block.version);\n if (block.blockHash !== computedBlockHash) {\n return { valid: false, error: `Block ${i} block hash mismatch` };\n }\n \n // Verify signatures for signed entries\n const signatureVerification = await verifyBlockSignatures(block);\n if (!signatureVerification.valid) {\n return { \n valid: false, \n error: `Block ${i} has invalid signatures: ${signatureVerification.invalidEntries.join(', ')}` \n };\n }\n }\n\n return { valid: true };\n}\n\nexport function computeMerkleRoot(hashes: string[]): string {\n if (hashes.length === 0) {\n return sha256('');\n }\n\n let level = hashes.slice();\n while (level.length > 1) {\n const nextLevel: string[] = [];\n for (let i = 0; i < level.length; i += 2) {\n const left = level[i];\n const right = level[i + 1] ?? left;\n nextLevel.push(sha256(`${left}:${right}`));\n }\n level = nextLevel;\n }\n\n return level[0]!;\n}\n\nfunction computeBlockHash(previousHash: string, merkleRoot: string, date: string, version: number): string {\n return sha256(`${version}:${date}:${previousHash}:${merkleRoot}`);\n}\n\nfunction createSyncableBlock(\n date: string,\n now: string,\n previousHash: string,\n author: string,\n gitCommit?: string,\n chainHeight: number = 0\n): SyncableLedgerBlock {\n return {\n version: LEDGER_VERSION,\n date,\n entries: [],\n previousHash,\n merkleRoot: '',\n blockHash: '',\n createdAt: now,\n updatedAt: now,\n author,\n chainHeight,\n ...(gitCommit && { gitCommit }),\n };\n}\n\n/**\n * Load ledger blocks from file\n * Supports both legacy array format and new wrapper format with content hash\n */\nasync function loadLedger(projectDir: string): Promise<LedgerBlock[]> {\n const result = await loadLedgerWithHash(projectDir);\n return result.blocks;\n}\n\n/**\n * Load ledger blocks along with content hash for optimistic concurrency\n * Returns both the blocks and the hash that can be used to verify no concurrent modifications\n */\nasync function loadLedgerWithHash(projectDir: string): Promise<{ blocks: LedgerBlock[]; contentHash: string }> {\n const ledgerPath = join(getTrieDirectory(projectDir), 'memory', LEDGER_FILENAME);\n try {\n if (!existsSync(ledgerPath)) {\n return { blocks: [], contentHash: sha256('[]') };\n }\n const content = await readFile(ledgerPath, 'utf-8');\n const parsed = JSON.parse(content);\n \n // Check if it's the new wrapper format\n if (parsed && parsed._format === 'ledger-v2') {\n const file = parsed as LedgerFile;\n return { \n blocks: file.blocks || [],\n contentHash: file._contentHash\n };\n }\n \n // Legacy format: plain array of blocks\n if (!Array.isArray(parsed)) {\n return { blocks: [], contentHash: sha256('[]') };\n }\n \n // Calculate hash for legacy format\n const blocks = parsed as LedgerBlock[];\n const contentHash = sha256(JSON.stringify(blocks));\n return { blocks, contentHash };\n } catch {\n return { blocks: [], contentHash: sha256('[]') };\n }\n}\n\n/** Load ledger blocks for UI display (block hashes, merkle roots, chain) */\nexport async function getLedgerBlocks(workDir?: string): Promise<LedgerBlock[]> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n return loadLedger(projectDir);\n}\n\n/**\n * Load ledger with content hash for optimistic concurrency control\n * \n * Use this when you need to detect concurrent modifications:\n * 1. Load with getLedgerBlocksWithHash()\n * 2. Modify blocks\n * 3. Save with saveLedgerOptimistic() passing the original hash\n * \n * @returns blocks and contentHash that can be used to verify no concurrent modifications\n */\nexport async function getLedgerBlocksWithHash(workDir?: string): Promise<{ blocks: LedgerBlock[]; contentHash: string }> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n return loadLedgerWithHash(projectDir);\n}\n\n/**\n * Save ledger with optimistic concurrency control\n * \n * Verifies the ledger hasn't been modified since it was loaded before saving.\n * Use with getLedgerBlocksWithHash() to implement optimistic locking.\n * \n * @param blocks - The modified blocks to save\n * @param expectedHash - The content hash from when the ledger was loaded\n * @param workDir - Working directory\n * @throws ConcurrentModificationError if the ledger was modified by another process\n */\nexport async function saveLedgerOptimistic(\n blocks: LedgerBlock[],\n expectedHash: string,\n workDir?: string\n): Promise<void> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const memoryDir = join(getTrieDirectory(projectDir), 'memory');\n const ledgerPath = join(memoryDir, LEDGER_FILENAME);\n \n // Use file locking AND optimistic concurrency for maximum safety\n await withFileLock(ledgerPath, async () => {\n await saveLedgerWithConcurrencyCheck(blocks, projectDir, expectedHash);\n }, { timeout: 10000 });\n}\n\n/**\n * Save ledger with file locking (use for standalone saves)\n */\nasync function saveLedger(blocks: LedgerBlock[], projectDir: string): Promise<void> {\n const ledgerPath = join(getTrieDirectory(projectDir), 'memory', LEDGER_FILENAME);\n await withFileLock(ledgerPath, async () => {\n await saveLedgerWithFormat(ledgerPath, blocks);\n }, { timeout: 10000 });\n}\n\n/**\n * Save ledger without acquiring lock (use when lock is already held)\n */\nasync function saveLedgerInternal(blocks: LedgerBlock[], projectDir: string): Promise<void> {\n const ledgerPath = join(getTrieDirectory(projectDir), 'memory', LEDGER_FILENAME);\n await saveLedgerWithFormat(ledgerPath, blocks);\n}\n\n/**\n * Save ledger with optimistic concurrency check\n * \n * @param expectedHash - If provided, verifies the file hasn't changed since it was loaded\n * @throws ConcurrentModificationError if expectedHash doesn't match current file\n */\nasync function saveLedgerWithConcurrencyCheck(\n blocks: LedgerBlock[],\n projectDir: string,\n expectedHash: string\n): Promise<void> {\n const ledgerPath = join(getTrieDirectory(projectDir), 'memory', LEDGER_FILENAME);\n \n // Read current hash\n const { contentHash: currentHash } = await loadLedgerWithHash(projectDir);\n \n if (currentHash !== expectedHash) {\n throw new ConcurrentModificationError(\n `Ledger was modified by another process. ` +\n `Expected hash: ${expectedHash.slice(0, 16)}..., ` +\n `Current hash: ${currentHash.slice(0, 16)}...`\n );\n }\n \n await saveLedgerWithFormat(ledgerPath, blocks);\n}\n\n/**\n * Internal helper to save ledger in the wrapper format\n */\nasync function saveLedgerWithFormat(ledgerPath: string, blocks: LedgerBlock[]): Promise<void> {\n const blocksJson = JSON.stringify(blocks);\n const contentHash = sha256(blocksJson);\n \n const ledgerFile: LedgerFile = {\n _format: 'ledger-v2',\n _contentHash: contentHash,\n _lastModified: new Date().toISOString(),\n blocks\n };\n \n await atomicWriteJSON(ledgerPath, ledgerFile);\n}\n\nfunction sha256(input: string): string {\n return createHash('sha256').update(input).digest('hex');\n}\n\n// ==================== Shared Storage Functions ====================\n\nfunction getSharedLedgerDir(projectDir: string): string {\n return join(projectDir, SHARED_LEDGER_DIR);\n}\n\nfunction getActiveBlocksDir(projectDir: string): string {\n return join(getSharedLedgerDir(projectDir), 'active');\n}\n\nfunction getArchivedBlocksDir(projectDir: string): string {\n return join(getSharedLedgerDir(projectDir), 'archived');\n}\n\nfunction getManifestPath(projectDir: string): string {\n return join(getSharedLedgerDir(projectDir), MANIFEST_FILENAME);\n}\n\nfunction getSyncStatePath(projectDir: string): string {\n return join(getTrieDirectory(projectDir), 'memory', SYNC_STATE_FILENAME);\n}\n\nasync function ensureSharedStorageStructure(projectDir: string): Promise<void> {\n const sharedDir = getSharedLedgerDir(projectDir);\n const activeDir = getActiveBlocksDir(projectDir);\n const archivedDir = getArchivedBlocksDir(projectDir);\n\n await mkdir(sharedDir, { recursive: true });\n await mkdir(activeDir, { recursive: true });\n await mkdir(archivedDir, { recursive: true });\n}\n\nasync function loadManifest(projectDir: string): Promise<LedgerManifest | null> {\n const manifestPath = getManifestPath(projectDir);\n\n try {\n if (!existsSync(manifestPath)) return null;\n const content = await readFile(manifestPath, 'utf-8');\n return JSON.parse(content) as LedgerManifest;\n } catch {\n return null;\n }\n}\n\nasync function saveManifest(manifest: LedgerManifest, projectDir: string): Promise<void> {\n const manifestPath = getManifestPath(projectDir);\n await atomicWriteJSON(manifestPath, manifest);\n}\n\nasync function createDefaultManifest(_projectDir: string): Promise<LedgerManifest> {\n const now = new Date().toISOString();\n\n return {\n version: LEDGER_VERSION,\n created: now,\n lastSync: now,\n totalBlocks: 0,\n totalEntries: 0,\n activeBlocks: [],\n archivedBlocks: [],\n index: {\n byDate: {},\n byAuthor: {},\n bySeverity: {}\n },\n compressionConfig: {\n enabled: true,\n archiveAfterDays: 30,\n compressionLevel: 6,\n maxHotStorageSize: 50 * 1024 * 1024 // 50MB\n }\n };\n}\n\nasync function loadSyncState(projectDir: string): Promise<LedgerSyncState | null> {\n const syncStatePath = getSyncStatePath(projectDir);\n\n try {\n if (!existsSync(syncStatePath)) return null;\n const content = await readFile(syncStatePath, 'utf-8');\n return JSON.parse(content) as LedgerSyncState;\n } catch {\n return null;\n }\n}\n\nasync function saveSyncState(syncState: LedgerSyncState, projectDir: string): Promise<void> {\n const syncStatePath = getSyncStatePath(projectDir);\n const memoryDir = join(getTrieDirectory(projectDir), 'memory');\n await mkdir(memoryDir, { recursive: true });\n await atomicWriteJSON(syncStatePath, syncState);\n}\n\n// ==================== Core Sync Functions ====================\n\nexport async function initializeSharedLedger(workDir?: string): Promise<void> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n await ensureSharedStorageStructure(projectDir);\n\n const existingManifest = await loadManifest(projectDir);\n if (!existingManifest) {\n const manifest = await createDefaultManifest(projectDir);\n await saveManifest(manifest, projectDir);\n }\n\n // Initialize sync state if needed\n const existingSyncState = await loadSyncState(projectDir);\n if (!existingSyncState) {\n const now = new Date().toISOString();\n const syncState: LedgerSyncState = {\n lastSyncTimestamp: now,\n conflicts: [],\n localChanges: false,\n sharedChanges: false\n };\n await saveSyncState(syncState, projectDir);\n }\n}\n\nexport async function syncLedgerFromShared(workDir?: string): Promise<ChainMergeResult> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const memoryDir = join(getTrieDirectory(projectDir), 'memory');\n const ledgerPath = join(memoryDir, LEDGER_FILENAME);\n\n // Ensure shared storage exists\n await initializeSharedLedger(projectDir);\n\n // Use file locking for the entire sync operation\n return withFileLock(ledgerPath, async () => {\n // Load current state\n const manifest = await loadManifest(projectDir);\n const localBlocks = await loadLedger(projectDir) as SyncableLedgerBlock[];\n const sharedBlocks = await loadSharedBlocks(projectDir);\n\n if (!manifest) {\n throw new Error('Failed to load ledger manifest');\n }\n\n // Merge chains (always merge entries, never discard)\n const mergeResult = await mergeChains(localBlocks, sharedBlocks, 'timestamp');\n\n // Save merged chain locally (lock already held)\n await saveLedgerInternal(mergeResult.mergedChain, projectDir);\n\n // Update sync state\n const syncState: LedgerSyncState = {\n lastSyncTimestamp: new Date().toISOString(),\n conflicts: mergeResult.conflicts,\n localChanges: false,\n sharedChanges: false\n };\n await saveSyncState(syncState, projectDir);\n\n return mergeResult;\n }, { timeout: 30000 }); // 30s timeout for sync operations\n}\n\nexport async function pushLedgerToShared(workDir?: string): Promise<void> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const memoryDir = join(getTrieDirectory(projectDir), 'memory');\n const ledgerPath = join(memoryDir, LEDGER_FILENAME);\n\n // Ensure shared storage exists\n await initializeSharedLedger(projectDir);\n\n // Use file locking for the entire push operation\n await withFileLock(ledgerPath, async () => {\n // Load current state\n const localBlocks = await loadLedger(projectDir) as SyncableLedgerBlock[];\n const manifest = await loadManifest(projectDir) || await createDefaultManifest(projectDir);\n\n // Save blocks to shared storage\n const activeDir = getActiveBlocksDir(projectDir);\n\n for (const block of localBlocks) {\n const blockFilename = `${block.date}.json`;\n const blockPath = join(activeDir, blockFilename);\n\n // Only save if not already present or if block has been updated\n if (!existsSync(blockPath) || block.updatedAt > manifest.lastSync) {\n await atomicWriteJSON(blockPath, block);\n\n // Update manifest index\n manifest.index.byDate[block.date] = `active/${blockFilename}`;\n\n const blockAuthor = block.author;\n if (blockAuthor) {\n if (!manifest.index.byAuthor[blockAuthor]) {\n manifest.index.byAuthor[blockAuthor] = [];\n }\n if (!manifest.index.byAuthor[blockAuthor].includes(`active/${blockFilename}`)) {\n manifest.index.byAuthor[blockAuthor].push(`active/${blockFilename}`);\n }\n }\n\n // Update active blocks list\n if (!manifest.activeBlocks.includes(blockFilename)) {\n manifest.activeBlocks.push(blockFilename);\n }\n }\n }\n\n // Update manifest metadata\n manifest.lastSync = new Date().toISOString();\n manifest.totalBlocks = manifest.activeBlocks.length + manifest.archivedBlocks.length;\n manifest.totalEntries = localBlocks.reduce((sum, block) => sum + block.entries.length, 0);\n\n await saveManifest(manifest, projectDir);\n }, { timeout: 30000 }); // 30s timeout for push operations\n}\n\nasync function loadSharedBlocks(projectDir: string): Promise<SyncableLedgerBlock[]> {\n const manifest = await loadManifest(projectDir);\n if (!manifest) return [];\n\n const blocks: SyncableLedgerBlock[] = [];\n const activeDir = getActiveBlocksDir(projectDir);\n\n // Load active blocks\n for (const filename of manifest.activeBlocks) {\n const blockPath = join(activeDir, filename);\n try {\n if (existsSync(blockPath)) {\n const content = await readFile(blockPath, 'utf-8');\n const block = JSON.parse(content) as SyncableLedgerBlock;\n blocks.push(block);\n }\n } catch (error) {\n console.warn(`Failed to load shared block ${filename}:`, error);\n }\n }\n\n // TODO: Load archived blocks when needed\n\n // Sort by date to maintain chronological order\n return blocks.sort((a, b) => a.date.localeCompare(b.date));\n}\n\n// ==================== Chain Merge & Conflict Resolution ====================\n\nasync function mergeChains(\n localBlocks: SyncableLedgerBlock[],\n remoteBlocks: SyncableLedgerBlock[],\n strategy: 'longest' | 'timestamp' | 'manual' = 'timestamp'\n): Promise<ChainMergeResult> {\n const conflicts: ChainConflict[] = [];\n const mergedBlocks = new Map<string, SyncableLedgerBlock>();\n const stats = {\n localBlocks: localBlocks.length,\n remoteBlocks: remoteBlocks.length,\n mergedBlocks: 0,\n duplicatesRemoved: 0\n };\n\n // Index blocks by date for quick lookup\n const localByDate = new Map<string, SyncableLedgerBlock>();\n for (const block of localBlocks) {\n localByDate.set(block.date, block);\n }\n\n const remoteByDate = new Map<string, SyncableLedgerBlock>();\n for (const block of remoteBlocks) {\n remoteByDate.set(block.date, block);\n }\n\n // Get all unique dates\n const allDates = new Set([...localByDate.keys(), ...remoteByDate.keys()]);\n\n for (const date of allDates) {\n const localBlock = localByDate.get(date);\n const remoteBlock = remoteByDate.get(date);\n\n if (localBlock && remoteBlock) {\n // Both chains have a block for this date - potential conflict\n const conflict = detectBlockConflict(localBlock, remoteBlock);\n\n if (conflict) {\n conflicts.push(conflict);\n\n // Apply resolution strategy\n const resolvedBlock = resolveConflict(conflict, strategy);\n if (resolvedBlock) {\n mergedBlocks.set(date, resolvedBlock);\n }\n } else {\n // No conflict - merge entries\n const mergedBlock = mergeBlockEntries(localBlock, remoteBlock);\n mergedBlocks.set(date, mergedBlock);\n }\n } else if (localBlock) {\n // Only local block exists\n mergedBlocks.set(date, localBlock);\n } else if (remoteBlock) {\n // Only remote block exists\n mergedBlocks.set(date, remoteBlock);\n }\n }\n\n // Convert to sorted array and recalculate chain heights\n const resultBlocks = Array.from(mergedBlocks.values())\n .sort((a, b) => a.date.localeCompare(b.date))\n .map((block, index) => ({\n ...block,\n chainHeight: index\n }));\n\n stats.mergedBlocks = resultBlocks.length;\n stats.duplicatesRemoved = stats.localBlocks + stats.remoteBlocks - stats.mergedBlocks;\n\n return {\n mergedChain: resultBlocks,\n conflicts,\n resolutionStrategy: strategy,\n stats\n };\n}\n\nfunction detectBlockConflict(\n localBlock: SyncableLedgerBlock,\n remoteBlock: SyncableLedgerBlock\n): ChainConflict | null {\n // Check for hash mismatch (different content for same date)\n if (localBlock.blockHash !== remoteBlock.blockHash) {\n return {\n type: 'hash_mismatch',\n description: `Different block content for date ${localBlock.date}`,\n localBlock,\n remoteBlock\n };\n }\n\n // Check for entry conflicts\n const hasConflictingEntries = localBlock.entries.some(localEntry => {\n const conflictingRemoteEntry = remoteBlock.entries.find(remoteEntry =>\n remoteEntry.id === localEntry.id && remoteEntry.hash !== localEntry.hash\n );\n return !!conflictingRemoteEntry;\n });\n\n if (hasConflictingEntries) {\n return {\n type: 'duplicate_entry',\n description: `Conflicting entries found for date ${localBlock.date}`,\n localBlock,\n remoteBlock\n };\n }\n\n return null; // No conflict\n}\n\n/**\n * Resolve conflicts by ALWAYS merging entries from both blocks.\n * This prevents data loss - no entries are ever discarded.\n * \n * The strategy parameter now only affects metadata (author, timestamps),\n * not the actual entry merging which always includes all entries.\n */\nfunction resolveConflict(\n conflict: ChainConflict,\n strategy: 'longest' | 'timestamp' | 'manual'\n): SyncableLedgerBlock | null {\n if (!conflict.localBlock || !conflict.remoteBlock) {\n return null;\n }\n\n // ALWAYS merge entries from both blocks to prevent data loss\n const mergedBlock = mergeBlockEntries(conflict.localBlock, conflict.remoteBlock);\n \n // Mark that this block resolved a conflict\n mergedBlock.conflictResolved = true;\n \n // Use strategy only for determining author attribution when merged\n switch (strategy) {\n case 'timestamp':\n // Prefer author from the more recently updated block\n if (conflict.remoteBlock.updatedAt > conflict.localBlock.updatedAt) {\n mergedBlock.author = `${conflict.remoteBlock.author}+${conflict.localBlock.author}`;\n } else {\n mergedBlock.author = `${conflict.localBlock.author}+${conflict.remoteBlock.author}`;\n }\n break;\n \n case 'longest':\n // Prefer author from block with more entries\n if (conflict.remoteBlock.entries.length > conflict.localBlock.entries.length) {\n mergedBlock.author = `${conflict.remoteBlock.author}+${conflict.localBlock.author}`;\n } else {\n mergedBlock.author = `${conflict.localBlock.author}+${conflict.remoteBlock.author}`;\n }\n break;\n \n case 'manual':\n default:\n mergedBlock.author = `${conflict.localBlock.author}+${conflict.remoteBlock.author}`;\n break;\n }\n \n return mergedBlock;\n}\n\nfunction mergeBlockEntries(\n localBlock: SyncableLedgerBlock,\n remoteBlock: SyncableLedgerBlock\n): SyncableLedgerBlock {\n // Combine entries, deduplicating by hash\n const entryMap = new Map<string, LedgerEntry>();\n\n // Add local entries first\n for (const entry of localBlock.entries) {\n entryMap.set(entry.hash, entry);\n }\n\n // Add remote entries (will overwrite locals with same hash)\n for (const entry of remoteBlock.entries) {\n entryMap.set(entry.hash, entry);\n }\n\n const mergedEntries = Array.from(entryMap.values());\n const now = new Date().toISOString();\n\n // Combine author information\n const authors = [localBlock.author, remoteBlock.author].filter(Boolean);\n const combinedAuthor = authors.length > 1 ? authors.join('+') : authors[0] || 'unknown';\n\n return {\n ...localBlock,\n entries: mergedEntries,\n author: combinedAuthor,\n updatedAt: now,\n merkleRoot: computeMerkleRoot(mergedEntries.map(e => e.hash)),\n blockHash: computeBlockHash(\n localBlock.previousHash,\n computeMerkleRoot(mergedEntries.map(e => e.hash)),\n localBlock.date,\n localBlock.version\n )\n };\n}\n\n// ==================== Migration & Legacy Support ====================\n\nexport async function migrateLegacyLedger(workDir?: string): Promise<boolean> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const legacyLedgerPath = join(getTrieDirectory(projectDir), 'memory', LEDGER_FILENAME);\n\n // Check if legacy ledger exists\n if (!existsSync(legacyLedgerPath)) {\n return false; // No legacy ledger to migrate\n }\n\n try {\n // Load legacy blocks\n const legacyBlocks = await loadLedger(projectDir);\n\n // Check if already migrated (v2 format)\n if (legacyBlocks.length > 0 && (legacyBlocks[0] as any).author !== undefined) {\n return false; // Already migrated\n }\n\n console.log(`Migrating legacy ledger with ${legacyBlocks.length} blocks...`);\n\n // Convert legacy blocks to syncable blocks\n const isRepo = await isGitRepo(projectDir);\n const lastCommit = isRepo ? await getLastCommit(projectDir) : null;\n const defaultAuthor = lastCommit?.author || 'legacy-migration';\n\n const migratedBlocks: SyncableLedgerBlock[] = legacyBlocks.map((block, index) => ({\n ...block,\n version: LEDGER_VERSION,\n author: defaultAuthor,\n chainHeight: index,\n syncedAt: new Date().toISOString(),\n ...(lastCommit?.hash && { gitCommit: lastCommit.hash }),\n }));\n\n // Initialize shared storage\n await initializeSharedLedger(projectDir);\n\n // Save migrated blocks locally\n await saveLedger(migratedBlocks, projectDir);\n\n // Push to shared storage\n await pushLedgerToShared(projectDir);\n\n // Create backup of original ledger\n const backupPath = `${legacyLedgerPath}.backup.${Date.now()}`;\n await writeFile(backupPath, JSON.stringify(legacyBlocks, null, 2));\n\n console.log(`✓ Migration complete. Backup saved to ${backupPath}`);\n return true;\n } catch (error) {\n console.error('Failed to migrate legacy ledger:', error);\n return false;\n }\n}\n\nexport async function detectLegacyLedger(workDir?: string): Promise<boolean> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const legacyLedgerPath = join(getTrieDirectory(projectDir), 'memory', LEDGER_FILENAME);\n\n if (!existsSync(legacyLedgerPath)) {\n return false;\n }\n\n try {\n const blocks = await loadLedger(projectDir);\n return blocks.length > 0 && (blocks[0] as any).author === undefined;\n } catch {\n return false;\n }\n}\n\n// ==================== Status & Info Functions ====================\n\nexport async function getLedgerSyncStatus(workDir?: string): Promise<{\n isInitialized: boolean;\n hasLegacyLedger: boolean;\n syncState: LedgerSyncState | null;\n manifest: LedgerManifest | null;\n localBlocks: number;\n sharedBlocks: number;\n conflicts: number;\n}> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n\n const hasLegacyLedger = await detectLegacyLedger(projectDir);\n const manifest = await loadManifest(projectDir);\n const syncState = await loadSyncState(projectDir);\n const localBlocks = await loadLedger(projectDir);\n const sharedBlocks = await loadSharedBlocks(projectDir);\n\n return {\n isInitialized: !!manifest,\n hasLegacyLedger,\n syncState,\n manifest,\n localBlocks: localBlocks.length,\n sharedBlocks: sharedBlocks.length,\n conflicts: syncState?.conflicts.length || 0\n };\n}\n\n// ==================== Compression & Archival System ====================\n\nexport async function compressOldBlocks(workDir?: string): Promise<{\n archived: number;\n sizeReduction: number;\n}> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const manifest = await loadManifest(projectDir);\n\n if (!manifest || !manifest.compressionConfig.enabled) {\n return { archived: 0, sizeReduction: 0 };\n }\n\n const activeDir = getActiveBlocksDir(projectDir);\n const archivedDir = getArchivedBlocksDir(projectDir);\n const cutoffDate = new Date();\n cutoffDate.setDate(cutoffDate.getDate() - manifest.compressionConfig.archiveAfterDays);\n\n let archivedCount = 0;\n let originalSize = 0;\n let compressedSize = 0;\n\n // Group blocks by month for archival\n const blocksByMonth = new Map<string, string[]>();\n\n for (const blockFile of manifest.activeBlocks) {\n const blockDate = blockFile.replace('.json', '');\n\n if (new Date(blockDate) < cutoffDate) {\n const monthKey = blockDate.slice(0, 7); // YYYY-MM\n if (!blocksByMonth.has(monthKey)) {\n blocksByMonth.set(monthKey, []);\n }\n blocksByMonth.get(monthKey)!.push(blockFile);\n }\n }\n\n // Archive each month\n for (const [monthKey, blockFiles] of blocksByMonth) {\n const archivePath = join(archivedDir, `${monthKey}.tar.gz`);\n\n // Skip if already archived\n if (existsSync(archivePath)) {\n continue;\n }\n\n console.log(`Archiving ${blockFiles.length} blocks for ${monthKey}...`);\n\n const monthlyBlocks: SyncableLedgerBlock[] = [];\n for (const blockFile of blockFiles) {\n const blockPath = join(activeDir, blockFile);\n\n try {\n const stats = await stat(blockPath);\n originalSize += stats.size;\n\n const content = await readFile(blockPath, 'utf-8');\n const block = JSON.parse(content) as SyncableLedgerBlock;\n monthlyBlocks.push(block);\n } catch (error) {\n console.warn(`Failed to read block ${blockFile}:`, error);\n }\n }\n\n // Compress and write archive\n if (monthlyBlocks.length > 0) {\n const archiveData = JSON.stringify(monthlyBlocks);\n const tempPath = `${archivePath}.tmp`;\n\n // Write compressed archive\n await pipeline(\n Buffer.from(archiveData),\n createGzip({ level: manifest.compressionConfig.compressionLevel }),\n createWriteStream(tempPath)\n );\n\n // Get compressed size\n const compressedStats = await stat(tempPath);\n compressedSize += compressedStats.size;\n\n // Rename to final location\n await writeFile(archivePath, await readFile(tempPath));\n await unlink(tempPath);\n\n // Remove original block files\n for (const blockFile of blockFiles) {\n const blockPath = join(activeDir, blockFile);\n await unlink(blockPath);\n\n // Remove from manifest\n const index = manifest.activeBlocks.indexOf(blockFile);\n if (index > -1) {\n manifest.activeBlocks.splice(index, 1);\n }\n }\n\n // Add to archived blocks\n manifest.archivedBlocks.push(`${monthKey}.tar.gz`);\n archivedCount += blockFiles.length;\n }\n }\n\n // Update manifest\n if (archivedCount > 0) {\n await saveManifest(manifest, projectDir);\n }\n\n return {\n archived: archivedCount,\n sizeReduction: originalSize > 0 ? Math.round(((originalSize - compressedSize) / originalSize) * 100) : 0\n };\n}\n\n/** Load blocks from archived tar.gz - for read-back from archives */\nexport async function loadArchivedBlocks(\n projectDir: string,\n monthKey: string\n): Promise<SyncableLedgerBlock[]> {\n const archivedDir = getArchivedBlocksDir(projectDir);\n const archivePath = join(archivedDir, `${monthKey}.tar.gz`);\n\n if (!existsSync(archivePath)) {\n return [];\n }\n\n try {\n // Decompress and parse\n const chunks: Buffer[] = [];\n await pipeline(\n createReadStream(archivePath),\n createGunzip(),\n async function* (source) {\n for await (const chunk of source) {\n chunks.push(chunk);\n }\n yield Buffer.concat(chunks);\n }\n );\n\n const decompressedData = Buffer.concat(chunks).toString('utf-8');\n return JSON.parse(decompressedData) as SyncableLedgerBlock[];\n } catch (error) {\n console.error(`Failed to load archived blocks for ${monthKey}:`, error);\n return [];\n }\n}\n\nexport async function getStorageStats(workDir?: string): Promise<{\n activeBlocks: number;\n archivedBlocks: number;\n activeSize: number;\n archivedSize: number;\n compressionRatio: number;\n totalEntries: number;\n}> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const manifest = await loadManifest(projectDir);\n\n if (!manifest) {\n return {\n activeBlocks: 0,\n archivedBlocks: 0,\n activeSize: 0,\n archivedSize: 0,\n compressionRatio: 0,\n totalEntries: 0\n };\n }\n\n const activeDir = getActiveBlocksDir(projectDir);\n const archivedDir = getArchivedBlocksDir(projectDir);\n\n let activeSize = 0;\n let archivedSize = 0;\n\n // Calculate active storage size\n for (const blockFile of manifest.activeBlocks) {\n const blockPath = join(activeDir, blockFile);\n try {\n if (existsSync(blockPath)) {\n const stats = await stat(blockPath);\n activeSize += stats.size;\n }\n } catch {\n // Ignore missing files\n }\n }\n\n // Calculate archived storage size\n for (const archiveFile of manifest.archivedBlocks) {\n const archivePath = join(archivedDir, archiveFile);\n try {\n if (existsSync(archivePath)) {\n const stats = await stat(archivePath);\n archivedSize += stats.size;\n }\n } catch {\n // Ignore missing files\n }\n }\n\n const estimatedUncompressed = archivedSize * 5; // Rough estimate\n const compressionRatio = estimatedUncompressed > 0\n ? Math.round((1 - (archivedSize / estimatedUncompressed)) * 100)\n : 0;\n\n return {\n activeBlocks: manifest.activeBlocks.length,\n archivedBlocks: manifest.archivedBlocks.length,\n activeSize,\n archivedSize,\n compressionRatio,\n totalEntries: manifest.totalEntries\n };\n}\n\nexport async function shouldCompress(workDir?: string): Promise<boolean> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const manifest = await loadManifest(projectDir);\n\n if (!manifest || !manifest.compressionConfig.enabled) {\n return false;\n }\n\n const stats = await getStorageStats(projectDir);\n\n // Compress if hot storage exceeds limit or if old blocks exist\n const exceedsSize = stats.activeSize > manifest.compressionConfig.maxHotStorageSize;\n const hasOldBlocks = manifest.activeBlocks.some(blockFile => {\n const blockDate = blockFile.replace('.json', '');\n const cutoffDate = new Date();\n cutoffDate.setDate(cutoffDate.getDate() - manifest.compressionConfig.archiveAfterDays);\n return new Date(blockDate) < cutoffDate;\n });\n\n return exceedsSize || hasOldBlocks;\n}\n\n// ==================== Entry Correction Functions (Immutable Ledger) ====================\n\nexport interface CorrectionResult {\n success: boolean;\n correctedEntries: number;\n correctionBlock?: SyncableLedgerBlock;\n error?: string;\n}\n\n/**\n * Mark ledger entries as corrected by adding a correction entry to the ledger.\n * This maintains immutability - original entries remain in the chain for audit trail.\n * \n * @param entryIds - IDs of entries to mark as corrected\n * @param reason - Reason for the correction (e.g., \"false positive\", \"duplicate\", \"incorrect detection\")\n * @param correctionType - Type of correction: 'corrected' or 'false-positive'\n * @param workDir - Working directory\n * @param author - Author of the correction\n */\nexport async function correctLedgerEntries(\n entryIds: string[],\n reason: string,\n correctionType: 'corrected' | 'false-positive' = 'corrected',\n workDir?: string,\n author?: string\n): Promise<CorrectionResult> {\n if (entryIds.length === 0) {\n return {\n success: false,\n correctedEntries: 0,\n error: 'No entry IDs provided'\n };\n }\n\n if (!reason || reason.trim().length === 0) {\n return {\n success: false,\n correctedEntries: 0,\n error: 'Correction reason is required'\n };\n }\n\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const memoryDir = join(getTrieDirectory(projectDir), 'memory');\n const ledgerPath = join(memoryDir, LEDGER_FILENAME);\n\n // Use file locking to prevent concurrent write conflicts\n return withFileLock(ledgerPath, async () => {\n const blocks = await loadLedger(projectDir) as SyncableLedgerBlock[];\n\n // Find entries to correct\n const entriesToCorrect: LedgerEntry[] = [];\n for (const block of blocks) {\n for (const entry of block.entries) {\n if (entryIds.includes(entry.id) && entry.status === 'active') {\n entriesToCorrect.push(entry);\n }\n }\n }\n\n if (entriesToCorrect.length === 0) {\n return {\n success: false,\n correctedEntries: 0,\n error: 'No active entries found with the provided IDs'\n };\n }\n\n try {\n const now = new Date().toISOString();\n const isRepo = await isGitRepo(projectDir);\n const lastCommit = isRepo ? await getLastCommit(projectDir) : null;\n const correctionAuthor = author || lastCommit?.author || 'unknown';\n\n // Create correction entries (append-only: we add new entries that mark the old ones as corrected)\n const correctionEntries: LedgerEntry[] = entriesToCorrect.map(entry => {\n const correctionId = `correction-${entry.id}-${Date.now()}`;\n return {\n id: correctionId,\n hash: sha256(`${correctionId}:${entry.hash}:${reason}:${now}`),\n severity: 'info',\n file: entry.file,\n agent: 'ledger-correction',\n timestamp: now,\n status: 'active',\n correction: `Correcting entry ${entry.id}: ${reason}`,\n correctedBy: entry.id,\n };\n });\n\n // Update original entries in their blocks to mark them as corrected\n for (const block of blocks) {\n let blockModified = false;\n for (const entry of block.entries) {\n if (entryIds.includes(entry.id) && entry.status === 'active') {\n entry.status = correctionType;\n entry.correctionTimestamp = now;\n entry.correction = reason;\n blockModified = true;\n }\n }\n \n if (blockModified) {\n // Recalculate merkle root and block hash\n block.merkleRoot = computeMerkleRoot(block.entries.map(e => e.hash));\n block.blockHash = computeBlockHash(\n block.previousHash,\n block.merkleRoot,\n block.date,\n block.version\n );\n block.updatedAt = now;\n }\n }\n\n // Save updated blocks (lock already held)\n await saveLedgerInternal(blocks, projectDir);\n\n // Note: appendIssuesToLedger will acquire its own lock, which is fine\n // since we've released ours by returning from this callback\n // We need to save correction entries without the recursive lock\n const correctionBlock = await appendCorrectionEntries(\n correctionEntries,\n projectDir,\n correctionAuthor\n );\n\n return {\n success: true,\n correctedEntries: entriesToCorrect.length,\n ...(correctionBlock && { correctionBlock }),\n };\n } catch (error) {\n return {\n success: false,\n correctedEntries: 0,\n error: `Failed to correct entries: ${error instanceof Error ? error.message : 'Unknown error'}`\n };\n }\n }, { timeout: 15000 });\n}\n\n/**\n * Internal helper to append correction entries without re-acquiring lock\n * Called from within correctLedgerEntries which already holds the lock\n */\nasync function appendCorrectionEntries(\n correctionEntries: LedgerEntry[],\n projectDir: string,\n author: string\n): Promise<SyncableLedgerBlock | null> {\n const blocks = await loadLedger(projectDir) as SyncableLedgerBlock[];\n const today = new Date().toISOString().slice(0, 10);\n const now = new Date().toISOString();\n\n const previousBlock = blocks[blocks.length - 1];\n const block = previousBlock && previousBlock.date === today\n ? previousBlock\n : createSyncableBlock(today, now, previousBlock?.blockHash ?? GENESIS_HASH, author, undefined, blocks.length);\n\n if (block !== previousBlock) {\n blocks.push(block);\n }\n\n block.entries = [...block.entries, ...correctionEntries];\n block.merkleRoot = computeMerkleRoot(block.entries.map(entry => entry.hash));\n block.blockHash = computeBlockHash(block.previousHash, block.merkleRoot, block.date, block.version);\n block.updatedAt = now;\n\n await saveLedgerInternal(blocks, projectDir);\n return block;\n}\n\n/**\n * Get all entries from the ledger, optionally filtering by status.\n * By default, only returns active entries (excludes corrected/false-positives).\n */\nexport async function getLedgerEntries(\n workDir?: string,\n includeStatus?: Array<'active' | 'corrected' | 'false-positive'>\n): Promise<LedgerEntry[]> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const blocks = await loadLedger(projectDir);\n \n const statusFilter = includeStatus || ['active'];\n const entries: LedgerEntry[] = [];\n \n for (const block of blocks) {\n for (const entry of block.entries) {\n const entryStatus = entry.status || 'active';\n if (statusFilter.includes(entryStatus as any)) {\n entries.push(entry);\n }\n }\n }\n \n return entries;\n}\n\n/**\n * Get correction history for specific entry IDs.\n * Returns the original entry and any correction entries.\n */\nexport async function getEntryCorrectionHistory(\n entryIds: string[],\n workDir?: string\n): Promise<Map<string, { original: LedgerEntry; corrections: LedgerEntry[] }>> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const blocks = await loadLedger(projectDir);\n \n const history = new Map<string, { original: LedgerEntry; corrections: LedgerEntry[] }>();\n \n for (const entryId of entryIds) {\n const corrections: LedgerEntry[] = [];\n let original: LedgerEntry | null = null;\n \n for (const block of blocks) {\n for (const entry of block.entries) {\n if (entry.id === entryId) {\n original = entry;\n }\n if (entry.correctedBy === entryId) {\n corrections.push(entry);\n }\n }\n }\n \n if (original) {\n history.set(entryId, { original, corrections });\n }\n }\n \n return history;\n}\n\n/**\n * Get statistics about ledger corrections\n */\nexport async function getCorrectionStats(workDir?: string): Promise<{\n totalEntries: number;\n activeEntries: number;\n correctedEntries: number;\n falsePositives: number;\n correctionRate: number;\n}> {\n const projectDir = workDir || getWorkingDirectory(undefined, true);\n const blocks = await loadLedger(projectDir);\n \n let totalEntries = 0;\n let activeEntries = 0;\n let correctedEntries = 0;\n let falsePositives = 0;\n \n for (const block of blocks) {\n for (const entry of block.entries) {\n totalEntries++;\n const status = entry.status || 'active';\n \n if (status === 'active') activeEntries++;\n else if (status === 'corrected') correctedEntries++;\n else if (status === 'false-positive') falsePositives++;\n }\n }\n \n const correctionRate = totalEntries > 0 \n ? ((correctedEntries + falsePositives) / totalEntries) * 100 \n : 0;\n \n return {\n totalEntries,\n activeEntries,\n correctedEntries,\n falsePositives,\n correctionRate: Math.round(correctionRate * 100) / 100\n };\n}\n","/**\n * File Locking Utility\n * \n * Provides advisory file locking for coordinating concurrent access\n * to shared files like the ledger and issue store.\n * \n * Uses the atomic create-if-not-exists pattern (O_CREAT | O_EXCL)\n * for cross-platform lock acquisition.\n * \n * Features:\n * - Stale lock detection and cleanup\n * - Configurable timeout with exponential backoff\n * - Process ID tracking for debugging\n * - Automatic cleanup on process exit\n */\n\nimport { open, unlink, readFile, stat, mkdir } from 'fs/promises';\nimport { existsSync } from 'fs';\nimport { dirname } from 'path';\n\nexport interface FileLockOptions {\n /**\n * Maximum time to wait for lock acquisition (ms)\n * @default 10000\n */\n timeout?: number;\n \n /**\n * Initial retry delay (ms), doubles on each retry\n * @default 50\n */\n retryDelay?: number;\n \n /**\n * Maximum retry delay (ms)\n * @default 500\n */\n maxRetryDelay?: number;\n \n /**\n * Time after which a lock is considered stale and can be forcibly acquired (ms)\n * This handles crashed processes that didn't clean up their locks\n * @default 30000\n */\n staleTimeout?: number;\n}\n\nexport interface LockInfo {\n pid: number;\n timestamp: number;\n hostname: string;\n}\n\nconst activeLocks = new Set<string>();\n\n// Cleanup locks on process exit\nfunction setupCleanupHandler() {\n const cleanup = () => {\n for (const lockPath of activeLocks) {\n try {\n // Synchronous unlink for exit handler\n const fs = require('fs');\n if (fs.existsSync(lockPath)) {\n fs.unlinkSync(lockPath);\n }\n } catch {\n // Best effort cleanup\n }\n }\n };\n \n process.on('exit', cleanup);\n process.on('SIGINT', () => { cleanup(); process.exit(130); });\n process.on('SIGTERM', () => { cleanup(); process.exit(143); });\n}\n\nlet cleanupHandlerInstalled = false;\n\n/**\n * Execute a function with an exclusive file lock\n * \n * @param filePath - The file to lock (lock file will be `${filePath}.lock`)\n * @param fn - The async function to execute while holding the lock\n * @param options - Lock options\n * @returns The result of the function\n * @throws Error if lock cannot be acquired within timeout\n * \n * @example\n * ```typescript\n * await withFileLock('/path/to/data.json', async () => {\n * const data = await readFile('/path/to/data.json', 'utf-8');\n * const modified = JSON.parse(data);\n * modified.count++;\n * await writeFile('/path/to/data.json', JSON.stringify(modified));\n * });\n * ```\n */\nexport async function withFileLock<T>(\n filePath: string,\n fn: () => Promise<T>,\n options: FileLockOptions = {}\n): Promise<T> {\n const {\n timeout = 10000,\n retryDelay = 50,\n maxRetryDelay = 500,\n staleTimeout = 30000,\n } = options;\n \n const lockPath = `${filePath}.lock`;\n const start = Date.now();\n let currentDelay = retryDelay;\n \n // Install cleanup handler on first use\n if (!cleanupHandlerInstalled) {\n setupCleanupHandler();\n cleanupHandlerInstalled = true;\n }\n \n // Ensure parent directory exists before any lock operations\n await mkdir(dirname(lockPath), { recursive: true });\n \n // Try to acquire the lock\n while (true) {\n try {\n // Check for stale lock first\n await cleanupStaleLock(lockPath, staleTimeout);\n \n // Try atomic create (O_CREAT | O_EXCL equivalent)\n const lockInfo: LockInfo = {\n pid: process.pid,\n timestamp: Date.now(),\n hostname: require('os').hostname(),\n };\n \n const handle = await open(lockPath, 'wx');\n await handle.writeFile(JSON.stringify(lockInfo));\n await handle.close();\n \n // Track active lock for cleanup\n activeLocks.add(lockPath);\n \n try {\n return await fn();\n } finally {\n // Release lock\n activeLocks.delete(lockPath);\n await unlink(lockPath).catch(() => {\n // Lock file may have been removed by stale cleanup\n });\n }\n } catch (err: any) {\n if (err.code !== 'EEXIST') {\n // Unexpected error (e.g., permission denied)\n throw err;\n }\n \n // Lock exists, check timeout\n if (Date.now() - start > timeout) {\n // Try to get info about who holds the lock\n let lockHolder = 'unknown';\n try {\n const content = await readFile(lockPath, 'utf-8');\n const info = JSON.parse(content) as LockInfo;\n lockHolder = `PID ${info.pid} on ${info.hostname}`;\n } catch {\n // Can't read lock info\n }\n \n throw new Error(\n `Timeout acquiring lock for ${filePath} after ${timeout}ms. ` +\n `Lock held by: ${lockHolder}`\n );\n }\n \n // Wait with exponential backoff before retry\n await new Promise(resolve => setTimeout(resolve, currentDelay));\n currentDelay = Math.min(currentDelay * 2, maxRetryDelay);\n }\n }\n}\n\n/**\n * Clean up a stale lock file\n * \n * A lock is considered stale if:\n * 1. It's older than staleTimeout\n * 2. The process that created it is no longer running (on same machine)\n */\nasync function cleanupStaleLock(lockPath: string, staleTimeout: number): Promise<void> {\n if (!existsSync(lockPath)) {\n return;\n }\n \n try {\n const content = await readFile(lockPath, 'utf-8');\n const info = JSON.parse(content) as LockInfo;\n const lockAge = Date.now() - info.timestamp;\n \n // Check if lock is stale by age\n if (lockAge > staleTimeout) {\n console.warn(`[FileLock] Removing stale lock (age: ${Math.round(lockAge / 1000)}s): ${lockPath}`);\n await unlink(lockPath);\n return;\n }\n \n // Check if the process is still running (only works on same machine)\n const currentHostname = require('os').hostname();\n if (info.hostname === currentHostname) {\n if (!isProcessRunning(info.pid)) {\n console.warn(`[FileLock] Removing orphaned lock (PID ${info.pid} not running): ${lockPath}`);\n await unlink(lockPath);\n return;\n }\n }\n } catch {\n // If we can't read the lock file, it might be corrupted\n // Check by file age instead\n try {\n const stats = await stat(lockPath);\n const fileAge = Date.now() - stats.mtimeMs;\n if (fileAge > staleTimeout) {\n console.warn(`[FileLock] Removing stale/corrupted lock: ${lockPath}`);\n await unlink(lockPath);\n }\n } catch {\n // File doesn't exist or can't be accessed\n }\n }\n}\n\n/**\n * Check if a process is still running\n */\nfunction isProcessRunning(pid: number): boolean {\n try {\n // Sending signal 0 checks if process exists without affecting it\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Try to acquire a lock without blocking\n * \n * @returns true if lock was acquired, false if already locked\n */\nexport async function tryAcquireLock(\n filePath: string,\n options: { staleTimeout?: number } = {}\n): Promise<boolean> {\n const lockPath = `${filePath}.lock`;\n const { staleTimeout = 30000 } = options;\n \n await mkdir(dirname(lockPath), { recursive: true });\n \n try {\n await cleanupStaleLock(lockPath, staleTimeout);\n \n const lockInfo: LockInfo = {\n pid: process.pid,\n timestamp: Date.now(),\n hostname: require('os').hostname(),\n };\n \n const handle = await open(lockPath, 'wx');\n await handle.writeFile(JSON.stringify(lockInfo));\n await handle.close();\n \n activeLocks.add(lockPath);\n return true;\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n return false;\n }\n throw err;\n }\n}\n\n/**\n * Release a previously acquired lock\n */\nexport async function releaseLock(filePath: string): Promise<void> {\n const lockPath = `${filePath}.lock`;\n activeLocks.delete(lockPath);\n await unlink(lockPath).catch(() => {});\n}\n\n/**\n * Check if a file is currently locked\n */\nexport async function isLocked(\n filePath: string,\n options: { staleTimeout?: number } = {}\n): Promise<boolean> {\n const lockPath = `${filePath}.lock`;\n const { staleTimeout = 30000 } = options;\n \n if (!existsSync(lockPath)) {\n return false;\n }\n \n // Check if lock is stale\n try {\n const content = await readFile(lockPath, 'utf-8');\n const info = JSON.parse(content) as LockInfo;\n const lockAge = Date.now() - info.timestamp;\n \n if (lockAge > staleTimeout) {\n return false; // Stale lock\n }\n \n // Check if process is still running\n const currentHostname = require('os').hostname();\n if (info.hostname === currentHostname && !isProcessRunning(info.pid)) {\n return false; // Orphaned lock\n }\n \n return true;\n } catch {\n return false;\n }\n}\n","import { existsSync } from 'node:fs';\nimport path from 'node:path';\nimport { runExecFile } from '../utils/command-runner.js';\n\nexport interface Commit {\n hash: string;\n author: string;\n date: string;\n message: string;\n}\n\nexport interface Change {\n path: string;\n status: string;\n oldPath?: string;\n}\n\nasync function execGit(args: string[], cwd: string): Promise<string | null> {\n try {\n const { stdout } = await runExecFile(\n 'git',\n ['-C', cwd, ...args],\n { actor: 'internal:git', triggeredBy: 'manual', targetPath: cwd },\n { maxBuffer: 10 * 1024 * 1024, captureOutput: false }\n );\n return stdout.trim();\n } catch (error: any) {\n const stderr: string | undefined = error?.stderr?.toString();\n // Gracefully handle non-git directories and repos with no commits\n if (stderr?.includes('not a git repository') || stderr?.includes('does not have any commits')) {\n return null;\n }\n throw error;\n }\n}\n\nasync function ensureRepo(projectPath: string): Promise<boolean> {\n const result = await execGit(['rev-parse', '--is-inside-work-tree'], projectPath);\n return result === 'true';\n}\n\nfunction parseNameStatus(output: string): Change[] {\n return output\n .split('\\n')\n .map((line) => line.trim())\n .filter(Boolean)\n .map((line) => {\n const parts = line.split('\\t');\n const status = parts[0] ?? '';\n const filePath = parts[1] ?? '';\n const oldPath = parts[2];\n const change: Change = { status, path: filePath };\n if (oldPath) change.oldPath = oldPath;\n return change;\n })\n .filter((entry) => entry.path.length > 0);\n}\n\nexport async function getRecentCommits(projectPath: string, limit: number): Promise<Commit[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n const output = await execGit(\n ['log', `-n`, String(limit), '--pretty=format:%H%x09%an%x09%ad%x09%s', '--date=iso'],\n projectPath\n );\n\n if (!output) return [];\n\n return output.split('\\n').map((line) => {\n const [hash, author, date, message] = line.split('\\t');\n return { hash, author, date, message } as Commit;\n });\n}\n\nexport async function getLastCommit(projectPath: string): Promise<Commit | null> {\n const commits = await getRecentCommits(projectPath, 1);\n return commits[0] ?? null;\n}\n\nexport async function getStagedChanges(projectPath: string): Promise<Change[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n const output = await execGit(['diff', '--cached', '--name-status'], projectPath);\n if (!output) return [];\n return parseNameStatus(output);\n}\n\nexport async function getUncommittedChanges(projectPath: string): Promise<Change[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n const changes: Change[] = [];\n\n const unstaged = await execGit(['diff', '--name-status'], projectPath);\n if (unstaged) {\n changes.push(...parseNameStatus(unstaged));\n }\n\n const untracked = await execGit(['ls-files', '--others', '--exclude-standard'], projectPath);\n if (untracked) {\n changes.push(\n ...untracked\n .split('\\n')\n .map((p) => p.trim())\n .filter(Boolean)\n .map((p) => ({ status: '??', path: p }))\n );\n }\n\n return changes;\n}\n\n/**\n * Get a flat list of changed file paths in the working tree.\n * Convenience helper used by tooling (e.g. cache invalidation).\n *\n * Returns null if not a git repository.\n */\nexport async function getGitChangedFiles(projectPath: string): Promise<string[] | null> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return null;\n\n const [staged, uncommitted] = await Promise.all([\n getStagedChanges(projectPath).catch(() => []),\n getUncommittedChanges(projectPath).catch(() => []),\n ]);\n\n const paths = new Set<string>();\n for (const change of [...staged, ...uncommitted]) {\n if (change.path) paths.add(change.path);\n if (change.oldPath) paths.add(change.oldPath);\n }\n\n return [...paths];\n}\n\nexport async function getDiff(projectPath: string, commitHash: string): Promise<string> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return '';\n\n const diff = await execGit(['show', commitHash, '--unified=3', '--no-color'], projectPath);\n return diff ?? '';\n}\n\nexport async function getWorkingTreeDiff(projectPath: string, stagedOnly = false): Promise<string> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return '';\n\n const args = stagedOnly ? ['diff', '--cached', '--unified=3', '--no-color'] : ['diff', '--unified=3', '--no-color'];\n const diff = await execGit(args, projectPath);\n return diff ?? '';\n}\n\nexport async function getUnpushedCommits(projectPath: string): Promise<Commit[]> {\n const isRepo = await ensureRepo(projectPath);\n if (!isRepo) return [];\n\n // Handles detached HEAD by falling back to HEAD if upstream missing\n const upstream = await execGit(['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], projectPath);\n if (!upstream) {\n return getRecentCommits(projectPath, 10);\n }\n\n const output = await execGit(['log', `${upstream}..HEAD`, '--pretty=format:%H%x09%an%x09%ad%x09%s', '--date=iso'], projectPath);\n if (!output) return [];\n\n return output.split('\\n').filter(Boolean).map((line) => {\n const [hash, author, date, message] = line.split('\\t');\n return { hash, author, date, message } as Commit;\n });\n}\n\nexport function resolveRepoPath(projectPath: string): string {\n const gitDir = path.join(projectPath, '.git');\n if (existsSync(gitDir)) return projectPath;\n return projectPath;\n}\n\n/**\n * Check if the given path is inside a git repository\n */\nexport async function isGitRepo(projectPath: string): Promise<boolean> {\n const result = await execGit(['rev-parse', '--is-inside-work-tree'], projectPath);\n return result === 'true';\n}\n\n/**\n * Get files changed since a given timestamp\n * Uses git log to find commits after timestamp, then gets affected files\n * Returns null if not a git repo or on error\n */\nexport async function getChangedFilesSinceTimestamp(\n projectPath: string,\n timestamp: number\n): Promise<string[] | null> {\n const isRepo = await isGitRepo(projectPath);\n if (!isRepo) return null;\n\n try {\n // Convert timestamp to ISO date for git\n const sinceDate = new Date(timestamp).toISOString();\n \n // Set timeout for git operations (5 seconds total)\n const GIT_TIMEOUT_MS = 5000;\n const startTime = Date.now();\n \n // Get all files that changed in commits since the timestamp\n // Use Promise.race to timeout if git operations take too long\n const committedChangesPromise = execGit(\n ['log', `--since=${sinceDate}`, '--name-only', '--pretty=format:'],\n projectPath\n );\n const committedChangesTimeout = new Promise<string | null>((resolve) => {\n setTimeout(() => resolve(null), GIT_TIMEOUT_MS);\n });\n const committedChanges = await Promise.race([committedChangesPromise, committedChangesTimeout]);\n\n // Check if we've exceeded timeout\n if (Date.now() - startTime > GIT_TIMEOUT_MS) {\n return null;\n }\n\n // Get currently modified files (staged + unstaged) - run in parallel with timeout\n const stagedPromise = execGit(['diff', '--cached', '--name-only'], projectPath);\n const unstagedPromise = execGit(['diff', '--name-only'], projectPath);\n const untrackedPromise = execGit(\n ['ls-files', '--others', '--exclude-standard'],\n projectPath\n );\n \n const timeoutPromise = new Promise<null>((resolve) => {\n setTimeout(() => resolve(null), Math.max(0, GIT_TIMEOUT_MS - (Date.now() - startTime)));\n });\n \n const [stagedChanges, unstagedChanges, untrackedFiles] = await Promise.race([\n Promise.all([stagedPromise, unstagedPromise, untrackedPromise]),\n timeoutPromise.then(() => [null, null, null] as const)\n ]);\n\n // Combine all changed files\n const changedFiles = new Set<string>();\n \n const addFiles = (output: string | null) => {\n if (output) {\n output.split('\\n')\n .map(f => f.trim())\n .filter(Boolean)\n .forEach(f => changedFiles.add(path.join(projectPath, f)));\n }\n };\n\n addFiles(committedChanges);\n addFiles(stagedChanges);\n addFiles(unstagedChanges);\n addFiles(untrackedFiles);\n\n return Array.from(changedFiles);\n } catch {\n return null;\n }\n}\n","/**\n * Command Runner (with audit logging)\n *\n * Goal: Whenever Trie runs a shell command, record:\n * - command string\n * - exit code\n * - duration\n * - optional (redacted) stdout/stderr\n */\nimport { exec, execFile, execSync, type ExecException } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nimport {\n createAuditEntry,\n completeAuditEntry,\n logSkillExecution,\n type ExecutedCommand,\n type SkillExecution,\n} from './audit-logger.js';\n\nconst execAsync = promisify(exec);\nconst execFileAsync = promisify(execFile);\n\nexport type { ExecutedCommand, SkillExecution };\nexport type AuditTriggeredBy = SkillExecution['triggeredBy'];\n\nexport interface CommandAuditContext {\n /** Shown as `skillName` in audit logs; use something like `tool:pr-review` */\n actor: string;\n /** Where this came from in the product flow */\n triggeredBy: AuditTriggeredBy;\n /** Usually the working directory / repo path */\n targetPath: string;\n /** Optional string for `skillSource` */\n source?: string;\n}\n\nexport interface RunCommandOptions {\n cwd?: string;\n timeoutMs?: number;\n maxBuffer?: number;\n\n /** Capture stdout/stderr in the audit log */\n captureOutput?: boolean;\n /** Redact obvious secrets from captured output */\n redactOutput?: boolean;\n /** Max chars to keep per output stream */\n maxOutputChars?: number;\n}\n\nfunction redact(text: string): string {\n // Keep this conservative to avoid false redaction and avoid expensive processing.\n return text\n // Common key=value secrets\n .replace(/\\b(AWS|ANTHROPIC|OPENAI|GITHUB)_[A-Z0-9_]*\\s*=\\s*([^\\s\"'`]+)/gi, '$1_<REDACTED>=<REDACTED>')\n // Bearer tokens\n .replace(/\\bBearer\\s+[A-Za-z0-9\\-._~+/]+=*\\b/g, 'Bearer <REDACTED>')\n // GitHub tokens / generic tokens\n .replace(/\\bghp_[A-Za-z0-9]{20,}\\b/g, 'ghp_<REDACTED>')\n .replace(/\\b(?:xox[baprs]-)[A-Za-z0-9-]{10,}\\b/g, '<REDACTED_SLACK_TOKEN>')\n // AWS access key id (best-effort)\n .replace(/\\bAKIA[0-9A-Z]{16}\\b/g, 'AKIA<REDACTED>');\n}\n\nfunction clampOutput(text: string, maxChars: number): string {\n if (text.length <= maxChars) return text;\n return text.slice(0, maxChars) + `\\n…(truncated ${text.length - maxChars} chars)`;\n}\n\nfunction buildCommandRecord(command: string): ExecutedCommand {\n return {\n command,\n timestamp: new Date().toISOString(),\n };\n}\n\nasync function finalizeAndWrite(\n entry: SkillExecution,\n cmd: ExecutedCommand,\n outcome: { success: boolean; exitCode?: number; stdout?: string; stderr?: string; error?: string; startedAt: number },\n options?: Pick<RunCommandOptions, 'captureOutput' | 'redactOutput' | 'maxOutputChars'>\n): Promise<void> {\n const duration = Date.now() - outcome.startedAt;\n cmd.duration = duration;\n if (outcome.exitCode !== undefined) {\n cmd.exitCode = outcome.exitCode;\n }\n\n const captureOutput = options?.captureOutput ?? false;\n const redactOutput = options?.redactOutput ?? true;\n const maxOutputChars = options?.maxOutputChars ?? 2000;\n\n if (captureOutput) {\n const out = outcome.stdout ?? '';\n const err = outcome.stderr ?? '';\n cmd.stdout = redactOutput ? redact(clampOutput(out, maxOutputChars)) : clampOutput(out, maxOutputChars);\n cmd.stderr = redactOutput ? redact(clampOutput(err, maxOutputChars)) : clampOutput(err, maxOutputChars);\n }\n\n const completed = completeAuditEntry(entry, outcome.success, outcome.error);\n await logSkillExecution(completed);\n}\n\nexport async function runShellCommand(\n command: string,\n audit: CommandAuditContext,\n options?: RunCommandOptions\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n const startedAt = Date.now();\n const entry = createAuditEntry(audit.actor, audit.source ?? 'trie', audit.triggeredBy, audit.targetPath);\n const cmd = buildCommandRecord(command);\n entry.commands?.push(cmd);\n\n try {\n const { stdout, stderr } = await execAsync(command, {\n cwd: options?.cwd,\n timeout: options?.timeoutMs,\n maxBuffer: options?.maxBuffer,\n });\n\n await finalizeAndWrite(entry, cmd, { success: true, exitCode: 0, stdout, stderr, startedAt }, options);\n return { stdout: stdout ?? '', stderr: stderr ?? '', exitCode: 0 };\n } catch (e) {\n const err = e as ExecException & { stdout?: unknown; stderr?: unknown; code?: unknown };\n const stdout = typeof err.stdout === 'string' ? err.stdout : '';\n const stderr = typeof err.stderr === 'string' ? err.stderr : '';\n const exitCode = typeof err.code === 'number' ? err.code : 1;\n\n await finalizeAndWrite(\n entry,\n cmd,\n { success: false, exitCode, stdout, stderr, error: err.message, startedAt },\n // Capture output for failures by default (so audits are useful)\n { ...options, captureOutput: options?.captureOutput ?? true }\n );\n\n return { stdout, stderr, exitCode };\n }\n}\n\nexport function runShellCommandSync(\n command: string,\n audit: CommandAuditContext,\n options?: Omit<RunCommandOptions, 'timeoutMs'> & { timeoutMs?: number }\n): { stdout: string; exitCode: number } {\n const startedAt = Date.now();\n const entry = createAuditEntry(audit.actor, audit.source ?? 'trie', audit.triggeredBy, audit.targetPath);\n const cmd = buildCommandRecord(command);\n entry.commands?.push(cmd);\n\n try {\n const stdout = execSync(command, {\n cwd: options?.cwd,\n timeout: options?.timeoutMs,\n maxBuffer: options?.maxBuffer,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n // Fire-and-forget write; sync APIs can’t await.\n void finalizeAndWrite(entry, cmd, { success: true, exitCode: 0, stdout, stderr: '', startedAt }, options);\n return { stdout: stdout ?? '', exitCode: 0 };\n } catch (e) {\n const err = e as ExecException & { stdout?: unknown; stderr?: unknown; status?: unknown };\n const stdout = typeof err.stdout === 'string' ? err.stdout : '';\n const stderr = typeof err.stderr === 'string' ? err.stderr : '';\n const exitCode = typeof err.status === 'number' ? err.status : 1;\n\n void finalizeAndWrite(\n entry,\n cmd,\n { success: false, exitCode, stdout, stderr, error: err.message, startedAt },\n { ...options, captureOutput: options?.captureOutput ?? true }\n );\n\n return { stdout, exitCode };\n }\n}\n\nexport async function runExecFile(\n file: string,\n args: string[],\n audit: CommandAuditContext,\n options?: Omit<RunCommandOptions, 'timeoutMs'> & { timeoutMs?: number }\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n const startedAt = Date.now();\n const command = [file, ...args].join(' ');\n const entry = createAuditEntry(audit.actor, audit.source ?? 'trie', audit.triggeredBy, audit.targetPath);\n const cmd = buildCommandRecord(command);\n entry.commands?.push(cmd);\n\n try {\n const { stdout, stderr } = await execFileAsync(file, args, {\n cwd: options?.cwd,\n timeout: options?.timeoutMs,\n maxBuffer: options?.maxBuffer,\n });\n\n await finalizeAndWrite(entry, cmd, { success: true, exitCode: 0, stdout: String(stdout ?? ''), stderr: String(stderr ?? ''), startedAt }, options);\n return { stdout: String(stdout ?? ''), stderr: String(stderr ?? ''), exitCode: 0 };\n } catch (e) {\n const err = e as ExecException & { stdout?: unknown; stderr?: unknown; code?: unknown };\n const stdout = typeof err.stdout === 'string' ? err.stdout : '';\n const stderr = typeof err.stderr === 'string' ? err.stderr : '';\n const exitCode = typeof err.code === 'number' ? err.code : 1;\n\n await finalizeAndWrite(\n entry,\n cmd,\n { success: false, exitCode, stdout, stderr, error: err.message, startedAt },\n { ...options, captureOutput: options?.captureOutput ?? true }\n );\n return { stdout, stderr, exitCode };\n }\n}\n\n","/**\n * Audit logger stub\n *\n * Audit functionality has been integrated into the decision ledger.\n * This module exists to keep legacy CLI/tooling paths working without the old skills system.\n */\n\nexport interface AuditStatistics {\n totalScans: number;\n totalIssues: number;\n criticalCount: number;\n seriousCount: number;\n moderateCount: number;\n lowCount: number;\n totalExecutions: number;\n successfulExecutions: number;\n failedExecutions: number;\n uniqueSkills: number;\n totalCommands: number;\n blockedCommands: number;\n totalNetworkCalls: number;\n blockedNetworkCalls: number;\n}\n\nexport interface AuditEntry {\n id: string;\n timestamp: string;\n command: string;\n status: string;\n commands?: ExecutedCommand[];\n}\n\nexport interface ExecutedCommand {\n command: string;\n timestamp: string;\n exitCode?: number;\n duration?: number;\n stdout?: string;\n stderr?: string;\n}\n\nexport interface SkillExecution {\n skillName: string;\n skillSource: string;\n triggeredBy: 'scan' | 'mcp' | 'cli' | 'watch' | 'manual';\n targetPath: string;\n startedAt: string;\n completedAt?: string;\n success?: boolean;\n error?: string;\n commands?: ExecutedCommand[];\n}\n\nexport function formatAuditLog(_entry: AuditEntry): string {\n return 'Audit logging has been integrated into the decision ledger';\n}\n\nexport function getAuditStatistics(): AuditStatistics {\n return {\n totalScans: 0,\n totalIssues: 0,\n criticalCount: 0,\n seriousCount: 0,\n moderateCount: 0,\n lowCount: 0,\n totalExecutions: 0,\n successfulExecutions: 0,\n failedExecutions: 0,\n uniqueSkills: 0,\n totalCommands: 0,\n blockedCommands: 0,\n totalNetworkCalls: 0,\n blockedNetworkCalls: 0,\n };\n}\n\nexport function createAuditEntry(\n skillName: string,\n skillSource: string,\n triggeredBy: SkillExecution['triggeredBy'],\n targetPath: string\n): SkillExecution {\n return {\n skillName,\n skillSource,\n triggeredBy,\n targetPath,\n startedAt: new Date().toISOString(),\n commands: [],\n };\n}\n\nexport function completeAuditEntry(\n entry: SkillExecution,\n success: boolean,\n error?: string\n): SkillExecution {\n const result: SkillExecution = {\n ...entry,\n completedAt: new Date().toISOString(),\n success,\n };\n if (error !== undefined) {\n result.error = error;\n }\n return result;\n}\n\nexport async function logSkillExecution(_execution: SkillExecution): Promise<void> {\n // Stub - no-op\n}\n\nexport async function getRecentAuditLogs(_limit: number = 10): Promise<AuditEntry[]> {\n return [];\n}\n\nexport async function getSkillAuditLogs(_skillName: string): Promise<AuditEntry[]> {\n return [];\n}\n\n","/**\n * Cryptographic Key Management\n * \n * Ed25519 signature support for ledger entries.\n * Keys are stored in .trie/keys/ directory.\n * \n * Usage:\n * - generateKeyPair() - Create new signing key\n * - getOrCreateKeyPair() - Get existing or create new\n * - signData() - Sign arbitrary data\n * - verifySignature() - Verify a signature\n */\n\nimport * as ed25519 from '@noble/ed25519';\nimport { randomBytes } from 'crypto';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { join } from 'path';\nimport { getTrieDirectory } from '../utils/workspace.js';\n\nexport interface KeyPair {\n publicKey: string; // Hex-encoded public key\n privateKey: string; // Hex-encoded private key\n}\n\nexport interface SignatureData {\n signature: string;\n publicKey: string;\n algorithm: 'Ed25519';\n signedAt: string;\n}\n\n/**\n * Get keys directory path\n */\nfunction getKeysDirectory(workDir?: string): string {\n const trieDir = getTrieDirectory(workDir || process.cwd());\n return join(trieDir, 'keys');\n}\n\n/**\n * Get the default key file path\n */\nfunction getDefaultKeyPath(workDir?: string): string {\n return join(getKeysDirectory(workDir), 'signing-key.json');\n}\n\n/**\n * Generate a new Ed25519 key pair\n */\nexport async function generateKeyPair(): Promise<KeyPair> {\n // Generate 32 random bytes for private key\n const privateKeyBytes = randomBytes(32);\n const publicKeyBytes = await ed25519.getPublicKeyAsync(privateKeyBytes);\n \n return {\n publicKey: Buffer.from(publicKeyBytes).toString('hex'),\n privateKey: Buffer.from(privateKeyBytes).toString('hex')\n };\n}\n\n/**\n * Save key pair to disk (encrypted would be better, but starting simple)\n */\nexport function saveKeyPair(keyPair: KeyPair, workDir?: string): void {\n const keysDir = getKeysDirectory(workDir);\n \n // Create keys directory if it doesn't exist\n if (!existsSync(keysDir)) {\n mkdirSync(keysDir, { recursive: true });\n }\n \n const keyPath = getDefaultKeyPath(workDir);\n const keyData = {\n ...keyPair,\n createdAt: new Date().toISOString(),\n version: 1\n };\n \n writeFileSync(keyPath, JSON.stringify(keyData, null, 2), 'utf-8');\n \n // Warn about security\n console.error('⚠️ Signing key created at:', keyPath);\n console.error(' Keep this file secure and add to .gitignore');\n}\n\n/**\n * Load key pair from disk\n */\nexport function loadKeyPair(workDir?: string): KeyPair | null {\n const keyPath = getDefaultKeyPath(workDir);\n \n if (!existsSync(keyPath)) {\n return null;\n }\n \n try {\n const keyData = JSON.parse(readFileSync(keyPath, 'utf-8'));\n return {\n publicKey: keyData.publicKey,\n privateKey: keyData.privateKey\n };\n } catch (error) {\n console.error('Failed to load signing key:', error);\n return null;\n }\n}\n\n/**\n * Get existing key pair or create a new one\n */\nexport async function getOrCreateKeyPair(workDir?: string): Promise<KeyPair> {\n const existing = loadKeyPair(workDir);\n if (existing) {\n return existing;\n }\n \n const newKeyPair = await generateKeyPair();\n saveKeyPair(newKeyPair, workDir);\n return newKeyPair;\n}\n\n/**\n * Sign arbitrary data with private key\n */\nexport async function signData(data: string, privateKey: string): Promise<string> {\n const dataBytes = Buffer.from(data, 'utf-8');\n const privateKeyBytes = Buffer.from(privateKey, 'hex');\n const signatureBytes = await ed25519.signAsync(dataBytes, privateKeyBytes);\n \n return Buffer.from(signatureBytes).toString('hex');\n}\n\n/**\n * Verify a signature\n */\nexport async function verifySignature(\n data: string,\n signature: string,\n publicKey: string\n): Promise<boolean> {\n try {\n const dataBytes = Buffer.from(data, 'utf-8');\n const signatureBytes = Buffer.from(signature, 'hex');\n const publicKeyBytes = Buffer.from(publicKey, 'hex');\n \n return await ed25519.verifyAsync(signatureBytes, dataBytes, publicKeyBytes);\n } catch (error) {\n console.error('Signature verification failed:', error);\n return false;\n }\n}\n\n/**\n * Sign a data hash and return signature metadata\n */\nexport async function signHash(hash: string, workDir?: string): Promise<SignatureData> {\n const keyPair = await getOrCreateKeyPair(workDir);\n const signature = await signData(hash, keyPair.privateKey);\n \n return {\n signature,\n publicKey: keyPair.publicKey,\n algorithm: 'Ed25519',\n signedAt: new Date().toISOString()\n };\n}\n\n/**\n * Verify a hash signature\n */\nexport async function verifyHashSignature(\n hash: string,\n signatureData: SignatureData\n): Promise<boolean> {\n if (signatureData.algorithm !== 'Ed25519') {\n console.error('Unsupported signature algorithm:', signatureData.algorithm);\n return false;\n }\n \n return await verifySignature(hash, signatureData.signature, signatureData.publicKey);\n}\n\n/**\n * Get the public key for the current workspace\n */\nexport function getPublicKey(workDir?: string): string | null {\n const keyPair = loadKeyPair(workDir);\n return keyPair?.publicKey || null;\n}\n\n/**\n * Check if signing keys exist\n */\nexport function hasSigningKey(workDir?: string): boolean {\n const keyPath = getDefaultKeyPath(workDir);\n return existsSync(keyPath);\n}\n","/**\n * Git Integration for Ledger\n * \n * Auto-commit ledger changes to provide:\n * - Distributed backup (every clone has a copy)\n * - Git's content-addressable storage (tamper-evident)\n * - History tracking via commit graph\n * - Remote backup via push\n * \n * Usage:\n * - autoCommitLedger() - Commit ledger changes after append\n * - isGitIntegrationEnabled() - Check if Git integration is on\n */\n\nimport { exec } from 'child_process';\nimport { promisify } from 'util';\nimport { existsSync } from 'fs';\nimport { join } from 'path';\nimport { getTrieDirectory } from '../utils/workspace.js';\n\nconst execAsync = promisify(exec);\n\nexport interface GitCommitResult {\n committed: boolean;\n commitHash?: string;\n error?: string;\n}\n\n/**\n * Check if Git integration is enabled for this project\n * \n * Git integration is enabled if:\n * 1. Project is a git repo\n * 2. .trie/config.json has gitIntegration: true (or doesn't exist, defaults to true)\n */\nexport async function isGitIntegrationEnabled(workDir: string): Promise<boolean> {\n try {\n // Check if git repo\n const gitDir = join(workDir, '.git');\n if (!existsSync(gitDir)) {\n return false;\n }\n \n // Check config (default to true if config doesn't exist)\n const configPath = join(getTrieDirectory(workDir), 'config.json');\n if (!existsSync(configPath)) {\n return true; // Default: enabled\n }\n \n const config = JSON.parse(await import('fs/promises').then(fs => fs.readFile(configPath, 'utf-8')));\n return config.gitIntegration !== false;\n } catch {\n return false;\n }\n}\n\n/**\n * Auto-commit ledger changes\n * \n * Commits ledger.json to git with a structured commit message.\n * This provides distributed backup and tamper-evident history.\n */\nexport async function autoCommitLedger(workDir: string, message?: string): Promise<GitCommitResult> {\n try {\n const enabled = await isGitIntegrationEnabled(workDir);\n if (!enabled) {\n return { committed: false, error: 'Git integration disabled' };\n }\n \n const ledgerPath = join(getTrieDirectory(workDir), 'memory', 'ledger.json');\n \n // Check if ledger has changes\n const { stdout: statusOutput } = await execAsync('git status --porcelain', { cwd: workDir });\n const hasLedgerChanges = statusOutput.includes('ledger.json');\n \n if (!hasLedgerChanges) {\n return { committed: false, error: 'No ledger changes to commit' };\n }\n \n // Stage ledger file\n await execAsync(`git add ${ledgerPath}`, { cwd: workDir });\n \n // Commit with structured message\n const commitMessage = message || 'ledger: append entries';\n await execAsync(\n `git commit -m \"${commitMessage}\"`,\n { cwd: workDir }\n );\n \n // Get commit hash\n const { stdout: hashOutput } = await execAsync('git rev-parse HEAD', { cwd: workDir });\n const commitHash = hashOutput.trim();\n \n return {\n committed: true,\n commitHash\n };\n } catch (error) {\n return {\n committed: false,\n error: error instanceof Error ? error.message : String(error)\n };\n }\n}\n\n/**\n * Enable or disable Git integration\n */\nexport async function setGitIntegration(workDir: string, enabled: boolean): Promise<void> {\n const configPath = join(getTrieDirectory(workDir), 'config.json');\n const fs = await import('fs/promises');\n \n let config: Record<string, any> = {};\n if (existsSync(configPath)) {\n config = JSON.parse(await fs.readFile(configPath, 'utf-8'));\n }\n \n config.gitIntegration = enabled;\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');\n}\n\n/**\n * Add .trie/keys/ to .gitignore\n * \n * Signing keys should NOT be committed to git.\n * This ensures they stay local and secure.\n */\nexport async function ensureKeysIgnored(workDir: string): Promise<void> {\n try {\n const gitignorePath = join(workDir, '.gitignore');\n const fs = await import('fs/promises');\n \n let gitignore = '';\n if (existsSync(gitignorePath)) {\n gitignore = await fs.readFile(gitignorePath, 'utf-8');\n }\n \n // Check if already ignored\n if (gitignore.includes('.trie/keys/')) {\n return;\n }\n \n // Add to gitignore\n const addition = '\\n# Trie signing keys (keep secure, do not commit)\\n.trie/keys/\\n';\n await fs.appendFile(gitignorePath, addition, 'utf-8');\n } catch (error) {\n console.error('Failed to update .gitignore:', error);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAAA,QAAO,YAAAC,WAAU,WAAW,QAAAC,OAAM,UAAAC,eAAc;AACzD,SAAS,cAAAC,mBAAkB;AAC3B,SAAS,YAAY,oBAAoB;AACzC,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,QAAAC,aAAY;;;ACUrB,SAAS,MAAM,QAAQ,UAAU,MAAM,aAAa;AACpD,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAmCxB,IAAM,cAAc,oBAAI,IAAY;AAGpC,SAAS,sBAAsB;AAC7B,QAAM,UAAU,MAAM;AACpB,eAAW,YAAY,aAAa;AAClC,UAAI;AAEF,cAAM,KAAK,UAAQ,IAAI;AACvB,YAAI,GAAG,WAAW,QAAQ,GAAG;AAC3B,aAAG,WAAW,QAAQ;AAAA,QACxB;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,UAAQ,GAAG,QAAQ,OAAO;AAC1B,UAAQ,GAAG,UAAU,MAAM;AAAE,YAAQ;AAAG,YAAQ,KAAK,GAAG;AAAA,EAAG,CAAC;AAC5D,UAAQ,GAAG,WAAW,MAAM;AAA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AU;AAE1C,QAAM,UAAU,oBAAI,IAAmE;AAEvF,aAAW,WAAW,UAAU;AAC9B,UAAM,cAA6B,CAAC;AACpC,QAAI,WAA+B;AAEnC,eAAW,SAAS,QAAQ;AAC1B,iBAAW,SAAS,MAAM,SAAS;AACjC,YAAI,MAAM,OAAO,SAAS;AACxB,qBAAW;AAAA,QACb;AACA,YAAI,MAAM,gBAAgB,SAAS;AACjC,sBAAY,KAAK,KAAK;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAEA,QAAI,UAAU;AACZ,cAAQ,IAAI,SAAS,EAAE,UAAU,YAAY,CAAC;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AACT;AAKA,eAAsB,mBAAmB,SAMtC;AACD,QAAM,aAAa,WAAW,oBAAoB,QAAW,IAAI;AACjE,QAAM,SAAS,MAAM,WAAW,UAAU;AAE1C,MAAI,eAAe;AACnB,MAAI,gBAAgB;AACpB,MAAI,mBAAmB;AACvB,MAAI,iBAAiB;AAErB,aAAW,SAAS,QAAQ;AAC1B,eAAW,SAAS,MAAM,SAAS;AACjC;AACA,YAAM,SAAS,MAAM,UAAU;AAE/B,UAAI,WAAW,SAAU;AAAA,eAChB,WAAW,YAAa;AAAA,eACxB,WAAW,iBAAkB;AAAA,IACxC;AAAA,EACF;AAEA,QAAM,iBAAiB,eAAe,KAChC,mBAAmB,kBAAkB,eAAgB,MACvD;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,KAAK,MAAM,iBAAiB,GAAG,IAAI;AAAA,EACrD;AACF;","names":["mkdir","readFile","stat","unlink","existsSync","join","existsSync","existsSync","existsSync","exec","promisify","existsSync","join","execAsync","promisify","exec","join","existsSync","join","existsSync","join","mkdir","existsSync","readFile","stat","unlink"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|