agjan 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,8 +86,9 @@ Approval commands are meant for humans in a terminal. agjan makes it hard for an
86
86
  to run them (instructions, deny rules and hooks, and a confirmation read from the
87
87
  terminal), but a model with unrestricted shell access could in principle get around
88
88
  that. The trust boundary is the reviewed merge of the pull request; branch protection
89
- with the required `agjan-check` status and CODEOWNERS are the recommended hardening.
90
- See section 9.4 of the design.
89
+ with the required `agjan-check` status and CODEOWNERS are the recommended hardening
90
+ ([guide](docs/guide.md#protecting-the-main-branch-on-github-optional)). See section 9.4
91
+ of the design.
91
92
 
92
93
  ## Contributing
93
94
 
package/docs/guide.md CHANGED
@@ -10,7 +10,7 @@ in the [design](design.md); this guide is about using it.
10
10
  - [Commands](#commands)
11
11
  - [Configuration](#configuration)
12
12
  - [Hosts](#hosts)
13
- - [CI and repository settings](#ci-and-repository-settings)
13
+ - [Protecting the main branch on GitHub](#protecting-the-main-branch-on-github-optional)
14
14
  - [Upgrading](#upgrading)
15
15
  - [Troubleshooting](#troubleshooting)
16
16
 
@@ -49,13 +49,15 @@ Then:
49
49
  1. Open the project in Claude Code once and **trust the folder**: the reviewer's tools
50
50
  load only in a trusted folder. Allow the project MCP servers when asked (`cap`, `ui5`,
51
51
  `fiori`: documentation tools for the role skills).
52
- 2. Follow what `init` printed for branch protection and CODEOWNERS (see
53
- [CI and repository settings](#ci-and-repository-settings)).
52
+ 2. Later, when a team shares the repository on GitHub, consider
53
+ [protecting the main branch](#protecting-the-main-branch-on-github-optional)
54
+ (optional).
54
55
  3. For an existing application, run `/agjan-map` once (see below).
55
56
 
56
57
  ## The workflow
57
58
 
58
- Each feature on a branch of its own.
59
+ Each feature on a branch of its own. When one is needed, the agent asks you: create the
60
+ name it proposes, use a branch that already exists (it lists them), or give another name.
59
61
 
60
62
  **Spec**: in Claude Code or Copilot:
61
63
 
@@ -146,7 +148,7 @@ Run `npx agjan --help` for the full list.
146
148
  | `doctor` | anyone | check Node, git, versions, managed files, hook, CI, the MCP server, guards, trust |
147
149
  | `status [--feature <id> \| --all]` | anyone | state, blockers, tasks, due reviews, next step |
148
150
  | `progress [--open]` | anyone | regenerate the progress pages, print the overview, open the HTML page |
149
- | `branch <name>` | agent, or you with `git.branch.create: confirm` | create the branch of a unit |
151
+ | `branch <name>` · `--list` · `--use <name>` | agent, after asking you | create the branch of a unit, list the existing branches, or switch to one |
150
152
  | `check [--staged \| --ci] [--base <ref>]` | anyone, hook, CI | enforce the rules |
151
153
  | `review show [--step <step>]` | anyone | review records, or the material a reviewer gets |
152
154
  | `pr-summary`, `report` | anyone | PR description; `report.md` with time and tokens |
@@ -187,8 +189,6 @@ lists replace. The schema is `node_modules/agjan/schemas/config.schema.json`.
187
189
  | `domains` | enabled domains; phase 1 has `btp` (areas `cap`, `fiori`, `btp`) |
188
190
  | `hosts` | `claude-code`, `copilot`; decides which files `sync` generates |
189
191
  | `git.base` | the branch features merge into; default: the remote's default branch |
190
- | `git.branch.create` | who creates the branch of a feature, fix or map run: `agent` (default; the agent runs `npx agjan branch <name>`) or `confirm` (the agent proposes a name; a human runs `npx agjan branch <name>` in a terminal, may edit the name, and the guard hook blocks `git switch -c` and similar for agents) |
191
- | `git.branch.pattern` | a regular expression for branch names, for teams with naming rules: `agjan branch` refuses other names, `check` warns about them (an error with `--ci`) |
192
192
  | `verify.<area>` | `build`, `test`, `lint` commands for the skills; `results`: a JUnit XML, Jest or Mocha JSON file that `check` reads to require a passing test per AC |
193
193
  | `tests.<area>`, `scope.implicit.<area>` | test file globs; files every task of the area may change (i18n, lockfiles, fixtures) |
194
194
  | `risk_paths` | paths whose change needs a review per task and are never a fix |
@@ -259,24 +259,63 @@ Set `agent.script_edits` to `"allow"` in `agjan.config.json` to turn this off.
259
259
  Copilot keeps your own "don't ask again" answers per folder in
260
260
  `~/.copilot/permissions-config.json`; that file is personal and not part of the project.
261
261
 
262
- ## CI and repository settings
262
+ ## Protecting the main branch on GitHub (optional)
263
+
264
+ Not needed to work with agjan; recommended once a team shares the repository on GitHub.
265
+
266
+ **Why.** On your machine, agjan's checks (the pre-commit hook, the guard, `agjan check`)
267
+ make it hard for an agent to skip a step, but a model with full shell access could get
268
+ around them in principle. What reaches `main` is decided when a pull request is merged,
269
+ so that is where the last check belongs.
270
+
271
+ **What agjan already adds.** `init` creates `.github/workflows/agjan.yml`, a GitHub
272
+ Actions workflow. On every pull request, GitHub runs `agjan check --ci` and shows the
273
+ result as a check named **agjan-check** on the pull request: green, or red with the
274
+ reason (a document changed after its approval, code outside the approved paths, a stale
275
+ final review). It uses the agjan version pinned on `main`, so a pull request cannot
276
+ bring its own, weaker checker.
277
+
278
+ **What you turn on.** By default, GitHub lets you merge even when a check is red. A
279
+ *branch rule* makes the check, and a review, required:
280
+
281
+ 1. Push the repository to GitHub and open one pull request, so that the check has run
282
+ once and GitHub knows its name.
283
+ 2. In the repository: **Settings → Rules → Rulesets → New ruleset → New branch ruleset**.
284
+ Name it, set **Enforcement status** to *Active*, and under **Target branches** add the
285
+ default branch.
286
+ 3. Turn on **Require a pull request before merging**, with 1 required approval.
287
+ 4. Turn on **Require status checks to pass**, choose **Add checks** and select
288
+ `agjan-check`.
289
+ 5. Save. A pull request with a red `agjan-check`, or one that removes the workflow (the
290
+ check then never reports), can no longer be merged.
291
+
292
+ **Optionally, owners for the rules.** A `CODEOWNERS` file names who must review changes
293
+ to certain files. With **Require review from Code Owners** turned on in the same rule,
294
+ changes to agjan's configuration, approvals, hooks and workflows need your review.
295
+ Create `.github/CODEOWNERS` (replace `@<owner>` with your GitHub user or team):
263
296
 
264
- `init` creates `.github/workflows/agjan.yml`. On every pull request it runs
265
- `agjan check --ci` with the agjan version **pinned on the base branch**, fetched from
266
- the registry, so a pull request cannot change the checker that checks it.
267
-
268
- Recommended settings for the base branch:
297
+ ```text
298
+ # agjan: changes to the rules need an owner's review
299
+ /agjan.config.json @<owner>
300
+ /agjan.lock.json @<owner>
301
+ /docs/agjan/**/approvals.json @<owner>
302
+ /.claude/ @<owner>
303
+ /.github/agents/ @<owner>
304
+ /.github/hooks/ @<owner>
305
+ /.github/workflows/ @<owner>
306
+ /package.json @<owner>
307
+ /package-lock.json @<owner>
308
+ ```
269
309
 
270
- - branch protection with the status check **`agjan-check`** required, and a required
271
- review;
272
- - CODEOWNERS for the files that change the rules (`init` prints a block):
273
- `agjan.config.json`, `agjan.lock.json`, `docs/agjan/**/approvals.json`, `.claude/`,
274
- `.github/agents/`, `.github/hooks/`, `.github/workflows/`, `package.json`,
275
- `package-lock.json`.
310
+ Good to know:
276
311
 
277
- The trust boundary is the reviewed merge. The approval commands are guardrails, not a
278
- proof that a human approved: a model with unrestricted shell access could get around
279
- them in principle.
312
+ - GitHub Actions minutes: private repositories have a monthly quota. When it is used up,
313
+ the check cannot run, and a required check blocks every merge until the quota resets
314
+ (or an admin bypasses the rule). Public repositories are not affected.
315
+ - Working alone: GitHub does not let you approve your own pull request. Leave the
316
+ required review off, or add yourself to the rule's **Bypass list**.
317
+ - The approval commands are guardrails, not proof that a human approved; the reviewed
318
+ merge is the trust boundary.
280
319
 
281
320
  ## Upgrading
282
321
 
@@ -41,12 +41,13 @@ const REASON =
41
41
  const HUMAN_ONLY = /\bagjan(?:\.mjs)?["']?\s+(?:--\s+)?["']?(approve|accept|reject)\b/;
42
42
 
43
43
  const BRANCH_REASON =
44
- 'In this project a human creates branches (git.branch.create: confirm in agjan.config.json). Propose a branch name and ask the user to run in a terminal: npx agjan branch <name>';
44
+ 'Create branches with npx agjan branch, not with git. Ask the user first: create the proposed name, use an existing branch (npx agjan branch --list, then npx agjan branch --use <name>), or another name.';
45
45
 
46
46
  /**
47
47
  * Commands that create or rename a branch: git switch -c/-C, git checkout -b/-B/--orphan,
48
- * git branch <name> (also -m/-c), git worktree add -b. Denied when git.branch.create is
49
- * "confirm" (design decision 62); git options such as `-C <dir>` may come before.
48
+ * git branch <name> (also -m/-c), git worktree add -b. Always denied: agents create branches
49
+ * with npx agjan branch after asking the user (design decision 62); git options such as
50
+ * `-C <dir>` may come before.
50
51
  */
51
52
  const BRANCH_CREATE = new RegExp(
52
53
  String.raw`\bgit(?:\s+-[cC]\s+\S+|\s+--[\w-]+(?:=\S+)?)*\s+` +
@@ -213,7 +214,7 @@ export function decide(payload, config = {}, root = process.env.CLAUDE_PROJECT_D
213
214
  const command = payload?.toolArgs?.command ?? payload?.tool_input?.command;
214
215
  if (typeof command !== 'string') return null;
215
216
  if (HUMAN_ONLY.test(command)) return answer(payload, 'deny', REASON);
216
- if (config?.git?.branch?.create === 'confirm' && BRANCH_CREATE.test(command)) return answer(payload, 'deny', BRANCH_REASON);
217
+ if (BRANCH_CREATE.test(command)) return answer(payload, 'deny', BRANCH_REASON);
217
218
  if (config?.agent?.script_edits !== 'allow' && SCRIPT_EDITS.some((matches) => matches(command))) return answer(payload, 'deny', EDIT_REASON);
218
219
  const allow = config?.agent?.allow ?? [];
219
220
  const shell = /^(bash|powershell|shell)$/i.test(payload.toolName ?? payload.tool_name ?? '');
@@ -20,9 +20,17 @@ change, or a business decision: stop and recommend `/agjan-spec`.
20
20
 
21
21
  ## 2. Start
22
22
 
23
- Work on a branch of its own, without features. If you are on the base branch, create
24
- it with `npx agjan branch <name>`, or, when `npx agjan status` says a human creates
25
- branches, propose the name and ask the user to run that command; never with git directly.
23
+ Work on a branch of its own, without features. If you are on the base branch,
24
+ ask the user one question with these choices (your host's question tool):
25
+ "Work needs its own branch. Create one, or use an existing branch?"
26
+ 1. Create branch "<name>" (your proposal, following the team's naming rule if
27
+ AGENTS.md names one): run `npx agjan branch <name>`.
28
+ 2. Use an existing branch: run `npx agjan branch --list`, let the user pick one
29
+ (offer the names as choices), then run `npx agjan branch --use <picked>`.
30
+ 3. Another name: ask for it, then run `npx agjan branch <their name>`.
31
+ If `agjan branch` refuses a name (invalid, already exists), say why and ask again.
32
+ Never create or switch branches with git directly.
33
+
26
34
  Pick a slug and a key of 2 to 6 capitals:
27
35
 
28
36
  `npx agjan fix start <slug> --key <KEY> --what "<one sentence: what the fix changes>"`
@@ -10,9 +10,18 @@ The merge of this branch is its approval.
10
10
 
11
11
  ## 1. Start
12
12
 
13
- On a branch of its own, without features or fixes (create it with
14
- `npx agjan branch <name>`, or ask the user to when `npx agjan status` says a human
15
- creates branches; never with git directly):
13
+ On a branch of its own, without features or fixes. If you are on the base branch,
14
+ ask the user one question with these choices (your host's question tool):
15
+ "Work needs its own branch. Create one, or use an existing branch?"
16
+ 1. Create branch "<name>" (your proposal, following the team's naming rule if
17
+ AGENTS.md names one): run `npx agjan branch <name>`.
18
+ 2. Use an existing branch: run `npx agjan branch --list`, let the user pick one
19
+ (offer the names as choices), then run `npx agjan branch --use <picked>`.
20
+ 3. Another name: ask for it, then run `npx agjan branch <their name>`.
21
+ If `agjan branch` refuses a name (invalid, already exists), say why and ask again.
22
+ Never create or switch branches with git directly.
23
+
24
+ Then:
16
25
 
17
26
  `npx agjan map start`
18
27
 
@@ -14,11 +14,18 @@ design. You write; the agjan reviewer checks; the human approves.
14
14
  Run `npx agjan status`. If a feature is already in progress on this branch, continue
15
15
  it instead of starting a new one. Otherwise:
16
16
 
17
- - If you are on the base branch, the work needs a branch of its own. The settings line
18
- of `npx agjan status` says who creates it. Propose a name (and follow the branch
19
- pattern if it names one): if the agent creates branches, run `npx agjan branch <name>`;
20
- if a human does, ask the user to run `npx agjan branch <name>` in their terminal (they
21
- may edit the name) and stop until they did. Never create branches with git directly.
17
+ - If you are on the base branch, the work needs a branch of its own. Ask the user one
18
+ question with these choices (your host's question tool):
19
+ "Work needs its own branch. Create one, or use an existing branch?"
20
+ 1. Create branch "<name>" (your proposal, following the team's naming rule if
21
+ AGENTS.md names one): run `npx agjan branch <name>`.
22
+ 2. Use an existing branch: run `npx agjan branch --list`, let the user pick one
23
+ (offer the names as choices), then run `npx agjan branch --use <picked>`.
24
+ 3. Another name: ask for it, then run `npx agjan branch <their name>`.
25
+ If `agjan branch` refuses a name (invalid, already exists), say why and ask again.
26
+ Never create or switch branches with git directly.
27
+ After switching, run `npx agjan status` again: an existing branch may already carry a
28
+ feature to continue.
22
29
  - Pick a slug (lowercase, `-`, short: `order-status-filter`) and a key of 2 to 6
23
30
  capitals (`OSF`).
24
31
  - `npx agjan new <slug> --key <KEY>`
@@ -18,8 +18,9 @@ Rules for agents:
18
18
  results.
19
19
  - During Build, change only files within the approved task paths; otherwise revert, or
20
20
  propose `npx agjan amend`.
21
- - Create branches only with `npx agjan branch <name>`, never with git directly. When
22
- `npx agjan status` says a human creates branches, propose the name and ask the user.
21
+ - Branches: ask the user first (create your proposed name, use an existing branch, or
22
+ another name), then use `npx agjan branch <name>`, `--list` or `--use <name>`; never
23
+ git directly.
23
24
  - Run commands from the project root; do not `cd` into folders. Edit files with your
24
25
  editor tool, not with scripts. Check behavior with the project's tests (add one if
25
26
  needed), not with throwaway scripts.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agjan",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Spec-driven workflow kit for AI coding agents, with human approval gates and a read-only reviewer at every step.",
5
5
  "keywords": [
6
6
  "ai",
@@ -13,21 +13,7 @@
13
13
  "git": {
14
14
  "type": "object",
15
15
  "properties": {
16
- "base": { "type": ["string", "null"] },
17
- "branch": {
18
- "type": "object",
19
- "properties": {
20
- "create": {
21
- "description": "Who creates branches: 'agent' (default; with npx agjan branch) or 'confirm' (the agent proposes a name, a human runs npx agjan branch in a terminal and may edit it).",
22
- "enum": ["agent", "confirm"]
23
- },
24
- "pattern": {
25
- "description": "Regular expression every branch name must match (npx agjan branch refuses others; check reports them).",
26
- "type": ["string", "null"]
27
- }
28
- },
29
- "additionalProperties": false
30
- }
16
+ "base": { "type": ["string", "null"] }
31
17
  },
32
18
  "additionalProperties": false
33
19
  },
package/src/cli.mjs CHANGED
@@ -58,8 +58,9 @@ Setup (human):
58
58
  doctor check the environment and the project setup
59
59
 
60
60
  Agent and human:
61
- branch <name> create the branch for a feature, fix or map run (with
62
- git.branch.create "confirm": a human, who may edit the name)
61
+ branch <name> | --list | --use <name>
62
+ create the branch for a feature, fix or map run, list
63
+ the existing ones, or switch to one (after asking the user)
63
64
  new <slug> --key <KEY> create a feature folder with approvals.json and spec.md
64
65
  scaffold design create design.md and tasks.md from the templates
65
66
  progress [--open] regenerate the progress pages and show the overview
@@ -2,43 +2,53 @@ import { parseArgs } from 'node:util';
2
2
  import { git, currentBranch, resolveBase } from '../git.mjs';
3
3
  import { AgjanError, UsageError } from '../errors.mjs';
4
4
 
5
- /** Problems with a proposed branch name: git's rules, the project's pattern, existence. */
5
+ /** Problems with a proposed branch name: git's rules, existence. */
6
6
  export function branchProblems(root, config, name) {
7
7
  const problems = [];
8
8
  if (git(root, ['check-ref-format', '--branch', name], { allowFail: true }) === null) problems.push(`'${name}' is not a valid branch name`);
9
- const pattern = config.git?.branch?.pattern;
10
- if (pattern && !new RegExp(pattern).test(name)) problems.push(`'${name}' does not match the branch pattern ${pattern} (git.branch.pattern)`);
11
9
  if (git(root, ['rev-parse', '--verify', '--quiet', `refs/heads/${name}`], { allowFail: true }) !== null) problems.push(`branch '${name}' already exists`);
12
10
  return problems;
13
11
  }
14
12
 
13
+ /** Local branches other than the base branch, most recent commit first. */
14
+ export function existingBranches(root, config) {
15
+ const base = (resolveBase(root, config.git?.base) ?? '').replace(/^origin\//, '');
16
+ const out = git(root, ['for-each-ref', '--sort=-committerdate', '--format=%(refname:short)\t%(committerdate:relative)', 'refs/heads'], { allowFail: true }) ?? '';
17
+ return out.split('\n').filter(Boolean).map((line) => {
18
+ const [name, when] = line.split('\t');
19
+ return { name, when };
20
+ }).filter((b) => b.name !== base);
21
+ }
22
+
15
23
  /**
16
- * agjan branch <name>: creates the branch for a feature, fix or map run and switches to it.
17
- * With git.branch.create "confirm" a human runs it in a terminal and may edit the proposed
18
- * name first (design decision 62); with "agent" (the default) the agent runs it.
24
+ * agjan branch <name> | --list | --use <name>: the branch for a feature, fix or map run.
25
+ * The agent asks the user first (create the proposed name, use an existing branch, or
26
+ * another name; design decision 62), then runs this: <name> creates the branch and
27
+ * switches to it, --list shows the existing ones, --use switches to one of them.
19
28
  */
20
29
  export async function run(ctx, argv) {
21
- const { positionals } = parseArgs({ args: argv, allowPositionals: true });
22
- if (positionals.length !== 1) throw new UsageError('usage: agjan branch <name>');
30
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { list: { type: 'boolean' }, use: { type: 'string' } } });
23
31
  const s = ctx.style;
24
- const policy = ctx.config.git?.branch ?? {};
25
- let name = positionals[0];
26
- if (policy.create === 'confirm') {
27
- let edited;
28
- try {
29
- edited = await ctx.edit(`${s.bold('Branch name')} (Enter to create, empty to cancel): `, name);
30
- } catch (error) {
31
- if (!(error instanceof AgjanError)) throw error;
32
- throw new AgjanError(
33
- `in this project a human creates branches (git.branch.create: confirm).\nAsk the user to run in a terminal: npx agjan branch ${name}`,
34
- );
35
- }
36
- name = String(edited ?? '').trim();
37
- if (!name) {
38
- ctx.out(s.yellow('cancelled, no branch created'));
39
- return 1;
32
+ if (values.list) {
33
+ if (positionals.length || values.use) throw new UsageError('usage: agjan branch --list');
34
+ const current = currentBranch(ctx.root);
35
+ const branches = existingBranches(ctx.root, ctx.config);
36
+ if (!branches.length) ctx.out(s.gray('no branches besides the base branch'));
37
+ for (const b of branches) ctx.out(`${b.name === current ? s.green('* ') : ' '}${s.bold(b.name)} ${s.gray(`(${b.when})`)}`);
38
+ return 0;
39
+ }
40
+ if (values.use !== undefined) {
41
+ if (positionals.length) throw new UsageError('usage: agjan branch --use <name>');
42
+ const name = values.use;
43
+ if (!existingBranches(ctx.root, ctx.config).some((b) => b.name === name)) {
44
+ throw new AgjanError(`'${name}' is not an existing branch other than the base branch (npx agjan branch --list)`);
40
45
  }
46
+ if (currentBranch(ctx.root) !== name) git(ctx.root, ['switch', '-q', name]);
47
+ ctx.out(`${s.green('on branch')} ${s.bold(name)}`);
48
+ return 0;
41
49
  }
50
+ if (positionals.length !== 1) throw new UsageError('usage: agjan branch <name> | --list | --use <name>');
51
+ const name = positionals[0];
42
52
  const problems = branchProblems(ctx.root, ctx.config, name);
43
53
  if (problems.length) throw new AgjanError(`cannot create the branch:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
44
54
  const from = currentBranch(ctx.root);
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parseArgs } from 'node:util';
4
- import { git, changedFiles, currentBranch, mergeBase, resolveBase } from '../git.mjs';
4
+ import { git, changedFiles, mergeBase, resolveBase } from '../git.mjs';
5
5
  import { CONFIG_FILE, resolveArea } from '../config.mjs';
6
6
  import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature } from '../feature.mjs';
7
7
  import { documentProblems, designProblems } from '../validate.mjs';
@@ -335,7 +335,6 @@ export function runChecks(ctx, level, explicitFeature) {
335
335
  checkScope(report, features, config, files, level);
336
336
  const policy = level === 'ci' ? checkPolicy(report, root, config, files, base) : [];
337
337
  if (level !== 'staged') {
338
- checkBranchName(report, root, config, base, level);
339
338
  checkManaged(report, ctx);
340
339
  // The baseline describes the application; changes to watched files make it stale.
341
340
  const drift = features.some((f) => f.kind === 'map') ? null : baselineDrift(root, config);
@@ -346,21 +345,6 @@ export function runChecks(ctx, level, explicitFeature) {
346
345
  return { report, slugs, features, files, policy };
347
346
  }
348
347
 
349
- /**
350
- * git.branch.pattern (design decision 62): a branch with work on it must match. A warning
351
- * locally, an error in CI. The base branch itself and a detached HEAD are not judged.
352
- */
353
- function checkBranchName(report, root, config, base, level) {
354
- const pattern = config.git?.branch?.pattern;
355
- if (!pattern) return;
356
- const branch = currentBranch(root);
357
- if (!branch || branch === base?.replace(/^origin\//, '')) return;
358
- if (new RegExp(pattern).test(branch)) return;
359
- const message = `branch '${branch}' does not match the branch pattern ${pattern} (git.branch.pattern)`;
360
- if (level === 'ci') report.error('git', message);
361
- else report.warn('git', message);
362
- }
363
-
364
348
  /** `--base <ref>` overrides git.base for this run, for CI where the base ref is known. */
365
349
  export function overrideBase(ctx, base) {
366
350
  if (base) ctx.config.git = { ...ctx.config.git, base };
@@ -14,23 +14,12 @@ import { hookStatus, installHook } from '../hook.mjs';
14
14
  import { GUARD } from '../adapters/copilot.mjs';
15
15
  import { git, mergeBase, resolveBase } from '../git.mjs';
16
16
  import { AgjanError, UsageError } from '../errors.mjs';
17
- import { mark, pad, tone, verdictColor } from '../ui.mjs';
17
+ import { blink, mark, pad, tone, verdictColor } from '../ui.mjs';
18
18
 
19
19
  const CI_FILE = '.github/workflows/agjan.yml';
20
20
  const CI_TEMPLATE = new URL('../../kit/templates/agjan-ci.yml', import.meta.url);
21
21
  const BIN = fileURLToPath(new URL('../../bin/agjan.mjs', import.meta.url));
22
22
 
23
- const CODEOWNERS = `# agjan: changes to the rules need an owner's review
24
- /agjan.config.json @<owner>
25
- /agjan.lock.json @<owner>
26
- /docs/agjan/**/approvals.json @<owner>
27
- /.claude/ @<owner>
28
- /.github/agents/ @<owner>
29
- /.github/hooks/ @<owner>
30
- /.github/workflows/ @<owner>
31
- /package.json @<owner>
32
- /package-lock.json @<owner>`;
33
-
34
23
  function list(value) {
35
24
  return value ? value.split(',').map((v) => v.trim()).filter(Boolean) : null;
36
25
  }
@@ -69,7 +58,6 @@ function missingModels(raw, hosts, { existing }) {
69
58
  */
70
59
  function missingSettings(raw) {
71
60
  const out = [];
72
- if (raw.git?.branch?.create === undefined) out.push('git.branch.create');
73
61
  if (raw.agent?.allow === undefined || raw.agent?.allow_edits === undefined) out.push('agent');
74
62
  return out;
75
63
  }
@@ -84,7 +72,6 @@ function doSync(ctx, { force }) {
84
72
  const visible = missingSettings(raw);
85
73
  if (Object.keys(added).length || visible.length) {
86
74
  const next = { ...raw, models: { ...(raw.models ?? {}), ...added } };
87
- if (visible.includes('git.branch.create')) next.git = { ...(raw.git ?? {}), branch: { ...(raw.git?.branch ?? {}), create: 'agent' } };
88
75
  if (visible.includes('agent')) next.agent = { allow: raw.agent?.allow ?? [], allow_edits: raw.agent?.allow_edits ?? false, ...(raw.agent ?? {}) };
89
76
  writeJson(file, next);
90
77
  config.models = { ...(config.models ?? {}), ...added };
@@ -93,7 +80,6 @@ function doSync(ctx, { force }) {
93
80
  for (const [host, tiers] of Object.entries(added)) {
94
81
  results.push({ path: CONFIG_FILE, action: `models.${host}: ${MODEL_TIERS.map((t) => `${t}=${tiers[t]}`).join(', ')}` });
95
82
  }
96
- if (visible.includes('git.branch.create')) results.push({ path: CONFIG_FILE, action: 'git.branch.create: agent' });
97
83
  if (visible.includes('agent')) results.push({ path: CONFIG_FILE, action: 'agent: allow, allow_edits' });
98
84
  const current = readJson(file) ?? {};
99
85
  if (current.kit !== ctx.kit) {
@@ -108,30 +94,6 @@ function ask(ctx, question, options) {
108
94
  return ctx.ask(question, options);
109
95
  }
110
96
 
111
- /** Asks for one line with a prefilled answer; '' without a terminal. */
112
- async function askLine(ctx, prompt, initial = '') {
113
- try {
114
- return String((await ctx.edit(prompt, initial)) ?? '').trim();
115
- } catch {
116
- return '';
117
- }
118
- }
119
-
120
- /** The branch pattern: asked until it is a valid regular expression (or left empty). */
121
- async function askPattern(ctx) {
122
- for (let i = 0; i < 3; i++) {
123
- const answer = await askLine(ctx, 'Branch name pattern (regular expression, Enter for none): ');
124
- if (!answer) return null;
125
- try {
126
- new RegExp(answer);
127
- return answer;
128
- } catch (error) {
129
- ctx.out(ctx.style.yellow(`not a valid regular expression: ${error.message}`));
130
- }
131
- }
132
- return null;
133
- }
134
-
135
97
  /** The next steps after init, for the configured hosts (design decision 69). */
136
98
  function nextSteps(ctx, hosts, firstCommit) {
137
99
  const s = ctx.style;
@@ -146,8 +108,6 @@ function nextSteps(ctx, hosts, firstCommit) {
146
108
  if (hosts.includes('copilot')) {
147
109
  steps.push(`Start ${s.cyan('copilot')} in this folder and trust it. Without agent.allow_edits, answer the first file edit prompt with "don't ask again for file operations", or start ${s.cyan('copilot --allow-tool write')}.`);
148
110
  }
149
- steps.push('Protect the base branch: require the "agjan-check" status check and a review.');
150
- steps.push(['Add this to .github/CODEOWNERS (replace @<owner>):', ...CODEOWNERS.split('\n')].join('\n '));
151
111
  steps.push(`Run: ${s.cyan('npx agjan doctor')}`);
152
112
  return ['', s.bold('Next steps:'), ...steps.map((text, i) => ` ${i + 1}. ${text}`)];
153
113
  }
@@ -155,7 +115,6 @@ function nextSteps(ctx, hosts, firstCommit) {
155
115
  /**
156
116
  * agjan init [--domains btp] [--hosts claude-code] [--language en] [--base <ref>] [--no-hook] [--no-ci]
157
117
  * [--prepare] [--agent-allow | --no-agent-allow] [--agent-allow-edits | --no-agent-allow-edits]
158
- * [--branch-create agent|confirm] [--branch-pattern <regex>]
159
118
  */
160
119
  export async function init(ctx, argv) {
161
120
  const { values } = parseArgs({
@@ -172,8 +131,6 @@ export async function init(ctx, argv) {
172
131
  'no-agent-allow': { type: 'boolean' },
173
132
  'agent-allow-edits': { type: 'boolean' },
174
133
  'no-agent-allow-edits': { type: 'boolean' },
175
- 'branch-create': { type: 'string' },
176
- 'branch-pattern': { type: 'string' },
177
134
  },
178
135
  });
179
136
  const root = ctx.root;
@@ -182,32 +139,21 @@ export async function init(ctx, argv) {
182
139
  for (const d of domains) loadDomain(d);
183
140
  const hosts = list(values.hosts) ?? ['claude-code'];
184
141
  for (const h of hosts) if (!ADAPTERS[h]) throw new UsageError(`host '${h}' is not supported in this version (supported: ${Object.keys(ADAPTERS).join(', ')})`);
185
- if (values['branch-create'] && !['agent', 'confirm'].includes(values['branch-create'])) throw new UsageError('--branch-create must be agent or confirm');
186
- if (values['branch-pattern']) {
187
- try {
188
- new RegExp(values['branch-pattern']);
189
- } catch (error) {
190
- throw new UsageError(`--branch-pattern is not a valid regular expression: ${error.message}`);
191
- }
192
- }
193
142
 
194
143
  // The mark first, then the questions (design decision 69).
195
144
  const s = ctx.style;
196
- for (const line of mark(s, ctx.kit, 'setting up this repository')) ctx.out(line);
145
+ const lines = mark(s, ctx.kit, 'setting up this repository');
146
+ for (const line of lines) ctx.out(line);
147
+ await blink(ctx, lines);
197
148
 
198
- // Opt-in decisions, asked once; without a terminal the safe defaults apply. They are
199
- // written visibly, defaults included, so the team sees and can change them.
149
+ // Opt-in decisions, asked once. Enter takes the recommended answer (yes); without a
150
+ // terminal the safe defaults (no) apply. They are written visibly, so the team sees
151
+ // and can change them.
200
152
  const flag = (yes, no) => (values[yes] ? true : values[no] ? false : null);
201
153
  const agentAllow = flag('agent-allow', 'no-agent-allow') ??
202
- ask(ctx, `Let agents run these commands without a prompt: ${RECOMMENDED_ALLOW.join(', ')}?\n(agjan approve, accept and reject stay blocked; change agent.allow in ${CONFIG_FILE} later.)`) ?? false;
154
+ ask(ctx, `Let agents run these commands without a prompt: ${RECOMMENDED_ALLOW.join(', ')}?\n(agjan approve, accept and reject stay blocked; change agent.allow in ${CONFIG_FILE} later.)`, { defaultYes: true }) ?? false;
203
155
  const allowEdits = flag('agent-allow-edits', 'no-agent-allow-edits') ??
204
- ask(ctx, 'Let agents change files in this project without a prompt?\n(agjan records and policy files excluded; agjan checks the scope of every change.)') ?? false;
205
- let branchCreate = values['branch-create'] ?? null;
206
- if (!branchCreate) {
207
- const own = ask(ctx, 'Should agents create branches themselves? (no: they propose a name, you create it with npx agjan branch)', { defaultYes: true });
208
- branchCreate = own === false ? 'confirm' : 'agent';
209
- }
210
- const branchPattern = values['branch-pattern'] ?? (values['branch-create'] ? null : await askPattern(ctx));
156
+ ask(ctx, 'Let agents change files in this project without a prompt?\n(agjan records and policy files excluded; agjan checks the scope of every change.)', { defaultYes: true }) ?? false;
211
157
 
212
158
  const config = {
213
159
  $schema: './node_modules/agjan/schemas/config.schema.json',
@@ -216,7 +162,7 @@ export async function init(ctx, argv) {
216
162
  hosts,
217
163
  language: values.language ?? 'en',
218
164
  models: missingModels({}, hosts, { existing: false }),
219
- git: { ...(values.base ? { base: values.base } : {}), branch: { create: branchCreate, ...(branchPattern ? { pattern: branchPattern } : {}) } },
165
+ git: { ...(values.base ? { base: values.base } : {}) },
220
166
  agent: { allow: agentAllow ? RECOMMENDED_ALLOW : [], allow_edits: allowEdits },
221
167
  };
222
168
  writeJson(join(root, CONFIG_FILE), config);
@@ -226,7 +172,6 @@ export async function init(ctx, argv) {
226
172
  const setting = (on, text) => ` ${pad(on ? tone(s, 'created') : s.gray('none'), on ? 'created' : 'none', 14)} ${text}`;
227
173
  ctx.out(setting(agentAllow, `agent.allow${agentAllow ? ` (${RECOMMENDED_ALLOW.length} commands)` : ''}`));
228
174
  ctx.out(setting(allowEdits, `agent.allow_edits${allowEdits ? ' (file changes without a prompt)' : ''}`));
229
- ctx.out(` ${pad(tone(s, 'created'), 'created', 14)} git.branch: ${branchCreate === 'confirm' ? 'you create branches' : 'agents create branches'}${branchPattern ? `, pattern ${branchPattern}` : ''}`);
230
175
 
231
176
  if (!values['no-hook']) {
232
177
  const hook = installHook(root);
@@ -388,7 +333,7 @@ export function doctor(ctx) {
388
333
  ok('agent allow list', allow.length ? `${allow.length} command(s) without a prompt: ${allow.join(', ')}` : 'none (the hosts ask for every command)');
389
334
  ok('reviewer models', config.hosts.map((h) => `${h}: ${MODEL_TIERS.map((t) => `${t} ${agentModel(config, h, t) ?? 'session model'}`).join(', ')}`).join('; '));
390
335
  ok('file edits', config.agent?.allow_edits === true ? 'without a prompt inside the project (agjan records denied, policy files ask)' : 'the host asks for every file change (agent.allow_edits)');
391
- ok('branches', `${config.git?.branch?.create === 'confirm' ? 'you create them (npx agjan branch)' : 'agents create them (npx agjan branch)'}${config.git?.branch?.pattern ? `, pattern ${config.git.branch.pattern}` : ''}`);
336
+ ok('branches', 'agents ask you, then run npx agjan branch');
392
337
  ok('script edits', config.agent?.script_edits === 'allow' ? 'allowed (agent.script_edits)' : 'denied by the guard: agents edit files with their edit tool');
393
338
  const tracked = (git(root, ['ls-files', '--', 'node_modules'], { allowFail: true }) ?? '').trim();
394
339
  if (tracked) warn('node_modules', 'is committed; remove it: git rm -r -q --cached node_modules && git commit -m "chore: stop tracking node_modules"');
@@ -231,10 +231,9 @@ export function run(ctx, argv) {
231
231
  slugs = values.all ? listFeatures(root) : changedFeatures(root, ctx.config);
232
232
  }
233
233
  const c = ctx.config;
234
- const branches = c.git?.branch?.create === 'confirm' ? 'a human creates branches (npx agjan branch, name proposed by the agent)' : 'the agent creates branches with npx agjan branch';
235
- const pattern = c.git?.branch?.pattern ? `, names matching ${c.git.branch.pattern}` : '';
234
+ const branches = 'branches: ask the user, then npx agjan branch';
236
235
  for (const line of markLine(ctx.style, ctx.kit, 'status')) ctx.out(line);
237
- ctx.out(ctx.style.gray(`settings: documents in '${c.language ?? 'en'}' (headings in English); reviews up to ${roundLimit(c)} rounds; ${fixAttempts(c)} attempts for failing checks; ${branches}${pattern}`));
236
+ ctx.out(ctx.style.gray(`settings: documents in '${c.language ?? 'en'}' (headings in English); reviews up to ${roundLimit(c)} rounds; ${fixAttempts(c)} attempts for failing checks; ${branches}`));
238
237
  if (slugs.length === 0) {
239
238
  ctx.out(values.all ? `no features in ${FEATURES_DIR}` : 'no changed feature on this branch (agjan status --all lists every feature)');
240
239
  return 0;
package/src/context.mjs CHANGED
@@ -50,6 +50,12 @@ export function createContext({
50
50
  email() {
51
51
  return userEmail(this.root);
52
52
  },
53
+ /** Whether stdout is a terminal (for the mark's blink). */
54
+ isTTY: Boolean(stdout?.isTTY),
55
+ /** Writes raw text to stdout, for terminal control sequences. */
56
+ write(text) {
57
+ stdout.write(text);
58
+ },
53
59
  /** Writes each argument as one line; no argument writes an empty line. */
54
60
  out(...lines) {
55
61
  stdout.write(`${(lines.length ? lines : ['']).join('\n')}\n`);
package/src/terminal.mjs CHANGED
@@ -66,7 +66,9 @@ export function askOnTerminal(question, { defaultYes = false } = {}) {
66
66
  const tty = openTerminal();
67
67
  if (!tty) return null;
68
68
  try {
69
- writeSync(tty.output, `${question} ${defaultYes ? '[Y/n]' : '[y/N]'} `);
69
+ // The capital letter is the default (Enter), also in bold.
70
+ const bold = (t) => (process.env.NO_COLOR !== undefined ? t : `\x1b[1m\x1b[36m${t}\x1b[0m`);
71
+ writeSync(tty.output, `${question} ${defaultYes ? `[${bold('Y')}/n]` : `[y/${bold('N')}]`} `);
70
72
  const answer = readLine(tty.input).trim();
71
73
  if (answer === '') return defaultYes;
72
74
  return /^y(es)?$/i.test(answer);
package/src/ui.mjs CHANGED
@@ -107,6 +107,28 @@ export function mark(style, version, line2 = 'spec-driven work with AI agents, g
107
107
  ];
108
108
  }
109
109
 
110
+ /**
111
+ * The mark blinks twice (its two bowls close and open), on a real terminal only: not in
112
+ * CI, not when the brand is off, not for streams that tests pass. `lines` is what
113
+ * mark() returned and was just written.
114
+ */
115
+ export async function blink(ctx, lines) {
116
+ if (!lines.length || !ctx.isTTY || process.env.CI) return;
117
+ const open = [lines[1], lines[2]];
118
+ const closed = [lines[1].replace(/╭─╮/g, ' '), lines[2].replace(/╰─╯/g, '╶─╴')];
119
+ const draw = ([top, bottom]) => ctx.write(`\x1b[${lines.length - 1}A\r\x1b[2K${top}\n\x1b[2K${bottom}\n\x1b[${lines.length - 3}B`);
120
+ const wait = (ms) => new Promise((done) => setTimeout(done, ms));
121
+ ctx.write('\x1b[?25l');
122
+ try {
123
+ for (const [frame, ms] of [[closed, 120], [open, 220], [closed, 120], [open, 0]]) {
124
+ draw(frame);
125
+ await wait(ms);
126
+ }
127
+ } finally {
128
+ ctx.write('\x1b[?25h');
129
+ }
130
+ }
131
+
110
132
  /** The one-line mark for frequent commands: `┃ agjan 0.0.6 · status`. Empty when the brand is off. */
111
133
  export function markLine(style, version, what) {
112
134
  if (!style.brand) return [];