pushwork 1.2.2 → 1.2.3

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 (35) hide show
  1. package/dist/cli/commands.d.ts +71 -0
  2. package/dist/cli/commands.d.ts.map +1 -0
  3. package/dist/cli/commands.js +794 -0
  4. package/dist/cli/commands.js.map +1 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +19 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/cli.js +0 -0
  10. package/dist/config/index.d.ts +71 -0
  11. package/dist/config/index.d.ts.map +1 -0
  12. package/dist/config/index.js +314 -0
  13. package/dist/config/index.js.map +1 -0
  14. package/dist/utils/content-similarity.d.ts +53 -0
  15. package/dist/utils/content-similarity.d.ts.map +1 -0
  16. package/dist/utils/content-similarity.js +155 -0
  17. package/dist/utils/content-similarity.js.map +1 -0
  18. package/dist/utils/node-polyfills.d.ts +9 -0
  19. package/dist/utils/node-polyfills.d.ts.map +1 -0
  20. package/dist/utils/node-polyfills.js +9 -0
  21. package/dist/utils/node-polyfills.js.map +1 -0
  22. package/dist/utils/repo-factory.d.ts.map +1 -1
  23. package/dist/utils/repo-factory.js +1 -0
  24. package/dist/utils/repo-factory.js.map +1 -1
  25. package/package.json +96 -98
  26. package/scripts/roundtrip-test.sh +0 -0
  27. package/src/utils/repo-factory.ts +85 -78
  28. package/test/integration/clone-test.sh +0 -0
  29. package/test/integration/conflict-resolution-test.sh +0 -0
  30. package/test/integration/deletion-behavior-test.sh +0 -0
  31. package/test/integration/deletion-sync-test-simple.sh +0 -0
  32. package/test/integration/deletion-sync-test.sh +0 -0
  33. package/test/integration/full-integration-test.sh +0 -0
  34. package/test/integration/manual-sync-test.sh +0 -0
  35. package/test/run-tests.sh +0 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentSimilarity = void 0;
