@dev.fast/whiteboard 0.3.3 → 0.3.4-preview.20261019.126

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.
Files changed (118) hide show
  1. package/dist/{account-alias-xOdmMnDH.js → account-alias-B5-HYi1D.js} +16 -9
  2. package/dist/{agent-cli-DT7MdaqL.js → agent-cli-CohHf6Ua.js} +15 -10
  3. package/dist/agent-cli-_YyMIMRY.js +2 -0
  4. package/dist/{agent-client-BRBzv3AV.js → agent-client-Dtc-Kn_w.js} +13 -3
  5. package/dist/{authoring-tools-DGSEag8y.js → authoring-tools-B7KU04f7.js} +34 -27
  6. package/dist/{background-server-WKzI_a98.js → background-server-C03RKxKS.js} +5 -5
  7. package/dist/{background-server-C_REWFkG.js → background-server-CB9C4uoc.js} +1 -1
  8. package/dist/build-info.json +1 -1
  9. package/dist/{cli-BBSDi_dX.js → cli-CJaEb7zC.js} +1 -1
  10. package/dist/{cli-runner-DshTBske.js → cli-runner-DGDIqh3V.js} +26 -26
  11. package/dist/cli.js +4 -3
  12. package/dist/{client-BN_FDxFr.js → client-lKVF_Elo.js} +253 -47
  13. package/dist/{fuzzy-match-bFX6wm8j.js → fuzzy-match-BmVJJm9I.js} +42 -14
  14. package/dist/{headless-host-CzvYpKOX.js → headless-host-DRtjf9WA.js} +1 -1
  15. package/dist/{headless-host-CS4Gv0c5.js → headless-host-XhL1X4vX.js} +523 -146
  16. package/dist/lens-selection-CyJapcsl.js +214 -0
  17. package/dist/{local-data-DtQTIzHX.js → local-data-Cpl4ENbJ.js} +2434 -328
  18. package/dist/{mcp-DpKnnmHH.js → mcp-ovmiUE_x.js} +5 -9
  19. package/dist/{package-paths-jMg6JxDP.js → package-paths-BWxO-UEL.js} +1 -1
  20. package/dist/{profile-DaqmODhc.js → profile-BadSkCkI.js} +20 -8
  21. package/dist/profile-DJvkBJNQ.js +2 -0
  22. package/dist/{remote-attach-DCngg8cl.js → remote-attach-Dd-YobM6.js} +4 -4
  23. package/dist/{remote-extensions-BCAbQZTv.js → remote-extensions-CNXwqK0D.js} +3 -3
  24. package/dist/{remote-extensions-Cf3L-ZGG.js → remote-extensions-VP-kfq0C.js} +1 -1
  25. package/dist/{remote-language-server-UWQgpoh-.js → remote-language-server-BXk87KCr.js} +5 -5
  26. package/dist/{remote-uninstall-CcDOcGyi.js → remote-uninstall-DuOzsvaD.js} +6 -6
  27. package/dist/{request-origin-Zcn_CjX4.js → request-origin-B9qCPiVB.js} +45 -12
  28. package/dist/{review-app-launcher-tqSQPlbu.js → review-app-launcher-C7el2Uoy.js} +2 -2
  29. package/dist/{review-home-paths-Lc02WFuX.js → review-home-paths-D8AoCdd2.js} +19 -17
  30. package/dist/{review-telemetry-BHWJsnoD.js → review-telemetry-BsoRMC2w.js} +5 -5
  31. package/dist/runtime-Bj2tD33R.js +27 -0
  32. package/dist/runtime.d.ts +1 -1
  33. package/dist/runtime.js +1 -1
  34. package/dist/{s3-77-qkEhs.js → s3-CsG2EWED.js} +1 -1
  35. package/dist/{s3-config-DDWWMh5x.js → s3-config-CjcLyFV5.js} +5 -3
  36. package/dist/{s3-config-0xuCh-F_.js → s3-config-zz4GWh2T.js} +1 -1
  37. package/dist/server/desktop-host.js +29 -76
  38. package/dist/{server-discovery-BVqrE1_-.js → server-discovery-CKjw3-6h.js} +6 -5
  39. package/dist/sharing/index.d.ts +486 -70
  40. package/dist/sharing/index.js +1 -1
  41. package/dist/{src-DsM3jO8G.js → src-BiWNbcF_.js} +89 -12
  42. package/dist/{src-BMPuxWv4.js → src-WPaQn75m.js} +208 -73
  43. package/dist/{stored-document-migration-CChxtFAy.js → stored-document-migration-dFbewRTG.js} +270 -269
  44. package/dist/{thread-state-5pYr6_zM.js → thread-state-Do5LX10I.js} +7 -2
  45. package/dist/{tool-failure-BFt2xj9i.js → tool-failure-DvI-gys2.js} +10 -3
  46. package/instructions/authoring.md +3 -2
  47. package/package.json +4 -4
  48. package/src/agent-connect.ts +8 -2
  49. package/src/ask/agents.ts +51 -9
  50. package/src/ask/checkout-files.ts +2 -5
  51. package/src/ask/thread-state.ts +4 -0
  52. package/src/ask/thread.ts +16 -0
  53. package/src/ask/threads.ts +24 -3
  54. package/src/cli-install.ts +13 -2
  55. package/src/cli-runner.ts +4 -1
  56. package/src/cli.ts +4 -1
  57. package/src/diff-selection-migration.ts +48 -34
  58. package/src/heading-anchors.ts +42 -0
  59. package/src/lens-selection.ts +38 -2
  60. package/src/review-api/README.md +52 -13
  61. package/src/review-api/activity.ts +1 -4
  62. package/src/review-api/agent-cli.ts +9 -1
  63. package/src/review-api/anchor-quotes.ts +14 -7
  64. package/src/review-api/ask-history.ts +137 -51
  65. package/src/review-api/authoring-tools.ts +45 -30
  66. package/src/review-api/blocks/definition.ts +1 -1
  67. package/src/review-api/blocks/markdown.ts +2 -2
  68. package/src/review-api/board-order.ts +144 -0
  69. package/src/review-api/checkout-groups.ts +560 -0
  70. package/src/review-api/document-headings.ts +58 -27
  71. package/src/review-api/document-text.ts +31 -2
  72. package/src/review-api/document.ts +281 -34
  73. package/src/review-api/foreign-references.ts +328 -0
  74. package/src/review-api/github-provider.ts +51 -13
  75. package/src/review-api/http.ts +702 -123
  76. package/src/review-api/instructions.ts +0 -19
  77. package/src/review-api/link-preview.ts +113 -0
  78. package/src/review-api/local-data.ts +310 -46
  79. package/src/review-api/mcp.ts +3 -11
  80. package/src/review-api/onboarding.ts +1 -1
  81. package/src/review-api/profile.ts +37 -6
  82. package/src/review-api/public-tools.ts +24 -2
  83. package/src/review-api/pull-request.ts +82 -49
  84. package/src/review-api/request-origin.ts +10 -0
  85. package/src/review-api/review-progress.ts +61 -27
  86. package/src/review-api/scratchpad-plan-upgrade.ts +250 -0
  87. package/src/review-api/store-migrations.ts +357 -0
  88. package/src/review-api/store-schema.ts +38 -29
  89. package/src/review-api/store.ts +2144 -480
  90. package/src/review-api/workspaces.ts +52 -13
  91. package/src/review-api/worktree-events.ts +3 -5
  92. package/src/review-api/worktree-source.ts +3 -7
  93. package/src/review-api/worktree-structural.integration.ts +72 -0
  94. package/src/review-stack.ts +15 -23
  95. package/src/runtime.ts +4 -30
  96. package/src/server/desktop-host.ts +6 -1
  97. package/src/server/desktop-server.ts +1 -31
  98. package/src/server/headless-host.ts +21 -14
  99. package/src/server/hono-http.ts +2 -1
  100. package/src/server/legacy-tutorial-cleanup.ts +2 -3
  101. package/src/server/review-gateway-list.ts +3 -5
  102. package/src/server/review-gateway-memory.ts +1 -1
  103. package/src/server/review-lifecycle-telemetry.ts +2 -2
  104. package/src/server/review-server-core.ts +1 -5
  105. package/src/server/structural-comparisons.ts +47 -0
  106. package/src/server-discovery.ts +4 -2
  107. package/src/sharing/export.ts +36 -7
  108. package/src/sharing/host.ts +34 -14
  109. package/src/sharing/import.ts +156 -24
  110. package/src/sharing/repository.ts +128 -20
  111. package/src/startup-trace.ts +3 -3
  112. package/src/stored-document-migration.ts +110 -19
  113. package/src/ui-telemetry-events.ts +33 -11
  114. package/dist/agent-cli-DeCrUC2s.js +0 -2
  115. package/dist/profile-Cz7L781D.js +0 -2
  116. package/dist/runtime-CKiWhGrf.js +0 -52
  117. package/instructions/scratchpad.md +0 -23
  118. package/src/review-preferences.ts +0 -88
