@nowcrew/daemon 0.5.28 → 0.5.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/attachments.js +196 -0
- package/dist/bound-im-decision.js +22 -0
- package/dist/completion-retransmitter.js +77 -0
- package/dist/computer-cli.js +274 -0
- package/dist/computer-profile-lock.js +395 -0
- package/dist/computer-profile.js +364 -0
- package/dist/computer-service.js +358 -0
- package/dist/config.js +82 -0
- package/dist/console-collapse.js +13 -0
- package/dist/console-formatter.js +77 -0
- package/dist/console-payload.js +73 -0
- package/dist/console.js +329 -0
- package/dist/daemon-startup-error.js +30 -0
- package/dist/execution-backend.js +44 -0
- package/dist/execution-event-limit.js +64 -0
- package/dist/execution-journal-lock.js +421 -0
- package/dist/execution-journal.js +716 -0
- package/dist/execution-protocol.js +342 -0
- package/dist/execution-recovery.js +95 -0
- package/dist/execution-runner.js +659 -0
- package/dist/execution-supervisor-child.js +236 -0
- package/dist/execution-supervisor.js +316 -0
- package/dist/execution-telemetry-journal.js +71 -0
- package/dist/external-output.js +114 -0
- package/dist/i18n.js +64 -0
- package/dist/json-result.js +27 -0
- package/dist/list-models.js +92 -0
- package/dist/local-executor.js +439 -0
- package/dist/log-format.js +10 -0
- package/dist/machine-info.js +124 -0
- package/dist/main.js +118 -0
- package/dist/normalize.js +170 -0
- package/dist/origin-decision.js +44 -0
- package/dist/platform.js +8 -0
- package/dist/prompt.js +307 -0
- package/dist/provider-env.js +90 -0
- package/dist/runner.js +234 -0
- package/dist/runtime-cancellation.js +74 -0
- package/dist/runtime-capabilities.js +43 -0
- package/dist/runtime-path.js +60 -0
- package/dist/runtimes/claude.js +51 -0
- package/dist/runtimes/codex-app-server-runner.js +541 -0
- package/dist/runtimes/codex-deepseek-catalog.js +7 -0
- package/dist/runtimes/codex-deepseek-config.js +50 -0
- package/dist/runtimes/codex.js +53 -0
- package/dist/runtimes/kimi-acp-runner.js +364 -0
- package/dist/runtimes/kimi.js +45 -0
- package/dist/runtimes/progress-watchdog.js +26 -0
- package/dist/scheduled-report.js +51 -0
- package/dist/scheduled-run-report.js +57 -0
- package/dist/serve-lifecycle.js +82 -0
- package/dist/serve.js +868 -0
- package/dist/session.js +82 -0
- package/dist/shared-execution-slots.js +68 -0
- package/dist/shutdown-deadline.js +32 -0
- package/dist/skill-preview.js +21 -0
- package/dist/skills.js +56 -0
- package/dist/slog.js +228 -0
- package/dist/supervised-runtime.js +104 -0
- package/dist/token.js +24 -0
- package/dist/unified-diff.js +84 -0
- package/dist/websocket-shutdown.js +53 -0
- package/dist/win32-job-object.js +193 -0
- package/dist/workspace-fs.js +80 -0
- package/dist/workspace-import.js +127 -0
- package/dist/workspace.js +148 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export class RuntimeCancelledError extends Error {
|
|
2
|
+
constructor(message = "Runtime launch cancelled") {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "RuntimeCancelledError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export async function awaitWithCancellation(promise, cancellation) {
|
|
8
|
+
if (cancellation === undefined)
|
|
9
|
+
return promise;
|
|
10
|
+
if (cancellation.isRequested())
|
|
11
|
+
throw new RuntimeCancelledError();
|
|
12
|
+
const result = await Promise.race([
|
|
13
|
+
promise,
|
|
14
|
+
cancellation.requested.then(() => { throw new RuntimeCancelledError(); }),
|
|
15
|
+
]);
|
|
16
|
+
if (cancellation.isRequested())
|
|
17
|
+
throw new RuntimeCancelledError();
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
export function createRuntimeCancellation() {
|
|
21
|
+
let requested = false;
|
|
22
|
+
let resolveRequested;
|
|
23
|
+
const requestedPromise = new Promise((resolve) => { resolveRequested = resolve; });
|
|
24
|
+
const registrations = new Map();
|
|
25
|
+
const startRegisteredStops = () => {
|
|
26
|
+
if (!requested)
|
|
27
|
+
return;
|
|
28
|
+
for (const [cancel, stopPromise] of registrations) {
|
|
29
|
+
if (stopPromise !== null)
|
|
30
|
+
continue;
|
|
31
|
+
const started = Promise.resolve().then(cancel);
|
|
32
|
+
registrations.set(cancel, started);
|
|
33
|
+
void started.catch(() => undefined);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const waitForStop = async () => {
|
|
37
|
+
if (!requested)
|
|
38
|
+
return;
|
|
39
|
+
while (true) {
|
|
40
|
+
startRegisteredStops();
|
|
41
|
+
const registrationCount = registrations.size;
|
|
42
|
+
const results = await Promise.allSettled([...registrations.values()].filter((value) => value !== null));
|
|
43
|
+
if (registrations.size !== registrationCount)
|
|
44
|
+
continue;
|
|
45
|
+
const failures = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
46
|
+
if (failures.length === 1)
|
|
47
|
+
throw failures[0];
|
|
48
|
+
if (failures.length > 1)
|
|
49
|
+
throw new AggregateError(failures, "Runtime cancellation failed");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const cancellation = {
|
|
54
|
+
isRequested: () => requested,
|
|
55
|
+
requested: requestedPromise,
|
|
56
|
+
register: (next) => {
|
|
57
|
+
if (registrations.has(next))
|
|
58
|
+
return;
|
|
59
|
+
registrations.set(next, null);
|
|
60
|
+
startRegisteredStops();
|
|
61
|
+
},
|
|
62
|
+
waitForStop,
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
cancellation,
|
|
66
|
+
request: () => {
|
|
67
|
+
if (requested)
|
|
68
|
+
return;
|
|
69
|
+
requested = true;
|
|
70
|
+
resolveRequested();
|
|
71
|
+
startRegisteredStops();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const LOCAL_EXECUTION_RUNTIMES = ["claude", "codex", "kimi"];
|
|
2
|
+
export const LOCAL_RUNTIME_CAPABILITIES = Object.freeze({
|
|
3
|
+
claude: Object.freeze({
|
|
4
|
+
transport: "claude-stream-json",
|
|
5
|
+
nativeResume: true,
|
|
6
|
+
systemPromptTransport: "file",
|
|
7
|
+
}),
|
|
8
|
+
codex: Object.freeze({
|
|
9
|
+
transport: "codex-app-server",
|
|
10
|
+
nativeResume: true,
|
|
11
|
+
systemPromptTransport: "protocol",
|
|
12
|
+
}),
|
|
13
|
+
kimi: Object.freeze({
|
|
14
|
+
transport: "kimi-acp",
|
|
15
|
+
nativeResume: true,
|
|
16
|
+
systemPromptTransport: "protocol",
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
export function runtimeCapability(runtime) {
|
|
20
|
+
return LOCAL_RUNTIME_CAPABILITIES[runtime];
|
|
21
|
+
}
|
|
22
|
+
const LOCAL_EXECUTION_RUNTIME_SET = new Set(LOCAL_EXECUTION_RUNTIMES);
|
|
23
|
+
export function executableRuntimes(installed) {
|
|
24
|
+
return [...new Set(installed)].filter((runtime) => LOCAL_EXECUTION_RUNTIME_SET.has(runtime));
|
|
25
|
+
}
|
|
26
|
+
export function routeRuntimeAttachments(runtime, attachments) {
|
|
27
|
+
if (attachments.length === 0)
|
|
28
|
+
return { nativeImagePaths: [], promptSuffix: "" };
|
|
29
|
+
const lines = attachments.map((attachment) => `- ${JSON.stringify(attachment.path)} (${attachment.mime}, ${attachment.sizeBytes} bytes)`);
|
|
30
|
+
return {
|
|
31
|
+
nativeImagePaths: runtime === "codex"
|
|
32
|
+
? attachments.filter((attachment) => attachment.mime.startsWith("image/"))
|
|
33
|
+
.map((attachment) => attachment.path)
|
|
34
|
+
: [],
|
|
35
|
+
promptSuffix: [
|
|
36
|
+
"",
|
|
37
|
+
"",
|
|
38
|
+
"## Files attached to the triggering message",
|
|
39
|
+
"These files were downloaded into the local execution workspace. Open/read the relevant files before describing their contents; do not infer contents from filenames alone.",
|
|
40
|
+
...lines,
|
|
41
|
+
].join("\n"),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* daemon 被非登录/非交互进程(sh -c / pnpm script / tmux / 后台转发)拉起时,继承的 PATH 常退化为系统
|
|
3
|
+
* 默认,缺用户级 CLI 目录——尤其 Claude 官方原生安装器默认的 `~/.local/bin`。结果 `which claude` 探测
|
|
4
|
+
* 落空、真正 spawn 也 ENOENT。Kimi 官方安装器同样只把 `~/.kimi-code/bin` 写入 shell rc。
|
|
5
|
+
* 这里在探测与启动前把常见安装目录补进 PATH,保证「扫得到 = 起得来」。
|
|
6
|
+
*
|
|
7
|
+
* codex 装在 `/usr/local/bin`(系统默认 PATH 本就含之)所以不受影响;本模块对已在 PATH 中的目录是无操作。
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { win32, posix } from "node:path";
|
|
11
|
+
const pathApi = (platform) => (platform === "win32" ? win32 : posix);
|
|
12
|
+
/** 该平台常见 CLI 安装目录候选(是否真实存在稍后由 augmentedPath 校验)。 */
|
|
13
|
+
export function commonBinDirs(env = process.env, platform = process.platform) {
|
|
14
|
+
const p = pathApi(platform);
|
|
15
|
+
if (platform === "win32") {
|
|
16
|
+
const dirs = [];
|
|
17
|
+
if (env.USERPROFILE) {
|
|
18
|
+
dirs.push(p.join(env.USERPROFILE, ".kimi-code", "bin"), // Kimi 官方安装器默认落点
|
|
19
|
+
p.join(env.USERPROFILE, ".local", "bin"));
|
|
20
|
+
}
|
|
21
|
+
if (env.APPDATA)
|
|
22
|
+
dirs.push(p.join(env.APPDATA, "npm"));
|
|
23
|
+
if (env.LOCALAPPDATA)
|
|
24
|
+
dirs.push(p.join(env.LOCALAPPDATA, "Microsoft", "WindowsApps"));
|
|
25
|
+
return dirs;
|
|
26
|
+
}
|
|
27
|
+
const dirs = [];
|
|
28
|
+
const home = env.HOME;
|
|
29
|
+
if (home) {
|
|
30
|
+
dirs.push(p.join(home, ".kimi-code", "bin"), // Kimi 官方安装器默认落点
|
|
31
|
+
p.join(home, ".local", "bin"), // Claude 官方原生安装器默认落点
|
|
32
|
+
p.join(home, ".claude", "local"));
|
|
33
|
+
}
|
|
34
|
+
dirs.push("/opt/homebrew/bin", "/usr/local/bin"); // Apple Silicon brew / Intel brew & npm 全局
|
|
35
|
+
if (home) {
|
|
36
|
+
dirs.push(p.join(home, ".npm-global", "bin"), p.join(home, ".bun", "bin"), p.join(home, ".deno", "bin"));
|
|
37
|
+
}
|
|
38
|
+
return dirs;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 在 `env.PATH` 基础上,把候选目录里「真实存在且尚未在 PATH 中」的去重后 prepend,返回新的 PATH 字符串。
|
|
42
|
+
* 用户装的目录优先命中(prepend);全部已存在或都不在磁盘上时,原样返回 `env.PATH`。
|
|
43
|
+
*/
|
|
44
|
+
export function augmentedPath(env = process.env, deps = {}, platform = process.platform) {
|
|
45
|
+
const dirExists = deps.dirExists ?? existsSync;
|
|
46
|
+
const sep = pathApi(platform).delimiter;
|
|
47
|
+
const current = env.PATH ?? "";
|
|
48
|
+
const existing = new Set(current.split(sep).filter((entry) => entry.length > 0));
|
|
49
|
+
const extra = [];
|
|
50
|
+
for (const dir of commonBinDirs(env, platform)) {
|
|
51
|
+
if (existing.has(dir) || extra.includes(dir))
|
|
52
|
+
continue;
|
|
53
|
+
if (!dirExists(dir))
|
|
54
|
+
continue;
|
|
55
|
+
extra.push(dir);
|
|
56
|
+
}
|
|
57
|
+
if (extra.length === 0)
|
|
58
|
+
return current;
|
|
59
|
+
return current.length > 0 ? `${extra.join(sep)}${sep}${current}` : extra.join(sep);
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code runtime 适配:print + stream-json 模式,headless 驱动。
|
|
3
|
+
*/
|
|
4
|
+
// cross-spawn:win32 上 npm CLI 是 .cmd shim,node 原生 spawn 不带 shell 无法执行(ENOENT/EINVAL)
|
|
5
|
+
import spawn from "cross-spawn";
|
|
6
|
+
// Claude Code 原生 --effort 档位(claude 2.1.196 实测:--help 与非法值告警均枚举这五档)。
|
|
7
|
+
// 白名单外的值(含 "default" 与 codex 专属档)回落 CLAUDE_DEFAULT_EFFORT,脏数据不影响启动。
|
|
8
|
+
export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
9
|
+
// 未配置/非法档位时的默认思考强度:medium 开启原生 thinking(终端透传要展示思考过程),
|
|
10
|
+
// 又不至于 high/max 的 token 开销;agent 配置白名单档位可覆盖。
|
|
11
|
+
export const CLAUDE_DEFAULT_EFFORT = "medium";
|
|
12
|
+
export function buildClaudeArgs(input) {
|
|
13
|
+
const args = [
|
|
14
|
+
"--print",
|
|
15
|
+
"--verbose",
|
|
16
|
+
"--output-format",
|
|
17
|
+
"stream-json",
|
|
18
|
+
"--include-partial-messages",
|
|
19
|
+
"--append-system-prompt-file",
|
|
20
|
+
input.systemPromptPath,
|
|
21
|
+
];
|
|
22
|
+
if (input.model)
|
|
23
|
+
args.push("--model", input.model);
|
|
24
|
+
const effort = input.reasoning && CLAUDE_EFFORT_LEVELS.includes(input.reasoning)
|
|
25
|
+
? input.reasoning
|
|
26
|
+
: CLAUDE_DEFAULT_EFFORT;
|
|
27
|
+
args.push("--effort", effort);
|
|
28
|
+
if (input.sessionId) {
|
|
29
|
+
args.push(input.resume ? "--resume" : "--session-id", input.sessionId);
|
|
30
|
+
}
|
|
31
|
+
if (input.effectivePermission === undefined) {
|
|
32
|
+
if (input.dangerous)
|
|
33
|
+
args.push("--dangerously-skip-permissions");
|
|
34
|
+
}
|
|
35
|
+
else if (input.effectivePermission === "full_access") {
|
|
36
|
+
args.push("--dangerously-skip-permissions");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
args.push("--permission-mode", input.effectivePermission === "sandboxed" ? "plan" : "acceptEdits");
|
|
40
|
+
}
|
|
41
|
+
args.push(input.wakePrompt);
|
|
42
|
+
return args;
|
|
43
|
+
}
|
|
44
|
+
export function spawnClaude(input) {
|
|
45
|
+
// stdio 固定 ignore/pipe/pipe,stdout/stderr 必为 Readable;cross-spawn 类型不带该细化,断言之
|
|
46
|
+
return spawn(input.bin, buildClaudeArgs(input), {
|
|
47
|
+
cwd: input.cwd,
|
|
48
|
+
env: input.env,
|
|
49
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
50
|
+
});
|
|
51
|
+
}
|