4
+ const fs_1 = require("./fs");
5
+ /**
6
+ * Content similarity calculation for move detection
7
+ */
8
+ class ContentSimilarity {
9
+ /**
10
+ * Calculate similarity between two content pieces
11
+ */
12
+ static async calculateSimilarity(content1, content2) {
13
+ // Quick early exit for identical content
14
+ if (await this.areIdentical(content1, content2)) {
15
+ return 1.0;
16
+ }
17
+ // Size-based quick rejection
18
+ const size1 = typeof content1 === "string" ? content1.length : content1.length;
19
+ const size2 = typeof content2 === "string" ? content2.length : content2.length;
20
+ const sizeDiff = Math.abs(size1 - size2) / Math.max(size1, size2);
21
+ if (sizeDiff > 0.5) {
22
+ return 0.0; // Too different in size
23
+ }
24
+ // For small files, use full content comparison
25
+ if (size1 < this.CHUNK_SIZE * 4 && size2 < this.CHUNK_SIZE * 4) {
26
+ return this.calculateFullSimilarity(content1, content2);
27
+ }
28
+ // For large files, use sampling
29
+ return this.calculateSampledSimilarity(content1, content2);
30
+ }
31
+ /**
32
+ * Check if two content pieces are identical
33
+ */
34
+ static async areIdentical(content1, content2) {
35
+ const hash1 = await (0, fs_1.calculateContentHash)(content1);
36
+ const hash2 = await (0, fs_1.calculateContentHash)(content2);
37
+ return hash1 === hash2;
38
+ }
39
+ /**
40
+ * Calculate similarity for small files using full content
41
+ */
42
+ static calculateFullSimilarity(content1, content2) {
43
+ const str1 = typeof content1 === "string" ? content1 : this.bufferToString(content1);
44
+ const str2 = typeof content2 === "string" ? content2 : this.bufferToString(content2);
45
+ return this.levenshteinSimilarity(str1, str2);
46
+ }
47
+ /**
48
+ * Calculate similarity for large files using sampling
49
+ */
50
+ static calculateSampledSimilarity(content1, content2) {
51
+ const samples1 = this.getSamples(content1);
52
+ const samples2 = this.getSamples(content2);
53
+ let totalSimilarity = 0;
54
+ let comparisons = 0;
55
+ for (let i = 0; i < Math.min(samples1.length, samples2.length); i++) {
56
+ totalSimilarity += this.levenshteinSimilarity(samples1[i], samples2[i]);
57
+ comparisons++;
58
+ }
59
+ return comparisons > 0 ? totalSimilarity / comparisons : 0;
60
+ }
61
+ /**
62
+ * Get representative samples from content
63
+ */
64
+ static getSamples(content) {
65
+ const str = typeof content === "string" ? content : this.bufferToString(content);
66
+ const length = str.length;
67
+ const samples = [];
68
+ if (length <= this.CHUNK_SIZE) {
69
+ samples.push(str);
70
+ return samples;
71
+ }
72
+ // Beginning
73
+ samples.push(str.slice(0, this.CHUNK_SIZE));
74
+ // Middle
75
+ const midStart = Math.floor(length / 2) - Math.floor(this.CHUNK_SIZE / 2);
76
+ samples.push(str.slice(midStart, midStart + this.CHUNK_SIZE));
77
+ // End
78
+ samples.push(str.slice(-this.CHUNK_SIZE));
79
+ return samples;
80
+ }
81
+ /**
82
+ * Calculate Levenshtein similarity (0-1 scale)
83
+ */
84
+ static levenshteinSimilarity(str1, str2) {
85
+ if (str1 === str2)
86
+ return 1.0;
87
+ if (str1.length === 0 || str2.length === 0)
88
+ return 0.0;
89
+ const distance = this.levenshteinDistance(str1, str2);
90
+ const maxLength = Math.max(str1.length, str2.length);
91
+ return 1 - distance / maxLength;
92
+ }
93
+ /**
94
+ * Calculate Levenshtein distance
95
+ */
96
+ static levenshteinDistance(str1, str2) {
97
+ const matrix = Array(str2.length + 1)
98
+ .fill(null)
99
+ .map(() => Array(str1.length + 1).fill(null));
100
+ for (let i = 0; i <= str1.length; i++)
101
+ matrix[0][i] = i;
102
+ for (let j = 0; j <= str2.length; j++)
103
+ matrix[j][0] = j;
104
+ for (let j = 1; j <= str2.length; j++) {
105
+ for (let i = 1; i <= str1.length; i++) {
106
+ const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
107
+ matrix[j][i] = Math.min(matrix[j][i - 1] + 1, // deletion
108
+ matrix[j - 1][i] + 1, // insertion
109
+ matrix[j - 1][i - 1] + indicator // substitution
110
+ );
111
+ }
112
+ }
113
+ return matrix[str2.length][str1.length];
114
+ }
115
+ /**
116
+ * Convert buffer to string for comparison
117
+ */
118
+ static bufferToString(buffer) {
119
+ // For binary content, use hex representation for comparison
120
+ return Array.from(buffer)
121
+ .map((b) => b.toString(16).padStart(2, "0"))
122
+ .join("");
123
+ }
124
+ /**
125
+ * Determine confidence level based on similarity score
126
+ */
127
+ static getConfidenceLevel(similarity) {
128
+ if (similarity >= this.AUTO_THRESHOLD) {
129
+ return "auto";
130
+ }
131
+ else if (similarity >= this.PROMPT_THRESHOLD) {
132
+ return "prompt";
133
+ }
134
+ else {
135
+ return "low";
136
+ }
137
+ }
138
+ /**
139
+ * Should auto-apply move based on similarity
140
+ */
141
+ static shouldAutoApply(similarity) {
142
+ return similarity >= this.AUTO_THRESHOLD;
143
+ }
144
+ /**
145
+ * Should prompt user for move confirmation
146
+ */
147
+ static shouldPromptUser(similarity) {
148
+ return (similarity >= this.PROMPT_THRESHOLD && similarity < this.AUTO_THRESHOLD);
149
+ }
150
+ }
151
+ exports.ContentSimilarity = ContentSimilarity;
152
+ ContentSimilarity.CHUNK_SIZE = 1024; // 1KB chunks for sampling
153
+ ContentSimilarity.AUTO_THRESHOLD = 0.8;
154
+ ContentSimilarity.PROMPT_THRESHOLD = 0.5;
155
+ //# sourceMappingURL=content-similarity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-similarity.js","sourceRoot":"","sources":["../../src/utils/content-similarity.ts"],"names":[],"mappings":";;;AAAA,6BAA4C;AAE5C;;GAEG;AACH,MAAa,iBAAiB;IAK5B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAC9B,QAA6B,EAC7B,QAA6B;QAE7B,yCAAyC;QACzC,IAAI,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC;YAChD,OAAO,GAAG,CAAC;QACb,CAAC;QAED,6BAA6B;QAC7B,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnE,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,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AO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;aACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;aAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,UAAkB;QAC1C,IAAI,UAAU,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtC,OAAO,MAAM,CAAC;QAChB,CAAC;aAAM,IAAI,UAAU,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC/C,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,UAAkB;QACvC,OAAO,UAAU,IAAI,IAAI,CAAC,cAAc,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,UAAkB;QACxC,OAAO,CACL,UAAU,IAAI,IAAI,CAAC,gBAAgB,IAAI,UAAU,GAAG,IAAI,CAAC,cAAc,CACxE,CAAC;IACJ,CAAC;;AA3LH,8CA4LC;AA3LyB,4BAAU,GAAG,IAAI,CAAC,CAAC,0BAA0B;AAC7C,gCAAc,GAAG,GAAG,CAAC;AACrB,kCAAgB,GAAG,GAAG,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Polyfills for browser APIs required by @automerge/automerge-subduction.
3
+ * Must be imported before any subduction code.
4
+ *
5
+ * The Subduction WASM module uses IndexedDB for key persistence
6
+ * (via WebCryptoSigner). In Node.js we provide a fake-indexeddb polyfill.
7
+ */
8
+ import "fake-indexeddb/auto";
9
+ //# sourceMappingURL=node-polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-polyfills.d.ts","sourceRoot":"","sources":["../../src/utils/node-polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,qBAAqB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Polyfills for browser APIs required by @automerge/automerge-subduction.
3
+ * Must be imported before any subduction code.
4
+ *
5
+ * The Subduction WASM module uses IndexedDB for key persistence
6
+ * (via WebCryptoSigner). In Node.js we provide a fake-indexeddb polyfill.
7
+ */
8
+ import "fake-indexeddb/auto";
9
+ //# sourceMappingURL=node-polyfills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-polyfills.js","sourceRoot":"","sources":["../../src/utils/node-polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"repo-factory.d.ts","sourceRoot":"","sources":["../../src/utils/repo-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAiD,MAAM,2BAA2B,CAAC;AAIrG,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AA0E3C;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,EACvB,GAAG,GAAE,OAAe,GACnB,OAAO,CAAC,IAAI,CAAC,CAgDf"}
1
+ {"version":3,"file":"repo-factory.d.ts","sourceRoot":"","sources":["../../src/utils/repo-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,IAAI,EAGT,MAAM,2BAA2B,CAAA;AAIlC,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAA;AA0ExC;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC/B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,EACvB,GAAG,GAAE,OAAe,GAClB,OAAO,CAAC,IAAI,CAAC,CAmDf"}
@@ -137,6 +137,7 @@ async function createRepo(workingDir, config, sub = false) {
137
137
  }
138
138
  return new RepoClass({
139
139
  storage,
140
+ // @ts-expect-error i don't know why
140
141
  subductionWebsocketEndpoints: endpoints,
141
142
  });
142
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"repo-factory.js","sourceRoot":"","sources":["../../src/utils/repo-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,gCAoDC;AA5ID,4FAAgF;AAChF,gDAAkC;AAClC,2CAA6B;AAG7B;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAEzD,CAAC;AAElB;;;;;;;;;;;GAWG;AACH,IAAI,eAAwC,CAAC;AAE7C,KAAK,UAAU,YAAY;IACzB,IAAI,eAAe;QAAE,OAAO,eAAe,CAAC;IAE5C,kEAAkE;IAClE,sEAAsE;IACtE,uEAAuE;IACvE,6CAA6C;IAC7C,EAAE;IACF,oEAAoE;IACpE,0DAA0D;IAC1D,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,2BAA2B,CAAC,CAAC;IACjE,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;IAC/B,eAAe,GAAG,OAAO,CAAC,IAAmB,CAAC;IAC9C,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,iBAAiB,CAAC,GAAW;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,WAAW,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CAAA;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,99 +1,97 @@
1
1
  {
2
- "name": "pushwork",
3
- "version": "1.2.2",
4
- "description": "Bidirectional directory synchronization using Automerge CRDTs",
5
- "main": "dist/index.js",
6
- "exports": {
7
- ".": "./dist/index.js"
8
- },
9
- "bin": {
10
- "pushwork": "./dist/cli.js"
11
- },
12
- "scripts": {
13
- "build": "tsc",
14
- "dev": "tsc --watch",
15
- "test": "jest",
16
- "test:bail": "jest --bail",
17
- "test:watch": "jest --watch",
18
- "test:coverage": "jest --coverage",
19
- "lint": "eslint src --ext .ts",
20
- "lint:fix": "eslint src --ext .ts --fix",
21
- "clean": "rm -rf dist",
22
- "prepack": "pnpm run build",
23
- "start": "node dist/cli.js",
24
- "typecheck": "tsc --noEmit"
25
- },
26
- "packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
27
- "engines": {
28
- "node": ">=24.0.0",
29
- "pnpm": ">=8.0.0"
30
- },
31
- "keywords": [
32
- "automerge",
33
- "sync",
34
- "crdt",
35
- "collaboration",
36
- "filesystem"
37
- ],
38
- "author": "Peter van Hardenberg",
39
- "license": "MIT",
40
- "dependencies": {
41
- "@automerge/automerge": "^3.2.5",
42
- "@automerge/automerge-repo": "2.6.0-subduction.14",
43
- "@automerge/automerge-repo-network-websocket": "2.6.0-subduction.14",
44
- "@automerge/automerge-repo-storage-nodefs": "2.6.0-subduction.14",
45
- "@automerge/automerge-subduction": "0.7.0",
46
- "@commander-js/extra-typings": "^14.0.0",
47
- "chalk": "^5.3.0",
48
- "commander": "^14.0.2",
49
- "diff": "^8.0.2",
50
- "glob": "^10.3.0",
51
- "ignore": "^5.3.0",
52
- "mime-types": "^2.1.35",
53
- "ora": "^7.0.1"
54
- },
55
- "devDependencies": {
56
- "@babel/core": "^7.28.6",
57
- "@babel/preset-env": "^7.28.6",
58
- "@types/diff": "^5.0.3",
59
- "@types/jest": "^29.5.0",
60
- "@types/mime-types": "^2.1.1",
61
- "@types/node": "^20.0.0",
62
- "@types/tmp": "^0.2.4",
63
- "babel-jest": "^30.2.0",
64
- "fast-check": "^4.3.0",
65
- "jest": "^29.7.0",
66
- "tmp": "^0.2.1",
67
- "ts-jest": "^29.1.0",
68
- "tsx": "^4.19.2",
69
- "typescript": "^5.2.0"
70
- },
71
- "jest": {
72
- "preset": "ts-jest",
73
- "testEnvironment": "node",
74
- "roots": [
75
- "<rootDir>/src",
76
- "<rootDir>/test"
77
- ],
78
- "testMatch": [
79
- "**/__tests__/**/*.ts",
80
- "**/*.(test|spec).ts"
81
- ],
82
- "collectCoverageFrom": [
83
- "src/**/*.ts",
84
- "!src/**/*.d.ts"
85
- ],
86
- "setupFilesAfterEnv": [
87
- "<rootDir>/test/jest.setup.ts"
88
- ],
89
- "maxWorkers": "75%",
90
- "maxConcurrency": 10,
91
- "transformIgnorePatterns": [
92
- "node_modules/(?!.*@automerge)"
93
- ],
94
- "transform": {
95
- "^.+\\.tsx?$": "ts-jest",
96
- "^.+\\.jsx?$": "babel-jest"
97
- }
98
- }
99
- }
2
+ "name": "pushwork",
3
+ "version": "1.2.3",
4
+ "description": "Bidirectional directory synchronization using Automerge CRDTs",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": "./dist/index.js"
8
+ },
9
+ "bin": {
10
+ "pushwork": "./dist/cli.js"
11
+ },
12
+ "engines": {
13
+ "node": ">=24.0.0",
14
+ "pnpm": ">=8.0.0"
15
+ },
16
+ "keywords": [
17
+ "automerge",
18
+ "sync",
19
+ "crdt",
20
+ "collaboration",
21
+ "filesystem"
22
+ ],
23
+ "author": "Peter van Hardenberg",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "@automerge/automerge": "^3.2.6",
27
+ "@automerge/automerge-repo": "2.6.0-subduction.15",
28
+ "@automerge/automerge-repo-network-websocket": "2.6.0-subduction.15",
29
+ "@automerge/automerge-repo-storage-nodefs": "2.6.0-subduction.15",
30
+ "@automerge/automerge-subduction": "0.8.1",
31
+ "@commander-js/extra-typings": "^14.0.0",
32
+ "chalk": "^5.3.0",
33
+ "commander": "^14.0.2",
34
+ "diff": "^8.0.2",
35
+ "glob": "^10.3.0",
36
+ "ignore": "^5.3.0",
37
+ "mime-types": "^2.1.35",
38
+ "ora": "^7.0.1"
39
+ },
40
+ "devDependencies": {
41
+ "@babel/core": "^7.28.6",
42
+ "@babel/preset-env": "^7.28.6",
43
+ "@types/diff": "^5.0.3",
44
+ "@types/jest": "^29.5.0",
45
+ "@types/mime-types": "^2.1.1",
46
+ "@types/node": "^20.0.0",
47
+ "@types/tmp": "^0.2.4",
48
+ "babel-jest": "^30.2.0",
49
+ "fast-check": "^4.3.0",
50
+ "jest": "^29.7.0",
51
+ "tmp": "^0.2.1",
52
+ "ts-jest": "^29.1.0",
53
+ "tsx": "^4.19.2",
54
+ "typescript": "^5.2.0"
55
+ },
56
+ "jest": {
57
+ "preset": "ts-jest",
58
+ "testEnvironment": "node",
59
+ "roots": [
60
+ "<rootDir>/src",
61
+ "<rootDir>/test"
62
+ ],
63
+ "testMatch": [
64
+ "**/__tests__/**/*.ts",
65
+ "**/*.(test|spec).ts"
66
+ ],
67
+ "collectCoverageFrom": [
68
+ "src/**/*.ts",
69
+ "!src/**/*.d.ts"
70
+ ],
71
+ "setupFilesAfterEnv": [
72
+ "<rootDir>/test/jest.setup.ts"
73
+ ],
74
+ "maxWorkers": "75%",
75
+ "maxConcurrency": 10,
76
+ "transformIgnorePatterns": [
77
+ "node_modules/(?!.*@automerge)"
78
+ ],
79
+ "transform": {
80
+ "^.+\\.tsx?$": "ts-jest",
81
+ "^.+\\.jsx?$": "babel-jest"
82
+ }
83
+ },
84
+ "scripts": {
85
+ "build": "tsc",
86
+ "dev": "tsc --watch",
87
+ "test": "jest",
88
+ "test:bail": "jest --bail",
89
+ "test:watch": "jest --watch",
90
+ "test:coverage": "jest --coverage",
91
+ "lint": "eslint src --ext .ts",
92
+ "lint:fix": "eslint src --ext .ts --fix",
93
+ "clean": "rm -rf dist",
94
+ "start": "node dist/cli.js",
95
+ "typecheck": "tsc --noEmit"
96
+ }
97
+ }
File without changes
@@ -1,8 +1,12 @@
1
- import { type Repo, type RepoConfig, type NetworkAdapterInterface } from "@automerge/automerge-repo";
2
- import { NodeFSStorageAdapter } from "@automerge/automerge-repo-storage-nodefs";
3
- import * as fs from "fs/promises";
4
- import * as path from "path";
5
- import { DirectoryConfig } from "../types";
1
+ import {
2
+ type Repo,
3
+ type RepoConfig,
4
+ type NetworkAdapterInterface,
5
+ } from "@automerge/automerge-repo"
6
+ import {NodeFSStorageAdapter} from "@automerge/automerge-repo-storage-nodefs"
7
+ import * as fs from "fs/promises"
8
+ import * as path from "path"
9
+ import {DirectoryConfig} from "../types"
6
10
 
