// Which project and state directory the Claude channel plugin joins (#604 PR B, agent-hub#1030 item 10). It applies the same decision the CLI makes at startup: `projectContext` for an // ordinary process, plus the one exception the CLI has for a declared extra instance, whose cwd is its own managed worktree and whose state directory is the main project's by design. // Without this the plugin trusted an inherited AGENTHUB_STATE_DIR as is, so a Claude process started in `/.worktrees/` that inherited the main checkout's variables joined the // main repository's hub. // // Limit, stated plainly: this stops accidental and inherited-environment joins. It is not a defence against a same-user process that sets the variables and the launch evidence itself. import { definitionOf } from "../adapters/registry.ts"; import { readInstanceConfig } from "./instance-config.ts"; import { effectiveInstanceRoles } from "./instances.ts"; import { resolveInstanceExecutionCwd } from "./instance-execution.ts"; import { existsSync } from "node:fs"; import { join } from "node:path"; import { canonicalPath, inheritedStateDir, projectContext, projectRoot, realPath } from "./project.ts"; export interface ChannelProject { root: string; stateDir: string; /** True when the state directory came from the inherited environment, proven. */ inherited: boolean; /** * Set when this process has no project of its own and an inherited state directory that records another project (agent-hub#1036): it joins that hub as a distinct session, never as the * peer id it names. `label` is the origin part of the id the hub mints (`~