@vzn/vx 0.0.542 → 0.0.543

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 (2) hide show
  1. package/package.json +5 -5
  2. package/src/cli/why.ts +27 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vzn/vx",
3
- "version": "0.0.542",
3
+ "version": "0.0.543",
4
4
  "description": "The fastest task runner and build cache for JavaScript monorepos.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,10 +21,10 @@
21
21
  "node": ">=18"
22
22
  },
23
23
  "optionalDependencies": {
24
- "@vzn/vx-linux-x64": "0.0.542",
25
- "@vzn/vx-linux-arm64": "0.0.542",
26
- "@vzn/vx-darwin-x64": "0.0.542",
27
- "@vzn/vx-darwin-arm64": "0.0.542"
24
+ "@vzn/vx-linux-x64": "0.0.543",
25
+ "@vzn/vx-linux-arm64": "0.0.543",
26
+ "@vzn/vx-darwin-x64": "0.0.543",
27
+ "@vzn/vx-darwin-arm64": "0.0.543"
28
28
  },
29
29
  "dependencies": {
30
30
  "@anthropic-ai/sandbox-runtime": "^0.0.76"
package/src/cli/why.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from '../orchestrator/index.js'
19
19
  import { MASKED, nearMatches, printable, UserError } from '../util/index.js'
20
20
  import { findWorkspaceRoot } from '../workspace/index.js'
21
+ import { findCwdProject } from './select.js'
21
22
  import { cliCacheDir, parseCacheDirFlag } from './workspace-config.js'
22
23
 
23
24
  interface WhyArgs {
@@ -127,9 +128,14 @@ function suggest(query: string, ids: readonly string[]): string {
127
128
  /**
128
129
  * Resolve a positional target to a full `project#task` id against the runs
129
130
  * table. A `pkg#task` form is used as-is; a bare task name matches every
130
- * project that ran it — unique → resolved, several → error listing them.
131
+ * project that ran it — unique → resolved, several → the project the cwd
132
+ * sits in, as `vx run build` there picks (X-18), else an error listing them.
131
133
  */
132
- function resolveTarget(cache: Cache, target: string): string {
134
+ async function resolveTarget(
135
+ cache: Cache,
136
+ target: string,
137
+ cwdProject: () => Promise<string | null>,
138
+ ): Promise<string> {
133
139
  const db = cache.dbHandle()
134
140
  if (target.includes('#')) {
135
141
  // An exact id needs one row, and its newest is where a scan from the
@@ -151,6 +157,8 @@ function resolveTarget(cache: Cache, target: string): string {
151
157
  const matches = ids.filter((id) => id.endsWith(`#${target}`))
152
158
  if (matches.length === 1) return matches[0]!
153
159
  if (matches.length > 1) {
160
+ const here = await cwdProject()
161
+ if (here !== null && matches.includes(`${here}#${target}`)) return `${here}#${target}`
154
162
  throw new UserError(
155
163
  `vx why: "${target}" ran in ${matches.length} projects — pick one:\n` +
156
164
  matches.map((m) => ` ${m}`).join('\n'),
@@ -187,11 +195,19 @@ export async function whyCmd(args: readonly string[]): Promise<number> {
187
195
  const cache = Cache.inspect(await cliCacheDir(root, parsed.cacheDir))
188
196
  try {
189
197
  const db = cache.dbHandle()
190
- const taskId = resolveTarget(cache, await rootSpelled(root, parsed.target))
191
- const runId =
192
- parsed.runId !== undefined
193
- ? (resolveRunId(db, parsed.runId, 'vx why') ?? parsed.runId)
194
- : latestRunId(db, taskId)
198
+ const taskId = await resolveTarget(cache, await rootSpelled(root, parsed.target), () =>
199
+ findCwdProject(process.cwd()),
200
+ )
201
+ let runId: string | null
202
+ if (parsed.runId !== undefined) {
203
+ runId = resolveRunId(db, parsed.runId, 'vx why')
204
+ // An unknown id read as a known run missing the task (X-18).
205
+ if (runId === null) {
206
+ throw new UserError(
207
+ `vx why: no recorded run ${parsed.runId} (vx last --list shows recent runs)`,
208
+ )
209
+ }
210
+ } else runId = latestRunId(db, taskId)
195
211
 
196
212
  if (runId === null) {
197
213
  // Runs exist (resolveTarget passed) but predate run ids — fall back to
@@ -245,7 +261,10 @@ export async function whyCmd(args: readonly string[]): Promise<number> {
245
261
  // The key moved and the diff says by what: the verdict names it, so
246
262
  // an env-only change reads as one line, not "inputs differ" above a
247
263
  // table to scan.
248
- const moved = diff.entries.map((e) => `${e.kind} ${printable(e.name)}`)
264
+ // The config component is kind and name `config`: it read "config config".
265
+ const moved = diff.entries.map((e) =>
266
+ e.name === e.kind ? e.kind : `${e.kind} ${printable(e.name)}`,
267
+ )
249
268
  lines.push(
250
269
  ` verdict ${
251
270
  why.hashChanged === true && moved.length > 0