probe-research 0.31.0 → 0.33.0

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.
@@ -831,11 +831,14 @@ function sleep(ms) {
831
831
  }
832
832
 
833
833
  /** Run an agent's call (`step`) under the backstop; a call it had to stop answers `run_again` (75). */
834
- async function runAgentCall(cmd, cmdArgs, startedMs, step) {
834
+ async function runAgentCall(cmd, cmdArgs, startedMs, step, watch = null) {
835
835
  const ran = await agentRun.runWithBackstop(cmd, cmdArgs, { deadlineMs: startedMs + agentRun.AGENT_BUDGET_MS });
836
836
  if (ran.stopped) {
837
+ // `sign-in --wait`'s (fixes-1108): a call stopped unsaved still says whether the person approved, read once
838
+ // after the CLI is gone, so the agent never says "still waiting" to someone who approved.
839
+ if (watch) await watch.update();
837
840
  await refuseAgent(step, agentRun.Reason.RUN_AGAIN, "Stopped at the agent's time limit: run the same command again.",
838
- agentRun.EXIT_AGAIN);
841
+ agentRun.EXIT_AGAIN, watch ? watch.getFacts() : {});
839
842
  }
840
843
  if (ran.error) await refuseAgent(step, agentRun.Reason.INCOMPLETE, `could not run ${cmd}: ${ran.error}`, 1);
841
844
  if (SHIM_REASONS[ran.code]) {
@@ -910,11 +913,31 @@ async function waitForRunningDownload(startedMs, step, watch = null) {
910
913
  const isRunning = record && record.state === download.DownloadState.RUNNING;
911
914
  await updateWatch(watch, step, isRunning ? record.stage || download.DownloadStage.DOWNLOADING : null);
912
915
  if (!isRunning) return record;
913
- if (Date.now() >= until) await refuseUnfinished(step, watch, record.stage || download.DownloadStage.DOWNLOADING);
916
+ // Not approved yet: the approval is read on to the budget's end, the download with it (fixes-1108b).
917
+ if (Date.now() >= (watch && watch.isPending() ? getWatchEndMs(startedMs) : until)) {
918
+ await refuseUnfinished(step, watch, record.stage || download.DownloadStage.DOWNLOADING);
919
+ }
914
920
  await sleep(DOWNLOAD_POLL_MS);
915
921
  }
916
922
  }
917
923
 
924
+ /** When a call still waiting for the approval stops reading it: its last read and its answer inside the budget. */
925
+ function getWatchEndMs(startedMs) {
926
+ return startedMs + agentRun.AGENT_BUDGET_MS - agentRun.CLI_MARGIN_MS - signIn.APPROVAL_TIMEOUT_MS;
927
+ }
928
+
929
+ /**
930
+ * Not approved yet, with no time left to hand the CLI anything: the approval is read here until the budget's end,
931
+ * so a call waits for it the whole budget and never answers `waiting_for_approval` early (fixes-1108b). An approval
932
+ * that comes meanwhile while Probe still installs is answered at once, as PR39b's.
933
+ */
934
+ async function watchUntilBudgetEnd(watch, startedMs, step, stage) {
935
+ while (watch && watch.isPending() && Date.now() + DOWNLOAD_POLL_MS < getWatchEndMs(startedMs)) {
936
+ await sleep(DOWNLOAD_POLL_MS);
937
+ await updateWatch(watch, step, stage);
938
+ }
939
+ }
940
+
918
941
  /**
919
942
  * Read `watch` and report `stage` (none without a watch). The approval read while Probe still installs is
920
943
  * answered at once (PR39b): `downloading` with `approved`, who and the stage's `say`, so the agent says it
@@ -1036,13 +1059,22 @@ async function waitForSignIn(json, startedMs) {
1036
1059
  // Read only while it waited for the install: a `probe` already here is handed the sign-in at once.
1037
1060
  if (watch.hasWatched()) await sayInstalled(watch, startedMs);
1038
1061
  return runAgentCall(probe, ["wizard", "--action", "login", "--pending", ...(json ? ["--json"] : [])], startedMs,
1039
- AgentStep.SIGN_IN_WAIT);
1062
+ AgentStep.SIGN_IN_WAIT, watch);
1040
1063
  }
1041
1064
 
1042
- /** Probe installed during the wait (PR39): approved, say so, and hand the CLI the save only with time for it. */
1065
+ /** Probe installed during the wait (PR39): approved, say so, and hand the CLI the save only with time for it. Too
1066
+ * little left and not approved yet: the approval is waited for here (fixes-1108b), never handed to a CLI that would
1067
+ * answer `waiting_for_approval` the moment it started. */
1043
1068
  async function sayInstalled(watch, startedMs) {
1044
1069
  await updateWatch(watch, AgentStep.SIGN_IN_WAIT, approval.InstallStage.DONE);
1045
- if (!watch.isApproved() || startedMs + agentRun.AGENT_BUDGET_MS - Date.now() >= APPROVED_RESERVE_MS) return;
1070
+ if (startedMs + agentRun.AGENT_BUDGET_MS - Date.now() >= APPROVED_RESERVE_MS) return;
1071
+ await watchUntilBudgetEnd(watch, startedMs, AgentStep.SIGN_IN_WAIT, approval.InstallStage.DONE);
1072
+ if (watch.isPending()) {
1073
+ await refuseAgent(AgentStep.SIGN_IN_WAIT, agentRun.Reason.WAITING_FOR_APPROVAL,
1074
+ "Waiting for the browser approval: run this again.", agentRun.EXIT_AGAIN,
1075
+ watch.getRunAgainFacts(approval.InstallStage.DONE));
1076
+ }
1077
+ if (!watch.isApproved()) return;
1046
1078
  watch.markSaid(approval.InstallStage.DONE);
1047
1079
  await refuseAgent(AgentStep.SIGN_IN_WAIT, agentRun.Reason.RUN_AGAIN,
1048
1080
  "Probe is installed, with too little time left to save the sign-in: run the same command again.",
@@ -1065,6 +1097,7 @@ async function getAgentProbe(startedMs, step, watch = null) {
1065
1097
  if (!probe && done && done.state === download.DownloadState.DONE) {
1066
1098
  // Installed, but its `probe` did not answer yet: the Probe service it just started restarts
1067
1099
  // once for its first update, and `probe --version` goes through it (PR3b dry run, 1 in 4).
1100
+ await watchUntilBudgetEnd(watch, startedMs, step, approval.InstallStage.STARTING);
1068
1101
  await refuseUnfinished(step, watch, approval.InstallStage.STARTING,
1069
1102
  "Probe is finishing its install: run the same command again.");
1070
1103
  }
package/lib/sign-in.js CHANGED
@@ -359,6 +359,7 @@ async function fetchApproval(pending, { fetchImpl = fetch, timeoutMs = APPROVAL_
359
359
 
360
360
  module.exports = {
361
361
  AGENT_CLIENT_CONTEXT,
362
+ APPROVAL_TIMEOUT_MS,
362
363
  AGENT_MARKERS,
363
364
  AGENT_GRANTS,
364
365
  ACCOUNT_NAME,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "probe-research",
3
- "version": "0.31.0",
3
+ "version": "0.33.0",
4
4
  "description": "Setup wizard for Probe Research in your coding agents. Runs from zero with npx.",
5
5
  "bin": {
6
6
  "probe-research": "bin/probe-research.js"