agent-valley 3.0.2 → 3.0.4

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "av",
4
- "version": "3.0.2",
4
+ "version": "3.0.4",
5
5
  "description": "Delegate repository goals to Agent Valley and inspect mission progress and verification evidence.",
6
6
  "author": {
7
7
  "name": "Agent Valley"
package/dist/index.js CHANGED
@@ -16358,13 +16358,26 @@ function buildAgentEnv(agentType, extra = {}, source = process.env) {
16358
16358
  }
16359
16359
  return { ...env, ...extra };
16360
16360
  }
16361
- function waitForExit(proc) {
16361
+ function waitForReap(proc, timeoutMs) {
16362
+ if (proc.exitCode !== null || proc.signalCode != null)
16363
+ return Promise.resolve(true);
16362
16364
  return new Promise((resolve) => {
16363
- if (proc.exitCode !== null || proc.signalCode != null) {
16364
- resolve();
16365
- return;
16366
- }
16367
- proc.once("close", () => resolve());
16365
+ let settled = false;
16366
+ const finish = (exited) => {
16367
+ if (settled)
16368
+ return;
16369
+ settled = true;
16370
+ clearTimeout(timer);
16371
+ proc.off("exit", onExit);
16372
+ proc.off("close", onExit);
16373
+ resolve(exited);
16374
+ };
16375
+ const onExit = () => finish(true);
16376
+ const timer = setTimeout(() => finish(false), timeoutMs);
16377
+ proc.once("exit", onExit);
16378
+ proc.once("close", onExit);
16379
+ if (proc.exitCode !== null || proc.signalCode != null)
16380
+ onExit();
16368
16381
  });
16369
16382
  }
16370
16383
  function waitForStreamCompletion(proc, graceMs = 250) {
@@ -16414,6 +16427,7 @@ class BaseSession {
16414
16427
  config = null;
16415
16428
  startedAt = 0;
16416
16429
  _process = null;
16430
+ stopping = null;
16417
16431
  terminalEventReceived = false;
16418
16432
  processFailed = false;
16419
16433
  sandboxPlatform = null;
@@ -16421,6 +16435,8 @@ class BaseSession {
16421
16435
  return this._process;
16422
16436
  }
16423
16437
  set process(proc) {
16438
+ if (this._process !== proc)
16439
+ this.stopping = null;
16424
16440
  this._process = proc;
16425
16441
  if (!proc)
16426
16442
  this.sandboxPlatform = null;
@@ -16512,7 +16528,36 @@ class BaseSession {
16512
16528
  }
16513
16529
  async kill() {
16514
16530
  if (this.process)
16515
- signalProcessTree(this.process, "SIGKILL");
16531
+ await this.stopProcess(this.process);
16532
+ }
16533
+ stopProcess(proc) {
16534
+ if (this.stopping?.process === proc)
16535
+ return this.stopping.result;
16536
+ const result = this.terminateProcess(proc);
16537
+ this.stopping = { process: proc, result };
16538
+ return result;
16539
+ }
16540
+ async terminateProcess(proc) {
16541
+ if (!proc.pid)
16542
+ return;
16543
+ let signalError;
16544
+ try {
16545
+ signalProcessTree(proc, "SIGKILL");
16546
+ } catch (error) {
16547
+ if (error.code !== "EPERM")
16548
+ throw error;
16549
+ signalError = error;
16550
+ }
16551
+ if (!await waitForReap(proc, 5000)) {
16552
+ throw signalError ?? new Error(`Agent process ${proc.pid} did not exit within 5000ms after SIGKILL; inspect it before retrying.`);
16553
+ }
16554
+ if (signalError) {
16555
+ try {
16556
+ signalProcessTree(proc, "SIGKILL");
16557
+ } catch {
16558
+ throw signalError;
16559
+ }
16560
+ }
16516
16561
  }
16517
16562
  isAlive() {
16518
16563
  if (!this.process)
@@ -16520,12 +16565,8 @@ class BaseSession {
16520
16565
  return !this.processFailed && this.process.exitCode === null && this.process.signalCode == null;
16521
16566
  }
16522
16567
  async dispose() {
16523
- if (this.process) {
16524
- const wasAlive = this.isAlive();
16525
- signalProcessTree(this.process, "SIGKILL");
16526
- if (wasAlive)
16527
- await waitForExit(this.process);
16528
- }
16568
+ if (this.process)
16569
+ await this.stopProcess(this.process);
16529
16570
  this.listeners.clear();
16530
16571
  this.process = null;
16531
16572
  this.config = null;
@@ -16577,6 +16618,58 @@ var init_base_session = __esm(() => {
16577
16618
  ];
16578
16619
  });
16579
16620
 
16621
+ // ../../packages/core/src/sessions/codex-protocol.ts
16622
+ function closeInputAndJoin(proc) {
16623
+ return new Promise((resolve, reject) => {
16624
+ let inputError;
16625
+ const onInputError = (error) => {
16626
+ inputError = error;
16627
+ };
16628
+ const cleanup = () => {
16629
+ clearTimeout(timer);
16630
+ proc.off("close", onClose);
16631
+ proc.stdin?.off("error", onInputError);
16632
+ };
16633
+ const onClose = () => {
16634
+ cleanup();
16635
+ if (proc.exitCode === 0 && proc.signalCode == null)
16636
+ resolve();
16637
+ else
16638
+ reject(new Error(`Codex shutdown exited with ${proc.signalCode ?? proc.exitCode ?? "unknown"}.`, {
16639
+ cause: inputError
16640
+ }));
16641
+ };
16642
+ const timer = setTimeout(() => {
16643
+ cleanup();
16644
+ reject(new Error("Codex did not exit within 5 seconds of closing its input.", { cause: inputError }));
16645
+ }, 5000);
16646
+ timer.unref();
16647
+ proc.once("close", onClose);
16648
+ proc.stdin?.on("error", onInputError);
16649
+ try {
16650
+ if (!proc.stdin)
16651
+ throw new Error("Codex stdin pipe is unavailable.");
16652
+ proc.stdin.end();
16653
+ } catch (error) {
16654
+ cleanup();
16655
+ reject(error);
16656
+ }
16657
+ });
16658
+ }
16659
+ function extractTokenUsage(params, defaultModel) {
16660
+ if (!params)
16661
+ return;
16662
+ const usage = params.usage;
16663
+ if (!usage)
16664
+ return;
16665
+ const input = usage.input ?? usage.input_tokens ?? usage.prompt_tokens ?? 0;
16666
+ const output = usage.output ?? usage.output_tokens ?? usage.completion_tokens ?? 0;
16667
+ if (input === 0 && output === 0)
16668
+ return;
16669
+ const model = usage.model ?? params.model ?? defaultModel ?? "codex";
16670
+ return { input, output, model };
16671
+ }
16672
+
16580
16673
  // ../../packages/core/src/sessions/json-lines.ts
16581
16674
  function readJsonLines(stream, onEvent, onText) {
16582
16675
  const decoder = new TextDecoder;
@@ -16625,11 +16718,19 @@ var init_codex_session = __esm(() => {
16625
16718
  finalAnswer;
16626
16719
  completedMessage;
16627
16720
  phasedMessageSeen = false;
16721
+ cancellation;
16722
+ shutdown;
16723
+ shutdownFailure;
16724
+ executionPrepared = false;
16725
+ interruptCompletion;
16628
16726
  pendingResolvers = new Map;
16629
16727
  async start(config) {
16630
16728
  this.config = config;
16631
16729
  this.startedAt = Date.now();
16632
16730
  this.disposing = false;
16731
+ this.shutdown = undefined;
16732
+ this.shutdownFailure = undefined;
16733
+ this.executionPrepared = false;
16633
16734
  const args = ["app-server", "--listen", "stdio://"];
16634
16735
  if (config.model) {
16635
16736
  args.push("-c", `model=${JSON.stringify(config.model)}`);
@@ -16653,6 +16754,7 @@ var init_codex_session = __esm(() => {
16653
16754
  async execute(prompt) {
16654
16755
  if (!this.assertStarted())
16655
16756
  return;
16757
+ this.executionPrepared = true;
16656
16758
  this.filesChanged = [];
16657
16759
  this.outputTail = "";
16658
16760
  this.finalAnswer = undefined;
@@ -16678,16 +16780,52 @@ var init_codex_session = __esm(() => {
16678
16780
  this.turnId = turnResult.turn.id;
16679
16781
  }
16680
16782
  async cancel() {
16783
+ if (this.cancellation)
16784
+ return this.cancellation;
16785
+ const cancelling = this.cancelTurn();
16786
+ this.cancellation = cancelling;
16787
+ try {
16788
+ await cancelling;
16789
+ } finally {
16790
+ if (this.cancellation === cancelling)
16791
+ this.cancellation = undefined;
16792
+ }
16793
+ }
16794
+ async cancelTurn() {
16681
16795
  if (this.paused)
16682
16796
  await this.resume();
16683
- if (this.threadId && this.turnId) {
16684
- try {
16685
- await this.rpc("turn/interrupt", { threadId: this.threadId, turnId: this.turnId });
16686
- } catch {
16687
- await super.cancel();
16688
- }
16689
- } else {
16797
+ const threadId = this.threadId;
16798
+ const turnId = this.turnId;
16799
+ if (!threadId || !turnId) {
16800
+ await super.cancel();
16801
+ return;
16802
+ }
16803
+ let rejectCompletion;
16804
+ const completed = new Promise((resolve, reject) => {
16805
+ rejectCompletion = reject;
16806
+ this.interruptCompletion = { threadId, turnId, resolve, reject };
16807
+ });
16808
+ const timer = setTimeout(() => {
16809
+ rejectCompletion(new Error("Codex did not confirm turn completion within 5 seconds of interruption. Inspect and reconcile the task before retrying."));
16810
+ }, 5000);
16811
+ timer.unref();
16812
+ let requestFailed = false;
16813
+ try {
16814
+ await Promise.all([
16815
+ completed,
16816
+ this.rpc("turn/interrupt", { threadId, turnId }).catch((error) => {
16817
+ requestFailed = true;
16818
+ throw error;
16819
+ })
16820
+ ]);
16821
+ } catch (error) {
16822
+ if (!requestFailed || this.disposing)
16823
+ throw error;
16690
16824
  await super.cancel();
16825
+ } finally {
16826
+ clearTimeout(timer);
16827
+ if (this.interruptCompletion?.threadId === threadId && this.interruptCompletion.turnId === turnId)
16828
+ this.interruptCompletion = undefined;
16691
16829
  }
16692
16830
  }
16693
16831
  async pause() {
@@ -16741,9 +16879,43 @@ var init_codex_session = __esm(() => {
16741
16879
  input: [{ type: "text", text }]
16742
16880
  });
16743
16881
  }
16744
- async dispose() {
16882
+ async kill() {
16883
+ if (this.shutdownFailure)
16884
+ throw this.shutdownFailure;
16885
+ if (this.shutdown)
16886
+ return this.shutdown;
16887
+ const proc = this.process;
16888
+ if (!proc)
16889
+ return;
16745
16890
  this.disposing = true;
16746
16891
  this.rejectPending(new Error("Codex session disposed while waiting for an RPC response."));
16892
+ const shuttingDown = (async () => {
16893
+ if (!this.isAlive() && proc.pid && this.executionPrepared) {
16894
+ await this.forceUnconfirmedShutdown(new Error("Codex exited before graceful shutdown was joined. Inspect its command processes and reconcile the task before retrying."));
16895
+ }
16896
+ if (this.isAlive()) {
16897
+ try {
16898
+ await closeInputAndJoin(proc);
16899
+ } catch (error) {
16900
+ await this.forceUnconfirmedShutdown(new Error("Codex graceful shutdown was not confirmed. Inspect its command processes and reconcile the task before retrying.", { cause: error }));
16901
+ }
16902
+ }
16903
+ await super.kill();
16904
+ })();
16905
+ this.shutdown = shuttingDown;
16906
+ return shuttingDown;
16907
+ }
16908
+ async forceUnconfirmedShutdown(error) {
16909
+ this.shutdownFailure = error;
16910
+ try {
16911
+ await super.kill();
16912
+ } catch (forceError) {
16913
+ this.shutdownFailure = new AggregateError([error, forceError], error.message);
16914
+ }
16915
+ throw this.shutdownFailure;
16916
+ }
16917
+ async dispose() {
16918
+ await this.kill();
16747
16919
  await super.dispose();
16748
16920
  this.threadId = null;
16749
16921
  this.turnId = null;
@@ -16794,6 +16966,7 @@ var init_codex_session = __esm(() => {
16794
16966
  });
16795
16967
  }
16796
16968
  rejectPending(error) {
16969
+ this.interruptCompletion?.reject(error);
16797
16970
  for (const pending of this.pendingResolvers.values()) {
16798
16971
  clearTimeout(pending.timer);
16799
16972
  pending.reject(error);
@@ -16801,6 +16974,8 @@ var init_codex_session = __esm(() => {
16801
16974
  this.pendingResolvers.clear();
16802
16975
  }
16803
16976
  handleMessage(msg) {
16977
+ if (this.disposing)
16978
+ return;
16804
16979
  if (msg.id != null && this.pendingResolvers.has(msg.id)) {
16805
16980
  const resolver = this.pendingResolvers.get(msg.id);
16806
16981
  if (!resolver)
@@ -16891,6 +17066,13 @@ var init_codex_session = __esm(() => {
16891
17066
  const turn = msg.params?.turn;
16892
17067
  if (turn?.id && this.turnId && turn.id !== this.turnId)
16893
17068
  return;
17069
+ const interrupt = this.interruptCompletion;
17070
+ if (interrupt?.threadId === this.threadId && interrupt.turnId === turn?.id) {
17071
+ if (turn?.status && ["completed", "interrupted", "failed"].includes(turn.status))
17072
+ interrupt.resolve();
17073
+ else
17074
+ interrupt.reject(new Error("Codex interruption has no valid turn completion status. Inspect the task before retrying."));
17075
+ }
16894
17076
  this.turnId = null;
16895
17077
  if (turn?.status !== "completed") {
16896
17078
  this.emitError("CRASH", turn?.error?.message ?? `Codex turn ${turn?.status ?? "has no completion status"}. Check the agent output and retry.`, true);
@@ -16899,7 +17081,7 @@ var init_codex_session = __esm(() => {
16899
17081
  const output = this.finalAnswer ?? this.completedMessage ?? (this.phasedMessageSeen ? "" : this.outputTail);
16900
17082
  const result = this.buildRunResult(output, this.filesChanged);
16901
17083
  result.exitCode = 0;
16902
- const usage = this.tokenUsage ?? this.extractTokenUsage(msg.params);
17084
+ const usage = this.tokenUsage ?? extractTokenUsage(msg.params, this.config?.model);
16903
17085
  if (usage)
16904
17086
  result.tokenUsage = usage;
16905
17087
  this.emit({ type: "complete", result });
@@ -16919,19 +17101,6 @@ var init_codex_session = __esm(() => {
16919
17101
  this.emit({ type: "heartbeat", timestamp: new Date().toISOString() });
16920
17102
  }
16921
17103
  }
16922
- extractTokenUsage(params) {
16923
- if (!params)
16924
- return;
16925
- const usage = params.usage;
16926
- if (!usage)
16927
- return;
16928
- const input = usage.input ?? usage.input_tokens ?? usage.prompt_tokens ?? 0;
16929
- const output = usage.output ?? usage.output_tokens ?? usage.completion_tokens ?? 0;
16930
- if (input === 0 && output === 0)
16931
- return;
16932
- const model = usage.model ?? params.model ?? this.config?.model ?? "codex";
16933
- return { input, output, model };
16934
- }
16935
17104
  };
16936
17105
  });
16937
17106
 
@@ -69845,6 +70014,12 @@ function context(mission) {
69845
70014
  }
69846
70015
  function planPrompt(mission) {
69847
70016
  const chief = mission.personas.find((persona) => persona.id === mission.chiefId);
70017
+ const responseKeys = [
70018
+ "tasks",
70019
+ ...mission.availableAgents ? ["actors"] : [],
70020
+ ...mission.supervision ? ["goalBrief"] : [],
70021
+ ...mission.verificationMode === "chief" ? ["verificationContract"] : []
70022
+ ];
69848
70023
  return [
69849
70024
  "You are the Chief Director coordinating this mission. Understand the user's intent and the actual business and product context, then decide a strategy and plan the requested work.",
69850
70025
  CHIEF_DIRECTOR_ROLE,
@@ -69881,6 +70056,8 @@ function planPrompt(mission) {
69881
70056
  `Verified installed OMA skill catalog (JSON data): ${JSON.stringify(mission.availableSkills.map(({ name, description }) => ({ name, description: description.slice(0, 300) })))}`,
69882
70057
  "Select only needed catalog skill names for each generated Actor. No invented names or paths; the runtime supplies selected skill files. Skill access does not extend publication, spending or file-change authorization."
69883
70058
  ] : [],
70059
+ `Allowed top-level response keys for this mode: ${JSON.stringify(responseKeys)}. Return no other root keys.`,
70060
+ "Mission input identity fields are metadata, not response fields. Do not copy chiefId, technicalLeadId, designLeadId or marketingLeadId into the response root, or copy other Mission metadata. When generating a roster, retain nominated companions only as entries in actors with their supplied ids. With a fixed roster, use configured Actor ids without returning actors.",
69884
70061
  ...mission.availableAgents ? [
69885
70062
  `The operator's Chief Director CLI is fixed: ${JSON.stringify({ id: mission.chiefId, actorType: chief?.agentType })}. Do not replace it with another vendor. Omit model from every response Actor; the scheduler retains the selected Chief Director model and Actors use their CLI defaults.`,
69886
70063
  mission.availableSkills?.length ? "Select relevant skills only from the verified installed catalog. Assign tasks to generated Actor ids. Return actors, tasks and the requested goalBrief together in one JSON object within the 8,000-character limit." : "Set skills: [] because no installed skill capabilities were supplied; describe expertise in role. Assign tasks to generated Actor ids. Return actors, tasks and any requested goalBrief together in one JSON object within the 8,000-character limit.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-valley",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=26.10.0",