probe-research 0.27.0 → 0.29.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.
@@ -36,6 +36,8 @@ const approval = require("../lib/approval-watch");
36
36
  const download = require("../lib/background-download");
37
37
  const setupCheck = require("../lib/setup-check");
38
38
  const signIn = require("../lib/sign-in");
39
+ /** Probe's own upkeep (`PROBE_UPKEEP`), as `make sync-probe-upkeep` writes it from the CLI's flags. */
40
+ const upkeep = require("../upkeep.json");
39
41
 
40
42
  const DIST = "probe-research";
41
43
  /** The compiled CLI `probe-research[all]` pins to its own version since the split (the CLI's `_entry.CLI_DIST`). */
@@ -140,8 +142,14 @@ const FIX_MIN = "0.385.0";
140
142
  * sign-out and agent removal (`isMenuChange`), and Change settings' `install` keeping this chat's own switch;
141
143
  * 0.439.0 was cut before it merged. Launcher 0.23.0 carries it (0.22.0 was already on npm, so #4456's own
142
144
  * floor never published).
145
+ * 0.452.0 since fixes-1107b PR A (#4522): the pages' upkeep runs from any chat (`PROBE_UPKEEP`), what records
146
+ * less takes `--directed`, and this chat's switch is `session state <target> --directed`; an older CLI's gate
147
+ * refuses those from a chat the daemon records (`daemon_chat`). `needsAgentCli` covers every one of them.
148
+ * 0.457.0 since fixes-1107b T4 + T6a (#4527): the pages' `import review --chats-*` narrowing (big-history.md),
149
+ * T5's `wandb key request|receive` (0.454.0), PR B's `notice`/`notices` and `--sessions missed` (0.454.0), and
150
+ * PR C's confirmed `service stop` (0.455.0); 0.456.0 was cut before #4527 merged.
143
151
  */
144
- const AGENT_MIN_CLI = "0.445.0";
152
+ const AGENT_MIN_CLI = "0.457.0";
145
153
  /** `install` flags only AGENT_MIN_CLI knows (D36). */
146
154
  const AGENT_INSTALL_FLAGS = Object.freeze(["--recommended", "--who-records", "--session-default", "--profile",
147
155
  "--attempt"]);
@@ -744,6 +752,10 @@ const BARRIER_FILE = [".local", "state", "probe", "uninstall", "barrier.json"];
744
752
  const AGENT_STATUS_FLAGS = Object.freeze(["--repaste-choice", "--past-work-choice"]);
745
753
  /** `import` verbs only AGENT_MIN_CLI has: bringing in past work (D49, D74). `import wandb` is older. */
746
754
  const AGENT_IMPORT_VERBS = Object.freeze(["folders", "review", "start", "status", "resume"]);
755
+ /** `session` verbs only AGENT_MIN_CLI takes from an agent: this chat's switch (T3) and the new-chat default (D102). */
756
+ const AGENT_SESSION_VERBS = Object.freeze(["state", "default"]);
757
+ /** The longest upkeep command, in words (`wandb key status`). */
758
+ const UPKEEP_MAX_WORDS = 3;
747
759
 
748
760
  /** The wizard action a `probe wizard` call names (`--action X` or `--action=X`), or null. */
749
761
  function getWizardAction(forwarded) {
@@ -762,8 +774,26 @@ function isMenuChange(forwarded) {
762
774
  return action === "logout" || (action === "uninstall" && forwarded.some((word) => word.split("=")[0] === "--agent"));
763
775
  }
764
776
 
765
- /** `probe` arguments only AGENT_MIN_CLI runs (D36). */
766
- function needsAgentCli(forwarded) {
777
+ /** Whether `probe` arguments are Probe's own upkeep (`upkeep.json`): a wizard by its action, else by its words. */
778
+ function isUpkeepCall(forwarded) {
779
+ if (forwarded[0] === LauncherVerb.WIZARD || forwarded[0] === "setup") {
780
+ return upkeep.wizard_actions.includes(getWizardAction(forwarded));
781
+ }
782
+ const end = forwarded.findIndex((word) => word.startsWith("-"));
783
+ const words = end < 0 ? forwarded : forwarded.slice(0, end);
784
+ for (let count = Math.min(UPKEEP_MAX_WORDS, words.length); count > 0; count--) {
785
+ if (Object.hasOwn(upkeep.commands, words.slice(0, count).join(" "))) return true;
786
+ }
787
+ return false;
788
+ }
789
+
790
+ /** An agent's spelling: the pages pass `--json`, and only an agent passes `--directed` (the person's yes). */
791
+ function isAgentSpelling(forwarded) {
792
+ return forwarded.includes("--json") || forwarded.includes("--directed");
793
+ }
794
+
795
+ /** The install prompt's own calls (D36): only AGENT_MIN_CLI runs them. */
796
+ function isPromptCall(forwarded) {
767
797
  if (forwarded[0] === "example") return true;
768
798
  if (forwarded[0] === "import") return AGENT_IMPORT_VERBS.includes(forwarded[1]);
769
799
  if (forwarded[0] === "status") return forwarded.some((word) => AGENT_STATUS_FLAGS.includes(word.split("=")[0]));
@@ -772,9 +802,18 @@ function needsAgentCli(forwarded) {
772
802
  || forwarded.some((word) => AGENT_INSTALL_FLAGS.includes(word.split("=")[0]));
773
803
  }
774
804
 
775
- /** An agent's call: one of those, answered as JSON, so it runs under the 110 s backstop. */
805
+ /** `probe` arguments only AGENT_MIN_CLI runs: the prompt's calls, and the pages' upkeep from an agent (T4). */
806
+ function needsAgentCli(forwarded) {
807
+ if (isPromptCall(forwarded)) return true;
808
+ if (forwarded[0] === "session") return AGENT_SESSION_VERBS.includes(forwarded[1]);
809
+ if (forwarded[0] === "wandb" && forwarded[1] === "key") return true;
810
+ return isUpkeepCall(forwarded) && isAgentSpelling(forwarded);
811
+ }
812
+
813
+ /** An agent's call: a prompt call answered as JSON, so it runs under the 110 s backstop. Upkeep keeps its own
814
+ * time (uninstall.md gives the uninstall 5 minutes). */
776
815
  function isAgentCall(forwarded) {
777
- return needsAgentCli(forwarded) && forwarded.includes("--json");
816
+ return isPromptCall(forwarded) && forwarded.includes("--json");
778
817
  }
779
818
 
780
819
  function isStatusJson(forwarded) {
@@ -929,6 +968,11 @@ async function runSignIn(rest, startedMs) {
929
968
  if (rest.includes("--wait")) return waitForSignIn(rest.includes("--json"), startedMs);
930
969
  if (hasBarrier()) await finishStoppedUninstall(deadlineMs);
931
970
  if (rest.includes(IF_NEEDED_FLAG)) await answerIfSetUp(deadlineMs);
971
+ const override = signIn.getServerOverride(process.env);
972
+ if (override) {
973
+ await refuseAgent(AgentStep.SIGN_IN, agentRun.Reason.SERVER_OVERRIDE, override, agentRun.EXIT_REFUSED,
974
+ { next: null, retry: "none", side_effects: "none" });
975
+ }
932
976
  const started = await signIn.startSignIn({ noBrowser: rest.includes("--no-browser") });
933
977
  if (!started.ok) await refuseAgent(AgentStep.SIGN_IN, agentRun.Reason.INCOMPLETE, started.message, 1);
934
978
  const downloading = findProbe(AGENT_MIN_CLI) ? "not_needed" : startBackgroundDownload();
package/lib/agent-run.js CHANGED
@@ -33,9 +33,12 @@ const Reason = Object.freeze({
33
33
  INCOMPLETE: "incomplete",
34
34
  RUN_AGAIN: "run_again",
35
35
  HOSTED_AGENT: "hosted_agent",
36
+ SERVER_OVERRIDE: "server_override",
37
+ SANDBOXED: "sandboxed",
36
38
  });
37
- /** Exit statuses: 75 means "run the same command again" (the CLI's `AGENT_EXIT_CODES`). */
39
+ /** Exit statuses: 75 means "run the same command again", 3 a refusal (the CLI's `AGENT_EXIT_CODES`). */
38
40
  const EXIT_AGAIN = 75;
41
+ const EXIT_REFUSED = 3;
39
42
  /** Every line's `v` (`probe.core.events.SCHEMA_VERSION`). */
40
43
  const SCHEMA_VERSION = 1;
41
44
  /** A line's `event`: the answer is the CLI's `done` (`probe.core.events.Event`); a line before it, `progress`. */
@@ -128,6 +131,7 @@ module.exports = {
128
131
  CLI_MARGIN_MS,
129
132
  DEADLINE_ENV,
130
133
  EXIT_AGAIN,
134
+ EXIT_REFUSED,
131
135
  Event,
132
136
  KILL_GRACE_MS,
133
137
  Reason,
package/lib/sign-in.js CHANGED
@@ -21,6 +21,9 @@ const STATE_FOLDER = [".local", "state", "probe", "agent-install"];
21
21
  const PENDING_NAME = "sign-in.json";
22
22
  const PENDING_VERSION = 1;
23
23
  const START_PATH = "/auth/device/code";
24
+ /** The server's last answer about each key, kept by the CLI (`agent_install.account`: ANSWER_NAME, ANSWER_VERSION). */
25
+ const ACCOUNT_NAME = "account.json";
26
+ const ACCOUNT_VERSION = 1;
24
27
  /** Where the waiting sign-in stands, read without exchanging it (PR39). */
25
28
  const STATUS_PATH = "/auth/device/status";
26
29
  /** The server's answers (`DeviceAuthorizationStatusOut.status`), and UNREADABLE: this server cannot say
@@ -112,14 +115,14 @@ function getSayLine(uri, code) {
112
115
  return `Approve Probe in your browser: ${uri} (code ${code})`;
113
116
  }
114
117
 
115
- /** The body of the agent's device request (the fixture's keys, nothing else). */
116
- function buildRequestBody({ challenge, deviceInstanceId, agent = null }) {
118
+ /** The body of the agent's device request (the fixture's keys, nothing else). `prior`: `loadPriorAccount`'s. */
119
+ function buildRequestBody({ challenge, deviceInstanceId, agent = null, prior = {} }) {
117
120
  const body = {
118
121
  token_name: `${TOKEN_NAME_PREFIX}${getHostname()}`,
119
122
  scopes: null,
120
123
  code_challenge: challenge,
121
124
  grants: [...AGENT_GRANTS],
122
- client_context: { ...AGENT_CLIENT_CONTEXT, ...(agent ? { agent } : {}) },
125
+ client_context: { ...AGENT_CLIENT_CONTEXT, ...(agent ? { agent } : {}), ...prior },
123
126
  };
124
127
  if (deviceInstanceId) body.device_instance_id = deviceInstanceId;
125
128
  return body;
@@ -156,12 +159,82 @@ function getSignInBase(env) {
156
159
  return DEFAULT_BASE;
157
160
  }
158
161
 
162
+ /** `url` as the CLI compares endpoints (`settings.normalize_endpoint`): scheme and host lower case, https's
163
+ * `:443` dropped, no trailing slash. */
164
+ function normalizeEndpoint(url) {
165
+ const text = String(url || "").trim().replace(/\/+$/, "");
166
+ const parts = /^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]+)([^?#]*)(.*)$/.exec(text);
167
+ if (!parts) return text;
168
+ const scheme = parts[1].toLowerCase();
169
+ const at = parts[2].lastIndexOf("@");
170
+ let host = parts[2].slice(at + 1).toLowerCase();
171
+ if (scheme === "https" && host.endsWith(":443")) host = host.slice(0, -4);
172
+ return `${scheme}://${parts[2].slice(0, at + 1)}${host}${parts[3].replace(/\/+$/, "")}${parts[4]}`;
173
+ }
174
+
175
+ /**
176
+ * Who this computer is signed in as, as the CLI last heard from the server (`account.json`, found by the
177
+ * active key's short sha256, never the key itself): `{ prior_email, prior_team_id }`, each only when known.
178
+ * Display only: the approval page says approving moves new work to another account or team (T7).
179
+ */
180
+ function loadPriorAccount(env) {
181
+ const active = loadActiveContext(env);
182
+ const token = active && typeof active.token === "string" ? active.token : "";
183
+ if (!token) return {};
184
+ try {
185
+ const data = JSON.parse(fs.readFileSync(path.join(getStateFolder(), ACCOUNT_NAME), "utf8"));
186
+ if (!data || data.v !== ACCOUNT_VERSION || !data.answers || typeof data.answers !== "object") return {};
187
+ const fingerprint = crypto.createHash("sha256").update(token).digest("hex").slice(0, 16);
188
+ const base = typeof active.base_url === "string" && active.base_url ? active.base_url : DEFAULT_BASE;
189
+ const answer = data.answers[`${normalizeEndpoint(base)} ${fingerprint}`];
190
+ if (!answer || answer.verdict !== "accepted") return {};
191
+ const prior = {};
192
+ if (typeof answer.email === "string" && answer.email) prior.prior_email = answer.email;
193
+ if (typeof answer.team_id === "string" && answer.team_id) prior.prior_team_id = answer.team_id;
194
+ return prior;
195
+ } catch {
196
+ return {};
197
+ }
198
+ }
199
+
159
200
  /** Is a sign-in saved here (the active account holds a key)? Only whether: the key itself is never read out. */
160
201
  function hasSavedSignIn(env) {
161
202
  const active = loadActiveContext(env);
162
203
  return Boolean(active && typeof active.token === "string" && active.token);
163
204
  }
164
205
 
206
+ /** An endpoint as two compare (the CLI's `settings.normalize_endpoint`): no trailing slash, scheme and host lower
207
+ * case, https's `:443` dropped; a string that is not a URL comes back stripped. */
208
+ function normalizeEndpoint(url) {
209
+ const text = String(url || "").trim().replace(/\/+$/, "");
210
+ const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/([^/?#]*)(.*)$/.exec(text);
211
+ if (!match || !match[2]) return text;
212
+ const scheme = match[1].toLowerCase();
213
+ const at = match[2].lastIndexOf("@");
214
+ const userinfo = at >= 0 ? match[2].slice(0, at + 1) : "";
215
+ let hostport = match[2].slice(at + 1).toLowerCase();
216
+ if (scheme === "https" && hostport.endsWith(":443")) hostport = hostport.slice(0, -":443".length);
217
+ return `${scheme}://${userinfo}${hostport}${match[3].replace(/\/+$/, "")}`;
218
+ }
219
+
220
+ /**
221
+ * `server_override` (fixes-1107b T2): the refusal when an agent's sign-in, on a computer signed in already, would
222
+ * point Probe at another server through `PROBE_BASE_URL` (read first by `getSignInBase`), else null. A tripwire, as
223
+ * the CLI's write gate: the person's own terminal (no agent) and a first install (no sign-in saved) are left alone.
224
+ */
225
+ function getServerOverride(env) {
226
+ const fromEnv = String(env.PROBE_BASE_URL || "").trim();
227
+ if (!fromEnv || !detectAgent(env) || !hasSavedSignIn(env)) return null;
228
+ const active = loadActiveContext(env);
229
+ const saved = normalizeEndpoint(typeof active.base_url === "string" && active.base_url.trim() ? active.base_url
230
+ : DEFAULT_BASE);
231
+ if (normalizeEndpoint(fromEnv) === saved) return null;
232
+ const shown = fromEnv.replace(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)[^/?#@]*@/, "$1"); // never a user:password part
233
+ return `\`npx -y probe-research sign-in\` would point Probe on this computer at ${shown} (\`PROBE_BASE_URL\` in this `
234
+ + `shell), so it was refused before it ran: from a chat, Probe keeps the server and account it is signed in to `
235
+ + `(${saved}). Tell the person what was refused and why; do not run it another way.`;
236
+ }
237
+
165
238
  /** `content` written whole into `file`, readable by this user only. */
166
239
  function savePrivate(file, content) {
167
240
  fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
@@ -194,7 +267,9 @@ function openBrowser(url, env) {
194
267
  async function startSignIn({ env = process.env, fetchImpl = fetch, noBrowser = false } = {}) {
195
268
  const base = getSignInBase(env);
196
269
  const { verifier, challenge } = makePkcePair();
197
- const body = buildRequestBody({ challenge, deviceInstanceId: getDeviceInstanceId(env), agent: detectAgent(env) });
270
+ const body = buildRequestBody({
271
+ challenge, deviceInstanceId: getDeviceInstanceId(env), agent: detectAgent(env), prior: loadPriorAccount(env),
272
+ });
198
273
  let data;
199
274
  try {
200
275
  const response = await fetchImpl(`${base}${START_PATH}`, {
@@ -286,6 +361,8 @@ module.exports = {
286
361
  AGENT_CLIENT_CONTEXT,
287
362
  AGENT_MARKERS,
288
363
  AGENT_GRANTS,
364
+ ACCOUNT_NAME,
365
+ ACCOUNT_VERSION,
289
366
  ApprovalStatus,
290
367
  PENDING_NAME,
291
368
  STATE_FOLDER,
@@ -299,10 +376,14 @@ module.exports = {
299
376
  fetchApproval,
300
377
  findHostedAgent,
301
378
  getSayLine,
379
+ getServerOverride,
302
380
  getSignInBase,
303
381
  getStateFolder,
304
382
  hasSavedSignIn,
305
383
  loadPending,
384
+ loadPriorAccount,
385
+ normalizeEndpoint,
306
386
  makePkcePair,
387
+ normalizeEndpoint,
307
388
  startSignIn,
308
389
  };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "probe-research",
3
- "version": "0.27.0",
3
+ "version": "0.29.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"
7
7
  },
8
8
  "files": [
9
9
  "bin",
10
- "lib"
10
+ "lib",
11
+ "upkeep.json"
11
12
  ],
12
13
  "engines": {
13
14
  "node": ">=18"
package/upkeep.json ADDED
@@ -0,0 +1,169 @@
1
+ {
2
+ "commands": {
3
+ "capture off": {
4
+ "--agent": 1,
5
+ "--json": 0,
6
+ "--yes": 0,
7
+ "-y": 0
8
+ },
9
+ "capture on": {
10
+ "--agent": 1,
11
+ "--json": 0,
12
+ "--no-browser": 0,
13
+ "--yes": 0,
14
+ "-y": 0
15
+ },
16
+ "doctor": {
17
+ "--bundle": 0,
18
+ "--fix": 0,
19
+ "--json": 0,
20
+ "--out": 1,
21
+ "--send": 0
22
+ },
23
+ "example delete": {
24
+ "--json": 0
25
+ },
26
+ "example keep": {
27
+ "--json": 0
28
+ },
29
+ "example status": {
30
+ "--json": 0
31
+ },
32
+ "import folders": {
33
+ "--json": 0
34
+ },
35
+ "import review": {
36
+ "--agent": 1,
37
+ "--chats-agent": 1,
38
+ "--chats-folder": 1,
39
+ "--chats-since": 1,
40
+ "--folder": 1,
41
+ "--json": 0,
42
+ "--sessions": 1,
43
+ "--wandb-folder": 1,
44
+ "--wandb-key": 1,
45
+ "--wandb-project": 1,
46
+ "--workspace": 1
47
+ },
48
+ "import status": {
49
+ "--json": 0
50
+ },
51
+ "install": {
52
+ "--agent": 1,
53
+ "--agent-rules": 0,
54
+ "--auto-update": 0,
55
+ "--capture": 0,
56
+ "--json": 0,
57
+ "--profile": 1,
58
+ "--tracking": 0,
59
+ "--yes": 0,
60
+ "-y": 0
61
+ },
62
+ "login": {
63
+ "--device": 0
64
+ },
65
+ "logout": {},
66
+ "repair": {
67
+ "--json": 0
68
+ },
69
+ "service start": {
70
+ "--json": 0,
71
+ "--min-version": 1
72
+ },
73
+ "service status": {
74
+ "--json": 0
75
+ },
76
+ "service stop": {
77
+ "--json": 0
78
+ },
79
+ "session default": {
80
+ "<arguments>": 1
81
+ },
82
+ "setup": {
83
+ "--action": 1,
84
+ "--agent": 1,
85
+ "--agent-rules": 0,
86
+ "--attempt": 1,
87
+ "--auto-update": 0,
88
+ "--capture": 0,
89
+ "--json": 0,
90
+ "--no-browser": 0,
91
+ "--pending": 0,
92
+ "--profile": 1,
93
+ "--recommended": 0,
94
+ "--reinstall": 0,
95
+ "--session-default": 1,
96
+ "--tracking": 0,
97
+ "--who-records": 1,
98
+ "--yes": 0,
99
+ "-y": 0
100
+ },
101
+ "status": {
102
+ "--demo-choice": 1,
103
+ "--json": 0,
104
+ "--past-work-choice": 1,
105
+ "--refresh": 0,
106
+ "--repaste-choice": 1,
107
+ "--timeout": 1
108
+ },
109
+ "uninstall": {
110
+ "--backup-unsent": 0,
111
+ "--discard-unsent": 0,
112
+ "--force": 0,
113
+ "--json": 0,
114
+ "--yes": 0,
115
+ "-y": 0
116
+ },
117
+ "update": {
118
+ "--check": 0,
119
+ "--plugin": 0,
120
+ "--yes": 0,
121
+ "-y": 0
122
+ },
123
+ "wandb discover": {
124
+ "<arguments>": 1
125
+ },
126
+ "wandb key receive": {
127
+ "--json": 0,
128
+ "--request": 1,
129
+ "--wait": 0
130
+ },
131
+ "wandb key request": {
132
+ "--json": 0
133
+ },
134
+ "wandb key set": {
135
+ "--key": 1
136
+ },
137
+ "wandb key status": {},
138
+ "wandb login": {},
139
+ "whoami": {},
140
+ "wizard": {
141
+ "--action": 1,
142
+ "--agent": 1,
143
+ "--agent-rules": 0,
144
+ "--attempt": 1,
145
+ "--auto-update": 0,
146
+ "--capture": 0,
147
+ "--json": 0,
148
+ "--no-browser": 0,
149
+ "--pending": 0,
150
+ "--profile": 1,
151
+ "--recommended": 0,
152
+ "--reinstall": 0,
153
+ "--session-default": 1,
154
+ "--tracking": 0,
155
+ "--who-records": 1,
156
+ "--yes": 0,
157
+ "-y": 0
158
+ }
159
+ },
160
+ "wizard_actions": [
161
+ "configure",
162
+ "diagnose",
163
+ "login",
164
+ "logout",
165
+ "recorder",
166
+ "uninstall",
167
+ "update"
168
+ ]
169
+ }