codex-copilot-dx 1.4.21 → 1.4.23

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.
@@ -3,11 +3,17 @@ import path from "node:path";
3
3
  import os from "node:os";
4
4
  import {execFile} from "node:child_process";
5
5
  import {promisify} from "node:util";
6
+ import { inspectWindowsAntigravity, windowsAntigravityEnvironment, windowsAntigravityPath } from "./windows-antigravity-app.mjs";
6
7
 
7
8
  const execute=promisify(execFile);
8
9
 
9
- export async function inspectGeminiApp({platform=process.platform,app="/Applications/Gemini.app",exec=execute,exists=fs.existsSync}={}) {
10
+ export async function inspectGeminiApp({platform=process.platform,app,env=process.env,exec=execute,exists=fs.existsSync}={}) {
11
+ if(platform==="win32"){
12
+ const state=await inspectWindowsAntigravity({env,exec,app});
13
+ return !app&&state.app?inspectWindowsAntigravity({env,exec,app:state.app}):state;
14
+ }
10
15
  if(platform!=="darwin")return {status:"unsupported"};
16
+ app??="/Applications/Gemini.app";
11
17
  const metadata=path.join(app,"Contents/Info.plist");
12
18
  if(!exists(metadata))return {status:"not_installed"};
13
19
  const result=await exec("/usr/bin/plutil",["-convert","json","-o","-",metadata],{encoding:"utf8",timeout:3000,maxBuffer:65536});
@@ -24,12 +30,17 @@ export async function inspectGeminiApp({platform=process.platform,app="/Applicat
24
30
 
25
31
  // A launch plan is reviewable without changing files, credentials, or running apps.
26
32
  // A prepared environment is not evidence that the App has adopted the route.
27
- export function planGeminiAppLaunch(state,{cloudCodeUrl,env=process.env,home=os.homedir(),managedGateway=false}={}) {
33
+ export function planGeminiAppLaunch(state,{cloudCodeUrl,env=process.env,home=os.homedir(),platform=process.platform,managedGateway=false}={}) {
28
34
  if(!["running","stopped","multiple"].includes(state?.status))return {status:state?.status||"unknown"};
29
- if(state.status==="stopped"&&!["/Applications/Gemini.app",path.join(home,"Applications/Gemini.app")].includes(state.app))throw new Error("Unrecognized Gemini App location");
30
- const url=new URL(cloudCodeUrl);
31
- if(url.protocol!=="http:"||url.hostname!=="127.0.0.1"||!url.port||Number(url.port)<1||url.username||url.password||url.search||url.hash)throw new Error("Gemini route must use a local CCDX endpoint");
32
- if(managedGateway||Object.entries(env).some(([key,value])=>key.startsWith("AGY_LLM_GATEWAY_")&&value)||env.CLOUD_CODE_URL&&env.CLOUD_CODE_URL!==url.href)return {status:"route_conflict"};
35
+ if(state.status==="stopped"&&!(platform==="win32"?windowsAntigravityPath(state.app):
36
+ ["/Applications/Gemini.app",path.join(home,"Applications/Gemini.app")].includes(state.app)))throw new Error("Unrecognized Gemini App location");
37
+ const url=cloudCodeUrl===undefined?null:new URL(cloudCodeUrl);
38
+ if(url&&(url.protocol!=="http:"||url.hostname!=="127.0.0.1"||!url.port||Number(url.port)<1||url.username||url.password||url.search||url.hash))throw new Error("Gemini route must use a local CCDX endpoint");
39
+ if(url&&(managedGateway||platform==="win32"&&state.wsl||Object.entries(env).some(([name,value])=>{
40
+ const key=name.toUpperCase();
41
+ return Boolean(value)&&(key.startsWith("AGY_LLM_GATEWAY_")||key==="CLOUD_CODE_URL"&&value!==url.href||platform==="win32"&&key==="ANTIGRAVITY_WSL_DISTRO");
42
+ })))return {status:"route_conflict"};
33
43
  if(state.status!=="stopped")return {status:state.status==="multiple"?"multiple":"needs_app_relaunch",pids:[...state.pids]};
34
- return {status:"prepared",command:"/usr/bin/open",args:["-a",state.app,"--env","CLOUD_CODE_URL="+url.href]};
44
+ if(platform==="win32")return {status:"prepared",command:state.app,args:[],environment:windowsAntigravityEnvironment(env,url?.href)};
45
+ return {status:"prepared",command:"/usr/bin/open",args:["-a",state.app,...(url?["--env","CLOUD_CODE_URL="+url.href]:[])]};
35
46
  }
@@ -1,8 +1,8 @@
1
- export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/live.js", "/time.js", "/animation.js", "/status.js", "/view-boundary.js", "/activity.js", "/flow.js", "/tool-activity-machines.js", "/usage.js", "/context.js", "/ui.js", "/console.js", "/updates.js", "/preferences.js", "/features.js", "/icons.js", "/disclosure.js", "/tools.js", "/connections.js", "/privacy.js"]);
1
+ import { DASHBOARD_PATHS } from "./dashboard-assets.mjs";
2
+
3
+ export { DASHBOARD_PATHS };
2
4
  export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers", "/_ccdx/ui/settings", "/_ccdx/ui/m365/accounts", "/_ccdx/ui/updates", "/_ccdx/ui/account", "/_ccdx/ui/checks", "/_ccdx/ui/connections", "/_ccdx/ui/context", "/_ccdx/ui/privacy"]);
3
5
 
4
- DASHBOARD_PATHS.add("/gemini.js");
5
- DASHBOARD_PATHS.add("/dashboard.js");
6
6
  DASHBOARD_API_PATHS.add("/_ccdx/ui/gemini");
7
7
 
8
8
  export function isOptionalRoute(method, pathname) {
@@ -4,6 +4,7 @@ import { chatCompletions } from "./copilot.mjs";
4
4
  import { webStreamLines } from "./stream.mjs";
5
5
  import { cancelSourceResponse, sourceResponseAccepted, sourceResponseFailed } from "./source-response.mjs";
6
6
  import { normalizeCallLessToolOutputs } from "./responses-tool-output.mjs";
7
+ import { chatOutputParts } from "./chat-output-parts.mjs";
7
8
  import {
8
9
  abortErrorStatusCode,
9
10
  isAbortLikeError,
@@ -322,7 +323,10 @@ export function chatToResponses(chatResp, model, { toolChoice, toolAdapter } = {
322
323
  const name = call?.function?.name || "";
323
324
  return terminal.status === "completed" ? !allowed.has(name) : name && ![...allowed].some(candidate => candidate.startsWith(name));
324
325
  }) || terminal.status === "completed" && toolChoice.allowed_tools.mode === "required" && !msg?.tool_calls?.length)) throw disallowedUpstreamTool();
325
- if (msg?.content) output.push({ type: "message", id: `msg_${uid()}`, role: "assistant", status: terminal.status, content: [{ type: "output_text", text: msg.content }] });
326
+ for (const { text, thought } of chatOutputParts(msg?.content)) {
327
+ output.push(thought ? { type: "reasoning", id: `rs_${uid()}`, summary: [{ type: "summary_text", text }] }
328
+ : { type: "message", id: `msg_${uid()}`, role: "assistant", status: terminal.status, content: [{ type: "output_text", text }] });
329
+ }
326
330
  if (msg?.tool_calls) for (const tc of msg.tool_calls) output.push(toolAdapter
327
331
  ? toolAdapter.outputItem({ id: tc.id, callId: tc.id, name: tc.function?.name, arguments: tc.function?.arguments }, terminal.status)
328
332
  : { type: "function_call", id: tc.id, call_id: tc.id, name: tc.function.name, arguments: tc.function.arguments, status: terminal.status });
@@ -400,6 +404,7 @@ export async function forwardToChat(chatReq, emitEvent, onDone, onError, options
400
404
  let finishReason = null;
401
405
  let fullText = "";
402
406
  let messageItem = null;
407
+ let reasoningItem = null;
403
408
  let nextOutputIndex = 0;
404
409
  let usage = { input_tokens: 0, output_tokens: 0, total_tokens: 0 };
405
410
  const toolCalls = new Map();
@@ -462,11 +467,32 @@ export async function forwardToChat(chatReq, emitEvent, onDone, onError, options
462
467
  return { tool, created: true };
463
468
  };
464
469
 
470
+ async function appendReasoning(text) {
471
+ if (!reasoningItem) {
472
+ reasoningItem = { id: `rs_${uid()}`, outputIndex: nextOutputIndex++, text: "" };
473
+ const { id, outputIndex } = reasoningItem;
474
+ await emitEvent("response.output_item.added", { output_index: outputIndex, item: { type:"reasoning", id, summary:[] } });
475
+ await emitEvent("response.reasoning_summary_part.added", { item_id:id, output_index:outputIndex, summary_index:0, part:{ type:"summary_text", text:"" } });
476
+ }
477
+ reasoningItem.text += text;
478
+ await emitEvent("response.reasoning_summary_text.delta", { item_id:reasoningItem.id, output_index:reasoningItem.outputIndex, summary_index:0, delta:text });
479
+ }
480
+
465
481
  const emitTerminal = async () => {
466
482
  const terminal = chatTerminal(finishReason);
467
483
  if (allowed && terminal.status === "completed" && ([...toolCalls.values()].some(tool => !allowed.has(tool.name)) || allowedRequired && !toolCalls.size)) throw disallowedUpstreamTool();
468
- if (!messageItem && toolCalls.size === 0) await ensureMessageItem();
484
+ if (!messageItem && !reasoningItem && toolCalls.size === 0) await ensureMessageItem();
469
485
  const output = [];
486
+ if (reasoningItem) {
487
+ const { id, text, outputIndex } = reasoningItem;
488
+ const part = { type:"summary_text", text };
489
+ const item = { type:"reasoning", id, summary:[part] };
490
+ const details = { item_id:id, output_index:outputIndex, summary_index:0 };
491
+ await emitEvent("response.reasoning_summary_text.done", { ...details, text });
492
+ await emitEvent("response.reasoning_summary_part.done", { ...details, part });
493
+ await emitEvent("response.output_item.done", { output_index:outputIndex, item });
494
+ output[outputIndex] = item;
495
+ }
470
496
  if (messageItem) {
471
497
  const item = {
472
498
  type: "message",
@@ -556,11 +582,15 @@ export async function forwardToChat(chatReq, emitEvent, onDone, onError, options
556
582
  if (choice?.finish_reason) finishReason = choice.finish_reason;
557
583
  const delta = choice?.delta;
558
584
  if (!delta) continue;
559
- if (isChatOutputDelta(delta)) markPerformanceOutput();
560
- if (delta.content) {
561
- const message = await ensureMessageItem();
562
- fullText += delta.content;
563
- await emitEvent("response.output_text.delta", { output_index: message.outputIndex, content_index: 0, delta: delta.content });
585
+ const parts = chatOutputParts(delta.content);
586
+ if (parts.length || isChatOutputDelta(delta)) markPerformanceOutput();
587
+ for (const { text, thought } of parts) {
588
+ if (thought) await appendReasoning(text);
589
+ else {
590
+ const message = await ensureMessageItem();
591
+ fullText += text;
592
+ await emitEvent("response.output_text.delta", { output_index: message.outputIndex, content_index: 0, delta: text });
593
+ }
564
594
  }
565
595
  if (delta.tool_calls) {
566
596
  for (const tc of delta.tool_calls) {
package/src/shutdown.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  export async function closeHttpServer(server, { timeoutMs = 5000 } = {}) {
2
2
  server?.ccdxCloseActivity?.();
3
- if (!server?.listening) return { forced: false };
3
+ if (!server?.listening) {
4
+ await server?.ccdxDrainBackground?.();
5
+ return { forced: false };
6
+ }
4
7
 
5
8
  return new Promise((resolve, reject) => {
6
9
  let settled = false;
@@ -26,5 +29,5 @@ export async function closeHttpServer(server, { timeoutMs = 5000 } = {}) {
26
29
  if (e?.code === "ERR_SERVER_NOT_RUNNING") finish(null);
27
30
  else finish(e);
28
31
  }
29
- });
32
+ }).finally(() => server.ccdxDrainBackground?.());
30
33
  }
@@ -0,0 +1,111 @@
1
+ import path from "node:path";
2
+ import { execFile, spawn } from "node:child_process";
3
+ import { promisify } from "node:util";
4
+ import { windowsPowerShellEnvironment } from "./windows-process.mjs";
5
+
6
+ const execute = promisify(execFile);
7
+ // Extracted from Google's Authenticode-bearing Antigravity App installers, not the IDE.
8
+ // Windows App payload identity is verified against all three routing components.
9
+ // https://antigravity.google/download
10
+ const officialBundles = new Map([
11
+ ["fdf8a0a6af474d54301740bdf0144d95a30be3105d96a2cb39bb8086278513ac", [
12
+ "9f0aad7274795d7fbde04931d96b348dcfc5f3d81d7373e6b70aeb09307442df",
13
+ "73ce9a2405b455a93d1f13db2ae555da50406110217a349b6dd85c377fbdb9d1",
14
+ ]],
15
+ ["ec43b6ade67822195c8529c99468bddc10baa5de1aaeccaa8e55f9d79fd03ff7", [
16
+ "9f0aad7274795d7fbde04931d96b348dcfc5f3d81d7373e6b70aeb09307442df",
17
+ "3ab260e0e1bed6e2c86eab13f385200f62e26c33f27174f485ddae21933c4f74",
18
+ ]],
19
+ ]);
20
+
21
+ const inventory = String.raw`
22
+ [Console]::OutputEncoding=[Text.UTF8Encoding]::new($false)
23
+ $ErrorActionPreference='Stop'
24
+ $paths=@()
25
+ if($env:CCDX_AGY_INSPECT_APP){$paths=@($env:CCDX_AGY_INSPECT_APP)}
26
+ else{
27
+ if($env:LOCALAPPDATA){$paths+=Join-Path $env:LOCALAPPDATA 'Programs\Antigravity\Antigravity.exe'}
28
+ if($env:ProgramFiles){$paths+=Join-Path $env:ProgramFiles 'Antigravity\Antigravity.exe'}
29
+ $keys=@('HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
30
+ 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
31
+ 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*')
32
+ foreach($entry in (Get-ItemProperty -Path $keys -ErrorAction SilentlyContinue)){
33
+ if($entry.DisplayName -ne 'Antigravity' -or $entry.Publisher -notin @('Google','Google LLC')){continue}
34
+ if($entry.InstallLocation){$paths+=Join-Path $entry.InstallLocation 'Antigravity.exe'}
35
+ if($entry.DisplayIcon -match '^\s*"?([a-z]:\\[^"]*\\Antigravity\.exe)"?(?:,\d+)?\s*$'){$paths+=$Matches[1]}
36
+ }
37
+ }
38
+ $rows=@(foreach($p in ($paths|Sort-Object -Unique)){
39
+ if($p -notmatch '^[a-z]:\\' -or [IO.Path]::GetFileName($p) -ne 'Antigravity.exe'){continue}
40
+ $item=Get-Item -LiteralPath $p -ErrorAction SilentlyContinue
41
+ if(!$item -or $item.PSIsContainer){continue}
42
+ $v=$item.VersionInfo
43
+ if($v.ProductName -ne 'Antigravity' -or $v.CompanyName -notin @('Google','Google LLC')){continue}
44
+ $helper=Join-Path $item.DirectoryName 'resources\bin\language_server.exe'
45
+ $asar=Join-Path $item.DirectoryName 'resources\app.asar'
46
+ if(!(Test-Path -LiteralPath $helper -PathType Leaf) -or !(Test-Path -LiteralPath $asar -PathType Leaf)){continue}
47
+ $row=@{app=$item.FullName;helper=$helper;version=$v.ProductVersion}
48
+ if($env:CCDX_AGY_INSPECT_APP){
49
+ $before=@($item, (Get-Item -LiteralPath $asar), (Get-Item -LiteralPath $helper))
50
+ $row.hashes=@(foreach($f in $before){(Get-FileHash -LiteralPath $f.FullName -Algorithm SHA256).Hash})
51
+ foreach($f in $before){
52
+ $after=Get-Item -LiteralPath $f.FullName
53
+ if($after.Length -ne $f.Length -or $after.LastWriteTimeUtc -ne $f.LastWriteTimeUtc){throw 'Antigravity files changed during verification'}
54
+ }
55
+ $row.pids=@(Get-CimInstance Win32_Process -Filter "Name = 'Antigravity.exe'" |
56
+ Where-Object { $_.ExecutablePath -eq $item.FullName } | ForEach-Object { [int]$_.ProcessId })
57
+ if($env:APPDATA){
58
+ $state=Get-Item -LiteralPath (Join-Path $env:APPDATA 'Antigravity\wsl_state.json') -ErrorAction SilentlyContinue
59
+ if($state -and $state.Length -le 16384){
60
+ try {$row.wsl=[bool]((Get-Content -Raw -LiteralPath $state.FullName | ConvertFrom-Json).distro)}catch{}
61
+ }
62
+ }
63
+ }
64
+ $row
65
+ })
66
+ ConvertTo-Json -InputObject @($rows) -Depth 4 -Compress
67
+ `;
68
+
69
+ export const windowsAntigravityPath = value => typeof value === "string" && /^[a-z]:\\/i.test(value)
70
+ && path.win32.normalize(value) === value && path.win32.basename(value).toLowerCase() === "antigravity.exe";
71
+
72
+ export async function inspectWindowsAntigravity({ env = process.env, exec = execute, app } = {}) {
73
+ if (app !== undefined && !windowsAntigravityPath(app)) throw new Error("Unrecognized Antigravity App location");
74
+ const command = path.win32.join(env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
75
+ const childEnv = windowsPowerShellEnvironment({ ...env, CCDX_AGY_INSPECT_APP: app || "" });
76
+ const { stdout } = await exec(command, ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", inventory],
77
+ { env: childEnv, encoding: "utf8", timeout: app ? 15000 : 3000, maxBuffer: 64 * 1024, windowsHide: true });
78
+ const value = JSON.parse(stdout);
79
+ const rows = Array.isArray(value) ? value.filter(row => windowsAntigravityPath(row?.app)
80
+ && (!app || row.app.toLowerCase() === app.toLowerCase())
81
+ && typeof row.version === "string" && /^[0-9][0-9A-Za-z.+_-]{0,63}$/.test(row.version)) : [];
82
+ const distinct = [...new Map(rows.map(row => [row.app.toLowerCase(), row])).values()];
83
+ if (distinct.length !== 1) return { status: distinct.length ? "multiple" : "not_installed" };
84
+ const row = distinct[0], executable = row.app,
85
+ helper = path.win32.join(path.win32.dirname(executable), "resources", "bin", "language_server.exe");
86
+ const result = { app: executable, target: executable, executable, helper, version: row.version };
87
+ if (!app) return result;
88
+ const hashes = Array.isArray(row.hashes) && row.hashes.length === 3 ? row.hashes.map(value => String(value).toLowerCase()) : [];
89
+ const expected = officialBundles.get(hashes[0]);
90
+ if (!expected || expected.some((value, i) => hashes[i+1] !== value)) return { ...result, status: "unknown" };
91
+ const pids = Array.isArray(row.pids) ? row.pids.filter(pid => Number.isSafeInteger(pid) && pid > 0) : [];
92
+ return { ...result, status: pids.length ? "running" : "stopped", pids, wsl: row.wsl === true };
93
+ }
94
+
95
+ export function windowsAntigravityEnvironment(env, url) {
96
+ const launch = Object.fromEntries(Object.entries(env).filter(([name]) =>
97
+ /^(PATH|SYSTEMROOT|SYSTEMDRIVE|WINDIR|COMSPEC|PATHEXT|LOCALAPPDATA|APPDATA|TEMP|TMP|USERPROFILE|HOMEDRIVE|HOMEPATH|USERNAME|USERDOMAIN|PROGRAMDATA|PROGRAMFILES(?:\(X86\))?|PROGRAMW6432|PROCESSOR_ARCHITECTURE|NUMBER_OF_PROCESSORS|OS|LANG|LC_ALL|TZ|(?:HTTP|HTTPS|ALL|NO)_PROXY|ANTIGRAVITY_WSL_DISTRO)$/i.test(name)));
98
+ if (url) launch.CLOUD_CODE_URL = url;
99
+ return launch;
100
+ }
101
+
102
+ export async function launchWindowsAntigravity(plan, { spawnImpl = spawn } = {}) {
103
+ return new Promise((resolve, reject) => {
104
+ const child = spawnImpl(plan.command, plan.args, {
105
+ cwd: path.win32.dirname(plan.command), env: plan.environment,
106
+ detached: true, stdio: "ignore", shell: false,
107
+ });
108
+ child.once("error", reject);
109
+ child.once("spawn", () => { child.unref();resolve(); });
110
+ });
111
+ }