Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/agentctx/src/cli/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { existsSync } from "node:fs";
import { parseArgs } from "node:util";
import { openDatabase } from "../storage/db.js";
import { countProjectRecords, deleteProjectData } from "../storage/maintenance.js";
import { resolveProjectId } from "../storage/namespace.js";
import { resolveProjectId, shortProjectId } from "../storage/namespace.js";
import type { CliEnv } from "./env.js";

export const RESET_USAGE = `Usage: agentctx reset [options]
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function runReset(env: CliEnv, args: string[]): Promise<number> {
const result = deleteProjectData(db, projectId);
env.io.out(
`✓ deleted ${result.records} record(s), ${result.nodes} node(s), ` +
`${result.edges} edge(s), ${result.sessions} session(s) for project ${projectId.slice(0, 12)}…`,
`${result.edges} edge(s), ${result.sessions} session(s) for project ${shortProjectId(projectId)}`,
);
} finally {
db.close();
Expand Down
4 changes: 2 additions & 2 deletions packages/agentctx/src/cli/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { existsSync } from "node:fs";
import { parseArgs } from "node:util";
import { loadConfig } from "../config.js";
import { openDatabase } from "../storage/db.js";
import { resolveProjectId } from "../storage/namespace.js";
import { resolveProjectId, shortProjectId } from "../storage/namespace.js";
import { GLOBAL_VISIBLE_SQL } from "../storage/records.js";
import { RECORD_TYPES } from "../storage/types.js";
import type { CliEnv } from "./env.js";
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function runStatus(env: CliEnv, args: string[]): Promise<number> {
const all = sessionTotals(db, null);
const config = loadConfig(env.configPath);

env.io.out(`agentctx status — project ${projectId.slice(0, 12)}… (${env.cwd})`);
env.io.out(`agentctx status — project ${shortProjectId(projectId)} (${env.cwd})`);
env.io.out("");
env.io.out("Context records (active):");
let total = 0;
Expand Down
5 changes: 5 additions & 0 deletions packages/agentctx/src/storage/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createHash } from "node:crypto";
import { resolve } from "node:path";

export { GLOBAL_PROJECT_ID } from "./types.js";
export const PROJECT_ID_DISPLAY_LEN = 12;

/**
* Normalize a git remote URL to a canonical `host/path` form: unifies
Expand Down Expand Up @@ -69,6 +70,10 @@ export function resolveProjectId(cwd: string = process.cwd()): string {
return projectIdFromPath(repoRoot ?? cwd);
}

export function shortProjectId(projectId: string): string {
return `${projectId.slice(0, PROJECT_ID_DISPLAY_LEN)}…`;
}

function git(args: string[], cwd: string): string | null {
try {
const out = execFileSync("git", args, {
Expand Down
10 changes: 10 additions & 0 deletions packages/agentctx/test/storage/namespace.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { describe, expect, it } from "vitest";
import {
PROJECT_ID_DISPLAY_LEN,
normalizeGitRemoteUrl,
projectIdFromPath,
projectIdFromRemote,
shortProjectId,
} from "../../src/storage/namespace.js";

describe("normalizeGitRemoteUrl", () => {
Expand Down Expand Up @@ -47,3 +49,11 @@ describe("project ids", () => {
expect(fromPath).not.toBe(projectIdFromRemote("github.com/org/repo"));
});
});

describe("shortProjectId", () => {
it("renders the first 12 hex chars plus an ellipsis", () => {
const projectId = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
expect(shortProjectId(projectId)).toBe("0123456789ab…");
expect(shortProjectId(projectId)).toHaveLength(PROJECT_ID_DISPLAY_LEN + 1);
});
});
Loading