cotal-ai 0.164.12 → 0.164.14
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/daemon/auto-update.js +62 -3
- package/dist/daemon/command.js +8 -2
- package/dist/daemon/desktop-path.js +17 -4
- package/dist/daemon/desktop-setup.js +33 -0
- package/dist/daemon/desktop.js +76 -16
- package/dist/daemon/install-native-run.js +6 -4
- package/dist/daemon/install-receipt.js +4 -1
- package/dist/daemon/install.js +128 -58
- package/dist/daemon/lifetime.js +19 -2
- package/dist/daemon/manager.js +149 -34
- package/dist/daemon/setup.js +5 -5
- package/dist/daemon/update-windows-activation.js +72 -0
- package/dist/daemon/update-windows-runner.js +89 -0
- package/dist/daemon/update-windows.js +234 -0
- package/package.json +19 -19
- package/seeded-connectors/_shared/docs-bundle.bin +0 -0
- package/seeded-connectors/_shared/docs-index.bin +0 -0
- package/seeded-connectors/_shared/placements.json +2 -2
- package/seeded-connectors/claude/dist/index.js +1 -1
- package/seeded-connectors/claude/dist/mcp.cjs +2 -2
- package/seeded-connectors/claude/package.json +1 -1
- package/seeded-connectors/codex/dist/host.js +2 -2
- package/seeded-connectors/codex/dist/index.js +1 -1
- package/seeded-connectors/codex/dist/personal.js +2 -2
- package/seeded-connectors/codex/package.json +1 -1
- package/seeded-connectors/hermes/dist/index.js +1 -1
- package/seeded-connectors/hermes/dist/launch.js +2 -2
- package/seeded-connectors/hermes/package.json +1 -1
- package/seeded-connectors/hermes/plugin/cotal/_sidecar/standalone.cjs +2 -2
- package/seeded-connectors/jcode/dist/host.js +2 -2
- package/seeded-connectors/jcode/dist/index.js +1 -1
- package/seeded-connectors/jcode/dist/mcp.js +1 -1
- package/seeded-connectors/jcode/package.json +1 -1
- package/seeded-connectors/opencode/dist/index.js +1 -1
- package/seeded-connectors/opencode/dist/plugin/index.js +2 -2
- package/seeded-connectors/opencode/package.json +1 -1
- package/seeded-connectors/pi/dist/index.js +2 -2
- package/seeded-connectors/pi/dist/standalone.js +2 -2
- package/seeded-connectors/pi/package.json +1 -1
- package/seeded-connectors/web/package.json +1 -1
|
@@ -4,6 +4,8 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { openPrivateAppend, writeSecretFileAtomic } from "@cotal-ai/core";
|
|
6
6
|
import { checkForUpdate, homeCotalDir, newerUpdate, readUpdateCheck, readUpdateRecovery, readUpdateSettings, recoveryDisposition, UPDATE_DAY_MS, UPDATE_HOUR_MS } from "@cotal-ai/workspace";
|
|
7
|
+
import { cleanWindowsUpdate, startWindowsUpdate } from "./update-windows.js";
|
|
8
|
+
import { WINDOWS_INTERRUPTED_UPDATE, readWindowsUpdatePause } from "@cotal-ai/workspace";
|
|
7
9
|
import { cleanLaunchUpdate, startLaunchUpdate } from "./update-launchd.js";
|
|
8
10
|
/** Schedule only the existing updater. Manager preparation holds its native empty-seat admission fence. */
|
|
9
11
|
export function automaticUpdates(host) {
|
|
@@ -20,6 +22,7 @@ export function automaticUpdates(host) {
|
|
|
20
22
|
if (error.code !== "ENOENT")
|
|
21
23
|
state = { ...state, result: "automatic updates paused: unreadable attempt record", next: Number.MAX_SAFE_INTEGER };
|
|
22
24
|
}
|
|
25
|
+
let windowsPending = process.platform === "win32" && existsSync(join(homeCotalDir(), "update-windows.json"));
|
|
23
26
|
let child, busy, closed = false, launchdPending = process.platform === "darwin" && (existsSync(join(homeCotalDir(), "update-launchd.json")) || existsSync(join(homeCotalDir(), "update-launchd-result.json")));
|
|
24
27
|
const persist = () => writeSecretFileAtomic(file, `${JSON.stringify(state)}\n`);
|
|
25
28
|
try {
|
|
@@ -43,7 +46,7 @@ export function automaticUpdates(host) {
|
|
|
43
46
|
try {
|
|
44
47
|
const settings = readUpdateSettings();
|
|
45
48
|
notify = settings.notify;
|
|
46
|
-
automatic = ["linux", "darwin"].includes(process.platform) && !desktop && settings.auto && process.env.COTAL_NO_UPDATE_CHECK !== "1" && host.eligible();
|
|
49
|
+
automatic = ["linux", "darwin", "win32"].includes(process.platform) && !desktop && settings.auto && process.env.COTAL_NO_UPDATE_CHECK !== "1" && host.eligible();
|
|
47
50
|
const recovery = readUpdateRecovery();
|
|
48
51
|
if (recovery) {
|
|
49
52
|
const decision = recoveryDisposition(recovery);
|
|
@@ -51,12 +54,31 @@ export function automaticUpdates(host) {
|
|
|
51
54
|
automatic = false;
|
|
52
55
|
reason = `automatic updates ${decision.action === "retire" ? "can resume" : "paused"}: installed ${recovery.installed}; ${recovery.reason}; ${decision.instruction}`;
|
|
53
56
|
}
|
|
57
|
+
if (process.platform === "win32" && readWindowsUpdatePause()) {
|
|
58
|
+
automatic = false;
|
|
59
|
+
reason = WINDOWS_INTERRUPTED_UPDATE;
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
62
|
catch (error) {
|
|
56
63
|
automatic = false;
|
|
57
64
|
reason = `automatic updates paused: ${String(error)}`;
|
|
58
65
|
}
|
|
59
|
-
if (
|
|
66
|
+
if (process.platform === "win32") {
|
|
67
|
+
try {
|
|
68
|
+
const activation = JSON.parse(readFileSync(join(homeCotalDir(), "update-windows-activation.json"), "utf8"));
|
|
69
|
+
if (activation?.v !== 1 || !["pending", "ready", "failed", "not-needed"].includes(activation.activation) || typeof activation.target !== "string" || !Number.isFinite(activation.deadline))
|
|
70
|
+
throw new Error("invalid Windows activation result");
|
|
71
|
+
if (activation.target === state.version && activation.activation === "failed" && !readWindowsUpdatePause())
|
|
72
|
+
reason = `release ${activation.target} installed; automatic activation failed; use Start service`;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error.code !== "ENOENT") {
|
|
76
|
+
automatic = false;
|
|
77
|
+
reason = `automatic activation status unreadable: ${String(error)}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!["linux", "darwin", "win32"].includes(process.platform))
|
|
60
82
|
reason = `${reason}. Automatic installation is unavailable on ${process.platform === "win32" ? "Windows" : process.platform} in this release. Run \`cotal update --self\` here`;
|
|
61
83
|
if (desktop)
|
|
62
84
|
reason = "update the desktop app with its signed platform installer";
|
|
@@ -81,6 +103,31 @@ export function automaticUpdates(host) {
|
|
|
81
103
|
return;
|
|
82
104
|
}
|
|
83
105
|
}
|
|
106
|
+
if (process.platform === "win32") {
|
|
107
|
+
try {
|
|
108
|
+
windowsPending = true;
|
|
109
|
+
const custody = cleanWindowsUpdate();
|
|
110
|
+
if (custody === "pending")
|
|
111
|
+
return;
|
|
112
|
+
windowsPending = false;
|
|
113
|
+
if (custody === "paused") {
|
|
114
|
+
state = { ...state, result: WINDOWS_INTERRUPTED_UPDATE, next: Number.MAX_SAFE_INTEGER };
|
|
115
|
+
persist();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const recorded = JSON.parse(readFileSync(file, "utf8"));
|
|
119
|
+
const cleared = recorded.next === Number.MAX_SAFE_INTEGER && recorded.result === WINDOWS_INTERRUPTED_UPDATE;
|
|
120
|
+
state = cleared ? { ...recorded, next: 0, result: "Windows automatic update interruption cleared" } : recorded;
|
|
121
|
+
if (cleared || custody !== "absent")
|
|
122
|
+
persist();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
state = { ...state, result: `Windows automatic update custody unresolved: ${error instanceof Error ? error.message : String(error)}`, next: Date.now() + UPDATE_HOUR_MS };
|
|
126
|
+
persist();
|
|
127
|
+
host.report(state.result);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
84
131
|
const settings = readUpdateSettings();
|
|
85
132
|
const cached = process.env.COTAL_NO_UPDATE_CHECK !== "1" && (settings.auto || settings.notify) ? await checkForUpdate() : readUpdateCheck();
|
|
86
133
|
const recovery = readUpdateRecovery();
|
|
@@ -131,6 +178,18 @@ export function automaticUpdates(host) {
|
|
|
131
178
|
return;
|
|
132
179
|
state = { ...state, failures: state.failures, result: `updating to ${cached.latest}`, next: Date.now() + UPDATE_HOUR_MS };
|
|
133
180
|
persist();
|
|
181
|
+
if (process.platform === "win32") {
|
|
182
|
+
try {
|
|
183
|
+
windowsPending = true;
|
|
184
|
+
startWindowsUpdate(state.failures);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
state = { ...state, result: `Windows automatic update handoff refused: ${error instanceof Error ? error.message : String(error)}`, next: Date.now() + UPDATE_HOUR_MS };
|
|
188
|
+
persist();
|
|
189
|
+
host.report(state.result);
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
134
193
|
if (process.platform === "darwin") {
|
|
135
194
|
try {
|
|
136
195
|
launchdPending = true;
|
|
@@ -175,7 +234,7 @@ export function automaticUpdates(host) {
|
|
|
175
234
|
busy = tick().catch(error => { host.report(`automatic update: ${String(error)}`); }).finally(() => { busy = undefined; });
|
|
176
235
|
}, 30_000);
|
|
177
236
|
timer.unref();
|
|
178
|
-
return { status, async check() { await checkForUpdate(); return status(); }, updating: () => child !== undefined || launchdPending, async close() {
|
|
237
|
+
return { status, async check() { await checkForUpdate(); return status(); }, updating: () => child !== undefined || launchdPending || windowsPending, async close() {
|
|
179
238
|
closed = true;
|
|
180
239
|
clearInterval(timer);
|
|
181
240
|
if (child) {
|
package/dist/daemon/command.js
CHANGED
|
@@ -517,9 +517,15 @@ async function serve(args) {
|
|
|
517
517
|
const { recoverInterruptedUpdate } = await import("@cotal-ai/cli/update");
|
|
518
518
|
// Unusable abandoned records retire under the updater lock. Unknown owners remain paused
|
|
519
519
|
// without blocking startup. A valid snapshot whose restoration failed still waits for repair.
|
|
520
|
+
let automaticCustodyPaused = false;
|
|
521
|
+
if (process.platform === "win32") {
|
|
522
|
+
const { cleanWindowsUpdate } = await import("./update-windows.js");
|
|
523
|
+
const disposition = cleanWindowsUpdate();
|
|
524
|
+
automaticCustodyPaused = disposition === "paused" || disposition === "pending";
|
|
525
|
+
}
|
|
520
526
|
const deferredRecovery = readUpdateRecovery();
|
|
521
|
-
const observedLiveUpdater = deferredRecovery !== undefined && liveUpdateClosureOwner(deferredRecovery);
|
|
522
|
-
if (await recoverInterruptedUpdate(undefined, true))
|
|
527
|
+
const observedLiveUpdater = !automaticCustodyPaused && deferredRecovery !== undefined && liveUpdateClosureOwner(deferredRecovery);
|
|
528
|
+
if (!automaticCustodyPaused && await recoverInterruptedUpdate(undefined, true))
|
|
523
529
|
throw new Error("interrupted update restored the previous installation; restart the daemon with the restored CLI");
|
|
524
530
|
const { paths, home } = resolveTarget(args);
|
|
525
531
|
let running;
|
|
@@ -13,6 +13,19 @@ const run = (command, args) => new Promise((resolve, reject) => {
|
|
|
13
13
|
resolve(stdout);
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
|
+
/** Keep only absolute POSIX entries for the desktop service and name any relative entries left out, in order and without duplicates. */
|
|
17
|
+
export function filterDesktopApplicationPath(raw, nodeDir) {
|
|
18
|
+
const entries = `${raw}${posix.delimiter}${nodeDir}`.split(posix.delimiter).filter((entry) => entry !== "");
|
|
19
|
+
const kept = [];
|
|
20
|
+
const omitted = [];
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
if (posix.isAbsolute(entry))
|
|
23
|
+
kept.push(entry);
|
|
24
|
+
else if (!omitted.includes(entry))
|
|
25
|
+
omitted.push(entry);
|
|
26
|
+
}
|
|
27
|
+
return { path: pinnedPath(kept.join(posix.delimiter), posix), omittedRelativeEntries: omitted };
|
|
28
|
+
}
|
|
16
29
|
/** Windows tasks do not pin PATH. Read the current machine and user values on each native start. */
|
|
17
30
|
export async function windowsApplicationPath() {
|
|
18
31
|
const root = process.env.SystemRoot ?? process.env.SYSTEMROOT;
|
|
@@ -22,10 +35,10 @@ export async function windowsApplicationPath() {
|
|
|
22
35
|
const value = await run(join(root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script]);
|
|
23
36
|
return pinnedPath(`${value};${dirname(process.execPath)}`, win32);
|
|
24
37
|
}
|
|
25
|
-
/** No renderer-supplied executable, argument, shell or environment is accepted. */
|
|
26
|
-
export async function
|
|
38
|
+
/** Discover the desktop application PATH and any relative entries left out of it. No renderer-supplied executable, argument, shell or environment is accepted. */
|
|
39
|
+
export async function discoverDesktopApplicationPath() {
|
|
27
40
|
if (process.platform === "win32")
|
|
28
|
-
return windowsApplicationPath();
|
|
41
|
+
return { path: await windowsApplicationPath(), omittedRelativeEntries: [] };
|
|
29
42
|
if (process.platform !== "linux" && process.platform !== "darwin")
|
|
30
43
|
throw new CommandFailure("refused", "UNSUPPORTED", "this OS has no desktop application discovery");
|
|
31
44
|
const shell = userInfo().shell;
|
|
@@ -36,5 +49,5 @@ export async function desktopApplicationPath() {
|
|
|
36
49
|
const parts = output.split(marker);
|
|
37
50
|
if (parts.length !== 3)
|
|
38
51
|
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the login shell returned no bounded application PATH; no service was changed");
|
|
39
|
-
return
|
|
52
|
+
return filterDesktopApplicationPath(parts[1], dirname(process.execPath));
|
|
40
53
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { CommandFailure } from "@cotal-ai/workspace/local-observation";
|
|
4
|
+
/** An incomplete desktop replacement must never be started through the service controls. */
|
|
5
|
+
export function assertDesktopSetupComplete(executable = process.execPath, localAppData = process.env.LOCALAPPDATA, platform = process.platform) {
|
|
6
|
+
if (platform !== "win32" || !localAppData)
|
|
7
|
+
return;
|
|
8
|
+
const installPath = dirname(executable);
|
|
9
|
+
let state;
|
|
10
|
+
try {
|
|
11
|
+
state = JSON.parse(readFileSync(join(localAppData, "CotalSetup", "service-update.json"), "utf8"));
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code === "ENOENT")
|
|
15
|
+
return;
|
|
16
|
+
throw new CommandFailure("refused", "CONFLICT", "Setup was interrupted or its handover could not be read. Run the installer again before starting the service.");
|
|
17
|
+
}
|
|
18
|
+
const record = state && typeof state === "object" ? state : undefined;
|
|
19
|
+
if (!record || record.schema !== 1 || typeof record.installPath !== "string")
|
|
20
|
+
throw new CommandFailure("refused", "CONFLICT", "Setup was interrupted and its handover is invalid. Run the installer again before starting the service.");
|
|
21
|
+
let sameInstallation;
|
|
22
|
+
try {
|
|
23
|
+
sameInstallation = realpathSync.native(record.installPath).toLowerCase() === realpathSync.native(installPath).toLowerCase();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new CommandFailure("refused", "CONFLICT", "Setup was interrupted and its installation folder could not be identified. Run the installer again before starting the service.");
|
|
27
|
+
}
|
|
28
|
+
if (!sameInstallation)
|
|
29
|
+
return;
|
|
30
|
+
if (record.phase === "ready")
|
|
31
|
+
return;
|
|
32
|
+
throw new CommandFailure("refused", "CONFLICT", "Setup was interrupted. Run the installer again before starting the service.");
|
|
33
|
+
}
|
package/dist/daemon/desktop.js
CHANGED
|
@@ -3,14 +3,16 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { defaultComputerName } from "./computer-name.js";
|
|
4
4
|
import { computerName } from "./name-validation.js";
|
|
5
5
|
import { arch, platform, release, totalmem } from "node:os";
|
|
6
|
-
import { CommandFailure, readUpdateSettings, setUpdateSetting } from "@cotal-ai/workspace";
|
|
6
|
+
import { CommandFailure, readLocalRecordSource, readUpdateSettings, setUpdateSetting } from "@cotal-ai/workspace";
|
|
7
7
|
import { normalizeIdpUrl } from "@cotal-ai/auth";
|
|
8
8
|
import { loginViaDaemon, updateViaDaemon, openVerified, queryDaemon, readLine } from "./client.js";
|
|
9
9
|
import { DAEMON_PROTOCOL_VERSION, MAX_LINE_BYTES, EndpointRefusal } from "./endpoint.js";
|
|
10
10
|
import { applyInstall, planUninstall, startInstalled } from "./install.js";
|
|
11
|
+
import { nativeDaemonLog } from "./native-log.js";
|
|
11
12
|
import { encode, isDaemonSpaceName } from "./protocol.js";
|
|
12
13
|
import { runSetup } from "./setup.js";
|
|
13
|
-
import {
|
|
14
|
+
import { discoverDesktopApplicationPath } from "./desktop-path.js";
|
|
15
|
+
import { assertDesktopSetupComplete } from "./desktop-setup.js";
|
|
14
16
|
/** No renderer-supplied command, path, credentials or arbitrary arguments cross this boundary. */
|
|
15
17
|
export function parseDesktopRequest(value) {
|
|
16
18
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -95,6 +97,43 @@ function serviceInstalled(target) {
|
|
|
95
97
|
return false;
|
|
96
98
|
}
|
|
97
99
|
}
|
|
100
|
+
/** Read only a startup refusal line written during this install attempt, never an earlier launch's log. */
|
|
101
|
+
function attemptStartupRefusal(state, attemptStartedAt) {
|
|
102
|
+
let bytes;
|
|
103
|
+
try {
|
|
104
|
+
bytes = readLocalRecordSource(nativeDaemonLog(state), 64 * 1024 + 128, true);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
if (!bytes)
|
|
110
|
+
return undefined;
|
|
111
|
+
const lines = bytes.toString("utf8")
|
|
112
|
+
.replace(/\u001b\[[0-9;]*[A-Za-z]/g, "")
|
|
113
|
+
.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "")
|
|
114
|
+
.replace(/eyJ[A-Za-z0-9_.-]*/g, "<redacted>")
|
|
115
|
+
.split(/\r?\n/);
|
|
116
|
+
let launchIndex = -1;
|
|
117
|
+
for (let i = 0; i < lines.length; i++) {
|
|
118
|
+
const match = /^daemon service launch (\S+)$/.exec(lines[i]);
|
|
119
|
+
if (!match)
|
|
120
|
+
continue;
|
|
121
|
+
const launchedAt = Date.parse(match[1]);
|
|
122
|
+
launchIndex = Number.isFinite(launchedAt) && launchedAt >= attemptStartedAt ? i : -1;
|
|
123
|
+
}
|
|
124
|
+
if (launchIndex < 0)
|
|
125
|
+
return undefined;
|
|
126
|
+
let refusal;
|
|
127
|
+
for (let i = launchIndex + 1; i < lines.length; i++) {
|
|
128
|
+
const line = lines[i];
|
|
129
|
+
if (!line.startsWith("daemon startup refused:"))
|
|
130
|
+
continue;
|
|
131
|
+
const reason = line.slice("daemon startup refused:".length).trim().slice(0, 500);
|
|
132
|
+
if (reason)
|
|
133
|
+
refusal = reason;
|
|
134
|
+
}
|
|
135
|
+
return refusal;
|
|
136
|
+
}
|
|
98
137
|
/** Run one app operation through the stock local client. Closing the UI never stops the service. */
|
|
99
138
|
export async function runDesktopBridge(opts) {
|
|
100
139
|
const output = opts.output ?? process.stdout;
|
|
@@ -108,6 +147,8 @@ export async function runDesktopBridge(opts) {
|
|
|
108
147
|
return;
|
|
109
148
|
}
|
|
110
149
|
let target;
|
|
150
|
+
let startedAt;
|
|
151
|
+
let omittedRelativePathEntries = [];
|
|
111
152
|
try {
|
|
112
153
|
if (req.op === "update-policy") {
|
|
113
154
|
const settings = req.auto === undefined ? readUpdateSettings() : setUpdateSetting("auto", req.auto);
|
|
@@ -150,17 +191,28 @@ export async function runDesktopBridge(opts) {
|
|
|
150
191
|
emit({ v: 1, event: "result", ok: true, result: { assets } });
|
|
151
192
|
return;
|
|
152
193
|
}
|
|
194
|
+
if (req.op === "status" || req.op === "install" || req.op === "setup")
|
|
195
|
+
assertDesktopSetupComplete();
|
|
153
196
|
target = opts.resolveTarget();
|
|
154
197
|
const { paths, home } = target;
|
|
155
198
|
const client = { paths, peerUid: opts.peerUid, peerPid: opts.peerPid };
|
|
156
|
-
if (req.op === "install" || req.op === "setup")
|
|
157
|
-
|
|
199
|
+
if (req.op === "install" || req.op === "setup") {
|
|
200
|
+
const discovered = await discoverDesktopApplicationPath();
|
|
201
|
+
process.env.PATH = discovered.path;
|
|
202
|
+
omittedRelativePathEntries = discovered.omittedRelativeEntries;
|
|
203
|
+
if (omittedRelativePathEntries.length) {
|
|
204
|
+
const detail = `left out relative PATH entries: ${omittedRelativePathEntries.join(", ")}`;
|
|
205
|
+
emit({ v: 1, event: "setup-progress", line: `service: ${detail}`, progress: { step: "install", outcome: "running", detail } });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const omittedResult = omittedRelativePathEntries.length ? { omittedRelativePathEntries } : {};
|
|
158
209
|
if (req.op === "setup") {
|
|
159
|
-
|
|
210
|
+
startedAt = Date.now();
|
|
211
|
+
const result = await runSetup({ ...client, daemonHome: home, space: req.space, idp: req.idp, version: opts.version, waitSeconds: 0, ...omittedResult,
|
|
160
212
|
report: (line, progress) => emit({ v: 1, event: "setup-progress", line, progress }),
|
|
161
213
|
onPrompt: (prompt) => emit({ v: 1, event: "login-prompt", prompt }),
|
|
162
214
|
});
|
|
163
|
-
emit({ v: 1, event: "result", ok: true, result });
|
|
215
|
+
emit({ v: 1, event: "result", ok: true, result: { ...result, ...omittedResult } });
|
|
164
216
|
return;
|
|
165
217
|
}
|
|
166
218
|
if (req.op === "install") {
|
|
@@ -186,13 +238,14 @@ export async function runDesktopBridge(opts) {
|
|
|
186
238
|
throw new CommandFailure("refused", "CONFLICT", "an unowned daemon is already running; no service was installed");
|
|
187
239
|
if (!answering.ok || answering.result.version !== opts.version)
|
|
188
240
|
throw new CommandFailure("refused", "CONFLICT", "the installed daemon does not match this app; no service was started");
|
|
189
|
-
emit({ v: 1, event: "result", ok: true, result: { installed: true, status: answering.result } });
|
|
241
|
+
emit({ v: 1, event: "result", ok: true, result: { installed: true, status: answering.result, ...omittedResult } });
|
|
190
242
|
return;
|
|
191
243
|
}
|
|
244
|
+
startedAt = Date.now();
|
|
192
245
|
if (existing)
|
|
193
246
|
await startInstalled(paths, home, opts.version, detail => emit({ v: 1, event: "setup-progress", line: `service: ${detail}`, progress: { step: "install", outcome: "running", detail } }));
|
|
194
247
|
else
|
|
195
|
-
applyInstall(paths, home);
|
|
248
|
+
applyInstall(paths, home, omittedRelativePathEntries);
|
|
196
249
|
const deadline = Date.now() + 15_000;
|
|
197
250
|
for (;;) {
|
|
198
251
|
try {
|
|
@@ -201,14 +254,14 @@ export async function runDesktopBridge(opts) {
|
|
|
201
254
|
throw new Error("daemon refused status");
|
|
202
255
|
if (status.result.version !== opts.version)
|
|
203
256
|
throw new Error("daemon version mismatch");
|
|
204
|
-
emit({ v: 1, event: "result", ok: true, result: { installed: true, status: status.result } });
|
|
257
|
+
emit({ v: 1, event: "result", ok: true, result: { installed: true, status: status.result, ...omittedResult } });
|
|
205
258
|
return;
|
|
206
259
|
}
|
|
207
260
|
catch (e) {
|
|
208
261
|
if (!(e instanceof EndpointRefusal) || !["NOT_RUNNING", "PEER_NOT_LOCK_OWNER"].includes(e.code))
|
|
209
262
|
throw e;
|
|
210
263
|
if (Date.now() >= deadline)
|
|
211
|
-
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the installed daemon did not answer within 15 seconds of being started", { native: { code: "NOT_ANSWERING" } });
|
|
264
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the installed daemon did not answer within 15 seconds of being started", { native: { code: "NOT_ANSWERING", detail: { waitSeconds: 15 } } });
|
|
212
265
|
}
|
|
213
266
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
214
267
|
}
|
|
@@ -244,17 +297,24 @@ export async function runDesktopBridge(opts) {
|
|
|
244
297
|
}
|
|
245
298
|
catch (e) {
|
|
246
299
|
const code = e instanceof EndpointRefusal || e instanceof CommandFailure ? e.code : "OPERATION_FAILED";
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
300
|
+
const notAnswering = e instanceof CommandFailure && (req.op === "setup" || req.op === "install") && e.code === "DEPENDENCY_UNAVAILABLE" && e.native?.code === "NOT_ANSWERING";
|
|
301
|
+
const refusal = notAnswering && target && startedAt !== undefined ? attemptStartupRefusal(target.paths.state, startedAt) : undefined;
|
|
302
|
+
const rawWait = notAnswering && e.native?.detail && typeof e.native.detail === "object" ? e.native.detail.waitSeconds : undefined;
|
|
303
|
+
const waitSeconds = typeof rawWait === "number" && Number.isInteger(rawWait) && rawWait > 0 ? rawWait : undefined;
|
|
304
|
+
const baseMessage = notAnswering ? `Cotal asked the background service on this computer to start, and it ${waitSeconds !== undefined ? `did not answer within ${waitSeconds} seconds.` : "has not answered."}${refusal ? ` It refused to start: ${refusal}` : ""}`
|
|
305
|
+
: e instanceof CommandFailure && (e.code === "CONFLICT" || req.op === "setup" || req.op === "install") ? e.message
|
|
306
|
+
: code === "NOT_RUNNING" ? (target && serviceInstalled(target)
|
|
307
|
+
? "The background service is installed but stopped. Choose Start service to start it."
|
|
308
|
+
: "The daemon is not running. Install its background service first.")
|
|
252
309
|
: code === "NO_RUNTIME_DIR" ? "The daemon runtime path is unavailable or too long. On Linux, check XDG_RUNTIME_DIR for the intended operating-system user."
|
|
253
310
|
: code === "UNSUPPORTED_PLATFORM" ? "This platform does not have the required native daemon support."
|
|
254
311
|
: code === "PEER_UID_MISMATCH" || code === "PEER_NOT_LOCK_OWNER" ? "The local daemon identity could not be verified. The requested change was not sent."
|
|
255
312
|
: "The operation could not be completed. Use the matching `cotal daemon` command for diagnostics; no success is assumed.";
|
|
313
|
+
const message = (req.op === "setup" || req.op === "install") && omittedRelativePathEntries.length
|
|
314
|
+
? `${baseMessage}${baseMessage.endsWith(".") ? "" : "."} Left out relative PATH entries: ${omittedRelativePathEntries.join(", ")}.`
|
|
315
|
+
: baseMessage;
|
|
256
316
|
emit({ v: 1, event: "result", ok: false, error: { code, message,
|
|
257
|
-
...(e instanceof CommandFailure && (req.op === "setup" || req.op === "install") ? { remedy: e.remedy, native: e.native } : {}),
|
|
317
|
+
...(e instanceof CommandFailure && (req.op === "setup" || req.op === "install") ? { remedy: notAnswering ? "choose Check status." : e.remedy, native: e.native } : {}),
|
|
258
318
|
} });
|
|
259
319
|
}
|
|
260
320
|
}
|
|
@@ -2,18 +2,20 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { basename } from "node:path";
|
|
3
3
|
import { CommandFailure } from "@cotal-ai/workspace/local-observation";
|
|
4
4
|
/** Runs one native tool by absolute path with the existing bounds, never through a shell. */
|
|
5
|
-
export function nativeRun(file, args, env) {
|
|
5
|
+
export function nativeRun(file, args, env, timeoutMs = 30_000) {
|
|
6
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
7
|
+
throw new Error("native operation deadline expired");
|
|
6
8
|
const started = Date.now();
|
|
7
|
-
const result = spawnSync(file, args, { encoding: "utf8", timeout:
|
|
9
|
+
const result = spawnSync(file, args, { encoding: "utf8", timeout: timeoutMs, maxBuffer: 256 * 1024, stdio: ["ignore", "pipe", "pipe"], windowsHide: true, ...(env ? { env } : {}) });
|
|
8
10
|
if (result.error || result.signal) {
|
|
9
11
|
const elapsedMs = Date.now() - started;
|
|
10
12
|
const code = result.error?.code;
|
|
11
|
-
const reason = code === "ETIMEDOUT" ?
|
|
13
|
+
const reason = code === "ETIMEDOUT" ? `timed out after ${timeoutMs / 1000} s`
|
|
12
14
|
: code === "ENOBUFS" ? "exceeded its 256 KiB output limit"
|
|
13
15
|
: code ? `could not start or complete (${code})`
|
|
14
16
|
: `exited by signal ${result.signal}`;
|
|
15
17
|
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `${basename(file)} ${reason} (elapsed ${elapsedMs} ms); no further native step was taken`, {
|
|
16
|
-
native: { code: code ?? result.signal ?? "NATIVE_TOOL_FAILED", detail: { elapsedMs, timeoutMs
|
|
18
|
+
native: { code: code ?? result.signal ?? "NATIVE_TOOL_FAILED", detail: { elapsedMs, timeoutMs, signal: result.signal } },
|
|
17
19
|
});
|
|
18
20
|
}
|
|
19
21
|
const stdout = typeof result.stdout === "string" ? result.stdout : "";
|
|
@@ -20,5 +20,8 @@ export function readReceipt(paths) {
|
|
|
20
20
|
return undefined;
|
|
21
21
|
if (r.mechanism !== undefined && r.mechanism !== "systemd-user" && r.mechanism !== "launchd-agent" && r.mechanism !== "scheduled-task")
|
|
22
22
|
return undefined;
|
|
23
|
-
|
|
23
|
+
const omitted = Array.isArray(r.omittedRelativePathEntries) && r.omittedRelativePathEntries.every((item) => typeof item === "string" && item.length > 0)
|
|
24
|
+
? r.omittedRelativePathEntries
|
|
25
|
+
: undefined;
|
|
26
|
+
return { v: 1, ...(r.mechanism !== undefined ? { mechanism: r.mechanism } : {}), unit: r.unit, unitPath: r.unitPath, unitSha256: r.unitSha256, installedAt: r.installedAt, ...(typeof r.daemonHome === "string" ? { daemonHome: r.daemonHome } : {}), ...(omitted?.length ? { omittedRelativePathEntries: omitted } : {}) };
|
|
24
27
|
}
|