@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,135 @@
1
+ // glassware[type="implementation", id="impl-cli-ls-cmd--05e6cad6", requirements="requirement-cli-ls-cmd--1dc1eaa1,requirement-cli-ls-requires-workspace--e869d236,requirement-cli-ls-filter-path--52fa1bda,requirement-cli-ls-filter-type--5c9fe146,requirement-cli-ls-filter-pattern--4cec491f"]
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 { formatFileTable, formatFileTree, formatFileJson, formatFilePaths, formatFileLong, getMimeCategory, } from '../lib/formatters.js';
6
+ import { matchGlob } from '../lib/local-fs.js';
7
+ // glassware[type="implementation", id="impl-cli-ls-requires-workspace--0d390a0f", requirements="requirement-cli-ls-requires-workspace--e869d236,requirement-cli-fd-error-no-workspace--1919b4fb"]
8
+ function requireWorkspaceConnection() {
9
+ const currentDir = process.cwd();
10
+ const connection = readWorkspaceConnection(currentDir);
11
+ if (!connection) {
12
+ console.error('Error: Not connected to a workspace.');
13
+ console.error('Run `mod init` to connect this directory first.');
14
+ process.exit(1);
15
+ }
16
+ return {
17
+ workspaceId: connection.workspaceId,
18
+ workspaceName: connection.workspaceName,
19
+ };
20
+ }
21
+ function parseArgs(args) {
22
+ const options = {
23
+ tree: false,
24
+ json: false,
25
+ long: false,
26
+ quiet: false,
27
+ };
28
+ let path;
29
+ for (let i = 0; i < args.length; i++) {
30
+ const arg = args[i];
31
+ if (arg === '--tree' || arg === '-t') {
32
+ options.tree = true;
33
+ }
34
+ else if (arg === '--json') {
35
+ options.json = true;
36
+ }
37
+ else if (arg === '--long' || arg === '-l') {
38
+ options.long = true;
39
+ }
40
+ else if (arg === '--quiet' || arg === '-q') {
41
+ options.quiet = true;
42
+ }
43
+ else if (arg === '--type' && args[i + 1]) {
44
+ const typeArg = args[i + 1];
45
+ if (typeArg === 'code' || typeArg === 'text' || typeArg === 'data') {
46
+ options.type = typeArg;
47
+ }
48
+ i++;
49
+ }
50
+ else if (arg.startsWith('--type=')) {
51
+ const typeArg = arg.slice('--type='.length);
52
+ if (typeArg === 'code' || typeArg === 'text' || typeArg === 'data') {
53
+ options.type = typeArg;
54
+ }
55
+ }
56
+ else if (arg === '--pattern' && args[i + 1]) {
57
+ options.pattern = args[i + 1];
58
+ i++;
59
+ }
60
+ else if (arg.startsWith('--pattern=')) {
61
+ options.pattern = arg.slice('--pattern='.length);
62
+ }
63
+ else if (!arg.startsWith('-') && !path) {
64
+ path = arg;
65
+ }
66
+ }
67
+ return { path, options };
68
+ }
69
+ // glassware[type="implementation", id="impl-cli-ls-filter-path--39b6a8c6", requirements="requirement-cli-ls-filter-path--52fa1bda"]
70
+ function filterByPath(files, pathFilter) {
71
+ const normalizedFilter = pathFilter.replace(/\/$/, ''); // Remove trailing slash
72
+ return files.filter(f => f.path.startsWith(normalizedFilter + '/') || f.path === normalizedFilter);
73
+ }
74
+ // glassware[type="implementation", id="impl-cli-ls-filter-type--45ec4f4a", requirements="requirement-cli-ls-filter-type--5c9fe146"]
75
+ function filterByType(files, type) {
76
+ return files.filter(f => getMimeCategory(f.mimeType) === type);
77
+ }
78
+ // glassware[type="implementation", id="impl-cli-ls-filter-pattern--d891ebe5", requirements="requirement-cli-ls-filter-pattern--4cec491f"]
79
+ function filterByPattern(files, pattern) {
80
+ return files.filter(f => matchGlob(f.path, pattern));
81
+ }
82
+ export async function lsCommand(args, repo) {
83
+ const { workspaceId } = requireWorkspaceConnection();
84
+ const { path: pathFilter, options } = parseArgs(args);
85
+ try {
86
+ const modWorkspace = createModWorkspace(repo);
87
+ const workspaceHandle = await modWorkspace.openWorkspace(workspaceId);
88
+ // Fetch all files
89
+ const fileRefs = await workspaceHandle.file.list();
90
+ // Convert to FileInfo
91
+ let files = fileRefs.map(ref => ({
92
+ id: ref.id,
93
+ path: ref.metadata?.path || ref.name,
94
+ name: ref.name,
95
+ size: ref.size,
96
+ mimeType: ref.mimeType,
97
+ updatedAt: ref.updatedAt,
98
+ folderId: ref.folderId,
99
+ }));
100
+ // Apply filters
101
+ if (pathFilter) {
102
+ files = filterByPath(files, pathFilter);
103
+ }
104
+ if (options.type) {
105
+ files = filterByType(files, options.type);
106
+ }
107
+ if (options.pattern) {
108
+ files = filterByPattern(files, options.pattern);
109
+ }
110
+ // Sort by path
111
+ files.sort((a, b) => a.path.localeCompare(b.path));
112
+ // Format output
113
+ let output;
114
+ if (options.json) {
115
+ output = formatFileJson(files);
116
+ }
117
+ else if (options.tree) {
118
+ output = formatFileTree(files);
119
+ }
120
+ else if (options.quiet) {
121
+ output = formatFilePaths(files);
122
+ }
123
+ else if (options.long) {
124
+ output = formatFileLong(files);
125
+ }
126
+ else {
127
+ output = formatFileTable(files);
128
+ }
129
+ console.log(output);
130
+ }
131
+ catch (error) {
132
+ console.error('Error listing files:', error.message);
133
+ process.exit(1);
134
+ }
135
+ }