@zonease/happy 0.6.38 → 0.6.39
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/dist/{types-BWpRU1VN.mjs → api-CIZKyfSn.mjs} +136 -1725
- package/dist/{types-DvTsFaqR.cjs → api-CwOCQeLH.cjs} +317 -1961
- package/dist/auth-0VnlXT9f.mjs +181 -0
- package/dist/auth-BE8dD20T.mjs +270 -0
- package/dist/auth-BIleVCw0.cjs +274 -0
- package/dist/auth-Cas9DR3b.cjs +183 -0
- package/dist/browser-Cc08m7of.cjs +22 -0
- package/dist/browser-Dll5hxOV.mjs +20 -0
- package/dist/claudeLocal-CPT3zcIU.mjs +344 -0
- package/dist/claudeLocal-WkgLbl1a.cjs +352 -0
- package/dist/codex/happyMcpStdioBridge.cjs +4 -1
- package/dist/codex/happyMcpStdioBridge.mjs +4 -1
- package/dist/common-BdNgghUJ.mjs +75 -0
- package/dist/common-CZvSRU4p.cjs +83 -0
- package/dist/{config-0Xnc8ARM.cjs → config-Draa-5XC.cjs} +21 -34
- package/dist/{config-_GW4YBCP.mjs → config-rTT4qTU5.mjs} +7 -20
- package/dist/connect-BfC1tYP_.mjs +679 -0
- package/dist/connect-CJZ73syK.cjs +681 -0
- package/dist/{constants-B4x1K7by.cjs → constants-E_UWYTo3.cjs} +2 -2
- package/dist/{constants-BO9OAFOT.mjs → constants-pmXZGibX.mjs} +1 -1
- package/dist/controlClient-CM_QcJnB.mjs +159 -0
- package/dist/controlClient-DZMIsKsT.cjs +168 -0
- package/dist/deviceExec-CU1R9CRb.cjs +84 -0
- package/dist/deviceExec-D93AOVV4.mjs +81 -0
- package/dist/diagnose-B3D1a_v0.cjs +60 -0
- package/dist/diagnose-CuRKXxt1.mjs +58 -0
- package/dist/doctor-C08m5Z9f.cjs +78 -0
- package/dist/doctor-Cya9YSA0.cjs +214 -0
- package/dist/doctor-DZYB6IVc.mjs +211 -0
- package/dist/doctor-ON7pN5G5.mjs +74 -0
- package/dist/downloadImage-DfSFLb-h.mjs +887 -0
- package/dist/downloadImage-MQMrUUxS.cjs +897 -0
- package/dist/enroll-BxlbVftP.cjs +115 -0
- package/dist/enroll-C52x8oly.mjs +113 -0
- package/dist/evidence-Ccd9iYcj.mjs +127 -0
- package/dist/evidence-CjWBG5rX.cjs +129 -0
- package/dist/formatImageMessage-B4lSxlk2.mjs +43 -0
- package/dist/formatImageMessage-DbyG8c2j.cjs +46 -0
- package/dist/github-DKcyF1zp.mjs +57 -0
- package/dist/github-h9GhJJ_C.cjs +59 -0
- package/dist/index-CDTNgfUf.cjs +578 -0
- package/dist/index-CPKdvi7J.mjs +554 -0
- package/dist/index.cjs +812 -40
- package/dist/index.mjs +813 -40
- package/dist/install-BokHRgFW.cjs +98 -0
- package/dist/install-C_cp8b2-.cjs +96 -0
- package/dist/install-DAeCn8ae.mjs +94 -0
- package/dist/install-oRAjVLjP.mjs +95 -0
- package/dist/lib.cjs +18 -12
- package/dist/lib.mjs +13 -7
- package/dist/{loadableToolOutput-va3RLplh.mjs → loadableToolOutput-Cuygmd4K.mjs} +4 -2
- package/dist/{loadableToolOutput-5vdQB98M.cjs → loadableToolOutput-DDCJjywt.cjs} +63 -61
- package/dist/mcpToolSchemas-CjeTfrAs.mjs +62 -0
- package/dist/mcpToolSchemas-DK42yoZ_.cjs +64 -0
- package/dist/persistence-BFjvtUad.mjs +944 -0
- package/dist/persistence-JLUn_Nou.cjs +996 -0
- package/dist/projectPath-BTBIMB57.mjs +10 -0
- package/dist/projectPath-ChLhdOyt.cjs +13 -0
- package/dist/prompt-BTWDZZO0.cjs +25 -0
- package/dist/prompt-BsAZsPbo.mjs +22 -0
- package/dist/release-BMEzNONE.mjs +168 -0
- package/dist/release-EhOJeAZe.cjs +171 -0
- package/dist/run-BDn2aE3Q.cjs +2152 -0
- package/dist/run-DBZqN6Kn.mjs +2128 -0
- package/dist/runClaude-DNHvERX0.mjs +3763 -0
- package/dist/runClaude-uaKxPZPm.cjs +3766 -0
- package/dist/{runCodex-skq0j05d.cjs → runCodex-82UrZLme.cjs} +169 -153
- package/dist/{runCodex-DiKzBf9q.mjs → runCodex-C-RTM0wA.mjs} +36 -20
- package/dist/{runGemini-BeqrVq8R.mjs → runGemini-Bm6-4Xm2.mjs} +34 -17
- package/dist/{runGemini-CVp-CEIh.cjs → runGemini-CXMr4Jwb.cjs} +212 -195
- package/dist/{runOneShot-BQNkNW61.cjs → runOneShot-1B6RMYT7.cjs} +31 -55
- package/dist/{runOneShot-ltCpHbBB.mjs → runOneShot-ioARRHrx.mjs} +14 -38
- package/dist/{serve-BECdtivY.cjs → serve-BtdAhkIE.cjs} +35 -58
- package/dist/{serve-BNdoEDVx.mjs → serve-CwibwU6N.mjs} +12 -35
- package/dist/session-2sU4Bu1R.mjs +108 -0
- package/dist/session-D--F87zL.cjs +110 -0
- package/dist/sessionKeyCache-4Tp8pJ3N.cjs +36 -0
- package/dist/sessionKeyCache-D2BwO91C.mjs +33 -0
- package/dist/sessionList-BCSw3qYt.mjs +51 -0
- package/dist/sessionList-ICJsjNtJ.cjs +54 -0
- package/dist/sessionSummary-Bkz52BPh.cjs +393 -0
- package/dist/sessionSummary-lHGBWQSb.mjs +387 -0
- package/dist/spawnHappyCLI-CoORX0YW.mjs +66 -0
- package/dist/spawnHappyCLI-D_V-AAoP.cjs +70 -0
- package/dist/ssh-BTOlhhxi.cjs +333 -0
- package/dist/ssh-DL_AkRAD.mjs +328 -0
- package/dist/systemdScope-BeOtAkhk.mjs +25 -0
- package/dist/systemdScope-DW3-UoKB.cjs +29 -0
- package/dist/task-CQzrHRZe.mjs +165 -0
- package/dist/task-CSpaC9HX.cjs +167 -0
- package/dist/time-Bj2HRkKH.cjs +33 -0
- package/dist/time-DgsBLJA_.mjs +29 -0
- package/dist/trimIdent-4gvk9Wk6.cjs +22 -0
- package/dist/trimIdent-BAjmv_TG.mjs +20 -0
- package/dist/types-BoJh4Qfv.mjs +57 -0
- package/dist/types-DWeB7aqh.cjs +59 -0
- package/dist/uninstall-BiKyRAb1.cjs +77 -0
- package/dist/uninstall-nFMFGUVM.mjs +75 -0
- package/dist/update-BcqRHXf2.mjs +109 -0
- package/dist/update-Dw8pgsAT.cjs +111 -0
- package/dist/workflowCommon-B0d01Y_a.mjs +56 -0
- package/dist/workflowCommon-Bl568-rt.cjs +62 -0
- package/dist/workflowReports-BEWuQesA.cjs +113 -0
- package/dist/workflowReports-Dd8-4-8f.mjs +108 -0
- package/package.json +1 -1
- package/dist/index-BbCDDvoB.cjs +0 -11376
- package/dist/index-vvZXdswy.mjs +0 -11336
- package/dist/mcpToolSchemas-CdPXJQmb.mjs +0 -175
- package/dist/mcpToolSchemas-f-kttjFw.cjs +0 -186
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
function trimIdent(text) {
|
|
4
|
-
const lines = text.split("\n");
|
|
5
|
-
while (lines.length > 0 && lines[0].trim() === "") {
|
|
6
|
-
lines.shift();
|
|
7
|
-
}
|
|
8
|
-
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
|
9
|
-
lines.pop();
|
|
10
|
-
}
|
|
11
|
-
const minSpaces = lines.reduce((min, line) => {
|
|
12
|
-
if (line.trim() === "") {
|
|
13
|
-
return min;
|
|
14
|
-
}
|
|
15
|
-
const leadingSpaces = line.match(/^\s*/)[0].length;
|
|
16
|
-
return Math.min(min, leadingSpaces);
|
|
17
|
-
}, Infinity);
|
|
18
|
-
const trimmedLines = lines.map((line) => line.slice(minSpaces));
|
|
19
|
-
return trimmedLines.join("\n");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const ORCHESTRATOR_PROVIDERS = ["claude", "codex", "gemini"];
|
|
23
|
-
const ORCHESTRATOR_ENV_KEYS = {
|
|
24
|
-
oneshot: "HAPPY_ORCH_ONESHOT",
|
|
25
|
-
executionId: "HAPPY_ORCH_EXECUTION_ID",
|
|
26
|
-
runId: "HAPPY_ORCH_RUN_ID",
|
|
27
|
-
taskId: "HAPPY_ORCH_TASK_ID",
|
|
28
|
-
executionType: "HAPPY_ORCH_EXECUTION_TYPE",
|
|
29
|
-
childSessionId: "HAPPY_ORCH_CHILD_SESSION_ID",
|
|
30
|
-
modelMode: "HAPPY_ORCH_MODEL_MODE",
|
|
31
|
-
promptB64: "HAPPY_ORCH_PROMPT_B64",
|
|
32
|
-
timeoutMs: "HAPPY_ORCH_TIMEOUT_MS",
|
|
33
|
-
workingDirectory: "HAPPY_ORCH_WORKING_DIRECTORY"
|
|
34
|
-
};
|
|
35
|
-
function isOrchestratorProvider(value) {
|
|
36
|
-
return typeof value === "string" && ORCHESTRATOR_PROVIDERS.includes(value);
|
|
37
|
-
}
|
|
38
|
-
function mapFinishStatus(reason) {
|
|
39
|
-
if (reason.watchdogTriggered) {
|
|
40
|
-
return "timeout";
|
|
41
|
-
}
|
|
42
|
-
if (reason.cancelRequested) {
|
|
43
|
-
return "cancelled";
|
|
44
|
-
}
|
|
45
|
-
if (reason.exitCode === 0) {
|
|
46
|
-
return "completed";
|
|
47
|
-
}
|
|
48
|
-
return "failed";
|
|
49
|
-
}
|
|
50
|
-
function encodePromptToBase64(prompt) {
|
|
51
|
-
return Buffer.from(prompt, "utf8").toString("base64");
|
|
52
|
-
}
|
|
53
|
-
function decodePromptFromBase64(promptB64) {
|
|
54
|
-
return Buffer.from(promptB64, "base64").toString("utf8");
|
|
55
|
-
}
|
|
56
|
-
function buildOrchestratorEnv(payload) {
|
|
57
|
-
const env = {
|
|
58
|
-
[ORCHESTRATOR_ENV_KEYS.oneshot]: "1",
|
|
59
|
-
[ORCHESTRATOR_ENV_KEYS.executionId]: payload.executionId,
|
|
60
|
-
[ORCHESTRATOR_ENV_KEYS.runId]: payload.runId,
|
|
61
|
-
[ORCHESTRATOR_ENV_KEYS.taskId]: payload.taskId,
|
|
62
|
-
[ORCHESTRATOR_ENV_KEYS.executionType]: payload.executionType,
|
|
63
|
-
[ORCHESTRATOR_ENV_KEYS.promptB64]: encodePromptToBase64(payload.prompt),
|
|
64
|
-
[ORCHESTRATOR_ENV_KEYS.timeoutMs]: String(payload.timeoutMs)
|
|
65
|
-
};
|
|
66
|
-
if (payload.childSessionId) {
|
|
67
|
-
env[ORCHESTRATOR_ENV_KEYS.childSessionId] = payload.childSessionId;
|
|
68
|
-
}
|
|
69
|
-
if (payload.workingDirectory) {
|
|
70
|
-
env[ORCHESTRATOR_ENV_KEYS.workingDirectory] = payload.workingDirectory;
|
|
71
|
-
}
|
|
72
|
-
if (payload.model) {
|
|
73
|
-
env[ORCHESTRATOR_ENV_KEYS.modelMode] = payload.model;
|
|
74
|
-
}
|
|
75
|
-
return env;
|
|
76
|
-
}
|
|
77
|
-
function appendOutputChunk(current, chunk, maxChars) {
|
|
78
|
-
const combined = `${current}${chunk}`;
|
|
79
|
-
if (combined.length <= maxChars) {
|
|
80
|
-
return combined;
|
|
81
|
-
}
|
|
82
|
-
return combined.slice(combined.length - maxChars);
|
|
83
|
-
}
|
|
84
|
-
function buildOutputSummary(stdout, stderr, maxChars = 400) {
|
|
85
|
-
const source = stdout.trim() ? stdout : stderr;
|
|
86
|
-
if (!source.trim()) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
const lastLine = source.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0).at(-1) ?? source.trim();
|
|
90
|
-
if (lastLine.length <= maxChars) {
|
|
91
|
-
return lastLine;
|
|
92
|
-
}
|
|
93
|
-
return `${lastLine.slice(0, maxChars - 3)}...`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const CHAT_TITLE_INSTRUCTION = trimIdent(`
|
|
97
|
-
# Chat title
|
|
98
|
-
|
|
99
|
-
On your first response, call "change_title" to set a descriptive title based on the user's message. Update the title whenever the conversation's main focus shifts to a different topic or task.
|
|
100
|
-
`);
|
|
101
|
-
function isOrchestratorWorkerSession(env = process.env) {
|
|
102
|
-
return env[ORCHESTRATOR_ENV_KEYS.oneshot] === "1" || !!env[ORCHESTRATOR_ENV_KEYS.executionId];
|
|
103
|
-
}
|
|
104
|
-
function shouldEnableOrchestratorTools() {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
function getBaseSystemPrompt(env = process.env) {
|
|
108
|
-
if (isOrchestratorWorkerSession(env)) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
return CHAT_TITLE_INSTRUCTION;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const orchestratorTargetTypeSchema = z.preprocess(
|
|
115
|
-
(value) => value === "machine" ? "machine_id" : value,
|
|
116
|
-
z.enum(["current_machine", "machine_id"])
|
|
117
|
-
).describe('Dispatch target type. Use "current_machine" for this machine, or "machine_id" for explicit machine routing. Alias "machine" is accepted and normalized to "machine_id".');
|
|
118
|
-
const orchestratorTaskSchema = z.object({
|
|
119
|
-
taskKey: z.string().min(1).max(128).optional(),
|
|
120
|
-
title: z.string().min(1).max(256).optional(),
|
|
121
|
-
provider: z.enum(["claude", "codex", "gemini"]).describe("AI agent provider to execute the task."),
|
|
122
|
-
model: z.string().min(1).max(128).optional().describe('Optional model mode for the selected provider. Prefer values from orchestrator_get_context.data.modelModes[provider]. Use "default" to follow CLI defaults.'),
|
|
123
|
-
prompt: z.string().min(1).max(65536),
|
|
124
|
-
workingDirectory: z.string().max(512).optional().describe("Absolute path for task execution. Defaults to the controller session working directory from get_context."),
|
|
125
|
-
dependsOn: z.array(z.string().min(1).max(128)).max(31).optional().describe("Optional list of prerequisite taskKeys (use taskKey, not taskId). This controls execution order only: the task starts after all listed tasks complete, but receives NONE of their output or context."),
|
|
126
|
-
retry: z.object({
|
|
127
|
-
maxAttempts: z.number().int().min(1).max(10).optional().describe("Maximum attempts for this task (including first run)."),
|
|
128
|
-
backoffMs: z.number().int().min(0).max(24 * 60 * 60 * 1e3).optional().describe("Retry backoff delay in milliseconds before the next attempt.")
|
|
129
|
-
}).optional(),
|
|
130
|
-
target: z.object({
|
|
131
|
-
type: orchestratorTargetTypeSchema,
|
|
132
|
-
machineId: z.string().optional().describe('Required when target.type is "machine_id" (or alias "machine").')
|
|
133
|
-
}).optional().describe("Optional dispatch routing target."),
|
|
134
|
-
metadata: z.record(z.string(), z.string()).optional()
|
|
135
|
-
});
|
|
136
|
-
({
|
|
137
|
-
inputSchema: {
|
|
138
|
-
title: z.string().min(1).max(256).describe("Run title"),
|
|
139
|
-
tasks: z.array(orchestratorTaskSchema).min(1).max(32),
|
|
140
|
-
maxConcurrency: z.number().int().min(1).max(8).optional(),
|
|
141
|
-
idempotencyKey: z.string().min(1).max(128).optional(),
|
|
142
|
-
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
143
|
-
controllerSessionId: z.string().optional().describe("Optional controller session ID. Defaults to current MCP session when omitted.")
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
({
|
|
147
|
-
inputSchema: {
|
|
148
|
-
runId: z.string().describe("Run ID"),
|
|
149
|
-
cursor: z.string().optional(),
|
|
150
|
-
waitFor: z.enum(["change", "terminal"]).optional(),
|
|
151
|
-
timeoutMs: z.number().int().min(0).max(36e5).optional().describe("Total wait timeout in ms. Defaults to 10 minutes when omitted."),
|
|
152
|
-
include: z.enum(["summary", "all_tasks"]).optional().describe('"summary" returns run-level status only; "all_tasks" includes per-task details.')
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
({
|
|
156
|
-
inputSchema: {
|
|
157
|
-
status: z.enum(["active", "terminal", "queued", "running", "canceling", "completed", "failed", "cancelled"]).optional().describe('Filter by status. "active" = queued|running|canceling; "terminal" = completed|failed|cancelled.'),
|
|
158
|
-
limit: z.number().int().min(1).max(50).optional(),
|
|
159
|
-
cursor: z.string().optional()
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
({
|
|
163
|
-
inputSchema: {
|
|
164
|
-
runId: z.string().describe("Run ID"),
|
|
165
|
-
reason: z.string().max(512).optional()
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
({
|
|
169
|
-
inputSchema: {
|
|
170
|
-
taskId: z.string().describe("Task ID to resume"),
|
|
171
|
-
message: z.string().min(1).max(65536).describe("Message to send to the existing child session")
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
export { ORCHESTRATOR_ENV_KEYS as O, buildOrchestratorEnv as a, buildOutputSummary as b, appendOutputChunk as c, decodePromptFromBase64 as d, getBaseSystemPrompt as g, isOrchestratorProvider as i, mapFinishStatus as m, shouldEnableOrchestratorTools as s, trimIdent as t };
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var z = require('zod');
|
|
4
|
-
|
|
5
|
-
function trimIdent(text) {
|
|
6
|
-
const lines = text.split("\n");
|
|
7
|
-
while (lines.length > 0 && lines[0].trim() === "") {
|
|
8
|
-
lines.shift();
|
|
9
|
-
}
|
|
10
|
-
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
|
11
|
-
lines.pop();
|
|
12
|
-
}
|
|
13
|
-
const minSpaces = lines.reduce((min, line) => {
|
|
14
|
-
if (line.trim() === "") {
|
|
15
|
-
return min;
|
|
16
|
-
}
|
|
17
|
-
const leadingSpaces = line.match(/^\s*/)[0].length;
|
|
18
|
-
return Math.min(min, leadingSpaces);
|
|
19
|
-
}, Infinity);
|
|
20
|
-
const trimmedLines = lines.map((line) => line.slice(minSpaces));
|
|
21
|
-
return trimmedLines.join("\n");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const ORCHESTRATOR_PROVIDERS = ["claude", "codex", "gemini"];
|
|
25
|
-
const ORCHESTRATOR_ENV_KEYS = {
|
|
26
|
-
oneshot: "HAPPY_ORCH_ONESHOT",
|
|
27
|
-
executionId: "HAPPY_ORCH_EXECUTION_ID",
|
|
28
|
-
runId: "HAPPY_ORCH_RUN_ID",
|
|
29
|
-
taskId: "HAPPY_ORCH_TASK_ID",
|
|
30
|
-
executionType: "HAPPY_ORCH_EXECUTION_TYPE",
|
|
31
|
-
childSessionId: "HAPPY_ORCH_CHILD_SESSION_ID",
|
|
32
|
-
modelMode: "HAPPY_ORCH_MODEL_MODE",
|
|
33
|
-
promptB64: "HAPPY_ORCH_PROMPT_B64",
|
|
34
|
-
timeoutMs: "HAPPY_ORCH_TIMEOUT_MS",
|
|
35
|
-
workingDirectory: "HAPPY_ORCH_WORKING_DIRECTORY"
|
|
36
|
-
};
|
|
37
|
-
function isOrchestratorProvider(value) {
|
|
38
|
-
return typeof value === "string" && ORCHESTRATOR_PROVIDERS.includes(value);
|
|
39
|
-
}
|
|
40
|
-
function mapFinishStatus(reason) {
|
|
41
|
-
if (reason.watchdogTriggered) {
|
|
42
|
-
return "timeout";
|
|
43
|
-
}
|
|
44
|
-
if (reason.cancelRequested) {
|
|
45
|
-
return "cancelled";
|
|
46
|
-
}
|
|
47
|
-
if (reason.exitCode === 0) {
|
|
48
|
-
return "completed";
|
|
49
|
-
}
|
|
50
|
-
return "failed";
|
|
51
|
-
}
|
|
52
|
-
function encodePromptToBase64(prompt) {
|
|
53
|
-
return Buffer.from(prompt, "utf8").toString("base64");
|
|
54
|
-
}
|
|
55
|
-
function decodePromptFromBase64(promptB64) {
|
|
56
|
-
return Buffer.from(promptB64, "base64").toString("utf8");
|
|
57
|
-
}
|
|
58
|
-
function buildOrchestratorEnv(payload) {
|
|
59
|
-
const env = {
|
|
60
|
-
[ORCHESTRATOR_ENV_KEYS.oneshot]: "1",
|
|
61
|
-
[ORCHESTRATOR_ENV_KEYS.executionId]: payload.executionId,
|
|
62
|
-
[ORCHESTRATOR_ENV_KEYS.runId]: payload.runId,
|
|
63
|
-
[ORCHESTRATOR_ENV_KEYS.taskId]: payload.taskId,
|
|
64
|
-
[ORCHESTRATOR_ENV_KEYS.executionType]: payload.executionType,
|
|
65
|
-
[ORCHESTRATOR_ENV_KEYS.promptB64]: encodePromptToBase64(payload.prompt),
|
|
66
|
-
[ORCHESTRATOR_ENV_KEYS.timeoutMs]: String(payload.timeoutMs)
|
|
67
|
-
};
|
|
68
|
-
if (payload.childSessionId) {
|
|
69
|
-
env[ORCHESTRATOR_ENV_KEYS.childSessionId] = payload.childSessionId;
|
|
70
|
-
}
|
|
71
|
-
if (payload.workingDirectory) {
|
|
72
|
-
env[ORCHESTRATOR_ENV_KEYS.workingDirectory] = payload.workingDirectory;
|
|
73
|
-
}
|
|
74
|
-
if (payload.model) {
|
|
75
|
-
env[ORCHESTRATOR_ENV_KEYS.modelMode] = payload.model;
|
|
76
|
-
}
|
|
77
|
-
return env;
|
|
78
|
-
}
|
|
79
|
-
function appendOutputChunk(current, chunk, maxChars) {
|
|
80
|
-
const combined = `${current}${chunk}`;
|
|
81
|
-
if (combined.length <= maxChars) {
|
|
82
|
-
return combined;
|
|
83
|
-
}
|
|
84
|
-
return combined.slice(combined.length - maxChars);
|
|
85
|
-
}
|
|
86
|
-
function buildOutputSummary(stdout, stderr, maxChars = 400) {
|
|
87
|
-
const source = stdout.trim() ? stdout : stderr;
|
|
88
|
-
if (!source.trim()) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
const lastLine = source.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0).at(-1) ?? source.trim();
|
|
92
|
-
if (lastLine.length <= maxChars) {
|
|
93
|
-
return lastLine;
|
|
94
|
-
}
|
|
95
|
-
return `${lastLine.slice(0, maxChars - 3)}...`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const CHAT_TITLE_INSTRUCTION = trimIdent(`
|
|
99
|
-
# Chat title
|
|
100
|
-
|
|
101
|
-
On your first response, call "change_title" to set a descriptive title based on the user's message. Update the title whenever the conversation's main focus shifts to a different topic or task.
|
|
102
|
-
`);
|
|
103
|
-
function isOrchestratorWorkerSession(env = process.env) {
|
|
104
|
-
return env[ORCHESTRATOR_ENV_KEYS.oneshot] === "1" || !!env[ORCHESTRATOR_ENV_KEYS.executionId];
|
|
105
|
-
}
|
|
106
|
-
function shouldEnableOrchestratorTools() {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
function getBaseSystemPrompt(env = process.env) {
|
|
110
|
-
if (isOrchestratorWorkerSession(env)) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
return CHAT_TITLE_INSTRUCTION;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const orchestratorTargetTypeSchema = z.z.preprocess(
|
|
117
|
-
(value) => value === "machine" ? "machine_id" : value,
|
|
118
|
-
z.z.enum(["current_machine", "machine_id"])
|
|
119
|
-
).describe('Dispatch target type. Use "current_machine" for this machine, or "machine_id" for explicit machine routing. Alias "machine" is accepted and normalized to "machine_id".');
|
|
120
|
-
const orchestratorTaskSchema = z.z.object({
|
|
121
|
-
taskKey: z.z.string().min(1).max(128).optional(),
|
|
122
|
-
title: z.z.string().min(1).max(256).optional(),
|
|
123
|
-
provider: z.z.enum(["claude", "codex", "gemini"]).describe("AI agent provider to execute the task."),
|
|
124
|
-
model: z.z.string().min(1).max(128).optional().describe('Optional model mode for the selected provider. Prefer values from orchestrator_get_context.data.modelModes[provider]. Use "default" to follow CLI defaults.'),
|
|
125
|
-
prompt: z.z.string().min(1).max(65536),
|
|
126
|
-
workingDirectory: z.z.string().max(512).optional().describe("Absolute path for task execution. Defaults to the controller session working directory from get_context."),
|
|
127
|
-
dependsOn: z.z.array(z.z.string().min(1).max(128)).max(31).optional().describe("Optional list of prerequisite taskKeys (use taskKey, not taskId). This controls execution order only: the task starts after all listed tasks complete, but receives NONE of their output or context."),
|
|
128
|
-
retry: z.z.object({
|
|
129
|
-
maxAttempts: z.z.number().int().min(1).max(10).optional().describe("Maximum attempts for this task (including first run)."),
|
|
130
|
-
backoffMs: z.z.number().int().min(0).max(24 * 60 * 60 * 1e3).optional().describe("Retry backoff delay in milliseconds before the next attempt.")
|
|
131
|
-
}).optional(),
|
|
132
|
-
target: z.z.object({
|
|
133
|
-
type: orchestratorTargetTypeSchema,
|
|
134
|
-
machineId: z.z.string().optional().describe('Required when target.type is "machine_id" (or alias "machine").')
|
|
135
|
-
}).optional().describe("Optional dispatch routing target."),
|
|
136
|
-
metadata: z.z.record(z.z.string(), z.z.string()).optional()
|
|
137
|
-
});
|
|
138
|
-
({
|
|
139
|
-
inputSchema: {
|
|
140
|
-
title: z.z.string().min(1).max(256).describe("Run title"),
|
|
141
|
-
tasks: z.z.array(orchestratorTaskSchema).min(1).max(32),
|
|
142
|
-
maxConcurrency: z.z.number().int().min(1).max(8).optional(),
|
|
143
|
-
idempotencyKey: z.z.string().min(1).max(128).optional(),
|
|
144
|
-
metadata: z.z.record(z.z.string(), z.z.unknown()).optional(),
|
|
145
|
-
controllerSessionId: z.z.string().optional().describe("Optional controller session ID. Defaults to current MCP session when omitted.")
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
({
|
|
149
|
-
inputSchema: {
|
|
150
|
-
runId: z.z.string().describe("Run ID"),
|
|
151
|
-
cursor: z.z.string().optional(),
|
|
152
|
-
waitFor: z.z.enum(["change", "terminal"]).optional(),
|
|
153
|
-
timeoutMs: z.z.number().int().min(0).max(36e5).optional().describe("Total wait timeout in ms. Defaults to 10 minutes when omitted."),
|
|
154
|
-
include: z.z.enum(["summary", "all_tasks"]).optional().describe('"summary" returns run-level status only; "all_tasks" includes per-task details.')
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
({
|
|
158
|
-
inputSchema: {
|
|
159
|
-
status: z.z.enum(["active", "terminal", "queued", "running", "canceling", "completed", "failed", "cancelled"]).optional().describe('Filter by status. "active" = queued|running|canceling; "terminal" = completed|failed|cancelled.'),
|
|
160
|
-
limit: z.z.number().int().min(1).max(50).optional(),
|
|
161
|
-
cursor: z.z.string().optional()
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
({
|
|
165
|
-
inputSchema: {
|
|
166
|
-
runId: z.z.string().describe("Run ID"),
|
|
167
|
-
reason: z.z.string().max(512).optional()
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
({
|
|
171
|
-
inputSchema: {
|
|
172
|
-
taskId: z.z.string().describe("Task ID to resume"),
|
|
173
|
-
message: z.z.string().min(1).max(65536).describe("Message to send to the existing child session")
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
exports.ORCHESTRATOR_ENV_KEYS = ORCHESTRATOR_ENV_KEYS;
|
|
178
|
-
exports.appendOutputChunk = appendOutputChunk;
|
|
179
|
-
exports.buildOrchestratorEnv = buildOrchestratorEnv;
|
|
180
|
-
exports.buildOutputSummary = buildOutputSummary;
|
|
181
|
-
exports.decodePromptFromBase64 = decodePromptFromBase64;
|
|
182
|
-
exports.getBaseSystemPrompt = getBaseSystemPrompt;
|
|
183
|
-
exports.isOrchestratorProvider = isOrchestratorProvider;
|
|
184
|
-
exports.mapFinishStatus = mapFinishStatus;
|
|
185
|
-
exports.shouldEnableOrchestratorTools = shouldEnableOrchestratorTools;
|
|
186
|
-
exports.trimIdent = trimIdent;
|