@mod-computer/cli 0.1.0 → 0.2.1

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 +72 -0
  2. package/dist/cli.bundle.js +24633 -13744
  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 +545 -326
  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 +8 -3
  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 +56 -0
  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,182 @@
1
+ // glassware[type="implementation", id="impl-cli-diff-cmd--2caa2bcb", requirements="requirement-cli-diff-cmd--cfd908be,requirement-cli-diff-requires-workspace--a4b7f1ce,requirement-cli-diff-unified--a9889945,requirement-cli-diff-color--23d3ed12,requirement-cli-diff-stat--364f0431,requirement-cli-diff-direction-default--e6c9d2de,requirement-cli-diff-direction-workspace--dc23c716"]
2
+ // spec: packages/mod-cli/specs/file-directory.md
3
+ import { createModWorkspace } from '@mod/mod-core';
4
+ import { readWorkspaceConnection } from '../lib/storage.js';
5
+ import { readLocalFile, localFileExists, isBinaryFile } from '../lib/local-fs.js';
6
+ import { computeDiff, formatUnifiedDiff, formatDiffStat, calculateDiffStats, getWorkspaceContent, isBinaryContent, } from '../lib/diff.js';
7
+ import path from 'path';
8
+ // glassware[type="implementation", id="impl-cli-diff-requires-workspace--257badd4", requirements="requirement-cli-diff-requires-workspace--a4b7f1ce,requirement-cli-fd-error-no-workspace--1919b4fb"]
9
+ function requireWorkspaceConnection() {
10
+ const currentDir = process.cwd();
11
+ const connection = readWorkspaceConnection(currentDir);
12
+ if (!connection) {
13
+ console.error('Error: Not connected to a workspace.');
14
+ console.error('Run `mod init` to connect this directory first.');
15
+ process.exit(1);
16
+ }
17
+ return {
18
+ workspaceId: connection.workspaceId,
19
+ workspaceName: connection.workspaceName,
20
+ workspacePath: connection.path,
21
+ };
22
+ }
23
+ function parseArgs(args) {
24
+ const options = {
25
+ workspace: false,
26
+ stat: false,
27
+ noColor: false,
28
+ context: 3,
29
+ };
30
+ let filePath;
31
+ for (let i = 0; i < args.length; i++) {
32
+ const arg = args[i];
33
+ if (arg === '--workspace' || arg === '-w') {
34
+ options.workspace = true;
35
+ }
36
+ else if (arg === '--stat') {
37
+ options.stat = true;
38
+ }
39
+ else if (arg === '--no-color') {
40
+ options.noColor = true;
41
+ }
42
+ else if (arg === '--context' && args[i + 1]) {
43
+ options.context = parseInt(args[i + 1], 10) || 3;
44
+ i++;
45
+ }
46
+ else if (arg.startsWith('--context=')) {
47
+ options.context = parseInt(arg.slice('--context='.length), 10) || 3;
48
+ }
49
+ else if (!arg.startsWith('-') && !filePath) {
50
+ filePath = arg;
51
+ }
52
+ }
53
+ // Check if terminal supports color
54
+ if (!process.stdout.isTTY) {
55
+ options.noColor = true;
56
+ }
57
+ return { filePath, options };
58
+ }
59
+ // glassware[type="implementation", id="impl-cli-fd-perf-diff--61c6010d", requirements="requirement-cli-fd-perf-diff--43c2078c"]
60
+ export async function diffCommand(args, repo) {
61
+ const { workspaceId, workspacePath } = requireWorkspaceConnection();
62
+ const { filePath, options } = parseArgs(args);
63
+ try {
64
+ const modWorkspace = createModWorkspace(repo);
65
+ const workspaceHandle = await modWorkspace.openWorkspace(workspaceId);
66
+ // Get workspace files
67
+ const workspaceFiles = await workspaceHandle.file.list();
68
+ // If specific file requested, diff only that file
69
+ const filesToDiff = filePath
70
+ ? workspaceFiles.filter(f => (f.metadata?.path || f.name) === filePath)
71
+ : workspaceFiles;
72
+ if (filePath && filesToDiff.length === 0) {
73
+ console.error(`Error: File not found in workspace: ${filePath}`);
74
+ console.error("Run `mod ls` to see workspace files.");
75
+ process.exit(1);
76
+ }
77
+ const diffResults = [];
78
+ for (const file of filesToDiff) {
79
+ const wsPath = file.metadata?.path || file.name;
80
+ const localPath = path.join(workspacePath, wsPath);
81
+ // Check if local file exists
82
+ const localExists = await localFileExists(localPath);
83
+ const localContent = localExists ? await readLocalFile(localPath) : null;
84
+ // Get workspace content
85
+ let wsContent = '';
86
+ try {
87
+ const handle = await workspaceHandle.file.get(file.id);
88
+ if (handle) {
89
+ const doc = handle.doc();
90
+ wsContent = getWorkspaceContent(doc?.content);
91
+ }
92
+ }
93
+ catch {
94
+ continue; // Skip files we can't load
95
+ }
96
+ // Skip if no differences
97
+ if (localContent === wsContent) {
98
+ continue;
99
+ }
100
+ // Check for binary
101
+ const localIsBinary = localContent !== null && (await isBinaryFile(localPath) || isBinaryContent(localContent));
102
+ const wsIsBinary = isBinaryContent(wsContent);
103
+ if (localIsBinary || wsIsBinary) {
104
+ const localStats = localContent !== null ? localContent.length : 0;
105
+ const wsStats = wsContent.length;
106
+ diffResults.push({
107
+ path: wsPath,
108
+ additions: 0,
109
+ deletions: 0,
110
+ diffOutput: `Binary files differ (workspace: ${formatBytes(wsStats)}, local: ${formatBytes(localStats)})`,
111
+ isBinary: true,
112
+ });
113
+ continue;
114
+ }
115
+ // Compute diff based on direction
116
+ let oldContent;
117
+ let newContent;
118
+ let oldLabel;
119
+ let newLabel;
120
+ if (options.workspace) {
121
+ // Show workspace changes (what would come from workspace)
122
+ oldContent = localContent || '';
123
+ newContent = wsContent;
124
+ oldLabel = `local:${wsPath}`;
125
+ newLabel = `workspace:${wsPath}`;
126
+ }
127
+ else {
128
+ // Show local changes (what would go to workspace)
129
+ oldContent = wsContent;
130
+ newContent = localContent || '';
131
+ oldLabel = `workspace:${wsPath}`;
132
+ newLabel = `local:${wsPath}`;
133
+ }
134
+ // Compute unified diff
135
+ const hunks = computeDiff(oldContent, newContent, options.context);
136
+ if (hunks.length === 0) {
137
+ continue; // No differences
138
+ }
139
+ const stats = calculateDiffStats(hunks);
140
+ // Format with color if supported
141
+ const diffOutput = formatUnifiedDiff(oldLabel, newLabel, hunks, !options.noColor);
142
+ diffResults.push({
143
+ path: wsPath,
144
+ additions: stats.additions,
145
+ deletions: stats.deletions,
146
+ diffOutput,
147
+ isBinary: false,
148
+ });
149
+ }
150
+ if (diffResults.length === 0) {
151
+ console.log('No differences.');
152
+ return;
153
+ }
154
+ // Show diffstat summary if requested
155
+ if (options.stat) {
156
+ const statOutput = formatDiffStat(diffResults.map(r => ({
157
+ path: r.path,
158
+ additions: r.additions,
159
+ deletions: r.deletions,
160
+ })), !options.noColor);
161
+ console.log(statOutput);
162
+ return;
163
+ }
164
+ // Output diffs
165
+ for (const result of diffResults) {
166
+ console.log(result.diffOutput);
167
+ console.log('');
168
+ }
169
+ }
170
+ catch (error) {
171
+ console.error('Error computing diff:', error.message);
172
+ process.exit(1);
173
+ }
174
+ }
175
+ function formatBytes(bytes) {
176
+ if (bytes === 0)
177
+ return '0 B';
178
+ const k = 1024;
179
+ const sizes = ['B', 'KB', 'MB', 'GB'];
180
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
181
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
182
+ }
@@ -1,16 +1,28 @@
1
1
  import { agentsRunCommand } from './agents-run.js';
