@nowcrew/daemon 0.6.88-beta.2 → 0.6.88-beta.20
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 +38 -10
- package/dist/agent-memory/policy.js +3 -1
- package/dist/daemon-update-eligibility.js +1 -1
- package/dist/execution-journal.js +9 -6
- package/dist/execution-protocol.js +2 -1
- package/dist/execution-runner.js +5 -3
- package/dist/list-models.js +2 -0
- package/dist/local-execution-lease.js +22 -0
- package/dist/local-executor.js +57 -37
- package/dist/local-memory/candidate.js +43 -0
- package/dist/local-memory/index-budget.js +8 -0
- package/dist/local-memory/inventory-cli.js +61 -0
- package/dist/local-memory/inventory-preview.js +154 -0
- package/dist/local-memory/inventory-source.js +159 -0
- package/dist/local-memory/pending-match.js +29 -0
- package/dist/local-memory/pending-query.js +100 -0
- package/dist/local-memory/pending-schema.js +29 -0
- package/dist/local-memory/pending-source.js +126 -0
- package/dist/local-memory/pending.js +34 -84
- package/dist/local-memory/prompt.js +14 -11
- package/dist/local-memory/read-cli.js +59 -8
- package/dist/local-memory/runtime.js +24 -17
- package/dist/local-memory/work-log-execution.js +31 -0
- package/dist/local-memory/work-log.js +58 -0
- package/dist/local-memory/write.js +27 -58
- package/dist/machine-info.js +54 -16
- package/dist/main.js +4 -69
- package/dist/native-thread-context.js +59 -0
- package/dist/pre-admission-rejection.js +64 -0
- package/dist/project-skills/execution-adapter.js +3 -2
- package/dist/project-skills/runtime-launch.js +14 -0
- package/dist/prompt.js +15 -15
- package/dist/provider-env.js +3 -4
- package/dist/runner.js +14 -15
- package/dist/runtime-probe.js +34 -5
- package/dist/runtimes/acp-probe-transport.js +69 -0
- package/dist/runtimes/claude-session-start-hook.js +24 -0
- package/dist/runtimes/claude-thread-runner.js +266 -0
- package/dist/runtimes/claude.js +23 -4
- package/dist/runtimes/codex-app-server-runner.js +43 -4
- package/dist/runtimes/deepseek-harness-profile.js +92 -0
- package/dist/runtimes/deepseek-harness-runner.js +224 -0
- package/dist/runtimes/deepseek-harness.js +64 -11
- package/dist/runtimes/harness-probe-retry.js +42 -0
- package/dist/runtimes/kimi-acp-runner.js +63 -10
- package/dist/runtimes/opencode-runner.js +7 -1
- package/dist/serve.js +58 -88
- package/dist/session.js +4 -0
- package/dist/storage-identity.js +0 -3
- package/dist/storage-serve-adapter.js +6 -72
- package/dist/supervised-runtime.js +28 -18
- package/dist/thread-input-delivery.js +217 -0
- package/package.json +2 -2
- package/dist/daemon-migration-controller.js +0 -211
- package/dist/daemon-migration-wiring.js +0 -22
- package/dist/storage-control.js +0 -212
- package/dist/storage-copy.js +0 -628
- package/dist/storage-credential-guard.js +0 -21
- package/dist/storage-doctor.js +0 -228
- package/dist/storage-manifest.js +0 -1027
- package/dist/storage-migration-controller.js +0 -440
- package/dist/storage-migration-manifest.js +0 -105
- package/dist/storage-migration-policy.js +0 -100
- package/dist/storage-runtime-controller.js +0 -381
- package/dist/storage-runtime-readiness.js +0 -240
- package/dist/storage-safe-fs.js +0 -302
- package/dist/storage-status-delivery.js +0 -224
- package/dist/storage-status-replay.js +0 -140
- package/dist/storage-target-confirmation.js +0 -129
- package/dist/storage-worker-command.js +0 -37
- package/dist/storage-worker-executor.js +0 -449
- package/dist/storage-worker-handoff.js +0 -151
- package/dist/storage-worker-operation.js +0 -294
- package/dist/storage-worker-status.js +0 -259
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** 短命执行配置:不读取全局 Harness home,不新增 daemon 状态。 */
|
|
2
|
+
import { mkdtemp, mkdir, writeFile, access } from "node:fs/promises";
|
|
3
|
+
import { join, isAbsolute } from "node:path";
|
|
4
|
+
import { stringify } from "yaml";
|
|
5
|
+
export const harnessPermissionMode = (permission) => permission === "sandboxed"
|
|
6
|
+
? "read-only"
|
|
7
|
+
: permission === "workspace_write"
|
|
8
|
+
? "workspace-write"
|
|
9
|
+
: "danger-full-access";
|
|
10
|
+
// A variable's returned value is interpolated once: literal {{...}} in NowWork
|
|
11
|
+
// instructions must not become unknown Harness template variables.
|
|
12
|
+
const instructionsPlugin = `export const name = 'nowwork-instructions';
|
|
13
|
+
export const inject = ['systemPrompt'];
|
|
14
|
+
export function apply(ctx, config) {
|
|
15
|
+
ctx.systemPrompt.variable('nowwork_instructions', () => config.text);
|
|
16
|
+
ctx.systemPrompt.section({name: 'nowwork-instructions', order: 100000, text: '{{nowwork_instructions}}'});
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
export async function prepareHarnessProfile(input) {
|
|
20
|
+
if (![input.stateRoot, input.cwd, ...input.skillRoots].every(isAbsolute)) {
|
|
21
|
+
throw new Error("DeepSeek Harness execution paths must be absolute");
|
|
22
|
+
}
|
|
23
|
+
if (input.patchPath !== undefined) {
|
|
24
|
+
if (!isAbsolute(input.patchPath))
|
|
25
|
+
throw new Error("DeepSeek Harness patch must be absolute");
|
|
26
|
+
await access(input.patchPath);
|
|
27
|
+
}
|
|
28
|
+
await mkdir(input.stateRoot, { recursive: true, mode: 0o700 });
|
|
29
|
+
const home = await mkdtemp(join(input.stateRoot, ".deepseek-harness-"));
|
|
30
|
+
const pluginPath = join(home, "nowwork-instructions.mjs");
|
|
31
|
+
const policyPath = join(home, "nowwork-policy.yml");
|
|
32
|
+
const mode = harnessPermissionMode(input.effectivePermission);
|
|
33
|
+
await writeFile(pluginPath, instructionsPlugin, { mode: 0o600 });
|
|
34
|
+
await writeFile(policyPath, stringify([
|
|
35
|
+
{
|
|
36
|
+
id: "sandbox-policy",
|
|
37
|
+
disabled: false,
|
|
38
|
+
config: { mode, workspaceRoot: input.cwd },
|
|
39
|
+
},
|
|
40
|
+
{ id: "approval", disabled: false, config: { policy: "never" } },
|
|
41
|
+
{
|
|
42
|
+
id: "permission",
|
|
43
|
+
disabled: false,
|
|
44
|
+
config: {
|
|
45
|
+
defaultPreset: "nowwork",
|
|
46
|
+
presets: { nowwork: { sandbox: mode, approval: "never" } },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "skill-filesystem",
|
|
51
|
+
disabled: false,
|
|
52
|
+
config: {
|
|
53
|
+
includeDefaultRoots: false,
|
|
54
|
+
customSkillDirs: [...input.skillRoots],
|
|
55
|
+
watch: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "session-persistence-jsonl",
|
|
60
|
+
disabled: false,
|
|
61
|
+
config: { root: join(home, "sessions") },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
insert: [
|
|
65
|
+
{
|
|
66
|
+
id: "nowwork-instructions",
|
|
67
|
+
name: pluginPath,
|
|
68
|
+
config: { text: input.systemPrompt },
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
]), { mode: 0o600 });
|
|
73
|
+
const env = Object.fromEntries(Object.entries(input.env).filter(([key]) => !key.toUpperCase().startsWith("DSH_")));
|
|
74
|
+
return {
|
|
75
|
+
home,
|
|
76
|
+
policyPath,
|
|
77
|
+
args: [
|
|
78
|
+
"--profile",
|
|
79
|
+
"acp",
|
|
80
|
+
...(input.patchPath ? ["--patch", input.patchPath] : []),
|
|
81
|
+
"--patch",
|
|
82
|
+
policyPath,
|
|
83
|
+
],
|
|
84
|
+
env: {
|
|
85
|
+
...env,
|
|
86
|
+
DSH_HOME: home,
|
|
87
|
+
DSH_AGENTS_HOME: join(home, "agents-home"),
|
|
88
|
+
DSH_PERMISSION_MODE: mode,
|
|
89
|
+
DSH_TELEMETRY_DISABLED: "1",
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/** 新版 Harness 的短命 ACP 桥:产品状态与重试仍属于 server。 */
|
|
2
|
+
import { once } from "node:events";
|
|
3
|
+
import { Readable, Writable } from "node:stream";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { isAbsolute } from "node:path";
|
|
7
|
+
import spawn from "cross-spawn";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { client, methods, ndJsonStream, PROTOCOL_VERSION, } from "@agentclientprotocol/sdk";
|
|
10
|
+
import { prepareHarnessProfile } from "./deepseek-harness-profile.js";
|
|
11
|
+
import { mapAcpUpdate } from "./kimi-acp-runner.js";
|
|
12
|
+
import { prepareThreadDelivery } from "../thread-input-delivery.js";
|
|
13
|
+
const absolutePath = z.string().refine(isAbsolute, "must be an absolute path");
|
|
14
|
+
export const HarnessInputSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
systemPrompt: z.string(),
|
|
17
|
+
wakePrompt: z.string().min(1),
|
|
18
|
+
stateRoot: absolutePath,
|
|
19
|
+
skillRoots: z.array(absolutePath).default([]),
|
|
20
|
+
effectivePermission: z.enum([
|
|
21
|
+
"sandboxed",
|
|
22
|
+
"workspace_write",
|
|
23
|
+
"full_access",
|
|
24
|
+
]),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
const emit = async (event) => {
|
|
28
|
+
if (!process.stdout.write(`${JSON.stringify(event)}\n`))
|
|
29
|
+
await once(process.stdout, "drain");
|
|
30
|
+
};
|
|
31
|
+
async function settleWithin(promise, ms) {
|
|
32
|
+
let timer;
|
|
33
|
+
try {
|
|
34
|
+
return await Promise.race([
|
|
35
|
+
promise,
|
|
36
|
+
new Promise((resolve) => {
|
|
37
|
+
timer = setTimeout(() => resolve(undefined), ms);
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
if (timer)
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export async function runHarness(input, bin, patchPath) {
|
|
47
|
+
const delivery = await prepareThreadDelivery({
|
|
48
|
+
env: process.env,
|
|
49
|
+
resumed: false,
|
|
50
|
+
sessionId: "cold-harness",
|
|
51
|
+
wakePrompt: input.wakePrompt,
|
|
52
|
+
});
|
|
53
|
+
const profile = await prepareHarnessProfile({
|
|
54
|
+
...input,
|
|
55
|
+
cwd: process.cwd(),
|
|
56
|
+
env: process.env,
|
|
57
|
+
...(patchPath ? { patchPath } : {}),
|
|
58
|
+
});
|
|
59
|
+
const child = spawn(bin, profile.args, {
|
|
60
|
+
cwd: profile.home,
|
|
61
|
+
env: profile.env,
|
|
62
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
63
|
+
});
|
|
64
|
+
// Boot away from the repository: the CLI must not load a project's .env into
|
|
65
|
+
// trusted process credentials. ACP session/new carries the real workspace.
|
|
66
|
+
let spawnError;
|
|
67
|
+
const closed = new Promise((resolve) => {
|
|
68
|
+
child.once("error", (error) => {
|
|
69
|
+
spawnError = error;
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
child.once("close", () => resolve());
|
|
73
|
+
});
|
|
74
|
+
if (!child.stdin || !child.stdout || !child.stderr)
|
|
75
|
+
throw new Error("DeepSeek Harness stdio unavailable");
|
|
76
|
+
// Provider diagnostics may include secrets or prompts; do not stream raw stderr.
|
|
77
|
+
child.stderr.resume();
|
|
78
|
+
let context;
|
|
79
|
+
let sessionId;
|
|
80
|
+
let cancelled = false;
|
|
81
|
+
let stage = "initialize";
|
|
82
|
+
let exitCode = 1;
|
|
83
|
+
let stopping;
|
|
84
|
+
const stop = () => (stopping ??= (async () => {
|
|
85
|
+
child.stdin?.end();
|
|
86
|
+
if (await settleWithin(closed.then(() => true), 2000))
|
|
87
|
+
return;
|
|
88
|
+
child.kill("SIGTERM");
|
|
89
|
+
if (await settleWithin(closed.then(() => true), 1000))
|
|
90
|
+
return;
|
|
91
|
+
child.kill("SIGKILL");
|
|
92
|
+
if (!(await settleWithin(closed.then(() => true), 2000)))
|
|
93
|
+
throw new Error("DeepSeek Harness process stop unconfirmed");
|
|
94
|
+
})());
|
|
95
|
+
const cancel = () => {
|
|
96
|
+
cancelled = true;
|
|
97
|
+
void (async () => {
|
|
98
|
+
if (context && sessionId)
|
|
99
|
+
await settleWithin(context
|
|
100
|
+
.notify(methods.agent.session.cancel, { sessionId })
|
|
101
|
+
.catch(() => undefined), 1000);
|
|
102
|
+
await stop();
|
|
103
|
+
})().catch(() => {
|
|
104
|
+
/* finally reports stop failure; supervisor owns process tree */
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
process.once("SIGTERM", cancel);
|
|
108
|
+
process.once("SIGINT", cancel);
|
|
109
|
+
const app = client({ name: "nowwork-harness" })
|
|
110
|
+
.onRequest(methods.client.session.requestPermission, () => ({
|
|
111
|
+
outcome: { outcome: "cancelled" },
|
|
112
|
+
}))
|
|
113
|
+
.onNotification(methods.client.session.update, async ({ params }) => {
|
|
114
|
+
if (params.sessionId !== sessionId)
|
|
115
|
+
return;
|
|
116
|
+
for (const event of mapAcpUpdate("deepseek-harness", params.update))
|
|
117
|
+
await emit(event);
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
const stream = ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
|
|
121
|
+
const result = await app.connectWith(stream, async (ctx) => {
|
|
122
|
+
context = ctx;
|
|
123
|
+
const initialized = await ctx.request(methods.agent.initialize, {
|
|
124
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
125
|
+
clientCapabilities: {},
|
|
126
|
+
clientInfo: { name: "nowwork", version: "1" },
|
|
127
|
+
});
|
|
128
|
+
if (initialized.protocolVersion !== PROTOCOL_VERSION)
|
|
129
|
+
throw new Error("Incompatible ACP protocol");
|
|
130
|
+
if (cancelled)
|
|
131
|
+
throw new Error("cancelled");
|
|
132
|
+
stage = "session_new";
|
|
133
|
+
const session = await ctx.request(methods.agent.session.new, {
|
|
134
|
+
cwd: process.cwd(),
|
|
135
|
+
mcpServers: [],
|
|
136
|
+
});
|
|
137
|
+
sessionId = session.sessionId;
|
|
138
|
+
if (!sessionId || cancelled)
|
|
139
|
+
throw new Error("Harness session unavailable");
|
|
140
|
+
await emit({ type: "thread.started", thread_id: sessionId });
|
|
141
|
+
stage = "prompt";
|
|
142
|
+
const response = await ctx.request(methods.agent.session.prompt, {
|
|
143
|
+
sessionId,
|
|
144
|
+
prompt: [{ type: "text", text: delivery.prompt }],
|
|
145
|
+
});
|
|
146
|
+
if (initialized.agentCapabilities?.sessionCapabilities?.close != null) {
|
|
147
|
+
stage = "session_close";
|
|
148
|
+
const close = await settleWithin(ctx
|
|
149
|
+
.request(methods.agent.session.close, { sessionId })
|
|
150
|
+
.then(() => true), 5000);
|
|
151
|
+
if (!close)
|
|
152
|
+
throw new Error("Harness session close timed out");
|
|
153
|
+
}
|
|
154
|
+
return response;
|
|
155
|
+
});
|
|
156
|
+
const usage = result.usage;
|
|
157
|
+
if (!cancelled)
|
|
158
|
+
await emit({
|
|
159
|
+
type: "turn.completed",
|
|
160
|
+
stop_reason: result.stopReason,
|
|
161
|
+
...(usage
|
|
162
|
+
? {
|
|
163
|
+
usage: {
|
|
164
|
+
input_tokens: usage.inputTokens,
|
|
165
|
+
output_tokens: usage.outputTokens,
|
|
166
|
+
cache_read_input_tokens: usage.cachedReadTokens ?? 0,
|
|
167
|
+
cache_creation_input_tokens: usage.cachedWriteTokens ?? 0,
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
: {}),
|
|
171
|
+
});
|
|
172
|
+
exitCode =
|
|
173
|
+
result.stopReason === "end_turn"
|
|
174
|
+
? 0
|
|
175
|
+
: result.stopReason === "cancelled"
|
|
176
|
+
? 130
|
|
177
|
+
: 1;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
if (!cancelled)
|
|
181
|
+
process.stderr.write(spawnError
|
|
182
|
+
? "DeepSeek Harness launch failed; verify the installed dsh executable.\n"
|
|
183
|
+
: `DeepSeek Harness ACP execution failed at ${stage}; verify the pinned version, machine credentials and profile patch.\n`);
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
try {
|
|
187
|
+
await stop();
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
process.off("SIGTERM", cancel);
|
|
191
|
+
process.off("SIGINT", cancel);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (cancelled)
|
|
195
|
+
return 130;
|
|
196
|
+
return child.exitCode !== 0 ? 1 : exitCode;
|
|
197
|
+
}
|
|
198
|
+
async function main() {
|
|
199
|
+
const { values } = parseArgs({
|
|
200
|
+
options: { bin: { type: "string" }, patch: { type: "string" } },
|
|
201
|
+
});
|
|
202
|
+
if (!values.bin)
|
|
203
|
+
throw new Error("DeepSeek Harness --bin is required");
|
|
204
|
+
process.stdin.setEncoding("utf8");
|
|
205
|
+
let text = "";
|
|
206
|
+
for await (const chunk of process.stdin) {
|
|
207
|
+
text += String(chunk);
|
|
208
|
+
if (Buffer.byteLength(text) > 16 * 1024 * 1024)
|
|
209
|
+
throw new Error("Harness input exceeds 16 MiB");
|
|
210
|
+
}
|
|
211
|
+
const input = HarnessInputSchema.parse(JSON.parse(text));
|
|
212
|
+
return runHarness(input, values.bin, values.patch);
|
|
213
|
+
}
|
|
214
|
+
if (process.argv[1] &&
|
|
215
|
+
import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
216
|
+
main()
|
|
217
|
+
.then((code) => {
|
|
218
|
+
process.exitCode = code;
|
|
219
|
+
})
|
|
220
|
+
.catch(() => {
|
|
221
|
+
process.stderr.write("DeepSeek Harness configuration or cleanup failed; check execution paths and machine patch.\n");
|
|
222
|
+
process.exitCode = 1;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
@@ -1,20 +1,73 @@
|
|
|
1
1
|
import spawn from "cross-spawn";
|
|
2
2
|
import { isAbsolute } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { prepareHarnessProfile } from "./deepseek-harness-profile.js";
|
|
7
|
+
import { probeKimiAcp, AcpProbeCleanupError } from "./kimi-acp-runner.js";
|
|
4
8
|
export const DEEPSEEK_HARNESS_CONFIG_ENV = "NOWCREW_DEEPSEEK_HARNESS_CONFIG";
|
|
9
|
+
export const DEEPSEEK_HARNESS_PATCH_ENV = "NOWCREW_DEEPSEEK_HARNESS_PATCH";
|
|
10
|
+
export function deepSeekHarnessLauncher(env = process.env) {
|
|
11
|
+
const configPath = env[DEEPSEEK_HARNESS_CONFIG_ENV]?.trim();
|
|
12
|
+
const patchPath = env[DEEPSEEK_HARNESS_PATCH_ENV]?.trim();
|
|
13
|
+
if (configPath && !isAbsolute(configPath))
|
|
14
|
+
throw new Error(`${DEEPSEEK_HARNESS_CONFIG_ENV} must be an absolute path`);
|
|
15
|
+
if (patchPath && !isAbsolute(patchPath))
|
|
16
|
+
throw new Error(`${DEEPSEEK_HARNESS_PATCH_ENV} must be an absolute path`);
|
|
17
|
+
if (configPath && patchPath)
|
|
18
|
+
throw new Error("DeepSeek Harness legacy config and profile patch are mutually exclusive");
|
|
19
|
+
return configPath
|
|
20
|
+
? { kind: "legacy", bin: "dsh-acp-demo", configPath }
|
|
21
|
+
: { kind: "profile", bin: "dsh", ...(patchPath ? { patchPath } : {}) };
|
|
22
|
+
}
|
|
5
23
|
export function deepSeekHarnessConfigPath(env = process.env) {
|
|
6
24
|
const path = env[DEEPSEEK_HARNESS_CONFIG_ENV]?.trim();
|
|
7
25
|
return path && isAbsolute(path) ? path : null;
|
|
8
26
|
}
|
|
9
27
|
/** The published DeepSeek Harness ACP executable speaks JSON-RPC directly on stdio. */
|
|
10
|
-
export function probeDeepSeekHarnessAcp(options, spawnProcess = spawn) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
export async function probeDeepSeekHarnessAcp(options, spawnProcess = spawn) {
|
|
29
|
+
if (options.signal?.aborted)
|
|
30
|
+
return false;
|
|
31
|
+
let root;
|
|
32
|
+
try {
|
|
33
|
+
const launcher = options.configPath === undefined
|
|
34
|
+
? deepSeekHarnessLauncher()
|
|
35
|
+
: deepSeekHarnessLauncher({
|
|
36
|
+
[DEEPSEEK_HARNESS_CONFIG_ENV]: options.configPath,
|
|
37
|
+
});
|
|
38
|
+
if (launcher.kind === "legacy")
|
|
39
|
+
return await probeKimiAcp({
|
|
40
|
+
...options,
|
|
41
|
+
provider: "deepseek-harness",
|
|
42
|
+
configPath: launcher.configPath,
|
|
43
|
+
effectivePermission: "sandboxed",
|
|
44
|
+
}, spawnProcess);
|
|
45
|
+
root = await mkdtemp(join(tmpdir(), "nowwork-dsh-probe-"));
|
|
46
|
+
const profile = await prepareHarnessProfile({
|
|
47
|
+
stateRoot: root,
|
|
48
|
+
cwd: root,
|
|
49
|
+
systemPrompt: "",
|
|
50
|
+
skillRoots: [],
|
|
51
|
+
effectivePermission: "sandboxed",
|
|
52
|
+
env: process.env,
|
|
53
|
+
...(launcher.patchPath ? { patchPath: launcher.patchPath } : {}),
|
|
54
|
+
});
|
|
55
|
+
return await probeKimiAcp({
|
|
56
|
+
...options,
|
|
57
|
+
provider: "deepseek-harness",
|
|
58
|
+
effectivePermission: "sandboxed",
|
|
59
|
+
launchArgs: profile.args,
|
|
60
|
+
launchEnv: profile.env,
|
|
61
|
+
launchCwd: root,
|
|
62
|
+
}, spawnProcess);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof AcpProbeCleanupError)
|
|
66
|
+
throw error;
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (root)
|
|
71
|
+
await rm(root, { recursive: true, force: true }).catch(() => undefined);
|
|
72
|
+
}
|
|
20
73
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { dslog } from "../slog.js";
|
|
2
|
+
const RETRY_DELAYS_MS = [1_000, 2_000];
|
|
3
|
+
/** 只延迟当前启动探测,不设后台定时任务;stop 立即清除等待。 */
|
|
4
|
+
function waitForRetry(ms, signal) {
|
|
5
|
+
if (signal?.aborted)
|
|
6
|
+
return Promise.resolve(false);
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const finish = (ready) => {
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
signal?.removeEventListener("abort", onAbort);
|
|
11
|
+
resolve(ready);
|
|
12
|
+
};
|
|
13
|
+
const onAbort = () => finish(false);
|
|
14
|
+
const timer = setTimeout(() => finish(true), ms);
|
|
15
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** 成功才公布能力;每次 probe 返回前已完成进程清理,异常保持原有传播。 */
|
|
19
|
+
export async function retryHarnessProbe(probe, signal, probeId) {
|
|
20
|
+
for (let attempt = 1; attempt <= RETRY_DELAYS_MS.length + 1; attempt++) {
|
|
21
|
+
if (signal?.aborted)
|
|
22
|
+
return false;
|
|
23
|
+
const ready = await probe();
|
|
24
|
+
dslog("runtime_probe.harness_attempt", "Harness 启动探测尝试结束", {
|
|
25
|
+
probe_id: probeId, runtime: "deepseek-harness", attempt, ready,
|
|
26
|
+
aborted: signal?.aborted ?? false,
|
|
27
|
+
});
|
|
28
|
+
if (signal?.aborted)
|
|
29
|
+
return false;
|
|
30
|
+
if (ready)
|
|
31
|
+
return true;
|
|
32
|
+
const delayMs = RETRY_DELAYS_MS[attempt - 1];
|
|
33
|
+
if (delayMs === undefined)
|
|
34
|
+
return false;
|
|
35
|
+
dslog("runtime_probe.harness_retry", "延迟重试 Harness 启动探测", {
|
|
36
|
+
probe_id: probeId, runtime: "deepseek-harness", next_attempt: attempt + 1, delay_ms: delayMs,
|
|
37
|
+
});
|
|
38
|
+
if (!await waitForRetry(delayMs, signal))
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { AcpProbeTransport } from "./acp-probe-transport.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { dslog } from "../slog.js";
|
|
1
4
|
import { once } from "node:events";
|
|
2
5
|
import { isAbsolute } from "node:path";
|
|
3
6
|
import { parseArgs } from "node:util";
|
|
@@ -6,6 +9,7 @@ import { pathToFileURL } from "node:url";
|
|
|
6
9
|
import spawn from "cross-spawn";
|
|
7
10
|
import { PROTOCOL_VERSION, RequestError, client, methods, ndJsonStream, } from "@agentclientprotocol/sdk";
|
|
8
11
|
import { augmentedPath } from "../runtime-path.js";
|
|
12
|
+
import { prepareThreadDelivery } from "../thread-input-delivery.js";
|
|
9
13
|
import { startFirstProgressWatchdog } from "./progress-watchdog.js";
|
|
10
14
|
import { assertKimiLegacyPromptFits, buildKimiArgs } from "./kimi.js";
|
|
11
15
|
const ERROR_MESSAGE_CAP = 2_000;
|
|
@@ -193,18 +197,38 @@ async function stopChild(child) {
|
|
|
193
197
|
await closed;
|
|
194
198
|
}
|
|
195
199
|
}
|
|
200
|
+
export class AcpProbeCleanupError extends Error {
|
|
201
|
+
constructor() { super("ACP probe process cleanup unconfirmed"); this.name = "AcpProbeCleanupError"; }
|
|
202
|
+
}
|
|
196
203
|
/** Probe the ACP transport without starting a session or forcing an optional interactive login flow. */
|
|
197
204
|
export async function probeKimiAcp(options, spawnProcess = spawn) {
|
|
198
205
|
const provider = options.provider ?? "kimi";
|
|
199
206
|
const permission = options.effectivePermission ?? "sandboxed";
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
const probeId = options.probeId ?? randomUUID();
|
|
208
|
+
const started = performance.now();
|
|
209
|
+
const elapsed = () => Math.round(performance.now() - started);
|
|
210
|
+
const transport = new AcpProbeTransport(elapsed);
|
|
211
|
+
let spawnConfirmedMs;
|
|
212
|
+
let reason = "initializing", protocolVersion;
|
|
213
|
+
let stderrSeen = false;
|
|
214
|
+
const fields = () => ({ probe_id: probeId, runtime: provider, duration_ms: elapsed(),
|
|
215
|
+
...transport.fields(), spawn_confirmed_ms: spawnConfirmedMs, child_pid: child.pid,
|
|
216
|
+
reason, protocol_version: protocolVersion, stderr_seen: stderrSeen, aborted: options.signal?.aborted ?? false });
|
|
217
|
+
dslog("execution.acp_probe_started", "ACP 探测开始", { probe_id: probeId, runtime: provider, node_version: process.version });
|
|
218
|
+
const launchEnv = options.launchEnv ?? providerEnv(provider, permission);
|
|
219
|
+
const child = spawnProcess(options.bin, options.launchArgs ?? providerArgs(provider, options.configPath), {
|
|
220
|
+
cwd: options.launchCwd ?? process.cwd(),
|
|
221
|
+
// 显式 launchEnv 也决定 PATH/HOME;不能把它与父进程 PATH 混用。
|
|
222
|
+
env: { ...launchEnv, PATH: augmentedPath(launchEnv) },
|
|
204
223
|
stdio: ["pipe", "pipe", "pipe"],
|
|
205
224
|
});
|
|
225
|
+
child.once("spawn", () => {
|
|
226
|
+
spawnConfirmedMs = elapsed();
|
|
227
|
+
dslog("execution.acp_probe_spawned", "ACP 探测子进程已启动", fields());
|
|
228
|
+
});
|
|
206
229
|
if (child.stdin === null || child.stdout === null || child.stderr === null)
|
|
207
230
|
return false;
|
|
231
|
+
child.stderr.on("data", () => { stderrSeen = true; });
|
|
208
232
|
child.stderr.resume();
|
|
209
233
|
const app = client({ name: `nowcrew-daemon-${provider}-probe` })
|
|
210
234
|
.onRequest(methods.client.session.requestPermission, () => ({
|
|
@@ -214,25 +238,36 @@ export async function probeKimiAcp(options, spawnProcess = spawn) {
|
|
|
214
238
|
let timeout;
|
|
215
239
|
let onAbort;
|
|
216
240
|
try {
|
|
217
|
-
const stream = ndJsonStream(
|
|
241
|
+
const stream = ndJsonStream(transport.writable(child.stdin), transport.readable(child.stdout));
|
|
218
242
|
const connected = app.connectWith(stream, async (context) => {
|
|
219
|
-
|
|
243
|
+
transport.initializeRequested();
|
|
244
|
+
const initialized = await context.request(methods.agent.initialize, {
|
|
220
245
|
protocolVersion: PROTOCOL_VERSION,
|
|
221
246
|
clientCapabilities: {},
|
|
222
247
|
clientInfo: { name: "nowcrew-daemon", version: "1" },
|
|
223
248
|
});
|
|
224
|
-
|
|
249
|
+
transport.initializeResponse();
|
|
250
|
+
protocolVersion = initialized.protocolVersion;
|
|
251
|
+
const ready = protocolVersion === PROTOCOL_VERSION;
|
|
252
|
+
if (reason === "initializing")
|
|
253
|
+
reason = ready ? "ready" : "protocol_mismatch";
|
|
254
|
+
dslog("execution.acp_probe_handshake", "ACP 握手结果", { ...fields(), ready });
|
|
255
|
+
return ready;
|
|
225
256
|
});
|
|
226
257
|
const result = await Promise.race([
|
|
227
258
|
connected,
|
|
228
259
|
new Promise((resolve) => {
|
|
229
260
|
timeout = setTimeout(() => {
|
|
261
|
+
if (reason === "initializing")
|
|
262
|
+
reason = "timeout";
|
|
230
263
|
void stopChild(child);
|
|
231
264
|
resolve(false);
|
|
232
265
|
}, PROBE_TIMEOUT_MS);
|
|
233
266
|
}),
|
|
234
267
|
new Promise((resolve) => {
|
|
235
268
|
onAbort = () => {
|
|
269
|
+
if (reason === "initializing")
|
|
270
|
+
reason = "aborted";
|
|
236
271
|
void stopChild(child);
|
|
237
272
|
resolve(false);
|
|
238
273
|
};
|
|
@@ -245,6 +280,8 @@ export async function probeKimiAcp(options, spawnProcess = spawn) {
|
|
|
245
280
|
return result;
|
|
246
281
|
}
|
|
247
282
|
catch {
|
|
283
|
+
if (reason === "initializing")
|
|
284
|
+
reason = options.signal?.aborted ? "aborted" : "transport_error";
|
|
248
285
|
return false;
|
|
249
286
|
}
|
|
250
287
|
finally {
|
|
@@ -252,17 +289,33 @@ export async function probeKimiAcp(options, spawnProcess = spawn) {
|
|
|
252
289
|
clearTimeout(timeout);
|
|
253
290
|
if (onAbort !== undefined)
|
|
254
291
|
options.signal?.removeEventListener("abort", onAbort);
|
|
255
|
-
|
|
292
|
+
dslog("execution.acp_probe_cleanup_started", "ACP 探测清理开始", fields());
|
|
293
|
+
let cleanupFinished = false;
|
|
294
|
+
try {
|
|
295
|
+
await stopChild(child);
|
|
296
|
+
cleanupFinished = true;
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
throw new AcpProbeCleanupError();
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
dslog("execution.acp_probe_finished", "ACP 探测结束", { ...fields(),
|
|
303
|
+
cleanup_finished: cleanupFinished, exit_code: child.exitCode, exit_signal: child.signalCode,
|
|
304
|
+
level: reason === "ready" && cleanupFinished ? "INFO" : "WARN" });
|
|
305
|
+
}
|
|
256
306
|
}
|
|
257
307
|
}
|
|
258
|
-
export async function runKimiAcp(
|
|
308
|
+
export async function runKimiAcp(requestedOptions) {
|
|
309
|
+
// Until this adapter verifies native restoration, thread-bound runs are cold.
|
|
310
|
+
const options = process.env.CREW_THREAD_ROOT ? { ...requestedOptions, resume: false } : requestedOptions;
|
|
259
311
|
const provider = options.provider ?? "kimi";
|
|
260
312
|
const displayName = providerDisplayName(provider);
|
|
261
313
|
const permission = options.effectivePermission ?? "full_access";
|
|
262
314
|
if (provider === "deepseek-harness" && options.resume) {
|
|
263
315
|
throw new Error("DeepSeek Harness ACP does not support session resume");
|
|
264
316
|
}
|
|
265
|
-
const prompt = await
|
|
317
|
+
const prompt = (await prepareThreadDelivery({ env: process.env, resumed: false,
|
|
318
|
+
sessionId: "unverified-cold-acp", wakePrompt: await readPrompt() })).prompt;
|
|
266
319
|
const child = spawn(options.bin, providerArgs(provider, options.configPath), {
|
|
267
320
|
cwd: process.cwd(),
|
|
268
321
|
env: providerEnv(provider, permission),
|
|
@@ -4,6 +4,7 @@ import { parseArgs } from "node:util";
|
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import spawn from "cross-spawn";
|
|
6
6
|
import { augmentedPath } from "../runtime-path.js";
|
|
7
|
+
import { prepareThreadDelivery } from "../thread-input-delivery.js";
|
|
7
8
|
import { buildOpenCodeArgs, createOpenCodeEventDecoder } from "./opencode.js";
|
|
8
9
|
const ERROR_CAP = 2_000;
|
|
9
10
|
async function readPrompt() {
|
|
@@ -86,7 +87,12 @@ async function runAttempt(options, prompt) {
|
|
|
86
87
|
return { code: 0, staleSession: false };
|
|
87
88
|
}
|
|
88
89
|
export async function runOpenCode(options) {
|
|
89
|
-
const prompt = await
|
|
90
|
+
const prompt = (await prepareThreadDelivery({ env: process.env, resumed: false,
|
|
91
|
+
sessionId: "unverified-cold-opencode", wakePrompt: await readPrompt() })).prompt;
|
|
92
|
+
if (process.env.CREW_THREAD_ROOT) {
|
|
93
|
+
const { sessionId: _unverified, ...coldOptions } = options;
|
|
94
|
+
return (await runAttempt(coldOptions, prompt)).code;
|
|
95
|
+
}
|
|
90
96
|
const first = await runAttempt(options, prompt);
|
|
91
97
|
if (!first.staleSession)
|
|
92
98
|
return first.code;
|