agent-cleandrive 0.2.2 → 0.3.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.
- package/README.md +93 -8
- package/bin/cleandrive.js +97 -7
- package/config.example.json +3 -1
- package/lib/actions.js +103 -55
- package/lib/archives.js +242 -0
- package/lib/catalog.js +222 -0
- package/lib/offload.js +87 -25
- package/lib/projects.js +114 -0
- package/lib/scan.js +15 -32
- package/lib/server.js +58 -5
- package/lib/util.js +16 -0
- package/package.json +1 -1
- package/ui/index.html +38 -6
package/ui/index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>
|
|
6
|
+
<title>agent-cleandrive</title>
|
|
7
7
|
<style>
|
|
8
8
|
:root {
|
|
9
9
|
--page: #f9f9f7; --surface: #fcfcfb;
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
</head>
|
|
105
105
|
<body>
|
|
106
106
|
<header>
|
|
107
|
-
<h1>
|
|
107
|
+
<h1>agent-cleandrive</h1>
|
|
108
108
|
<span class="meta" id="scanTs">no scan yet</span>
|
|
109
109
|
<span class="spacer"></span>
|
|
110
110
|
<span class="chip" id="diskChip"></span>
|
|
@@ -162,10 +162,21 @@
|
|
|
162
162
|
<button id="rTest">Test connection</button>
|
|
163
163
|
<span id="rStatus" class="risk" style="font-size:12px"></span>
|
|
164
164
|
</div>
|
|
165
|
-
<div class="hint">
|
|
165
|
+
<div class="hint">Project archives get a unique version directory and a receipt recording the original path, then are checksum-verified. Local copies are only removed with the “archive + remove local” action, and only after verification succeeds.</div>
|
|
166
166
|
</div>
|
|
167
167
|
</div>
|
|
168
168
|
|
|
169
|
+
<section class="card" aria-labelledby="archiveHeading">
|
|
170
|
+
<h2 id="archiveHeading">Project archives on your remote drive</h2>
|
|
171
|
+
<label for="archiveSearch">Find a project</label>
|
|
172
|
+
<input id="archiveSearch" type="search" placeholder="Name, original path, or archive ID" style="width:min(100%,420px)">
|
|
173
|
+
<p class="hint">Transfer verification confirms the stored contents. Independent backup status is unknown. Restore commands recover a project only when its original path is absent.</p>
|
|
174
|
+
<div style="overflow-x:auto"><table>
|
|
175
|
+
<thead><tr><th>Project and location</th><th>Size</th><th>State</th><th>Restore</th></tr></thead>
|
|
176
|
+
<tbody id="archiveRows"></tbody>
|
|
177
|
+
</table></div>
|
|
178
|
+
</section>
|
|
179
|
+
|
|
169
180
|
<section class="card">
|
|
170
181
|
<h2>Offload to the remote drive <span class="note" style="text-transform:none;letter-spacing:0;font-weight:400">— like iCloud: a verified copy goes to your remote drive, a small <code>.cloud</code> placeholder stays here</span></h2>
|
|
171
182
|
<div style="display:flex;gap:8px;align-items:center;margin-bottom:10px;flex-wrap:wrap">
|
|
@@ -211,6 +222,8 @@ const ACTIONS = {
|
|
|
211
222
|
// review-only categories where rm unlocks after "Mark reviewed"; apps stay manual
|
|
212
223
|
const REVIEW_RM = ['appdata', 'models'];
|
|
213
224
|
function actionsFor(it) {
|
|
225
|
+
if (it.kind === 'group') return [];
|
|
226
|
+
if (it.activity?.band === 'pinned') return ['keep', 'archive'];
|
|
214
227
|
if (it.protected) return [];
|
|
215
228
|
const base = ACTIONS[it.category] || [];
|
|
216
229
|
if (base.length) return base;
|
|
@@ -221,9 +234,16 @@ const $ = (id) => document.getElementById(id);
|
|
|
221
234
|
const gb = (kb) => { const g = kb/1048576; return g >= 10 ? g.toFixed(0)+' GB' : g >= 1 ? g.toFixed(1)+' GB' : (kb/1024).toFixed(0)+' MB'; };
|
|
222
235
|
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({'&':'&','<':'<','>':'>','"':'"'}[c]));
|
|
223
236
|
|
|
237
|
+
// per-run token the server injects into this page; API calls without it are refused
|
|
238
|
+
const TOKEN = document.querySelector('meta[name="cleandrive-token"]')?.content || '';
|
|
224
239
|
async function api(path, body) {
|
|
225
|
-
const
|
|
226
|
-
|
|
240
|
+
const headers = { 'X-Cleandrive-Token': TOKEN };
|
|
241
|
+
const r = await fetch(path, body ? { method: 'POST', headers: { ...headers, 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : { headers });
|
|
242
|
+
const j = await r.json();
|
|
243
|
+
// the server refuses approvals the executor would refuse; say why instead of failing silently
|
|
244
|
+
if (!r.ok && j.error) alert('Not approved: ' + j.error);
|
|
245
|
+
if (j.refused?.length) alert('Not approved:\n' + j.refused.map((x) => '• ' + x.error).join('\n'));
|
|
246
|
+
return j;
|
|
227
247
|
}
|
|
228
248
|
|
|
229
249
|
function planOf(it) { return S.plan.items[it.id] || {}; }
|
|
@@ -362,7 +382,7 @@ function render() {
|
|
|
362
382
|
const tr = document.createElement('tr');
|
|
363
383
|
const shortPath = it.path.replace(/^\/Users\/[^/]+/, '~');
|
|
364
384
|
tr.innerHTML =
|
|
365
|
-
'<td><div class="path">' + esc(shortPath) + '</div><div class="note">' + esc(it.note || '') + '</div></td>'
|
|
385
|
+
'<td><div class="path">' + esc(shortPath) + '</div><div class="note">' + esc(it.note || '') + '</div>' + (it.activity ? '<details><summary>Activity evidence</summary><div class="note">' + esc('Source edit: ' + (it.activity.newestSource ? new Date(it.activity.newestSource).toLocaleString() : 'unknown') + '; opened: ' + (it.activity.lastOpened ? new Date(it.activity.lastOpened).toLocaleString() : 'unknown') + '; Git: ' + (it.activity.git ? (it.activity.git.dirty === null ? 'unknown' : it.activity.git.dirty ? 'uncommitted work' : 'clean') : 'not detected') + '; inspection: ' + (it.activity.complete ? 'complete' : 'incomplete')) + '</div></details>' : '') + '</td>'
|
|
366
386
|
+ '<td class="num">' + gb(it.kb) + '</td>'
|
|
367
387
|
+ '<td><span class="risk ' + CAT[it.category].risk + '">' + (it.protected ? '🔒 protected' : RISK_LABEL[CAT[it.category].risk]) + '</span></td>'
|
|
368
388
|
+ '<td>' + (opts.length ? '<select>' + opts.map((o) => '<option' + (o === act ? ' selected' : '') + '>' + o + '</option>').join('') + '</select>' : '<span class="note">' + esc(it.suggest) + '</span>') + '</td>'
|
|
@@ -392,8 +412,20 @@ function render() {
|
|
|
392
412
|
if (visible.length > 80) rows.insertAdjacentHTML('beforeend', '<tr><td colspan="6" class="note" style="padding:10px 8px">… ' + (visible.length - 80) + ' smaller items not shown (see CLI: cleandrive state)</td></tr>');
|
|
393
413
|
}
|
|
394
414
|
|
|
415
|
+
function renderArchives() {
|
|
416
|
+
const query = $('archiveSearch').value.toLowerCase();
|
|
417
|
+
const records = (S.archives || []).filter(r => [r.id, r.originalPath, r.remotePath, r.label].join(' ').toLowerCase().includes(query));
|
|
418
|
+
$('archiveRows').innerHTML = records.map(r => '<tr><td><div class="path">' + esc(r.originalPath) + '</div><div class="note">'
|
|
419
|
+
+ esc(r.remote.host + ':' + r.remotePath) + '</div><div class="note">Transfer verified ' + esc(r.verification.checkedAt)
|
|
420
|
+
+ ' · Independent backup: unknown</div></td><td class="num">' + gb(r.bytes / 1024) + '</td><td>' + esc(r.state)
|
|
421
|
+
+ '</td><td><code>' + esc('cleandrive restore ' + r.id) + '</code></td></tr>').join('')
|
|
422
|
+
|| '<tr><td colspan="4">No matching project archives. Earlier archives without receipts are not included.</td></tr>';
|
|
423
|
+
}
|
|
424
|
+
$('archiveSearch').oninput = renderArchives;
|
|
425
|
+
|
|
395
426
|
async function refresh() {
|
|
396
427
|
const st = await api('/api/state');
|
|
428
|
+
S.archives = st.archives || []; renderArchives();
|
|
397
429
|
S.scan = st.scan; S.plan = st.plan || { items: {} }; S.disk = st.disk; S.executing = st.executing;
|
|
398
430
|
const cfgR = st.config?.remote || {};
|
|
399
431
|
if (document.activeElement?.tagName !== 'INPUT') {
|