@mod-computer/cli 0.1.1 → 0.2.2

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 (55) hide show
  1. package/README.md +98 -76
  2. package/dist/cli.bundle.js +23750 -12931
  3. package/dist/cli.bundle.js.map +4 -4
  4. package/dist/cli.js +23 -12
  5. package/dist/commands/add.js +245 -0
  6. package/dist/commands/auth.js +129 -21
  7. package/dist/commands/comment.js +568 -0
  8. package/dist/commands/diff.js +182 -0
  9. package/dist/commands/index.js +33 -3
  10. package/dist/commands/init.js +475 -221
  11. package/dist/commands/ls.js +135 -0
  12. package/dist/commands/members.js +687 -0
  13. package/dist/commands/mv.js +282 -0
  14. package/dist/commands/rm.js +257 -0
  15. package/dist/commands/status.js +273 -306
  16. package/dist/commands/sync.js +99 -75
  17. package/dist/commands/trace.js +1752 -0
  18. package/dist/commands/workspace.js +354 -330
  19. package/dist/config/features.js +18 -7
  20. package/dist/config/release-profiles/development.json +4 -1
  21. package/dist/config/release-profiles/mvp.json +4 -2
  22. package/dist/daemon/conflict-resolution.js +172 -0
  23. package/dist/daemon/content-hash.js +31 -0
  24. package/dist/daemon/file-sync.js +985 -0
  25. package/dist/daemon/index.js +203 -0
  26. package/dist/daemon/mime-types.js +166 -0
  27. package/dist/daemon/offline-queue.js +211 -0
  28. package/dist/daemon/path-utils.js +64 -0
  29. package/dist/daemon/share-policy.js +83 -0
  30. package/dist/daemon/wasm-errors.js +189 -0
  31. package/dist/daemon/worker.js +557 -0
  32. package/dist/daemon-worker.js +3 -2
  33. package/dist/errors/workspace-errors.js +48 -0
  34. package/dist/lib/auth-server.js +89 -26
  35. package/dist/lib/browser.js +1 -1
  36. package/dist/lib/diff.js +284 -0
  37. package/dist/lib/formatters.js +204 -0
  38. package/dist/lib/git.js +137 -0
  39. package/dist/lib/local-fs.js +201 -0
  40. package/dist/lib/prompts.js +23 -83
  41. package/dist/lib/storage.js +11 -1
  42. package/dist/lib/trace-formatters.js +314 -0
  43. package/dist/services/add-service.js +554 -0
  44. package/dist/services/add-validation.js +124 -0
  45. package/dist/services/mod-config.js +8 -2
  46. package/dist/services/modignore-service.js +2 -0
  47. package/dist/stores/use-workspaces-store.js +36 -14
  48. package/dist/types/add-types.js +99 -0
  49. package/dist/types/config.js +1 -1
  50. package/dist/types/workspace-connection.js +53 -2
  51. package/package.json +7 -5
  52. package/commands/execute.md +0 -156
  53. package/commands/overview.md +0 -233
  54. package/commands/review.md +0 -151
  55. package/commands/spec.md +0 -169
