@nowcrew/daemon 0.5.26 → 0.5.28

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.
Files changed (67) hide show
  1. package/package.json +1 -1
  2. package/dist/attachments.js +0 -196
  3. package/dist/bound-im-decision.js +0 -22
  4. package/dist/completion-retransmitter.js +0 -77
  5. package/dist/computer-cli.js +0 -274
  6. package/dist/computer-profile-lock.js +0 -395
  7. package/dist/computer-profile.js +0 -364
  8. package/dist/computer-service.js +0 -358
  9. package/dist/config.js +0 -82
  10. package/dist/console-collapse.js +0 -13
  11. package/dist/console-formatter.js +0 -77
  12. package/dist/console-payload.js +0 -73
  13. package/dist/console.js +0 -329
  14. package/dist/daemon-startup-error.js +0 -30
  15. package/dist/execution-backend.js +0 -44
  16. package/dist/execution-event-limit.js +0 -64
  17. package/dist/execution-journal-lock.js +0 -421
  18. package/dist/execution-journal.js +0 -716
  19. package/dist/execution-protocol.js +0 -342
  20. package/dist/execution-recovery.js +0 -95
  21. package/dist/execution-runner.js +0 -659
  22. package/dist/execution-supervisor-child.js +0 -236
  23. package/dist/execution-supervisor.js +0 -302
  24. package/dist/execution-telemetry-journal.js +0 -71
  25. package/dist/external-output.js +0 -114
  26. package/dist/i18n.js +0 -64
  27. package/dist/json-result.js +0 -27
  28. package/dist/list-models.js +0 -92
  29. package/dist/local-executor.js +0 -439
  30. package/dist/log-format.js +0 -10
  31. package/dist/machine-info.js +0 -124
  32. package/dist/main.js +0 -118
  33. package/dist/normalize.js +0 -170
  34. package/dist/origin-decision.js +0 -44
  35. package/dist/platform.js +0 -8
  36. package/dist/prompt.js +0 -307
  37. package/dist/provider-env.js +0 -90
  38. package/dist/runner.js +0 -234
  39. package/dist/runtime-cancellation.js +0 -74
  40. package/dist/runtime-capabilities.js +0 -43
  41. package/dist/runtime-path.js +0 -60
  42. package/dist/runtimes/claude.js +0 -51
  43. package/dist/runtimes/codex-app-server-runner.js +0 -340
  44. package/dist/runtimes/codex-deepseek-catalog.js +0 -7
  45. package/dist/runtimes/codex-deepseek-config.js +0 -50
  46. package/dist/runtimes/codex.js +0 -53
  47. package/dist/runtimes/kimi-acp-runner.js +0 -364
  48. package/dist/runtimes/kimi.js +0 -45
  49. package/dist/runtimes/progress-watchdog.js +0 -26
  50. package/dist/scheduled-report.js +0 -51
  51. package/dist/scheduled-run-report.js +0 -57
  52. package/dist/serve-lifecycle.js +0 -82
  53. package/dist/serve.js +0 -868
  54. package/dist/session.js +0 -82
  55. package/dist/shared-execution-slots.js +0 -68
  56. package/dist/shutdown-deadline.js +0 -32
  57. package/dist/skill-preview.js +0 -21
  58. package/dist/skills.js +0 -56
  59. package/dist/slog.js +0 -228
  60. package/dist/supervised-runtime.js +0 -104
  61. package/dist/token.js +0 -24
  62. package/dist/unified-diff.js +0 -84
  63. package/dist/websocket-shutdown.js +0 -53
  64. package/dist/win32-job-object.js +0 -193
  65. package/dist/workspace-fs.js +0 -80
  66. package/dist/workspace-import.js +0 -127
  67. package/dist/workspace.js +0 -148
