@space-lens/cli 0.2.8 → 0.3.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.
package/README.md CHANGED
@@ -2,12 +2,38 @@
2
2
 
3
3
  The published `@space-lens/cli` package uses Solid and the public `@uniview/tui-solid` binding.
4
4
 
5
+ This is the current `main` branch TUI. It runs on Node.js 20+, and currently covers the existing scan/cleanup workflow; the new Rust iCloud eviction API is exposed through NAPI but is not wired into this TUI yet.
6
+
5
7
  ```bash
6
8
  yarn tui . --preset node
7
9
  # or, from this package directory
8
10
  vite-node src/cli.ts . --preset node
9
11
  ```
10
12
 
13
+ ## Serve (web workbench over HTTP)
14
+
15
+ `spacelens serve` starts an authenticated HTTP host (built on
16
+ `@space-lens/host`) that serves the web UI and speaks the closed JSON contract
17
+ (`@space-lens/contract`): pairing tickets, bearer sessions, REST reads, and SSE
18
+ scan events.
19
+
20
+ ```bash
21
+ spacelens serve # loopback only, read-only, current dir
22
+ spacelens serve --allow-cleanup # also grant trash-based cleanup
23
+ spacelens serve --host 0.0.0.0 --allow-cidr 192.168.1.0/24
24
+ spacelens serve --host en0 --allow-lan
25
+ spacelens serve --ui-origin https://<your>.workers.dev # needs SPACLENS_HOSTED_PASSWORD
26
+ spacelens serve --machine # supervisor mode: readiness JSON on stdout, ticket on stderr
27
+ ```
28
+
29
+ Rules that hold in every mode:
30
+
31
+ - Pairing tickets are 256-bit, single-use, 60 seconds, and minted only on the
32
+ serving terminal — never over HTTP.
33
+ - Cleanup through the web is trash-only. Permanent deletion stays a CLI/TUI
34
+ `--execute` concern.
35
+ - Scans may only target `--root` directories (default: the working directory).
36
+
11
37
  ## Publish
12
38
 
13
39
  Build and publish the public CLI from this directory:
@@ -22,6 +48,9 @@ The package uses `@uniview/tui-solid` and requires Node.js 20 or newer.
22
48
  ## Controls
23
49
 
24
50
  In Scan mode, use `j/k` or arrows to move and `enter` to expand or collapse
25
- the active folder. In Clean mode, use `space` to select, `a` to select all,
26
- and `x` followed by `enter` to delete. `tab` switches modes; `esc`, `q`, and
27
- Ctrl-C cancel or exit.
51
+ the active folder. Click a row to focus it; clicking a folder also toggles its
52
+ expansion. Preset candidates such as `node_modules` and `target` are shown in
53
+ red. Press `d` followed by `enter` to delete the current file or directory, or
54
+ `A` followed by `enter` to delete all preset candidates at once. In Clean mode,
55
+ use `space` to select, `a` to select all, and `x` followed by `enter` to delete.
56
+ `tab` switches modes; `esc`, `q`, and Ctrl-C cancel or exit.
@@ -48,6 +48,7 @@ function createInitialTuiState() {
48
48
  expandedScanPaths: /* @__PURE__ */ new Set(),
49
49
  selectedPaths: /* @__PURE__ */ new Set(),
50
50
  confirmExecute: false,
51
+ confirmDeleteAll: false,
51
52
  status: ""
52
53
  };
53
54
  }
@@ -69,8 +70,8 @@ function createCleanViewModel(plan, options) {
69
70
  errors: plan.errors
70
71
  };
71
72
  }
