gestalt-mobile 0.68.4 → 0.68.6
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 +15 -4
- package/dist/client/assets/index-Dl5gXKZh.js +183 -0
- package/dist/client/index.html +1 -1
- package/dist/server/server/composition.contracts.js +232 -12
- package/dist/server/server/composition.js +111 -29
- package/dist/server/server/features/plans/application/plan-attachment-supervision.js +3 -1
- package/dist/server/server/features/plans/application/prepare-org-plan-supervision.js +18 -10
- package/dist/server/server/features/plans/application/start-org-plan-supervision.js +23 -4
- package/dist/server/server/features/plans/execute-plan/endpoint.js +1 -1
- package/dist/server/server/features/sessions/application/workspace-conflict.js +19 -0
- package/dist/server/server/features/sessions/application/writer-acquisition.js +7 -0
- package/dist/server/server/features/sessions/forget-session/endpoint.js +7 -0
- package/dist/server/server/features/sessions/forget-session/use-case.js +8 -2
- package/dist/server/server/features/sessions/register-routes.js +1 -0
- package/dist/server/server/features/sessions/restore-session/endpoint.js +10 -1
- package/dist/server/server/features/sessions/start-session/endpoint.js +8 -0
- package/dist/server/server/features/sessions/start-turn/use-case.js +13 -1
- package/dist/server/server/platform/codex/error-code.js +2 -2
- package/dist/server/server/platform/codex/protocol-compatibility.js +7 -24
- package/dist/server/server/platform/codex/session-runtime.js +18 -0
- package/dist/server/server/platform/http/problem-handler.js +9 -0
- package/dist/server/server/platform/kimi/kimi-session-runtime.js +5 -0
- package/dist/server/server/platform/persistence/migrate.js +17 -0
- package/dist/server/server/platform/persistence/sqlite-event-journal.js +6 -2
- package/dist/server/server/platform/persistence/sqlite-forget-operation-store.js +38 -6
- package/dist/server/server/platform/persistence/sqlite-org-plan-launch-store.js +43 -16
- package/dist/server/server/platform/persistence/sqlite-session-repository.js +29 -7
- package/dist/server/server/platform/persistence/sqlite-workspace-lifecycle.js +59 -0
- package/dist/server/server/platform/plans/filesystem-plan-status-source.js +2 -2
- package/dist/server/server/platform/scratch/filesystem-session-scratch.js +3 -1
- package/dist/server/server/platform/scratch/filesystem-workspace-forget.js +123 -0
- package/dist/server/shared/contracts/org-plan-execution.js +1 -1
- package/dist/server/shared/contracts/plan-signal.js +2 -1
- package/package.json +1 -1
- package/dist/client/assets/index-CKyExrMf.js +0 -183
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { lstatSync, mkdirSync, realpathSync, renameSync } from 'node:fs';
|
|
7
|
+
import { lstat, rm } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { WorkspaceSessionConflict } from '../../features/sessions/application/workspace-conflict.js';
|
|
10
|
+
import { canonicalSessionWorkspace, workspaceContains, } from '../persistence/sqlite-workspace-lifecycle.js';
|
|
11
|
+
/** Final Forget owns the entire selected workspace's explicitly disposable tmp directory. */
|
|
12
|
+
export class FilesystemWorkspaceForget {
|
|
13
|
+
db;
|
|
14
|
+
constructor(db) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
}
|
|
17
|
+
async clean(session, operationId, authorized, knownSessions) {
|
|
18
|
+
const workspace = canonicalSessionWorkspace(session.workspacePath);
|
|
19
|
+
const others = knownSessions().filter((other) => other.id !== session.id);
|
|
20
|
+
if (others.some((other) => canonicalSessionWorkspace(other.workspacePath) === workspace))
|
|
21
|
+
return 'retained';
|
|
22
|
+
const temporary = join(workspace, 'tmp');
|
|
23
|
+
for (const other of others) {
|
|
24
|
+
if (workspaceContains(temporary, canonicalSessionWorkspace(other.workspacePath)))
|
|
25
|
+
throw new WorkspaceSessionConflict('SESSION_NESTED_WORKSPACE', other.id);
|
|
26
|
+
}
|
|
27
|
+
const retired = this.retire(session, operationId, workspace, temporary, authorized);
|
|
28
|
+
if (retired)
|
|
29
|
+
await rm(retired, { recursive: true, force: true, maxRetries: 3 });
|
|
30
|
+
// A non-cooperating external publisher must not turn retained files into a
|
|
31
|
+
// successful final Forget. New Mobile starts remain durably fenced.
|
|
32
|
+
try {
|
|
33
|
+
await lstat(temporary);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.code === 'ENOENT')
|
|
37
|
+
return;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
throw new Error('SESSION_CLEANUP_FAILED');
|
|
41
|
+
}
|
|
42
|
+
retire(session, operationId, workspace, temporary, authorized) {
|
|
43
|
+
// The short synchronous transaction atomically checks authority and moves
|
|
44
|
+
// tmp out of the allocation namespace. Duplicate/restarted requests can
|
|
45
|
+
// delete only this operation's retired path, never a later session's tmp.
|
|
46
|
+
this.db.exec('BEGIN IMMEDIATE');
|
|
47
|
+
try {
|
|
48
|
+
const lock = this.db
|
|
49
|
+
.prepare('SELECT retired_path FROM workspace_forget_locks WHERE workspace_path=? AND operation_id=?')
|
|
50
|
+
.get(workspace, operationId);
|
|
51
|
+
if (!lock || !authorized())
|
|
52
|
+
throw new Error('SESSION_FORGET_OPERATION_CHANGED');
|
|
53
|
+
if (lock.retired_path !== null) {
|
|
54
|
+
if (lock.retired_path !== '' &&
|
|
55
|
+
lock.retired_path !== join(workspace, '.gestalt', 'forgotten-tmp', operationId))
|
|
56
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
|
|
57
|
+
this.db.exec('COMMIT');
|
|
58
|
+
return lock.retired_path;
|
|
59
|
+
}
|
|
60
|
+
if (!/^[0-9a-f-]{36}$/.test(operationId))
|
|
61
|
+
throw new Error('SESSION_FORGET_OPERATION_CHANGED');
|
|
62
|
+
const directory = (path) => {
|
|
63
|
+
const info = lstatSync(path);
|
|
64
|
+
if (!info.isDirectory() ||
|
|
65
|
+
info.isSymbolicLink() ||
|
|
66
|
+
realpathSync(path) !== path ||
|
|
67
|
+
(process.getuid && info.uid !== process.getuid()))
|
|
68
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
|
|
69
|
+
};
|
|
70
|
+
let retired = '';
|
|
71
|
+
try {
|
|
72
|
+
directory(workspace);
|
|
73
|
+
directory(temporary);
|
|
74
|
+
const metadata = join(workspace, '.gestalt');
|
|
75
|
+
const staging = join(metadata, 'forgotten-tmp');
|
|
76
|
+
for (const path of [metadata, staging]) {
|
|
77
|
+
try {
|
|
78
|
+
mkdirSync(path, { mode: 0o700 });
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error.code !== 'EEXIST')
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
directory(path);
|
|
85
|
+
}
|
|
86
|
+
retired = join(staging, operationId);
|
|
87
|
+
try {
|
|
88
|
+
lstatSync(retired);
|
|
89
|
+
throw new Error('SESSION_SCRATCH_BUSY');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.code !== 'ENOENT')
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
renameSync(temporary, retired);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error.code !== 'ENOENT')
|
|
99
|
+
throw error;
|
|
100
|
+
// A crash between rename and commit leaves the exact durable operation's
|
|
101
|
+
// private retirement directory. Recover it without touching a new tmp.
|
|
102
|
+
const candidate = join(workspace, '.gestalt', 'forgotten-tmp', operationId);
|
|
103
|
+
try {
|
|
104
|
+
directory(candidate);
|
|
105
|
+
retired = candidate;
|
|
106
|
+
}
|
|
107
|
+
catch (missing) {
|
|
108
|
+
if (missing.code !== 'ENOENT')
|
|
109
|
+
throw missing;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
this.db
|
|
113
|
+
.prepare('UPDATE workspace_forget_locks SET retired_path=? WHERE operation_id=?')
|
|
114
|
+
.run(retired, operationId);
|
|
115
|
+
this.db.exec('COMMIT');
|
|
116
|
+
return retired;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
this.db.exec('ROLLBACK');
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -24,7 +24,7 @@ export const orgPlanLaunchConflictSchema = z.discriminatedUnion('kind', [
|
|
|
24
24
|
z
|
|
25
25
|
.object({
|
|
26
26
|
kind: z.literal('blocked'),
|
|
27
|
-
code: z.enum(['CONTEXT_CHANGED', 'ACTIVE_SUPERVISION']),
|
|
27
|
+
code: z.enum(['CONTEXT_CHANGED', 'ACTIVE_SUPERVISION', 'WORKSPACE_BUSY']),
|
|
28
28
|
reason: z.string().min(1),
|
|
29
29
|
existingSessionId: identity.optional(),
|
|
30
30
|
})
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
6
|
+
/** Helper publications and Mobile's display-only attachment signal. */
|
|
7
7
|
export const planSignalReasons = [
|
|
8
8
|
'authoring-start',
|
|
9
|
+
'display-open',
|
|
9
10
|
'work-start',
|
|
10
11
|
'checkpoint',
|
|
11
12
|
'update',
|