Skip to content

Commit fc84a67

Browse files
chitcommitclaude
andcommitted
feat: route Claude contexts to Person (P) entity type + auto-create entity dirs
Updates mintChittyId to explicitly request entity_type=P for context minting, ensuring Claude sessions are Person (Synthetic) not Thing. writeSessionBinding now auto-creates entity-scoped directories under chittycontext/entities/{chittyId}/{project}/ on bind. Adds detectProjectSlug helper for entity directory naming. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2080635 commit fc84a67

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

src/commands/hook-handlers.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,21 @@ function detectOrganization(projectPath: string): string | null {
680680
return null;
681681
}
682682

683+
/**
684+
* Detect project slug from project path for entity directory naming
685+
*/
686+
function detectProjectSlug(projectPath: string): string | null {
687+
if (!projectPath) return null;
688+
// Extract the last path segment as the project slug
689+
const parts = projectPath.replace(/\/+$/, "").split("/");
690+
const last = parts[parts.length - 1];
691+
if (last) {
692+
// Convert to kebab-case slug
693+
return last.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-");
694+
}
695+
return null;
696+
}
697+
683698
/**
684699
* Resolve context from ChittyCanon database
685700
*/
@@ -760,7 +775,8 @@ async function mintChittyId(anchors: {
760775
try {
761776
// Call ChittyID directly - it routes to ChittyMint on the backend
762777
// ChittyMint handles controlled minting with drand randomness and signing
763-
const response = await fetch("https://id.chitty.cc/api/get-chittyid?for=context", {
778+
// @canon: chittycanon://gov/governance#core-types — contexts are Person (P), not Thing (T)
779+
const response = await fetch("https://id.chitty.cc/api/get-chittyid?for=context&entity_type=P", {
764780
method: "GET",
765781
headers: {
766782
"Content-Type": "application/json"
@@ -901,6 +917,23 @@ async function writeSessionBinding(binding: ContextBinding): Promise<void> {
901917
mkdirSync(dir, { recursive: true });
902918
}
903919
writeFileSync(SESSION_BINDING_FILE, JSON.stringify(binding, null, 2));
920+
921+
// Create entity directory for this ChittyID if it doesn't exist
922+
if (binding.chittyId && binding.chittyId !== "OFFLINE") {
923+
const entityDir = join(dir, "entities", binding.chittyId);
924+
if (!existsSync(entityDir)) {
925+
mkdirSync(entityDir, { recursive: true });
926+
}
927+
928+
// Create project directory based on detected org/project
929+
const projectSlug = detectProjectSlug(binding.projectPath);
930+
if (projectSlug) {
931+
const projectDir = join(entityDir, projectSlug);
932+
if (!existsSync(projectDir)) {
933+
mkdirSync(join(projectDir, "checkpoints"), { recursive: true });
934+
}
935+
}
936+
}
904937
}
905938

906939
/**

0 commit comments

Comments
 (0)