72
- function createScanViewModel(trees, state) {
73
- const rows = [...trees].sort(compareTreeNodes).flatMap((tree) => flattenTree(tree, state.expandedScanPaths));
73
+ function createScanViewModel(trees, state, candidatePresets = /* @__PURE__ */ new Map()) {
74
+ const rows = [...trees].sort(compareTreeNodes).flatMap((tree) => flattenTree(tree, state.expandedScanPaths, candidatePresets));
74
75
  const totalSize = trees.reduce((total, tree) => total + tree.size, 0);
75
76
  const nodeCount = trees.reduce((total, tree) => total + countTreeNodes(tree), 0);
76
77
  const cursor = clampCursor(state.scanCursor, rows.length);
@@ -90,40 +91,75 @@ function applyTuiAction(state, action) {
90
91
  case "switch-mode":
91
92
  state.mode = state.mode === "scan" ? "clean" : "scan";
92
93
  state.confirmExecute = false;
94
+ state.confirmDelete = void 0;
95
+ state.confirmDeleteAll = false;
93
96
  return;
94
97
  case "move":
95
98
  if (state.mode === "scan") state.scanCursor = moveCursor(state.scanCursor, action.delta, action.rowCount);
96
99
  else state.cleanCursor = moveCursor(state.cleanCursor, action.delta, action.rowCount);
97
100
  state.confirmExecute = false;
101
+ state.confirmDelete = void 0;
102
+ state.confirmDeleteAll = false;
103
+ return;
104
+ case "focus-row":
105
+ if (state.mode === "scan") state.scanCursor = clampCursor(action.index, action.rowCount);
106
+ else state.cleanCursor = clampCursor(action.index, action.rowCount);
107
+ state.confirmExecute = false;
108
+ state.confirmDelete = void 0;
109
+ state.confirmDeleteAll = false;
98
110
  return;
99
111
  case "toggle-expanded":
100
112
  if (state.expandedScanPaths.has(action.path)) state.expandedScanPaths.delete(action.path);
101
113
  else state.expandedScanPaths.add(action.path);
102
114
  state.confirmExecute = false;
115
+ state.confirmDelete = void 0;
116
+ state.confirmDeleteAll = false;
103
117
  return;
104
118
  case "toggle-selected":
105
119
  if (state.selectedPaths.has(action.path)) state.selectedPaths.delete(action.path);
106
120
  else state.selectedPaths.add(action.path);
107
121
  state.confirmExecute = false;
122
+ state.confirmDelete = void 0;
123
+ state.confirmDeleteAll = false;
108
124
  return;
109
125
  case "toggle-all":
110
126
  if (action.paths.length === 0) return;
111
127
  if (action.paths.every((path) => state.selectedPaths.has(path))) for (const path of action.paths) state.selectedPaths.delete(path);
112
128
  else for (const path of action.paths) state.selectedPaths.add(path);
113
129
  state.confirmExecute = false;
130
+ state.confirmDelete = void 0;
131
+ state.confirmDeleteAll = false;
114
132
  return;
115
133
  case "request-execute":
116
134
  state.confirmExecute = true;
135
+ state.confirmDelete = void 0;
136
+ state.confirmDeleteAll = false;
137
+ return;
138
+ case "request-delete":
139
+ state.confirmExecute = false;
140
+ state.confirmDelete = action.target;
141
+ state.confirmDeleteAll = false;
142
+ return;
143
+ case "request-delete-all":
144
+ state.confirmExecute = false;
145
+ state.confirmDelete = void 0;
146
+ state.confirmDeleteAll = true;
117
147
  return;
118
148
  case "cancel-execute":
119
149
  state.confirmExecute = false;
120
150
  return;
151
+ case "cancel-delete":
152
+ state.confirmDelete = void 0;
153
+ state.confirmDeleteAll = false;
154
+ return;
121
155
  case "set-status":
122
156
  state.status = action.status;
123
157
  return;
124
158
  case "clear-selection":
125
159
  state.selectedPaths.clear();
126
160
  state.confirmExecute = false;
161
+ state.confirmDelete = void 0;
162
+ state.confirmDeleteAll = false;
127
163
  return;
128
164
  }
129
165
  }
@@ -156,7 +192,7 @@ function compareEntries(sort) {
156
192
  return right.size - left.size || left.path.localeCompare(right.path);
157
193
  };
158
194
  }
159
- function flattenTree(node, expandedPaths, depth = 0) {
195
+ function flattenTree(node, expandedPaths, candidatePresets, depth = 0) {
160
196
  const hasChildren = node.children.length > 0;
161
197
  const expandable = hasChildren && depth > 0;
162
198
  const expanded = hasChildren && (depth === 0 || expandedPaths.has(node.path));
@@ -171,8 +207,10 @@ function flattenTree(node, expandedPaths, depth = 0) {
171
207
  ignored: node.ignored,
172
208
  collapsed: node.collapsed,
173
209
  expandable,
174
- expanded
175
- }, ...expanded ? [...node.children].sort(compareTreeNodes).flatMap((child) => flattenTree(child, expandedPaths, depth + 1)) : []];
210
+ expanded,
211
+ directory: hasChildren || node.collapsed,
212
+ preset: candidatePresets.get(node.path)
213
+ }, ...expanded ? [...node.children].sort(compareTreeNodes).flatMap((child) => flattenTree(child, expandedPaths, candidatePresets, depth + 1)) : []];
176
214
  }
177
215
  function compareTreeNodes(left, right) {
178
216
  return right.size - left.size || left.name.localeCompare(right.name);
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { executeCleanup, planCleanup, scanDirectory } from "space-lens";
2
+ import { deletePath, executeCleanup, planCleanup, scanDirectory } from "space-lens";
3
3
  //#region src/scanner.ts
4
4
  function loadSpaceLensData(options) {
5
5
  return {
@@ -25,5 +25,12 @@ function executeCleanupEntries(entries) {
25
25
  errors: []
26
26
  });
27
27
  }
28
+ function deleteScanPath(target) {
29
+ deletePath(target.path);
30
+ return {
31
+ path: target.path,
32
+ bytesRemoved: target.size
33
+ };
34
+ }
28
35
  //#endregion
29
- export { executeCleanupEntries, loadSpaceLensData };
36
+ export { deleteScanPath, executeCleanupEntries, loadSpaceLensData };