Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

fix(init): skip the plugin install hint when the plugin is installed

Eren5bf5b42e2294
diff --git a/packages/cli/src/agents/claude/index.ts b/packages/cli/src/agents/claude/index.ts
index c51d6f8..d9c5fc9 100644
--- a/packages/cli/src/agents/claude/index.ts
+++ b/packages/cli/src/agents/claude/index.ts
@@ -3,7 +3,9 @@ import { additionalContext, parseHookInput } from "./hooks.js";
import {
allowSkill,
CLAUDE_DEFAULT_RETENTION,
+ INSTALL_COMMAND,
markLive,
+ readPluginInstalled,
readProjectSetup,
readRetention,
readSkillAllowed,
@@ -34,6 +36,7 @@ export const claude: AgentAdapter = {
name: DEFAULT_AGENT,
skill: "/cogit:record",
skillRule: SKILL_RULE,
+ installCommand: INSTALL_COMMAND,
projectDirEnv: "CLAUDE_PROJECT_DIR",
pluginRootEnv: "CLAUDE_PLUGIN_ROOT",
sessionIdEnv: "CLAUDE_SESSION_ID",
@@ -55,6 +58,7 @@ export const claude: AgentAdapter = {
additionalContext,
readRetention,
+ readPluginInstalled,
readSkillAllowed,
setRetention,
allowSkill,
diff --git a/packages/cli/src/agents/claude/settings.ts b/packages/cli/src/agents/claude/settings.ts
index 0d82927..f9e0b07 100644
--- a/packages/cli/src/agents/claude/settings.ts
+++ b/packages/cli/src/agents/claude/settings.ts
@@ -112,6 +112,20 @@ export const MARKETPLACE = "cogit";
export const MARKETPLACE_REPO = "erensrtky/cogit";
export const INSTALL_COMMAND = `claude plugin install cogit --marketplace ${MARKETPLACE_REPO}`;
+/**
+ * Whether Claude Code lists the plugin as installed, in any scope; undefined when its
+ * plugin list cannot be read (missing or another shape), so the caller says nothing either way.
+ */
+export async function readPluginInstalled(env: NodeJS.ProcessEnv): Promise<boolean | undefined> {
+ const base = env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
+ const read = await readJson(join(base, "plugins", "installed_plugins.json"));
+ if (!read.found || "error" in read) return undefined;
+ const plugins = isObject(read.value) ? read.value.plugins : undefined;
+ if (!isObject(plugins)) return undefined;
+ const entries = plugins[PLUGIN_ID];
+ return Array.isArray(entries) && entries.length > 0;
+}
+
/** Where a session's SessionStart leaves its mark; the guard reads the same path. */
export function liveDir(): string {
return join(tmpdir(), "cogit-live");
diff --git a/packages/cli/src/agents/types.ts b/packages/cli/src/agents/types.ts
index 22a441b..198c1ef 100644
--- a/packages/cli/src/agents/types.ts
+++ b/packages/cli/src/agents/types.ts
@@ -93,6 +93,8 @@ export interface AgentAdapter {
readonly skill: string;
/** The permission rule that allows the skill without a prompt. */
readonly skillRule: string;
+ /** The shell command that installs the plugin. */
+ readonly installCommand: string;
/** Env var the agent sets to the project directory for hooks. */
readonly projectDirEnv: string;
/** Env var that points at the installed plugin (skill text uses it). */
@@ -137,6 +139,8 @@ export interface AgentAdapter {
additionalContext(event: string, text: string): Record<string, unknown>;
/** Days the agent keeps transcripts, undefined when the setting is unreadable. */
readRetention(env: NodeJS.ProcessEnv): Promise<number | undefined>;
+ /** Whether the agent lists the plugin as installed; undefined when unreadable. */
+ readPluginInstalled(env: NodeJS.ProcessEnv): Promise<boolean | undefined>;
/** Whether the record skill is already allowed; undefined when unreadable. */
readSkillAllowed(env: NodeJS.ProcessEnv): Promise<boolean | undefined>;
/** Sets the transcript retention in the agent's settings. */
diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts
index 48627df..e64edac 100644
--- a/packages/cli/src/commands/init.ts
+++ b/packages/cli/src/commands/init.ts
@@ -255,5 +255,10 @@ export async function init(dir: string, opts: InitOptions, io: Io): Promise<void
: "Conversations are stored in .cogit/conversations/ (kept out of git; turn on shareConversations to share them).",
);
io.out(`Initialized ${name} in ${projectPaths(root).base}`);
- io.out("Next: install the Claude Code plugin, then run `cogit open` after a session.");
+ const installed = await agent.readPluginInstalled(io.env).catch(() => undefined);
+ io.out(
+ installed
+ ? "Next: work with Claude Code here, then run `cogit open` to see the map."
+ : `Next: install the Claude Code plugin (\`${agent.installCommand}\`), then run \`cogit open\` after a session.`,
+ );
}
diff --git a/packages/cli/test/init.test.ts b/packages/cli/test/init.test.ts
index 89c374b..8a450b5 100644
--- a/packages/cli/test/init.test.ts
+++ b/packages/cli/test/init.test.ts
@@ -7,6 +7,7 @@ import { promisify } from "node:util";
import { beforeEach, describe, expect, it } from "vitest";
import {
allowSkill,
+ readPluginInstalled,
readProjectSetup,
readRetention,
readSkillAllowed,
@@ -78,6 +79,8 @@ describe("init", () => {
expect(await readProjectSetup(root)).toBe(true);
expect(await readSkillAllowed(env)).toBe(true);
expect(io.lines.at(-2)).toMatch(/^Initialized proj/);
+ // No plugin list in this Claude Code config: the last line says how to install it.
+ expect(io.lines.at(-1)).toContain("claude plugin install cogit --marketplace erensrtky/cogit");
// The default commit policy writes the project's own ignore rules.
expect(await readText(join(root, ".cogit", ".gitignore"))).toBe(cogitGitignore(false));
expect(io.lines).toContain(
@@ -85,6 +88,31 @@ describe("init", () => {
);
});
+ it("skips the install hint when Claude Code lists the plugin as installed", async () => {
+ const list = join(env.CLAUDE_CONFIG_DIR ?? "", "plugins", "installed_plugins.json");
+ await mkdir(join(list, ".."), { recursive: true });
+ const write = (plugins: unknown) => writeFile(list, JSON.stringify({ version: 2, plugins }));
+
+ await write({ "cogit@cogit": [{ scope: "user", version: "0.19.0" }] });
+ expect(await readPluginInstalled(env)).toBe(true);
+ const io = fakeIo(env);
+ await init(root, {}, io);
+ expect(io.lines.at(-1)).toBe(
+ "Next: work with Claude Code here, then run `cogit open` to see the map.",
+ );
+
+ // Another plugin only, an empty entry, or a list of another shape.
+ await write({ "other@market": [{ scope: "user" }] });
+ expect(await readPluginInstalled(env)).toBe(false);
+ await write({ "cogit@cogit": [] });
+ expect(await readPluginInstalled(env)).toBe(false);
+ await write(["cogit@cogit"]);
+ expect(await readPluginInstalled(env)).toBeUndefined();
+ await writeFile(list, "[1,");
+ expect(await readPluginInstalled(env)).toBeUndefined();
+ expect(await readPluginInstalled({ CLAUDE_CONFIG_DIR: join(dir, "nowhere") })).toBeUndefined();
+ });
+
it("writes the project ignore file once for the commit policy", async () => {
await mkdir(join(root, ".cogit"));
expect(await ensureCogitGitignore(root, "commit", false)).toBe(true);