xcodebug 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.ts +2 -0
  2. package/mcp/server.ts +58 -10
  3. package/package.json +1 -1
package/index.ts CHANGED
@@ -1691,6 +1691,7 @@ export default function xcodebug(pi: ExtensionAPI): void {
1691
1691
 
1692
1692
  if (!appPath) throw new Error("launch requires appPath, or a scheme to build.");
1693
1693
  executable ??= params.processName ?? (await readBundleExecutable(appPath));
1694
+ setRunPhase(`installing on ${device.name}`);
1694
1695
  const install = await installApp(device, appPath, { timeoutMs: 180_000, signal });
1695
1696
  if (!install.ok) {
1696
1697
  return { content: [{ type: "text", text: install.message }], details: install, isError: true };
@@ -1714,6 +1715,7 @@ export default function xcodebug(pi: ExtensionAPI): void {
1714
1715
  // stdout/stderr (plus os_log via OS_ACTIVITY_DT_MODE) and keeps running
1715
1716
  // until the app exits. A second plain launch would create a second,
1716
1717
  // short-lived instance and leave a stale pid behind.
1718
+ setRunPhase(`launching ${resolvedBundleId}`);
1717
1719
  const capture = new Capture({
1718
1720
  mode: "console",
1719
1721
  deviceId: device.id,
package/mcp/server.ts CHANGED
@@ -27,7 +27,9 @@ import { createInterface } from "node:readline";
27
27
  interface ExtensionContextLike {
28
28
  cwd: string;
29
29
  agentDir: string;
30
- ui: { notify(): void; setStatus(): void; setWidget(): void };
30
+ /** The status ticker in index.ts only runs when this is set. */
31
+ hasUI?: boolean;
32
+ ui: { notify(): void; setStatus(key: string, text?: string): void; setWidget(): void };
31
33
  }
32
34
 
33
35
  interface ToolResult {
@@ -94,11 +96,44 @@ if (!registered) {
94
96
  }
95
97
  const tool = registered;
96
98
 
97
- const ctx: ExtensionContextLike = {
98
- cwd: process.cwd(),
99
- agentDir: AGENT_DIR,
100
- ui: { notify() {}, setStatus() {}, setWidget() {} },
101
- };
99
+ function sendNotification(method: string, params: unknown): void {
100
+ process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", method, params })}\n`);
101
+ }
102
+
103
+ // While an action runs, index.ts repaints its status line once a second. That is
104
+ // the same cadence MCP progress wants, so the status text becomes the progress
105
+ // message instead of being dropped. `hasUI` is what makes that ticker run at all.
106
+ function makeCtx(progressToken: unknown): { ctx: ExtensionContextLike; close(): void } {
107
+ let step = 0;
108
+ let active = true;
109
+ const report = (text: string | undefined): void => {
110
+ if (!active) return;
111
+ if (progressToken === undefined || progressToken === null) return;
112
+ if (text === undefined || text === "") return;
113
+ step += 1;
114
+ sendNotification("notifications/progress", { progressToken, progress: step, message: text });
115
+ };
116
+ return {
117
+ ctx: {
118
+ cwd: process.cwd(),
119
+ agentDir: AGENT_DIR,
120
+ hasUI: true,
121
+ ui: {
122
+ notify() {},
123
+ setStatus(_key, text) {
124
+ report(text);
125
+ },
126
+ setWidget() {},
127
+ },
128
+ },
129
+ // The status ticker keeps running while a capture is alive, which outlives
130
+ // the call that started it. Without closing, the adapter would keep
131
+ // reporting progress for a request that already answered.
132
+ close() {
133
+ active = false;
134
+ },
135
+ };
136
+ }
102
137
 
103
138
  // Typebox attaches symbol metadata; JSON round-tripping leaves a plain schema.
104
139
  const inputSchema = JSON.parse(JSON.stringify(tool.parameters)) as Record<string, unknown>;
@@ -111,7 +146,11 @@ function replyError(id: unknown, code: number, message: string): void {
111
146
  process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } })}\n`);
112
147
  }
113
148
 
114
- async function callTool(args: Record<string, unknown>, signal: AbortSignal): Promise<ToolResult> {
149
+ async function callTool(
150
+ args: Record<string, unknown>,
151
+ signal: AbortSignal,
152
+ progressToken: unknown,
153
+ ): Promise<ToolResult> {
115
154
  // `defaultPushMode` defaults to "context", but this transport cannot deliver
116
155
  // pushed lines. Refusing an explicit request beats accepting it and going quiet.
117
156
  if (args.push !== undefined && args.push !== "off") {
@@ -120,7 +159,12 @@ async function callTool(args: Record<string, unknown>, signal: AbortSignal): Pro
120
159
  isError: true,
121
160
  };
122
161
  }
123
- return tool.execute("mcp", { ...args, push: "off" }, signal, undefined, ctx);
162
+ const progress = makeCtx(progressToken);
163
+ try {
164
+ return await tool.execute("mcp", { ...args, push: "off" }, signal, undefined, progress.ctx);
165
+ } finally {
166
+ progress.close();
167
+ }
124
168
  }
125
169
 
126
170
  async function handle(message: Record<string, unknown>): Promise<void> {
@@ -147,7 +191,11 @@ async function handle(message: Record<string, unknown>): Promise<void> {
147
191
  return;
148
192
  }
149
193
  if (method === "tools/call") {
150
- const params = (message.params ?? {}) as { name?: string; arguments?: Record<string, unknown> };
194
+ const params = (message.params ?? {}) as {
195
+ name?: string;
196
+ arguments?: Record<string, unknown>;
197
+ _meta?: { progressToken?: unknown };
198
+ };
151
199
  if (params.name !== "xcodebug") {
152
200
  replyError(id, -32602, `Unknown tool "${params.name ?? ""}"`);
153
201
  return;
@@ -157,7 +205,7 @@ async function handle(message: Record<string, unknown>): Promise<void> {
157
205
  const controller = new AbortController();
158
206
  inflight.set(id, controller);
159
207
  try {
160
- reply(id, await callTool(params.arguments ?? {}, controller.signal));
208
+ reply(id, await callTool(params.arguments ?? {}, controller.signal, params._meta?.progressToken));
161
209
  } catch (error) {
162
210
  reply(id, { content: [{ type: "text", text: (error as Error).message }], isError: true });
163
211
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcodebug",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "Build, install and launch an iOS app on a physical device and read its console inside the agent session (pi / omp extension)",
6
6
  "keywords": [