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.

feat(init): ask only what needs a decision

Erend5cd34b1b320
diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md
index e3a595f..ad05289 100644
--- a/docs/guide/getting-started.md
+++ b/docs/guide/getting-started.md
@@ -44,20 +44,23 @@ cd your-project
cogit init
```
-`init` asks a few questions. Every one has a flag, so `cogit init --yes` with flags runs
-without asking.
+`init` asks two questions; the rest have sensible defaults, and every one has a flag so
+`cogit init --yes` runs without asking.
| Question | Default | Flag |
|---|---|---|
| Project name | the directory name | `--name` |
| Commit the session records to git? | yes | `--git commit\|ignore` |
| Keep Claude Code transcripts longer? Claude Code deletes them after 30 days by default. | keep as is | `--retention <days\|keep>` |
-| Let the agent update the record without asking each time? | yes | `--allow-skill` / `--no-allow-skill` |
-| Turn the plugin on for everyone who opens this repository? | yes | `--project-settings` / `--no-project-settings` |
-| Summary language | the conversation's | `--language <lang\|auto>` |
-`init` changes your Claude Code settings only for the questions you agreed to. It backs up
-`~/.claude/settings.json` before the first change and prints what it changed.
+Without asking, `init` lets the agent run the cogit skill without a permission prompt (so it
+updates the record as it works), turns the plugin on for the project (writes
+`.claude/settings.json`, which a teammate's session reads to load the plugin and stops one
+that started without it), and sets the summary language to the conversation's.
+`--no-allow-skill`, `--no-project-settings` and `--language <lang|auto>` override them, and
+`--yes` leaves Claude Code's settings unchanged.
+
+`init` backs up `~/.claude/settings.json` before the first change and prints what it changed.
Running `init` again in a set-up project changes nothing except what you pass as flags, and
refreshes the git hooks.
diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts
index a2e4ffc..76cffdc 100644
--- a/packages/cli/src/commands/init.ts
+++ b/packages/cli/src/commands/init.ts
@@ -89,17 +89,9 @@ async function askSkillPermission(io: Io, opts: InitOptions): Promise<void> {
return;
}
if (allowed) return;
- const allow =
- opts.allowSkill ??
- (await io.prompt.confirm(
- "Let the agent update the lineage record without asking each time? " +
- `(adds ${agent.skillRule} to your Claude Code permissions)`,
- true,
- ));
- if (!allow) {
- io.out(
- `Claude Code will ask before each lineage update; allow ${agent.skillRule} to stop that.`,
- );
+ // Recording is what the plugin is for: allow the skill unless asked not to.
+ if (opts.allowSkill === false) {
+ io.out(`Claude Code will ask before each cogit update; allow ${agent.skillRule} to stop that.`);
return;
}
const { file, backup } = await agent.allowSkill(io.env, io.now());
@@ -113,14 +105,9 @@ async function askProjectSettings(io: Io, root: string, opts: InitOptions): Prom
return;
}
if (done) return;
- const add =
- opts.projectSettings ??
- (await io.prompt.confirm(
- "Turn the plugin on for everyone who opens this project, and stop a session that " +
- "started without it? (writes .claude/settings.json; commit it to share)",
- true,
- ));
- if (!add) return;
+ // On by default: the project's settings are what tells a teammate's session
+ // to load the plugin at all.
+ if (opts.projectSettings === false) return;
await bestEffort(io, "could not update the project's Claude Code settings", async () => {
const { file } = await agent.writeProjectSetup(root);
io.out(`Enabled the plugin and the missing-plugin guard in ${file}.`);
@@ -130,21 +117,9 @@ async function askProjectSettings(io: Io, root: string, opts: InitOptions): Prom
async function askLanguage(io: Io, opts: InitOptions): Promise<void> {
const firstRun = !(await readJson(globalPaths(io.env).config)).found;
if (!firstRun && opts.language === undefined) return;
- let language = opts.language;
- if (language === undefined) {
- const mode = await io.prompt.select(
- "Language for session summaries?",
- [
- { value: "auto", name: "Same as the conversation (auto)" },
- { value: "fixed", name: "Always one language" },
- ],
- "auto",
- );
- language = mode === "auto" ? "auto" : await io.prompt.input("Which language?", "English");
- }
- const lang = language;
+ // The conversation's own language is the default; `--language` overrides it.
await bestEffort(io, "could not save global config", () =>
- updateConfig((c) => ({ ...c, language: lang }), io.env),
+ updateConfig((c) => ({ ...c, language: opts.language ?? "auto" }), io.env),
);
}
diff --git a/packages/cli/src/program.ts b/packages/cli/src/program.ts
index 6ed9068..e7a406c 100644
--- a/packages/cli/src/program.ts
+++ b/packages/cli/src/program.ts
@@ -364,7 +364,7 @@ export function createProgram(makeIo: IoFactory = processIo, deps: ProgramDeps =
)
.option("--language <lang>", 'summary language: "auto" or a language')
.option("--retention <days>", 'Claude Code transcript retention, or "keep"', retention)
- .option("--allow-skill", "let the agent run the lineage skill without asking")
+ .option("--allow-skill", "let the agent run the cogit skill without asking")
.option("--no-allow-skill", "leave Claude Code's permissions unchanged")
.option(
"--project-settings",
diff --git a/packages/cli/test/init.test.ts b/packages/cli/test/init.test.ts
index 7a8318d..cf62adf 100644
--- a/packages/cli/test/init.test.ts
+++ b/packages/cli/test/init.test.ts
@@ -77,8 +77,8 @@ describe("init", () => {
data: { projects: [{ path: root, name: "proj" }] },
});
expect((await loadConfig(env)).language).toBe("auto");
- // name, git policy, retention, skill permission, project settings and language
- expect(io.asked).toHaveLength(6);
+ // name, git policy and retention; the rest take their defaults
+ expect(io.asked).toHaveLength(3);
expect(await readProjectSetup(root)).toBe(true);
expect(await readSkillAllowed(env)).toBe(true);
expect(io.lines.at(-2)).toMatch(/^Initialized proj/);
@@ -182,7 +182,7 @@ describe("init", () => {
const io = fakeIo(env);
await init(root, {}, io);
expect(io.lines).toContain("Claude Code keeps transcripts for 365 days.");
- expect(io.asked).toHaveLength(5);
+ expect(io.asked).toHaveLength(2);
});
it("applies a retention option without asking, and skips an unchanged one", async () => {
@@ -233,14 +233,15 @@ describe("init", () => {
expect(await readText(settingsFile())).toBe("{oops");
});
- it("asks which fixed language on the first run only", async () => {
- await init(root, {}, fakeIo(env, ["proj", "commit", "keep", "yes", "yes", "fixed", "Turkish"]));
- expect((await loadConfig(env)).language).toBe("Turkish");
+ it("takes the conversation's language without asking, and the option when given", async () => {
+ const io = fakeIo(env, ["proj", "commit", "keep"]);
+ await init(root, {}, io);
+ expect((await loadConfig(env)).language).toBe("auto");
+ expect(io.asked.some((q) => q.startsWith("Language"))).toBe(false);
const second = join(dir, "second");
await mkdir(second);
- const io = fakeIo(env);
- await init(second, {}, io);
- expect(io.asked.some((q) => q.startsWith("Language"))).toBe(false);
+ await init(second, { language: "Turkish" }, fakeIo(env));
+ expect((await loadConfig(env)).language).toBe("Turkish");
});
it("adds the skill rule to existing permissions, and only once", async () => {
@@ -263,12 +264,12 @@ describe("init", () => {
expect(again.asked.some((q) => q.startsWith("Let the agent"))).toBe(false);
});
- it("leaves permissions alone when declined", async () => {
- const io = fakeIo(env, ["proj", "commit", "keep", "no"]);
- await init(root, {}, io);
+ it("leaves permissions alone when declined with the flag", async () => {
+ const io = fakeIo(env, ["proj", "commit", "keep"]);
+ await init(root, { allowSkill: false }, io);
expect(await readSkillAllowed(env)).toBe(false);
expect(io.lines).toContain(
- `Claude Code will ask before each lineage update; allow ${SKILL_RULE} to stop that.`,
+ `Claude Code will ask before each cogit update; allow ${SKILL_RULE} to stop that.`,
);
});