craftvault 0.0.0-stage → 1.0.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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +352 -2
  3. package/dist/.cv/HEAD +1 -0
  4. package/dist/.cv/index +4 -0
  5. package/dist/.cv/refs/heads/main +0 -0
  6. package/dist/api/index.d.ts +6 -0
  7. package/dist/api/index.d.ts.map +1 -0
  8. package/dist/api/index.js +22 -0
  9. package/dist/api/index.js.map +1 -0
  10. package/dist/api/server.d.ts +37 -0
  11. package/dist/api/server.d.ts.map +1 -0
  12. package/dist/api/server.js +406 -0
  13. package/dist/api/server.js.map +1 -0
  14. package/dist/api/types.d.ts +90 -0
  15. package/dist/api/types.d.ts.map +1 -0
  16. package/dist/api/types.js +6 -0
  17. package/dist/api/types.js.map +1 -0
  18. package/dist/cli/commands/add.d.ts +3 -0
  19. package/dist/cli/commands/add.d.ts.map +1 -0
  20. package/dist/cli/commands/add.js +37 -0
  21. package/dist/cli/commands/add.js.map +1 -0
  22. package/dist/cli/commands/branch.d.ts +3 -0
  23. package/dist/cli/commands/branch.d.ts.map +1 -0
  24. package/dist/cli/commands/branch.js +58 -0
  25. package/dist/cli/commands/branch.js.map +1 -0
  26. package/dist/cli/commands/commit.d.ts +3 -0
  27. package/dist/cli/commands/commit.d.ts.map +1 -0
  28. package/dist/cli/commands/commit.js +31 -0
  29. package/dist/cli/commands/commit.js.map +1 -0
  30. package/dist/cli/commands/diff.d.ts +3 -0
  31. package/dist/cli/commands/diff.d.ts.map +1 -0
  32. package/dist/cli/commands/diff.js +74 -0
  33. package/dist/cli/commands/diff.js.map +1 -0
  34. package/dist/cli/commands/init.d.ts +3 -0
  35. package/dist/cli/commands/init.d.ts.map +1 -0
  36. package/dist/cli/commands/init.js +42 -0
  37. package/dist/cli/commands/init.js.map +1 -0
  38. package/dist/cli/commands/log.d.ts +3 -0
  39. package/dist/cli/commands/log.d.ts.map +1 -0
  40. package/dist/cli/commands/log.js +56 -0
  41. package/dist/cli/commands/log.js.map +1 -0
  42. package/dist/cli/commands/status.d.ts +3 -0
  43. package/dist/cli/commands/status.d.ts.map +1 -0
  44. package/dist/cli/commands/status.js +65 -0
  45. package/dist/cli/commands/status.js.map +1 -0
  46. package/dist/cli/commands/ui.d.ts +3 -0
  47. package/dist/cli/commands/ui.d.ts.map +1 -0
  48. package/dist/cli/commands/ui.js +78 -0
  49. package/dist/cli/commands/ui.js.map +1 -0
  50. package/dist/cli.d.ts +3 -0
  51. package/dist/cli.d.ts.map +1 -0
  52. package/dist/cli.js +28 -0
  53. package/dist/cli.js.map +1 -0
  54. package/dist/core/add.d.ts +57 -0
  55. package/dist/core/add.d.ts.map +1 -0
  56. package/dist/core/add.js +169 -0
  57. package/dist/core/add.js.map +1 -0
  58. package/dist/core/blob.d.ts +38 -0
  59. package/dist/core/blob.d.ts.map +1 -0
  60. package/dist/core/blob.js +69 -0
  61. package/dist/core/blob.js.map +1 -0
  62. package/dist/core/commit-builder.d.ts +49 -0
  63. package/dist/core/commit-builder.d.ts.map +1 -0
  64. package/dist/core/commit-builder.js +137 -0
  65. package/dist/core/commit-builder.js.map +1 -0
  66. package/dist/core/commit.d.ts +53 -0
  67. package/dist/core/commit.d.ts.map +1 -0
  68. package/dist/core/commit.js +128 -0
  69. package/dist/core/commit.js.map +1 -0
  70. package/dist/core/diff-engine.d.ts +77 -0
  71. package/dist/core/diff-engine.d.ts.map +1 -0
  72. package/dist/core/diff-engine.js +361 -0
  73. package/dist/core/diff-engine.js.map +1 -0
  74. package/dist/core/history.d.ts +92 -0
  75. package/dist/core/history.d.ts.map +1 -0
  76. package/dist/core/history.js +283 -0
  77. package/dist/core/history.js.map +1 -0
  78. package/dist/core/index.d.ts +17 -0
  79. package/dist/core/index.d.ts.map +1 -0
  80. package/dist/core/index.js +33 -0
  81. package/dist/core/index.js.map +1 -0
  82. package/dist/core/refs.d.ts +80 -0
  83. package/dist/core/refs.d.ts.map +1 -0
  84. package/dist/core/refs.js +183 -0
  85. package/dist/core/refs.js.map +1 -0
  86. package/dist/core/repository.d.ts +83 -0
  87. package/dist/core/repository.d.ts.map +1 -0
  88. package/dist/core/repository.js +194 -0
  89. package/dist/core/repository.js.map +1 -0
  90. package/dist/core/staging.d.ts +95 -0
  91. package/dist/core/staging.d.ts.map +1 -0
  92. package/dist/core/staging.js +245 -0
  93. package/dist/core/staging.js.map +1 -0
  94. package/dist/core/status.d.ts +48 -0
  95. package/dist/core/status.d.ts.map +1 -0
  96. package/dist/core/status.js +209 -0
  97. package/dist/core/status.js.map +1 -0
  98. package/dist/core/storage.d.ts +98 -0
  99. package/dist/core/storage.d.ts.map +1 -0
  100. package/dist/core/storage.js +225 -0
  101. package/dist/core/storage.js.map +1 -0
  102. package/dist/core/tree.d.ts +50 -0
  103. package/dist/core/tree.d.ts.map +1 -0
  104. package/dist/core/tree.js +124 -0
  105. package/dist/core/tree.js.map +1 -0
  106. package/dist/core/watcher.d.ts +35 -0
  107. package/dist/core/watcher.d.ts.map +1 -0
  108. package/dist/core/watcher.js +110 -0
  109. package/dist/core/watcher.js.map +1 -0
  110. package/dist/index.d.ts +7 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +23 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/types/index.d.ts +50 -0
  115. package/dist/types/index.d.ts.map +1 -0
  116. package/dist/types/index.js +6 -0
  117. package/dist/types/index.js.map +1 -0
  118. package/dist/utils/compression.d.ts +29 -0
  119. package/dist/utils/compression.d.ts.map +1 -0
  120. package/dist/utils/compression.js +50 -0
  121. package/dist/utils/compression.js.map +1 -0
  122. package/dist/utils/diff.d.ts +52 -0
  123. package/dist/utils/diff.d.ts.map +1 -0
  124. package/dist/utils/diff.js +265 -0
  125. package/dist/utils/diff.js.map +1 -0
  126. package/dist/utils/hash.d.ts +25 -0
  127. package/dist/utils/hash.d.ts.map +1 -0
  128. package/dist/utils/hash.js +45 -0
  129. package/dist/utils/hash.js.map +1 -0
  130. package/dist/utils/ignore.d.ts +53 -0
  131. package/dist/utils/ignore.d.ts.map +1 -0
  132. package/dist/utils/ignore.js +204 -0
  133. package/dist/utils/ignore.js.map +1 -0
  134. package/dist/utils/index.d.ts +8 -0
  135. package/dist/utils/index.d.ts.map +1 -0
  136. package/dist/utils/index.js +24 -0
  137. package/dist/utils/index.js.map +1 -0
  138. package/package.json +65 -4
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ /**
3
+ * Add Command Implementation
4
+ * Stages files for commit by hashing and updating the index
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AddCommand = void 0;
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const staging_1 = require("./staging");
14
+ const storage_1 = require("./storage");
15
+ const blob_1 = require("./blob");
16
+ const hash_1 = require("../utils/hash");
17
+ const ignore_1 = require("../utils/ignore");
18
+ class AddCommand {
19
+ constructor(repo) {
20
+ // Accept either Repository instance or string path
21
+ this.repoPath = typeof repo === 'string' ? repo : repo.getRepoPath();
22
+ this.staging = new staging_1.StagingArea(this.repoPath);
23
+ this.storage = new storage_1.ObjectStorage(this.repoPath);
24
+ this.ignoreParser = new ignore_1.IgnoreParser(this.repoPath);
25
+ }
26
+ /**
27
+ * Stage files (convenience method for CLI)
28
+ */
29
+ async add(files) {
30
+ const results = await this.addFiles(files);
31
+ return Array.from(results.keys());
32
+ }
33
+ /**
34
+ * Stage a single file
35
+ * Reads file, creates blob, stores it, and updates index
36
+ */
37
+ async addFile(filePath) {
38
+ const fullPath = path_1.default.join(this.repoPath, filePath);
39
+ // Check if file exists
40
+ if (!fs_1.default.existsSync(fullPath)) {
41
+ throw new Error(`File not found: ${filePath}`);
42
+ }
43
+ // Check if it's a file (not directory)
44
+ const stats = fs_1.default.statSync(fullPath);
45
+ if (!stats.isFile()) {
46
+ throw new Error(`Not a file: ${filePath}`);
47
+ }
48
+ // Read file content
49
+ const content = fs_1.default.readFileSync(fullPath);
50
+ // Create blob
51
+ const blob = blob_1.Blob.fromContent(content);
52
+ const hash = blob.hash();
53
+ // Store blob if not already present
54
+ if (!this.storage.hasObject(hash)) {
55
+ await this.storage.writeBlob(blob);
56
+ }
57
+ // Update index
58
+ this.staging.stageFile(filePath, hash);
59
+ return hash;
60
+ }
61
+ /**
62
+ * Stage multiple files
63
+ */
64
+ async addFiles(filePaths) {
65
+ const results = new Map();
66
+ for (const filePath of filePaths) {
67
+ try {
68
+ const hash = await this.addFile(filePath);
69
+ results.set(filePath, hash);
70
+ }
71
+ catch (error) {
72
+ throw new Error(`Failed to add ${filePath}: ${error.message}`);
73
+ }
74
+ }
75
+ return results;
76
+ }
77
+ /**
78
+ * Stage all modified and untracked files
79
+ */
80
+ async addAll() {
81
+ const files = this.getAllTrackableFiles();
82
+ return await this.addFiles(files);
83
+ }
84
+ /**
85
+ * Get all files that can be staged (respecting .cvignore)
86
+ */
87
+ getAllTrackableFiles() {
88
+ const files = [];
89
+ const walk = (dir) => {
90
+ const entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
91
+ for (const entry of entries) {
92
+ const fullPath = path_1.default.join(dir, entry.name);
93
+ const relativePath = path_1.default.relative(this.repoPath, fullPath);
94
+ // Skip empty relative path
95
+ if (!relativePath || relativePath === '') {
96
+ continue;
97
+ }
98
+ if (entry.isDirectory()) {
99
+ if (this.ignoreParser.shouldSkipDirectory(relativePath)) {
100
+ continue; // Skip entire directory
101
+ }
102
+ walk(fullPath);
103
+ }
104
+ else if (entry.isFile()) {
105
+ if (!this.ignoreParser.isIgnored(relativePath, false)) {
106
+ files.push(relativePath);
107
+ }
108
+ }
109
+ }
110
+ };
111
+ walk(this.repoPath);
112
+ return files;
113
+ }
114
+ /**
115
+ * Stage files matching a pattern
116
+ */
117
+ async addPattern(pattern) {
118
+ const allFiles = this.getAllTrackableFiles();
119
+ const matchingFiles = this.matchPattern(allFiles, pattern);
120
+ return await this.addFiles(matchingFiles);
121
+ }
122
+ /**
123
+ * Simple pattern matching (supports * wildcard)
124
+ */
125
+ matchPattern(files, pattern) {
126
+ // Convert glob pattern to regex
127
+ const regexPattern = pattern
128
+ .replace(/\./g, '\\.')
129
+ .replace(/\*/g, '.*')
130
+ .replace(/\?/g, '.');
131
+ const regex = new RegExp(`^${regexPattern}$`);
132
+ return files.filter(file => regex.test(file));
133
+ }
134
+ /**
135
+ * Unstage a file (remove from staged, keep in index as modified)
136
+ */
137
+ unstageFile(filePath) {
138
+ this.staging.unstageFile(filePath);
139
+ }
140
+ /**
141
+ * Unstage multiple files
142
+ */
143
+ unstageFiles(filePaths) {
144
+ for (const filePath of filePaths) {
145
+ this.staging.unstageFile(filePath);
146
+ }
147
+ }
148
+ /**
149
+ * Check if file is already staged with same content
150
+ */
151
+ isFileStaged(filePath) {
152
+ const entry = this.staging.getEntry(filePath);
153
+ if (!entry || entry.status !== 'staged') {
154
+ return false;
155
+ }
156
+ // Check if file has changed since staging
157
+ return !this.staging.hasFileChanged(filePath);
158
+ }
159
+ /**
160
+ * Get hash of file without staging it
161
+ */
162
+ getFileHash(filePath) {
163
+ const fullPath = path_1.default.join(this.repoPath, filePath);
164
+ const content = fs_1.default.readFileSync(fullPath);
165
+ return (0, hash_1.computeObjectHash)('blob', content);
166
+ }
167
+ }
168
+ exports.AddCommand = AddCommand;
169
+ //# sourceMappingURL=add.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/core/add.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAAoB;AACpB,gDAAwB;AACxB,uCAAwC;AACxC,uCAA0C;AAC1C,iCAA8B;AAC9B,wCAAkD;AAClD,4CAA+C;AAE/C,MAAa,UAAU;IAMrB,YAAY,IAAS;QACnB,mDAAmD;QACnD,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,KAA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@@
1
+ /**
2
+ * Blob Object Implementation
3
+ * Stores raw file content without metadata
4
+ * Format: blob {size}\0{content}
5
+ */
6
+ import { BlobObject } from '../types';
7
+ export declare class Blob implements BlobObject {
8
+ type: 'blob';
9
+ size: number;
10
+ content: Buffer;
11
+ constructor(content: Buffer);
12
+ /**
13
+ * Compute SHA-1 hash of this blob
14
+ */
15
+ hash(): string;
16
+ /**
17
+ * Serialize blob to storage format
18
+ * Format: blob {size}\0{content}
19
+ */
20
+ serialize(): Buffer;
21
+ /**
22
+ * Deserialize blob from storage format
23
+ */
24
+ static deserialize(data: Buffer): Blob;
25
+ /**
26
+ * Create blob from file content
27
+ */
28
+ static fromContent(content: Buffer): Blob;
29
+ /**
30
+ * Get raw content
31
+ */
32
+ getContent(): Buffer;
33
+ /**
34
+ * Get content as string
35
+ */
36
+ getContentAsString(): string;
37
+ }
38
+ //# sourceMappingURL=blob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/core/blob.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,qBAAa,IAAK,YAAW,UAAU;IACrC,IAAI,EAAE,MAAM,CAAU;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;gBAEJ,OAAO,EAAE,MAAM;IAK3B;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;;OAGG;IACH,SAAS,IAAI,MAAM;IAKnB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAqBtC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIzC;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,kBAAkB,IAAI,MAAM;CAG7B"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * Blob Object Implementation
4
+ * Stores raw file content without metadata
5
+ * Format: blob {size}\0{content}
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Blob = void 0;
9
+ const hash_1 = require("../utils/hash");
10
+ class Blob {
11
+ constructor(content) {
12
+ this.type = 'blob';
13
+ this.content = content;
14
+ this.size = content.length;
15
+ }
16
+ /**
17
+ * Compute SHA-1 hash of this blob
18
+ */
19
+ hash() {
20
+ return (0, hash_1.computeObjectHash)(this.type, this.content);
21
+ }
22
+ /**
23
+ * Serialize blob to storage format
24
+ * Format: blob {size}\0{content}
25
+ */
26
+ serialize() {
27
+ const header = Buffer.from(`${this.type} ${this.size}\0`);
28
+ return Buffer.concat([header, this.content]);
29
+ }
30
+ /**
31
+ * Deserialize blob from storage format
32
+ */
33
+ static deserialize(data) {
34
+ // Find null byte separator
35
+ const nullIndex = data.indexOf(0);
36
+ if (nullIndex === -1) {
37
+ throw new Error('Invalid blob format: missing null separator');
38
+ }
39
+ // Extract header
40
+ const header = data.slice(0, nullIndex).toString('utf-8');
41
+ const [type, sizeStr] = header.split(' ');
42
+ if (type !== 'blob') {
43
+ throw new Error(`Invalid object type: expected blob, got ${type}`);
44
+ }
45
+ // Extract content
46
+ const content = data.slice(nullIndex + 1);
47
+ return new Blob(content);
48
+ }
49
+ /**
50
+ * Create blob from file content
51
+ */
52
+ static fromContent(content) {
53
+ return new Blob(content);
54
+ }
55
+ /**
56
+ * Get raw content
57
+ */
58
+ getContent() {
59
+ return this.content;
60
+ }
61
+ /**
62
+ * Get content as string
63
+ */
64
+ getContentAsString() {
65
+ return this.content.toString('utf-8');
66
+ }
67
+ }
68
+ exports.Blob = Blob;
69
+ //# sourceMappingURL=blob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/core/blob.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,wCAAkD;AAElD,MAAa,IAAI;IAKf,YAAY,OAAe;QAJ3B,SAAI,GAAW,MAAM,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C,WAAW,CAAC,OAAe;QAChC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF;AAtED,oBAsEC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Commit Builder
3
+ * Creates commits from staged files by building tree objects
4
+ */
5
+ export interface CommitOptions {
6
+ message: string;
7
+ author?: string;
8
+ timestamp?: number;
9
+ }
10
+ export declare class CommitBuilder {
11
+ private repoPath;
12
+ private staging;
13
+ private storage;
14
+ private refManager;
15
+ constructor(repo: any);
16
+ /**
17
+ * Convenience method for CLI - commit with message and author
18
+ */
19
+ commit(message: string, author?: string): Promise<string>;
20
+ /**
21
+ * Create a commit from staged files
22
+ */
23
+ createCommit(options: CommitOptions): Promise<string>;
24
+ /**
25
+ * Build tree objects from staged files
26
+ * Recursively creates tree hierarchy
27
+ */
28
+ private buildTreeFromStaged;
29
+ /**
30
+ * Build directory tree structure from flat file list
31
+ */
32
+ private buildDirectoryTree;
33
+ /**
34
+ * Recursively write tree objects
35
+ */
36
+ private writeTreeRecursive;
37
+ /**
38
+ * Check if commit can be created
39
+ */
40
+ canCommit(): boolean;
41
+ /**
42
+ * Get commit preview information
43
+ */
44
+ getCommitPreview(): Promise<{
45
+ stagedFiles: string[];
46
+ parent: string | null;
47
+ }>;
48
+ }
49
+ //# sourceMappingURL=commit-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-builder.d.ts","sourceRoot":"","sources":["../../src/core/commit-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAa;gBAEnB,IAAI,EAAE,GAAG;IAQrB;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/D;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IAgC3D;;;OAGG;YACW,mBAAmB;IAWjC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqC1B;;OAEG;YACW,kBAAkB;IAkBhC;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC;QAChC,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CAMH"}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /**
3
+ * Commit Builder
4
+ * Creates commits from staged files by building tree objects
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.CommitBuilder = void 0;
11
+ const path_1 = __importDefault(require("path"));
12
+ const staging_1 = require("./staging");
13
+ const storage_1 = require("./storage");
14
+ const refs_1 = require("./refs");
15
+ const tree_1 = require("./tree");
16
+ const commit_1 = require("./commit");
17
+ class CommitBuilder {
18
+ constructor(repo) {
19
+ // Accept either Repository instance or string path
20
+ this.repoPath = typeof repo === 'string' ? repo : repo.getRepoPath();
21
+ this.staging = new staging_1.StagingArea(this.repoPath);
22
+ this.storage = new storage_1.ObjectStorage(this.repoPath);
23
+ this.refManager = new refs_1.RefManager(path_1.default.join(this.repoPath, '.cv'));
24
+ }
25
+ /**
26
+ * Convenience method for CLI - commit with message and author
27
+ */
28
+ async commit(message, author) {
29
+ return await this.createCommit({ message, author });
30
+ }
31
+ /**
32
+ * Create a commit from staged files
33
+ */
34
+ async createCommit(options) {
35
+ const { message, author = 'CraftVault User', timestamp = Date.now() } = options;
36
+ // Check if there are staged files
37
+ if (!this.staging.hasStagedChanges()) {
38
+ throw new Error('No changes staged for commit');
39
+ }
40
+ // Get parent commit hash
41
+ const parentHash = this.refManager.resolveHEAD();
42
+ // Build tree from staged files
43
+ const treeHash = await this.buildTreeFromStaged();
44
+ // Create commit object
45
+ const commit = new commit_1.Commit(treeHash, message, author, parentHash, timestamp);
46
+ const commitHash = await this.storage.writeCommit(commit);
47
+ // Update current branch reference
48
+ try {
49
+ this.refManager.updateCurrentBranch(commitHash);
50
+ }
51
+ catch (error) {
52
+ // If HEAD is detached or no branch exists, just update HEAD
53
+ this.refManager.writeHEAD(commitHash);
54
+ }
55
+ // Clear staged files from index
56
+ this.staging.clearStaged();
57
+ return commitHash;
58
+ }
59
+ /**
60
+ * Build tree objects from staged files
61
+ * Recursively creates tree hierarchy
62
+ */
63
+ async buildTreeFromStaged() {
64
+ const stagedFiles = this.staging.getStagedFiles();
65
+ const entries = this.staging.getAllEntries();
66
+ // Build directory structure
67
+ const rootTree = this.buildDirectoryTree(stagedFiles, entries);
68
+ // Recursively write tree objects
69
+ return await this.writeTreeRecursive(rootTree);
70
+ }
71
+ /**
72
+ * Build directory tree structure from flat file list
73
+ */
74
+ buildDirectoryTree(files, entries) {
75
+ const root = { name: '', children: new Map(), files: [] };
76
+ for (const filePath of files) {
77
+ const parts = filePath.split(path_1.default.sep);
78
+ let current = root;
79
+ // Navigate/create directory structure
80
+ for (let i = 0; i < parts.length - 1; i++) {
81
+ const dirName = parts[i];
82
+ if (!current.children.has(dirName)) {
83
+ current.children.set(dirName, {
84
+ name: dirName,
85
+ children: new Map(),
86
+ files: []
87
+ });
88
+ }
89
+ current = current.children.get(dirName);
90
+ }
91
+ // Add file to current directory
92
+ const fileName = parts[parts.length - 1];
93
+ const entry = entries[filePath];
94
+ if (entry && entry.hash) {
95
+ current.files.push({
96
+ name: fileName,
97
+ hash: entry.hash
98
+ });
99
+ }
100
+ }
101
+ return root;
102
+ }
103
+ /**
104
+ * Recursively write tree objects
105
+ */
106
+ async writeTreeRecursive(node) {
107
+ const tree = new tree_1.Tree();
108
+ // Add files to tree
109
+ for (const file of node.files) {
110
+ tree.addEntry('100644', file.name, file.hash);
111
+ }
112
+ // Recursively process subdirectories
113
+ for (const [dirName, childNode] of node.children) {
114
+ const childTreeHash = await this.writeTreeRecursive(childNode);
115
+ tree.addEntry('040000', dirName, childTreeHash);
116
+ }
117
+ // Write tree object
118
+ return await this.storage.writeTree(tree);
119
+ }
120
+ /**
121
+ * Check if commit can be created
122
+ */
123
+ canCommit() {
124
+ return this.staging.hasStagedChanges();
125
+ }
126
+ /**
127
+ * Get commit preview information
128
+ */
129
+ async getCommitPreview() {
130
+ return {
131
+ stagedFiles: this.staging.getStagedFiles(),
132
+ parent: this.refManager.resolveHEAD()
133
+ };
134
+ }
135
+ }
136
+ exports.CommitBuilder = CommitBuilder;
137
+ //# sourceMappingURL=commit-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-builder.js","sourceRoot":"","sources":["../../src/core/commit-builder.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,gDAAwB;AACxB,uCAAwC;AACxC,uCAA0C;AAC1C,iCAAoC;AACpC,iCAA8B;AAC9B,qCAAkC;AASlC,MAAa,aAAa;IAMxB,YAAY,IAAS;QACnB,mDAAmD;QACnD,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACrE,IAAI,CAAC,OAAO,GAAG,IAAI,qBAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;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AAgB,EAAE,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QAIpB,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YAC1C,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE;SACtC,CAAC;IACJ,CAAC;CACF;AAvJD,sCAuJC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Commit Object Implementation
3
+ * Stores snapshot context with metadata
4
+ * Format: commit {size}\0tree {tree_hash}\nparent {parent_hash}\nauthor {author}\ntimestamp {timestamp}\n\n{message}
5
+ */
6
+ import { CommitObject } from '../types';
7
+ export declare class Commit implements CommitObject {
8
+ type: 'commit';
9
+ size: number;
10
+ tree: string;
11
+ parent: string | null;
12
+ author: string;
13
+ timestamp: number;
14
+ message: string;
15
+ constructor(tree: string, message: string, author?: string, parent?: string | null, timestamp?: number);
16
+ /**
17
+ * Calculate size of commit content
18
+ */
19
+ private calculateSize;
20
+ /**
21
+ * Serialize commit content (without header)
22
+ */
23
+ private serializeContent;
24
+ /**
25
+ * Compute SHA-1 hash of this commit
26
+ */
27
+ hash(): string;
28
+ /**
29
+ * Serialize commit to storage format
30
+ * Format: commit {size}\0{content}
31
+ */
32
+ serialize(): Buffer;
33
+ /**
34
+ * Deserialize commit from storage format
35
+ */
36
+ static deserialize(data: Buffer): Commit;
37
+ /**
38
+ * Get commit metadata
39
+ */
40
+ getMetadata(): {
41
+ tree: string;
42
+ parent: string | null;
43
+ author: string;
44
+ timestamp: number;
45
+ message: string;
46
+ hash: string;
47
+ };
48
+ /**
49
+ * Format commit for display
50
+ */
51
+ format(): string;
52
+ }
53
+ //# sourceMappingURL=commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../src/core/commit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,qBAAa,MAAO,YAAW,YAAY;IACzC,IAAI,EAAE,QAAQ,CAAY;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;gBAGd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAA0B,EAClC,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,SAAS,GAAE,MAAmB;IAUhC;;OAEG;IACH,OAAO,CAAC,aAAa;IAKrB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;OAEG;IACH,IAAI,IAAI,MAAM;IAKd;;;OAGG;IACH,SAAS,IAAI,MAAM;IAMnB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAkDxC;;OAEG;IACH,WAAW;;;;;;;;IAWX;;OAEG;IACH,MAAM,IAAI,MAAM;CAIjB"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ /**
3
+ * Commit Object Implementation
4
+ * Stores snapshot context with metadata
5
+ * Format: commit {size}\0tree {tree_hash}\nparent {parent_hash}\nauthor {author}\ntimestamp {timestamp}\n\n{message}
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Commit = void 0;
9
+ const hash_1 = require("../utils/hash");
10
+ class Commit {
11
+ constructor(tree, message, author = 'CraftVault User', parent = null, timestamp = Date.now()) {
12
+ this.type = 'commit';
13
+ this.tree = tree;
14
+ this.parent = parent;
15
+ this.author = author;
16
+ this.timestamp = timestamp;
17
+ this.message = message;
18
+ this.size = this.calculateSize();
19
+ }
20
+ /**
21
+ * Calculate size of commit content
22
+ */
23
+ calculateSize() {
24
+ const content = this.serializeContent();
25
+ return Buffer.byteLength(content);
26
+ }
27
+ /**
28
+ * Serialize commit content (without header)
29
+ */
30
+ serializeContent() {
31
+ const lines = [];
32
+ lines.push(`tree ${this.tree}`);
33
+ if (this.parent) {
34
+ lines.push(`parent ${this.parent}`);
35
+ }
36
+ lines.push(`author ${this.author}`);
37
+ lines.push(`timestamp ${this.timestamp}`);
38
+ lines.push(''); // Empty line before message
39
+ lines.push(this.message);
40
+ return lines.join('\n');
41
+ }
42
+ /**
43
+ * Compute SHA-1 hash of this commit
44
+ */
45
+ hash() {
46
+ const content = this.serializeContent();
47
+ return (0, hash_1.computeObjectHash)(this.type, content);
48
+ }
49
+ /**
50
+ * Serialize commit to storage format
51
+ * Format: commit {size}\0{content}
52
+ */
53
+ serialize() {
54
+ const content = this.serializeContent();
55
+ const header = `${this.type} ${Buffer.byteLength(content)}\0`;
56
+ return Buffer.from(header + content);
57
+ }
58
+ /**
59
+ * Deserialize commit from storage format
60
+ */
61
+ static deserialize(data) {
62
+ // Find null byte separator
63
+ const nullIndex = data.indexOf(0);
64
+ if (nullIndex === -1) {
65
+ throw new Error('Invalid commit format: missing null separator');
66
+ }
67
+ // Extract header
68
+ const header = data.slice(0, nullIndex).toString('utf-8');
69
+ const [type, sizeStr] = header.split(' ');
70
+ if (type !== 'commit') {
71
+ throw new Error(`Invalid object type: expected commit, got ${type}`);
72
+ }
73
+ // Extract content
74
+ const content = data.slice(nullIndex + 1).toString('utf-8');
75
+ const lines = content.split('\n');
76
+ // Parse fields
77
+ let tree = '';
78
+ let parent = null;
79
+ let author = '';
80
+ let timestamp = 0;
81
+ let messageStartIndex = 0;
82
+ for (let i = 0; i < lines.length; i++) {
83
+ const line = lines[i];
84
+ if (line.startsWith('tree ')) {
85
+ tree = line.slice(5);
86
+ }
87
+ else if (line.startsWith('parent ')) {
88
+ parent = line.slice(7);
89
+ }
90
+ else if (line.startsWith('author ')) {
91
+ author = line.slice(7);
92
+ }
93
+ else if (line.startsWith('timestamp ')) {
94
+ timestamp = parseInt(line.slice(10), 10);
95
+ }
96
+ else if (line === '') {
97
+ // Empty line marks start of message
98
+ messageStartIndex = i + 1;
99
+ break;
100
+ }
101
+ }
102
+ // Extract message (everything after empty line)
103
+ const message = lines.slice(messageStartIndex).join('\n');
104
+ return new Commit(tree, message, author, parent, timestamp);
105
+ }
106
+ /**
107
+ * Get commit metadata
108
+ */
109
+ getMetadata() {
110
+ return {
111
+ tree: this.tree,
112
+ parent: this.parent,
113
+ author: this.author,
114
+ timestamp: this.timestamp,
115
+ message: this.message,
116
+ hash: this.hash()
117
+ };
118
+ }
119
+ /**
120
+ * Format commit for display
121
+ */
122
+ format() {
123
+ const date = new Date(this.timestamp).toLocaleString();
124
+ return `commit ${this.hash()}\nAuthor: ${this.author}\nDate: ${date}\n\n ${this.message}\n`;
125
+ }
126
+ }
127
+ exports.Commit = Commit;
128
+ //# sourceMappingURL=commit.js.map