@@ -1,4 +1,4 @@
1
- import { A as ReviewSelectedDiffSchema, C as ReviewApiSelectionSourceSchema } from "./src-DsM3jO8G.js";
1
+ import { M as ReviewSelectedDiffSchema, T as ReviewApiSelectionSourceSchema } from "./src-BiWNbcF_.js";
2
2
  import { z } from "zod";
3
3
  /** A semantic selection, independent of comment/thread creation. */
4
4
  const AgentSelectionSchema = z.strictObject({
@@ -374,7 +374,12 @@ const askHistoryEntrySchema = z.object({
374
374
  /** The commit the agent read. */
375
375
  head: z.string(),
376
376
  createdAt: z.string(),
377
- updatedAt: z.string()
377
+ updatedAt: z.string(),
378
+ /** The board the conversation started on, and the block if it was about one. */
379
+ anchor: z.object({
380
+ board: z.string(),
381
+ block: z.string().optional()
382
+ }).optional()
378
383
  });
379
384
  //#endregion
380
385
  export { askHistoryEntrySchema as a, askPicksSchema as c, selectionMarkdown as d, askEntrySchema as i, askQuestionSchema as l, askAgentIds as n, askOfferSchema as o, askChoiceKinds as r, askPermissionsSchema as s, applyAskChange as t, AgentSelectionSchema as u };
@@ -1,5 +1,6 @@
1
1
  import { m as isStringValue, n as isJsonObject } from "./src-X9phtB2j.js";
2
- import { n as callAuthoringTool, s as ReviewApiError, t as ToolText } from "./agent-client-BRBzv3AV.js";
2
+ import { l as boardTitle } from "./src-BiWNbcF_.js";
3
+ import { n as callAuthoringTool, s as ReviewApiError, t as ToolText } from "./agent-client-Dtc-Kn_w.js";
3
4
  import { t as ReviewInputError } from "./input-error-OLgB_h31.js";
4
5
  //#region src/review-api/public-tools.ts
5
6
  function publicDescription(text) {
@@ -38,7 +39,7 @@ function publicResult(value) {
38
39
  if (Array.isArray(value)) return value.map(publicResult);
39
40
  if (!isJsonObject(value)) return value;
40
41
  return Object.fromEntries(Object.entries(value).map(([key, item]) => {
41
- return [key === "reviewId" ? "sessionId" : key === "review" ? "session" : key === "reviews" ? "sessions" : key, key === "review" || key === "reviews" ? publicResult(item) : item];
42
+ return [key === "reviewId" ? "sessionId" : key === "review" ? "session" : key === "reviews" ? "sessions" : key, key === "review" || key === "reviews" ? publicResult(item) : key === "title" && "reviewId" in value && isStringValue(item) ? boardTitle(item) : item];
42
43
  }));
43
44
  }
44
45
  async function callPublicTool(client, tool, input, signal) {
@@ -47,7 +48,13 @@ async function callPublicTool(client, tool, input, signal) {
47
48
  const fields = { ...rest };
48
49
  if (sessionId !== void 0) fields.reviewId = sessionId;
49
50
  const result = await callAuthoringTool(client, tool, fields, signal);
50
- return result instanceof ToolText ? result : publicResult(result);
51
+ return result instanceof ToolText ? result : withoutRepositoryIds(publicResult(result));
52
+ }
53
+ /** Agents never see repository ids. */
54
+ function withoutRepositoryIds(value) {
55
+ if (Array.isArray(value)) return value.map(withoutRepositoryIds);
56
+ if (!isJsonObject(value)) return value;
57
+ return Object.fromEntries(Object.entries(value).filter(([key]) => key !== "repositoryId").map(([key, item]) => [key, withoutRepositoryIds(item)]));
51
58
  }
52
59
  //#endregion
53
60
  //#region src/review-api/recovery.ts
@@ -3,7 +3,7 @@ you are writing an interactive rfc-style whiteboard, for consumption by a staff
3
3
  **flow**
4
4
  follow these first five steps in order, with no tool calls beyond what they need: loading the tools they use (`session_create`, `session_activity_begin`, `session_edit`, `session_get`, and later `session_activity_update` and `session_activity_end`) and, for a PR, reading its description (`gh pr view`).
5
5
 
6
- - create the whiteboard, pinned to the commits/pr the user describes, naming the checkout by its `repositoryPath`. if they name none, use a `worktree` target with no `base`: it reviews the checkout, uncommitted work included, against the default branch. for uncommitted work only, pass `base: "HEAD"`. untracked files are left out: run `git add -N <file>` on new files you want reviewed
6
+ - create the whiteboard with a `target` naming the checkout by its `repositoryPath`: `{kind:"commits", head, base?}` for commits, `{kind:"pullRequest", pullRequest}` for a PR by URL or number, or `{kind:"project"}` for a plan with no change yet. if they name none, use a `worktree` target with no `base`: it reviews the checkout, uncommitted work included, against the default branch. for uncommitted work only, pass `base: "HEAD"`. untracked files are left out: run `git add -N <file>` on new files you want reviewed
7
7
  - trigger a subagent with this exact instruction: "Call `session_get_instructions({topic:\"file-lenses\"})` and follow it for whiteboard <sessionId>, whose change is `<base>..<head>` in `<repositoryPath>`."
8
8
  - call `session_activity_begin` and pass its `activityId` on every `session_edit`
9
9
  - read the diff with git (or jj) in `repositoryPath`, at the commits `session_create` returned: `git diff <base> <head>`, or for a worktree target `git diff <base>` plus `git status` for untracked files. if it shows no changes, the target is wrong: fix it with `session_set_target` before writing
@@ -37,4 +37,5 @@ follow these first five steps in order, with no tool calls beyond what they need
37
37
  - use `session_activity_update` to provide regular status updates on your area of focus.
38
38
  - keep whiteboards short and sweet when possible (esp. for small changes.) feel free to omit sections.
39
39
  - when something (a phrase in the prose, diagram node, etc.) describes actual code in the codebase, always default to attaching/hyperlink code.
40
- - Link repository code as `[label](review-source:head/src/file.ts#L10-L24)`; use `base` for old code. Use repository-relative paths and verified line numbers.
40
+ - Link repository code as `[label](whiteboard:source/head/src/file.ts#L10-L24)`; use `base` for old code. To quote any other commit of the board's repository, as a plan does, put the commit in place of `head`: `[label](whiteboard:source/<commit>/src/file.ts#L10-L24)`. Use repository-relative paths and verified line numbers.
41
+ - Link another whiteboard inline as `[label](whiteboard:board/<sessionId>)`, or one of its blocks as `[label](whiteboard:board/<sessionId>#<blockId>)`, wherever the prose refers to it. The board and block must exist.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev.fast/whiteboard",
3
- "version": "0.3.3",
3
+ "version": "0.3.4-preview.20261019.126",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -77,8 +77,8 @@
77
77
  "@dev.fast/json": "0.0.0",
78
78
  "@dev.fast/review-protocol": "0.0.0",
79
79
  "@dev.fast/review-share-protocol": "0.1.2",
80
- "@dev.fast/trace-protocol": "0.5.0",
81
- "@dev.fast/trace-core": "0.0.0"
80
+ "@dev.fast/trace-core": "0.0.0",
81
+ "@dev.fast/trace-protocol": "0.5.0"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=24 <25"
@@ -88,7 +88,7 @@
88
88
  "repo": "devdotfast/review",
89
89
  "docs": "packages/review/instructions/authoring.md"
90
90
  },
91
- "gitHead": "710b08c0dcb2166b8088ded6af639dd9598288c9",
91
+ "gitHead": "dfbb058ea293f9629d5380bcfc27af97484a52f7",
92
92
  "scripts": {
93
93
  "prebuild": "pnpm run build:workspace-deps",
94
94
  "build": "node --max-old-space-size=8192 node_modules/tsdown/dist/run.mjs",
@@ -9,7 +9,7 @@ import type {
9
9
  ReviewConnectResult,
10
10
  } from "@dev.fast/review-protocol";
11
11
 
12
- import { findExecutable } from "./ask/agents.js";
12
+ import { executableCommand, findExecutable } from "./ask/agents.js";
13
13
  import {
14
14
  type McpLaunch,
15
15
  WHITEBOARD_PLUGIN as PLUGIN,
@@ -72,12 +72,18 @@ export type ConnectRun = (
72
72
  args: string[],
73
73
  ) => Promise<{ code: number; output: string }>;
74
74
 
75
- const runProcess: ConnectRun = (file, args) =>
75
+ const runProcess: ConnectRun = (executable, executableArgs) =>
76
76
  new Promise((resolve) => {
77
+ const { file, args, windowsVerbatimArguments } = executableCommand(
78
+ executable,
79
+ executableArgs,
80
+ );
81
+
77
82
  execFile(
78
83
  file,
79
84
  args,
80
85
  {
86
+ windowsVerbatimArguments,
81
87
  timeout: STEP_TIMEOUT_MS,
82
88
  maxBuffer: 4 * 1024 * 1024,
83
89
  // A plugin install must never wait on a prompt nobody can see.
package/src/ask/agents.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  type AskPermissions,
20
20
  askAgentIds,
21
21
  } from "@review/ask/thread-state.js";
22
+ import { ASK_THREAD_ENV } from "@review/review-api/request-origin.js";
22
23
 
23
24
  /** How Whiteboard runs an agent that speaks ACP on stdio. */
24
25
  type AskAgentLaunch =
@@ -113,6 +114,7 @@ export const askAgents: Record<AskAgentId, AskAgentSpec> = {
113
114
  claude: {
114
115
  name: "Claude Code",
115
116
  commands: ["claude"],
117
+ installDirs: [".claude/local", ".local/bin"],
116
118
  launch: {
117
119
  adapter: "@agentclientprotocol/claude-agent-acp/dist/index.js",
118
120
  executableEnv: "CLAUDE_CODE_EXECUTABLE",
@@ -246,34 +248,62 @@ export type AskAgentLauncher = (
246
248
  /** The MCP servers its sessions are given. */
247
249
  mcpServers?: McpServer[];
248
250
  env?: NodeJS.ProcessEnv;
251
+ /** The Ask thread this agent serves. */
252
+ threadId?: string;
249
253
  },
250
254
  ) => Promise<AskAgentProcess>;
251
255
 
256
+ /** Windows can't run the extensionless sh shims npm puts beside `.cmd`s. */
257
+ const WINDOWS_EXTENSIONS = [".exe", ".cmd"];
258
+
252
259
  /** Desktop inherits the login shell's PATH, so this sees what a terminal sees.
253
260
  * Package-manager bin directories are skipped: the adapters' own dependencies
254
261
  * put `codex` there, and that is not the user's install. */
255
262
  export async function findExecutable(
256
263
  command: string,
257
264
  env: NodeJS.ProcessEnv = process.env,
265
+ platform: NodeJS.Platform = process.platform,
258
266
  ): Promise<string | undefined> {
267
+ const names =
268
+ platform === "win32"
269
+ ? WINDOWS_EXTENSIONS.map((extension) => command + extension)
270
+ : [command];
271
+
259
272
  for (const directory of (env.PATH ?? "").split(path.delimiter)) {
260
273
  if (!directory || directory.split(path.sep).includes("node_modules"))
261
274
  continue;
262
- const candidate = path.join(directory, command);
263
275
 
264
- try {
265
- if (!(await stat(candidate)).isFile()) continue;
266
- await access(candidate, constants.X_OK);
276
+ for (const name of names) {
277
+ const candidate = path.join(directory, name);
278
+
279
+ try {
280
+ if (!(await stat(candidate)).isFile()) continue;
281
+ await access(candidate, constants.X_OK);
267
282
 
268
- return candidate;
269
- } catch {
270
- /* Not in this directory. */
283
+ return candidate;
284
+ } catch {
285
+ /* Not in this directory. */
286
+ }
271
287
  }
272
288
  }
273
289
 
274
290
  return undefined;
275
291
  }
276
292
 
293
+ /** Windows runs a `.cmd` only through cmd.exe. */
294
+ export function executableCommand(executable: string, args: string[]) {
295
+ if (process.platform !== "win32" || !/\.cmd$/i.test(executable))
296
+ return { file: executable, args, windowsVerbatimArguments: false };
297
+
298
+ const line = [executable, ...args].map((arg) => `"${arg}"`).join(" ");
299
+
300
+ return {
301
+ file: "cmd.exe",
302
+ args: ["/d", "/s", "/c", `"${line}"`],
303
+ windowsVerbatimArguments: true,
304
+ };
305
+ }
306
+
277
307
  /** The user's install of an agent's CLI: on PATH, else where its installer
278
308
  * puts it. */
279
309
  async function findAgent(
@@ -330,7 +360,12 @@ const STDERR_LIMIT = 8_000;
330
360
  export const launchAskAgent: AskAgentLauncher = async (
331
361
  agent,
332
362
  cwd,
333
- { permissions = "read-only", mcpServers = [], env: base = process.env } = {},
363
+ {
364
+ permissions = "read-only",
365
+ mcpServers = [],
366
+ env: base = process.env,
367
+ threadId,
368
+ } = {},
334
369
  ) => {
335
370
  const spec = askAgents[agent];
336
371
  const executable = await findAgent(spec, base);
@@ -342,6 +377,10 @@ export const launchAskAgent: AskAgentLauncher = async (
342
377
  ...askAgentSettings(agent, permissions).env,
343
378
  };
344
379
 
380
+ // Lets `whiteboard api` calls from the agent's shell name the thread.
381
+ // The MCP server gets it in its own env, since MCP clients may not pass theirs on.
382
+ if (threadId) env[ASK_THREAD_ENV] = threadId;
383
+
345
384
  // A server started from inside a Claude Code session must not look nested.
346
385
  delete env.CLAUDECODE;
347
386
  delete env.CLAUDE_CODE_ENTRYPOINT;
@@ -364,10 +403,13 @@ export const launchAskAgent: AskAgentLauncher = async (
364
403
  args = [createRequire(import.meta.url).resolve(launch.adapter)];
365
404
  } else args = launch.args;
366
405
 
367
- const child = spawn(command, args, {
406
+ const start = executableCommand(command, args);
407
+
408
+ const child = spawn(start.file, start.args, {
368
409
  cwd,
369
410
  env,
370
411
  stdio: ["pipe", "pipe", "pipe"],
412
+ windowsVerbatimArguments: start.windowsVerbatimArguments,
371
413
  });
372
414
 
373
415
  let stderr = "";
@@ -1,13 +1,10 @@
1
- import { execFile } from "node:child_process";
2
- import { promisify } from "node:util";
3
-
4
- const execFileAsync = promisify(execFile);
1
+ import { runVcs } from "@dev.fast/local-vcs";
5
2
 
6
3
  /** The checkout's files relative to its root: tracked ones, and new ones git
7
4
  * does not ignore. None where git cannot list them. */
8
5
  export async function checkoutFiles(root: string): Promise<string[]> {
9
6
  try {
10
- const { stdout } = await execFileAsync(
7
+ const { stdout } = await runVcs(
11
8
  "git",
12
9
  [
13
10
  "-C",
@@ -375,6 +375,10 @@ export const askHistoryEntrySchema = z.object({
375
375
  head: z.string(),
376
376
  createdAt: z.string(),
377
377
  updatedAt: z.string(),
378
+ /** The board the conversation started on, and the block if it was about one. */
379
+ anchor: z
380
+ .object({ board: z.string(), block: z.string().optional() })
381
+ .optional(),
378
382
  });
379
383
 
380
384
  export type AskHistoryEntry = z.infer<typeof askHistoryEntrySchema>;
package/src/ask/thread.ts CHANGED
@@ -176,6 +176,7 @@ export class AskThread {
176
176
  /** The number of changes so far; a snapshot carries the one it includes. */
177
177
  private seq = 0;
178
178
  private readonly listeners = new Set<(update: AskUpdate) => void>();
179
+ private readonly statusListeners = new Set<() => void>();
179
180
  private readonly closers = new Set<() => void>();
180
181
  private readonly decisions = new Map<
181
182
  string,
@@ -288,6 +289,10 @@ export class AskThread {
288
289
  return { seq: this.seq, snapshot: this.state };
289
290
  }
290
291
 
292
+ get status() {
293
+ return this.state.status;
294
+ }
295
+
291
296
  /** Every change after the current `seq`, in order. */
292
297
  subscribe(listener: (update: AskUpdate) => void) {
293
298
  this.listeners.add(listener);
@@ -295,6 +300,13 @@ export class AskThread {
295
300
  return () => this.listeners.delete(listener);
296
301
  }
297
302
 
303
+ /** Calls back when the status changes, without following the thread. */
304
+ onStatusChange(listener: () => void) {
305
+ this.statusListeners.add(listener);
306
+
307
+ return () => this.statusListeners.delete(listener);
308
+ }
309
+
298
310
  /** Whether anything follows the thread, as an open panel does. */
299
311
  watched() {
300
312
  return this.listeners.size > 0;
@@ -630,6 +642,7 @@ export class AskThread {
630
642
  const launched = await this.launch(this.start.agent, this.start.cwd, {
631
643
  permissions: this.state.permissions,
632
644
  mcpServers: this.mcpServers,
645
+ threadId: this.id,
633
646
  });
634
647
 
635
648
  // Closed, stopped or given up on while the process started.
@@ -1533,5 +1546,8 @@ export class AskThread {
1533
1546
  const update = { seq: this.seq, change };
1534
1547
 
1535
1548
  for (const listener of this.listeners) listener(update);
1549
+
1550
+ if (change.type === "set" && change.status)
1551
+ for (const listener of this.statusListeners) listener();
1536
1552
  }
1537
1553
  }
@@ -18,6 +18,7 @@ import {
18
18
  type AskThreadStart,
19
19
  askThreadLimits,
20
20
  } from "@review/ask/thread.js";
21
+ import { ASK_THREAD_ENV } from "@review/review-api/request-origin.js";
21
22
 
22
23
  /** How long an agent may take to say what it offers. */
23
24
  const OFFER_TIMEOUT_MS = 30_000;
@@ -163,7 +164,7 @@ export function cliAskTools(
163
164
  ];
164
165
 
165
166
  return {
166
- mcpServers: () => {
167
+ mcpServers: (threadId) => {
167
168
  const cli = cliPath();
168
169
 
169
170
  return cli
@@ -172,7 +173,9 @@ export function cliAskTools(
172
173
  name: "whiteboard",
173
174
  command: process.execPath,
174
175
  args: [cli, "mcp"],
175
- env: env(),
176
+ // MCP clients may not pass their own env on, so the server
177
+ // gets the thread it serves in its own.
178
+ env: [...env(), { name: ASK_THREAD_ENV, value: threadId }],
176
179
  },
177
180
  ]
178
181
  : [];
@@ -218,6 +221,8 @@ export class AskThreads {
218
221
 
219
222
  private readonly mcpServers: AskMcpServers;
220
223
 
224
+ private readonly statusListeners = new Set<() => void>();
225
+
221
226
  constructor(
222
227
  private readonly launch: AskAgentLauncher,
223
228
  private readonly tools: AskTools = {},
@@ -249,6 +254,8 @@ export class AskThreads {
249
254
  );
250
255
 
251
256
  this.threads.set(thread.id, thread);
257
+ thread.onStatusChange(() => this.statusChanged());
258
+ this.statusChanged();
252
259
  void thread.open();
253
260
  this.sweeper ??= setInterval(() => this.sweep(), SWEEP_MS);
254
261
  this.sweeper.unref?.();
@@ -291,6 +298,19 @@ export class AskThreads {
291
298
  }
292
299
  }
293
300
 
301
+ /** Calls back when a thread opens, closes or changes its status. */
302
+ subscribeStatus(listener: () => void) {
303
+ this.statusListeners.add(listener);
304
+
305
+ return () => {
306
+ this.statusListeners.delete(listener);
307
+ };
308
+ }
309
+
310
+ private statusChanged() {
311
+ for (const listener of this.statusListeners) listener();
312
+ }
313
+
294
314
  get(id: string) {
295
315
  return this.threads.get(id);
296
316
  }
@@ -313,9 +333,10 @@ export class AskThreads {
313
333
 
314
334
  close(id: string, save = true) {
315
335
  const thread = this.threads.get(id);
316
- this.threads.delete(id);
317
336
  this.unwatchedSince.delete(id);
318
337
  thread?.close(save);
338
+
339
+ if (this.threads.delete(id)) this.statusChanged();
319
340
  }
320
341
 
321
342
  closeDeletedReviews(isDeleted: (reviewId: string) => boolean) {
@@ -699,11 +699,16 @@ export async function writePathShim(
699
699
  cliPath: string,
700
700
  runtimePath: string | undefined,
701
701
  devHome: string,
702
+ previewHome = devHome,
702
703
  ): Promise<void> {
703
704
  if (process.platform === "win32") {
704
705
  await writeFileAtomicAsync(
705
706
  shimPath,
706
- windowsCliShim(cliPath, runtimePath ?? process.execPath, devHome),
707
+ windowsCliShim(
708
+ cliPath,
709
+ runtimePath ?? process.execPath,
710
+ devHome === previewHome ? devHome : undefined,
711
+ ),
707
712
  { replaceSymlink: true },
708
713
  );
709
714
 
@@ -716,6 +721,8 @@ export async function writePathShim(
716
721
  FALLBACK_CLI=${shSingleQuote(cliPath)}
717
722
  FALLBACK_RUNTIME=${shSingleQuote(runtimePath ?? "")}
718
723
  DEFAULT_HOME=${shSingleQuote(devHome)}
724
+ channel="\${DEV_FAST_REVIEW_CHANNEL:-\${DEV_REVIEW_INSTANCE:-}}"
725
+ [ "$channel" = preview ] && DEFAULT_HOME=${shSingleQuote(previewHome)}
719
726
  export DEV_REVIEW_HOME="\${DEV_REVIEW_HOME:-$DEFAULT_HOME}"
720
727
  DESKTOP="$DEV_REVIEW_HOME/review-desktop"
721
728
 
@@ -836,7 +843,11 @@ export async function installReviewCommand(input: {
836
843
  shimPath,
837
844
  input.cliPath,
838
845
  input.cliRuntimePath,
839
- devReviewHome(env, homeDir),
846
+ devReviewHome({ DEV_REVIEW_HOME: env.DEV_REVIEW_HOME }, homeDir),
847
+ devReviewHome(
848
+ { DEV_REVIEW_HOME: env.DEV_REVIEW_HOME, DEV_REVIEW_INSTANCE: "preview" },
849
+ homeDir,
850
+ ),
840
851
  );
841
852
 
842
853
  if (await traceMachineEnabled({ homeDir, env })) {
package/src/cli-runner.ts CHANGED
@@ -5,6 +5,7 @@ import { createInterface } from "node:readline/promises";
5
5
  import { Writable } from "node:stream";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
+ import { boardTitle } from "@dev.fast/review-protocol";
8
9
  import {
9
10
  REVIEW_CLI_INSTALL_TARGET_LABELS,
10
11
  REVIEW_REMOTE_AGENT_IDS,
@@ -836,7 +837,9 @@ export async function runReviewCli(input: ReviewCliInput): Promise<number> {
836
837
  : "Whiteboard Desktop is ready in the background. Pass --focus to bring it forward.\n",
837
838
  );
838
839
  } else {
839
- input.stdout.write(`Whiteboard Desktop is showing "${event.title}".\n`);
840
+ input.stdout.write(
841
+ `Whiteboard Desktop is showing "${boardTitle(event.title)}".\n`,
842
+ );
840
843
  }
841
844
  };
842
845
 
package/src/cli.ts CHANGED
@@ -84,9 +84,12 @@ async function maybeDelegateToDesktopCli(
84
84
  // This bootstrap runs before the Node floor check, so it cannot import
85
85
  // devReviewHome() from @dev.fast/trace-core: that module graph needs a modern
86
86
  // Node. Keep this copy in step with devReviewHome().
87
+ const channel =
88
+ env.DEV_FAST_REVIEW_CHANNEL?.trim() || env.DEV_REVIEW_INSTANCE?.trim();
89
+
87
90
  const devHome = env.DEV_REVIEW_HOME?.trim()
88
91
  ? path.resolve(env.DEV_REVIEW_HOME.trim())
89
- : path.join(os.homedir(), ".dev");
92
+ : path.join(os.homedir(), channel === "preview" ? ".dev-preview" : ".dev");
90
93
 
91
94
  let cliPath: string;
92
95
  let runtimePath: string | undefined;
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type JsonObject,
2
3
  type JsonValue,
3
4
  isJsonObject,
4
5
  isNumberValue,
@@ -14,50 +15,63 @@ export function migrateDiffSelections(input: unknown): JsonValue {
14
15
  return migrateNode(jsonValueSchema.parse(input));
15
16
  }
16
17
 
18
+ /** Keys whose values held retired attachments. */
19
+ export const ATTACHMENT_KEYS = [
20
+ "source",
21
+ "peek",
22
+ "sources",
23
+ "contextSources",
24
+ "callSite",
25
+ ];
26
+
27
+ /** A retired attachment as a selection, or undefined for anything else. */
28
+ export function retiredSelection(value: JsonObject): JsonObject | undefined {
29
+ if (!isStringValue(value.file)) return undefined;
30
+
31
+ if (isNumberValue(value.fromLine) && isNumberValue(value.toLine)) {
32
+ const side = value.side ?? value.graph ?? "head";
33
+
34
+ return {
35
+ file: value.file,
36
+ start: { side, line: value.fromLine },
37
+ end: { side, line: value.toLine },
38
+ };
39
+ }
40
+
41
+ if (
42
+ isJsonObject(value.start) &&
43
+ isJsonObject(value.end) &&
44
+ "baseLine" in value.start
45
+ ) {
46
+ const endpoint = (row: JsonObject) =>
47
+ isNumberValue(row.headLine)
48
+ ? { side: "head", line: row.headLine }
49
+ : { side: "base", line: row.baseLine ?? null };
50
+
51
+ return {
52
+ file: value.file,
53
+ start: endpoint(value.start),
54
+ end: endpoint(value.end),
55
+ };
56
+ }
57
+
58
+ return undefined;
59
+ }
60
+
17
61
  function migrateNode(value: JsonValue, attachment = false): JsonValue {
18
62
  if (Array.isArray(value))
19
63
  return value.map((child) => migrateNode(child, attachment));
20
64
 
21
65
  if (!isJsonObject(value)) return value;
22
66
 
23
- if (attachment && isStringValue(value.file)) {
24
- if (isNumberValue(value.fromLine) && isNumberValue(value.toLine)) {
25
- const side = value.side ?? value.graph ?? "head";
26
-
27
- return {
28
- file: value.file,
29
- start: { side, line: value.fromLine },
30
- end: { side, line: value.toLine },
31
- };
32
- }
33
-
34
- if (
35
- isJsonObject(value.start) &&
36
- isJsonObject(value.end) &&
37
- "baseLine" in value.start
38
- ) {
39
- const endpoint = (row: typeof value.start) =>
40
- isNumberValue(row.headLine)
41
- ? { side: "head", line: row.headLine }
42
- : { side: "base", line: row.baseLine };
43
-
44
- return {
45
- file: value.file,
46
- start: endpoint(value.start),
47
- end: endpoint(value.end),
48
- };
49
- }
50
- }
67
+ const selection = attachment ? retiredSelection(value) : undefined;
68
+
69
+ if (selection) return selection;
51
70
 
52
71
  return Object.fromEntries(
53
72
  Object.entries(value).map(([key, child]) => [
54
73
  key,
55
- migrateNode(
56
- child,
57
- ["source", "peek", "sources", "contextSources", "callSite"].includes(
58
- key,
59
- ),
60
- ),
74
+ migrateNode(child, ATTACHMENT_KEYS.includes(key)),
61
75
  ]),
62
76
  );
63
77
  }
@@ -0,0 +1,42 @@
1
+ import { slugify, uniqueId } from "./slug.js";
2
+
3
+ // A board's headings, as the server publishes them and the editor shows
4
+ // them: one rule for both, so a heading's anchor is the same in each.
5
+
6
+ /** Whether a Markdown heading with this many `#`s is one of the board's
7
+ * headings, with an anchor and a Contents row: `##` and `###`. */
8
+ export function isBoardHeading(hashes: number | undefined): boolean {
9
+ return hashes === 2 || hashes === 3;
10
+ }
11
+
12
+ /** Hands out heading anchors in document order: `slugify(text)`, made
13
+ * unique, so imported `#fragment` links still land. */
14
+ export function headingAnchors(): (text: string) => string {
15
+ const used = new Set<string>();
16
+
17
+ return (text) => {
18
+ const id = uniqueId(slugify(text) || "section", used);
19
+
20
+ used.add(id);
21
+
22
+ return id;
23
+ };
24
+ }
25
+
26
+ /**
27
+ * A Markdown heading's depth in Contents: one step under its section,
28
+ * whose blocks sit at `base`, and under the block's bigger headings before
29
+ * it. `open` holds those headings by `#` count, and takes this one.
30
+ */
31
+ export function markdownHeadingDepth(
32
+ open: number[],
33
+ hashes: number,
34
+ base: number,
35
+ ): number {
36
+ while (open.length && open.at(-1)! >= hashes) open.pop();
37
+ const depth = base + open.length;
38
+
39
+ open.push(hashes);
40
+
41
+ return depth;
42
+ }