-
Notifications
You must be signed in to change notification settings - Fork 94
fix(dir-config): route memory reads through .hivemind, not just capture #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * `hivemind whoami` rendering. | ||
| * | ||
| * Reports the EFFECTIVE identity for a given cwd — the one capture and memory | ||
| * search actually use — rather than the raw contents of | ||
| * `~/.deeplake/credentials.json`. Two things override the stored creds: | ||
| * | ||
| * - `HIVEMIND_ORG_ID` / `HIVEMIND_WORKSPACE_ID` in the environment | ||
| * - the nearest `.hivemind` for this directory (see src/dir-config.ts) | ||
| * | ||
| * Whenever the effective identity differs from what's stored, the reason and | ||
| * the stored values are both disclosed — a user asking "what am I connected | ||
| * to?" must never be told a value that isn't the one in use. | ||
| */ | ||
|
|
||
| import type { Config } from "../config.js"; | ||
| import type { Credentials } from "./auth.js"; | ||
| import { resolveDirConfig } from "../dir-config.js"; | ||
|
|
||
| const DEFAULT_API = "https://api.deeplake.ai"; | ||
|
|
||
| export function renderWhoami(config: Config | null, creds: Credentials, cwd: string): string { | ||
| const storedOrg = creds.orgName ?? creds.orgId; | ||
| const storedWs = creds.workspaceId ?? "default"; | ||
|
|
||
| // No usable Config (no token/orgId resolvable) — report what's stored. | ||
| if (!config) { | ||
| return [ | ||
| `User org: ${storedOrg}`, | ||
| `Workspace: ${storedWs}`, | ||
| `API: ${creds.apiUrl ?? DEFAULT_API}`, | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| const res = resolveDirConfig(config, cwd); | ||
| const eff = res.config; | ||
|
|
||
| // Attribute each override precisely: `config` has already folded the env in, | ||
| // so a diff against `creds` is the env's doing, and a diff between `eff` and | ||
| // `config` is the .hivemind's. | ||
| const envMoved = config.orgId !== creds.orgId || config.workspaceId !== storedWs; | ||
| const dirMoved = !!res.found && | ||
| (eff.orgId !== config.orgId || eff.workspaceId !== config.workspaceId); | ||
|
|
||
| const lines = [ | ||
| `User org: ${eff.orgName ?? eff.orgId}`, | ||
| `Workspace: ${eff.workspaceId}`, | ||
| `API: ${eff.apiUrl}`, | ||
| ]; | ||
|
|
||
| const notes: string[] = []; | ||
| if (dirMoved) notes.push(`Routed by ${res.found?.path}`); | ||
| if (envMoved) notes.push("Overridden by HIVEMIND_* environment variables"); | ||
| if (notes.length) { | ||
| notes.push(`Stored identity: ${storedOrg} / ${storedWs}`); | ||
| } | ||
| if (res.found && !res.collect) { | ||
| notes.push(`Capture: disabled for this directory by ${res.found.path}`); | ||
| } | ||
| if (notes.length) lines.push("", ...notes); | ||
|
|
||
| return lines.join("\n"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { join, dirname, sep } from "node:path"; | |
| import { fileURLToPath } from "node:url"; | ||
| import { readStdin } from "../utils/stdin.js"; | ||
| import { loadConfig } from "../config.js"; | ||
| import { resolveDirConfig } from "../dir-config.js"; | ||
| import { armSkillOptOnSkillUse } from "./shared/skillopt-hook.js"; | ||
| import { DeeplakeApi } from "../deeplake-api.js"; | ||
| import { sqlLike } from "../utils/sql.js"; | ||
|
|
@@ -266,7 +267,7 @@ interface ClaudePreToolDeps { | |
|
|
||
| export async function processPreToolUse(input: PreToolUseInput, deps: ClaudePreToolDeps = {}): Promise<ClaudePreToolDecision | null> { | ||
| const { | ||
| config = loadConfig(), | ||
| config: baseConfig = loadConfig(), | ||
| createApi = (table, activeConfig) => new DeeplakeApi( | ||
| activeConfig.token, | ||
| activeConfig.apiUrl, | ||
|
|
@@ -322,7 +323,13 @@ export async function processPreToolUse(input: PreToolUseInput, deps: ClaudePreT | |
| // unreachable. Do NOT return null here — that hands the original command to | ||
| // the host shell. Return the retry guidance instead so the command never | ||
| // touches the real filesystem. | ||
| if (!config) return buildRetryGuidanceDecision(input.tool_name); | ||
| if (!baseConfig) return buildRetryGuidanceDecision(input.tool_name); | ||
|
|
||
| // Reads are routed by the nearest `.hivemind` exactly like capture is: a | ||
| // directory pinned to another org/workspace must SEE that workspace's memory, | ||
| // not the global one. `collect` is a capture switch and deliberately does not | ||
| // gate reads (see src/dir-config.ts). | ||
| const config = resolveDirConfig(baseConfig, input.cwd ?? process.cwd()).config; | ||
|
Comment on lines
+328
to
+332
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift Directory routing does not isolate the session index cache. The effective identity changes by
📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| const table = process.env["HIVEMIND_TABLE"] ?? "memory"; | ||
| const sessionsTable = process.env["HIVEMIND_SESSIONS_TABLE"] ?? "sessions"; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
An environment-selected org can be printed with the stored org’s name.
orgIdreflectsHIVEMIND_ORG_ID, whileorgNamecan still originate from credentials.src/commands/whoami.ts#L38-L48: display the effective org ID when the environment changed the organization.tests/shared/dir-config-read-routing.test.ts#L144-L149: add a concreteHIVEMIND_ORG_IDassertion.📍 Affects 2 files
src/commands/whoami.ts#L38-L48(this comment)tests/shared/dir-config-read-routing.test.ts#L144-L149🤖 Prompt for AI Agents