Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

Merge pull request #733 from ix-infrastructure/fix/graph-health-signals

Ian Hockb1ae1b17a831
diff --cc ix-cli/src/cli/bootstrap.ts
index 7fc63a74,b1226c9e..69508055
--- a/ix-cli/src/cli/bootstrap.ts
+++ b/ix-cli/src/cli/bootstrap.ts
@@@ -143,32 -143,40 +144,57 @@@ export function ensureWorkspaceId(cwd
}
/**
- * Resolve the workspace id for a READ, without creating one. Returns the id of the
- * nearest registered workspace containing cwd, else the default workspace, else
- * undefined — meaning an unscoped/global read, preserving back-compat for callers
- * run outside any registered workspace.
+ * Resolve the workspace id for a READ, without creating one: the nearest
+ * registered workspace containing cwd, else a workspace pinned by name with
+ * `ix config set workspace <name>`, else undefined.
+ *
+ * Deliberately NOT the `default: true` workspace. That flag is set on whichever
+ * repo happened to be mapped first, not chosen, and falling back to it answered
+ * reads from an unrelated repository with nothing on screen saying so (the
+ * ix-bench runner found agents in an unregistered worktree getting another
+ * repo's `ix context`). Undefined is not "read everything" either: graph reads
+ * refuse it through {@link requireReadWorkspaceId}.
*/
export function resolveWorkspaceId(cwd = process.cwd()): string | undefined {
- return (findWorkspaceForCwd(cwd) ?? getDefaultWorkspace())?.workspace_id;
+ const nearest = findWorkspaceForCwd(cwd);
+ if (nearest) return nearest.workspace_id;
+ const pinned = loadConfig().workspace;
+ if (pinned) return loadWorkspaces().find(w => w.workspace_name === pinned)?.workspace_id;
+ return undefined;
+ }
+
+ /**
+ * The workspace a graph read is scoped to, or a {@link WorkspaceNotMappedError}
+ * naming the directory and how to map it. For every command whose answer comes
+ * from the graph; commands that do not need one (`text`, `status`, `doctor`,
+ * `view --all`, `map` itself) never call this.
+ */
+ export function requireReadWorkspaceId(cwd = process.cwd()): string {
+ const id = resolveWorkspaceId(cwd);
+ if (id) return id;
+ // git prints its top-level with forward slashes on Windows; the hint is
+ // for a person to read and paste, so it gets the platform's own form.
+ const gitRoot = gitRootFor(cwd);
+ throw new WorkspaceNotMappedError(cwd, workspaceNotMappedHint(cwd, gitRoot && resolve(gitRoot)));
}
+/**
+ * Whether an unreachable `endpoint` is the backend `ix docker start` brings up.
+ *
+ * That command always starts the standalone compose on localhost:8090. For any
+ * other endpoint -- a remote, a second local backend on another port -- it
+ * starts containers the command then never talks to (and may collide with
+ * someone else's on 8090), while the real endpoint stays down.
+ */
+export function canAutoStartBackend(endpoint: string): boolean {
+ if (!isLocalEndpoint(endpoint)) return false;
+ try {
+ return new URL(endpoint).port === "8090";
+ } catch {
+ return false;
+ }
+}
+
/**
* Ensure the backend is reachable. If not, auto-start via ix docker start.
*/