@moxxy/plugin-provider-claude-code 0.44.0 → 0.46.0
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/account-limit.d.ts +8 -0
- package/dist/account-limit.d.ts.map +1 -0
- package/dist/account-limit.js +23 -0
- package/dist/account-limit.js.map +1 -0
- package/dist/agent-provider.d.ts +61 -0
- package/dist/agent-provider.d.ts.map +1 -0
- package/dist/agent-provider.js +195 -0
- package/dist/agent-provider.js.map +1 -0
- package/dist/agent-session.d.ts +145 -0
- package/dist/agent-session.d.ts.map +1 -0
- package/dist/agent-session.js +703 -0
- package/dist/agent-session.js.map +1 -0
- package/dist/background-work.d.ts +42 -0
- package/dist/background-work.d.ts.map +1 -0
- package/dist/background-work.js +140 -0
- package/dist/background-work.js.map +1 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -2
- package/dist/constants.js.map +1 -1
- package/dist/executable.d.ts +15 -0
- package/dist/executable.d.ts.map +1 -0
- package/dist/executable.js +30 -0
- package/dist/executable.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -16
- package/dist/index.js.map +1 -1
- package/dist/login.d.ts +3 -0
- package/dist/login.d.ts.map +1 -1
- package/dist/login.js +8 -1
- package/dist/login.js.map +1 -1
- package/dist/offered-models.d.ts +13 -0
- package/dist/offered-models.d.ts.map +1 -0
- package/dist/offered-models.js +48 -0
- package/dist/offered-models.js.map +1 -0
- package/dist/own-settings.d.ts +12 -0
- package/dist/own-settings.d.ts.map +1 -0
- package/dist/own-settings.js +31 -0
- package/dist/own-settings.js.map +1 -0
- package/dist/questions.d.ts +6 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +38 -0
- package/dist/questions.js.map +1 -0
- package/dist/scheduled-wakeups.d.ts +10 -0
- package/dist/scheduled-wakeups.d.ts.map +1 -0
- package/dist/scheduled-wakeups.js +30 -0
- package/dist/scheduled-wakeups.js.map +1 -0
- package/dist/sdk-install.d.ts +25 -0
- package/dist/sdk-install.d.ts.map +1 -0
- package/dist/sdk-install.js +94 -0
- package/dist/sdk-install.js.map +1 -0
- package/dist/sdk-types.d.ts +312 -0
- package/dist/sdk-types.d.ts.map +1 -0
- package/dist/sdk-types.js +8 -0
- package/dist/sdk-types.js.map +1 -0
- package/dist/subagents.d.ts +39 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +114 -0
- package/dist/subagents.js.map +1 -0
- package/dist/task-list.d.ts +21 -0
- package/dist/task-list.d.ts.map +1 -0
- package/dist/task-list.js +68 -0
- package/dist/task-list.js.map +1 -0
- package/dist/translate.d.ts +66 -0
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +302 -0
- package/dist/translate.js.map +1 -0
- package/package.json +14 -9
- package/src/account-limit.ts +26 -0
- package/src/agent-cli.test.ts +83 -0
- package/src/agent-provider.test.ts +1176 -0
- package/src/agent-provider.ts +223 -0
- package/src/agent-session.ts +793 -0
- package/src/background-work.ts +163 -0
- package/src/constants.ts +2 -3
- package/src/event-coverage.test.ts +106 -0
- package/src/executable.test.ts +60 -0
- package/src/executable.ts +34 -0
- package/src/fake-claude.testkit.ts +376 -0
- package/src/fixtures/claude-agent-sdk-0.3.296.json +43 -0
- package/src/fixtures/claude-supported-models-0.3.296.json +218 -0
- package/src/index.test.ts +49 -0
- package/src/index.ts +61 -18
- package/src/login.ts +10 -1
- package/src/offered-models.test.ts +81 -0
- package/src/offered-models.ts +60 -0
- package/src/own-settings.test.ts +68 -0
- package/src/own-settings.ts +33 -0
- package/src/questions.test.ts +68 -0
- package/src/questions.ts +45 -0
- package/src/scheduled-wakeups.test.ts +41 -0
- package/src/scheduled-wakeups.ts +34 -0
- package/src/sdk-install.test.ts +124 -0
- package/src/sdk-install.ts +107 -0
- package/src/sdk-types.ts +278 -0
- package/src/subagents.ts +123 -0
- package/src/task-list.ts +65 -0
- package/src/translate.test.ts +474 -0
- package/src/translate.ts +306 -0
- package/dist/process.d.ts +0 -34
- package/dist/process.d.ts.map +0 -1
- package/dist/process.js +0 -197
- package/dist/process.js.map +0 -1
- package/dist/protocol.d.ts +0 -30
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js +0 -368
- package/dist/protocol.js.map +0 -1
- package/dist/provider.d.ts +0 -53
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -229
- package/dist/provider.js.map +0 -1
- package/src/process.test.ts +0 -208
- package/src/process.ts +0 -224
- package/src/protocol.ts +0 -390
- package/src/provider.test.ts +0 -671
- package/src/provider.ts +0 -267
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { Inbox, agentModeFor, earlierConversationNote, idleToolsHandler, moxxyToolsHandler, resumeAgentSession, sameToolNames, skillsForAgent, startMoxxyMcpServer, untilStopped, withoutOwnMcpServers, } from '@moxxy/agent-connection-kit';
|
|
4
|
+
import { isContextWindowSize } from '@moxxy/sdk';
|
|
5
|
+
import { fromClaudeQuestions, toClaudeAnswers } from './questions.js';
|
|
6
|
+
import { MOXXY_MCP_SERVER, MOXXY_TOOL_PREFIX, TurnTranslator, goalStatusFrom, isModeChange, toClaudeContent, toTokenUsage, } from './translate.js';
|
|
7
|
+
import { ClaudeBackgroundWork } from './background-work.js';
|
|
8
|
+
import { ClaudeSubagents } from './subagents.js';
|
|
9
|
+
import { ClaudeTaskList } from './task-list.js';
|
|
10
|
+
import { dueWakeup, wakeupsOf } from './scheduled-wakeups.js';
|
|
11
|
+
/**
|
|
12
|
+
* Moxxy tools Claude Code already has its own of, so they are not lent over
|
|
13
|
+
* MCP: its file and shell tools, web, background jobs, questions, skills,
|
|
14
|
+
* memory, its own plan (ExitPlanMode) and goal (`/goal`). `recall` is lent:
|
|
15
|
+
* it searches Moxxy's record of the whole conversation, which outlives
|
|
16
|
+
* Claude's own session. The person's Moxxy skills come as a `load_skill` of
|
|
17
|
+
* their own, listing them (see agent-skills).
|
|
18
|
+
*/
|
|
19
|
+
const CLAUDE_HAS_ITS_OWN = new Set([
|
|
20
|
+
'Read', 'Edit', 'Write', 'Bash', 'Grep', 'Glob', 'Sleep', 'Wait', 'StopJob',
|
|
21
|
+
'web_search', 'web_fetch', 'ask_user', 'session_recall',
|
|
22
|
+
'load_skill', 'reload_skills', 'synthesize_skill', 'load_tool',
|
|
23
|
+
'plan_complete', 'goal_complete', 'goal_abandon',
|
|
24
|
+
]);
|
|
25
|
+
const toolNames = (tools) => tools.map((tool) => tool.name);
|
|
26
|
+
/**
|
|
27
|
+
* Moxxy's tools reach Claude as a catalog of three small tools. Claude lists
|
|
28
|
+
* every deferred tool by name in each request (hundreds once the person's MCP
|
|
29
|
+
* servers are set up); behind the catalog it reads the groups and looks a tool
|
|
30
|
+
* up when it wants one.
|
|
31
|
+
*/
|
|
32
|
+
const LENT_AS = { catalog: true };
|
|
33
|
+
export function toolsLentToClaude(tools) {
|
|
34
|
+
return tools.filter((tool) => !CLAUDE_HAS_ITS_OWN.has(tool.name) && !tool.name.startsWith('memory_'));
|
|
35
|
+
}
|
|
36
|
+
/** Modes in which Claude acts without asking the person: `auto` lets its own classifier decide. */
|
|
37
|
+
export function runsWithoutAsking(mode) {
|
|
38
|
+
return mode === 'bypassPermissions' || mode === 'auto';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The permission mode a new Claude starts in; `undefined` keeps the mode from
|
|
42
|
+
* the person's Claude settings. `ownMode` is that mode when the conversation
|
|
43
|
+
* recorded auto-approve off: one that acts without asking is set to ask, so the
|
|
44
|
+
* person's switch wins over their own default.
|
|
45
|
+
*/
|
|
46
|
+
export function startingPermissionMode(mode, autoApprove, ownMode) {
|
|
47
|
+
if (mode === 'plan')
|
|
48
|
+
return 'plan';
|
|
49
|
+
if (mode === 'goal' || autoApprove)
|
|
50
|
+
return 'bypassPermissions';
|
|
51
|
+
return runsWithoutAsking(ownMode) ? 'default' : undefined;
|
|
52
|
+
}
|
|
53
|
+
const NOT_IN_A_TURN = 'Nobody is in the Moxxy conversation right now to answer this.';
|
|
54
|
+
const NO_RULES_YET = 'Moxxy could not check this call against its rules: no turn has run in this conversation yet.';
|
|
55
|
+
/** Moxxy's record of the conversation goes first, on its own (and `/goal` must start the person's message). */
|
|
56
|
+
const READ_ONLY_REPLY = 'Reply with OK only: the person\'s message follows next.';
|
|
57
|
+
class SessionGone extends Error {
|
|
58
|
+
}
|
|
59
|
+
const MAX_STDERR = 2048;
|
|
60
|
+
/** Where Claude's plan mode keeps the plan it writes: `~/.claude/plans/<name>.md`. */
|
|
61
|
+
const PLAN_FILE = /[\\/]\.claude[\\/]plans[\\/][^\\/]+\.md$/;
|
|
62
|
+
/** The plan file a Write or Edit of Claude's touches, if it is one. */
|
|
63
|
+
export function claudePlanFileOf(name, input) {
|
|
64
|
+
if (name !== 'Write' && name !== 'Edit' && name !== 'MultiEdit')
|
|
65
|
+
return undefined;
|
|
66
|
+
const path = typeof input === 'object' && input !== null ? input.file_path : undefined;
|
|
67
|
+
return typeof path === 'string' && PLAN_FILE.test(path) ? path : undefined;
|
|
68
|
+
}
|
|
69
|
+
/** Claude's answer for a plan the person now decides on in Moxxy: no "approved", no second copy of it. */
|
|
70
|
+
const PLAN_HANDED_OVER = 'The plan is now with the person in Moxxy, who will implement it, have it rewritten or dismiss it there. ' +
|
|
71
|
+
'Stay in plan mode and end your turn now without repeating the plan.';
|
|
72
|
+
/**
|
|
73
|
+
* One running Claude Code (one Agent SDK `query()`) for one Moxxy
|
|
74
|
+
* conversation. Every message the person sends is the next user message of
|
|
75
|
+
* the same query, so Claude keeps its context, tools and goal between turns.
|
|
76
|
+
* Everything Claude asks of Moxxy (approvals, the PreToolUse rule check,
|
|
77
|
+
* Moxxy tools over MCP) is queued with its messages and handled in order, so
|
|
78
|
+
* the log shows a call before the decision about it.
|
|
79
|
+
*/
|
|
80
|
+
export class ClaudeAgentSession {
|
|
81
|
+
settings;
|
|
82
|
+
mcp;
|
|
83
|
+
newSession;
|
|
84
|
+
input = new Inbox();
|
|
85
|
+
inbox = new Inbox();
|
|
86
|
+
query;
|
|
87
|
+
alive = true;
|
|
88
|
+
closed = false;
|
|
89
|
+
inTurn = false;
|
|
90
|
+
/** This turn handed Claude's plan to the plan card through ExitPlanMode. */
|
|
91
|
+
planHandedOver = false;
|
|
92
|
+
/** A turn ended before Claude's `result` (its reader stopped early); the next turn waits it out. */
|
|
93
|
+
owesResult = false;
|
|
94
|
+
/** Claude took up a turn by itself and no Moxxy turn has read it yet. */
|
|
95
|
+
agentTurnPending = false;
|
|
96
|
+
/** When Claude set itself to come back, as its last `Stop` said. */
|
|
97
|
+
wakeups = [];
|
|
98
|
+
/** Claude's tasks by id, named as they started, to say which one finished. */
|
|
99
|
+
taskNames = new Map();
|
|
100
|
+
/** The task whose end Claude takes up next, once it finished in the background. */
|
|
101
|
+
finishedTask;
|
|
102
|
+
/** That task as Moxxy's background work (`AgentBackgroundWork.id`). */
|
|
103
|
+
finishedWork;
|
|
104
|
+
/** What Claude runs in the background, as its list says. */
|
|
105
|
+
background = new ClaudeBackgroundWork();
|
|
106
|
+
/** The last turn's host: Moxxy's rules for a call made while no turn runs (a helper in the background). */
|
|
107
|
+
lastHost;
|
|
108
|
+
permissionMode;
|
|
109
|
+
/** Claude's task list, which its tools change one task at a time across turns. */
|
|
110
|
+
tasks = new ClaudeTaskList();
|
|
111
|
+
/** Claude's subagents; one in the background ends after the turn that started it. */
|
|
112
|
+
subagents = new ClaudeSubagents();
|
|
113
|
+
/** Reads a background helper's messages while no turn runs; the next turn reads them again and shows nothing twice. */
|
|
114
|
+
between;
|
|
115
|
+
/** The conversation's auto-approve as this turn knows it: as it began, then as Claude's mode changed it. */
|
|
116
|
+
switchedOn = false;
|
|
117
|
+
model;
|
|
118
|
+
goalActive = false;
|
|
119
|
+
stderr = '';
|
|
120
|
+
/** The Moxxy tools Claude is shown: every one of the conversation, the same in every mode. */
|
|
121
|
+
listed;
|
|
122
|
+
/** The Moxxy skills Claude is offered. */
|
|
123
|
+
offered;
|
|
124
|
+
static async start(settings) {
|
|
125
|
+
const checked = await withoutLostSession(settings);
|
|
126
|
+
const mcp = await startMoxxyMcpServer({ name: 'moxxy' });
|
|
127
|
+
try {
|
|
128
|
+
return new ClaudeAgentSession(checked.settings, mcp, checked.newSession);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
await mcp.close();
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
constructor(settings, mcp,
|
|
136
|
+
/** Claude's session is new while the conversation may already have run: its first message carries the conversation so far. */
|
|
137
|
+
newSession) {
|
|
138
|
+
this.settings = settings;
|
|
139
|
+
this.mcp = mcp;
|
|
140
|
+
this.newSession = newSession;
|
|
141
|
+
this.model = settings.model;
|
|
142
|
+
this.permissionMode = settings.permissionMode;
|
|
143
|
+
this.between = new TurnTranslator(settings.cwd, this.tasks, this.subagents);
|
|
144
|
+
// Claude reads Moxxy's tools as it starts: they are listed before it does.
|
|
145
|
+
this.listed = toolsLentToClaude(settings.tools ?? []);
|
|
146
|
+
this.offered = skillsForAgent(settings.skills ?? [], toolNames(this.listed), []);
|
|
147
|
+
mcp.setHandler(idleToolsHandler(this.listed, this.offered, LENT_AS));
|
|
148
|
+
this.query = settings.sdk.query({
|
|
149
|
+
prompt: this.userMessages(),
|
|
150
|
+
options: {
|
|
151
|
+
cwd: settings.cwd,
|
|
152
|
+
model: settings.model,
|
|
153
|
+
...(settings.effort ? { effort: settings.effort } : {}),
|
|
154
|
+
systemPrompt: { type: 'preset', preset: 'claude_code' },
|
|
155
|
+
...(settings.executable ? { pathToClaudeCodeExecutable: settings.executable } : {}),
|
|
156
|
+
...(settings.permissionMode ? { permissionMode: settings.permissionMode } : {}),
|
|
157
|
+
// Lets Moxxy's auto-approve switch Claude to bypassPermissions mid-session.
|
|
158
|
+
allowDangerouslySkipPermissions: true,
|
|
159
|
+
includePartialMessages: true,
|
|
160
|
+
...(settings.resume ? { resume: settings.resume } : {}),
|
|
161
|
+
mcpServers: { [MOXXY_MCP_SERVER]: { type: 'http', url: mcp.url, headers: { Authorization: mcp.authorization } } },
|
|
162
|
+
canUseTool: (name, input, options) => this.onCanUseTool(name, input, options),
|
|
163
|
+
hooks: {
|
|
164
|
+
PreToolUse: [{ hooks: [async (input) => this.onPreToolUse(input.tool_name, input.tool_input, input.tool_use_id, input.agent_id !== undefined)] }],
|
|
165
|
+
Stop: [{ hooks: [async (input) => this.onStop(input)] }],
|
|
166
|
+
},
|
|
167
|
+
env: claudeEnv(),
|
|
168
|
+
stderr: (data) => {
|
|
169
|
+
this.stderr = (this.stderr + data).slice(-MAX_STDERR);
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
void this.pump();
|
|
174
|
+
}
|
|
175
|
+
get isAlive() {
|
|
176
|
+
return this.alive;
|
|
177
|
+
}
|
|
178
|
+
/** Whether this Claude was started with what the turn needs (settings a running Claude cannot change). */
|
|
179
|
+
fits(settings) {
|
|
180
|
+
return (settings.effort === this.settings.effort &&
|
|
181
|
+
settings.executable === this.settings.executable &&
|
|
182
|
+
settings.cwd === this.settings.cwd);
|
|
183
|
+
}
|
|
184
|
+
async *turn(req) {
|
|
185
|
+
// Claude's own turn was already read by a turn of the person's.
|
|
186
|
+
if (req.continuesAgentTurn && !this.agentTurnPending)
|
|
187
|
+
return;
|
|
188
|
+
const ownTurn = req.continuesAgentTurn === true;
|
|
189
|
+
const mode = agentModeFor(req.mode);
|
|
190
|
+
this.inTurn = true;
|
|
191
|
+
this.lastHost = req.host;
|
|
192
|
+
this.switchedOn = req.autoApprove;
|
|
193
|
+
const interrupt = () => void this.query.interrupt().catch(() => undefined);
|
|
194
|
+
req.signal.addEventListener('abort', interrupt, { once: true });
|
|
195
|
+
const all = withoutOwnMcpServers(toolsLentToClaude(req.allTools ?? req.tools), await this.ownMcpServerNames());
|
|
196
|
+
if (!sameToolNames(all, this.listed))
|
|
197
|
+
this.listed = all;
|
|
198
|
+
try {
|
|
199
|
+
this.offered = skillsForAgent(req.skills ?? [], toolNames(this.listed), await this.ownSkillNames());
|
|
200
|
+
this.mcp.setHandler(moxxyToolsHandler(this.listed, { runTool: (call) => new Promise((resolve) => this.inbox.push({ kind: 'moxxy-tool', call, resolve })) }, this.offered, LENT_AS));
|
|
201
|
+
// The conversation gained or lost a tool or a skill since Claude read the list: it reads it again on this notice.
|
|
202
|
+
await this.mcp.announceTools({ signal: req.signal });
|
|
203
|
+
if (!ownTurn) {
|
|
204
|
+
if (this.owesResult && !(await this.settlePrevious())) {
|
|
205
|
+
yield this.endedError();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
await this.align(req, mode);
|
|
209
|
+
const note = this.newSession ? earlierConversationNote(this.newSession, req.earlierConversation?.()) : req.missedTurns?.();
|
|
210
|
+
this.newSession = undefined;
|
|
211
|
+
const prefix = mode === 'goal' && !this.goalActive ? '/goal ' : '';
|
|
212
|
+
// The record goes in a message of its own: sent together, Claude took the person's message for part of the record.
|
|
213
|
+
if (note)
|
|
214
|
+
await this.silently(`${note}\n\n${READ_ONLY_REPLY}`);
|
|
215
|
+
if (mode === 'goal')
|
|
216
|
+
this.goalActive = true;
|
|
217
|
+
this.send(toClaudeContent(req.prompt, prefix));
|
|
218
|
+
}
|
|
219
|
+
const translator = new TurnTranslator(this.settings.cwd, this.tasks, this.subagents);
|
|
220
|
+
this.planHandedOver = false;
|
|
221
|
+
let planFile;
|
|
222
|
+
for (;;) {
|
|
223
|
+
const item = await this.inbox.next();
|
|
224
|
+
if (item.kind === 'ended') {
|
|
225
|
+
yield* translator.finish();
|
|
226
|
+
yield this.endedError(item.error);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (item.kind === 'message') {
|
|
230
|
+
if (isOwnResult(item.message, this.owesResult)) {
|
|
231
|
+
this.agentTurnPending = false;
|
|
232
|
+
this.finishedTask = undefined;
|
|
233
|
+
this.finishedWork = undefined;
|
|
234
|
+
if (ownTurn) {
|
|
235
|
+
yield* translator.finish();
|
|
236
|
+
yield* resultEvents(item.message, req.signal.aborted, this.model);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (isPersonResult(item.message, this.owesResult)) {
|
|
241
|
+
this.owesResult = false;
|
|
242
|
+
yield* translator.finish();
|
|
243
|
+
yield* resultEvents(item.message, req.signal.aborted, this.model);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
const reported = isInit(item.message) || isModeChange(item.message) ? item.message.permissionMode : undefined;
|
|
247
|
+
// Only the person lets Claude act without asking: a mode that does, set outside Moxxy while auto-approve is off, is set back.
|
|
248
|
+
// A mode not known yet is the person's own Claude setup, shown as it is.
|
|
249
|
+
const was = this.permissionMode;
|
|
250
|
+
const restore = reported !== undefined && was !== undefined && mode !== 'goal' && !this.switchedOn && runsWithoutAsking(reported) && !runsWithoutAsking(was);
|
|
251
|
+
if (restore) {
|
|
252
|
+
await this.setPermissionMode(was);
|
|
253
|
+
yield { type: 'auto_approve_restored' };
|
|
254
|
+
}
|
|
255
|
+
else if (reported !== undefined) {
|
|
256
|
+
this.permissionMode = reported;
|
|
257
|
+
}
|
|
258
|
+
for (const event of translator.translate(item.message)) {
|
|
259
|
+
if (event.type === 'tool_call')
|
|
260
|
+
planFile = claudePlanFileOf(event.name, event.input) ?? planFile;
|
|
261
|
+
if (event.type === 'auto_approve') {
|
|
262
|
+
// In goal mode Claude runs bypassPermissions for the goal, not because the person chose auto-approve.
|
|
263
|
+
if (mode === 'goal' || restore)
|
|
264
|
+
continue;
|
|
265
|
+
this.switchedOn = event.enabled;
|
|
266
|
+
yield isModeChange(item.message) ? { ...event, elsewhere: true } : event;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
yield event;
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
yield* this.handle(item, req, translator, mode);
|
|
274
|
+
}
|
|
275
|
+
// Claude wrote or changed its plan but ended without handing it over: it still goes on the plan card.
|
|
276
|
+
if (mode === 'plan' && !this.planHandedOver && planFile && !req.signal.aborted) {
|
|
277
|
+
const plan = await readFile(planFile, 'utf8').catch(() => '');
|
|
278
|
+
if (plan.trim())
|
|
279
|
+
yield { type: 'plan', text: plan.trim() };
|
|
280
|
+
}
|
|
281
|
+
if (mode === 'goal' && !ownTurn && !req.signal.aborted) {
|
|
282
|
+
const status = await this.goalStatus();
|
|
283
|
+
if (status === 'complete')
|
|
284
|
+
this.goalActive = false;
|
|
285
|
+
if (status)
|
|
286
|
+
yield { type: 'goal', status };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
req.signal.removeEventListener('abort', interrupt);
|
|
291
|
+
this.mcp.setHandler(idleToolsHandler(this.listed, this.offered, LENT_AS));
|
|
292
|
+
this.inTurn = false;
|
|
293
|
+
this.dismissQueued();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Stop one work Claude runs in the background (`AgentBackgroundWork.id`); `false` when Claude runs no such work. */
|
|
297
|
+
async stopWork(workId) {
|
|
298
|
+
const task = this.background.taskOf(workId);
|
|
299
|
+
if (task === undefined || !this.alive)
|
|
300
|
+
return false;
|
|
301
|
+
await this.query.stopTask(task);
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
async close() {
|
|
305
|
+
if (this.closed)
|
|
306
|
+
return;
|
|
307
|
+
this.closed = true;
|
|
308
|
+
this.alive = false;
|
|
309
|
+
// Claude's background work ends with it.
|
|
310
|
+
this.report(this.background.stopped());
|
|
311
|
+
this.input.push(null);
|
|
312
|
+
this.query.close();
|
|
313
|
+
this.dismissQueued();
|
|
314
|
+
await this.mcp.close();
|
|
315
|
+
}
|
|
316
|
+
/** What Claude asked of Moxxy, answered in order with the turn's host. */
|
|
317
|
+
async *handle(item, req, translator, mode) {
|
|
318
|
+
switch (item.kind) {
|
|
319
|
+
case 'moxxy-tool':
|
|
320
|
+
item.resolve(await req.host.runTool(item.call));
|
|
321
|
+
return;
|
|
322
|
+
case 'hook': {
|
|
323
|
+
yield* translator.announce(item.callId, item.name, item.input, { inSubagent: item.inSubagent });
|
|
324
|
+
const decision = await req.host.approve({ callId: item.callId, name: item.name, input: item.input, policyOnly: true });
|
|
325
|
+
item.resolve(decision.allow ? {} : refusedByRules(decision.reason));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
case 'approve':
|
|
329
|
+
if (item.name === 'AskUserQuestion') {
|
|
330
|
+
item.resolve(await this.answerQuestion(item.input, req));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
// In Moxxy's plan mode the plan is the person's to answer on the plan card, like Codex's and OpenCode's.
|
|
334
|
+
if (item.name === 'ExitPlanMode' && mode === 'plan' && typeof item.input.plan === 'string') {
|
|
335
|
+
yield* translator.announce(item.callId, item.name, item.input, { inSubagent: item.inSubagent });
|
|
336
|
+
yield* translator.handOver(item.callId, 'The plan is with the person, on the plan card.');
|
|
337
|
+
this.planHandedOver = true;
|
|
338
|
+
yield { type: 'plan', text: item.input.plan };
|
|
339
|
+
item.resolve({ behavior: 'deny', message: PLAN_HANDED_OVER });
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
yield* translator.announce(item.callId, item.name, item.input, { inSubagent: item.inSubagent });
|
|
343
|
+
item.resolve(await this.decide(item, req));
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async decide(item, req) {
|
|
348
|
+
const plan = item.name === 'ExitPlanMode' && typeof item.input.plan === 'string' ? item.input.plan : undefined;
|
|
349
|
+
const description = plan ?? item.description;
|
|
350
|
+
const decision = await untilStopped(req.host.approve({ callId: item.callId, name: item.name, input: item.input, ...(description ? { description } : {}) }), req.signal, { allow: false, reason: 'The person stopped the turn.' });
|
|
351
|
+
if (!decision.allow)
|
|
352
|
+
return { behavior: 'deny', message: decision.reason };
|
|
353
|
+
// An approved plan runs at once; with auto-approve on, without asking again.
|
|
354
|
+
if (plan !== undefined && this.switchedOn)
|
|
355
|
+
void this.setPermissionMode('bypassPermissions');
|
|
356
|
+
return { behavior: 'allow', updatedInput: item.input };
|
|
357
|
+
}
|
|
358
|
+
async answerQuestion(input, req) {
|
|
359
|
+
const items = fromClaudeQuestions(input);
|
|
360
|
+
const outcome = await untilStopped(req.host.ask(items), req.signal, { kind: 'dismissed', reason: 'cancelled' });
|
|
361
|
+
switch (outcome.kind) {
|
|
362
|
+
case 'answered':
|
|
363
|
+
return { behavior: 'allow', updatedInput: { ...input, answers: toClaudeAnswers(items, outcome.answers) } };
|
|
364
|
+
case 'dismissed':
|
|
365
|
+
return { behavior: 'deny', message: 'The person closed the question without answering.' };
|
|
366
|
+
case 'unanswerable':
|
|
367
|
+
return {
|
|
368
|
+
behavior: 'deny',
|
|
369
|
+
message: 'Nobody is there to answer questions right now. Pick the sensible choice yourself and say which one you picked.',
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/** Model, mode and goal as this turn wants them, changed on the running Claude. */
|
|
374
|
+
async align(req, mode) {
|
|
375
|
+
if (req.model && req.model !== this.model) {
|
|
376
|
+
await this.query.setModel(req.model);
|
|
377
|
+
this.model = req.model;
|
|
378
|
+
}
|
|
379
|
+
if (mode !== 'goal' && this.goalActive) {
|
|
380
|
+
await this.silently('/goal clear');
|
|
381
|
+
this.goalActive = false;
|
|
382
|
+
}
|
|
383
|
+
const wanted = startingPermissionMode(mode, req.autoApprove) ??
|
|
384
|
+
(this.permissionMode === 'bypassPermissions' || this.permissionMode === 'plan' ? 'default' : undefined);
|
|
385
|
+
if (wanted && wanted !== this.permissionMode)
|
|
386
|
+
await this.setPermissionMode(wanted);
|
|
387
|
+
}
|
|
388
|
+
async setPermissionMode(mode) {
|
|
389
|
+
// Known before Claude reports it back, so the report is not taken for a change made elsewhere.
|
|
390
|
+
this.permissionMode = mode;
|
|
391
|
+
await this.query.setPermissionMode(mode);
|
|
392
|
+
}
|
|
393
|
+
/** After a goal turn: ask `/goal` once whether the goal is still open. Its answer is not shown. */
|
|
394
|
+
async goalStatus() {
|
|
395
|
+
let status;
|
|
396
|
+
await this.silently('/goal', (message) => {
|
|
397
|
+
if (message.type !== 'assistant' || !('message' in message))
|
|
398
|
+
return;
|
|
399
|
+
for (const block of message.message.content) {
|
|
400
|
+
if (block.type === 'text' && 'text' in block && typeof block.text === 'string')
|
|
401
|
+
status = goalStatusFrom(block.text) ?? status;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
return status;
|
|
405
|
+
}
|
|
406
|
+
/** Send a command and read through to its result without showing anything. */
|
|
407
|
+
/** Claude's own skills and commands, not its built-in ones: a Moxxy skill of the same name is left to Claude's. */
|
|
408
|
+
/** Claude's own MCP servers that are on: Moxxy's server of the same name is left to Claude's. */
|
|
409
|
+
async ownMcpServerNames() {
|
|
410
|
+
try {
|
|
411
|
+
const servers = await this.query.mcpServerStatus();
|
|
412
|
+
return servers.filter((server) => server.name !== MOXXY_MCP_SERVER && server.status !== 'disabled').map((server) => server.name);
|
|
413
|
+
}
|
|
414
|
+
catch {
|
|
415
|
+
return [];
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async ownSkillNames() {
|
|
419
|
+
try {
|
|
420
|
+
const commands = await this.query.supportedCommands();
|
|
421
|
+
return commands.filter((command) => !command.builtin).flatMap((command) => [command.name, ...(command.aliases ?? [])]);
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async silently(text, onMessage) {
|
|
428
|
+
this.send(text);
|
|
429
|
+
for (;;) {
|
|
430
|
+
const item = await this.inbox.next();
|
|
431
|
+
if (item.kind === 'ended')
|
|
432
|
+
return;
|
|
433
|
+
if (item.kind !== 'message') {
|
|
434
|
+
refuse(item);
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
if (isPersonResult(item.message, this.owesResult)) {
|
|
438
|
+
this.owesResult = false;
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
onMessage?.(item.message);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/** Wait out the result of a turn whose reader stopped early, so it does not leak into this one. */
|
|
445
|
+
async settlePrevious() {
|
|
446
|
+
await this.query.interrupt().catch(() => undefined);
|
|
447
|
+
for (;;) {
|
|
448
|
+
const item = await this.inbox.next();
|
|
449
|
+
if (item.kind === 'ended')
|
|
450
|
+
return false;
|
|
451
|
+
if (item.kind !== 'message')
|
|
452
|
+
refuse(item);
|
|
453
|
+
else if (isPersonResult(item.message, this.owesResult)) {
|
|
454
|
+
this.owesResult = false;
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
send(content) {
|
|
460
|
+
this.owesResult = true;
|
|
461
|
+
this.input.push({ type: 'user', message: { role: 'user', content }, parent_tool_use_id: null, origin: { kind: 'human' } });
|
|
462
|
+
}
|
|
463
|
+
async *userMessages() {
|
|
464
|
+
for (;;) {
|
|
465
|
+
const message = await this.input.next();
|
|
466
|
+
if (message === null)
|
|
467
|
+
return;
|
|
468
|
+
yield message;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async pump() {
|
|
472
|
+
try {
|
|
473
|
+
for await (const message of this.query) {
|
|
474
|
+
this.inbox.push({ kind: 'message', message });
|
|
475
|
+
this.notice(message);
|
|
476
|
+
}
|
|
477
|
+
this.inbox.push({ kind: 'ended' });
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
this.inbox.push({ kind: 'ended', error: err instanceof Error ? err.message : String(err) });
|
|
481
|
+
}
|
|
482
|
+
finally {
|
|
483
|
+
this.alive = false;
|
|
484
|
+
this.report(this.background.stopped());
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
onCanUseTool(name, input, options) {
|
|
488
|
+
// Moxxy asks about its own tools when it runs them; a second window would ask twice.
|
|
489
|
+
const server = options.mcpServer;
|
|
490
|
+
if (name.startsWith(MOXXY_TOOL_PREFIX) && server && server.name === MOXXY_MCP_SERVER && server.source === 'dynamic') {
|
|
491
|
+
return Promise.resolve({ behavior: 'allow', updatedInput: input });
|
|
492
|
+
}
|
|
493
|
+
if (!this.inTurn)
|
|
494
|
+
return Promise.resolve({ behavior: 'deny', message: NOT_IN_A_TURN });
|
|
495
|
+
const description = options.description ?? options.title;
|
|
496
|
+
return new Promise((resolve) => this.inbox.push({
|
|
497
|
+
kind: 'approve',
|
|
498
|
+
callId: options.toolUseID ?? randomUUID(),
|
|
499
|
+
name,
|
|
500
|
+
input,
|
|
501
|
+
...(description ? { description } : {}),
|
|
502
|
+
inSubagent: options.agentID !== undefined,
|
|
503
|
+
resolve,
|
|
504
|
+
}));
|
|
505
|
+
}
|
|
506
|
+
/** Claude ended a turn: what it set itself to come back for is said again, whenever it changed. */
|
|
507
|
+
async onStop(input) {
|
|
508
|
+
// An older Claude does not say; nothing is listed rather than a guess.
|
|
509
|
+
if (input.session_crons)
|
|
510
|
+
this.setWakeups(wakeupsOf(input.session_crons, Date.now()));
|
|
511
|
+
return {};
|
|
512
|
+
}
|
|
513
|
+
setWakeups(wakeups) {
|
|
514
|
+
if (JSON.stringify(wakeups) === JSON.stringify(this.wakeups))
|
|
515
|
+
return;
|
|
516
|
+
this.wakeups = wakeups;
|
|
517
|
+
this.report([{ type: 'scheduled_wakeups', wakeups }]);
|
|
518
|
+
}
|
|
519
|
+
onPreToolUse(name, input, callId, inSubagent) {
|
|
520
|
+
if (name.startsWith(MOXXY_TOOL_PREFIX))
|
|
521
|
+
return Promise.resolve({});
|
|
522
|
+
if (!this.inTurn)
|
|
523
|
+
return this.checkRulesBetweenTurns(name, input, callId);
|
|
524
|
+
return new Promise((resolve) => this.inbox.push({ kind: 'hook', callId, name, input, inSubagent, resolve }));
|
|
525
|
+
}
|
|
526
|
+
/** A call made while no turn runs (a helper in the background) still meets Moxxy's rules. */
|
|
527
|
+
async checkRulesBetweenTurns(name, input, callId) {
|
|
528
|
+
const host = this.lastHost;
|
|
529
|
+
if (!host)
|
|
530
|
+
return refusedByRules(NO_RULES_YET);
|
|
531
|
+
const decision = await host.approve({ callId, name, input, policyOnly: true });
|
|
532
|
+
return decision.allow ? {} : refusedByRules(decision.reason);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Watch what Claude sends whether or not a turn runs: which task finished,
|
|
536
|
+
* and Claude taking up a turn by itself (its `init` while Moxxy is idle),
|
|
537
|
+
* which the conversation opens a turn for.
|
|
538
|
+
*/
|
|
539
|
+
notice(message) {
|
|
540
|
+
if (message.type === 'system') {
|
|
541
|
+
const note = message;
|
|
542
|
+
if (note.subtype === 'task_started' && typeof note.task_id === 'string' && typeof note.description === 'string') {
|
|
543
|
+
this.taskNames.set(note.task_id, note.description);
|
|
544
|
+
}
|
|
545
|
+
if (note.subtype === 'task_notification' && typeof note.task_id === 'string') {
|
|
546
|
+
this.finishedTask = this.taskNames.get(note.task_id) ?? this.finishedTask;
|
|
547
|
+
this.finishedWork = this.background.workIdOf(note.task_id, typeof note.tool_use_id === 'string' ? note.tool_use_id : undefined);
|
|
548
|
+
void this.background.end(note).then((events) => this.report(events));
|
|
549
|
+
}
|
|
550
|
+
this.report(this.background.fromNote(note));
|
|
551
|
+
}
|
|
552
|
+
if (!this.inTurn && isBackgroundHelperNote(message))
|
|
553
|
+
this.report(this.between.translate(message));
|
|
554
|
+
if (this.closed || this.inTurn || this.owesResult || this.agentTurnPending || !isInit(message))
|
|
555
|
+
return;
|
|
556
|
+
this.agentTurnPending = true;
|
|
557
|
+
const due = this.finishedTask ? undefined : dueWakeup(this.wakeups, Date.now());
|
|
558
|
+
// A one-shot wakeup is spent once Claude comes back for it; its Stop says what is left.
|
|
559
|
+
if (due && !due.recurring)
|
|
560
|
+
this.setWakeups(this.wakeups.filter((wakeup) => wakeup !== due));
|
|
561
|
+
const name = this.finishedTask ? `${this.finishedTask} finished in the background` : due ? 'Scheduled check-in' : 'A background task finished';
|
|
562
|
+
this.settings.onAgentTurn?.(name, this.finishedWork);
|
|
563
|
+
}
|
|
564
|
+
report(events) {
|
|
565
|
+
if (events.length > 0)
|
|
566
|
+
this.settings.onActivity?.(events);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Answer whatever is still queued once no turn can: Claude must never wait on
|
|
570
|
+
* Moxxy forever. What is left of a turn whose reader stopped early is dropped,
|
|
571
|
+
* up to its result; what Claude sent after it is its own (a helper in the
|
|
572
|
+
* background, a turn it took up) and stays for the next reader.
|
|
573
|
+
*/
|
|
574
|
+
dismissQueued() {
|
|
575
|
+
const kept = [];
|
|
576
|
+
let ended;
|
|
577
|
+
for (const item of this.inbox.drain()) {
|
|
578
|
+
if (item.kind === 'ended')
|
|
579
|
+
ended = item;
|
|
580
|
+
else if (item.kind !== 'message')
|
|
581
|
+
refuse(item);
|
|
582
|
+
else if (!this.owesResult)
|
|
583
|
+
kept.push(item.message);
|
|
584
|
+
else if (isPersonResult(item.message, this.owesResult))
|
|
585
|
+
this.owesResult = false;
|
|
586
|
+
}
|
|
587
|
+
for (const message of kept) {
|
|
588
|
+
this.inbox.push({ kind: 'message', message });
|
|
589
|
+
this.notice(message);
|
|
590
|
+
}
|
|
591
|
+
if (ended)
|
|
592
|
+
this.inbox.push(ended);
|
|
593
|
+
}
|
|
594
|
+
endedError(error) {
|
|
595
|
+
const detail = error ?? 'Claude Code stopped.';
|
|
596
|
+
const stderr = this.stderr.trim();
|
|
597
|
+
return { type: 'error', message: stderr && !detail.includes(stderr) ? `${detail}\n${stderr}` : detail, retryable: false };
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* The settings to start Claude with: without `resume` when Claude's session
|
|
602
|
+
* for this conversation no longer exists (Claude would fail every turn on it),
|
|
603
|
+
* so the conversation goes on in a new one. A check that keeps failing stops
|
|
604
|
+
* the turn rather than start over.
|
|
605
|
+
*/
|
|
606
|
+
async function withoutLostSession(settings) {
|
|
607
|
+
const { resume, sdk } = settings;
|
|
608
|
+
if (!resume)
|
|
609
|
+
return { settings, newSession: 'new' };
|
|
610
|
+
if (!sdk.getSessionInfo)
|
|
611
|
+
return { settings };
|
|
612
|
+
const resumed = await resumeAgentSession({
|
|
613
|
+
label: 'Claude Code',
|
|
614
|
+
load: async () => {
|
|
615
|
+
if (!(await sdk.getSessionInfo?.(resume)))
|
|
616
|
+
throw new SessionGone(`Claude has no session ${resume}.`);
|
|
617
|
+
return resume;
|
|
618
|
+
},
|
|
619
|
+
gone: (error) => error instanceof SessionGone,
|
|
620
|
+
});
|
|
621
|
+
if (resumed.kind === 'loaded')
|
|
622
|
+
return { settings };
|
|
623
|
+
const { resume: _lost, ...fresh } = settings;
|
|
624
|
+
return { settings: fresh, newSession: 'lost' };
|
|
625
|
+
}
|
|
626
|
+
function refuse(item) {
|
|
627
|
+
switch (item.kind) {
|
|
628
|
+
case 'approve':
|
|
629
|
+
item.resolve({ behavior: 'deny', message: NOT_IN_A_TURN });
|
|
630
|
+
return;
|
|
631
|
+
case 'hook':
|
|
632
|
+
item.resolve({});
|
|
633
|
+
return;
|
|
634
|
+
case 'moxxy-tool':
|
|
635
|
+
item.resolve({ ok: false, message: 'No Moxxy turn is running, so the tool cannot run now.' });
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function* resultEvents(message, stopped, model) {
|
|
640
|
+
if (message.usage)
|
|
641
|
+
yield { type: 'usage', usage: toTokenUsage(message.usage) };
|
|
642
|
+
const tokens = contextWindowOf(message.modelUsage, model);
|
|
643
|
+
if (tokens !== undefined)
|
|
644
|
+
yield { type: 'context_window', model, tokens };
|
|
645
|
+
if (!message.is_error || stopped)
|
|
646
|
+
return;
|
|
647
|
+
const detail = message.errors && message.errors.length > 0 ? message.errors.join('; ') : (message.result ?? message.subtype);
|
|
648
|
+
yield { type: 'error', message: `Claude Code: ${detail}`, retryable: false };
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The window Claude ran the model with. `modelUsage` is keyed by the model string Claude
|
|
652
|
+
* used (`claude-opus-5-5[1m]`) and also lists helper models, so match the turn's own.
|
|
653
|
+
*/
|
|
654
|
+
function contextWindowOf(usage, model) {
|
|
655
|
+
if (!usage)
|
|
656
|
+
return undefined;
|
|
657
|
+
for (const [key, entry] of Object.entries(usage)) {
|
|
658
|
+
const named = key === model || key.replace(/\[[^\]]*\]$/, '') === model || entry.canonicalModel === model;
|
|
659
|
+
if (named && isContextWindowSize(entry.contextWindow))
|
|
660
|
+
return entry.contextWindow;
|
|
661
|
+
}
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
664
|
+
/** The `result` of a turn Claude took up by itself. */
|
|
665
|
+
function isOwnResult(message, owed) {
|
|
666
|
+
return message.type === 'result' && 'is_error' in message && !isPersonResult(message, owed);
|
|
667
|
+
}
|
|
668
|
+
function refusedByRules(reason) {
|
|
669
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: reason } };
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* The `result` of the person's turn. A turn Claude started itself is not: one after a background
|
|
673
|
+
* task carries its origin, but one it woke itself up for (ScheduleWakeup, /loop) carries none, so
|
|
674
|
+
* a result without an origin is the person's only while Moxxy waits for one (`owed`), as from
|
|
675
|
+
* a Claude too old to send origins.
|
|
676
|
+
*/
|
|
677
|
+
function isPersonResult(message, owed) {
|
|
678
|
+
if (message.type !== 'result' || !('is_error' in message))
|
|
679
|
+
return false;
|
|
680
|
+
const origin = message.origin;
|
|
681
|
+
return origin === undefined ? owed : origin.kind === 'human';
|
|
682
|
+
}
|
|
683
|
+
/** A background helper's own message, or Claude's report on one of its tasks. */
|
|
684
|
+
function isBackgroundHelperNote(message) {
|
|
685
|
+
if (message.type === 'assistant')
|
|
686
|
+
return message.parent_tool_use_id !== null && message.parent_tool_use_id !== undefined;
|
|
687
|
+
return message.type === 'system' && 'subtype' in message && (message.subtype === 'task_progress' || message.subtype === 'task_notification');
|
|
688
|
+
}
|
|
689
|
+
function isInit(message) {
|
|
690
|
+
return message.type === 'system' && 'subtype' in message && message.subtype === 'init';
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* The environment for Claude Code: Moxxy's own, without the markers that make
|
|
694
|
+
* Claude refuse to start as a nested session when Moxxy itself was launched
|
|
695
|
+
* from Claude Code. The SDK replaces the environment, so it is spread here.
|
|
696
|
+
*/
|
|
697
|
+
export function claudeEnv() {
|
|
698
|
+
const env = { ...process.env, CLAUDE_AGENT_SDK_CLIENT_APP: 'moxxy' };
|
|
699
|
+
delete env.CLAUDECODE;
|
|
700
|
+
delete env.CLAUDE_CODE_ENTRYPOINT;
|
|
701
|
+
return env;
|
|
702
|
+
}
|
|
703
|
+
//# sourceMappingURL=agent-session.js.map
|