Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat(daemon): credit the human owner as author, agent as committer
Claudette9920e5cdc499
diff --git a/src/daemon/src/drivers/cliTransport.test.ts b/src/daemon/src/drivers/cliTransport.test.tsindex c7cba9c11..2ec102342 100644--- a/src/daemon/src/drivers/cliTransport.test.ts+++ b/src/daemon/src/drivers/cliTransport.test.ts@@ -1,4 +1,4 @@-import { describe, it, expect, afterEach } from "vitest";+import { describe, it, expect, afterEach, vi } from "vitest";import * as fs from "fs";import * as os from "os";import * as path from "path";@@ -7,6 +7,19 @@ import { CredentialBroker } from "../credentials/credentialProxy";import type { LaunchContext } from "../types";import { makeRuntimeConfig } from "../runtimeConfig";+// The git-identity two-author split reads the HOST owner's `git config`+// (readHostGitIdentity) at spawn. That would make GIT_AUTHOR_* depend on+// whatever git identity the test machine happens to have — flaky across+// dev/CI. Mock the read to a controllable value; keep buildGitIdentityEnv+// real. Hoisted vi.mock is file-scoped (no cross-file leak). Default: no host+// identity → agent is both author+committer (the pre-two-author behavior the+// existing assertions expect); the two-author test overrides it.+const mockReadHostGitIdentity = vi.fn<() => { name?: string; email?: string } | null>(() => null);+vi.mock("./gitIdentityEnv.js", async (importActual) => {+ const actual = await importActual<typeof import("./gitIdentityEnv.js")>();+ return { ...actual, readHostGitIdentity: () => mockReadHostGitIdentity() };+});+const tmpDirs: string[] = [];function mkTmp(): string {const d = fs.mkdtempSync(path.join(os.tmpdir(), "clitransport-"));@@ -173,6 +186,20 @@ describe("prepareCliTransport — layered spawn env", () => {expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Melisa");});+ it("two-author: host owner git identity ⇒ AUTHOR = owner, COMMITTER = agent", async () => {+ mockReadHostGitIdentity.mockReturnValueOnce({ name: "Gus", email: "[email protected]" });+ const ctx = baseCtx(mkTmp(), {+ agentId: "a3f90c21beef",+ config: { agentName: "Melisa", agentDiscriminator: "1043" },+ });+ const { spawnEnv } = await prepareCliTransport(ctx, {}, undefined, "linux");+ // Author = the human owner (they wrote it), committer = the agent.+ expect(spawnEnv.GIT_AUTHOR_NAME).toBe("Gus");+ expect(spawnEnv.GIT_AUTHOR_EMAIL).toBe("[email protected]");+ expect(spawnEnv.GIT_COMMITTER_NAME).toBe("Melisa");+ expect(spawnEnv.GIT_COMMITTER_EMAIL).toBe("[email protected]");+ });+it("creates a symlink when hostCliPath is set", async () => {const wd = mkTmp();const host = path.join(wd, "real.js");diff --git a/src/daemon/src/drivers/cliTransport.ts b/src/daemon/src/drivers/cliTransport.tsindex d80bbd55b..c7ad694b0 100644--- a/src/daemon/src/drivers/cliTransport.ts+++ b/src/daemon/src/drivers/cliTransport.ts@@ -48,7 +48,7 @@ import { buildCliSystemPrompt } from "./systemPrompt.js";import { resolveLaunchFieldsOrDefault } from "../runtimeConfig.js";import { writeCliLink } from "./cliLink.js";import { mergeEnvLayers, platformEnv, runtimeContextEnv, type EnvLayer } from "./spawnEnv.js";-import { buildGitIdentityEnv } from "./gitIdentityEnv.js";+import { buildGitIdentityEnv, readHostGitIdentity } from "./gitIdentityEnv.js";import { writeAgentFile } from "./agentFile.js";export interface PreparedCliTransport {@@ -201,9 +201,12 @@ export async function prepareCliTransport({ name: "hostStatic", precedence: 10, vars: cli.extraEnv ?? {} },{ name: "userEnv", precedence: 20, vars: resolved.envVars },{ name: "driver", precedence: 30, vars: extraEnv as Record<string, string | undefined> },- // Per-agent git identity (GIT_AUTHOR_*/GIT_COMMITTER_*) so commits are- // attributed to the agent that made them. ENV-ONLY by design — never writes- // ~/.gitconfig or any repo .git/config, so the owner's own git identity is+ // Per-agent git identity (GIT_AUTHOR_*/GIT_COMMITTER_*). Two-author+ // attribution: when the host owner has a git identity, AUTHOR = the owner+ // (they wrote it) and COMMITTER = the agent (it applied it); with no host+ // identity, the agent is both. ENV-ONLY for WRITES — reads the owner's+ // existing `git config user.*` to credit them, but never writes+ // ~/.gitconfig or any repo .git/config, so the owner's git state is// untouched. Above `driver` (30) so a driver can't clobber it; below// `platformContract` (40) though keys don't overlap. Not sensitive.{@@ -212,6 +215,7 @@ export async function prepareCliTransport(vars: buildGitIdentityEnv({agentName: ctx.config.agentName,discriminator: ctx.config.agentDiscriminator,+ hostUser: readHostGitIdentity() ?? undefined,}),},{diff --git a/src/daemon/src/drivers/gitIdentityEnv.test.ts b/src/daemon/src/drivers/gitIdentityEnv.test.tsindex fb37bd8e7..f2e42da02 100644--- a/src/daemon/src/drivers/gitIdentityEnv.test.ts+++ b/src/daemon/src/drivers/gitIdentityEnv.test.ts@@ -54,4 +54,61 @@ describe("buildGitIdentityEnv", () => {expect(a.GIT_AUTHOR_EMAIL).toBe(b.GIT_AUTHOR_EMAIL);expect(a.GIT_AUTHOR_EMAIL).toBe("[email protected]");});++ it("host user present (name+email) ⇒ AUTHOR = human owner, COMMITTER = agent (two-author split)", () => {+ const env = buildGitIdentityEnv({+ agentName: "Claudette",+ discriminator: "9873",+ hostUser: { name: "Gus", email: "[email protected]" },+ });+ // Author = the human owner (they wrote it).+ expect(env.GIT_AUTHOR_NAME).toBe("Gus");+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");+ // Committer = the agent (it applied it).+ expect(env.GIT_COMMITTER_NAME).toBe("Claudette");+ expect(env.GIT_COMMITTER_EMAIL).toBe("[email protected]");+ });++ it("host user with only a name (no email) ⇒ not enough to attribute → agent is both", () => {+ const env = buildGitIdentityEnv({+ agentName: "Claudette",+ discriminator: "9873",+ hostUser: { name: "Gus" },+ });+ expect(env.GIT_AUTHOR_NAME).toBe("Claudette");+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");+ expect(env.GIT_COMMITTER_NAME).toBe("Claudette");+ expect(env.GIT_COMMITTER_EMAIL).toBe("[email protected]");+ });++ it("host user with only an email (no name) ⇒ not enough to attribute → agent is both", () => {+ const env = buildGitIdentityEnv({+ agentName: "Claudette",+ discriminator: "9873",+ hostUser: { email: "[email protected]" },+ });+ expect(env.GIT_AUTHOR_NAME).toBe("Claudette");+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");+ });++ it("host user name is control-char/newline sanitized (commit-metadata injection guard)", () => {+ const env = buildGitIdentityEnv({+ agentName: "Claudette",+ discriminator: "9873",+ hostUser: { name: "Real\r\nHuman", email: "[email protected]" },+ });+ expect(env.GIT_AUTHOR_NAME).toBe("RealHuman");+ expect(env.GIT_AUTHOR_NAME).not.toMatch(/[\n\r\x00]/);+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");+ });++ it("empty-string host name/email ⇒ treated as absent → agent is both", () => {+ const env = buildGitIdentityEnv({+ agentName: "Claudette",+ discriminator: "9873",+ hostUser: { name: "", email: "" },+ });+ expect(env.GIT_AUTHOR_NAME).toBe("Claudette");+ expect(env.GIT_AUTHOR_EMAIL).toBe("[email protected]");+ });});diff --git a/src/daemon/src/drivers/gitIdentityEnv.ts b/src/daemon/src/drivers/gitIdentityEnv.tsindex 7bdbde4e8..3b259ec9a 100644--- a/src/daemon/src/drivers/gitIdentityEnv.ts+++ b/src/daemon/src/drivers/gitIdentityEnv.ts@@ -20,8 +20,13 @@* suffix in the local-part.*/+import { execFileSync } from "child_process";+const GIT_IDENTITY_DOMAIN = "alook.ai";+/** Timeout for the `git config` read of the host owner's identity. */+const HOST_GIT_READ_TIMEOUT_MS = 2000;+/** Generic identity when an agent's name/handle is unavailable (degraded spawn). */const FALLBACK_NAME = "Alook Agent";const FALLBACK_LOCAL_PART = "alook-agent";@@ -51,9 +56,26 @@ function asciiSlug(s: string): string {.replace(/^-+|-+$/g, "");}+/** The host owner's own git identity, if their environment has one. */+export interface HostGitUser {+ name?: string;+ email?: string;+}+export interface GitIdentityInput {agentName?: string;discriminator?: string;+ /**+ * The host owner's own git identity (from `git config user.name/user.email`),+ * when present. When BOTH name and email are legible, the commit is+ * attributed two-ways: AUTHOR = the human owner (they wrote it), COMMITTER =+ * the agent (it applied it) — git's native author≠committer, both visible in+ * `git log --format=fuller` / on GitHub. When absent (owner never set a git+ * identity), falls back to the agent as both author and committer (today's+ * behavior). Read at the I/O boundary (`readHostGitIdentity`) and passed in;+ * this builder stays pure.+ */+ hostUser?: HostGitUser;}/**@@ -61,14 +83,19 @@ export interface GitIdentityInput {* 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]`.+ * The agent's own identity: 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]`.+ *+ * Two-author attribution: when `hostUser` carries a legible name AND email,+ * AUTHOR is set to the human owner and COMMITTER to the agent (git's native+ * author/committer split — "the human wrote it, the agent committed it"). With+ * no host identity, author and committer are both the agent (today's behavior).*/export function buildGitIdentityEnv(input: GitIdentityInput): Record<string, string> {- const { agentName, discriminator } = input;+ const { agentName, discriminator, hostUser } = input;const cleanName = agentName ? sanitizeGitName(agentName) : "";const displayName = cleanName || FALLBACK_NAME;@@ -81,10 +108,64 @@ export function buildGitIdentityEnv(input: GitIdentityInput): Record<string, str[nameSlug, discriminator].filter(Boolean).join(".") || FALLBACK_LOCAL_PART;const email = `${localPart}@${GIT_IDENTITY_DOMAIN}`;+ // Two-author split: only when the host owner has a legible name AND email+ // (partial/empty → not enough to attribute, keep agent-only). Sanitize the+ // host name the same way (it also becomes a git header line). The host email+ // is used verbatim except for CR/LF/control stripping — it is the owner's+ // real address, not something we mint.+ const hostName = hostUser?.name ? sanitizeGitName(hostUser.name) : "";+ const hostEmail = hostUser?.email ? sanitizeGitName(hostUser.email) : "";+ const hasHostAuthor = hostName !== "" && hostEmail !== "";+return {- GIT_AUTHOR_NAME: displayName,- GIT_AUTHOR_EMAIL: email,+ GIT_AUTHOR_NAME: hasHostAuthor ? hostName : displayName,+ GIT_AUTHOR_EMAIL: hasHostAuthor ? hostEmail : email,GIT_COMMITTER_NAME: displayName,GIT_COMMITTER_EMAIL: email,};}++let hostGitIdentityMemo: { value: HostGitUser | null } | undefined;++/**+ * Read the host owner's own git identity from their git config+ * (`git config --get user.name` / `user.email`). READ-ONLY: this only reads+ * the owner's existing config — it never writes `~/.gitconfig` or any repo's+ * `.git/config` (the module's env-only invariant is about not MUTATING the+ * owner's git state; reading their name/email to credit them as author does+ * not touch it). Returns `null` for a field the owner never set, and never+ * throws — any failure (git absent, config unset, timeout) degrades to no host+ * user, so `buildGitIdentityEnv` falls back to agent-only attribution.+ *+ * MEMOIZED for the daemon process: the host owner's git identity is static+ * across the process lifetime, and this sits on the per-spawn hot path (two+ * synchronous `git` forks otherwise), so the result — including `null` — is+ * cached after the first read. `resetHostGitIdentityCache()` clears it (tests).+ */+export function readHostGitIdentity(): HostGitUser | null {+ if (hostGitIdentityMemo) return hostGitIdentityMemo.value;+ const read = (key: string): string | undefined => {+ try {+ const out = execFileSync("git", ["config", "--get", key], {+ encoding: "utf8",+ timeout: HOST_GIT_READ_TIMEOUT_MS,+ stdio: ["ignore", "pipe", "ignore"],+ }).trim();+ return out.length > 0 ? out : undefined;+ } catch {+ // Unset key exits non-zero; git missing / timeout throws — all mean+ // "no host identity for this field", never fatal.+ return undefined;+ }+ };+ const name = read("user.name");+ const email = read("user.email");+ const value = name === undefined && email === undefined ? null : { name, email };+ hostGitIdentityMemo = { value };+ return value;+}++/** Clear the memoized host git identity (test-only; the value is static in prod). */+export function resetHostGitIdentityCache(): void {+ hostGitIdentityMemo = undefined;+}