@liy/agent-runner 0.2.0 → 0.2.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.
@@ -15506,6 +15506,7 @@ function buildPiRpcArgs(harness) {
15506
15506
  model,
15507
15507
  "--thinking",
15508
15508
  thinking,
15509
+ "--no-session",
15509
15510
  "--no-extensions",
15510
15511
  "--no-prompt-templates",
15511
15512
  "--no-themes",
@@ -15790,6 +15791,7 @@ async function runTaskAgentRunner(spec, options = {}) {
15790
15791
  spec,
15791
15792
  harness,
15792
15793
  channel,
15794
+ ...spec.timeouts?.taskMs !== void 0 ? { timeoutMs: spec.timeouts.taskMs } : {},
15793
15795
  ...options.env ? { env: options.env } : {}
15794
15796
  });
15795
15797
  sendTaskStatus(channel, {
@@ -15927,7 +15929,28 @@ async function runHarnessAndReadCompletion(input) {
15927
15929
  ...input.env ? { env: input.env } : {}
15928
15930
  })
15929
15931
  });
15930
- const result = await activeRun.result;
15932
+ const result = await waitForHarnessResult({
15933
+ run: activeRun,
15934
+ ...input.timeoutMs !== void 0 ? { timeoutMs: input.timeoutMs } : {}
15935
+ });
15936
+ if (result === "timeout") {
15937
+ activeRun.cancel();
15938
+ await waitForHarnessCleanup(activeRun.result);
15939
+ const recovered = await readTaskCompletion(paths).catch(() => void 0);
15940
+ if (recovered) {
15941
+ await validateTaskArtifactFiles({
15942
+ paths,
15943
+ completion: recovered
15944
+ });
15945
+ return recovered;
15946
+ }
15947
+ const completion2 = createTimeoutCompletion(input.timeoutMs);
15948
+ await writeTaskCompletion({
15949
+ paths,
15950
+ completion: completion2
15951
+ });
15952
+ return completion2;
15953
+ }
15931
15954
  if (cancelRequested) {
15932
15955
  const completion2 = {
15933
15956
  status: "cancelled",
@@ -15957,6 +15980,38 @@ async function runHarnessAndReadCompletion(input) {
15957
15980
  }
15958
15981
  return completion;
15959
15982
  }
15983
+ async function waitForHarnessResult(input) {
15984
+ const timeoutMs = normalizeTimeoutMs(input.timeoutMs);
15985
+ if (timeoutMs === void 0) {
15986
+ return input.run.result;
15987
+ }
15988
+ let timer;
15989
+ try {
15990
+ return await Promise.race([
15991
+ input.run.result,
15992
+ new Promise((resolve2) => {
15993
+ timer = setTimeout(() => resolve2("timeout"), timeoutMs);
15994
+ })
15995
+ ]);
15996
+ } finally {
15997
+ if (timer) {
15998
+ clearTimeout(timer);
15999
+ }
16000
+ }
16001
+ }
16002
+ async function waitForHarnessCleanup(result) {
16003
+ await Promise.race([
16004
+ result.catch(() => void 0),
16005
+ sleep(1e4)
16006
+ ]);
16007
+ }
16008
+ function createTimeoutCompletion(timeoutMs) {
16009
+ return {
16010
+ status: "failed",
16011
+ summary: timeoutMs === void 0 ? "execute_task harness timed out" : `execute_task harness timed out after ${timeoutMs}ms`,
16012
+ artifactIds: []
16013
+ };
16014
+ }
15960
16015
  function createMissingCompletionFailure(error48) {
15961
16016
  const detail = error48 instanceof Error ? error48.message : String(error48);
15962
16017
  return {
@@ -15978,6 +16033,9 @@ function validateRunnerSpec(spec) {
15978
16033
  if (!spec.rpcUrl?.trim()) {
15979
16034
  throw new Error("task spec rpcUrl is required");
15980
16035
  }
16036
+ if (spec.timeouts?.taskMs !== void 0 && normalizeTimeoutMs(spec.timeouts.taskMs) === void 0) {
16037
+ throw new Error("task spec timeouts.taskMs must be a positive finite number");
16038
+ }
15981
16039
  if (spec.agentRunner?.harness !== void 0 && typeof spec.agentRunner.harness !== "string") {
15982
16040
  throw new Error("task spec agentRunner.harness must be a string");
15983
16041
  }
@@ -15990,6 +16048,14 @@ function validateRunnerSpec(spec) {
15990
16048
  }
15991
16049
  assertNoForbiddenSpecKeys(spec);
15992
16050
  }
16051
+ function normalizeTimeoutMs(value) {
16052
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
16053
+ }
16054
+ function sleep(ms) {
16055
+ return new Promise((resolve2) => {
16056
+ setTimeout(resolve2, ms);
16057
+ });
16058
+ }
15993
16059
  async function openControlChannel(url2) {
15994
16060
  const WebSocketCtor = globalThis.WebSocket;
15995
16061
  if (!WebSocketCtor) {