7
11
  /**
8
12
  * Perform a real ESM dynamic import that tsc won't rewrite to require().
@@ -18,8 +22,8 @@ import { DirectoryConfig } from "../types";
18
22
  * Repo's internal imports.
19
23
  */
20
24
  const dynamicImport = new Function("specifier", "return import(specifier)") as (
21
- specifier: string,
22
- ) => Promise<any>;
25
+ specifier: string
26
+ ) => Promise<any>
23
27
 
24
28
  /**
25
29
  * Initialize the Subduction Wasm module and return the Repo constructor.
@@ -33,22 +37,22 @@ const dynamicImport = new Function("specifier", "return import(specifier)") as (
33
37
  * Both the Repo and initSubduction must be loaded via ESM dynamic import()
34
38
  * so they share the same module graph as the Repo's internal /slim imports.
35
39
  */
36
- let cachedRepoClass: typeof Repo | undefined;
40
+ let cachedRepoClass: typeof Repo | undefined
37
41
 
38
42
  async function getRepoClass(): Promise<typeof Repo> {
39
- if (cachedRepoClass) return cachedRepoClass;
43
+ if (cachedRepoClass) return cachedRepoClass
40
44
 
41
- // Import Repo and initialize Subduction Wasm via automerge-repo's
42
- // initSubduction() helper. This must happen before new Repo() because
43
- // the constructor calls set_subduction_logger() and new MemorySigner()
44
- // which require the Wasm module to be ready.
45
- //
46
- // Both imports use the ESM dynamic import wrapper so they share the
47
- // same module graph as the Repo's internal /slim imports.
48
- const repoMod = await dynamicImport("@automerge/automerge-repo");
49
- await repoMod.initSubduction();
50
- cachedRepoClass = repoMod.Repo as typeof Repo;
51
- return cachedRepoClass;
45
+ // Import Repo and initialize Subduction Wasm via automerge-repo's
46
+ // initSubduction() helper. This must happen before new Repo() because
47
+ // the constructor calls set_subduction_logger() and new MemorySigner()
48
+ // which require the Wasm module to be ready.
49
+ //
50
+ // Both imports use the ESM dynamic import wrapper so they share the
51
+ // same module graph as the Repo's internal /slim imports.
52
+ const repoMod = await dynamicImport("@automerge/automerge-repo")
53
+ await repoMod.initSubduction()
54
+ cachedRepoClass = repoMod.Repo as typeof Repo
55
+ return cachedRepoClass
52
56
  }
