botmux 2.33.0 → 2.33.1
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.en.md +12 -1
- package/README.md +45 -1
- package/dist/adapters/cli/claude-code.d.ts.map +1 -1
- package/dist/adapters/cli/claude-code.js +11 -0
- package/dist/adapters/cli/claude-code.js.map +1 -1
- package/dist/cli/bots-list-output.d.ts +21 -0
- package/dist/cli/bots-list-output.d.ts.map +1 -0
- package/dist/cli/bots-list-output.js +23 -0
- package/dist/cli/bots-list-output.js.map +1 -0
- package/dist/cli/workflow.d.ts +13 -0
- package/dist/cli/workflow.d.ts.map +1 -0
- package/dist/cli/workflow.js +781 -0
- package/dist/cli/workflow.js.map +1 -0
- package/dist/cli.js +69 -14
- package/dist/cli.js.map +1 -1
- package/dist/core/command-handler.d.ts.map +1 -1
- package/dist/core/command-handler.js +211 -4
- package/dist/core/command-handler.js.map +1 -1
- package/dist/core/session-manager.d.ts +6 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +22 -12
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/worker-pool.d.ts +13 -0
- package/dist/core/worker-pool.d.ts.map +1 -1
- package/dist/core/worker-pool.js +100 -6
- package/dist/core/worker-pool.js.map +1 -1
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +884 -3
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard/auth.d.ts +36 -0
- package/dist/dashboard/auth.d.ts.map +1 -1
- package/dist/dashboard/auth.js +22 -0
- package/dist/dashboard/auth.js.map +1 -1
- package/dist/dashboard/web/app.js +20 -1
- package/dist/dashboard/web/app.js.map +1 -1
- package/dist/dashboard/web/i18n.d.ts.map +1 -1
- package/dist/dashboard/web/i18n.js +356 -0
- package/dist/dashboard/web/i18n.js.map +1 -1
- package/dist/dashboard/web/workflow-catalog.d.ts +2 -0
- package/dist/dashboard/web/workflow-catalog.d.ts.map +1 -0
- package/dist/dashboard/web/workflow-catalog.js +323 -0
- package/dist/dashboard/web/workflow-catalog.js.map +1 -0
- package/dist/dashboard/web/workflows.d.ts +2 -0
- package/dist/dashboard/web/workflows.d.ts.map +1 -0
- package/dist/dashboard/web/workflows.js +1618 -0
- package/dist/dashboard/web/workflows.js.map +1 -0
- package/dist/dashboard/workflow-api.d.ts +23 -0
- package/dist/dashboard/workflow-api.d.ts.map +1 -0
- package/dist/dashboard/workflow-api.js +463 -0
- package/dist/dashboard/workflow-api.js.map +1 -0
- package/dist/dashboard-web/app.js +494 -199
- package/dist/dashboard-web/index.html +1 -0
- package/dist/dashboard-web/style.css +160 -6
- package/dist/dashboard-web/terminal-replay.html +227 -0
- package/dist/dashboard.js +29 -12
- package/dist/dashboard.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +12 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +12 -0
- package/dist/i18n/zh.js.map +1 -1
- package/dist/im/lark/card-handler.d.ts +3 -0
- package/dist/im/lark/card-handler.d.ts.map +1 -1
- package/dist/im/lark/card-handler.js +27 -1
- package/dist/im/lark/card-handler.js.map +1 -1
- package/dist/im/lark/client.d.ts +19 -2
- package/dist/im/lark/client.d.ts.map +1 -1
- package/dist/im/lark/client.js +21 -2
- package/dist/im/lark/client.js.map +1 -1
- package/dist/im/lark/workflow-card-handler.d.ts +50 -0
- package/dist/im/lark/workflow-card-handler.d.ts.map +1 -0
- package/dist/im/lark/workflow-card-handler.js +152 -0
- package/dist/im/lark/workflow-card-handler.js.map +1 -0
- package/dist/im/lark/workflow-cards.d.ts +46 -0
- package/dist/im/lark/workflow-cards.d.ts.map +1 -0
- package/dist/im/lark/workflow-cards.js +226 -0
- package/dist/im/lark/workflow-cards.js.map +1 -0
- package/dist/im/lark/workflow-progress-card.d.ts +76 -0
- package/dist/im/lark/workflow-progress-card.d.ts.map +1 -0
- package/dist/im/lark/workflow-progress-card.js +279 -0
- package/dist/im/lark/workflow-progress-card.js.map +1 -0
- package/dist/im/lark/workflow-slash-command.d.ts +92 -0
- package/dist/im/lark/workflow-slash-command.d.ts.map +1 -0
- package/dist/im/lark/workflow-slash-command.js +185 -0
- package/dist/im/lark/workflow-slash-command.js.map +1 -0
- package/dist/services/group-creator.d.ts.map +1 -1
- package/dist/services/group-creator.js +17 -4
- package/dist/services/group-creator.js.map +1 -1
- package/dist/services/groups-store.d.ts +11 -0
- package/dist/services/groups-store.d.ts.map +1 -1
- package/dist/services/groups-store.js +26 -0
- package/dist/services/groups-store.js.map +1 -1
- package/dist/services/jsonl-cursor.d.ts +12 -0
- package/dist/services/jsonl-cursor.d.ts.map +1 -0
- package/dist/services/jsonl-cursor.js +45 -0
- package/dist/services/jsonl-cursor.js.map +1 -0
- package/dist/services/schedule-store.d.ts +35 -0
- package/dist/services/schedule-store.d.ts.map +1 -1
- package/dist/services/schedule-store.js +108 -1
- package/dist/services/schedule-store.js.map +1 -1
- package/dist/skills/definitions.d.ts.map +1 -1
- package/dist/skills/definitions.js +399 -0
- package/dist/skills/definitions.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cli-usage-limit.d.ts.map +1 -1
- package/dist/utils/cli-usage-limit.js +4 -0
- package/dist/utils/cli-usage-limit.js.map +1 -1
- package/dist/worker.js +118 -14
- package/dist/worker.js.map +1 -1
- package/dist/workflows/attempt-resume.d.ts +114 -0
- package/dist/workflows/attempt-resume.d.ts.map +1 -0
- package/dist/workflows/attempt-resume.js +385 -0
- package/dist/workflows/attempt-resume.js.map +1 -0
- package/dist/workflows/attempt-terminal.d.ts +21 -0
- package/dist/workflows/attempt-terminal.d.ts.map +1 -0
- package/dist/workflows/attempt-terminal.js +7 -0
- package/dist/workflows/attempt-terminal.js.map +1 -0
- package/dist/workflows/blob.d.ts +27 -0
- package/dist/workflows/blob.d.ts.map +1 -0
- package/dist/workflows/blob.js +39 -0
- package/dist/workflows/blob.js.map +1 -0
- package/dist/workflows/cancel-run.d.ts +45 -0
- package/dist/workflows/cancel-run.d.ts.map +1 -0
- package/dist/workflows/cancel-run.js +99 -0
- package/dist/workflows/cancel-run.js.map +1 -0
- package/dist/workflows/cancel.d.ts +111 -0
- package/dist/workflows/cancel.d.ts.map +1 -0
- package/dist/workflows/cancel.js +120 -0
- package/dist/workflows/cancel.js.map +1 -0
- package/dist/workflows/catalog.d.ts +60 -0
- package/dist/workflows/catalog.d.ts.map +1 -0
- package/dist/workflows/catalog.js +119 -0
- package/dist/workflows/catalog.js.map +1 -0
- package/dist/workflows/cold-attach.d.ts +30 -0
- package/dist/workflows/cold-attach.d.ts.map +1 -0
- package/dist/workflows/cold-attach.js +40 -0
- package/dist/workflows/cold-attach.js.map +1 -0
- package/dist/workflows/cold-scan.d.ts +21 -0
- package/dist/workflows/cold-scan.d.ts.map +1 -0
- package/dist/workflows/cold-scan.js +70 -0
- package/dist/workflows/cold-scan.js.map +1 -0
- package/dist/workflows/daemon-spawn.d.ts +117 -0
- package/dist/workflows/daemon-spawn.d.ts.map +1 -0
- package/dist/workflows/daemon-spawn.js +551 -0
- package/dist/workflows/daemon-spawn.js.map +1 -0
- package/dist/workflows/definition.d.ts +1309 -0
- package/dist/workflows/definition.d.ts.map +1 -0
- package/dist/workflows/definition.js +334 -0
- package/dist/workflows/definition.js.map +1 -0
- package/dist/workflows/effect-input.d.ts +4 -0
- package/dist/workflows/effect-input.d.ts.map +1 -0
- package/dist/workflows/effect-input.js +18 -0
- package/dist/workflows/effect-input.js.map +1 -0
- package/dist/workflows/events/append.d.ts +77 -0
- package/dist/workflows/events/append.d.ts.map +1 -0
- package/dist/workflows/events/append.js +214 -0
- package/dist/workflows/events/append.js.map +1 -0
- package/dist/workflows/events/idempotency.d.ts +77 -0
- package/dist/workflows/events/idempotency.d.ts.map +1 -0
- package/dist/workflows/events/idempotency.js +116 -0
- package/dist/workflows/events/idempotency.js.map +1 -0
- package/dist/workflows/events/index.d.ts +7 -0
- package/dist/workflows/events/index.d.ts.map +1 -0
- package/dist/workflows/events/index.js +7 -0
- package/dist/workflows/events/index.js.map +1 -0
- package/dist/workflows/events/payloads.d.ts +917 -0
- package/dist/workflows/events/payloads.d.ts.map +1 -0
- package/dist/workflows/events/payloads.js +337 -0
- package/dist/workflows/events/payloads.js.map +1 -0
- package/dist/workflows/events/replay.d.ts +238 -0
- package/dist/workflows/events/replay.d.ts.map +1 -0
- package/dist/workflows/events/replay.js +608 -0
- package/dist/workflows/events/replay.js.map +1 -0
- package/dist/workflows/events/schema.d.ts +5242 -0
- package/dist/workflows/events/schema.d.ts.map +1 -0
- package/dist/workflows/events/schema.js +295 -0
- package/dist/workflows/events/schema.js.map +1 -0
- package/dist/workflows/events/types.d.ts +34 -0
- package/dist/workflows/events/types.d.ts.map +1 -0
- package/dist/workflows/events/types.js +2 -0
- package/dist/workflows/events/types.js.map +1 -0
- package/dist/workflows/fanout.d.ts +36 -0
- package/dist/workflows/fanout.d.ts.map +1 -0
- package/dist/workflows/fanout.js +114 -0
- package/dist/workflows/fanout.js.map +1 -0
- package/dist/workflows/hostExecutors/botmux-schedule.d.ts +41 -0
- package/dist/workflows/hostExecutors/botmux-schedule.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/botmux-schedule.js +121 -0
- package/dist/workflows/hostExecutors/botmux-schedule.js.map +1 -0
- package/dist/workflows/hostExecutors/feishu-im.d.ts +12 -0
- package/dist/workflows/hostExecutors/feishu-im.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/feishu-im.js +49 -0
- package/dist/workflows/hostExecutors/feishu-im.js.map +1 -0
- package/dist/workflows/hostExecutors/feishu-reply.d.ts +24 -0
- package/dist/workflows/hostExecutors/feishu-reply.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/feishu-reply.js +88 -0
- package/dist/workflows/hostExecutors/feishu-reply.js.map +1 -0
- package/dist/workflows/hostExecutors/feishu-send.d.ts +23 -0
- package/dist/workflows/hostExecutors/feishu-send.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/feishu-send.js +124 -0
- package/dist/workflows/hostExecutors/feishu-send.js.map +1 -0
- package/dist/workflows/hostExecutors/index.d.ts +8 -0
- package/dist/workflows/hostExecutors/index.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/index.js +8 -0
- package/dist/workflows/hostExecutors/index.js.map +1 -0
- package/dist/workflows/hostExecutors/protocol.d.ts +42 -0
- package/dist/workflows/hostExecutors/protocol.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/protocol.js +181 -0
- package/dist/workflows/hostExecutors/protocol.js.map +1 -0
- package/dist/workflows/hostExecutors/registry.d.ts +10 -0
- package/dist/workflows/hostExecutors/registry.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/registry.js +36 -0
- package/dist/workflows/hostExecutors/registry.js.map +1 -0
- package/dist/workflows/hostExecutors/types.d.ts +78 -0
- package/dist/workflows/hostExecutors/types.d.ts.map +1 -0
- package/dist/workflows/hostExecutors/types.js +2 -0
- package/dist/workflows/hostExecutors/types.js.map +1 -0
- package/dist/workflows/loader.d.ts +16 -0
- package/dist/workflows/loader.d.ts.map +1 -0
- package/dist/workflows/loader.js +56 -0
- package/dist/workflows/loader.js.map +1 -0
- package/dist/workflows/loop.d.ts +50 -0
- package/dist/workflows/loop.d.ts.map +1 -0
- package/dist/workflows/loop.js +350 -0
- package/dist/workflows/loop.js.map +1 -0
- package/dist/workflows/ops-projection.d.ts +168 -0
- package/dist/workflows/ops-projection.d.ts.map +1 -0
- package/dist/workflows/ops-projection.js +707 -0
- package/dist/workflows/ops-projection.js.map +1 -0
- package/dist/workflows/orchestrator.d.ts +107 -0
- package/dist/workflows/orchestrator.d.ts.map +1 -0
- package/dist/workflows/orchestrator.js +197 -0
- package/dist/workflows/orchestrator.js.map +1 -0
- package/dist/workflows/output-binding.d.ts +70 -0
- package/dist/workflows/output-binding.d.ts.map +1 -0
- package/dist/workflows/output-binding.js +265 -0
- package/dist/workflows/output-binding.js.map +1 -0
- package/dist/workflows/params.d.ts +61 -0
- package/dist/workflows/params.d.ts.map +1 -0
- package/dist/workflows/params.js +195 -0
- package/dist/workflows/params.js.map +1 -0
- package/dist/workflows/resume.d.ts +263 -0
- package/dist/workflows/resume.d.ts.map +1 -0
- package/dist/workflows/resume.js +808 -0
- package/dist/workflows/resume.js.map +1 -0
- package/dist/workflows/run-id.d.ts +2 -0
- package/dist/workflows/run-id.d.ts.map +1 -0
- package/dist/workflows/run-id.js +7 -0
- package/dist/workflows/run-id.js.map +1 -0
- package/dist/workflows/run-init.d.ts +48 -0
- package/dist/workflows/run-init.d.ts.map +1 -0
- package/dist/workflows/run-init.js +99 -0
- package/dist/workflows/run-init.js.map +1 -0
- package/dist/workflows/runs-dir.d.ts +4 -0
- package/dist/workflows/runs-dir.d.ts.map +1 -0
- package/dist/workflows/runs-dir.js +15 -0
- package/dist/workflows/runs-dir.js.map +1 -0
- package/dist/workflows/runtime.d.ts +211 -0
- package/dist/workflows/runtime.d.ts.map +1 -0
- package/dist/workflows/runtime.js +594 -0
- package/dist/workflows/runtime.js.map +1 -0
- package/dist/workflows/spawn-bot.d.ts +165 -0
- package/dist/workflows/spawn-bot.d.ts.map +1 -0
- package/dist/workflows/spawn-bot.js +215 -0
- package/dist/workflows/spawn-bot.js.map +1 -0
- package/dist/workflows/system.d.ts +49 -0
- package/dist/workflows/system.d.ts.map +1 -0
- package/dist/workflows/system.js +48 -0
- package/dist/workflows/system.js.map +1 -0
- package/dist/workflows/trigger-run.d.ts +70 -0
- package/dist/workflows/trigger-run.d.ts.map +1 -0
- package/dist/workflows/trigger-run.js +88 -0
- package/dist/workflows/trigger-run.js.map +1 -0
- package/dist/workflows/wait.d.ts +120 -0
- package/dist/workflows/wait.d.ts.map +1 -0
- package/dist/workflows/wait.js +181 -0
- package/dist/workflows/wait.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { ATTEMPT_TERMINAL_SCHEMA_VERSION, attemptTerminalSidecarPath, } from './attempt-terminal.js';
|
|
7
|
+
import { forkWorkerJsFactory, syntheticSessionUuid, } from './daemon-spawn.js';
|
|
8
|
+
import { isPathInsideDir, isValidPathSegment, isValidRunId, } from './ops-projection.js';
|
|
9
|
+
export const ATTEMPT_RESUME_SCHEMA_VERSION = 1;
|
|
10
|
+
export const ATTEMPT_RESUME_IDLE_MS = 30 * 60 * 1000;
|
|
11
|
+
export const ATTEMPT_RESUME_GRACE_MS = 5000;
|
|
12
|
+
export const RESUME_REQUIRES_CLI_SESSION_ID = new Set(['antigravity', 'cursor']);
|
|
13
|
+
export const RESUME_USES_SESSION_ID = new Set(['aiden', 'coco', 'claude-code', 'codex']);
|
|
14
|
+
export class AttemptResumeManager {
|
|
15
|
+
deps;
|
|
16
|
+
entries = new Map();
|
|
17
|
+
factory;
|
|
18
|
+
workerPath;
|
|
19
|
+
idleMs;
|
|
20
|
+
graceMs;
|
|
21
|
+
now;
|
|
22
|
+
constructor(deps) {
|
|
23
|
+
this.deps = deps;
|
|
24
|
+
this.factory = deps.factory ?? forkWorkerJsFactory;
|
|
25
|
+
this.workerPath = deps.workerPath ?? defaultWorkerPath();
|
|
26
|
+
this.idleMs = deps.idleMs ?? ATTEMPT_RESUME_IDLE_MS;
|
|
27
|
+
this.graceMs = deps.graceMs ?? ATTEMPT_RESUME_GRACE_MS;
|
|
28
|
+
this.now = deps.now ?? (() => Date.now());
|
|
29
|
+
}
|
|
30
|
+
async start(input) {
|
|
31
|
+
const ids = validateAttemptIds(input);
|
|
32
|
+
if (!ids.ok)
|
|
33
|
+
return ids;
|
|
34
|
+
const key = resumeKey(input);
|
|
35
|
+
const existing = this.entries.get(key);
|
|
36
|
+
if (existing && existing.webPort && existing.writeToken) {
|
|
37
|
+
this.bumpIdle(existing);
|
|
38
|
+
return {
|
|
39
|
+
ok: true,
|
|
40
|
+
resumeId: existing.resumeId,
|
|
41
|
+
runId: existing.runId,
|
|
42
|
+
activityId: existing.activityId,
|
|
43
|
+
attemptId: existing.attemptId,
|
|
44
|
+
sessionId: existing.sessionId,
|
|
45
|
+
originalSessionId: existing.originalSessionId,
|
|
46
|
+
cliSessionId: existing.cliSessionId,
|
|
47
|
+
webPort: existing.webPort,
|
|
48
|
+
writeToken: existing.writeToken,
|
|
49
|
+
url: this.resumeUrl(existing.webPort, existing.writeToken),
|
|
50
|
+
alreadyRunning: true,
|
|
51
|
+
startedAt: existing.startedAt,
|
|
52
|
+
logPath: existing.logPath,
|
|
53
|
+
sidecarPath: existing.sidecarPath,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (existing)
|
|
57
|
+
return existing.readyPromise;
|
|
58
|
+
const terminal = readTerminalSidecar(this.deps.runsDir, input);
|
|
59
|
+
if (!terminal.ok)
|
|
60
|
+
return terminal;
|
|
61
|
+
if (!terminal.terminal.larkAppId) {
|
|
62
|
+
return { ok: false, error: 'missing_lark_app_id' };
|
|
63
|
+
}
|
|
64
|
+
const bot = this.deps.resolveBot(terminal.terminal.larkAppId, terminal.terminal);
|
|
65
|
+
if (!bot)
|
|
66
|
+
return { ok: false, error: 'bot_not_registered' };
|
|
67
|
+
if (!isResumeCapableCli(bot.cliId)) {
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
error: 'resume_unsupported_cli',
|
|
71
|
+
hint: `${bot.cliId} does not support precise session resume.`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (cliRequiresNativeSessionId(bot.cliId) && !terminal.terminal.cliSessionId) {
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error: 'missing_cli_session_id',
|
|
78
|
+
hint: 'This CLI requires a native cliSessionId; rerun the workflow step before resuming.',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const startedAt = this.now();
|
|
82
|
+
const resumeId = `resume-${startedAt.toString(36)}-${randomBytes(4).toString('hex')}`;
|
|
83
|
+
const resumeDir = join(this.deps.runsDir, input.runId, 'attempts', input.activityId, input.attemptId, 'resumes', resumeId);
|
|
84
|
+
if (!isPathInsideDir(this.deps.runsDir, resumeDir)) {
|
|
85
|
+
return { ok: false, error: 'bad_path' };
|
|
86
|
+
}
|
|
87
|
+
mkdirSync(resumeDir, { recursive: true });
|
|
88
|
+
const logPath = join(resumeDir, 'terminal.log');
|
|
89
|
+
const ptyLogPath = join(resumeDir, 'pty.log');
|
|
90
|
+
const sidecarPath = join(resumeDir, 'resume.json');
|
|
91
|
+
const workingDir = expandWorkflowWorkingDir(terminal.terminal.workingDir) ?? process.cwd();
|
|
92
|
+
const sessionId = syntheticSessionUuid(`wf-resume-${input.runId}-${input.activityId}-${input.attemptId}-${resumeId}`);
|
|
93
|
+
const originalSessionId = terminal.terminal.sessionId;
|
|
94
|
+
appendResumeLog(logPath, 'system', `starting dashboard resume cwd=${workingDir}`);
|
|
95
|
+
const worker = this.factory.spawn({
|
|
96
|
+
workerPath: this.workerPath,
|
|
97
|
+
cwd: workingDir,
|
|
98
|
+
env: {
|
|
99
|
+
...process.env,
|
|
100
|
+
PATH: `${join(homedir(), '.botmux', 'bin')}:${process.env.PATH ?? ''}`,
|
|
101
|
+
BOTMUX_WORKFLOW: '1',
|
|
102
|
+
BOTMUX_WORKFLOW_RESUME: '1',
|
|
103
|
+
BOTMUX_WORKFLOW_RUN_ID: input.runId,
|
|
104
|
+
BOTMUX_WORKFLOW_ACTIVITY_ID: input.activityId,
|
|
105
|
+
BOTMUX_WORKFLOW_ATTEMPT_ID: input.attemptId,
|
|
106
|
+
BOTMUX_WORKFLOW_PTY_LOG_PATH: ptyLogPath,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
let readyResolve;
|
|
110
|
+
const readyPromise = new Promise((resolve) => {
|
|
111
|
+
readyResolve = resolve;
|
|
112
|
+
});
|
|
113
|
+
const entry = {
|
|
114
|
+
key,
|
|
115
|
+
resumeId,
|
|
116
|
+
runId: input.runId,
|
|
117
|
+
activityId: input.activityId,
|
|
118
|
+
attemptId: input.attemptId,
|
|
119
|
+
sessionId,
|
|
120
|
+
originalSessionId,
|
|
121
|
+
cliSessionId: terminal.terminal.cliSessionId,
|
|
122
|
+
larkAppId: bot.larkAppId,
|
|
123
|
+
botName: bot.botName ?? terminal.terminal.botName,
|
|
124
|
+
cliId: bot.cliId,
|
|
125
|
+
workingDir,
|
|
126
|
+
logPath,
|
|
127
|
+
sidecarPath,
|
|
128
|
+
startedAt,
|
|
129
|
+
updatedAt: startedAt,
|
|
130
|
+
worker,
|
|
131
|
+
readyPromise,
|
|
132
|
+
readyResolve,
|
|
133
|
+
};
|
|
134
|
+
this.entries.set(key, entry);
|
|
135
|
+
this.writeSidecar(entry, 'starting');
|
|
136
|
+
this.attachWorker(entry, bot);
|
|
137
|
+
this.bumpIdle(entry);
|
|
138
|
+
const init = {
|
|
139
|
+
type: 'init',
|
|
140
|
+
sessionId,
|
|
141
|
+
chatId: `wf-resume-chat-${input.runId}`,
|
|
142
|
+
rootMessageId: `wf-resume-root-${input.attemptId}`,
|
|
143
|
+
workingDir,
|
|
144
|
+
cliId: bot.cliId,
|
|
145
|
+
cliPathOverride: bot.cliPathOverride,
|
|
146
|
+
backendType: bot.backendType ?? 'pty',
|
|
147
|
+
prompt: '',
|
|
148
|
+
resume: true,
|
|
149
|
+
originalSessionId,
|
|
150
|
+
...(terminal.terminal.cliSessionId ? { cliSessionId: terminal.terminal.cliSessionId } : {}),
|
|
151
|
+
larkAppId: bot.larkAppId,
|
|
152
|
+
larkAppSecret: bot.larkAppSecret,
|
|
153
|
+
botName: bot.botName ?? terminal.terminal.botName,
|
|
154
|
+
botOpenId: bot.botOpenId,
|
|
155
|
+
locale: bot.locale ?? 'zh',
|
|
156
|
+
};
|
|
157
|
+
try {
|
|
158
|
+
worker.send(init);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
this.closeEntry(entry, `init_send_failed:${err instanceof Error ? err.message : String(err)}`);
|
|
162
|
+
return { ok: false, error: 'worker_init_failed', message: String(err) };
|
|
163
|
+
}
|
|
164
|
+
return readyPromise;
|
|
165
|
+
}
|
|
166
|
+
async end(input) {
|
|
167
|
+
const ids = validateAttemptIds(input);
|
|
168
|
+
if (!ids.ok)
|
|
169
|
+
return ids;
|
|
170
|
+
const entry = this.entries.get(resumeKey(input));
|
|
171
|
+
if (!entry)
|
|
172
|
+
return { ok: false, error: 'resume_not_running' };
|
|
173
|
+
const closedAt = this.closeEntry(entry, input.reason ?? 'ended_by_dashboard');
|
|
174
|
+
return {
|
|
175
|
+
ok: true,
|
|
176
|
+
resumeId: entry.resumeId,
|
|
177
|
+
status: 'closed',
|
|
178
|
+
closeReason: entry.closeReason ?? input.reason ?? 'ended_by_dashboard',
|
|
179
|
+
closedAt,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
attachWorker(entry, bot) {
|
|
183
|
+
const worker = entry.worker;
|
|
184
|
+
worker.stdout?.on('data', (data) => {
|
|
185
|
+
this.bumpIdle(entry);
|
|
186
|
+
appendResumeLog(entry.logPath, 'stdout', data.toString());
|
|
187
|
+
});
|
|
188
|
+
worker.stderr?.on('data', (data) => {
|
|
189
|
+
this.bumpIdle(entry);
|
|
190
|
+
appendResumeLog(entry.logPath, 'stderr', data.toString());
|
|
191
|
+
});
|
|
192
|
+
worker.on('message', (event) => {
|
|
193
|
+
this.bumpIdle(entry);
|
|
194
|
+
switch (event?.type) {
|
|
195
|
+
case 'ready': {
|
|
196
|
+
const webPort = Number(event.port);
|
|
197
|
+
const writeToken = String(event.token);
|
|
198
|
+
entry.webPort = webPort;
|
|
199
|
+
entry.writeToken = writeToken;
|
|
200
|
+
entry.updatedAt = this.now();
|
|
201
|
+
appendResumeLog(entry.logPath, 'system', `worker ready port=${event.port}`);
|
|
202
|
+
this.writeSidecar(entry, 'live');
|
|
203
|
+
entry.readyResolve({
|
|
204
|
+
ok: true,
|
|
205
|
+
resumeId: entry.resumeId,
|
|
206
|
+
runId: entry.runId,
|
|
207
|
+
activityId: entry.activityId,
|
|
208
|
+
attemptId: entry.attemptId,
|
|
209
|
+
sessionId: entry.sessionId,
|
|
210
|
+
originalSessionId: entry.originalSessionId,
|
|
211
|
+
cliSessionId: entry.cliSessionId,
|
|
212
|
+
webPort,
|
|
213
|
+
writeToken,
|
|
214
|
+
url: this.resumeUrl(webPort, writeToken),
|
|
215
|
+
alreadyRunning: false,
|
|
216
|
+
startedAt: entry.startedAt,
|
|
217
|
+
logPath: entry.logPath,
|
|
218
|
+
sidecarPath: entry.sidecarPath,
|
|
219
|
+
});
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case 'cli_session_id': {
|
|
223
|
+
if (typeof event.cliSessionId === 'string' && event.cliSessionId) {
|
|
224
|
+
entry.cliSessionId = event.cliSessionId;
|
|
225
|
+
this.writeSidecar(entry, entry.webPort ? 'live' : 'starting');
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case 'error':
|
|
230
|
+
appendResumeLog(entry.logPath, 'error', event.message ?? 'worker error');
|
|
231
|
+
if (!entry.webPort) {
|
|
232
|
+
entry.readyResolve({ ok: false, error: 'worker_error', message: String(event.message ?? '') });
|
|
233
|
+
}
|
|
234
|
+
this.closeEntry(entry, 'worker_error');
|
|
235
|
+
break;
|
|
236
|
+
default:
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
worker.on('error', (err) => {
|
|
241
|
+
appendResumeLog(entry.logPath, 'error', err.message);
|
|
242
|
+
if (!entry.webPort)
|
|
243
|
+
entry.readyResolve({ ok: false, error: 'worker_error', message: err.message });
|
|
244
|
+
this.closeEntry(entry, 'worker_error');
|
|
245
|
+
});
|
|
246
|
+
worker.on('exit', (code) => {
|
|
247
|
+
appendResumeLog(entry.logPath, 'system', `worker process exit code=${code ?? 'null'}`);
|
|
248
|
+
if (!entry.webPort) {
|
|
249
|
+
entry.readyResolve({ ok: false, error: 'worker_exited_before_ready' });
|
|
250
|
+
}
|
|
251
|
+
this.closeEntry(entry, entry.closeReason ?? 'worker_exit', { noKill: true });
|
|
252
|
+
});
|
|
253
|
+
appendResumeLog(entry.logPath, 'system', `worker spawned pid=${worker.pid ?? 'unknown'} cli=${bot.cliId}`);
|
|
254
|
+
}
|
|
255
|
+
bumpIdle(entry) {
|
|
256
|
+
if (entry.idleTimer)
|
|
257
|
+
clearTimeout(entry.idleTimer);
|
|
258
|
+
entry.idleTimer = setTimeout(() => {
|
|
259
|
+
this.closeEntry(entry, 'idle_timeout');
|
|
260
|
+
}, this.idleMs);
|
|
261
|
+
}
|
|
262
|
+
closeEntry(entry, reason, opts = {}) {
|
|
263
|
+
const current = this.entries.get(entry.key);
|
|
264
|
+
if (current !== entry && !opts.noKill)
|
|
265
|
+
return this.now();
|
|
266
|
+
entry.closeReason = entry.closeReason ?? reason;
|
|
267
|
+
if (entry.idleTimer)
|
|
268
|
+
clearTimeout(entry.idleTimer);
|
|
269
|
+
if (entry.closeTimer)
|
|
270
|
+
clearTimeout(entry.closeTimer);
|
|
271
|
+
const closedAt = this.now();
|
|
272
|
+
entry.updatedAt = closedAt;
|
|
273
|
+
this.writeSidecar(entry, 'closed');
|
|
274
|
+
this.entries.delete(entry.key);
|
|
275
|
+
if (!opts.noKill) {
|
|
276
|
+
try {
|
|
277
|
+
entry.worker.send({ type: 'close' });
|
|
278
|
+
}
|
|
279
|
+
catch { /* gone */ }
|
|
280
|
+
try {
|
|
281
|
+
entry.worker.kill('SIGINT');
|
|
282
|
+
}
|
|
283
|
+
catch { /* gone */ }
|
|
284
|
+
entry.closeTimer = setTimeout(() => {
|
|
285
|
+
try {
|
|
286
|
+
entry.worker.kill('SIGKILL');
|
|
287
|
+
}
|
|
288
|
+
catch { /* gone */ }
|
|
289
|
+
}, this.graceMs);
|
|
290
|
+
}
|
|
291
|
+
return closedAt;
|
|
292
|
+
}
|
|
293
|
+
writeSidecar(entry, status) {
|
|
294
|
+
const now = this.now();
|
|
295
|
+
entry.updatedAt = now;
|
|
296
|
+
const sidecar = {
|
|
297
|
+
schemaVersion: ATTEMPT_RESUME_SCHEMA_VERSION,
|
|
298
|
+
resumeId: entry.resumeId,
|
|
299
|
+
runId: entry.runId,
|
|
300
|
+
activityId: entry.activityId,
|
|
301
|
+
attemptId: entry.attemptId,
|
|
302
|
+
sessionId: entry.sessionId,
|
|
303
|
+
originalSessionId: entry.originalSessionId,
|
|
304
|
+
cliSessionId: entry.cliSessionId,
|
|
305
|
+
webPort: entry.webPort,
|
|
306
|
+
writeToken: entry.writeToken,
|
|
307
|
+
status,
|
|
308
|
+
larkAppId: entry.larkAppId,
|
|
309
|
+
botName: entry.botName,
|
|
310
|
+
cliId: entry.cliId,
|
|
311
|
+
workingDir: entry.workingDir,
|
|
312
|
+
logPath: entry.logPath,
|
|
313
|
+
startedAt: entry.startedAt,
|
|
314
|
+
updatedAt: now,
|
|
315
|
+
...(status === 'closed' ? { closedAt: now, closeReason: entry.closeReason } : {}),
|
|
316
|
+
};
|
|
317
|
+
mkdirSync(dirname(entry.sidecarPath), { recursive: true });
|
|
318
|
+
writeFileSync(entry.sidecarPath, JSON.stringify(sidecar, null, 2), 'utf-8');
|
|
319
|
+
}
|
|
320
|
+
resumeUrl(webPort, writeToken) {
|
|
321
|
+
return `http://${this.deps.externalHost}:${webPort}?token=${encodeURIComponent(writeToken)}`;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function validateAttemptIds(input) {
|
|
325
|
+
if (!isValidRunId(input.runId))
|
|
326
|
+
return { ok: false, error: 'bad_run_id' };
|
|
327
|
+
if (!isValidPathSegment(input.activityId) || !isValidPathSegment(input.attemptId)) {
|
|
328
|
+
return { ok: false, error: 'bad_attempt_id' };
|
|
329
|
+
}
|
|
330
|
+
return { ok: true };
|
|
331
|
+
}
|
|
332
|
+
function resumeKey(input) {
|
|
333
|
+
return `${input.runId}\n${input.activityId}\n${input.attemptId}`;
|
|
334
|
+
}
|
|
335
|
+
function readTerminalSidecar(runsDir, input) {
|
|
336
|
+
const runDir = join(runsDir, input.runId);
|
|
337
|
+
const sidecarPath = attemptTerminalSidecarPath(runDir, input.activityId, input.attemptId);
|
|
338
|
+
if (!isPathInsideDir(runsDir, sidecarPath))
|
|
339
|
+
return { ok: false, error: 'bad_path' };
|
|
340
|
+
if (!existsSync(sidecarPath))
|
|
341
|
+
return { ok: false, error: 'no_terminal_sidecar' };
|
|
342
|
+
let parsed;
|
|
343
|
+
try {
|
|
344
|
+
parsed = JSON.parse(readFileSync(sidecarPath, 'utf-8'));
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
return { ok: false, error: 'bad_terminal_sidecar' };
|
|
348
|
+
}
|
|
349
|
+
if (!isTerminalSidecar(parsed))
|
|
350
|
+
return { ok: false, error: 'bad_terminal_sidecar' };
|
|
351
|
+
return { ok: true, terminal: parsed };
|
|
352
|
+
}
|
|
353
|
+
function isTerminalSidecar(raw) {
|
|
354
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
355
|
+
return false;
|
|
356
|
+
const r = raw;
|
|
357
|
+
return (r.schemaVersion === ATTEMPT_TERMINAL_SCHEMA_VERSION &&
|
|
358
|
+
typeof r.sessionId === 'string' &&
|
|
359
|
+
typeof r.webPort === 'number' &&
|
|
360
|
+
(r.status === 'live' || r.status === 'closed'));
|
|
361
|
+
}
|
|
362
|
+
export function isResumeCapableCli(cliId) {
|
|
363
|
+
return !!cliId && (RESUME_USES_SESSION_ID.has(cliId) || RESUME_REQUIRES_CLI_SESSION_ID.has(cliId));
|
|
364
|
+
}
|
|
365
|
+
export function cliRequiresNativeSessionId(cliId) {
|
|
366
|
+
return !!cliId && RESUME_REQUIRES_CLI_SESSION_ID.has(cliId);
|
|
367
|
+
}
|
|
368
|
+
function appendResumeLog(logPath, label, content) {
|
|
369
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
370
|
+
const body = content.endsWith('\n') ? content : `${content}\n`;
|
|
371
|
+
appendFileSync(logPath, `[${new Date().toISOString()}] ${label} ${body}`, 'utf-8');
|
|
372
|
+
}
|
|
373
|
+
function expandWorkflowWorkingDir(dir) {
|
|
374
|
+
if (!dir)
|
|
375
|
+
return undefined;
|
|
376
|
+
if (dir === '~')
|
|
377
|
+
return homedir();
|
|
378
|
+
if (dir.startsWith('~/'))
|
|
379
|
+
return join(homedir(), dir.slice(2));
|
|
380
|
+
return dir;
|
|
381
|
+
}
|
|
382
|
+
function defaultWorkerPath() {
|
|
383
|
+
return join(dirname(fileURLToPath(import.meta.url)), '..', 'worker.js');
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=attempt-resume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt-resume.js","sourceRoot":"","sources":["../../src/workflows/attempt-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,GAE3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GAGrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;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AAG,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const ATTEMPT_TERMINAL_SIDECAR = "terminal.json";
|
|
2
|
+
export declare const ATTEMPT_TERMINAL_SCHEMA_VERSION = 1;
|
|
3
|
+
export type AttemptTerminalStatus = 'live' | 'closed';
|
|
4
|
+
export type AttemptTerminalSidecar = {
|
|
5
|
+
schemaVersion: typeof ATTEMPT_TERMINAL_SCHEMA_VERSION;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
/** CLI-native resume id when available (Claude/Codex/etc.). */
|
|
8
|
+
cliSessionId?: string;
|
|
9
|
+
webPort: number;
|
|
10
|
+
status: AttemptTerminalStatus;
|
|
11
|
+
larkAppId?: string;
|
|
12
|
+
botName?: string;
|
|
13
|
+
cliId?: string;
|
|
14
|
+
workingDir?: string;
|
|
15
|
+
logPath?: string;
|
|
16
|
+
startedAt: number;
|
|
17
|
+
updatedAt: number;
|
|
18
|
+
closedAt?: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function attemptTerminalSidecarPath(runDir: string, activityId: string, attemptId: string): string;
|
|
21
|
+
//# sourceMappingURL=attempt-terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt-terminal.d.ts","sourceRoot":"","sources":["../../src/workflows/attempt-terminal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB,kBAAkB,CAAC;AACxD,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEtD,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,OAAO,+BAA+B,CAAC;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,MAAM,CAER"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
export const ATTEMPT_TERMINAL_SIDECAR = 'terminal.json';
|
|
3
|
+
export const ATTEMPT_TERMINAL_SCHEMA_VERSION = 1;
|
|
4
|
+
export function attemptTerminalSidecarPath(runDir, activityId, attemptId) {
|
|
5
|
+
return join(runDir, 'attempts', activityId, attemptId, ATTEMPT_TERMINAL_SIDECAR);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=attempt-terminal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt-terminal.js","sourceRoot":"","sources":["../../src/workflows/attempt-terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC;AACxD,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AAqBjD,MAAM,UAAU,0BAA0B,CACxC,MAAc,EACd,UAAkB,EAClB,SAAiB;IAEjB,OAAO,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,wBAAwB,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-addressed blob writer for OutputRef-shaped fields.
|
|
3
|
+
*
|
|
4
|
+
* Used by run-init (params), runtime (prompts / outputs), and host
|
|
5
|
+
* executors to persist payloads too large for the inline envelope cap.
|
|
6
|
+
* The hash is over canonical bytes — caller is responsible for handing
|
|
7
|
+
* us already-serialized content; we don't second-guess the format.
|
|
8
|
+
*/
|
|
9
|
+
import type { EventLog } from './events/append.js';
|
|
10
|
+
import type { OutputRef } from './events/payloads.js';
|
|
11
|
+
export type WriteBlobOptions = {
|
|
12
|
+
contentType?: string;
|
|
13
|
+
schemaVersion?: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Write a buffer as a content-addressed blob and return the `OutputRef`
|
|
17
|
+
* to embed in event payloads. Idempotent: identical bytes produce the
|
|
18
|
+
* same path; we just overwrite (same content, same result).
|
|
19
|
+
*/
|
|
20
|
+
export declare function writeBlob(log: EventLog, buf: Buffer, opts?: WriteBlobOptions): Promise<OutputRef>;
|
|
21
|
+
/**
|
|
22
|
+
* Canonical-JSON variant: sorts keys recursively so semantically equal
|
|
23
|
+
* inputs hash to identical blob paths. Use this any time the hash will
|
|
24
|
+
* be compared across runs / retries (e.g. idempotency-key derivation).
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeJsonBlob(log: EventLog, value: unknown, opts?: WriteBlobOptions): Promise<OutputRef>;
|
|
27
|
+
//# sourceMappingURL=blob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/workflows/blob.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,SAAS,CAAC,CAWpB;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,SAAS,CAAC,CAGpB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-addressed blob writer for OutputRef-shaped fields.
|
|
3
|
+
*
|
|
4
|
+
* Used by run-init (params), runtime (prompts / outputs), and host
|
|
5
|
+
* executors to persist payloads too large for the inline envelope cap.
|
|
6
|
+
* The hash is over canonical bytes — caller is responsible for handing
|
|
7
|
+
* us already-serialized content; we don't second-guess the format.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
import { promises as fs } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { canonicalJsonStringify } from './definition.js';
|
|
13
|
+
/**
|
|
14
|
+
* Write a buffer as a content-addressed blob and return the `OutputRef`
|
|
15
|
+
* to embed in event payloads. Idempotent: identical bytes produce the
|
|
16
|
+
* same path; we just overwrite (same content, same result).
|
|
17
|
+
*/
|
|
18
|
+
export async function writeBlob(log, buf, opts = {}) {
|
|
19
|
+
const hash = createHash('sha256').update(buf).digest('hex');
|
|
20
|
+
const path = join(log.blobDir, hash);
|
|
21
|
+
await fs.writeFile(path, buf);
|
|
22
|
+
return {
|
|
23
|
+
outputHash: `sha256:${hash}`,
|
|
24
|
+
outputPath: path,
|
|
25
|
+
outputBytes: buf.length,
|
|
26
|
+
outputSchemaVersion: opts.schemaVersion ?? 1,
|
|
27
|
+
contentType: opts.contentType ?? 'application/octet-stream',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Canonical-JSON variant: sorts keys recursively so semantically equal
|
|
32
|
+
* inputs hash to identical blob paths. Use this any time the hash will
|
|
33
|
+
* be compared across runs / retries (e.g. idempotency-key derivation).
|
|
34
|
+
*/
|
|
35
|
+
export async function writeJsonBlob(log, value, opts = {}) {
|
|
36
|
+
const buf = Buffer.from(canonicalJsonStringify(value), 'utf-8');
|
|
37
|
+
return writeBlob(log, buf, { contentType: 'application/json', ...opts });
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=blob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/workflows/blob.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AASzD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAa,EACb,GAAW,EACX,OAAyB,EAAE;IAE3B,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC9B,OAAO;QACL,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,GAAG,CAAC,MAAM;QACvB,mBAAmB,EAAE,IAAI,CAAC,aAAa,IAAI,CAAC;QAC5C,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,0BAA0B;KAC5D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAa,EACb,KAAc,EACd,OAAyB,EAAE;IAE3B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type RunLoopResult } from './loop.js';
|
|
2
|
+
import type { WorkflowRuntimeContext } from './runtime.js';
|
|
3
|
+
import type { WorkflowDefinition } from './definition.js';
|
|
4
|
+
import type { EventLog } from './events/append.js';
|
|
5
|
+
import { type Snapshot } from './events/replay.js';
|
|
6
|
+
import { type RequestCancelActor } from './cancel.js';
|
|
7
|
+
export type CancelWorkflowRunInput = {
|
|
8
|
+
ctx: WorkflowRuntimeContext;
|
|
9
|
+
reason: string;
|
|
10
|
+
by: string;
|
|
11
|
+
actor?: RequestCancelActor;
|
|
12
|
+
maxTicks?: number;
|
|
13
|
+
};
|
|
14
|
+
export type CancelWorkflowRunResult = {
|
|
15
|
+
snapshot: Snapshot;
|
|
16
|
+
loopResult?: RunLoopResult;
|
|
17
|
+
cancelEventId?: string;
|
|
18
|
+
cancelAlreadyRequested: boolean;
|
|
19
|
+
alreadyTerminal: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type CancelWorkflowRunChatScopeResult = {
|
|
22
|
+
ok: true;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
error: 'bad_run_id' | 'unknown_run' | 'wrong_chat';
|
|
26
|
+
status?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* IM cancel is scoped to the chat that created the run. This is a pure
|
|
30
|
+
* guard: callers must run it before writing cancelRequested.
|
|
31
|
+
*/
|
|
32
|
+
export declare function guardWorkflowRunCancelChatScope(runsDir: string, runId: string, expectedChatId: string): Promise<CancelWorkflowRunChatScopeResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Shared run-level cancel operation used by CLI and dashboard/daemon IPC.
|
|
35
|
+
*
|
|
36
|
+
* The operation is idempotent:
|
|
37
|
+
* - terminal runs write zero events;
|
|
38
|
+
* - repeated cancels reuse the existing run-level cancel intent;
|
|
39
|
+
* - parent node/run cancel terminal events are written only once by replay
|
|
40
|
+
* intent markers.
|
|
41
|
+
*/
|
|
42
|
+
export declare function cancelWorkflowRun(input: CancelWorkflowRunInput): Promise<CancelWorkflowRunResult>;
|
|
43
|
+
export declare function finalizeRunCancelIfPossible(log: EventLog, def: WorkflowDefinition, snapshot: Snapshot): Promise<void>;
|
|
44
|
+
export declare function isTerminalRunStatus(status: string): boolean;
|
|
45
|
+
//# sourceMappingURL=cancel-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel-run.d.ts","sourceRoot":"","sources":["../../src/workflows/cancel-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,sBAAsB,GAAG;IACnC,GAAG,EAAE,sBAAsB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAA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