2
2
  import { authCommand } from './auth.js';
3
3
  import { branchCommand } from './branch.js';
4
- import { specCommand } from './spec.js';
5
4
  import { workspaceCommand } from './workspace.js';
6
5
  import { claudeSyncCommand } from './claude-sync.js';
7
6
  import { syncCommand } from './sync.js';
8
7
  import { initCommand } from './init.js';
9
8
  import { recoverCommand } from './recover.js';
9
+ import { lsCommand } from './ls.js';
10
+ import { rmCommand } from './rm.js';
11
+ import { mvCommand } from './mv.js';
12
+ import { statusCommand } from './status.js';
13
+ import { diffCommand } from './diff.js';
14
+ import { addCommand } from './add.js';
15
+ import { membersCommand } from './members.js';
16
+ import { commentCommand } from './comment.js';
17
+ import { traceCommand } from './trace.js';
10
18
  import { FEATURES, isFeatureEnabled } from '../config/features.js';
19
+ // Alias for 'mod signin' -> 'mod auth login'
20
+ const signinCommand = (args, repo) => {
21
+ return authCommand(['login', ...args], repo);
22
+ };
11
23
  const allCommands = {
12
24
  'auth': authCommand,
13
- 'spec': specCommand,
25
+ 'signin': signinCommand, // Alias for 'auth login'
14
26
  'sync': syncCommand,
15
27
  'agents-run': agentsRunCommand,
16
28
  'claude-sync': claudeSyncCommand,
@@ -18,10 +30,19 @@ const allCommands = {
18
30
  'workspace': workspaceCommand,
19
31
  'init': initCommand,
20
32
  'recover': recoverCommand,
33
+ 'ls': lsCommand,
34
+ 'rm': rmCommand,
35
+ 'mv': mvCommand,
36
+ 'status': statusCommand,
37
+ 'diff': diffCommand,
38
+ 'add': addCommand,
39
+ 'members': membersCommand,
40
+ 'comment': commentCommand,
41
+ 'trace': traceCommand,
21
42
  };
22
43
  const commandFeatureMapping = {
23
44
  'auth': FEATURES.AUTH,
24
- 'spec': FEATURES.TASK_MANAGEMENT, // Spec tracking, not in MVP
45
+ 'signin': FEATURES.AUTH, // Alias for 'auth login'
25
46
  'sync': FEATURES.WATCH_OPERATIONS,
26
47
  'agents-run': FEATURES.AGENT_INTEGRATIONS,
27
48
  'claude-sync': FEATURES.AGENT_INTEGRATIONS, // Claude projects sync, separate from file sync daemon
@@ -29,6 +50,15 @@ const commandFeatureMapping = {
29
50
  'workspace': FEATURES.WORKSPACE_MANAGEMENT,
30
51
  'init': FEATURES.SYNC_OPERATIONS, // Use existing feature flag for command installation
31
52
  'recover': FEATURES.STATUS, // Recovery command always available when status is enabled
53
+ 'ls': FEATURES.FILE_OPERATIONS,
54
+ 'rm': FEATURES.FILE_OPERATIONS,
55
+ 'mv': FEATURES.FILE_OPERATIONS,
56
+ 'status': FEATURES.FILE_OPERATIONS,
57
+ 'diff': FEATURES.FILE_OPERATIONS,
58
+ 'add': FEATURES.FILE_OPERATIONS, // Add files to workspace
59
+ 'members': FEATURES.MEMBER_MANAGEMENT, // Workspace member management
60
+ 'comment': FEATURES.FILE_OPERATIONS, // Comment metadata operations
61
+ 'trace': FEATURES.TRACING, // Trace management and reporting
32
62
  };
33
63
  const registry = {};
34
64
  for (const [commandName, commandHandler] of Object.entries(allCommands)) {