53
57
 
54
58
  /**
@@ -57,23 +61,23 @@ async function getRepoClass(): Promise<typeof Repo> {
57
61
  * if any are found.
58
62
  */
59
63
  async function hasCorruptStorage(dir: string): Promise<boolean> {
60
- try {
61
- await fs.access(dir);
62
- } catch {
63
- return false;
64
- }
64
+ try {
65
+ await fs.access(dir)
66
+ } catch {
67
+ return false
68
+ }
65
69
 
66
- const entries = await fs.readdir(dir, { withFileTypes: true });
67
- for (const entry of entries) {
68
- const fullPath = path.join(dir, entry.name);
69
- if (entry.isDirectory()) {
70
- if (await hasCorruptStorage(fullPath)) return true;
71
- } else if (entry.isFile()) {
72
- const stat = await fs.stat(fullPath);
73
- if (stat.size === 0) return true;
74
- }
75
- }
76
- return false;
70
+ const entries = await fs.readdir(dir, {withFileTypes: true})
71
+ for (const entry of entries) {
72
+ const fullPath = path.join(dir, entry.name)
73
+ if (entry.isDirectory()) {
74
+ if (await hasCorruptStorage(fullPath)) return true
75
+ } else if (entry.isFile()) {
76
+ const stat = await fs.stat(fullPath)
77
+ if (stat.size === 0) return true
78
+ }
79
+ }
80
+ return false
77
81
  }
