zapagent 1.14.28 → 1.14.30

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.
@@ -27,6 +27,7 @@ export interface AcpTurnOptions {
27
27
  /** Event path prefix for nested rendering (subagent path). */
28
28
  path?: string[];
29
29
  onEvent?: (event: AgentEvent) => void;
30
+ onContextUsage?: (usage: { used: number; size: number }) => void;
30
31
  }
31
32
 
32
33
  export interface AcpTurnResult {
@@ -84,6 +85,7 @@ export class AcpAgentSession {
84
85
  }
85
86
  const mode = options.mode ?? spec.mode;
86
87
  if (mode) await session.attempt(`mode ${mode}`, () => connection.setMode(session.sessionId, mode));
88
+ if (spec.requireSettings && session.warnings.length) throw new Error(session.warnings.join("; "));
87
89
  return session;
88
90
  } catch (error) {
89
91
  await connection.close();
@@ -100,7 +102,10 @@ export class AcpAgentSession {
100
102
  async prompt(content: string | ContentBlock[], options: AcpTurnOptions = {}): Promise<AcpTurnResult> {
101
103
  const mapper = new AcpEventMapper(options.path ?? []);
102
104
  const emit = (events: AgentEvent[]) => { for (const event of events) options.onEvent?.(event); };
103
- this.turn = update => emit(mapper.map(update));
105
+ this.turn = update => {
106
+ emit(mapper.map(update));
107
+ if (update.sessionUpdate === "usage_update" && mapper.contextUsage) options.onContextUsage?.(mapper.contextUsage);
108
+ };
104
109
  const blocks = typeof content === "string" ? [{ type: "text" as const, text: content }] : content;
105
110
  let response;
106
111
  try {
@@ -26,6 +26,8 @@ export interface AcpAgentSpec {
26
26
  model?: string;
27
27
  /** Session mode to select after session/new (`session/set_mode`). */
28
28
  mode?: string;
29
+ /** Reject the session if a requested mode, model or config option is refused. */
30
+ requireSettings?: boolean;
29
31
  /** Session config options to apply after session/new
30
32
  * (`session/set_config_option`), e.g. `{ thought_level: "high" }`. */
31
33
  config?: Record<string, string>;
@@ -1,4 +1,5 @@
1
- import { spawn, type ChildProcess } from "node:child_process";
1
+ import { join } from "node:path";
2
+ import { spawnSync, spawn, type ChildProcess } from "node:child_process";
2
3
  import { localExecutionShell } from "./shell.js";
3
4
  import { readProcessTable, snapshotDescendants } from "./process-tree.js";
4
5
  import type {
@@ -135,7 +136,13 @@ export function terminateProcessTree(
135
136
  let delivered = false;
136
137
  const killChild = () => child.exitCode === null && child.signalCode === null && child.kill(signal);
137
138
  try {
138
- if (process.platform === "win32" || !child.pid) delivered = killChild();
139
+ if (process.platform === "win32" && (signal === "SIGTERM" || signal === "SIGKILL") && child.pid && child.exitCode === null && child.signalCode === null) {
140
+ const systemRoot = process.env.SystemRoot ?? "C:\\Windows";
141
+ const result = spawnSync(join(systemRoot, "System32", "taskkill.exe"), ["/PID", String(child.pid), "/T", "/F"], {
142
+ stdio: "ignore", windowsHide: true, timeout: 3000,
143
+ });
144
+ delivered = result.status === 0 || killChild();
145
+ } else if (!child.pid || process.platform === "win32") delivered = killChild();
139
146
  // The group can outlive its leader and keep stdout/stderr open. A leader's
140
147
  // exit must not suppress escalation to surviving descendants.
141
148
  else delivered = process.kill(-child.pid, signal);