@happyvertical/smrt-template-sveltekit 0.43.10 → 0.44.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/AGENTS.md +31 -6
- package/README.md +26 -10
- package/index.js +53 -2
- package/package.json +19 -5
- package/template/.dockerignore +12 -0
- package/template/.env.cloud.example +9 -0
- package/template/.env.example +15 -3
- package/template/.env.self-hosted.example +11 -0
- package/template/AGENTS.md +32 -0
- package/template/Dockerfile +23 -0
- package/template/INSTALL_PROMPT.md +11 -0
- package/template/README.md +74 -32
- package/template/compose.yaml +56 -0
- package/template/gitignore.template +45 -0
- package/template/package.json +30 -15
- package/template/scripts/smrt-app.mjs +884 -0
- package/template/scripts/smrt-operation-lock.mjs +102 -0
- package/template/scripts/smrt-portability-assets.mjs +707 -0
- package/template/scripts/smrt-portability.mjs +470 -0
- package/template/scripts/smrt-prepare-migration.mjs +93 -0
- package/template/scripts/smrt-process.mjs +82 -0
- package/template/scripts/smrt-provider-readiness.mjs +33 -0
- package/template/scripts/smrt-runtime-identity.mjs +238 -0
- package/template/scripts/smrt-vite.mjs +45 -0
- package/template/scripts/smrt-web.mjs +10 -0
- package/template/scripts/smrt-worker.mjs +86 -0
- package/template/scripts/smrt-writer-lease.mjs +199 -0
- package/template/smrt.config.ts +34 -2
- package/template/src/hooks.server.ts +4 -1
- package/template/src/lib/RuntimeDiagnosticsWebMcp.svelte +11 -0
- package/template/src/lib/runtime-diagnostics-webmcp.ts +108 -0
- package/template/src/lib/server/application-runtime.ts +262 -0
- package/template/src/lib/server/runtime-diagnostics.ts +114 -0
- package/template/src/lib/server/smrt.ts +4 -4
- package/template/src/routes/+layout.svelte +2 -0
- package/template/src/routes/api/_runtime/diagnostics/+server.ts +5 -0
- package/template/src/routes/api/_runtime/health/+server.ts +30 -0
- package/template/src/routes/setup/+page.server.ts +96 -0
- package/template/src/routes/setup/+page.svelte +31 -0
- package/template/svelte.config.js +1 -1
- package/template/tsconfig.json +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
fstatSync,
|
|
5
|
+
lstatSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
} from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
function processExists(pid) {
|
|
15
|
+
try {
|
|
16
|
+
process.kill(pid, 0);
|
|
17
|
+
return true;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
// A permission boundary still proves that the process exists.
|
|
20
|
+
if (error?.code === 'EPERM' || error?.code === 'EACCES') return true;
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function withOperationLock(stateRoot, operation, callback) {
|
|
26
|
+
mkdirSync(stateRoot, { recursive: true, mode: 0o700 });
|
|
27
|
+
const path = join(stateRoot, 'operation.lock');
|
|
28
|
+
const instance = randomBytes(16).toString('hex');
|
|
29
|
+
let descriptor;
|
|
30
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
31
|
+
try {
|
|
32
|
+
descriptor = openSync(path, 'wx', 0o600);
|
|
33
|
+
try {
|
|
34
|
+
writeFileSync(
|
|
35
|
+
descriptor,
|
|
36
|
+
`${JSON.stringify({ schemaVersion: 1, pid: process.pid, operation, instance })}\n`,
|
|
37
|
+
);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
closeSync(descriptor);
|
|
40
|
+
descriptor = undefined;
|
|
41
|
+
rmSync(path, { force: true });
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error?.code !== 'EEXIST') throw error;
|
|
47
|
+
let ownerPid = null;
|
|
48
|
+
let staleIdentity;
|
|
49
|
+
let staleDescriptor;
|
|
50
|
+
try {
|
|
51
|
+
staleDescriptor = openSync(path, 'r');
|
|
52
|
+
staleIdentity = fstatSync(staleDescriptor);
|
|
53
|
+
ownerPid = JSON.parse(readFileSync(staleDescriptor, 'utf8')).pid;
|
|
54
|
+
} catch {
|
|
55
|
+
// A malformed partial lock has no authority.
|
|
56
|
+
} finally {
|
|
57
|
+
if (staleDescriptor !== undefined) closeSync(staleDescriptor);
|
|
58
|
+
}
|
|
59
|
+
if (!Number.isSafeInteger(ownerPid)) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'An application operation lock exists but cannot be verified; inspect the private state directory.',
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (processExists(ownerPid)) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Another application operation is active (process ${ownerPid}).`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const currentIdentity = lstatSync(path);
|
|
71
|
+
if (
|
|
72
|
+
!staleIdentity ||
|
|
73
|
+
currentIdentity.dev !== staleIdentity.dev ||
|
|
74
|
+
currentIdentity.ino !== staleIdentity.ino
|
|
75
|
+
) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
rmSync(path);
|
|
79
|
+
} catch (removeError) {
|
|
80
|
+
if (removeError?.code !== 'ENOENT') throw removeError;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (descriptor === undefined) {
|
|
85
|
+
throw new Error('The application operation lock could not be acquired.');
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return await callback({ instance, path });
|
|
89
|
+
} finally {
|
|
90
|
+
closeSync(descriptor);
|
|
91
|
+
// Do not unlink a replacement lock if an operator repaired this one while
|
|
92
|
+
// the operation was active.
|
|
93
|
+
try {
|
|
94
|
+
const current = JSON.parse(readFileSync(path, 'utf8'));
|
|
95
|
+
if (current.pid === process.pid && current.instance === instance) {
|
|
96
|
+
rmSync(path, { force: true });
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
// A missing or externally repaired lock is not ours to remove.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|