gestalt-mobile 0.65.8 → 0.66.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 +22 -0
- package/dist/client/assets/index-BDsGojoG.js +128 -0
- package/dist/client/assets/{index-VDRT2Esv.css → index-DxsD-jG4.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/server/cli.js +2 -1
- package/dist/server/server/composition.contracts.js +179 -84
- package/dist/server/server/composition.js +65 -5
- package/dist/server/server/features/sessions/application/session-scratch.js +6 -0
- package/dist/server/server/features/sessions/clean-tmp/endpoint.js +68 -0
- package/dist/server/server/features/sessions/clean-tmp/use-case.js +82 -0
- package/dist/server/server/features/sessions/forget-session/endpoint.js +10 -2
- package/dist/server/server/features/sessions/forget-session/use-case.js +75 -0
- package/dist/server/server/features/sessions/get-session/endpoint.js +2 -1
- package/dist/server/server/features/sessions/list-sessions/endpoint.js +3 -0
- package/dist/server/server/features/sessions/promote-recent-thread/use-case.js +4 -1
- package/dist/server/server/features/sessions/register-routes.js +29 -2
- package/dist/server/server/features/sessions/start-session/endpoint.js +7 -0
- package/dist/server/server/features/sessions/start-session/use-case.js +4 -1
- package/dist/server/server/platform/catalog/filesystem-workspace-catalog.js +19 -1
- package/dist/server/server/platform/codex/codex-playwright.js +41 -3
- package/dist/server/server/platform/codex/codex-process-launcher.js +24 -2
- package/dist/server/server/platform/codex/codex-serena.js +2 -1
- package/dist/server/server/platform/codex/managed-playwright.js +48 -36
- package/dist/server/server/platform/codex/session-runtime.js +134 -4
- package/dist/server/server/platform/git/command.js +7 -1
- package/dist/server/server/platform/host-tests/runner.js +47 -6
- package/dist/server/server/platform/kimi/kimi-session-runtime.js +41 -0
- package/dist/server/server/platform/kimi/kimi-web-server-manager.js +13 -17
- package/dist/server/server/platform/maintenance/managed-upgrade.js +2 -1
- package/dist/server/server/platform/persistence/migrate.js +24 -0
- package/dist/server/server/platform/persistence/sqlite-forget-operation-store.js +67 -0
- package/dist/server/server/platform/persistence/sqlite-session-repository.js +4 -0
- package/dist/server/server/platform/plans/org-plan-discovery.js +2 -0
- package/dist/server/server/platform/plans/plan-measurement-command.js +5 -1
- package/dist/server/server/platform/retrieval/codex-xerj.js +8 -1
- package/dist/server/server/platform/retrieval/managed-xerj.js +2 -1
- package/dist/server/server/platform/retrieval/repository-readiness.js +2 -1
- package/dist/server/server/platform/retrieval/xerj-indexer.js +21 -11
- package/dist/server/server/platform/scratch/child-environment.js +21 -0
- package/dist/server/server/platform/scratch/containment-fence.js +262 -0
- package/dist/server/server/platform/scratch/filesystem-scratch-cleanup.js +245 -0
- package/dist/server/server/platform/scratch/filesystem-session-scratch.js +360 -0
- package/dist/server/server/platform/scratch/legacy-scratch-layouts.js +22 -0
- package/dist/server/server/platform/scratch/managed-scratch-owner.js +148 -0
- package/dist/server/server/platform/scratch/owned-process-group.js +53 -0
- package/dist/server/server/platform/scratch/owner-fence.js +27 -0
- package/dist/server/server/platform/scratch/scratch-filesystem.js +53 -0
- package/dist/server/server/platform/self-debug/workspace.js +3 -0
- package/dist/server/shared/contracts/session-forget.js +6 -0
- package/dist/server/shared/contracts/tmp-cleanup.js +6 -0
- package/package.json +1 -1
- package/dist/client/assets/index-CKJWzSwH.js +0 -128
|
@@ -0,0 +1,148 @@
|
|
|
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 { lstat, readdir, realpath } from 'node:fs/promises';
|
|
7
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
8
|
+
import { mobileScratchOwnerId, privateDirectory, readMarker, scratchMarkerName, } from './scratch-filesystem.js';
|
|
9
|
+
export const scratchUuidPattern = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
|
|
10
|
+
const ownerPattern = `(?:mobile-[0-9a-f]{64}|(?:cli|service)-${scratchUuidPattern})`;
|
|
11
|
+
const ownerName = new RegExp(`^${ownerPattern}$`);
|
|
12
|
+
const removalName = new RegExp(`^\\.cleanup-(${ownerPattern})-${scratchUuidPattern}$`);
|
|
13
|
+
const isUuid = new RegExp(`^${scratchUuidPattern}$`);
|
|
14
|
+
const leaseName = new RegExp(`^(${scratchUuidPattern})\\.json$`);
|
|
15
|
+
const stableId = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/;
|
|
16
|
+
const validTime = (value) => typeof value === 'string' && Number.isFinite(Date.parse(value));
|
|
17
|
+
export function managedScratchOwnerId(name) {
|
|
18
|
+
return ownerName.test(name) ? name : removalName.exec(name)?.[1];
|
|
19
|
+
}
|
|
20
|
+
export async function canonicalScratchWorkspace(path) {
|
|
21
|
+
if (!isAbsolute(path))
|
|
22
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
|
|
23
|
+
const canonical = await realpath(path);
|
|
24
|
+
const info = await lstat(path);
|
|
25
|
+
if (canonical !== resolve(path) ||
|
|
26
|
+
!info.isDirectory() ||
|
|
27
|
+
info.isSymbolicLink() ||
|
|
28
|
+
(process.getuid && info.uid !== process.getuid()))
|
|
29
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
|
|
30
|
+
return canonical;
|
|
31
|
+
}
|
|
32
|
+
function rejectOwner() {
|
|
33
|
+
throw new Error('SCRATCH_CLEANUP_unrecognized');
|
|
34
|
+
}
|
|
35
|
+
/** Metadata recognition alone never authorizes deletion: leases, roster and fences still apply. */
|
|
36
|
+
export async function readManagedScratchOwner(directory, workspacePath, ownerId) {
|
|
37
|
+
let marker;
|
|
38
|
+
try {
|
|
39
|
+
marker = (await readMarker(join(directory, scratchMarkerName)));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error.code === 'ENOENT')
|
|
43
|
+
rejectOwner();
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
if (!marker ||
|
|
47
|
+
marker.schemaVersion !== 1 ||
|
|
48
|
+
marker.ownerId !== ownerId ||
|
|
49
|
+
marker.workspacePath !== workspacePath ||
|
|
50
|
+
!validTime(marker.createdAt) ||
|
|
51
|
+
!Array.isArray(marker.providerThreads) ||
|
|
52
|
+
marker.providerThreads.some((thread) => !thread ||
|
|
53
|
+
!['codex', 'kimi'].includes(thread.provider) ||
|
|
54
|
+
typeof thread.threadId !== 'string' ||
|
|
55
|
+
!stableId.test(thread.threadId)))
|
|
56
|
+
rejectOwner();
|
|
57
|
+
if (marker.ownerKind === 'mobile-session') {
|
|
58
|
+
if (typeof marker.sessionId !== 'string' ||
|
|
59
|
+
!stableId.test(marker.sessionId) ||
|
|
60
|
+
mobileScratchOwnerId(marker.sessionId) !== ownerId ||
|
|
61
|
+
marker.authority?.kind !== 'mobile-roster' ||
|
|
62
|
+
marker.authority.sessionId !== marker.sessionId)
|
|
63
|
+
rejectOwner();
|
|
64
|
+
}
|
|
65
|
+
else if (marker.ownerKind === 'cli-session' || marker.ownerKind === 'workspace-service') {
|
|
66
|
+
const prefix = marker.ownerKind === 'cli-session' ? 'cli-' : 'service-';
|
|
67
|
+
if (!ownerId.startsWith(prefix) ||
|
|
68
|
+
marker.sessionId !== ownerId ||
|
|
69
|
+
marker.authority?.kind !== 'lease' ||
|
|
70
|
+
!isUuid.test(marker.authority.leaseId ?? ''))
|
|
71
|
+
rejectOwner();
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
rejectOwner();
|
|
75
|
+
return marker;
|
|
76
|
+
}
|
|
77
|
+
/** Attribution is read-only; it does not prove release or supply deletion authority. */
|
|
78
|
+
export async function readManagedScratchAttribution(directory, allowRetired = false) {
|
|
79
|
+
const container = dirname(directory);
|
|
80
|
+
const temporary = dirname(container);
|
|
81
|
+
const name = basename(directory);
|
|
82
|
+
const ownerId = managedScratchOwnerId(name);
|
|
83
|
+
if (basename(container) !== 'sessions' ||
|
|
84
|
+
basename(temporary) !== 'tmp' ||
|
|
85
|
+
!ownerId ||
|
|
86
|
+
(!allowRetired && ownerId !== name))
|
|
87
|
+
rejectOwner();
|
|
88
|
+
const workspacePath = dirname(temporary);
|
|
89
|
+
await canonicalScratchWorkspace(workspacePath);
|
|
90
|
+
const info = await lstat(temporary);
|
|
91
|
+
if (!info.isDirectory() ||
|
|
92
|
+
info.isSymbolicLink() ||
|
|
93
|
+
(await realpath(temporary)) !== temporary ||
|
|
94
|
+
(process.getuid && info.uid !== process.getuid()))
|
|
95
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
|
|
96
|
+
await privateDirectory(container, false);
|
|
97
|
+
await privateDirectory(directory, false);
|
|
98
|
+
const marker = await readManagedScratchOwner(directory, workspacePath, ownerId);
|
|
99
|
+
return { directory, workspacePath, ownerId, marker };
|
|
100
|
+
}
|
|
101
|
+
function rejectLease() {
|
|
102
|
+
throw new Error('SESSION_SCRATCH_LEASE_INVALID');
|
|
103
|
+
}
|
|
104
|
+
export async function readManagedScratchLeases(directory, marker) {
|
|
105
|
+
if (!(await readdir(directory)).includes('leases')) {
|
|
106
|
+
if (marker.ownerKind !== 'mobile-session')
|
|
107
|
+
rejectLease();
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const leases = join(directory, 'leases');
|
|
111
|
+
await privateDirectory(leases, false);
|
|
112
|
+
const records = [];
|
|
113
|
+
for (const name of await readdir(leases)) {
|
|
114
|
+
const leaseId = leaseName.exec(name)?.[1];
|
|
115
|
+
if (!leaseId)
|
|
116
|
+
rejectLease();
|
|
117
|
+
const value = (await readMarker(join(leases, name)));
|
|
118
|
+
if (!value ||
|
|
119
|
+
value.schemaVersion !== 1 ||
|
|
120
|
+
value.ownerId !== marker.ownerId ||
|
|
121
|
+
value.workspacePath !== marker.workspacePath ||
|
|
122
|
+
value.leaseId !== leaseId ||
|
|
123
|
+
typeof value.processIdentity !== 'string' ||
|
|
124
|
+
!isUuid.test(value.processIdentity) ||
|
|
125
|
+
!validTime(value.createdAt) ||
|
|
126
|
+
!validTime(value.updatedAt) ||
|
|
127
|
+
!['active', 'released'].includes(value.state) ||
|
|
128
|
+
!Array.isArray(value.consumers) ||
|
|
129
|
+
!value.consumers.every((consumer) => typeof consumer === 'string' && stableId.test(consumer)) ||
|
|
130
|
+
(value.state === 'released' && value.consumers.length !== 0))
|
|
131
|
+
rejectLease();
|
|
132
|
+
records.push(value);
|
|
133
|
+
}
|
|
134
|
+
if (marker.ownerKind !== 'mobile-session' &&
|
|
135
|
+
!records.some((lease) => lease.leaseId === marker.authority.leaseId))
|
|
136
|
+
rejectLease();
|
|
137
|
+
return records;
|
|
138
|
+
}
|
|
139
|
+
/** Discovery excludes only attributed scratch; unknown/plain directories remain discoverable. */
|
|
140
|
+
export async function isManagedScratchOwnerDirectory(directory) {
|
|
141
|
+
try {
|
|
142
|
+
await readManagedScratchAttribution(directory, true);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { setTimeout as delay } from 'node:timers/promises';
|
|
7
|
+
/** Only for a group created by this runtime with detached:true; never persisted PIDs. */
|
|
8
|
+
export async function stopOwnedProcessGroup(child, graceMs = 2000, confirmationMs = 1000) {
|
|
9
|
+
if (process.platform === 'win32')
|
|
10
|
+
return false;
|
|
11
|
+
if (!child.pid) {
|
|
12
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
13
|
+
child.kill('SIGTERM');
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const group = -child.pid;
|
|
17
|
+
const signal = (value) => {
|
|
18
|
+
try {
|
|
19
|
+
process.kill(group, value);
|
|
20
|
+
return 'present';
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return error.code === 'ESRCH' ? 'absent' : 'unknown';
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const wait = async (timeout) => {
|
|
27
|
+
const deadline = Date.now() + timeout;
|
|
28
|
+
for (;;) {
|
|
29
|
+
const status = signal(0);
|
|
30
|
+
if (status !== 'present')
|
|
31
|
+
return status;
|
|
32
|
+
if (Date.now() >= deadline)
|
|
33
|
+
return 'present';
|
|
34
|
+
await delay(Math.min(20, deadline - Date.now()));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// Once the leader was already reaped, its numeric group ID may have been reused.
|
|
38
|
+
// Read-only absence can prove release; a present group cannot prove ownership.
|
|
39
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
40
|
+
return (await wait(confirmationMs)) === 'absent';
|
|
41
|
+
const term = signal('SIGTERM');
|
|
42
|
+
if (term !== 'present')
|
|
43
|
+
return term === 'absent';
|
|
44
|
+
const graceful = await wait(graceMs);
|
|
45
|
+
if (graceful !== 'present')
|
|
46
|
+
return graceful === 'absent';
|
|
47
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
48
|
+
return (await wait(confirmationMs)) === 'absent';
|
|
49
|
+
const forced = signal('SIGKILL');
|
|
50
|
+
if (forced !== 'present')
|
|
51
|
+
return forced === 'absent';
|
|
52
|
+
return (await wait(confirmationMs)) === 'absent';
|
|
53
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { lstat, mkdir, rmdir } from 'node:fs/promises';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
/** An absent fence can be claimed; an existing one is never retired by age or PID. */
|
|
9
|
+
export async function claimOwnerFence(directory) {
|
|
10
|
+
const path = join(directory, '.controller-lock');
|
|
11
|
+
try {
|
|
12
|
+
await mkdir(path, { mode: 0o700 });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error.code === 'EEXIST')
|
|
16
|
+
throw new Error('SESSION_SCRATCH_BUSY');
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
const identity = await lstat(path);
|
|
20
|
+
return async (at = directory) => {
|
|
21
|
+
const currentPath = join(at, '.controller-lock');
|
|
22
|
+
const current = await lstat(currentPath);
|
|
23
|
+
if (current.dev !== identity.dev || current.ino !== identity.ino || !current.isDirectory())
|
|
24
|
+
throw new Error('SESSION_SCRATCH_FENCE_CHANGED');
|
|
25
|
+
await rmdir(currentPath);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { createHash } from 'node:crypto';
|
|
7
|
+
import { constants } from 'node:fs';
|
|
8
|
+
import { lstat, mkdir, open, realpath } from 'node:fs/promises';
|
|
9
|
+
export const scratchMarkerName = '.gestalt-owner.json';
|
|
10
|
+
export const scratchContextVariable = 'GESTALT_SESSION_TMP_CONTEXT';
|
|
11
|
+
export function mobileScratchOwnerId(sessionId) {
|
|
12
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(sessionId))
|
|
13
|
+
throw new Error('SESSION_SCRATCH_INVALID_ID');
|
|
14
|
+
return `mobile-${createHash('sha256').update(sessionId).digest('hex')}`;
|
|
15
|
+
}
|
|
16
|
+
/** Reject links and foreign directories; never repair their permissions or contents. */
|
|
17
|
+
export async function privateDirectory(path, create) {
|
|
18
|
+
let created = false;
|
|
19
|
+
if (create) {
|
|
20
|
+
try {
|
|
21
|
+
await mkdir(path, { mode: 0o700 });
|
|
22
|
+
created = true;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code !== 'EEXIST')
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const info = await lstat(path);
|
|
30
|
+
if (!info.isDirectory() || info.isSymbolicLink() || (await realpath(path)) !== path)
|
|
31
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
|
|
32
|
+
if (process.getuid && info.uid !== process.getuid())
|
|
33
|
+
throw new Error('SESSION_SCRATCH_FOREIGN_OWNER');
|
|
34
|
+
if (process.platform !== 'win32' && (info.mode & 0o777) !== 0o700)
|
|
35
|
+
throw new Error('SESSION_SCRATCH_NOT_PRIVATE');
|
|
36
|
+
return created;
|
|
37
|
+
}
|
|
38
|
+
export async function readMarker(path) {
|
|
39
|
+
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
40
|
+
try {
|
|
41
|
+
const info = await handle.stat();
|
|
42
|
+
if (!info.isFile() ||
|
|
43
|
+
info.nlink !== 1 ||
|
|
44
|
+
info.size > 16384 ||
|
|
45
|
+
(process.getuid && info.uid !== process.getuid()) ||
|
|
46
|
+
(process.platform !== 'win32' && (info.mode & 0o077) !== 0))
|
|
47
|
+
throw new Error('SESSION_SCRATCH_UNSAFE_MARKER');
|
|
48
|
+
return JSON.parse(await handle.readFile('utf8'));
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await handle.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -7,6 +7,7 @@ import { execFile } from 'node:child_process';
|
|
|
7
7
|
import { lstat, mkdir, readFile, realpath, writeFile } from 'node:fs/promises';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { promisify } from 'node:util';
|
|
10
|
+
import { withoutSessionScratch } from '../scratch/child-environment.js';
|
|
10
11
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
11
12
|
import { exportControlPlaneTrace } from '../../features/control-plane-trace/export-trace.js';
|
|
12
13
|
import { z } from 'zod';
|
|
@@ -72,10 +73,12 @@ export class SelfDebugWorkspace {
|
|
|
72
73
|
if (!exists)
|
|
73
74
|
await exec('git', ['clone', '--', `https://github.com/dyne/${name}.git`, destination], {
|
|
74
75
|
timeout: 120_000,
|
|
76
|
+
env: withoutSessionScratch(),
|
|
75
77
|
maxBuffer: 1024 * 1024,
|
|
76
78
|
});
|
|
77
79
|
const origin = await exec('git', ['-C', destination, 'remote', 'get-url', 'origin'], {
|
|
78
80
|
timeout: 10_000,
|
|
81
|
+
env: withoutSessionScratch(),
|
|
79
82
|
});
|
|
80
83
|
if (!new RegExp(`^(?:https://github\\.com/dyne/|git@github\\.com:dyne/)${name}(?:\\.git)?$`).test(origin.stdout.trim()))
|
|
81
84
|
throw new Error('DEBUG_REPOSITORY_ORIGIN_INVALID');
|