@@ -1,342 +0,0 @@
1
- import { z } from "zod";
2
- const ExecutionIdSchema = z.string().uuid();
3
- const ProtocolVersionSchema = z.literal(1);
4
- const TimestampSchema = z.string().datetime({ offset: true });
5
- export const MAX_PG_INTEGER = 2_147_483_647;
6
- const MIN_SIGNED_32_INTEGER = -2_147_483_648;
7
- const SequenceSchema = z.number().int().min(0).max(MAX_PG_INTEGER);
8
- const TokenCountSchema = z.number().int().min(0).max(MAX_PG_INTEGER);
9
- const ExitCodeSchema = z.number().int().min(MIN_SIGNED_32_INTEGER).max(MAX_PG_INTEGER);
10
- const RuntimeSchema = z.enum(["claude", "codex", "kimi"]);
11
- const UnsafePathCharacterSchema = /[\p{Cc}<>:"/\\|?*]/u;
12
- const WindowsReservedNameSchema = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i;
13
- const AgentHandleSchema = z.string().min(1).max(64).refine((handle) => handle !== "."
14
- && handle !== ".."
15
- && !UnsafePathCharacterSchema.test(handle)
16
- && !WindowsReservedNameSchema.test(handle)
17
- && !handle.endsWith(".")
18
- && !handle.endsWith(" ")
19
- && Buffer.byteLength(handle, "utf8") <= 255, "agent handle must be a cross-platform safe filesystem component");
20
- export const ReasoningSchema = z.enum([
21
- "default",
22
- "none",
23
- "minimal",
24
- "low",
25
- "medium",
26
- "high",
27
- "xhigh",
28
- "max",
29
- ]);
30
- export const PermissionSchema = z.enum([
31
- "local_default",
32
- "sandboxed",
33
- "workspace_write",
34
- "full_access",
35
- ]);
36
- export const EffectivePermissionSchema = z.enum([
37
- "sandboxed",
38
- "workspace_write",
39
- "full_access",
40
- ]);
41
- export const LegacyAgentStartSchema = z.object({
42
- type: z.literal("agent:start"),
43
- agentHandle: z.string().min(1),
44
- channelId: z.string().min(1),
45
- reason: z.string().optional(),
46
- wake: z.object({
47
- seq: z.number().int().nonnegative().optional(),
48
- content: z.string().optional(),
49
- senderHandle: z.string().optional(),
50
- threadId: z.string().optional(),
51
- origin: z.enum(["wecom", "feishu"]).optional(),
52
- }).passthrough().optional(),
53
- scheduledRun: z.object({
54
- jobId: z.string().min(1),
55
- runId: z.string().min(1),
56
- title: z.string().optional(),
57
- outputPolicy: z.unknown().optional(),
58
- externalNotificationPolicy: z.unknown().optional(),
59
- }).passthrough().optional(),
60
- silent: z.boolean().optional(),
61
- }).passthrough();
62
- export const RejectionReasonSchema = z.enum([
63
- "invalid_spec",
64
- "runtime_unavailable",
65
- "capability_missing",
66
- "local_policy_denied",
67
- "resource_limit",
68
- ]);
69
- export const ActivityKindSchema = z.enum([
70
- "working",
71
- "thinking",
72
- "reading",
73
- "sending",
74
- "claiming",
75
- "checking",
76
- "done",
77
- "error",
78
- ]);
79
- export const ConsoleStreamSchema = z.enum([
80
- "system",
81
- "thinking",
82
- "text",
83
- "tool",
84
- "tool_result",
85
- "result",
86
- "error",
87
- ]);
88
- export const ExecutionAttachmentSchema = z.object({
89
- id: z.string().min(1).max(200),
90
- filename: z.string().min(1).max(255),
91
- mime: z.string().min(1).max(200),
92
- sizeBytes: z.number().int().nonnegative().max(25 * 1024 * 1024),
93
- }).strict();
94
- export const ExecutionStartSchema = z.object({
95
- type: z.literal("execution:start"),
96
- protocolVersion: ProtocolVersionSchema,
97
- executionId: ExecutionIdSchema,
98
- agent: z.object({
99
- id: z.string().min(1),
100
- handle: AgentHandleSchema,
101
- }).strict(),
102
- workspace: z.object({
103
- taskKey: z.string().min(1).max(200),
104
- resumeKey: z.string().min(1).max(200).optional(),
105
- }).strict(),
106
- instructions: z.object({
107
- language: z.enum(["zh", "en"]),
108
- systemPrompt: z.string(),
109
- wakePrompt: z.string(),
110
- }).strict(),
111
- runtime: z.object({
112
- name: RuntimeSchema,
113
- model: z.string().optional(),
114
- reasoning: ReasoningSchema.optional(),
115
- timeoutMs: z.number().int().positive().optional(),
116
- }).strict(),
117
- permissions: z.object({
118
- requested: PermissionSchema,
119
- }).strict(),
120
- context: z.object({
121
- channelId: z.string().min(1),
122
- threadId: z.string().min(1).optional(),
123
- wakeMessageId: z.string().min(1).optional(),
124
- externalResponseSessionId: ExecutionIdSchema.optional(),
125
- answerStream: z.boolean().optional(),
126
- attachments: z.array(ExecutionAttachmentSchema).max(20).optional(),
127
- }).strict(),
128
- reporting: z.object({
129
- captureFinal: z.boolean(),
130
- streamActivity: z.boolean(),
131
- streamConsole: z.boolean(),
132
- allowBoundImDecision: z.boolean().optional(),
133
- }).strict(),
134
- }).strict();
135
- export const ExecutionCancelSchema = z.object({
136
- type: z.literal("execution:cancel"),
137
- protocolVersion: ProtocolVersionSchema,
138
- executionId: ExecutionIdSchema,
139
- }).strict();
140
- export const ExecutionSyncSchema = z.object({
141
- type: z.literal("execution:sync"),
142
- protocolVersion: ProtocolVersionSchema,
143
- reqId: z.string().min(1).max(200),
144
- }).strict();
145
- export const ExecutionCompletionAckSchema = z.object({
146
- type: z.literal("execution:completion-ack"),
147
- protocolVersion: ProtocolVersionSchema,
148
- executionId: ExecutionIdSchema,
149
- }).strict();
150
- export const ExecutionEventAckSchema = z.object({
151
- type: z.literal("execution:event-ack"),
152
- protocolVersion: ProtocolVersionSchema,
153
- executionId: ExecutionIdSchema,
154
- kind: z.enum(["activity", "console"]),
155
- seq: SequenceSchema,
156
- }).strict();
157
- export const ExecutionAcceptedSchema = z.object({
158
- type: z.literal("execution:accepted"),
159
- protocolVersion: ProtocolVersionSchema,
160
- executionId: ExecutionIdSchema,
161
- state: z.enum(["queued", "ready"]),
162
- effectivePermission: EffectivePermissionSchema,
163
- at: TimestampSchema,
164
- }).strict();
165
- export const ExecutionRejectedSchema = z.object({
166
- type: z.literal("execution:rejected"),
167
- protocolVersion: ProtocolVersionSchema,
168
- executionId: ExecutionIdSchema,
169
- reason: RejectionReasonSchema,
170
- message: z.string().optional(),
171
- at: TimestampSchema,
172
- }).strict();
173
- export const ExecutionStartedSchema = z.object({
174
- type: z.literal("execution:started"),
175
- protocolVersion: ProtocolVersionSchema,
176
- executionId: ExecutionIdSchema,
177
- at: TimestampSchema,
178
- }).strict();
179
- export const ExecutionActivitySchema = z.object({
180
- type: z.literal("execution:activity"),
181
- protocolVersion: ProtocolVersionSchema,
182
- executionId: ExecutionIdSchema,
183
- activity: ActivityKindSchema,
184
- detail: z.string(),
185
- seq: SequenceSchema,
186
- at: TimestampSchema,
187
- }).strict();
188
- export const ExecutionConsoleSchema = z.object({
189
- type: z.literal("execution:console"),
190
- protocolVersion: ProtocolVersionSchema,
191
- executionId: ExecutionIdSchema,
192
- stream: ConsoleStreamSchema,
193
- text: z.string(),
194
- payload: z.record(z.string(), z.unknown()).optional(),
195
- seq: SequenceSchema,
196
- at: TimestampSchema,
197
- }).strict();
198
- export const ExecutionOutputSchema = z.object({
199
- type: z.literal("execution:output"),
200
- protocolVersion: ProtocolVersionSchema,
201
- executionId: ExecutionIdSchema,
202
- channel: z.literal("external_answer"),
203
- text: z.string().min(1),
204
- seq: SequenceSchema,
205
- at: TimestampSchema,
206
- }).strict();
207
- export const ExecutionUsageSchema = z.object({
208
- inputTokens: TokenCountSchema,
209
- outputTokens: TokenCountSchema,
210
- cacheReadTokens: TokenCountSchema,
211
- cacheCreationTokens: TokenCountSchema,
212
- costUsd: z.number().finite().nonnegative().optional(),
213
- }).strict();
214
- const RawExecutionCompletedSchema = z.object({
215
- type: z.literal("execution:completed"),
216
- protocolVersion: ProtocolVersionSchema,
217
- executionId: ExecutionIdSchema,
218
- outcome: z.enum(["succeeded", "failed", "cancelled"]),
219
- exitCode: ExitCodeSchema.optional(),
220
- terminationSignal: z.string().min(1).optional(),
221
- errorCode: z.string().min(1).optional(),
222
- errorMessage: z.string().min(1).optional(),
223
- runtime: RuntimeSchema,
224
- model: z.string().optional(),
225
- resumed: z.boolean(),
226
- finalText: z.string().optional(),
227
- externalAnswer: z.string().min(1).optional(),
228
- boundImDecision: z.enum(["notify", "silent"]).optional(),
229
- usage: ExecutionUsageSchema.optional(),
230
- startedAt: TimestampSchema,
231
- finishedAt: TimestampSchema,
232
- }).strict();
233
- function validateCompletionSemantics(completion, ctx) {
234
- const addIssue = (message, path) => {
235
- ctx.addIssue({ code: z.ZodIssueCode.custom, message, path });
236
- };
237
- if (Date.parse(completion.finishedAt) < Date.parse(completion.startedAt)) {
238
- addIssue("finishedAt must be greater than or equal to startedAt", ["finishedAt"]);
239
- }
240
- if (completion.outcome === "succeeded") {
241
- if (completion.exitCode !== 0) {
242
- addIssue("succeeded completion requires exitCode 0", ["exitCode"]);
243
- }
244
- for (const field of ["terminationSignal", "errorCode", "errorMessage"]) {
245
- if (completion[field] !== undefined) {
246
- addIssue(`succeeded completion cannot include ${field}`, [field]);
247
- }
248
- }
249
- return;
250
- }
251
- const hasNonExitDiagnostic = completion.terminationSignal !== undefined
252
- || completion.errorCode !== undefined
253
- || completion.errorMessage !== undefined;
254
- const hasDiagnostic = completion.outcome === "failed"
255
- ? (completion.exitCode !== undefined && completion.exitCode !== 0) || hasNonExitDiagnostic
256
- : completion.exitCode !== undefined || hasNonExitDiagnostic;
257
- if (!hasDiagnostic) {
258
- addIssue(`${completion.outcome} completion requires a diagnostic fact`, ["outcome"]);
259
- }
260
- }
261
- export const ExecutionCompletedSchema = RawExecutionCompletedSchema.superRefine(validateCompletionSemantics);
262
- const SnapshotAcceptedEntrySchema = z.object({
263
- executionId: ExecutionIdSchema,
264
- state: z.literal("accepted"),
265
- updatedAt: TimestampSchema,
266
- }).strict();
267
- const SnapshotRunningEntrySchema = z.object({
268
- executionId: ExecutionIdSchema,
269
- state: z.literal("running"),
270
- updatedAt: TimestampSchema,
271
- }).strict();
272
- const SnapshotCompletedEntrySchema = z.object({
273
- executionId: ExecutionIdSchema,
274
- state: z.literal("completed"),
275
- completion: ExecutionCompletedSchema,
276
- updatedAt: TimestampSchema,
277
- }).strict();
278
- const SnapshotInterruptedEntrySchema = z.object({
279
- executionId: ExecutionIdSchema,
280
- state: z.literal("interrupted"),
281
- completion: ExecutionCompletedSchema,
282
- updatedAt: TimestampSchema,
283
- }).strict();
284
- const RawExecutionSnapshotEntrySchema = z.discriminatedUnion("state", [
285
- SnapshotAcceptedEntrySchema,
286
- SnapshotRunningEntrySchema,
287
- SnapshotCompletedEntrySchema,
288
- SnapshotInterruptedEntrySchema,
289
- ]);
290
- export const ExecutionSnapshotEntrySchema = RawExecutionSnapshotEntrySchema.superRefine((entry, ctx) => {
291
- if ((entry.state === "completed" || entry.state === "interrupted")
292
- && entry.executionId !== entry.completion.executionId) {
293
- ctx.addIssue({
294
- code: z.ZodIssueCode.custom,
295
- message: "snapshot entry executionId must match completion executionId",
296
- path: ["completion", "executionId"],
297
- });
298
- }
299
- if (entry.state === "interrupted") {
300
- if (entry.completion.outcome !== "failed") {
301
- ctx.addIssue({
302
- code: z.ZodIssueCode.custom,
303
- message: "interrupted snapshot entry requires a failed completion",
304
- path: ["completion", "outcome"],
305
- });
306
- }
307
- if (entry.completion.errorCode !== "interrupted") {
308
- ctx.addIssue({
309
- code: z.ZodIssueCode.custom,
310
- message: "interrupted snapshot entry requires errorCode interrupted",
311
- path: ["completion", "errorCode"],
312
- });
313
- }
314
- }
315
- });
316
- export const ExecutionSnapshotSchema = z.object({
317
- type: z.literal("execution:snapshot"),
318
- protocolVersion: ProtocolVersionSchema,
319
- reqId: z.string().min(1).max(200),
320
- entries: z.array(ExecutionSnapshotEntrySchema),
321
- }).strict();
322
- export const ServerToDaemonExecutionFrameSchema = z.discriminatedUnion("type", [
323
- ExecutionStartSchema,
324
- ExecutionCancelSchema,
325
- ExecutionSyncSchema,
326
- ExecutionCompletionAckSchema,
327
- ExecutionEventAckSchema,
328
- ]);
329
- const RawDaemonToServerExecutionFrameSchema = z.discriminatedUnion("type", [
330
- ExecutionAcceptedSchema,
331
- ExecutionRejectedSchema,
332
- ExecutionStartedSchema,
333
- ExecutionActivitySchema,
334
- ExecutionConsoleSchema,
335
- ExecutionOutputSchema,
336
- RawExecutionCompletedSchema,
337
- ExecutionSnapshotSchema,
338
- ]);
339
- export const DaemonToServerExecutionFrameSchema = RawDaemonToServerExecutionFrameSchema.superRefine((frame, ctx) => {
340
- if (frame.type === "execution:completed")
341
- validateCompletionSemantics(frame, ctx);
342
- });
@@ -1,95 +0,0 @@
1
- import { join, resolve } from "node:path";
2
- import { JournalLockedError } from "./execution-journal.js";
3
- import { DaemonAlreadyRunningError } from "./daemon-startup-error.js";
4
- export async function reconcileExecutionJournal(journal, dependencies) {
5
- try {
6
- await journal.reconcileAfterRestart();
7
- }
8
- catch (error) {
9
- const agentsRoot = resolve(dependencies.agentsRoot);
10
- const errorRecord = typeof error === "object" && error !== null
11
- ? error
12
- : {};
13
- const journalPath = typeof errorRecord.journalPath === "string"
14
- ? resolve(errorRecord.journalPath)
15
- : join(agentsRoot, ".crew", "executions");
16
- const ownerPid = typeof errorRecord.ownerPid === "number" ? errorRecord.ownerPid : undefined;
17
- const errorType = error instanceof Error ? error.name : typeof error;
18
- const errorMessage = error instanceof Error ? error.message : String(error);
19
- const alreadyRunning = error instanceof JournalLockedError && ownerPid !== undefined;
20
- const diagnostics = {
21
- server_url: dependencies.serverUrl,
22
- agents_root: agentsRoot,
23
- journal_path: journalPath,
24
- owner_pid: ownerPid,
25
- ...(dependencies.profileName === undefined ? {} : { profile_name: dependencies.profileName }),
26
- error_type: errorType,
27
- error_message: errorMessage,
28
- };
29
- const failureEvent = alreadyRunning ? "daemon.already_running" : "execution.recovery_failed";
30
- const failureMessage = alreadyRunning ? "daemon 已在运行" : "execution journal 恢复失败";
31
- const failureLevel = alreadyRunning ? "WARN" : "ERROR";
32
- dependencies.log(failureEvent, failureMessage, {
33
- level: failureLevel,
34
- ...diagnostics,
35
- });
36
- dependencies.writeStderr(`${JSON.stringify({
37
- level: failureLevel,
38
- event_type: failureEvent,
39
- message: failureMessage,
40
- ...diagnostics,
41
- })}\n`);
42
- const reportCleanupFailure = (stage, cleanupError) => {
43
- const cleanupErrorType = cleanupError instanceof Error ? cleanupError.name : typeof cleanupError;
44
- const cleanupErrorMessage = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
45
- const cleanupDiagnostics = {
46
- server_url: dependencies.serverUrl,
47
- agents_root: agentsRoot,
48
- journal_path: journalPath,
49
- owner_pid: ownerPid,
50
- cleanup_stage: stage,
51
- error_type: cleanupErrorType,
52
- error_message: cleanupErrorMessage,
53
- ...(alreadyRunning
54
- ? { startup_error_type: errorType, startup_error_message: errorMessage }
55
- : { recovery_error_type: errorType, recovery_error_message: errorMessage }),
56
- };
57
- const cleanupEvent = alreadyRunning
58
- ? "daemon.already_running_cleanup_failed"
59
- : "execution.recovery_cleanup_failed";
60
- const cleanupMessage = alreadyRunning
61
- ? "daemon 重复启动后的清理失败"
62
- : "execution journal 恢复失败后的清理失败";
63
- dependencies.log(cleanupEvent, cleanupMessage, { level: "ERROR", ...cleanupDiagnostics });
64
- dependencies.writeStderr(`${JSON.stringify({
65
- level: "ERROR",
66
- event_type: cleanupEvent,
67
- message: cleanupMessage,
68
- ...cleanupDiagnostics,
69
- })}\n`);
70
- };
71
- try {
72
- await dependencies.flush();
73
- }
74
- catch (cleanupError) {
75
- reportCleanupFailure("slog_flush", cleanupError);
76
- }
77
- try {
78
- await journal.close();
79
- }
80
- catch (cleanupError) {
81
- reportCleanupFailure("journal_close", cleanupError);
82
- }
83
- if (alreadyRunning) {
84
- throw new DaemonAlreadyRunningError({
85
- ownerPid,
86
- agentsRoot,
87
- journalPath,
88
- serverUrl: dependencies.serverUrl,
89
- ...(dependencies.profileName === undefined ? {} : { profileName: dependencies.profileName }),
90
- cause: error,
91
- });
92
- }
93
- throw error;
94
- }
95
- }