@lifeaitools/clauth 1.19.4 → 1.30.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 +126 -109
- package/cli/commands/agent-pool.js +1946 -1745
- package/cli/commands/serve/tools/fs.js +1055 -0
- package/cli/commands/serve.js +12214 -12118
- package/cli/studio-debug.js +468 -32
- package/cli/webdav-service.js +339 -0
- package/package.json +68 -65
- package/scripts/bin/bootstrap-linux +0 -0
- package/scripts/bin/bootstrap-macos +0 -0
- package/scripts/bin/bootstrap-win.exe +0 -0
- package/scripts/postinstall.js +189 -164
package/scripts/postinstall.js
CHANGED
|
@@ -1,164 +1,189 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// scripts/postinstall.js
|
|
3
|
-
// Runs after npm install -g @lifeaitools/clauth
|
|
4
|
-
// On Windows: writes watchdog.ps1 to %APPDATA%\clauth\ and registers
|
|
5
|
-
// the Task Scheduler job via UAC elevation.
|
|
6
|
-
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import os from "os";
|
|
10
|
-
import { fileURLToPath } from "url";
|
|
11
|
-
import { spawnSync } from "child_process";
|
|
12
|
-
|
|
13
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
const APPDATA = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
15
|
-
const CLAUTH_DIR = path.join(APPDATA, "clauth");
|
|
16
|
-
const DEST_PS1 = path.join(CLAUTH_DIR, "watchdog.ps1");
|
|
17
|
-
const SOURCE_PS1 = path.join(__dirname, "..", "cli", "assets", "watchdog.ps1");
|
|
18
|
-
const PS_EXE = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
|
19
|
-
const TASK_NAME = "ClautWatchdog";
|
|
20
|
-
|
|
21
|
-
const CONFIG_DIR = os.platform() === "win32"
|
|
22
|
-
? path.join(APPDATA, "clauth-nodejs", "Config")
|
|
23
|
-
: path.join(os.homedir(), ".config", "clauth-nodejs");
|
|
24
|
-
|
|
25
|
-
let version = "1.0.0";
|
|
26
|
-
try {
|
|
27
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
|
|
28
|
-
version = pkg.version;
|
|
29
|
-
} catch {}
|
|
30
|
-
|
|
31
|
-
// ----------------------------------------------------------------
|
|
32
|
-
// Watchdog helpers (Windows only)
|
|
33
|
-
// ----------------------------------------------------------------
|
|
34
|
-
|
|
35
|
-
function writeWatchdogScript() {
|
|
36
|
-
try {
|
|
37
|
-
fs.mkdirSync(CLAUTH_DIR, { recursive: true });
|
|
38
|
-
fs.copyFileSync(SOURCE_PS1, DEST_PS1);
|
|
39
|
-
return true;
|
|
40
|
-
} catch (err) {
|
|
41
|
-
console.log(` ! Could not write watchdog script: ${err.message}`);
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function isWatchdogRegistered() {
|
|
47
|
-
try {
|
|
48
|
-
const r = spawnSync(PS_EXE, [
|
|
49
|
-
"-NoProfile", "-Command",
|
|
50
|
-
`(Get-ScheduledTask -TaskName '${TASK_NAME}' -ErrorAction SilentlyContinue) -ne $null`,
|
|
51
|
-
], { encoding: "utf8", stdio: ["pipe","pipe","pipe"], timeout: 5000 });
|
|
52
|
-
return (r.stdout || "").trim().toLowerCase() === "true";
|
|
53
|
-
} catch { return false; }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function registerWatchdog() {
|
|
57
|
-
const escaped = DEST_PS1.replace(/'/g, "''");
|
|
58
|
-
const psCmd = [
|
|
59
|
-
`$a = New-ScheduledTaskAction -Execute 'powershell.exe'`,
|
|
60
|
-
` -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \\"${escaped}\\"';`,
|
|
61
|
-
`$t = New-ScheduledTaskTrigger -AtLogOn;`,
|
|
62
|
-
`$s = New-ScheduledTaskSettingsSet -ExecutionTimeLimit 0 -RestartCount 3`,
|
|
63
|
-
` -RestartInterval (New-TimeSpan -Minutes 1) -MultipleInstances IgnoreNew;`,
|
|
64
|
-
`Unregister-ScheduledTask -TaskName '${TASK_NAME}' -Confirm:$false -ErrorAction SilentlyContinue;`,
|
|
65
|
-
`Register-ScheduledTask -TaskName '${TASK_NAME}' -Action $a -Trigger $t`,
|
|
66
|
-
` -Settings $s -RunLevel Highest -Description 'clauth daemon watchdog';`,
|
|
67
|
-
].join(" ");
|
|
68
|
-
|
|
69
|
-
// Try direct first (works if already running as Administrator)
|
|
70
|
-
const direct = spawnSync(PS_EXE, [
|
|
71
|
-
"-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", psCmd,
|
|
72
|
-
], { encoding: "utf8", stdio: ["pipe","pipe","pipe"], timeout: 10000 });
|
|
73
|
-
|
|
74
|
-
if (direct.status === 0) return "ok";
|
|
75
|
-
|
|
76
|
-
// Trigger UAC elevation — opens the Windows approval dialog
|
|
77
|
-
const inner = psCmd.replace(/"/g, '\\"');
|
|
78
|
-
const elevated = spawnSync(PS_EXE, [
|
|
79
|
-
"-NoProfile", "-Command",
|
|
80
|
-
`Start-Process '${PS_EXE}' -Verb RunAs -Wait -ArgumentList '-NoProfile -ExecutionPolicy Bypass -Command "${inner}"'`,
|
|
81
|
-
], { stdio: "inherit", encoding: "utf8", timeout: 60000 });
|
|
82
|
-
|
|
83
|
-
return elevated.status === 0 ? "ok" : "denied";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function startWatchdog() {
|
|
87
|
-
spawnSync(PS_EXE, [
|
|
88
|
-
"-NoProfile", "-Command",
|
|
89
|
-
`Start-ScheduledTask -TaskName '${TASK_NAME}' -ErrorAction SilentlyContinue`,
|
|
90
|
-
], { stdio: "pipe", timeout: 5000 });
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function installCodevelopTerminalProfiles() {
|
|
94
|
-
const cli = path.join(__dirname, "..", "cli", "index.js");
|
|
95
|
-
const result = spawnSync(process.execPath, [
|
|
96
|
-
cli,
|
|
97
|
-
"codevelop",
|
|
98
|
-
"install-terminal",
|
|
99
|
-
"--repo",
|
|
100
|
-
"C:\\Dev\\regen-root",
|
|
101
|
-
], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 10000 });
|
|
102
|
-
|
|
103
|
-
if (result.status === 0) {
|
|
104
|
-
console.log(" ✓ Co-development Windows Terminal profiles installed");
|
|
105
|
-
} else {
|
|
106
|
-
const msg = (result.stderr || result.stdout || "").trim();
|
|
107
|
-
console.log(` ! Co-development terminal profile install skipped${msg ? `: ${msg}` : ""}`);
|
|
108
|
-
console.log(" Install later with: clauth codevelop install-terminal --repo C:\\Dev\\regen-root");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ----------------------------------------------------------------
|
|
113
|
-
// Main
|
|
114
|
-
// ----------------------------------------------------------------
|
|
115
|
-
|
|
116
|
-
async function main() {
|
|
117
|
-
const configPath = path.join(CONFIG_DIR, "config.json");
|
|
118
|
-
const isUpgrade = fs.existsSync(configPath);
|
|
119
|
-
|
|
120
|
-
if (isUpgrade) {
|
|
121
|
-
console.log(`\n \u2713 clauth upgraded to v${version}`);
|
|
122
|
-
console.log(` \u2713 Config preserved at ${CONFIG_DIR}`);
|
|
123
|
-
try {
|
|
124
|
-
const controller = new AbortController();
|
|
125
|
-
const to = setTimeout(() => controller.abort(), 2000);
|
|
126
|
-
const res = await fetch("http://127.0.0.1:52437/ping", { signal: controller.signal });
|
|
127
|
-
clearTimeout(to);
|
|
128
|
-
if (res.ok) console.log(" \u21BB Daemon running \u2014 restart: clauth serve restart");
|
|
129
|
-
} catch {
|
|
130
|
-
console.log(" \u25CB Daemon not running");
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
console.log(`\n Welcome to clauth v${version}!`);
|
|
134
|
-
console.log(" Run 'clauth install' to set up your vault");
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Windows: register watchdog on fresh install; refresh script on upgrade
|
|
138
|
-
if (os.platform() === "win32") {
|
|
139
|
-
const registered = isWatchdogRegistered();
|
|
140
|
-
if (!registered) {
|
|
141
|
-
console.log("\n Setting up auto-restart watchdog...");
|
|
142
|
-
console.log(" Windows will ask for administrator approval \u2014 please click Yes.\n");
|
|
143
|
-
if (writeWatchdogScript()) {
|
|
144
|
-
const result = registerWatchdog();
|
|
145
|
-
if (result === "ok") {
|
|
146
|
-
startWatchdog();
|
|
147
|
-
console.log(" \u2713 Watchdog registered and started (Task: ClautWatchdog)");
|
|
148
|
-
console.log(` \u2713 Script: ${DEST_PS1}`);
|
|
149
|
-
} else {
|
|
150
|
-
console.log(" ! Watchdog registration skipped (approval denied).");
|
|
151
|
-
console.log(" Install later with: clauth watchdog install");
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
writeWatchdogScript(); // refresh script on upgrade
|
|
156
|
-
console.log(" \u2713 Watchdog script updated");
|
|
157
|
-
}
|
|
158
|
-
installCodevelopTerminalProfiles();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// scripts/postinstall.js
|
|
3
|
+
// Runs after npm install -g @lifeaitools/clauth
|
|
4
|
+
// On Windows: writes watchdog.ps1 to %APPDATA%\clauth\ and registers
|
|
5
|
+
// the Task Scheduler job via UAC elevation.
|
|
6
|
+
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import os from "os";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import { spawnSync } from "child_process";
|
|
12
|
+
|
|
13
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const APPDATA = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
15
|
+
const CLAUTH_DIR = path.join(APPDATA, "clauth");
|
|
16
|
+
const DEST_PS1 = path.join(CLAUTH_DIR, "watchdog.ps1");
|
|
17
|
+
const SOURCE_PS1 = path.join(__dirname, "..", "cli", "assets", "watchdog.ps1");
|
|
18
|
+
const PS_EXE = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
|
19
|
+
const TASK_NAME = "ClautWatchdog";
|
|
20
|
+
|
|
21
|
+
const CONFIG_DIR = os.platform() === "win32"
|
|
22
|
+
? path.join(APPDATA, "clauth-nodejs", "Config")
|
|
23
|
+
: path.join(os.homedir(), ".config", "clauth-nodejs");
|
|
24
|
+
|
|
25
|
+
let version = "1.0.0";
|
|
26
|
+
try {
|
|
27
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
|
|
28
|
+
version = pkg.version;
|
|
29
|
+
} catch {}
|
|
30
|
+
|
|
31
|
+
// ----------------------------------------------------------------
|
|
32
|
+
// Watchdog helpers (Windows only)
|
|
33
|
+
// ----------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
function writeWatchdogScript() {
|
|
36
|
+
try {
|
|
37
|
+
fs.mkdirSync(CLAUTH_DIR, { recursive: true });
|
|
38
|
+
fs.copyFileSync(SOURCE_PS1, DEST_PS1);
|
|
39
|
+
return true;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.log(` ! Could not write watchdog script: ${err.message}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isWatchdogRegistered() {
|
|
47
|
+
try {
|
|
48
|
+
const r = spawnSync(PS_EXE, [
|
|
49
|
+
"-NoProfile", "-Command",
|
|
50
|
+
`(Get-ScheduledTask -TaskName '${TASK_NAME}' -ErrorAction SilentlyContinue) -ne $null`,
|
|
51
|
+
], { encoding: "utf8", stdio: ["pipe","pipe","pipe"], timeout: 5000 });
|
|
52
|
+
return (r.stdout || "").trim().toLowerCase() === "true";
|
|
53
|
+
} catch { return false; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function registerWatchdog() {
|
|
57
|
+
const escaped = DEST_PS1.replace(/'/g, "''");
|
|
58
|
+
const psCmd = [
|
|
59
|
+
`$a = New-ScheduledTaskAction -Execute 'powershell.exe'`,
|
|
60
|
+
` -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \\"${escaped}\\"';`,
|
|
61
|
+
`$t = New-ScheduledTaskTrigger -AtLogOn;`,
|
|
62
|
+
`$s = New-ScheduledTaskSettingsSet -ExecutionTimeLimit 0 -RestartCount 3`,
|
|
63
|
+
` -RestartInterval (New-TimeSpan -Minutes 1) -MultipleInstances IgnoreNew;`,
|
|
64
|
+
`Unregister-ScheduledTask -TaskName '${TASK_NAME}' -Confirm:$false -ErrorAction SilentlyContinue;`,
|
|
65
|
+
`Register-ScheduledTask -TaskName '${TASK_NAME}' -Action $a -Trigger $t`,
|
|
66
|
+
` -Settings $s -RunLevel Highest -Description 'clauth daemon watchdog';`,
|
|
67
|
+
].join(" ");
|
|
68
|
+
|
|
69
|
+
// Try direct first (works if already running as Administrator)
|
|
70
|
+
const direct = spawnSync(PS_EXE, [
|
|
71
|
+
"-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", psCmd,
|
|
72
|
+
], { encoding: "utf8", stdio: ["pipe","pipe","pipe"], timeout: 10000 });
|
|
73
|
+
|
|
74
|
+
if (direct.status === 0) return "ok";
|
|
75
|
+
|
|
76
|
+
// Trigger UAC elevation — opens the Windows approval dialog
|
|
77
|
+
const inner = psCmd.replace(/"/g, '\\"');
|
|
78
|
+
const elevated = spawnSync(PS_EXE, [
|
|
79
|
+
"-NoProfile", "-Command",
|
|
80
|
+
`Start-Process '${PS_EXE}' -Verb RunAs -Wait -ArgumentList '-NoProfile -ExecutionPolicy Bypass -Command "${inner}"'`,
|
|
81
|
+
], { stdio: "inherit", encoding: "utf8", timeout: 60000 });
|
|
82
|
+
|
|
83
|
+
return elevated.status === 0 ? "ok" : "denied";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function startWatchdog() {
|
|
87
|
+
spawnSync(PS_EXE, [
|
|
88
|
+
"-NoProfile", "-Command",
|
|
89
|
+
`Start-ScheduledTask -TaskName '${TASK_NAME}' -ErrorAction SilentlyContinue`,
|
|
90
|
+
], { stdio: "pipe", timeout: 5000 });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function installCodevelopTerminalProfiles() {
|
|
94
|
+
const cli = path.join(__dirname, "..", "cli", "index.js");
|
|
95
|
+
const result = spawnSync(process.execPath, [
|
|
96
|
+
cli,
|
|
97
|
+
"codevelop",
|
|
98
|
+
"install-terminal",
|
|
99
|
+
"--repo",
|
|
100
|
+
"C:\\Dev\\regen-root",
|
|
101
|
+
], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 10000 });
|
|
102
|
+
|
|
103
|
+
if (result.status === 0) {
|
|
104
|
+
console.log(" ✓ Co-development Windows Terminal profiles installed");
|
|
105
|
+
} else {
|
|
106
|
+
const msg = (result.stderr || result.stdout || "").trim();
|
|
107
|
+
console.log(` ! Co-development terminal profile install skipped${msg ? `: ${msg}` : ""}`);
|
|
108
|
+
console.log(" Install later with: clauth codevelop install-terminal --repo C:\\Dev\\regen-root");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ----------------------------------------------------------------
|
|
113
|
+
// Main
|
|
114
|
+
// ----------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
async function main() {
|
|
117
|
+
const configPath = path.join(CONFIG_DIR, "config.json");
|
|
118
|
+
const isUpgrade = fs.existsSync(configPath);
|
|
119
|
+
|
|
120
|
+
if (isUpgrade) {
|
|
121
|
+
console.log(`\n \u2713 clauth upgraded to v${version}`);
|
|
122
|
+
console.log(` \u2713 Config preserved at ${CONFIG_DIR}`);
|
|
123
|
+
try {
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
const to = setTimeout(() => controller.abort(), 2000);
|
|
126
|
+
const res = await fetch("http://127.0.0.1:52437/ping", { signal: controller.signal });
|
|
127
|
+
clearTimeout(to);
|
|
128
|
+
if (res.ok) console.log(" \u21BB Daemon running \u2014 restart: clauth serve restart");
|
|
129
|
+
} catch {
|
|
130
|
+
console.log(" \u25CB Daemon not running");
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
console.log(`\n Welcome to clauth v${version}!`);
|
|
134
|
+
console.log(" Run 'clauth install' to set up your vault");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Windows: register watchdog on fresh install; refresh script on upgrade
|
|
138
|
+
if (os.platform() === "win32") {
|
|
139
|
+
const registered = isWatchdogRegistered();
|
|
140
|
+
if (!registered) {
|
|
141
|
+
console.log("\n Setting up auto-restart watchdog...");
|
|
142
|
+
console.log(" Windows will ask for administrator approval \u2014 please click Yes.\n");
|
|
143
|
+
if (writeWatchdogScript()) {
|
|
144
|
+
const result = registerWatchdog();
|
|
145
|
+
if (result === "ok") {
|
|
146
|
+
startWatchdog();
|
|
147
|
+
console.log(" \u2713 Watchdog registered and started (Task: ClautWatchdog)");
|
|
148
|
+
console.log(` \u2713 Script: ${DEST_PS1}`);
|
|
149
|
+
} else {
|
|
150
|
+
console.log(" ! Watchdog registration skipped (approval denied).");
|
|
151
|
+
console.log(" Install later with: clauth watchdog install");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
writeWatchdogScript(); // refresh script on upgrade
|
|
156
|
+
console.log(" \u2713 Watchdog script updated");
|
|
157
|
+
}
|
|
158
|
+
installCodevelopTerminalProfiles();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Windows: install dependencies via winget if not already present
|
|
162
|
+
if (os.platform() === "win32") {
|
|
163
|
+
const deps = [
|
|
164
|
+
{ cmd: "rclone", args: ["version"], wingetId: "Rclone.Rclone", label: "rclone (WebDAV bridge)" },
|
|
165
|
+
{ cmd: "pwsh", args: ["--version"], wingetId: "Microsoft.PowerShell", label: "PowerShell 7 (fs_exec shell)" },
|
|
166
|
+
];
|
|
167
|
+
for (const dep of deps) {
|
|
168
|
+
const check = spawnSync(dep.cmd, dep.args, { stdio: "pipe", timeout: 5000, windowsHide: true });
|
|
169
|
+
if (check.status === 0) {
|
|
170
|
+
console.log(` ✓ ${dep.label} already installed`);
|
|
171
|
+
} else {
|
|
172
|
+
console.log(` Installing ${dep.label}...`);
|
|
173
|
+
const r = spawnSync("winget", [
|
|
174
|
+
"install", "--id", dep.wingetId,
|
|
175
|
+
"--silent", "--accept-package-agreements", "--accept-source-agreements",
|
|
176
|
+
], { stdio: "inherit", timeout: 120000 });
|
|
177
|
+
if (r.status === 0) {
|
|
178
|
+
console.log(` ✓ ${dep.label} installed`);
|
|
179
|
+
} else {
|
|
180
|
+
console.log(` ! ${dep.label} install skipped — install manually: winget install ${dep.wingetId}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log(" Run 'clauth doctor' to verify installation\n");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
main().catch(() => {});
|