@keyou007/agent-bot 0.1.14-alpha.1 → 0.1.14-alpha.3
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/CHANGELOG.md +19 -1
- package/README.md +48 -15
- package/README.zh.md +48 -15
- package/config.example.yaml +1 -1
- package/dist/cli/AutostartManager.js +431 -0
- package/dist/cli/AutostartManager.js.map +1 -0
- package/dist/cli/FeishuAppConfiguration.js +21 -13
- package/dist/cli/FeishuAppConfiguration.js.map +1 -1
- package/dist/cli/Initializer.js +35 -0
- package/dist/cli/Initializer.js.map +1 -1
- package/dist/cli/SelfUpdateRunner.js +552 -0
- package/dist/cli/SelfUpdateRunner.js.map +1 -0
- package/dist/cli/SelfUpdater.js +431 -0
- package/dist/cli/SelfUpdater.js.map +1 -0
- package/dist/cli/autostartOutput.js +63 -0
- package/dist/cli/autostartOutput.js.map +1 -0
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +94 -18
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/taskGroupOptions.js +14 -11
- package/dist/cli/taskGroupOptions.js.map +1 -1
- package/dist/cli/taskListOutput.js +3 -0
- package/dist/cli/taskListOutput.js.map +1 -1
- package/dist/cli/taskTarget.js +99 -0
- package/dist/cli/taskTarget.js.map +1 -0
- package/dist/cli.js +661 -58
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexRuntime.js +8 -2
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/commands/CommandRouter.js +16 -1
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/feishu/CardRenderer.js +266 -38
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuMarkdown.js +25 -1
- package/dist/feishu/FeishuMarkdown.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +16 -0
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +42 -6
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +136 -2
- package/dist/index.js.map +1 -1
- package/dist/presentation/OutboundRouter.js +7 -0
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +21 -7
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +537 -13
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/state/StateStore.js +53 -0
- package/dist/state/StateStore.js.map +1 -1
- package/docs/technical-reference.md +17 -7
- package/docs/technical-reference.zh.md +17 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
- package/skills/agent-bot/SKILL.md +109 -188
- package/src/cli/AutostartManager.ts +579 -0
- package/src/cli/FeishuAppConfiguration.ts +26 -7
- package/src/cli/Initializer.ts +57 -0
- package/src/cli/SelfUpdateRunner.ts +817 -0
- package/src/cli/SelfUpdater.ts +688 -0
- package/src/cli/autostartOutput.ts +75 -0
- package/src/cli/controlProtocol.ts +119 -1
- package/src/cli/help.ts +94 -18
- package/src/cli/taskGroupOptions.ts +27 -17
- package/src/cli/taskListOutput.ts +10 -0
- package/src/cli/taskTarget.ts +168 -0
- package/src/cli.ts +809 -65
- package/src/codex/CodexRuntime.ts +8 -2
- package/src/commands/CommandRouter.ts +14 -1
- package/src/commands/commandTypes.ts +2 -0
- package/src/feishu/CardRenderer.ts +313 -35
- package/src/feishu/FeishuMarkdown.ts +27 -1
- package/src/feishu/FeishuMessageClient.ts +33 -0
- package/src/feishu/FeishuTurnPresenter.ts +43 -6
- package/src/feishu/types.ts +1 -0
- package/src/index.ts +174 -2
- package/src/presentation/OutboundRouter.ts +7 -0
- package/src/presentation/TurnStateReducer.ts +21 -7
- package/src/proxy/ProxySessionController.ts +661 -16
- package/src/runtime/types.ts +1 -0
- package/src/state/StateStore.ts +56 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import { AGENT_BOT_EXPLICIT_PROFILE_ENV, AGENT_BOT_HOME_ENV, agentBotHome, defaultConfigPath, resolveUserPath, } from "../config/paths.js";
|
|
8
|
+
import { nodeDiagnosticReportArguments, resolveSupervisorDiagnosticsPaths, } from "../supervision/SupervisorDiagnostics.js";
|
|
9
|
+
export class AutostartManager {
|
|
10
|
+
context;
|
|
11
|
+
plan;
|
|
12
|
+
dependencies;
|
|
13
|
+
constructor(context, overrides = {}) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.dependencies = { ...defaultDependencies(), ...overrides };
|
|
16
|
+
if (isSupportedPlatform(this.dependencies.platform)) {
|
|
17
|
+
this.plan = createAutostartPlan(context, this.dependencies.platform, this.dependencies.homeDirectory, this.dependencies.appDataDirectory);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
enable(options = {}) {
|
|
21
|
+
const plan = this.requirePlan();
|
|
22
|
+
if (options.linger && plan.platform !== "linux") {
|
|
23
|
+
throw new Error("--linger is supported only on Linux.");
|
|
24
|
+
}
|
|
25
|
+
this.dependencies.write(plan.bootstrapPath, plan.bootstrapContent);
|
|
26
|
+
if (plan.definitionContent !== undefined) {
|
|
27
|
+
this.dependencies.write(plan.definitionPath, plan.definitionContent);
|
|
28
|
+
}
|
|
29
|
+
if (plan.platform === "win32") {
|
|
30
|
+
const task = this.dependencies.run("schtasks.exe", [
|
|
31
|
+
"/Create",
|
|
32
|
+
"/TN",
|
|
33
|
+
plan.name,
|
|
34
|
+
"/SC",
|
|
35
|
+
"ONLOGON",
|
|
36
|
+
"/TR",
|
|
37
|
+
windowsCommandLine(plan.command, plan.commandArguments),
|
|
38
|
+
"/RL",
|
|
39
|
+
"LIMITED",
|
|
40
|
+
"/F",
|
|
41
|
+
]);
|
|
42
|
+
if (!task.error && task.status === 0) {
|
|
43
|
+
if (plan.windowsFallbackPath)
|
|
44
|
+
this.dependencies.remove(plan.windowsFallbackPath);
|
|
45
|
+
}
|
|
46
|
+
else if (plan.windowsFallbackPath && plan.windowsFallbackContent) {
|
|
47
|
+
this.dependencies.write(plan.windowsFallbackPath, plan.windowsFallbackContent);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.throwCommandError(task, "Could not register the Windows startup task");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (plan.platform === "linux") {
|
|
54
|
+
this.runChecked("systemctl", ["--user", "daemon-reload"], "Could not reload systemd user units");
|
|
55
|
+
this.runChecked("systemctl", ["--user", "enable", plan.name], "Could not enable the systemd user unit");
|
|
56
|
+
if (options.linger) {
|
|
57
|
+
this.runChecked("loginctl", ["enable-linger", this.dependencies.username], "Could not enable systemd user lingering");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return this.status();
|
|
61
|
+
}
|
|
62
|
+
disable() {
|
|
63
|
+
const plan = this.requirePlan();
|
|
64
|
+
const current = this.status();
|
|
65
|
+
if (plan.platform === "win32") {
|
|
66
|
+
const taskRegistered = this.dependencies.run("schtasks.exe", ["/Query", "/TN", plan.name]).status === 0;
|
|
67
|
+
if (taskRegistered) {
|
|
68
|
+
this.runChecked("schtasks.exe", ["/Delete", "/TN", plan.name, "/F"], "Could not remove the Windows startup task");
|
|
69
|
+
}
|
|
70
|
+
if (plan.windowsFallbackPath)
|
|
71
|
+
this.dependencies.remove(plan.windowsFallbackPath);
|
|
72
|
+
}
|
|
73
|
+
else if (plan.platform === "linux") {
|
|
74
|
+
if (current.enabled) {
|
|
75
|
+
this.runChecked("systemctl", ["--user", "disable", plan.name], "Could not disable the systemd user unit");
|
|
76
|
+
}
|
|
77
|
+
this.dependencies.remove(plan.definitionPath);
|
|
78
|
+
this.runChecked("systemctl", ["--user", "daemon-reload"], "Could not reload systemd user units");
|
|
79
|
+
}
|
|
80
|
+
else if (plan.platform === "darwin") {
|
|
81
|
+
this.dependencies.remove(plan.definitionPath);
|
|
82
|
+
}
|
|
83
|
+
this.dependencies.remove(plan.bootstrapPath);
|
|
84
|
+
this.dependencies.removeDirectoryIfEmpty(path.dirname(plan.bootstrapPath));
|
|
85
|
+
return this.status();
|
|
86
|
+
}
|
|
87
|
+
status() {
|
|
88
|
+
const platform = this.dependencies.platform;
|
|
89
|
+
if (!this.plan) {
|
|
90
|
+
return {
|
|
91
|
+
supported: false,
|
|
92
|
+
platform,
|
|
93
|
+
profilePath: this.context.profilePath,
|
|
94
|
+
configPath: this.context.configPath,
|
|
95
|
+
enabled: false,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const plan = this.plan;
|
|
99
|
+
if (plan.platform === "win32") {
|
|
100
|
+
const task = this.dependencies.run("schtasks.exe", ["/Query", "/TN", plan.name]);
|
|
101
|
+
const fallback = plan.windowsFallbackPath
|
|
102
|
+
? this.dependencies.exists(plan.windowsFallbackPath)
|
|
103
|
+
: false;
|
|
104
|
+
return this.registrationStatus(task.status === 0 || fallback, {
|
|
105
|
+
mechanism: task.status === 0 ? "task-scheduler" : fallback ? "startup-folder" : undefined,
|
|
106
|
+
definitionPath: fallback ? plan.windowsFallbackPath : plan.definitionPath,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (plan.platform === "darwin") {
|
|
110
|
+
const domain = `gui/${this.dependencies.uid ?? 0}/${plan.name}`;
|
|
111
|
+
const loaded = this.dependencies.run("launchctl", ["print", domain]).status === 0;
|
|
112
|
+
return this.registrationStatus(this.dependencies.exists(plan.definitionPath), {
|
|
113
|
+
loaded,
|
|
114
|
+
mechanism: "launch-agent",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const enabled = this.dependencies.run("systemctl", ["--user", "is-enabled", plan.name]).status === 0;
|
|
118
|
+
const loaded = this.dependencies.run("systemctl", ["--user", "is-active", plan.name]).status === 0;
|
|
119
|
+
const lingerResult = this.dependencies.run("loginctl", [
|
|
120
|
+
"show-user",
|
|
121
|
+
this.dependencies.username,
|
|
122
|
+
"--property=Linger",
|
|
123
|
+
"--value",
|
|
124
|
+
]);
|
|
125
|
+
const linger = lingerResult.status === 0 && lingerResult.stdout.trim().toLowerCase() === "yes";
|
|
126
|
+
return this.registrationStatus(enabled, {
|
|
127
|
+
loaded,
|
|
128
|
+
linger,
|
|
129
|
+
trigger: linger ? "boot" : "login",
|
|
130
|
+
mechanism: "systemd",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
requirePlan() {
|
|
134
|
+
if (!this.plan) {
|
|
135
|
+
throw new Error(`Autostart is not supported on ${this.dependencies.platform}.`);
|
|
136
|
+
}
|
|
137
|
+
return this.plan;
|
|
138
|
+
}
|
|
139
|
+
registrationStatus(enabled, details = {}) {
|
|
140
|
+
const plan = this.requirePlan();
|
|
141
|
+
return {
|
|
142
|
+
supported: true,
|
|
143
|
+
platform: plan.platform,
|
|
144
|
+
profilePath: plan.profilePath,
|
|
145
|
+
configPath: plan.configPath,
|
|
146
|
+
enabled,
|
|
147
|
+
name: plan.name,
|
|
148
|
+
definitionPath: details.definitionPath ?? plan.definitionPath,
|
|
149
|
+
trigger: details.trigger ?? "login",
|
|
150
|
+
...(details.mechanism === undefined ? {} : { mechanism: details.mechanism }),
|
|
151
|
+
...(details.loaded === undefined ? {} : { loaded: details.loaded }),
|
|
152
|
+
...(details.linger === undefined ? {} : { linger: details.linger }),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
runChecked(command, args, description) {
|
|
156
|
+
const result = this.dependencies.run(command, args);
|
|
157
|
+
if (!result.error && result.status === 0)
|
|
158
|
+
return;
|
|
159
|
+
this.throwCommandError(result, description);
|
|
160
|
+
}
|
|
161
|
+
throwCommandError(result, description) {
|
|
162
|
+
const detail = result.error?.message || result.stderr.trim() || result.stdout.trim()
|
|
163
|
+
|| `exit code ${result.status ?? "unknown"}`;
|
|
164
|
+
throw new Error(`${description}: ${detail}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export function createCurrentAutostartManager(config, overrides = {}) {
|
|
168
|
+
const configuredPath = process.env.AGENT_BOT_CONFIG?.trim();
|
|
169
|
+
const profilePath = agentBotHome();
|
|
170
|
+
const configPath = configuredPath ? resolveUserPath(configuredPath) : defaultConfigPath();
|
|
171
|
+
return new AutostartManager({
|
|
172
|
+
profilePath,
|
|
173
|
+
configPath,
|
|
174
|
+
nodePath: process.execPath,
|
|
175
|
+
supervisorPath: fileURLToPath(new URL("../supervisor.js", import.meta.url)),
|
|
176
|
+
crashReportDirectory: resolveSupervisorDiagnosticsPaths(config).crashReportDirectory,
|
|
177
|
+
pathValue: process.env.PATH,
|
|
178
|
+
}, overrides);
|
|
179
|
+
}
|
|
180
|
+
export function createAutostartPlan(context, platform, homeDirectory, appDataDirectory) {
|
|
181
|
+
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
182
|
+
const profilePath = pathApi.resolve(context.profilePath);
|
|
183
|
+
const configPath = pathApi.resolve(context.configPath);
|
|
184
|
+
const bootstrapPath = pathApi.join(profilePath, "autostart", "supervisor-bootstrap.mjs");
|
|
185
|
+
const identity = createHash("sha256")
|
|
186
|
+
.update(`${platform}\0${profilePath}\0${configPath}`)
|
|
187
|
+
.digest("hex")
|
|
188
|
+
.slice(0, 10);
|
|
189
|
+
const bootstrapContent = renderBootstrap({ ...context, profilePath, configPath }, platform);
|
|
190
|
+
const commandArguments = [
|
|
191
|
+
...nodeDiagnosticReportArguments(context.crashReportDirectory),
|
|
192
|
+
bootstrapPath,
|
|
193
|
+
];
|
|
194
|
+
if (platform === "win32") {
|
|
195
|
+
const profileName = sanitizeName(pathApi.basename(profilePath).replace(/^\.+/, "") || "main");
|
|
196
|
+
const name = `AgentBot-${profileName}-${identity}`;
|
|
197
|
+
const fallbackPath = pathApi.join(appDataDirectory ?? pathApi.join(homeDirectory, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", `${name}.vbs`);
|
|
198
|
+
return {
|
|
199
|
+
platform,
|
|
200
|
+
name,
|
|
201
|
+
profilePath,
|
|
202
|
+
configPath,
|
|
203
|
+
bootstrapPath,
|
|
204
|
+
bootstrapContent,
|
|
205
|
+
definitionPath: bootstrapPath,
|
|
206
|
+
command: context.nodePath,
|
|
207
|
+
commandArguments,
|
|
208
|
+
windowsFallbackPath: fallbackPath,
|
|
209
|
+
windowsFallbackContent: renderWindowsStartupScript(context.nodePath, commandArguments),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (platform === "darwin") {
|
|
213
|
+
const name = `com.keyou.agent-bot.${identity}`;
|
|
214
|
+
const definitionPath = pathApi.join(homeDirectory, "Library", "LaunchAgents", `${name}.plist`);
|
|
215
|
+
const stdoutPath = pathApi.join(profilePath, "logs", "autostart.stdout.log");
|
|
216
|
+
const stderrPath = pathApi.join(profilePath, "logs", "autostart.stderr.log");
|
|
217
|
+
return {
|
|
218
|
+
platform,
|
|
219
|
+
name,
|
|
220
|
+
profilePath,
|
|
221
|
+
configPath,
|
|
222
|
+
bootstrapPath,
|
|
223
|
+
bootstrapContent,
|
|
224
|
+
definitionPath,
|
|
225
|
+
definitionContent: renderLaunchAgent({
|
|
226
|
+
name,
|
|
227
|
+
command: context.nodePath,
|
|
228
|
+
commandArguments,
|
|
229
|
+
workingDirectory: profilePath,
|
|
230
|
+
stdoutPath,
|
|
231
|
+
stderrPath,
|
|
232
|
+
}),
|
|
233
|
+
command: context.nodePath,
|
|
234
|
+
commandArguments,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const name = `agent-bot-${identity}.service`;
|
|
238
|
+
const definitionPath = pathApi.join(homeDirectory, ".config", "systemd", "user", name);
|
|
239
|
+
return {
|
|
240
|
+
platform,
|
|
241
|
+
name,
|
|
242
|
+
profilePath,
|
|
243
|
+
configPath,
|
|
244
|
+
bootstrapPath,
|
|
245
|
+
bootstrapContent,
|
|
246
|
+
definitionPath,
|
|
247
|
+
definitionContent: renderSystemdUnit({
|
|
248
|
+
profilePath,
|
|
249
|
+
command: context.nodePath,
|
|
250
|
+
commandArguments,
|
|
251
|
+
}),
|
|
252
|
+
command: context.nodePath,
|
|
253
|
+
commandArguments,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function renderBootstrap(context, platform) {
|
|
257
|
+
return [
|
|
258
|
+
`process.env.${AGENT_BOT_HOME_ENV} = ${JSON.stringify(context.profilePath)};`,
|
|
259
|
+
`process.env.AGENT_BOT_CONFIG = ${JSON.stringify(context.configPath)};`,
|
|
260
|
+
`process.env.${AGENT_BOT_EXPLICIT_PROFILE_ENV} = "1";`,
|
|
261
|
+
...(context.pathValue?.trim()
|
|
262
|
+
? [`process.env.PATH = ${JSON.stringify(context.pathValue)};`]
|
|
263
|
+
: []),
|
|
264
|
+
"delete process.env.FEISHU_APP_ID;",
|
|
265
|
+
"delete process.env.FEISHU_APP_SECRET;",
|
|
266
|
+
"delete process.env.FEISHU_USER_OPEN_ID;",
|
|
267
|
+
`process.chdir(${JSON.stringify(context.profilePath)});`,
|
|
268
|
+
`await import(${JSON.stringify(fileUrlForPlatform(context.supervisorPath, platform))});`,
|
|
269
|
+
"",
|
|
270
|
+
].join("\n");
|
|
271
|
+
}
|
|
272
|
+
function fileUrlForPlatform(filePath, platform) {
|
|
273
|
+
if (platform !== "win32")
|
|
274
|
+
return pathToFileURL(filePath).href;
|
|
275
|
+
const normalized = filePath.replaceAll("\\", "/");
|
|
276
|
+
if (normalized.startsWith("//")) {
|
|
277
|
+
const [host = "", ...segments] = normalized.slice(2).split("/");
|
|
278
|
+
return `file://${host}/${segments.map(encodeURIComponent).join("/")}`;
|
|
279
|
+
}
|
|
280
|
+
const drivePath = /^([A-Za-z]):\/(.*)$/.exec(normalized);
|
|
281
|
+
if (!drivePath)
|
|
282
|
+
return pathToFileURL(filePath).href;
|
|
283
|
+
return `file:///${drivePath[1]}:/${(drivePath[2] ?? "").split("/").map(encodeURIComponent).join("/")}`;
|
|
284
|
+
}
|
|
285
|
+
function renderLaunchAgent(input) {
|
|
286
|
+
const argumentsXml = [input.command, ...input.commandArguments]
|
|
287
|
+
.map((value) => ` <string>${escapeXml(value)}</string>`)
|
|
288
|
+
.join("\n");
|
|
289
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
290
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
291
|
+
<plist version="1.0">
|
|
292
|
+
<dict>
|
|
293
|
+
<key>Label</key>
|
|
294
|
+
<string>${escapeXml(input.name)}</string>
|
|
295
|
+
<key>ProgramArguments</key>
|
|
296
|
+
<array>
|
|
297
|
+
${argumentsXml}
|
|
298
|
+
</array>
|
|
299
|
+
<key>WorkingDirectory</key>
|
|
300
|
+
<string>${escapeXml(input.workingDirectory)}</string>
|
|
301
|
+
<key>RunAtLoad</key>
|
|
302
|
+
<true/>
|
|
303
|
+
<key>KeepAlive</key>
|
|
304
|
+
<false/>
|
|
305
|
+
<key>ProcessType</key>
|
|
306
|
+
<string>Background</string>
|
|
307
|
+
<key>StandardOutPath</key>
|
|
308
|
+
<string>${escapeXml(input.stdoutPath)}</string>
|
|
309
|
+
<key>StandardErrorPath</key>
|
|
310
|
+
<string>${escapeXml(input.stderrPath)}</string>
|
|
311
|
+
</dict>
|
|
312
|
+
</plist>
|
|
313
|
+
`;
|
|
314
|
+
}
|
|
315
|
+
function renderSystemdUnit(input) {
|
|
316
|
+
const commandLine = [input.command, ...input.commandArguments].map(systemdQuote).join(" ");
|
|
317
|
+
return `[Unit]
|
|
318
|
+
Description=Agent Bot Supervisor
|
|
319
|
+
Wants=network-online.target
|
|
320
|
+
After=network-online.target
|
|
321
|
+
|
|
322
|
+
[Service]
|
|
323
|
+
Type=simple
|
|
324
|
+
WorkingDirectory=${systemdQuote(input.profilePath)}
|
|
325
|
+
ExecStart=${commandLine}
|
|
326
|
+
Restart=no
|
|
327
|
+
|
|
328
|
+
[Install]
|
|
329
|
+
WantedBy=default.target
|
|
330
|
+
`;
|
|
331
|
+
}
|
|
332
|
+
function defaultDependencies() {
|
|
333
|
+
return {
|
|
334
|
+
platform: process.platform,
|
|
335
|
+
homeDirectory: os.homedir(),
|
|
336
|
+
username: currentUsername(),
|
|
337
|
+
uid: process.getuid?.(),
|
|
338
|
+
appDataDirectory: process.env.APPDATA?.trim(),
|
|
339
|
+
run: (command, args) => {
|
|
340
|
+
const result = spawnSync(command, args, {
|
|
341
|
+
encoding: "utf8",
|
|
342
|
+
windowsHide: true,
|
|
343
|
+
timeout: 15_000,
|
|
344
|
+
});
|
|
345
|
+
return {
|
|
346
|
+
status: result.status,
|
|
347
|
+
stdout: result.stdout ?? "",
|
|
348
|
+
stderr: result.stderr ?? "",
|
|
349
|
+
...(result.error ? { error: result.error } : {}),
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
exists: (filePath) => fs.existsSync(filePath),
|
|
353
|
+
write: (filePath, content) => writePrivateFile(filePath, content),
|
|
354
|
+
remove: (filePath) => fs.rmSync(filePath, { force: true }),
|
|
355
|
+
removeDirectoryIfEmpty: (directoryPath) => {
|
|
356
|
+
try {
|
|
357
|
+
fs.rmdirSync(directoryPath);
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
// The directory is shared with a newer registration or contains user files.
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function writePrivateFile(filePath, content) {
|
|
366
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
367
|
+
fs.writeFileSync(filePath, content, { encoding: "utf8", mode: 0o600 });
|
|
368
|
+
try {
|
|
369
|
+
fs.chmodSync(filePath, 0o600);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
// Windows and some mounted filesystems do not implement POSIX modes.
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function currentUsername() {
|
|
376
|
+
try {
|
|
377
|
+
return os.userInfo().username;
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
return process.env.USER?.trim() || process.env.USERNAME?.trim() || "";
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function isSupportedPlatform(platform) {
|
|
384
|
+
return platform === "win32" || platform === "darwin" || platform === "linux";
|
|
385
|
+
}
|
|
386
|
+
function sanitizeName(value) {
|
|
387
|
+
return value.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "main";
|
|
388
|
+
}
|
|
389
|
+
function escapeXml(value) {
|
|
390
|
+
return value
|
|
391
|
+
.replaceAll("&", "&")
|
|
392
|
+
.replaceAll("<", "<")
|
|
393
|
+
.replaceAll(">", ">")
|
|
394
|
+
.replaceAll("\"", """)
|
|
395
|
+
.replaceAll("'", "'");
|
|
396
|
+
}
|
|
397
|
+
function systemdQuote(value) {
|
|
398
|
+
return `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"").replaceAll("%", "%%")}"`;
|
|
399
|
+
}
|
|
400
|
+
function windowsCommandLine(command, args) {
|
|
401
|
+
return [command, ...args].map(quoteWindowsArgument).join(" ");
|
|
402
|
+
}
|
|
403
|
+
function renderWindowsStartupScript(command, args) {
|
|
404
|
+
const commandLine = windowsCommandLine(command, args).replaceAll("\"", "\"\"");
|
|
405
|
+
return [
|
|
406
|
+
"Set shell = CreateObject(\"WScript.Shell\")",
|
|
407
|
+
`shell.Run "${commandLine}", 0, False`,
|
|
408
|
+
"",
|
|
409
|
+
].join("\r\n");
|
|
410
|
+
}
|
|
411
|
+
function quoteWindowsArgument(value) {
|
|
412
|
+
if (value && !/[\s"]/u.test(value))
|
|
413
|
+
return value;
|
|
414
|
+
let result = "\"";
|
|
415
|
+
let backslashes = 0;
|
|
416
|
+
for (const character of value) {
|
|
417
|
+
if (character === "\\") {
|
|
418
|
+
backslashes += 1;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
if (character === "\"") {
|
|
422
|
+
result += "\\".repeat(backslashes * 2 + 1) + "\"";
|
|
423
|
+
backslashes = 0;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
result += "\\".repeat(backslashes) + character;
|
|
427
|
+
backslashes = 0;
|
|
428
|
+
}
|
|
429
|
+
return `${result}${"\\".repeat(backslashes * 2)}\"`;
|
|
430
|
+
}
|
|
431
|
+
//# sourceMappingURL=AutostartManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutostartManager.js","sourceRoot":"","sources":["../../src/cli/AutostartManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,GAClC,MAAM,yCAAyC,CAAC;AAoEjD,MAAM,OAAO,gBAAgB;IAKR,OAAO;IAJjB,IAAI,CAAiB;IACb,YAAY,CAAwB;IAErD,YACmB,OAAyB,EAC1C,SAAS,GAAiC,EAAE;uBAD3B,OAAO;QAGxB,IAAI,CAAC,YAAY,GAAG,EAAE,GAAG,mBAAmB,EAAE,EAAE,GAAG,SAAS,EAAE,CAAC;QAC/D,IAAI,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAC7B,OAAO,EACP,IAAI,CAAC,YAAY,CAAC,QAAQ,EAC1B,IAAI,CAAC,YAAY,CAAC,aAAa,EAC/B,IAAI,CAAC,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16
16
|
requested: "im:chat:create",
|
|
17
17
|
accepted: ["im:chat:create", "im:chat"],
|
|
18
18
|
},
|
|
19
|
+
{
|
|
20
|
+
requested: "im:chat:delete",
|
|
21
|
+
accepted: ["im:chat:delete", "im:chat:operate_as_owner", "im:chat"],
|
|
22
|
+
},
|
|
19
23
|
{
|
|
20
24
|
requested: "im:chat:read",
|
|
21
25
|
accepted: ["im:chat:read", "im:chat:readonly", "im:chat"],
|
|
@@ -62,7 +66,8 @@ const CORE_FEISHU_SCOPES = new Set([
|
|
|
62
66
|
"im:message:send_as_bot",
|
|
63
67
|
]);
|
|
64
68
|
const CORE_FEISHU_EVENTS = new Set(["im.message.receive_v1"]);
|
|
65
|
-
const
|
|
69
|
+
const ALL_GROUP_MESSAGE_SCOPES = new Set(["im:message.group_msg"]);
|
|
70
|
+
const MANUAL_FEISHU_SCOPES = ALL_GROUP_MESSAGE_SCOPES;
|
|
66
71
|
export async function ensureFeishuAppConfiguration(credentials, options = {}) {
|
|
67
72
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
68
73
|
const sleep = options.sleep ?? delay;
|
|
@@ -70,6 +75,9 @@ export async function ensureFeishuAppConfiguration(credentials, options = {}) {
|
|
|
70
75
|
const timeoutMs = positiveInteger(options.timeoutMs) ?? DEFAULT_COMPLETION_TIMEOUT_MS;
|
|
71
76
|
const optionalTimeoutMs = positiveInteger(options.optionalTimeoutMs)
|
|
72
77
|
?? DEFAULT_OPTIONAL_COMPLETION_TIMEOUT_MS;
|
|
78
|
+
const excludedScopes = options.respondToAllGroupMessages === false
|
|
79
|
+
? ALL_GROUP_MESSAGE_SCOPES
|
|
80
|
+
: new Set();
|
|
73
81
|
let configuration;
|
|
74
82
|
try {
|
|
75
83
|
configuration = await readFeishuAppConfiguration(credentials, fetchImpl, options.signal);
|
|
@@ -79,7 +87,7 @@ export async function ensureFeishuAppConfiguration(credentials, options = {}) {
|
|
|
79
87
|
throw error;
|
|
80
88
|
configuration = emptyConfiguration();
|
|
81
89
|
}
|
|
82
|
-
const missing = missingFeishuAppConfiguration(configuration);
|
|
90
|
+
const missing = withoutIgnoredScopes(missingFeishuAppConfiguration(configuration), excludedScopes);
|
|
83
91
|
if (!hasMissingConfiguration(missing)) {
|
|
84
92
|
return {
|
|
85
93
|
status: "ready",
|
|
@@ -90,7 +98,7 @@ export async function ensureFeishuAppConfiguration(credentials, options = {}) {
|
|
|
90
98
|
}
|
|
91
99
|
const coreMissing = coreMissingFeishuAppConfiguration(missing);
|
|
92
100
|
if (!hasMissingConfiguration(coreMissing)) {
|
|
93
|
-
return completeOptionalFeishuConfiguration(credentials, configuration, missing, fetchImpl, sleep, pollIntervalMs, optionalTimeoutMs, options);
|
|
101
|
+
return completeOptionalFeishuConfiguration(credentials, configuration, missing, fetchImpl, sleep, pollIntervalMs, optionalTimeoutMs, options, new Set(), excludedScopes);
|
|
94
102
|
}
|
|
95
103
|
await requestMissingFeishuConfiguration(credentials.appId, coreMissing, true, options.onVerification);
|
|
96
104
|
let remainingMs = timeoutMs;
|
|
@@ -108,19 +116,19 @@ export async function ensureFeishuAppConfiguration(credentials, options = {}) {
|
|
|
108
116
|
refreshImmediately = false;
|
|
109
117
|
try {
|
|
110
118
|
configuration = await readFeishuAppConfiguration(credentials, fetchImpl, options.signal);
|
|
111
|
-
const remaining = missingFeishuAppConfiguration(configuration);
|
|
119
|
+
const remaining = withoutIgnoredScopes(missingFeishuAppConfiguration(configuration), excludedScopes);
|
|
112
120
|
const unresolvedCore = coreMissingFeishuAppConfiguration(remaining);
|
|
113
121
|
if (!hasBlockingCoreConfiguration(unresolvedCore, options.manualPermissionSkipSignal)) {
|
|
114
|
-
return completeOptionalFeishuConfiguration(credentials, configuration, missing, fetchImpl, sleep, pollIntervalMs, optionalTimeoutMs, options, skippedManualScopes(coreMissing, options.manualPermissionSkipSignal));
|
|
122
|
+
return completeOptionalFeishuConfiguration(credentials, configuration, missing, fetchImpl, sleep, pollIntervalMs, optionalTimeoutMs, options, skippedManualScopes(coreMissing, options.manualPermissionSkipSignal), excludedScopes);
|
|
115
123
|
}
|
|
116
124
|
lastError = undefined;
|
|
117
125
|
}
|
|
118
126
|
catch (error) {
|
|
119
127
|
if (options.signal?.aborted)
|
|
120
128
|
throw abortError(options.signal);
|
|
121
|
-
const knownRemaining = missingFeishuAppConfiguration(configuration);
|
|
129
|
+
const knownRemaining = withoutIgnoredScopes(missingFeishuAppConfiguration(configuration), excludedScopes);
|
|
122
130
|
if (!hasBlockingCoreConfiguration(coreMissingFeishuAppConfiguration(knownRemaining), options.manualPermissionSkipSignal)) {
|
|
123
|
-
return completeOptionalFeishuConfiguration(credentials, configuration, missing, fetchImpl, sleep, pollIntervalMs, optionalTimeoutMs, options, skippedManualScopes(coreMissing, options.manualPermissionSkipSignal));
|
|
131
|
+
return completeOptionalFeishuConfiguration(credentials, configuration, missing, fetchImpl, sleep, pollIntervalMs, optionalTimeoutMs, options, skippedManualScopes(coreMissing, options.manualPermissionSkipSignal), excludedScopes);
|
|
124
132
|
}
|
|
125
133
|
lastError = error;
|
|
126
134
|
}
|
|
@@ -153,14 +161,14 @@ async function requestMissingFeishuConfiguration(appId, missing, blocking, onVer
|
|
|
153
161
|
});
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
|
-
async function completeOptionalFeishuConfiguration(credentials, initialConfiguration, initialMissing, fetchImpl, sleep, pollIntervalMs, timeoutMs, options, ignoredScopes = new Set()) {
|
|
164
|
+
async function completeOptionalFeishuConfiguration(credentials, initialConfiguration, initialMissing, fetchImpl, sleep, pollIntervalMs, timeoutMs, options, ignoredScopes = new Set(), excludedScopes = new Set()) {
|
|
157
165
|
let configuration = initialConfiguration;
|
|
158
|
-
let remaining = missingFeishuAppConfiguration(configuration);
|
|
166
|
+
let remaining = withoutIgnoredScopes(missingFeishuAppConfiguration(configuration), excludedScopes);
|
|
159
167
|
const requested = withoutIgnoredScopes(remaining, ignoredScopes);
|
|
160
168
|
if (hasMissingConfiguration(requested)) {
|
|
161
169
|
await requestMissingFeishuConfiguration(credentials.appId, requested, false, options.onVerification);
|
|
162
170
|
if (!options.optionalSkipSignal?.aborted) {
|
|
163
|
-
const completed = await waitForOptionalFeishuConfiguration(credentials, configuration, fetchImpl, sleep, pollIntervalMs, timeoutMs, options.signal, options.optionalSkipSignal, ignoredScopes);
|
|
171
|
+
const completed = await waitForOptionalFeishuConfiguration(credentials, configuration, fetchImpl, sleep, pollIntervalMs, timeoutMs, options.signal, options.optionalSkipSignal, ignoredScopes, excludedScopes);
|
|
164
172
|
configuration = completed.configuration;
|
|
165
173
|
remaining = completed.remaining;
|
|
166
174
|
}
|
|
@@ -172,9 +180,9 @@ async function completeOptionalFeishuConfiguration(credentials, initialConfigura
|
|
|
172
180
|
remaining,
|
|
173
181
|
};
|
|
174
182
|
}
|
|
175
|
-
async function waitForOptionalFeishuConfiguration(credentials, initialConfiguration, fetchImpl, sleep, pollIntervalMs, timeoutMs, signal, optionalSkipSignal, ignoredScopes = new Set()) {
|
|
183
|
+
async function waitForOptionalFeishuConfiguration(credentials, initialConfiguration, fetchImpl, sleep, pollIntervalMs, timeoutMs, signal, optionalSkipSignal, ignoredScopes = new Set(), excludedScopes = new Set()) {
|
|
176
184
|
let configuration = initialConfiguration;
|
|
177
|
-
let remaining = missingFeishuAppConfiguration(configuration);
|
|
185
|
+
let remaining = withoutIgnoredScopes(missingFeishuAppConfiguration(configuration), excludedScopes);
|
|
178
186
|
let remainingMs = timeoutMs;
|
|
179
187
|
while (remainingMs > 0 && hasMissingConfiguration(withoutIgnoredScopes(remaining, ignoredScopes))) {
|
|
180
188
|
if (optionalSkipSignal?.aborted)
|
|
@@ -186,7 +194,7 @@ async function waitForOptionalFeishuConfiguration(credentials, initialConfigurat
|
|
|
186
194
|
remainingMs -= waitMs;
|
|
187
195
|
try {
|
|
188
196
|
configuration = await readFeishuAppConfiguration(credentials, fetchImpl, signal);
|
|
189
|
-
remaining = missingFeishuAppConfiguration(configuration);
|
|
197
|
+
remaining = withoutIgnoredScopes(missingFeishuAppConfiguration(configuration), excludedScopes);
|
|
190
198
|
}
|
|
191
199
|
catch (error) {
|
|
192
200
|
if (signal?.aborted)
|