78
82
 
79
83
  /**
@@ -88,55 +92,58 @@ async function hasCorruptStorage(dir: string): Promise<boolean> {
88
92
  * adapter for sync via the automerge sync server.
89
93
  */
90
94
  export async function createRepo(
91
- workingDir: string,
92
- config: DirectoryConfig,
93
- sub: boolean = false
95
+ workingDir: string,
96
+ config: DirectoryConfig,
97
+ sub: boolean = false
94
98
  ): Promise<Repo> {
95
- const RepoClass = await getRepoClass();
99
+ const RepoClass = await getRepoClass()
96
100
 
97
- const syncToolDir = path.join(workingDir, ".pushwork");
98
- const automergeDir = path.join(syncToolDir, "automerge");
101
+ const syncToolDir = path.join(workingDir, ".pushwork")
102
+ const automergeDir = path.join(syncToolDir, "automerge")
99
103
 
100
- // Detect and recover from corrupt local storage (0-byte files left by
101
- // incomplete writes from a previous run). Wipe the cache so the Repo
102
- // hydrates cleanly from the sync server.
103
- if (await hasCorruptStorage(automergeDir)) {
104
- console.warn("[pushwork] Corrupt local storage detected, clearing cache...");
105
- await fs.rm(automergeDir, { recursive: true, force: true });
106
- await fs.mkdir(automergeDir, { recursive: true });
107
- }
104
+ // Detect and recover from corrupt local storage (0-byte files left by
105
+ // incomplete writes from a previous run). Wipe the cache so the Repo
106
+ // hydrates cleanly from the sync server.
107
+ if (await hasCorruptStorage(automergeDir)) {
108
+ console.warn("[pushwork] Corrupt local storage detected, clearing cache...")
109
+ await fs.rm(automergeDir, {recursive: true, force: true})
110
+ await fs.mkdir(automergeDir, {recursive: true})
111
+ }
108
112
 
109
- const storage = new NodeFSStorageAdapter(automergeDir);
113
+ const storage = new NodeFSStorageAdapter(automergeDir)
110
114
 
111
- if (sub) {
112
- const endpoints: string[] = [];
113
- if (config.sync_enabled && config.sync_server) {
114
- endpoints.push(config.sync_server);
115
- }
115
+ if (sub) {
116
+ const endpoints: string[] = []
117
+ if (config.sync_enabled && config.sync_server) {
118
+ endpoints.push(config.sync_server)
119
+ }
116
120
 
117
- return new RepoClass({
118
- storage,
119
- subductionWebsocketEndpoints: endpoints,
120
- });
121
- }
121
+ return new RepoClass({
122
+ storage,
123
+ // @ts-expect-error i don't know why
124
+ subductionWebsocketEndpoints: endpoints,
125
+ })
126
+ }
122
127
 
123
- // Default: WebSocket sync adapter
124
- const repoConfig: RepoConfig = { storage };
128
+ // Default: WebSocket sync adapter
129
+ const repoConfig: RepoConfig = {storage}
125
130
 
126
- if (config.sync_enabled && config.sync_server) {
127
- // Load the WebSocket adapter via ESM dynamic import to stay in the
128
- // same module graph as the Repo.
129
- const wsMod = await dynamicImport("@automerge/automerge-repo-network-websocket");
130
- // The websocket adapter package (subduction.8) hasn't updated its
131
- // NetworkAdapter base-class types to match the repo's new
132
- // NetworkAdapterInterface (which added state() and stricter
133
- // EventEmitter generics). At runtime the adapter has all required
134
- // methods; this is purely a declaration mismatch.
135
- const networkAdapter = new wsMod.BrowserWebSocketClientAdapter(
136
- config.sync_server
137
- ) as unknown as NetworkAdapterInterface;
138
- repoConfig.network = [networkAdapter];
139
- }
131
+ if (config.sync_enabled && config.sync_server) {
132
+ // Load the WebSocket adapter via ESM dynamic import to stay in the
133
+ // same module graph as the Repo.
134
+ const wsMod = await dynamicImport(
135
+ "@automerge/automerge-repo-network-websocket"
136
+ )
137
+ // The websocket adapter package (subduction.8) hasn't updated its
138
+ // NetworkAdapter base-class types to match the repo's new
139
+ // NetworkAdapterInterface (which added state() and stricter
140
+ // EventEmitter generics). At runtime the adapter has all required
141
+ // methods; this is purely a declaration mismatch.
142
+ const networkAdapter = new wsMod.BrowserWebSocketClientAdapter(
143
+ config.sync_server
144
+ ) as unknown as NetworkAdapterInterface
145
+ repoConfig.network = [networkAdapter]
146
+ }
140
147
 
141
- return new RepoClass(repoConfig);
148
+ return new RepoClass(repoConfig)
142
149
  }
File without changes
File without changes