gestalt-mobile 0.72.3 → 0.72.5
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/dist/client/assets/{index-CwgSPgbi.css → index-BQD63G5z.css} +1 -1
- package/dist/client/assets/{index-C--Oj-7W.js → index-BbeZkUkt.js} +18 -18
- package/dist/client/index.html +2 -2
- package/dist/server/server/features/sessions/clean-tmp/endpoint.js +12 -0
- package/dist/server/server/features/sessions/clean-tmp/use-case.js +5 -0
- package/dist/server/server/platform/plans/filesystem-workspace-plan-catalog.js +69 -19
- package/dist/server/server/platform/plans/org-plan-discovery.js +41 -2
- package/dist/server/server/platform/scratch/filesystem-scratch-cleanup.js +11 -1
- package/dist/server/shared/contracts/tmp-cleanup.js +1 -1
- package/package.json +1 -1
package/dist/client/index.html
CHANGED
|
@@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
16
16
|
<link rel="icon" href="/icons/gestalt-mobile-192.png" />
|
|
17
17
|
<link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
|
|
18
18
|
<title>Gestalt Mobile</title>
|
|
19
|
-
<script type="module" crossorigin src="/assets/index-
|
|
20
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-BbeZkUkt.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BQD63G5z.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { CLEAN_TMP_FAILED_FOLDER_LIMIT, } from '../../../../shared/contracts/tmp-cleanup.js';
|
|
7
8
|
import { problem } from '../../../platform/http/problem.js';
|
|
8
9
|
const requestSchema = z.object({}).strict();
|
|
9
10
|
const counter = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
@@ -26,6 +27,16 @@ const responseSchema = z.object({
|
|
|
26
27
|
unavailable: counter,
|
|
27
28
|
io: counter,
|
|
28
29
|
}),
|
|
30
|
+
failedFolders: z
|
|
31
|
+
.array(z.object({
|
|
32
|
+
workspaceName: z.string().min(1).max(255),
|
|
33
|
+
relativePath: z
|
|
34
|
+
.string()
|
|
35
|
+
.max(200)
|
|
36
|
+
.regex(/^tmp\/sessions\/(?:\.cleanup-)?[a-z0-9-]+$/),
|
|
37
|
+
}))
|
|
38
|
+
.max(CLEAN_TMP_FAILED_FOLDER_LIMIT)
|
|
39
|
+
.optional(),
|
|
29
40
|
});
|
|
30
41
|
export function registerCleanTmp(app, cleanup) {
|
|
31
42
|
app.post('/api/maintenance/clean-tmp', async (request, reply) => {
|
|
@@ -56,6 +67,7 @@ export function registerCleanTmp(app, cleanup) {
|
|
|
56
67
|
unavailable: result.workspaces.unavailable,
|
|
57
68
|
},
|
|
58
69
|
reasons: result.folders.reasons,
|
|
70
|
+
failedFolders: result.folders.failedFolders,
|
|
59
71
|
});
|
|
60
72
|
return reply.send(response);
|
|
61
73
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
import { CLEAN_TMP_FAILED_FOLDER_LIMIT, } from '../../../../shared/contracts/tmp-cleanup.js';
|
|
6
7
|
export function emptyScratchCounts() {
|
|
7
8
|
return {
|
|
8
9
|
removed: 0,
|
|
@@ -61,6 +62,10 @@ export class CleanSessionScratch {
|
|
|
61
62
|
result.workspaces.removed++;
|
|
62
63
|
result.folders.skipped += counts.skipped;
|
|
63
64
|
result.folders.failed += counts.failed;
|
|
65
|
+
if (counts.failedFolders?.length) {
|
|
66
|
+
const details = (result.folders.failedFolders ??= []);
|
|
67
|
+
details.push(...counts.failedFolders.slice(0, CLEAN_TMP_FAILED_FOLDER_LIMIT - details.length));
|
|
68
|
+
}
|
|
64
69
|
for (const reason of Object.keys(counts.reasons))
|
|
65
70
|
result.folders.reasons[reason] += counts.reasons[reason];
|
|
66
71
|
result.workspaces[counts.failed ? 'failed' : counts.skipped ? 'skipped' : 'cleaned']++;
|
|
@@ -8,7 +8,7 @@ import { createHash } from 'node:crypto';
|
|
|
8
8
|
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
9
9
|
import { parseSupervisedPlan } from '../../features/plans/application/parse-supervised-plan.js';
|
|
10
10
|
import { OrgPlanDiscovery } from './org-plan-discovery.js';
|
|
11
|
-
import { isArchivedOrgPlan } from './org-plan-archive-tag.js';
|
|
11
|
+
import { archiveOrgPlan, isArchivedOrgPlan } from './org-plan-archive-tag.js';
|
|
12
12
|
const maximumBytes = 1_048_576;
|
|
13
13
|
/** Cached `.gestalt` Org discovery, with bounded parallel metadata checks. */
|
|
14
14
|
export class FilesystemWorkspacePlanCatalog {
|
|
@@ -51,22 +51,22 @@ export class FilesystemWorkspacePlanCatalog {
|
|
|
51
51
|
while (next < planNames.length) {
|
|
52
52
|
const index = next++;
|
|
53
53
|
const name = planNames[index];
|
|
54
|
-
let
|
|
54
|
+
let metadata;
|
|
55
55
|
try {
|
|
56
|
-
|
|
56
|
+
metadata = await this.filesystem.lstat(resolve(workspace, ...name.split('/')));
|
|
57
57
|
if (!metadata.isFile() || metadata.isSymbolicLink())
|
|
58
58
|
continue;
|
|
59
|
-
signature = [
|
|
60
|
-
metadata.dev,
|
|
61
|
-
metadata.ino,
|
|
62
|
-
metadata.size,
|
|
63
|
-
metadata.mtimeMs,
|
|
64
|
-
metadata.ctimeMs,
|
|
65
|
-
].join(':');
|
|
66
59
|
}
|
|
67
60
|
catch {
|
|
68
61
|
continue;
|
|
69
62
|
}
|
|
63
|
+
const signature = [
|
|
64
|
+
metadata.dev,
|
|
65
|
+
metadata.ino,
|
|
66
|
+
metadata.size,
|
|
67
|
+
metadata.mtimeMs,
|
|
68
|
+
metadata.ctimeMs,
|
|
69
|
+
].join(':');
|
|
70
70
|
const previous = cache.files.get(name);
|
|
71
71
|
if (previous?.signature === signature) {
|
|
72
72
|
try {
|
|
@@ -78,7 +78,7 @@ export class FilesystemWorkspacePlanCatalog {
|
|
|
78
78
|
catch {
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
|
-
entries[index] = previous
|
|
81
|
+
entries[index] = previous;
|
|
82
82
|
files.set(name, previous);
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
@@ -86,6 +86,7 @@ export class FilesystemWorkspacePlanCatalog {
|
|
|
86
86
|
if (candidate.kind === 'missing')
|
|
87
87
|
continue;
|
|
88
88
|
let entry;
|
|
89
|
+
let copyKey;
|
|
89
90
|
if (candidate.kind === 'unavailable') {
|
|
90
91
|
entry = toFallbackEntry(name);
|
|
91
92
|
}
|
|
@@ -101,13 +102,21 @@ export class FilesystemWorkspacePlanCatalog {
|
|
|
101
102
|
: toFallbackEntry(name, candidate.source);
|
|
102
103
|
if (isArchivedOrgPlan(candidate.source))
|
|
103
104
|
entry = { ...entry, archived: true };
|
|
104
|
-
|
|
105
|
+
copyKey = catalogCopyKey(name, candidate.source);
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
+
const file = {
|
|
108
|
+
signature,
|
|
109
|
+
entry,
|
|
110
|
+
sortDate: catalogDate(entry.date, metadata.mtimeMs),
|
|
111
|
+
copyKey,
|
|
112
|
+
};
|
|
113
|
+
if (candidate.kind === 'readable')
|
|
114
|
+
files.set(name, file);
|
|
115
|
+
entries[index] = file;
|
|
107
116
|
}
|
|
108
117
|
}));
|
|
109
118
|
cache.files = files;
|
|
110
|
-
cache.entries = entries
|
|
119
|
+
cache.entries = orderCatalog(entries);
|
|
111
120
|
cache.refreshedAt = this.now();
|
|
112
121
|
return cache.entries;
|
|
113
122
|
}
|
|
@@ -256,18 +265,59 @@ function toEntry(planName, plan) {
|
|
|
256
265
|
};
|
|
257
266
|
}
|
|
258
267
|
function toFallbackEntry(planName, source) {
|
|
268
|
+
const date = orgHeader('DATE', source);
|
|
259
269
|
return {
|
|
260
270
|
planName,
|
|
261
271
|
title: fallbackTitle(planName, source),
|
|
272
|
+
...(date === undefined ? {} : { date }),
|
|
262
273
|
previewAvailable: false,
|
|
263
274
|
};
|
|
264
275
|
}
|
|
265
|
-
function
|
|
266
|
-
const
|
|
276
|
+
function orgHeader(key, source) {
|
|
277
|
+
const pattern = new RegExp(`^#\\+${key}:(?:[ \\t](.*))?$`, 'i');
|
|
278
|
+
return source
|
|
267
279
|
?.replace(/\r\n?/g, '\n')
|
|
268
280
|
.split('\n')
|
|
269
|
-
.map((line) =>
|
|
270
|
-
.find((
|
|
281
|
+
.map((line) => pattern.exec(line)?.[1]?.trim())
|
|
282
|
+
.find((value) => value);
|
|
283
|
+
}
|
|
284
|
+
function fallbackTitle(planName, source) {
|
|
271
285
|
const filename = planName.split('/').at(-1) ?? planName;
|
|
272
|
-
return
|
|
286
|
+
return orgHeader('TITLE', source) ?? filename.slice(0, -'.org'.length);
|
|
287
|
+
}
|
|
288
|
+
function catalogCopyKey(planName, source) {
|
|
289
|
+
const parts = planName.split('/');
|
|
290
|
+
const owner = parts.slice(0, parts.indexOf('.gestalt')).join('/');
|
|
291
|
+
// A copied plan stays collapsed after archiving the selected original.
|
|
292
|
+
const digest = createHash('sha256').update(archiveOrgPlan(source)).digest('hex');
|
|
293
|
+
return JSON.stringify([owner, parts.at(-1), digest]);
|
|
294
|
+
}
|
|
295
|
+
function catalogDate(date, modifiedAt) {
|
|
296
|
+
const day = /^(?:<|\[)?(\d{4}-\d{2}-\d{2})(?=$|[T \t>\]])/.exec(date ?? '')?.[1];
|
|
297
|
+
if (!day)
|
|
298
|
+
return modifiedAt;
|
|
299
|
+
const parsed = new Date(`${day}T00:00:00Z`);
|
|
300
|
+
return parsed.toJSON()?.startsWith(day) ? parsed.getTime() : modifiedAt;
|
|
301
|
+
}
|
|
302
|
+
function orderCatalog(entries) {
|
|
303
|
+
const unique = new Map();
|
|
304
|
+
for (const file of entries) {
|
|
305
|
+
if (!file)
|
|
306
|
+
continue;
|
|
307
|
+
const key = file.copyKey ?? file.entry.planName;
|
|
308
|
+
const previous = unique.get(key);
|
|
309
|
+
if (!previous ||
|
|
310
|
+
file.entry.planName.split('/').length < previous.entry.planName.split('/').length)
|
|
311
|
+
unique.set(key, file);
|
|
312
|
+
}
|
|
313
|
+
const completed = (entry) => Boolean(entry.allDone || entry.archived);
|
|
314
|
+
return [...unique.values()]
|
|
315
|
+
.sort((left, right) => {
|
|
316
|
+
const leftDone = completed(left.entry);
|
|
317
|
+
const rightDone = completed(right.entry);
|
|
318
|
+
return (Number(leftDone) - Number(rightDone) ||
|
|
319
|
+
(leftDone ? 0 : right.sortDate - left.sortDate) ||
|
|
320
|
+
left.entry.planName.localeCompare(right.entry.planName));
|
|
321
|
+
})
|
|
322
|
+
.map(({ entry }) => entry);
|
|
273
323
|
}
|
|
@@ -34,7 +34,34 @@ export class OrgPlanDiscovery {
|
|
|
34
34
|
this.execute = execute;
|
|
35
35
|
}
|
|
36
36
|
async list(workspace) {
|
|
37
|
-
|
|
37
|
+
// Mark checkout roots without walking their Git metadata. A repository under
|
|
38
|
+
// a .gestalt directory is an internal checkout, not another project to list.
|
|
39
|
+
const args = [
|
|
40
|
+
'.',
|
|
41
|
+
'-name',
|
|
42
|
+
'.git',
|
|
43
|
+
'-print0',
|
|
44
|
+
'-prune',
|
|
45
|
+
'-o',
|
|
46
|
+
'-type',
|
|
47
|
+
'd',
|
|
48
|
+
'(',
|
|
49
|
+
'-path',
|
|
50
|
+
'*/tmp/sessions',
|
|
51
|
+
'-o',
|
|
52
|
+
'-path',
|
|
53
|
+
'*/.gestalt/evidence',
|
|
54
|
+
')',
|
|
55
|
+
'-prune',
|
|
56
|
+
'-o',
|
|
57
|
+
'-type',
|
|
58
|
+
'f',
|
|
59
|
+
'-name',
|
|
60
|
+
'*.org',
|
|
61
|
+
'-path',
|
|
62
|
+
'*/.gestalt/*',
|
|
63
|
+
'-print0',
|
|
64
|
+
];
|
|
38
65
|
let output;
|
|
39
66
|
try {
|
|
40
67
|
output = await this.execute(this.command, args, workspace);
|
|
@@ -45,11 +72,23 @@ export class OrgPlanDiscovery {
|
|
|
45
72
|
this.command = 'find';
|
|
46
73
|
output = await this.execute('find', args, workspace);
|
|
47
74
|
}
|
|
48
|
-
|
|
75
|
+
const paths = [
|
|
49
76
|
...new Set(output
|
|
50
77
|
.split('\0')
|
|
51
78
|
.filter(Boolean)
|
|
52
79
|
.map((path) => path.replace(/^\.\//, ''))),
|
|
53
80
|
];
|
|
81
|
+
const internalCheckouts = new Set(paths
|
|
82
|
+
.filter((path) => path.endsWith('/.git') && path.split('/').slice(0, -2).includes('.gestalt'))
|
|
83
|
+
.map((path) => path.slice(0, -'/.git'.length)));
|
|
84
|
+
return paths.filter((path) => {
|
|
85
|
+
if (!path.endsWith('.org'))
|
|
86
|
+
return false;
|
|
87
|
+
for (let end = path.lastIndexOf('/'); end > 0; end = path.lastIndexOf('/', end - 1)) {
|
|
88
|
+
if (internalCheckouts.has(path.slice(0, end)))
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
});
|
|
54
93
|
}
|
|
55
94
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { lstat, mkdir, open, readdir, realpath, rename, rm, rmdir } from 'node:fs/promises';
|
|
8
8
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
|
+
import { CLEAN_TMP_FAILED_FOLDER_LIMIT } from '../../../shared/contracts/tmp-cleanup.js';
|
|
9
10
|
import { emptyScratchCounts, } from '../../features/sessions/clean-tmp/use-case.js';
|
|
10
11
|
import { mobileScratchOwnerId, privateDirectory, scratchMarkerName } from './scratch-filesystem.js';
|
|
11
12
|
import { claimOwnerFence } from './owner-fence.js';
|
|
@@ -54,6 +55,7 @@ export class FilesystemScratchCleanup {
|
|
|
54
55
|
async cleanWorkspace(workspacePath, protectedSessions, onlyOwnerId, authorized, authorizedSessionId, inherited) {
|
|
55
56
|
await this.canonicalWorkspace(workspacePath);
|
|
56
57
|
const counts = emptyScratchCounts();
|
|
58
|
+
const workspaceName = basename(workspacePath) || 'root workspace';
|
|
57
59
|
const temporary = join(workspacePath, 'tmp');
|
|
58
60
|
try {
|
|
59
61
|
const info = await lstat(temporary);
|
|
@@ -106,9 +108,9 @@ export class FilesystemScratchCleanup {
|
|
|
106
108
|
containment = await claimScratchContainment(directory, ownerId, inherited);
|
|
107
109
|
release = await claimOwnerFence(directory);
|
|
108
110
|
const marker = await readManagedScratchOwner(directory, workspacePath, ownerId);
|
|
109
|
-
await this.releasedLeases(directory, marker);
|
|
110
111
|
await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized, onlyOwnerId ??
|
|
111
112
|
(authorizedSessionId ? mobileScratchOwnerId(authorizedSessionId) : undefined));
|
|
113
|
+
await this.releasedLeases(directory, marker);
|
|
112
114
|
if (authorized) {
|
|
113
115
|
await this.retireNestedNamespaces(directory, protectedSessions, authorized, authorizedSessionId, containment);
|
|
114
116
|
if (marker.runtime && (await validateRuntime(marker, marker.runtime, true)))
|
|
@@ -217,6 +219,14 @@ export class FilesystemScratchCleanup {
|
|
|
217
219
|
counts.reasons.io++;
|
|
218
220
|
}
|
|
219
221
|
}
|
|
222
|
+
if (outcome === 'failed' &&
|
|
223
|
+
(counts.failedFolders?.length ?? 0) < CLEAN_TMP_FAILED_FOLDER_LIMIT &&
|
|
224
|
+
!/[\\/\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(workspaceName)) {
|
|
225
|
+
(counts.failedFolders ??= []).push({
|
|
226
|
+
workspaceName,
|
|
227
|
+
relativePath: `tmp/sessions/${basename(directory)}`,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
220
230
|
}
|
|
221
231
|
}
|
|
222
232
|
return counts;
|