@@ -0,0 +1,83 @@
1
+ // glassware[type="implementation", id="impl-cli-share-policy--044307eb", specifications="specification-spec-no-permissive-bootstrap--2fc35117,specification-spec-strict-allowlist--44f56951,specification-spec-user-doc-init--f355cebf,specification-spec-workspace-allowlist--e668c367,specification-spec-file-allowlist--1bf67504,specification-spec-folder-allowlist--1cc8923c,specification-spec-cleanup-allowlist--9f816ed3,specification-spec-export-share-policy--4371539e,specification-spec-export-workspace-connect--431e5527"]
2
+ /**
3
+ * CLI SharePolicy - strict allowlist approach (aligned with mod-app-new browser).
4
+ * NO permissive bootstrap - all documents must be explicitly added to allowlist.
5
+ * Prevents CLI from accumulating docs from all workspaces.
6
+ */
7
+ // Set of document IDs we're allowed to sync
8
+ const allowedDocs = new Set();
9
+ // Track logged denials (one log per doc)
10
+ const deniedLogged = new Set();
11
+ /**
12
+ * SharePolicy for CLI: strict allowlist, NO permissive bootstrap.
13
+ * Only sync docs explicitly added to allowedDocs set.
14
+ */
15
+ export const cliSharePolicy = async (_peerId, documentId) => {
16
+ if (!documentId)
17
+ return false;
18
+ // STRICT: Only allow documents explicitly in allowlist
19
+ // NO permissive bootstrap (aligned with mod-app-new browser approach)
20
+ const allowed = allowedDocs.has(documentId);
21
+ if (!allowed && !deniedLogged.has(documentId)) {
22
+ deniedLogged.add(documentId);
23
+ // Debug log removed - not user-facing
24
+ }
25
+ return allowed;
26
+ };
27
+ /**
28
+ * Add user document to allowlist on authentication.
29
+ * Call during auth flow, BEFORE repo operations.
30
+ */
31
+ export function addUserToSharePolicy(userDocId) {
32
+ allowedDocs.add(userDocId);
33
+ }
34
+ /**
35
+ * Add workspace to allowlist when connecting.
36
+ * Call BEFORE repo.find(workspaceId).
37
+ */
38
+ export function addWorkspaceToSharePolicy(workspaceId) {
39
+ allowedDocs.add(workspaceId);
40
+ }
41
+ /**
42
+ * Add a single file document to the sharePolicy.
43
+ * Call when a file is tracked for sync.
44
+ */
45
+ export function addFileToSharePolicy(fileId) {
46
+ allowedDocs.add(fileId);
47
+ }
48
+ /**
49
+ * Add multiple file/folder documents to the sharePolicy.
50
+ * Call BEFORE loading file documents.
51
+ */
52
+ export function addFilesToSharePolicy(fileIds) {
53
+ fileIds.forEach(id => allowedDocs.add(id));
54
+ }
55
+ /**
56
+ * Remove a single file document from the sharePolicy.
57
+ * Call when a file is deleted.
58
+ */
59
+ export function removeFileFromSharePolicy(fileId) {
60
+ allowedDocs.delete(fileId);
61
+ }
62
+ /**
63
+ * Remove workspace and all associated documents from allowlist.
64
+ * Call when disconnecting from a workspace.
65
+ */
66
+ export function removeWorkspaceFromSharePolicy(workspaceId, fileIds, folderIds) {
67
+ allowedDocs.delete(workspaceId);
68
+ fileIds.forEach(id => allowedDocs.delete(id));
69
+ folderIds.forEach(id => allowedDocs.delete(id));
70
+ }
71
+ /**
72
+ * Get count of allowed docs (for debugging/testing).
73
+ */
74
+ export function getSharePolicyDocCount() {
75
+ return allowedDocs.size;
76
+ }
77
+ /**
78
+ * Reset sharePolicy state (for testing).
79
+ */
80
+ export function resetSharePolicyState() {
81
+ allowedDocs.clear();
82
+ deniedLogged.clear();
83
+ }
@@ -0,0 +1,189 @@
1
+ // glassware[type="implementation", id="impl-wasm-errors--8c42ad5f", requirements="requirement-cli-sync-wasm-detect--5517bb61,requirement-cli-sync-wasm-recover--ca8c0cb6"]
2
+ /**
3
+ * WASM error handling utilities for Automerge operations.
4
+ * Detects WASM panics and provides graceful error recovery.
5
+ */
6
+ /**
7
+ * Patterns that indicate a WASM panic error.
8
+ */
9
+ const WASM_ERROR_PATTERNS = [
10
+ 'panic',
11
+ 'recursive use of an object',
12
+ 'unsafe aliasing',
13
+ 'RuntimeError',
14
+ 'unreachable',
15
+ 'memory access out of bounds',
16
+ 'table index is out of bounds',
17
+ 'indirect call signature mismatch',
18
+ ];
19
+ /**
20
+ * Check if an error is a WASM panic error.
21
+ * @param err - The error to check
22
+ * @returns true if the error is a WASM panic
23
+ */
24
+ export function isWasmError(err) {
25
+ if (!err)
26
+ return false;
27
+ const message = String(err?.message || err || '');
28
+ const name = String(err?.name || '');
29
+ const stack = String(err?.stack || '');
30
+ const combined = `${name} ${message} ${stack}`.toLowerCase();
31
+ return WASM_ERROR_PATTERNS.some(pattern => combined.includes(pattern.toLowerCase()));
32
+ }
33
+ /**
34
+ * Log a WASM error with document context.
35
+ * @param documentId - The document ID that caused the error
36
+ * @param err - The error that occurred
37
+ */
38
+ export function logWasmError(documentId, err) {
39
+ const timestamp = new Date().toISOString();
40
+ const message = err?.message || String(err);
41
+ const stack = err?.stack || '';
42
+ console.error(`[WASM] ${timestamp} Error in document ${documentId}:`, message);
43
+ if (stack) {
44
+ console.error(`[WASM] Stack:`, stack);
45
+ }
46
+ }
47
+ /**
48
+ * WasmErrorRecovery - manages retry logic for WASM errors.
49
+ */
50
+ export class WasmErrorRecovery {
51
+ constructor(options = {}) {
52
+ this.retryQueue = new Map();
53
+ this.processInterval = null;
54
+ this.maxRetries = options.maxRetries ?? 3;
55
+ this.baseDelayMs = options.baseDelayMs ?? 100;
56
+ this.log = options.logger ?? console.log;
57
+ }
58
+ /**
59
+ * Execute an operation with WASM error recovery.
60
+ * @param documentId - Document ID for the operation
61
+ * @param operation - The operation to execute
62
+ * @returns Result of the operation, or null if all retries failed
63
+ */
64
+ async executeWithRecovery(documentId, operation) {
65
+ try {
66
+ return await operation();
67
+ }
68
+ catch (err) {
69
+ if (isWasmError(err)) {
70
+ logWasmError(documentId, err);
71
+ this.queueRetry(documentId, operation, err);
72
+ return null;
73
+ }
74
+ throw err; // Re-throw non-WASM errors
75
+ }
76
+ }
77
+ /**
78
+ * Queue an operation for retry.
79
+ */
80
+ queueRetry(documentId, operation, error) {
81
+ const existing = this.retryQueue.get(documentId);
82
+ if (existing && existing.attempts >= this.maxRetries) {
83
+ this.log(`[wasm-recovery] Giving up on ${documentId} after ${this.maxRetries} attempts`);
84
+ this.retryQueue.delete(documentId);
85
+ return;
86
+ }
87
+ this.retryQueue.set(documentId, {
88
+ documentId,
89
+ operation,
90
+ attempts: (existing?.attempts ?? 0) + 1,
91
+ lastError: error,
92
+ createdAt: existing?.createdAt ?? new Date().toISOString(),
93
+ });
94
+ this.log(`[wasm-recovery] Queued retry for ${documentId} (attempt ${(existing?.attempts ?? 0) + 1})`);
95
+ }
96
+ /**
97
+ * Process the retry queue, attempting to execute queued operations.
98
+ */
99
+ async processRetryQueue() {
100
+ let succeeded = 0;
101
+ let failed = 0;
102
+ const entries = Array.from(this.retryQueue.values());
103
+ for (const entry of entries) {
104
+ if (entry.attempts >= this.maxRetries) {
105
+ this.log(`[wasm-recovery] Max retries reached for ${entry.documentId}`);
106
+ this.retryQueue.delete(entry.documentId);
107
+ failed++;
108
+ continue;
109
+ }
110
+ // Exponential backoff delay
111
+ const delay = this.baseDelayMs * Math.pow(2, entry.attempts - 1);
112
+ await sleep(delay);
113
+ try {
114
+ await entry.operation();
115
+ this.retryQueue.delete(entry.documentId);
116
+ succeeded++;
117
+ this.log(`[wasm-recovery] Retry succeeded for ${entry.documentId}`);
118
+ }
119
+ catch (err) {
120
+ if (isWasmError(err)) {
121
+ entry.attempts++;
122
+ entry.lastError = err;
123
+ logWasmError(entry.documentId, err);
124
+ }
125
+ else {
126
+ // Non-WASM error, remove from queue
127
+ this.retryQueue.delete(entry.documentId);
128
+ failed++;
129
+ this.log(`[wasm-recovery] Non-WASM error for ${entry.documentId}, removing from queue`);
130
+ }
131
+ }
132
+ }
133
+ return {
134
+ succeeded,
135
+ failed,
136
+ remaining: this.retryQueue.size,
137
+ };
138
+ }
139
+ /**
140
+ * Start periodic processing of the retry queue.
141
+ * @param intervalMs - How often to process the queue (default: 1000ms)
142
+ */
143
+ startPeriodicProcessing(intervalMs = 1000) {
144
+ if (this.processInterval) {
145
+ return; // Already running
146
+ }
147
+ this.processInterval = setInterval(async () => {
148
+ if (this.retryQueue.size > 0) {
149
+ await this.processRetryQueue();
150
+ }
151
+ }, intervalMs);
152
+ this.log(`[wasm-recovery] Started periodic processing every ${intervalMs}ms`);
153
+ }
154
+ /**
155
+ * Stop periodic processing.
156
+ */
157
+ stopPeriodicProcessing() {
158
+ if (this.processInterval) {
159
+ clearInterval(this.processInterval);
160
+ this.processInterval = null;
161
+ this.log('[wasm-recovery] Stopped periodic processing');
162
+ }
163
+ }
164
+ /**
165
+ * Get the number of pending retries.
166
+ */
167
+ getPendingCount() {
168
+ return this.retryQueue.size;
169
+ }
170
+ /**
171
+ * Get all pending retry entries (for debugging).
172
+ */
173
+ getPendingEntries() {
174
+ return Array.from(this.retryQueue.values());
175
+ }
176
+ /**
177
+ * Clear all pending retries.
178
+ */
179
+ clearPending() {
180
+ this.retryQueue.clear();
181
+ this.log('[wasm-recovery] Cleared all pending retries');
182
+ }
183
+ }
184
+ /**
185
+ * Sleep helper for backoff delays.
186
+ */
187
+ function sleep(ms) {
188
+ return new Promise(resolve => setTimeout(resolve, ms));
189
+ }