Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

refactor(daemon): cleaner git author identity (plain name, name.disc email)

Claudette#9873a0782811fe52
diff --git a/src/daemon/src/drivers/cliTransport.test.ts b/src/daemon/src/drivers/cliTransport.test.ts
index c45c23208..c7cba9c11 100644
--- a/src/daemon/src/drivers/cliTransport.test.ts
+++ b/src/daemon/src/drivers/cliTransport.test.ts
@@ -149,18 +149,18 @@ describe("prepareCliTransport — layered spawn env", () => {
config: { agentName: "Melisa", agentDiscriminator: "1043" },
});
const { spawnEnv } = await prepareCliTransport(ctx, {}, undefined, "linux");
- expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Melisa#1043");
- expect(spawnEnv.GIT_AUTHOR_EMAIL).toBe("[email protected]");
- expect(spawnEnv.GIT_COMMITTER_NAME).toBe("Melisa#1043");
+ expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Melisa");
+ expect(spawnEnv.GIT_AUTHOR_EMAIL).toBe("[email protected]");
+ expect(spawnEnv.GIT_COMMITTER_NAME).toBe("Melisa");
expect(spawnEnv.GIT_COMMITTER_EMAIL).toBe(spawnEnv.GIT_AUTHOR_EMAIL);
});
- it("falls back to a valid generic git NAME when no agent name is set, email still keyed on agentId", async () => {
- // config: {} (baseCtx default) — degraded/unknown-bot spawn. baseCtx has
- // agentId "agent_1", so the email stays unique off the id even with no name.
+ it("falls back to a valid generic git identity when no agent name/discriminator is set", async () => {
+ // config: {} (baseCtx default) — degraded/unknown-bot spawn with no name
+ // and no discriminator, so identity falls back to the generic value.
const { spawnEnv } = await prepareCliTransport(baseCtx(mkTmp()), {}, undefined, "linux");
expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Alook Agent");
- expect(spawnEnv.GIT_AUTHOR_EMAIL).toBe("[email protected]");
+ expect(spawnEnv.GIT_AUTHOR_EMAIL).toBe("[email protected]");
expect(spawnEnv.GIT_AUTHOR_NAME).not.toBe("");
});
@@ -170,7 +170,7 @@ describe("prepareCliTransport — layered spawn env", () => {
config: { agentName: "Melisa", agentDiscriminator: "1043" },
});
const { spawnEnv } = await prepareCliTransport(ctx, { GIT_AUTHOR_NAME: "Someone Else" }, undefined, "linux");
- expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Melisa#1043");
+ expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Melisa");
});
it("creates a symlink when hostCliPath is set", async () => {
diff --git a/src/daemon/src/drivers/cliTransport.ts b/src/daemon/src/drivers/cliTransport.ts
index 0e23e89af..d80bbd55b 100644
--- a/src/daemon/src/drivers/cliTransport.ts
+++ b/src/daemon/src/drivers/cliTransport.ts
@@ -212,7 +212,6 @@ export async function prepareCliTransport(
vars: buildGitIdentityEnv({
agentName: ctx.config.agentName,
discriminator: ctx.config.agentDiscriminator,
- agentId: ctx.agentId,
}),
},
{
diff --git a/src/daemon/src/drivers/gitIdentityEnv.test.ts b/src/daemon/src/drivers/gitIdentityEnv.test.ts
index ad8b59575..fb37bd8e7 100644
--- a/src/daemon/src/drivers/gitIdentityEnv.test.ts
+++ b/src/daemon/src/drivers/gitIdentityEnv.test.ts
@@ -2,35 +2,32 @@ import { describe, it, expect } from "vitest";
import { buildGitIdentityEnv } from "./gitIdentityEnv";
describe("buildGitIdentityEnv", () => {
- it("normal identity — name#disc, unique email, author===committer", () => {
- const env = buildGitIdentityEnv({ agentName: "Melisa", discriminator: "1043", agentId: "a3f90c21beef" });
- expect(env.GIT_AUTHOR_NAME).toBe("Melisa#1043");
- expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
+ it("normal identity — plain name, [email protected] email, author===committer", () => {
+ const env = buildGitIdentityEnv({ agentName: "Claudette", discriminator: "9873" });
+ expect(env.GIT_AUTHOR_NAME).toBe("Claudette");
+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
expect(env.GIT_COMMITTER_NAME).toBe(env.GIT_AUTHOR_NAME);
expect(env.GIT_COMMITTER_EMAIL).toBe(env.GIT_AUTHOR_EMAIL);
});
- it("name with spaces/punct — email local-part is ASCII-slugged, display name kept", () => {
- const env = buildGitIdentityEnv({ agentName: "Bot One!", discriminator: "0007", agentId: "zzzz1111" });
- expect(env.GIT_AUTHOR_NAME).toBe("Bot One!#0007");
- expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
+ it("name with spaces/punct — email local-part is ASCII-slugged, display name kept plain", () => {
+ const env = buildGitIdentityEnv({ agentName: "Bot One!", discriminator: "0007" });
+ expect(env.GIT_AUTHOR_NAME).toBe("Bot One!");
+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
});
- it("CJK/emoji name — empty ASCII slug is dropped, email falls back to disc+shortid, display keeps UTF-8", () => {
- const env = buildGitIdentityEnv({ agentName: "总部🎉", discriminator: "1043", agentId: "a3f90c21beef" });
- expect(env.GIT_AUTHOR_NAME).toBe("总部🎉#1043");
- expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
+ it("CJK/emoji name — empty ASCII slug dropped, email falls back to disc only, display keeps UTF-8", () => {
+ const env = buildGitIdentityEnv({ agentName: "总部🎉", discriminator: "1043" });
+ expect(env.GIT_AUTHOR_NAME).toBe("总部🎉");
+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
});
it("strips control chars / newlines from the name (guards commit-metadata injection)", () => {
- const env = buildGitIdentityEnv({
- agentName: "Evil\r\nBot\x00 X",
- discriminator: "1234",
- agentId: "deadbeef00",
- });
+ const env = buildGitIdentityEnv({ agentName: "Evil\r\nBot\x00 X", discriminator: "1234" });
// Control chars removed; the surviving space between "Bot" and "X" stays.
- expect(env.GIT_AUTHOR_NAME).toBe("EvilBot X#1234");
+ expect(env.GIT_AUTHOR_NAME).toBe("EvilBot X");
expect(env.GIT_AUTHOR_NAME).not.toMatch(/[\n\r\x00]/);
+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
});
it("missing identity — falls back to a valid generic identity, never empty", () => {
@@ -40,18 +37,21 @@ describe("buildGitIdentityEnv", () => {
for (const v of Object.values(env)) expect(v).not.toBe("");
});
- it("UNIQUENESS — same name AND same discriminator but different agentId ⇒ DIFFERENT emails", () => {
- const a = buildGitIdentityEnv({ agentName: "Twin", discriminator: "1043", agentId: "aaaaaaaa1111" });
- const b = buildGitIdentityEnv({ agentName: "Twin", discriminator: "1043", agentId: "bbbbbbbb2222" });
- expect(a.GIT_AUTHOR_NAME).toBe(b.GIT_AUTHOR_NAME); // display collides — that's fine
- expect(a.GIT_AUTHOR_EMAIL).not.toBe(b.GIT_AUTHOR_EMAIL); // machine-readable key must not
- expect(a.GIT_AUTHOR_EMAIL).toBe("[email protected]");
- expect(b.GIT_AUTHOR_EMAIL).toBe("[email protected]");
+ it("name present but no discriminator — email local-part is just the name slug", () => {
+ const env = buildGitIdentityEnv({ agentName: "Claudette" });
+ expect(env.GIT_AUTHOR_NAME).toBe("Claudette");
+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");
});
- it("agentId is ASCII-slugged before slicing (nanoid '_'/'-' stay email-safe)", () => {
- const env = buildGitIdentityEnv({ agentName: "X", discriminator: "0001", agentId: "Ab_9-Cd_ef" });
- // local-part contains only [a-z0-9-]; no stray underscores from the id.
- expect(env.GIT_AUTHOR_EMAIL).toMatch(/^[a-z0-9-]+@alook\.ai$/);
+ it("email local-part is always email-safe ([a-z0-9.-])", () => {
+ const env = buildGitIdentityEnv({ agentName: "A B_c", discriminator: "0001" });
+ expect(env.GIT_AUTHOR_EMAIL).toMatch(/^[a-z0-9.-]+@alook\.ai$/);
+ });
+
+ it("same name AND discriminator ⇒ same identity (accepted collision — no agentId suffix)", () => {
+ const a = buildGitIdentityEnv({ agentName: "Twin", discriminator: "1043" });
+ const b = buildGitIdentityEnv({ agentName: "Twin", discriminator: "1043" });
+ expect(a.GIT_AUTHOR_EMAIL).toBe(b.GIT_AUTHOR_EMAIL);
+ expect(a.GIT_AUTHOR_EMAIL).toBe("[email protected]");
});
});
diff --git a/src/daemon/src/drivers/gitIdentityEnv.ts b/src/daemon/src/drivers/gitIdentityEnv.ts
index 57d5718cc..7bdbde4e8 100644
--- a/src/daemon/src/drivers/gitIdentityEnv.ts
+++ b/src/daemon/src/drivers/gitIdentityEnv.ts
@@ -10,18 +10,17 @@
* Both author and committer are set: git falls back committer → machine
* identity otherwise, which would leave attribution half-wrong.
*
- * The EMAIL is the machine-readable attribution key and MUST be unique per
- * agent. The discriminator alone is not enough (it is FNV-1a(user.id) mod
- * 10000 — a 4-digit space with expected collisions), and the display-name slug
- * is lossy ("Bot One"/"Bot-One" → "bot-one"). Uniqueness therefore comes from
- * `agentId` (a nanoid): a slice of it suffixes the local-part so two distinct
- * agents can never share an email even when name and discriminator collide.
- * The NAME field stays the human `Name#Disc` — display only, so cosmetic
- * ambiguity there is acceptable.
+ * NAME is the plain display name (`Claudette`) and EMAIL is
+ * `<name-slug>.<discriminator>@alook.ai` (`[email protected]`) — kept
+ * clean/readable per owner preference. The discriminator is FNV-1a(user.id)
+ * mod 10000, so two agents that share a name AND a discriminator would produce
+ * the same identity; that collision is accepted (name#disc is already the
+ * app's display-unique key, and the odds are low). If per-agent uniqueness
+ * ever needs to be guaranteed on the git side again, reintroduce an agentId
+ * suffix in the local-part.
*/
const GIT_IDENTITY_DOMAIN = "alook.ai";
-const SHORT_ID_LEN = 8;
/** Generic identity when an agent's name/handle is unavailable (degraded spawn). */
const FALLBACK_NAME = "Alook Agent";
@@ -55,31 +54,31 @@ function asciiSlug(s: string): string {
export interface GitIdentityInput {
agentName?: string;
discriminator?: string;
- agentId?: string;
}
/**
* Build the four `GIT_*` env vars for one agent. Pure — no I/O. Always returns
* a valid, non-empty identity; falls back to a generic one when name is
* missing.
+ *
+ * Name = the plain display name (`Claudette`). Email =
+ * `<name-slug>.<discriminator>@alook.ai` (`[email protected]`); if the
+ * name has no ASCII-alphanumeric characters (all CJK/emoji) the local-part is
+ * just the discriminator (`[email protected]`), and if neither is available it
+ * falls back to `[email protected]`.
*/
export function buildGitIdentityEnv(input: GitIdentityInput): Record<string, string> {
- const { agentName, discriminator, agentId } = input;
+ const { agentName, discriminator } = input;
const cleanName = agentName ? sanitizeGitName(agentName) : "";
- const displayName = cleanName
- ? discriminator
- ? `${cleanName}#${discriminator}`
- : cleanName
- : FALLBACK_NAME;
+ const displayName = cleanName || FALLBACK_NAME;
- // Local-part fragments in readability order: name slug, discriminator, and a
- // short slice of the (globally unique) agentId. The agentId slice is what
- // guarantees per-agent uniqueness; the rest is for human readability.
- const shortId = agentId ? asciiSlug(agentId).slice(0, SHORT_ID_LEN) : "";
+ // Email local-part: `<name-slug>.<discriminator>`, joined with "." and
+ // dropping any empty fragment (all-CJK name → discriminator only; neither →
+ // generic fallback).
const nameSlug = cleanName ? asciiSlug(cleanName) : "";
const localPart =
- [nameSlug, discriminator, shortId].filter(Boolean).join("-") || FALLBACK_LOCAL_PART;
+ [nameSlug, discriminator].filter(Boolean).join(".") || FALLBACK_LOCAL_PART;
const email = `${localPart}@${GIT_IDENTITY_DOMAIN}`;
return {