@qilin-agent/desktop-host 0.0.0-stage → 3.1.7
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/LICENSE +21 -0
- package/lib/cli.js +127 -0
- package/lib/index.js +334 -0
- package/lib/types/cli.d.ts +18 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/office-engine.d.ts +16 -0
- package/lib/types/office.d.ts +20 -0
- package/lib/types/quit-inspection.d.ts +18 -0
- package/lib/types/update-tasks.d.ts +18 -0
- package/lib/types/windows-cli-signals.d.ts +9 -0
- package/package.json +41 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kkutysllb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { registerHooks } from "node:module";
|
|
2
|
+
import { basename, delimiter, dirname, join, relative, resolve } from "node:path";
|
|
3
|
+
import { runCli } from "@qilin-agent/cli/bin";
|
|
4
|
+
import { realpathSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
//#region \0rolldown/runtime.js
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region lib/types/office-engine.js
|
|
20
|
+
/** Resolve packaged Office engine manifests from their complete, unpacked resource directories. */
|
|
21
|
+
/**
|
|
22
|
+
* Locate the archive containing a packaged runtime.
|
|
23
|
+
* @param runtimeDir - Prepared or ASAR-contained runtime directory.
|
|
24
|
+
* @returns Parent archive path, or undefined for a prepared directory.
|
|
25
|
+
*/
|
|
26
|
+
function runtimeArchivePath(runtimeDir) {
|
|
27
|
+
const parent = dirname(runtimeDir);
|
|
28
|
+
return basename(parent) === "app.asar" ? parent : void 0;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keep engine executable and resource paths usable by native child processes outside Electron.
|
|
32
|
+
* Hooks apply only to this thread; worker threads must install their own resolver.
|
|
33
|
+
* @param runtimeDir - Prepared or ASAR-contained qilin runtime directory.
|
|
34
|
+
* @returns Installed resolver for the Host lifetime, or undefined for a non-ASAR runtime.
|
|
35
|
+
*/
|
|
36
|
+
function installOfficeEngineResolution(runtimeDir) {
|
|
37
|
+
if (runtimeArchivePath(runtimeDir) === void 0) return void 0;
|
|
38
|
+
const root = realpathSync(runtimeDir);
|
|
39
|
+
const archive = dirname(root);
|
|
40
|
+
const source = pathToFileURL(join(root, "node_modules", "@deepseek-ai", "libreoffice-kit-")).href;
|
|
41
|
+
const destination = pathToFileURL(join(`${archive}.unpacked`, relative(archive, root), "node_modules", "@deepseek-ai", "libreoffice-kit-")).href;
|
|
42
|
+
return registerHooks({ resolve(specifier, context, nextResolve) {
|
|
43
|
+
const resolved = nextResolve(specifier, context);
|
|
44
|
+
if (!resolved.url.startsWith("file:")) return resolved;
|
|
45
|
+
const engineRequest = /^@deepseek-ai\/libreoffice-kit-(?:darwin|win32|linux)-/u.test(specifier);
|
|
46
|
+
const engineTarget = /\/node_modules\/@deepseek-ai\/libreoffice-kit-(?:darwin|win32|linux)-[^/]+\//u.test(new URL(resolved.url).pathname);
|
|
47
|
+
if (!engineRequest && !engineTarget) return resolved;
|
|
48
|
+
const canonical = pathToFileURL(realpathSync(fileURLToPath(resolved.url))).href;
|
|
49
|
+
if (!canonical.startsWith(source)) {
|
|
50
|
+
if (canonical.startsWith(pathToFileURL(archive + "/").href)) throw new Error(`desktop Office engine resolved outside the runtime package directory: ${resolved.url}`);
|
|
51
|
+
return resolved;
|
|
52
|
+
}
|
|
53
|
+
const physical = realpathSync(fileURLToPath(destination + canonical.slice(source.length)));
|
|
54
|
+
return {
|
|
55
|
+
...resolved,
|
|
56
|
+
url: pathToFileURL(physical).href
|
|
57
|
+
};
|
|
58
|
+
} });
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region lib/types/windows-cli-signals.js
|
|
62
|
+
var windows_cli_signals_exports = /* @__PURE__ */ __exportAll({ installWindowsCliSignals: () => installWindowsCliSignals });
|
|
63
|
+
/** Deliver console interrupts to CLI listeners in Electron's Windows Node mode. */
|
|
64
|
+
/**
|
|
65
|
+
* Register the CLI process's Windows console handler.
|
|
66
|
+
* Koffi queues callbacks from the console thread onto the JavaScript thread.
|
|
67
|
+
* The registration lasts until process exit; unknown events retain native handling.
|
|
68
|
+
* @returns Completion once the console handler is registered.
|
|
69
|
+
*/
|
|
70
|
+
async function installWindowsCliSignals() {
|
|
71
|
+
const { default: koffi } = await import("koffi");
|
|
72
|
+
const kernel = koffi.load("kernel32.dll");
|
|
73
|
+
const type = koffi.proto("int __stdcall DshCliConsoleHandler(uint32_t event)");
|
|
74
|
+
const handler = koffi.register((event) => {
|
|
75
|
+
if (event === 0) return Number(process.emit("SIGINT"));
|
|
76
|
+
if (event === 1) return Number(process.emit("SIGBREAK"));
|
|
77
|
+
return 0;
|
|
78
|
+
}, koffi.pointer(type));
|
|
79
|
+
if (!kernel.func("int __stdcall SetConsoleCtrlHandler(DshCliConsoleHandler *handler, int add)")(handler, 1)) {
|
|
80
|
+
koffi.unregister(handler);
|
|
81
|
+
throw new Error("desktop CLI: cannot register the Windows console handler");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var init_windows_cli_signals = __esmMin((() => {}));
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region lib/types/cli.js
|
|
87
|
+
/** Public qilin commands using the immutable runtime carried by the Desktop installation. */
|
|
88
|
+
/**
|
|
89
|
+
* Options the Desktop installation hands the ordinary CLI.
|
|
90
|
+
*
|
|
91
|
+
* @param supportDir - Physical Desktop runtime directory containing the primary-runtime payload and Node launchers.
|
|
92
|
+
* @returns the options that put the CLI on the bundled package manager with reserved-profile access.
|
|
93
|
+
*/
|
|
94
|
+
function desktopCliOptions(supportDir) {
|
|
95
|
+
return {
|
|
96
|
+
manageDesktopProfile: true,
|
|
97
|
+
packageManager: {
|
|
98
|
+
command: process.execPath,
|
|
99
|
+
args: ["--expose-internals", join(supportDir, "primary-runtime", "dependencies", "pnpm", "bin", "pnpm.mjs")],
|
|
100
|
+
env: {
|
|
101
|
+
ELECTRON_RUN_AS_NODE: "1",
|
|
102
|
+
QILIN_DESKTOP_NODE_EXECUTABLE: process.execPath,
|
|
103
|
+
PATH: join(supportDir, "bin") + delimiter + (process.env.PATH ?? "")
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Run the ordinary CLI with the Desktop's bundled package manager and reserved-profile plugin access.
|
|
110
|
+
* @param runtimeDir - Prepared or ASAR-contained production QiLin package tree.
|
|
111
|
+
* @param supportDir - Physical Desktop runtime directory containing the primary-runtime payload
|
|
112
|
+
* and Node launchers; defaults to the runtime directory's sibling.
|
|
113
|
+
* @returns Completion of the selected CLI command; profile plugins own their process lifetime.
|
|
114
|
+
*/
|
|
115
|
+
async function runDesktopCli(runtimeDir, supportDir = join(dirname(runtimeArchivePath(runtimeDir) ?? runtimeDir), "runtime")) {
|
|
116
|
+
installOfficeEngineResolution(runtimeDir);
|
|
117
|
+
await runCli(desktopCliOptions(supportDir));
|
|
118
|
+
}
|
|
119
|
+
if (import.meta.main) {
|
|
120
|
+
if (process.platform === "win32") {
|
|
121
|
+
const { installWindowsCliSignals } = await Promise.resolve().then(() => (init_windows_cli_signals(), windows_cli_signals_exports));
|
|
122
|
+
await installWindowsCliSignals();
|
|
123
|
+
}
|
|
124
|
+
await runDesktopCli(resolve(import.meta.dirname, "../../../.."));
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { desktopCliOptions, runDesktopCli };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { registerHooks } from "node:module";
|
|
2
|
+
import { basename, delimiter, dirname, join, relative } from "node:path";
|
|
3
|
+
import { inspect } from "node:util";
|
|
4
|
+
import { loadLayeredEnv, loadProfileDirectory, reportSkippedBundles } from "@qilin-agent/app-boot";
|
|
5
|
+
import { resolveQilinDesktopHome, resolveQilinHome } from "@qilin-agent/home-paths";
|
|
6
|
+
import { runProfile } from "@qilin-agent/cli/profile-boot";
|
|
7
|
+
import { realpathSync } from "node:fs";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
import * as officeSkills from "@qilin-agent/skill-office";
|
|
10
|
+
import * as workspaceDependencies from "@qilin-agent/tool-workspace-dependencies";
|
|
11
|
+
//#region \0rolldown/runtime.js
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __exportAll = (all, no_symbols) => {
|
|
14
|
+
let target = {};
|
|
15
|
+
for (var name in all) __defProp(target, name, {
|
|
16
|
+
get: all[name],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
20
|
+
return target;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region lib/types/office-engine.js
|
|
24
|
+
/** Resolve packaged Office engine manifests from their complete, unpacked resource directories. */
|
|
25
|
+
/**
|
|
26
|
+
* Locate the archive containing a packaged runtime.
|
|
27
|
+
* @param runtimeDir - Prepared or ASAR-contained runtime directory.
|
|
28
|
+
* @returns Parent archive path, or undefined for a prepared directory.
|
|
29
|
+
*/
|
|
30
|
+
function runtimeArchivePath(runtimeDir) {
|
|
31
|
+
const parent = dirname(runtimeDir);
|
|
32
|
+
return basename(parent) === "app.asar" ? parent : void 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Keep engine executable and resource paths usable by native child processes outside Electron.
|
|
36
|
+
* Hooks apply only to this thread; worker threads must install their own resolver.
|
|
37
|
+
* @param runtimeDir - Prepared or ASAR-contained qilin runtime directory.
|
|
38
|
+
* @returns Installed resolver for the Host lifetime, or undefined for a non-ASAR runtime.
|
|
39
|
+
*/
|
|
40
|
+
function installOfficeEngineResolution(runtimeDir) {
|
|
41
|
+
if (runtimeArchivePath(runtimeDir) === void 0) return void 0;
|
|
42
|
+
const root = realpathSync(runtimeDir);
|
|
43
|
+
const archive = dirname(root);
|
|
44
|
+
const source = pathToFileURL(join(root, "node_modules", "@deepseek-ai", "libreoffice-kit-")).href;
|
|
45
|
+
const destination = pathToFileURL(join(`${archive}.unpacked`, relative(archive, root), "node_modules", "@deepseek-ai", "libreoffice-kit-")).href;
|
|
46
|
+
return registerHooks({ resolve(specifier, context, nextResolve) {
|
|
47
|
+
const resolved = nextResolve(specifier, context);
|
|
48
|
+
if (!resolved.url.startsWith("file:")) return resolved;
|
|
49
|
+
const engineRequest = /^@deepseek-ai\/libreoffice-kit-(?:darwin|win32|linux)-/u.test(specifier);
|
|
50
|
+
const engineTarget = /\/node_modules\/@deepseek-ai\/libreoffice-kit-(?:darwin|win32|linux)-[^/]+\//u.test(new URL(resolved.url).pathname);
|
|
51
|
+
if (!engineRequest && !engineTarget) return resolved;
|
|
52
|
+
const canonical = pathToFileURL(realpathSync(fileURLToPath(resolved.url))).href;
|
|
53
|
+
if (!canonical.startsWith(source)) {
|
|
54
|
+
if (canonical.startsWith(pathToFileURL(archive + "/").href)) throw new Error(`desktop Office engine resolved outside the runtime package directory: ${resolved.url}`);
|
|
55
|
+
return resolved;
|
|
56
|
+
}
|
|
57
|
+
const physical = realpathSync(fileURLToPath(destination + canonical.slice(source.length)));
|
|
58
|
+
return {
|
|
59
|
+
...resolved,
|
|
60
|
+
url: pathToFileURL(physical).href
|
|
61
|
+
};
|
|
62
|
+
} });
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region lib/types/office.js
|
|
66
|
+
/** Desktop Office skills and bundled authoring dependencies. */
|
|
67
|
+
var office_exports = /* @__PURE__ */ __exportAll({
|
|
68
|
+
apply: () => apply,
|
|
69
|
+
name: () => name
|
|
70
|
+
});
|
|
71
|
+
/** Loader identity for the application-owned Office composition. */
|
|
72
|
+
const name = "desktop-office";
|
|
73
|
+
/**
|
|
74
|
+
* Enable offline Office authoring and LibreOffice Kit operations in the Desktop profile.
|
|
75
|
+
* @param ctx - Profile scope; child plugins declare their own service requirements.
|
|
76
|
+
* @param config - Bundled payload source and Harness-home installation root.
|
|
77
|
+
*/
|
|
78
|
+
async function apply(ctx, config) {
|
|
79
|
+
await ctx.plugin(workspaceDependencies, config);
|
|
80
|
+
const archive = runtimeArchivePath(config.runtimeDir) === void 0 ? void 0 : dirname(realpathSync(config.runtimeDir));
|
|
81
|
+
const manifest = fileURLToPath(import.meta.resolve("@deepseek-ai/libreoffice-kit/package.json"));
|
|
82
|
+
const packageRoot = dirname(archive === void 0 ? manifest : join(`${archive}.unpacked`, relative(archive, manifest)));
|
|
83
|
+
await ctx.plugin(officeSkills, {
|
|
84
|
+
assetRoot: join(dirname(config.source), "office-skills"),
|
|
85
|
+
node: join(config.source, "dependencies", "node", "bin", process.platform === "win32" ? "node.exe" : "node"),
|
|
86
|
+
cli: join(packageRoot, "lib", "cli.js")
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region lib/types/update-tasks.js
|
|
91
|
+
/** Desktop installation admission and task inspection for the shared Web Host. */
|
|
92
|
+
/**
|
|
93
|
+
* Whether stopping the Host now would interrupt work: a generating or tool-running
|
|
94
|
+
* agent (including subagents and turns waiting for approval), queued inbox
|
|
95
|
+
* messages, or a running or stopping background job.
|
|
96
|
+
* @param liveAgents - Current agent roster.
|
|
97
|
+
* @param jobs - Job registry queried for the global roster and each agent's own jobs.
|
|
98
|
+
* @returns true when any of those conditions holds.
|
|
99
|
+
*/
|
|
100
|
+
function hasDesktopActiveTasks(liveAgents, jobs) {
|
|
101
|
+
return liveAgents.some((agent) => agent.status === "running" || agent.inbox.nextTurn.length > 0 || agent.inbox.nextStep.length > 0) || [void 0, ...liveAgents].some((agent) => jobs.list(agent?.id).some((job) => job.status === "running" || job.status === "stopping"));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Register update admission on the owning Host context.
|
|
105
|
+
* @param ctx - Booted Desktop profile context; disposal removes the request listener.
|
|
106
|
+
* @returns Task inspector whose lock refuses new API requests, drains admitted requests, and rechecks work.
|
|
107
|
+
*/
|
|
108
|
+
function installDesktopUpdateTaskControl(ctx) {
|
|
109
|
+
let locked = false;
|
|
110
|
+
let lockGeneration = 0;
|
|
111
|
+
let stopped = false;
|
|
112
|
+
ctx.effect(() => () => {
|
|
113
|
+
stopped = true;
|
|
114
|
+
});
|
|
115
|
+
const pendingRequests = /* @__PURE__ */ new Set();
|
|
116
|
+
ctx.on("connection/request", async (_request, response, next) => {
|
|
117
|
+
if (locked) {
|
|
118
|
+
response.writeHead(503);
|
|
119
|
+
response.end();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const finished = Promise.withResolvers();
|
|
123
|
+
pendingRequests.add(finished.promise);
|
|
124
|
+
try {
|
|
125
|
+
await next();
|
|
126
|
+
} finally {
|
|
127
|
+
pendingRequests.delete(finished.promise);
|
|
128
|
+
finished.resolve();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return async (action) => {
|
|
132
|
+
if (stopped) throw new Error("desktop update: Host is stopping");
|
|
133
|
+
if (action === "unlock") {
|
|
134
|
+
locked = false;
|
|
135
|
+
lockGeneration++;
|
|
136
|
+
}
|
|
137
|
+
const agents = ctx.get("agents");
|
|
138
|
+
const jobs = ctx.get("jobs");
|
|
139
|
+
if (agents === void 0 || jobs === void 0) throw new Error("desktop update: task services are unavailable");
|
|
140
|
+
if (action === "lock") {
|
|
141
|
+
locked = true;
|
|
142
|
+
const generation = ++lockGeneration;
|
|
143
|
+
await Promise.all(pendingRequests);
|
|
144
|
+
if (stopped) throw new Error("desktop update: Host is stopping");
|
|
145
|
+
if (generation !== lockGeneration) throw new Error("desktop update: admission lock was superseded");
|
|
146
|
+
}
|
|
147
|
+
return hasDesktopActiveTasks(agents.list(), jobs);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region lib/types/quit-inspection.js
|
|
152
|
+
/** Quit-time inspection of interruptible work and armed scheduled reminders for the Electron shell. */
|
|
153
|
+
/**
|
|
154
|
+
* Register the quit inspector on the owning Host context.
|
|
155
|
+
* @param ctx - Booted Desktop profile context; disposal makes the inspector reject.
|
|
156
|
+
* @returns Inspector reporting active tasks together with armed reminders of the loaded sessions
|
|
157
|
+
* (the `schedule` family of `workspace/session-activity`); reminders in sessions that were never
|
|
158
|
+
* loaded during this run cannot fire and are not counted.
|
|
159
|
+
*/
|
|
160
|
+
function installDesktopQuitInspection(ctx) {
|
|
161
|
+
let stopped = false;
|
|
162
|
+
ctx.effect(() => () => {
|
|
163
|
+
stopped = true;
|
|
164
|
+
});
|
|
165
|
+
return async () => {
|
|
166
|
+
if (stopped) throw new Error("desktop quit: Host is stopping");
|
|
167
|
+
const agents = ctx.get("agents");
|
|
168
|
+
const jobs = ctx.get("jobs");
|
|
169
|
+
if (agents === void 0 || jobs === void 0) throw new Error("desktop quit: task services are unavailable");
|
|
170
|
+
const liveAgents = agents.list();
|
|
171
|
+
const activeTasks = hasDesktopActiveTasks(liveAgents, jobs);
|
|
172
|
+
let scheduledTasks = false;
|
|
173
|
+
for (const agent of liveAgents) if ((await ctx.waterfall("workspace/session-activity", { sessionId: agent.id }, () => Promise.resolve([]))).some((entry) => entry.kind === "schedule")) {
|
|
174
|
+
scheduledTasks = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
activeTasks,
|
|
179
|
+
scheduledTasks
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region lib/types/index.js
|
|
185
|
+
/** Launch the Desktop profile through the Web application and report its URL to Electron. */
|
|
186
|
+
async function main() {
|
|
187
|
+
const runtimeDir = process.argv[2];
|
|
188
|
+
installOfficeEngineResolution(runtimeDir);
|
|
189
|
+
const projectDir = process.argv[3];
|
|
190
|
+
const installAnchor = join(runtimeDir, "node_modules", "@qilin-agent", "cli", "package.json");
|
|
191
|
+
const profile = loadProfileDirectory("qilin", projectDir, installAnchor);
|
|
192
|
+
reportSkippedBundles("qilin", profile);
|
|
193
|
+
process.env.QILIN_HOME ??= resolveQilinDesktopHome();
|
|
194
|
+
const application = runProfile({
|
|
195
|
+
environment: loadLayeredEnv("qilin"),
|
|
196
|
+
profile: "desktop",
|
|
197
|
+
resolvedProfile: {
|
|
198
|
+
profile,
|
|
199
|
+
installAnchor
|
|
200
|
+
},
|
|
201
|
+
patchFiles: [],
|
|
202
|
+
args: [
|
|
203
|
+
"--no-open",
|
|
204
|
+
"--host",
|
|
205
|
+
"127.0.0.1",
|
|
206
|
+
"--port",
|
|
207
|
+
"0"
|
|
208
|
+
],
|
|
209
|
+
...process.argv[5] === void 0 ? {} : { packageManager: {
|
|
210
|
+
command: process.execPath,
|
|
211
|
+
args: ["--expose-internals", process.argv[5]],
|
|
212
|
+
env: {
|
|
213
|
+
ELECTRON_RUN_AS_NODE: "1",
|
|
214
|
+
QILIN_DESKTOP_NODE_EXECUTABLE: process.execPath,
|
|
215
|
+
PATH: `${process.argv[6] ?? ""}${delimiter}${process.env.PATH ?? ""}`
|
|
216
|
+
}
|
|
217
|
+
} }
|
|
218
|
+
});
|
|
219
|
+
let stopping;
|
|
220
|
+
const control = {};
|
|
221
|
+
const send = (message) => new Promise((resolve, reject) => {
|
|
222
|
+
if (!process.connected || process.send === void 0) {
|
|
223
|
+
resolve();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
process.send(message, (error) => {
|
|
227
|
+
if (error === null) resolve();
|
|
228
|
+
else reject(error);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
const stop = () => stopping ??= (async () => {
|
|
232
|
+
await (await application.catch(() => void 0))?.shutdown.shutdown(0);
|
|
233
|
+
await send({ type: "shutdown-complete" });
|
|
234
|
+
if (process.connected) process.disconnect();
|
|
235
|
+
})();
|
|
236
|
+
process.on("message", (message) => {
|
|
237
|
+
if (typeof message !== "object" || message === null || !("type" in message)) return;
|
|
238
|
+
if (message.type === "shutdown") {
|
|
239
|
+
stop();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (message.type === "quit-inspection") {
|
|
243
|
+
if (!("requestId" in message) || !Number.isSafeInteger(message.requestId)) return;
|
|
244
|
+
const requestId = message.requestId;
|
|
245
|
+
(async () => {
|
|
246
|
+
try {
|
|
247
|
+
if (stopping !== void 0 || control.quitInspection === void 0) throw new Error("desktop quit: Host is unavailable");
|
|
248
|
+
await send({
|
|
249
|
+
type: "quit-inspection",
|
|
250
|
+
requestId,
|
|
251
|
+
...await control.quitInspection()
|
|
252
|
+
});
|
|
253
|
+
} catch (error) {
|
|
254
|
+
await send({
|
|
255
|
+
type: "quit-inspection",
|
|
256
|
+
requestId,
|
|
257
|
+
activeTasks: true,
|
|
258
|
+
scheduledTasks: false,
|
|
259
|
+
error: error instanceof Error ? error.message : String(error)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
})().catch((error) => {
|
|
263
|
+
console.error(error);
|
|
264
|
+
});
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (message.type !== "update-tasks" || !("requestId" in message) || !Number.isSafeInteger(message.requestId) || !("action" in message) || ![
|
|
268
|
+
"inspect",
|
|
269
|
+
"lock",
|
|
270
|
+
"unlock"
|
|
271
|
+
].includes(String(message.action))) return;
|
|
272
|
+
(async () => {
|
|
273
|
+
try {
|
|
274
|
+
if (stopping !== void 0 || control.updateTasks === void 0) throw new Error("desktop update: Host is unavailable");
|
|
275
|
+
const active = await control.updateTasks(message.action);
|
|
276
|
+
await send({
|
|
277
|
+
type: "update-tasks",
|
|
278
|
+
requestId: message.requestId,
|
|
279
|
+
active
|
|
280
|
+
});
|
|
281
|
+
} catch (error) {
|
|
282
|
+
await send({
|
|
283
|
+
type: "update-tasks",
|
|
284
|
+
requestId: message.requestId,
|
|
285
|
+
active: true,
|
|
286
|
+
error: error instanceof Error ? error.message : String(error)
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
})().catch((error) => {
|
|
290
|
+
console.error(error);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
process.once("disconnect", () => {
|
|
294
|
+
stop();
|
|
295
|
+
});
|
|
296
|
+
const { ctx } = await application;
|
|
297
|
+
control.updateTasks = installDesktopUpdateTaskControl(ctx);
|
|
298
|
+
control.quitInspection = installDesktopQuitInspection(ctx);
|
|
299
|
+
await ctx.plugin(office_exports, {
|
|
300
|
+
runtimeDir,
|
|
301
|
+
source: process.argv[4] ?? join(runtimeDir, "..", "runtime", "primary-runtime"),
|
|
302
|
+
root: join(resolveQilinHome(), "qilin-runtimes", "qilin-primary-runtime")
|
|
303
|
+
});
|
|
304
|
+
await ctx.webServer.whenListened();
|
|
305
|
+
const url = ctx.connection.authenticatedUrl(`${ctx.webServer.protocol}//127.0.0.1:${String(ctx.webServer.port)}`);
|
|
306
|
+
if (process.connected) process.send?.({
|
|
307
|
+
type: "ready",
|
|
308
|
+
url,
|
|
309
|
+
injections: ctx.webServer.collectIndexInjections()
|
|
310
|
+
}, (error) => {
|
|
311
|
+
if (error !== null) console.error(error);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/** Upper bound of the startup diagnostic carried over IPC; the head holds the message and stack. */
|
|
315
|
+
const MAX_FATAL_DIAGNOSTIC_CHARS = 64 * 1024;
|
|
316
|
+
if (import.meta.main) main().catch((error) => {
|
|
317
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
318
|
+
const diagnostic = inspect(error, {
|
|
319
|
+
depth: 4,
|
|
320
|
+
maxArrayLength: 50
|
|
321
|
+
}).slice(0, MAX_FATAL_DIAGNOSTIC_CHARS);
|
|
322
|
+
if (process.connected) process.send?.({
|
|
323
|
+
type: "fatal",
|
|
324
|
+
message,
|
|
325
|
+
diagnostic
|
|
326
|
+
}, (error) => {
|
|
327
|
+
if (error !== null) console.error(error);
|
|
328
|
+
});
|
|
329
|
+
console.error(error);
|
|
330
|
+
process.exitCode = 1;
|
|
331
|
+
if (process.connected) process.disconnect();
|
|
332
|
+
});
|
|
333
|
+
//#endregion
|
|
334
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Public qilin commands using the immutable runtime carried by the Desktop installation. */
|
|
2
|
+
import { type RunCliOptions } from '@qilin-agent/cli/bin';
|
|
3
|
+
/**
|
|
4
|
+
* Options the Desktop installation hands the ordinary CLI.
|
|
5
|
+
*
|
|
6
|
+
* @param supportDir - Physical Desktop runtime directory containing the primary-runtime payload and Node launchers.
|
|
7
|
+
* @returns the options that put the CLI on the bundled package manager with reserved-profile access.
|
|
8
|
+
*/
|
|
9
|
+
export declare function desktopCliOptions(supportDir: string): RunCliOptions;
|
|
10
|
+
/**
|
|
11
|
+
* Run the ordinary CLI with the Desktop's bundled package manager and reserved-profile plugin access.
|
|
12
|
+
* @param runtimeDir - Prepared or ASAR-contained production QiLin package tree.
|
|
13
|
+
* @param supportDir - Physical Desktop runtime directory containing the primary-runtime payload
|
|
14
|
+
* and Node launchers; defaults to the runtime directory's sibling.
|
|
15
|
+
* @returns Completion of the selected CLI command; profile plugins own their process lifetime.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runDesktopCli(runtimeDir: string, supportDir?: string): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Resolve packaged Office engine manifests from their complete, unpacked resource directories. */
|
|
2
|
+
import { type ModuleHooks } from 'node:module';
|
|
3
|
+
/**
|
|
4
|
+
* Locate the archive containing a packaged runtime.
|
|
5
|
+
* @param runtimeDir - Prepared or ASAR-contained runtime directory.
|
|
6
|
+
* @returns Parent archive path, or undefined for a prepared directory.
|
|
7
|
+
*/
|
|
8
|
+
export declare function runtimeArchivePath(runtimeDir: string): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Keep engine executable and resource paths usable by native child processes outside Electron.
|
|
11
|
+
* Hooks apply only to this thread; worker threads must install their own resolver.
|
|
12
|
+
* @param runtimeDir - Prepared or ASAR-contained qilin runtime directory.
|
|
13
|
+
* @returns Installed resolver for the Host lifetime, or undefined for a non-ASAR runtime.
|
|
14
|
+
*/
|
|
15
|
+
export declare function installOfficeEngineResolution(runtimeDir: string): ModuleHooks | undefined;
|
|
16
|
+
//# sourceMappingURL=office-engine.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Desktop Office skills and bundled authoring dependencies. */
|
|
2
|
+
import type { Context } from '@qilin-agent/kylin';
|
|
3
|
+
/** Loader identity for the application-owned Office composition. */
|
|
4
|
+
export declare const name = "desktop-office";
|
|
5
|
+
/** Application-selected bundled payload and installation directories. */
|
|
6
|
+
export interface Config {
|
|
7
|
+
/** Bundled payload directory. Missing sibling `office-skills` resources fail Host startup. */
|
|
8
|
+
readonly source: string;
|
|
9
|
+
/** Harness-home directory where workspace dependencies are installed. */
|
|
10
|
+
readonly root: string;
|
|
11
|
+
/** Prepared or ASAR-contained application dependency directory. */
|
|
12
|
+
readonly runtimeDir: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Enable offline Office authoring and LibreOffice Kit operations in the Desktop profile.
|
|
16
|
+
* @param ctx - Profile scope; child plugins declare their own service requirements.
|
|
17
|
+
* @param config - Bundled payload source and Harness-home installation root.
|
|
18
|
+
*/
|
|
19
|
+
export declare function apply(ctx: Context, config: Config): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=office.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Quit-time inspection of interruptible work and armed scheduled reminders for the Electron shell. */
|
|
2
|
+
import type { Context } from '@qilin-agent/kylin';
|
|
3
|
+
/** What quitting the Host now would affect. */
|
|
4
|
+
export interface DesktopQuitInspection {
|
|
5
|
+
/** Work the shared update-restart check also counts: running agents, queued messages, live jobs. */
|
|
6
|
+
readonly activeTasks: boolean;
|
|
7
|
+
/** A loaded session holds a scheduled reminder whose timer is armed in this process. */
|
|
8
|
+
readonly scheduledTasks: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Register the quit inspector on the owning Host context.
|
|
12
|
+
* @param ctx - Booted Desktop profile context; disposal makes the inspector reject.
|
|
13
|
+
* @returns Inspector reporting active tasks together with armed reminders of the loaded sessions
|
|
14
|
+
* (the `schedule` family of `workspace/session-activity`); reminders in sessions that were never
|
|
15
|
+
* loaded during this run cannot fire and are not counted.
|
|
16
|
+
*/
|
|
17
|
+
export declare function installDesktopQuitInspection(ctx: Context): () => Promise<DesktopQuitInspection>;
|
|
18
|
+
//# sourceMappingURL=quit-inspection.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Desktop installation admission and task inspection for the shared Web Host. */
|
|
2
|
+
import type { Context } from '@qilin-agent/kylin';
|
|
3
|
+
/**
|
|
4
|
+
* Whether stopping the Host now would interrupt work: a generating or tool-running
|
|
5
|
+
* agent (including subagents and turns waiting for approval), queued inbox
|
|
6
|
+
* messages, or a running or stopping background job.
|
|
7
|
+
* @param liveAgents - Current agent roster.
|
|
8
|
+
* @param jobs - Job registry queried for the global roster and each agent's own jobs.
|
|
9
|
+
* @returns true when any of those conditions holds.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasDesktopActiveTasks(liveAgents: ReturnType<Context['agents']['list']>, jobs: Context['jobs']): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Register update admission on the owning Host context.
|
|
14
|
+
* @param ctx - Booted Desktop profile context; disposal removes the request listener.
|
|
15
|
+
* @returns Task inspector whose lock refuses new API requests, drains admitted requests, and rechecks work.
|
|
16
|
+
*/
|
|
17
|
+
export declare function installDesktopUpdateTaskControl(ctx: Context): (action: 'inspect' | 'lock' | 'unlock') => Promise<boolean>;
|
|
18
|
+
//# sourceMappingURL=update-tasks.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Deliver console interrupts to CLI listeners in Electron's Windows Node mode. */
|
|
2
|
+
/**
|
|
3
|
+
* Register the CLI process's Windows console handler.
|
|
4
|
+
* Koffi queues callbacks from the console thread onto the JavaScript thread.
|
|
5
|
+
* The registration lasts until process exit; unknown events retain native handling.
|
|
6
|
+
* @returns Completion once the console handler is registered.
|
|
7
|
+
*/
|
|
8
|
+
export declare function installWindowsCliSignals(): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=windows-cli-signals.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qilin-agent/desktop-host",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Private Node-mode host process for the Electron desktop application",
|
|
4
|
+
"version": "3.1.7",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib/*.js",
|
|
10
|
+
"lib/types/*.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@deepseek-ai/libreoffice-kit": "^0.1.0",
|
|
14
|
+
"koffi": "3.1.1",
|
|
15
|
+
"@qilin-agent/agent": "3.1.7",
|
|
16
|
+
"@qilin-agent/cli": "3.1.7",
|
|
17
|
+
"@qilin-agent/home-paths": "3.1.7",
|
|
18
|
+
"@qilin-agent/client-connection": "3.1.7",
|
|
19
|
+
"@qilin-agent/host-webserver": "3.1.7",
|
|
20
|
+
"@qilin-agent/app-boot": "3.1.7",
|
|
21
|
+
"@qilin-agent/jobs": "3.1.7",
|
|
22
|
+
"@qilin-agent/kylin": "~4.0.5",
|
|
23
|
+
"@qilin-agent/tool-workspace-dependencies": "3.1.7",
|
|
24
|
+
"@qilin-agent/skill-office": "3.1.7",
|
|
25
|
+
"@qilin-agent/schedule": "3.1.7",
|
|
26
|
+
"@qilin-agent/workspace": "3.1.7"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@qilin-agent/kylin-plugin-include": "~1.0.10",
|
|
30
|
+
"@qilin-agent/kylin-plugin-loader": "~1.0.6",
|
|
31
|
+
"@qilin-agent/skill": "3.1.7"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/kkutysllb/QiLin.git",
|
|
39
|
+
"directory": "apps/desktop-host"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
43
|
+
}
|
|
6
44
|
}
|
package/README.md
DELETED