agjan 0.0.1 → 0.0.3
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/docs/guide.md +27 -0
- package/kit/hooks/guard.mjs +67 -7
- package/kit/skills/agjan-build/SKILL.md +1 -1
- package/kit/skills/agjan-design/SKILL.md +1 -1
- package/kit/skills/agjan-fix/SKILL.md +5 -3
- package/kit/skills/agjan-map/SKILL.md +4 -2
- package/kit/skills/agjan-spec/SKILL.md +6 -1
- package/kit/skills/agjan-verify/SKILL.md +1 -1
- package/kit/skills/cap-developer/references/handlers.md +3 -0
- package/kit/skills/cap-developer/references/validation-security.md +5 -0
- package/kit/templates/agents-block.md +7 -0
- package/package.json +1 -1
- package/schemas/config.schema.json +32 -1
- package/src/adapters/claude-code.mjs +29 -9
- package/src/cli.mjs +5 -1
- package/src/commands/branch.mjs +50 -0
- package/src/commands/check.mjs +17 -1
- package/src/commands/setup.mjs +15 -3
- package/src/commands/status.mjs +20 -5
- package/src/config.mjs +7 -1
- package/src/context.mjs +4 -1
- package/src/feature.mjs +12 -1
- package/src/fix.mjs +2 -2
- package/src/git.mjs +9 -0
- package/src/progress.mjs +3 -3
- package/src/review-policy.mjs +3 -1
- package/src/review.mjs +90 -11
- package/src/terminal.mjs +16 -0
package/docs/guide.md
CHANGED
|
@@ -161,6 +161,8 @@ lists replace. The schema is `node_modules/agjan/schemas/config.schema.json`.
|
|
|
161
161
|
| `domains` | enabled domains; phase 1 has `btp` (areas `cap`, `fiori`, `btp`) |
|
|
162
162
|
| `hosts` | `claude-code`, `copilot`; decides which files `sync` generates |
|
|
163
163
|
| `git.base` | the branch features merge into; default: the remote's default branch |
|
|
164
|
+
| `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) |
|
|
165
|
+
| `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`) |
|
|
164
166
|
| `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 |
|
|
165
167
|
| `tests.<area>`, `scope.implicit.<area>` | test file globs; files every task of the area may change (i18n, lockfiles, fixtures) |
|
|
166
168
|
| `risk_paths` | paths whose change needs a review per task and are never a fix |
|
|
@@ -190,6 +192,31 @@ line; the skills take these values, and the reviewer agent per step, from `statu
|
|
|
190
192
|
On every host, `approve` needs a human at a real terminal: the confirmation is read
|
|
191
193
|
from the terminal, not from input an agent can pipe in.
|
|
192
194
|
|
|
195
|
+
### Fewer permission prompts
|
|
196
|
+
|
|
197
|
+
The hosts ask before every shell command and, in Copilot, before every file change. Two
|
|
198
|
+
settings remove the routine prompts without giving up control:
|
|
199
|
+
|
|
200
|
+
- **Commands: `agent.allow`** in `agjan.config.json`. `init` asks once whether to add the
|
|
201
|
+
recommended list (`--agent-allow` / `--no-agent-allow` decide without asking):
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
"agent": { "allow": ["npx agjan", "npm test", "git status", "git diff", "git log", "git add", "git commit"] }
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
agjan's guard hook approves a command without a prompt when it is a **single simple
|
|
208
|
+
command** starting with a listed entry: `npm test` and `git commit -m "…"` run, but
|
|
209
|
+
`npm test && git push`, pipes, redirections and `$(…)` still ask. `agjan approve`,
|
|
210
|
+
`accept` and `reject` are always denied, listed or not. Works in Claude Code and the
|
|
211
|
+
Copilot CLI (both run the hook). Edit the list like any configuration: a change is a
|
|
212
|
+
policy change that `check` reports and the PR shows.
|
|
213
|
+
- **File changes (Copilot):** start with `copilot --allow-tool write`, or answer the first
|
|
214
|
+
edit prompt with "don't ask again for file operations in this repo". agjan's scope
|
|
215
|
+
check, the pre-commit hook and the reviewer cover what the agent changes.
|
|
216
|
+
|
|
217
|
+
Copilot keeps your own "don't ask again" answers per folder in
|
|
218
|
+
`~/.copilot/permissions-config.json`; that file is personal and not part of the project.
|
|
219
|
+
|
|
193
220
|
## CI and repository settings
|
|
194
221
|
|
|
195
222
|
`init` creates `.github/workflows/agjan.yml`. On every pull request it runs
|
package/kit/hooks/guard.mjs
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* `cd … &&`, `node …/agjan.mjs`). It is a guardrail in front of the terminal
|
|
6
6
|
* confirmation, not a proof (design 9.4).
|
|
7
7
|
*
|
|
8
|
+
* It also approves, without a prompt, shell commands the project lists in `agent.allow`
|
|
9
|
+
* of agjan.config.json (opt-in, design decision 61): a single simple command that starts
|
|
10
|
+
* with a listed command. Anything with `;`, `&&`, `|`, `$(…)`, backticks or redirections is
|
|
11
|
+
* left to the host's own prompt. Denying always comes first.
|
|
12
|
+
*
|
|
8
13
|
* Reads the host's payload on stdin and answers in the host's format:
|
|
9
14
|
* - GitHub Copilot: { toolName, toolArgs: { command } } -> { permissionDecision, permissionDecisionReason }
|
|
10
15
|
* - Claude Code: { tool_name, tool_input: { command } } -> { hookSpecificOutput: { … } }
|
|
@@ -13,7 +18,8 @@
|
|
|
13
18
|
* Deliberately self-contained and dependency-free: it runs before every tool call.
|
|
14
19
|
*/
|
|
15
20
|
|
|
16
|
-
import { realpathSync } from 'node:fs';
|
|
21
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
22
|
+
import { join } from 'node:path';
|
|
17
23
|
import { fileURLToPath } from 'node:url';
|
|
18
24
|
|
|
19
25
|
const REASON =
|
|
@@ -22,13 +28,67 @@ const REASON =
|
|
|
22
28
|
/** `agjan` (or `agjan.mjs`) followed directly by a human-only command; an optional `--` (npm exec) between. */
|
|
23
29
|
const HUMAN_ONLY = /\bagjan(?:\.mjs)?["']?\s+(?:--\s+)?["']?(approve|accept|reject)\b/;
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const BRANCH_REASON =
|
|
32
|
+
'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>';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Commands that create or rename a branch: git switch -c/-C, git checkout -b/-B/--orphan,
|
|
36
|
+
* git branch <name> (also -m/-c), git worktree add -b. Denied when git.branch.create is
|
|
37
|
+
* "confirm" (design decision 62); git options such as `-C <dir>` may come before.
|
|
38
|
+
*/
|
|
39
|
+
const BRANCH_CREATE = new RegExp(
|
|
40
|
+
String.raw`\bgit(?:\s+-[cC]\s+\S+|\s+--[\w-]+(?:=\S+)?)*\s+` +
|
|
41
|
+
String.raw`(?:switch\s+(?:\S+\s+)*?(?:-c|-C|--create|--force-create)\b` +
|
|
42
|
+
String.raw`|checkout\s+(?:\S+\s+)*?(?:-b|-B|--orphan)\b` +
|
|
43
|
+
String.raw`|branch\s+(?:(?:-[mMcCf]|--move|--copy|--force)\s+)*[^-\s]` +
|
|
44
|
+
String.raw`|worktree\s+add\s+(?:\S+\s+)*?-[bB]\b)`,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/** Characters that chain, substitute or redirect: such commands are never auto-approved. */
|
|
48
|
+
const COMPOUND = /[;&|`$<>(){}\n\r]/;
|
|
49
|
+
|
|
50
|
+
/** Whether `command` is one simple command starting with an entry of the allow list. */
|
|
51
|
+
export function allowed(command, allow) {
|
|
52
|
+
if (!Array.isArray(allow) || COMPOUND.test(command)) return false;
|
|
53
|
+
const normalized = command.trim().replace(/\s+/g, ' ');
|
|
54
|
+
return allow.some((entry) => {
|
|
55
|
+
if (typeof entry !== 'string' || entry.trim() === '') return false;
|
|
56
|
+
const prefix = entry.trim().replace(/\s+/g, ' ');
|
|
57
|
+
return normalized === prefix || normalized.startsWith(`${prefix} `);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function answer(payload, decision, reason) {
|
|
28
62
|
if (payload.tool_input !== undefined) {
|
|
29
|
-
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision:
|
|
63
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: decision, permissionDecisionReason: reason } };
|
|
64
|
+
}
|
|
65
|
+
return { permissionDecision: decision, permissionDecisionReason: reason };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The guard's answer for a payload: deny, allow (listed in `config.agent.allow`), or null
|
|
70
|
+
* (the host decides). `config` is the project's agjan.config.json.
|
|
71
|
+
*/
|
|
72
|
+
export function decide(payload, config = {}) {
|
|
73
|
+
const command = payload?.toolArgs?.command ?? payload?.tool_input?.command;
|
|
74
|
+
if (typeof command !== 'string') return null;
|
|
75
|
+
if (HUMAN_ONLY.test(command)) return answer(payload, 'deny', REASON);
|
|
76
|
+
if (config?.git?.branch?.create === 'confirm' && BRANCH_CREATE.test(command)) return answer(payload, 'deny', BRANCH_REASON);
|
|
77
|
+
const allow = config?.agent?.allow ?? [];
|
|
78
|
+
const shell = /^(bash|powershell|shell)$/i.test(payload.toolName ?? payload.tool_name ?? '');
|
|
79
|
+
if (shell && allowed(command, allow)) return answer(payload, 'allow', 'listed in agent.allow of agjan.config.json');
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The project's agjan.config.json; empty when it cannot be read. */
|
|
84
|
+
function projectConfig() {
|
|
85
|
+
try {
|
|
86
|
+
const root = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
87
|
+
const config = JSON.parse(readFileSync(join(root, 'agjan.config.json'), 'utf8'));
|
|
88
|
+
return config !== null && typeof config === 'object' ? config : {};
|
|
89
|
+
} catch {
|
|
90
|
+
return {};
|
|
30
91
|
}
|
|
31
|
-
return { permissionDecision: 'deny', permissionDecisionReason: REASON };
|
|
32
92
|
}
|
|
33
93
|
|
|
34
94
|
function main() {
|
|
@@ -44,7 +104,7 @@ function main() {
|
|
|
44
104
|
} catch {
|
|
45
105
|
return; // not a payload we understand: default behavior
|
|
46
106
|
}
|
|
47
|
-
const decision = decide(payload);
|
|
107
|
+
const decision = decide(payload, projectConfig());
|
|
48
108
|
if (decision) process.stdout.write(JSON.stringify(decision));
|
|
49
109
|
});
|
|
50
110
|
}
|
|
@@ -32,7 +32,7 @@ Repeat until `npx agjan status` says `next: all tasks done and reviewed`:
|
|
|
32
32
|
- Commit the task with the subject `<KEY>-<id>: <title>`, for example
|
|
33
33
|
`ORDF-T1: Add the status filter`. Include the feature's `docs/agjan/` files if they
|
|
34
34
|
changed.
|
|
35
|
-
3. **A due review** (`due review build:<area>` or `build:<task>`): delegate to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
35
|
+
3. **A due review** (`due review build:<area>` or `build:<task>`): when all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
36
36
|
`Review step build:<area or task> of feature <slug>.` The work must be committed
|
|
37
37
|
first. Read the result with `npx agjan review show`; fix
|
|
38
38
|
blockers in a new commit with the same task subject prefix, then ask for the review
|
|
@@ -68,7 +68,7 @@ Run `npx agjan check` and fix every error.
|
|
|
68
68
|
|
|
69
69
|
## 5. Review (step `design`, deep)
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
When all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer-deep`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
72
72
|
`Review step design of feature <slug>.`
|
|
73
73
|
|
|
74
74
|
Read the result with `npx agjan review show`. Fix blockers and re-review, up to the round limit that `npx agjan status` shows (default 3); if blockers remain, stop and tell the user. Never edit review files or review
|
|
@@ -20,8 +20,10 @@ 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.
|
|
24
|
-
|
|
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.
|
|
26
|
+
Pick a slug and a key of 2 to 6 capitals:
|
|
25
27
|
|
|
26
28
|
`npx agjan fix start <slug> --key <KEY> --what "<one sentence: what the fix changes>"`
|
|
27
29
|
|
|
@@ -35,7 +37,7 @@ capitals:
|
|
|
35
37
|
|
|
36
38
|
## 4. Review (step `fix`)
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
When all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
39
41
|
`Review step fix of feature fixes/<id>.` (the id is the folder name under
|
|
40
42
|
`docs/agjan/fixes/`). Read the result with `npx agjan review show`. Fix blockers in a
|
|
41
43
|
new commit and review again, up to the round limit that `npx agjan status` shows (default 3); then stop and tell the user. Make no
|
|
@@ -10,7 +10,9 @@ 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
|
|
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):
|
|
14
16
|
|
|
15
17
|
`npx agjan map start`
|
|
16
18
|
|
|
@@ -39,7 +41,7 @@ user if unsure. These paths are protected for `/agjan-fix`.
|
|
|
39
41
|
## 4. Baseline and review (step `map`)
|
|
40
42
|
|
|
41
43
|
1. `npx agjan baseline refresh`
|
|
42
|
-
2.
|
|
44
|
+
2. When all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
43
45
|
`Review step map of feature maps/<id>.` Read the result with `npx agjan review show`;
|
|
44
46
|
fix blockers and review again, up to the round limit that `npx agjan status` shows (default 3).
|
|
45
47
|
3. Commit `docs/agjan/`. `npx agjan check --ci` must pass.
|
|
@@ -14,6 +14,11 @@ 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
22
|
- Pick a slug (lowercase, `-`, short: `order-status-filter`) and a key of 2 to 6
|
|
18
23
|
capitals (`OSF`).
|
|
19
24
|
- `npx agjan new <slug> --key <KEY>`
|
|
@@ -49,7 +54,7 @@ Run `npx agjan check` and fix every error in `spec.md`.
|
|
|
49
54
|
|
|
50
55
|
## 4. Review (step `spec`)
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
When all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
53
58
|
`Review step spec of feature <slug>.` Do not add your reasoning, summaries or opinions
|
|
54
59
|
to the prompt. If no such agent is available, stop and tell the user: the review
|
|
55
60
|
cannot be skipped (`npx agjan doctor` shows why).
|
|
@@ -31,7 +31,7 @@ since the baseline, and commit both.
|
|
|
31
31
|
|
|
32
32
|
## 4. Final review (step `verify`, deep)
|
|
33
33
|
|
|
34
|
-
Everything must be committed.
|
|
34
|
+
Everything must be committed. When all your edits are saved, delegate, on its own (not in parallel with other tool calls), to the reviewer agent that `npx agjan status` names for the step (default `agjan-reviewer-deep`), with exactly this prompt (Claude Code: the Agent tool with that subagent type; GitHub Copilot: the task tool with that custom agent):
|
|
35
35
|
`Review step verify of feature <slug>.`
|
|
36
36
|
|
|
37
37
|
Read the result with `npx agjan review show`. If it is blocked, fix the blockers in new
|
|
@@ -45,3 +45,6 @@ MCP server on 2026-10-17. Rules restated; check details with `search_docs`.
|
|
|
45
45
|
you, and nested calls to other services do not join it.
|
|
46
46
|
- Lock what you read before changing it in the same transaction:
|
|
47
47
|
`SELECT(1).from(Orders, id).forUpdate()`.
|
|
48
|
+
- For a status transition, make the update itself conditional on the expected state:
|
|
49
|
+
`UPDATE(Orders).set({ status: 'Shipped' }).where({ ID: id, status: 'Approved' })`
|
|
50
|
+
returns the number of changed rows; 0 means the state changed in between.
|
|
@@ -44,6 +44,11 @@ Default messages use the codes `ASSERT_MANDATORY`, `ASSERT_RANGE`, `ASSERT_ENUM`
|
|
|
44
44
|
collections, only simple comparisons of user attributes with literals
|
|
45
45
|
(`$user.level >= 2`) can be checked.
|
|
46
46
|
- `$metadata` does not apply `@restrict`; do not rely on hiding entities there.
|
|
47
|
+
- Users for tests and local runs (`auth` of kind `mocked` with `users`) belong in a
|
|
48
|
+
profile: `cds.requires["[development]"].auth` in `package.json` (`cds.test` runs in it
|
|
49
|
+
too). Without the profile they also apply in production, where anyone could log in
|
|
50
|
+
with those passwords. Check: `NODE_ENV=production npx cds env get requires.auth.kind`
|
|
51
|
+
must not print `mocked` or `dummy`.
|
|
47
52
|
- Name roles after the spec's business roles; the same roles go into
|
|
48
53
|
`xs-security.json` (btp area). Every authorization change is a risk in the design and
|
|
49
54
|
gets its own review.
|
|
@@ -17,4 +17,11 @@ Rules for agents:
|
|
|
17
17
|
results.
|
|
18
18
|
- During Build, change only files within the approved task paths; otherwise revert, or
|
|
19
19
|
propose `npx agjan amend`.
|
|
20
|
+
- Create branches only with `npx agjan branch <name>`, never with git directly. When
|
|
21
|
+
`npx agjan status` says a human creates branches, propose the name and ask the user.
|
|
22
|
+
- Run commands from the project root; do not `cd` into folders. Edit files with your
|
|
23
|
+
editor tool, not with scripts. Check behavior with the project's tests (add one if
|
|
24
|
+
needed), not with throwaway scripts.
|
|
25
|
+
- Start a review only when all your edits are saved, and on its own: never in parallel
|
|
26
|
+
with other tool calls. The reviewer must see the finished change.
|
|
20
27
|
- Run `npx agjan check` before you report a step as done.
|
package/package.json
CHANGED
|
@@ -10,7 +10,27 @@
|
|
|
10
10
|
"domains": { "type": "array", "items": { "type": "string" } },
|
|
11
11
|
"language": { "type": "string" },
|
|
12
12
|
"hosts": { "type": "array", "items": { "enum": ["claude-code", "copilot"] } },
|
|
13
|
-
"git": {
|
|
13
|
+
"git": {
|
|
14
|
+
"type": "object",
|
|
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
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"additionalProperties": false
|
|
33
|
+
},
|
|
14
34
|
"scope": {
|
|
15
35
|
"type": "object",
|
|
16
36
|
"properties": { "implicit": { "type": "object", "additionalProperties": { "type": "array", "items": { "type": "string" } } } },
|
|
@@ -69,6 +89,17 @@
|
|
|
69
89
|
"additionalProperties": false
|
|
70
90
|
},
|
|
71
91
|
"limits": { "type": "object", "additionalProperties": { "type": "number" } },
|
|
92
|
+
"agent": {
|
|
93
|
+
"type": "object",
|
|
94
|
+
"properties": {
|
|
95
|
+
"allow": {
|
|
96
|
+
"description": "Shell commands agents may run without a prompt (the agjan guard hook approves a single simple command starting with an entry). agjan approve, accept and reject are always denied.",
|
|
97
|
+
"type": "array",
|
|
98
|
+
"items": { "type": "string", "minLength": 1 }
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"additionalProperties": false
|
|
102
|
+
},
|
|
72
103
|
"ci": {
|
|
73
104
|
"type": "object",
|
|
74
105
|
"properties": { "policy_changes": { "enum": ["warn", "fail"] }, "untracked_changes": { "enum": ["warn", "fail"] } },
|
|
@@ -23,21 +23,39 @@ const LAUNCHERS = ['agjan', 'npx agjan', 'npx --no-install agjan', 'npx -y agjan
|
|
|
23
23
|
export const DENY_RULES = HUMAN_ONLY.flatMap((cmd) => LAUNCHERS.map((l) => `Bash(${l} ${cmd}:*)`));
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* The guard as a PreToolUse hook
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* The guard as a PreToolUse hook. It also catches wrapped forms the prefix deny rules miss
|
|
27
|
+
* (`sh -c "agjan approve …"`). If it cannot start (agjan not installed), Claude Code
|
|
28
|
+
* treats the error as non-blocking.
|
|
29
|
+
*
|
|
30
|
+
* Shell form, as in Claude Code's documentation (it runs hooks with bash, on Windows
|
|
31
|
+
* through Git Bash). Not the exec form (`command` + `args`): the GitHub Copilot CLI also
|
|
32
|
+
* runs the hooks of `.claude/settings.json`, ignores `args`, and denies every tool call
|
|
33
|
+
* when a hook fails (host experiments, GitHub Copilot CLI, 5b).
|
|
29
34
|
*/
|
|
30
35
|
export const GUARD_HOOK = {
|
|
31
36
|
type: 'command',
|
|
32
|
-
command: 'node',
|
|
33
|
-
args: ['${CLAUDE_PROJECT_DIR}/node_modules/agjan/kit/hooks/guard.mjs'],
|
|
37
|
+
command: 'node "$CLAUDE_PROJECT_DIR/node_modules/agjan/kit/hooks/guard.mjs"',
|
|
34
38
|
timeout: 10,
|
|
35
39
|
};
|
|
36
40
|
|
|
41
|
+
const GUARD_PATH = 'node_modules/agjan/kit/hooks/guard.mjs';
|
|
42
|
+
|
|
43
|
+
/** A guard entry written by an earlier agjan version (for example the exec form). */
|
|
44
|
+
function isOutdatedGuard(hook) {
|
|
45
|
+
const text = JSON.stringify(hook);
|
|
46
|
+
return text.includes(GUARD_PATH) && text !== JSON.stringify(GUARD_HOOK);
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
function hasGuard(data) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
const hooks = (data.hooks?.PreToolUse ?? []).flatMap((group) => group.hooks ?? []);
|
|
51
|
+
return hooks.some((h) => JSON.stringify(h) === JSON.stringify(GUARD_HOOK)) && !hooks.some(isOutdatedGuard);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** PreToolUse without outdated guard entries; a group left empty is dropped. */
|
|
55
|
+
function withoutOutdatedGuards(groups) {
|
|
56
|
+
return groups
|
|
57
|
+
.map((group) => (group.hooks?.some(isOutdatedGuard) ? { ...group, hooks: group.hooks.filter((h) => !isOutdatedGuard(h)) } : group))
|
|
58
|
+
.filter((group) => !Array.isArray(group.hooks) || group.hooks.length > 0);
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
function reviewerAgent(name, tier, model, skill) {
|
|
@@ -86,7 +104,9 @@ export function plan(config, skills) {
|
|
|
86
104
|
const deny = [...new Set([...(data.permissions?.deny ?? []), ...DENY_RULES])];
|
|
87
105
|
let hooks = data.hooks ?? {};
|
|
88
106
|
if (!hasGuard(data)) {
|
|
89
|
-
|
|
107
|
+
const groups = withoutOutdatedGuards(hooks.PreToolUse ?? []);
|
|
108
|
+
const current = groups.some((g) => (g.hooks ?? []).some((h) => JSON.stringify(h) === JSON.stringify(GUARD_HOOK)));
|
|
109
|
+
hooks = { ...hooks, PreToolUse: current ? groups : [...groups, { matcher: 'Bash', hooks: [GUARD_HOOK] }] };
|
|
90
110
|
}
|
|
91
111
|
return { ...data, permissions: { ...(data.permissions ?? {}), deny }, hooks };
|
|
92
112
|
},
|
package/src/cli.mjs
CHANGED
|
@@ -12,12 +12,14 @@ import * as setup from './commands/setup.mjs';
|
|
|
12
12
|
import * as report from './commands/report.mjs';
|
|
13
13
|
import * as fix from './commands/fix.mjs';
|
|
14
14
|
import * as mapCommand from './commands/map.mjs';
|
|
15
|
+
import * as branch from './commands/branch.mjs';
|
|
15
16
|
|
|
16
17
|
const COMMANDS = {
|
|
17
18
|
init: setup.init,
|
|
18
19
|
sync: setup.sync,
|
|
19
20
|
doctor: setup.doctor,
|
|
20
21
|
hook: setup.hook,
|
|
22
|
+
branch: branch.run,
|
|
21
23
|
new: newCommand.run,
|
|
22
24
|
scaffold: newCommand.scaffold,
|
|
23
25
|
status: status.run,
|
|
@@ -45,13 +47,15 @@ Usage: agjan <command> [options]
|
|
|
45
47
|
|
|
46
48
|
Setup (human):
|
|
47
49
|
init [--domains btp] [--hosts claude-code,copilot] [--base <ref>]
|
|
48
|
-
[--no-hook] [--no-ci] [--prepare]
|
|
50
|
+
[--no-hook] [--no-ci] [--prepare] [--agent-allow | --no-agent-allow]
|
|
49
51
|
set up agjan in this repository
|
|
50
52
|
sync [--force] regenerate managed files (skills, agents, blocks, settings)
|
|
51
53
|
hook install install the pre-commit hook
|
|
52
54
|
doctor check the environment and the project setup
|
|
53
55
|
|
|
54
56
|
Agent and human:
|
|
57
|
+
branch <name> create the branch for a feature, fix or map run (with
|
|
58
|
+
git.branch.create "confirm": a human, who may edit the name)
|
|
55
59
|
new <slug> --key <KEY> create a feature folder with approvals.json and spec.md
|
|
56
60
|
scaffold design create design.md and tasks.md from the templates
|
|
57
61
|
status [--feature <s> | --all]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { git, currentBranch, resolveBase } from '../git.mjs';
|
|
3
|
+
import { AgjanError, UsageError } from '../errors.mjs';
|
|
4
|
+
|
|
5
|
+
/** Problems with a proposed branch name: git's rules, the project's pattern, existence. */
|
|
6
|
+
export function branchProblems(root, config, name) {
|
|
7
|
+
const problems = [];
|
|
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
|
+
if (git(root, ['rev-parse', '--verify', '--quiet', `refs/heads/${name}`], { allowFail: true }) !== null) problems.push(`branch '${name}' already exists`);
|
|
12
|
+
return problems;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
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.
|
|
19
|
+
*/
|
|
20
|
+
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>');
|
|
23
|
+
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;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const problems = branchProblems(ctx.root, ctx.config, name);
|
|
43
|
+
if (problems.length) throw new AgjanError(`cannot create the branch:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
|
|
44
|
+
const from = currentBranch(ctx.root);
|
|
45
|
+
git(ctx.root, ['switch', '-q', '-c', name]);
|
|
46
|
+
ctx.out(`${s.green('created branch')} ${s.bold(name)}${from ? s.gray(` (from ${from})`) : ''}`);
|
|
47
|
+
const base = resolveBase(ctx.root, ctx.config.git?.base);
|
|
48
|
+
if (from && base && from !== base.replace(/^origin\//, '')) ctx.out(s.yellow(`note: created from ${from}, not from the base branch ${base}`));
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
package/src/commands/check.mjs
CHANGED
|
@@ -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, mergeBase, resolveBase } from '../git.mjs';
|
|
4
|
+
import { git, changedFiles, currentBranch, 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';
|
|
@@ -333,6 +333,7 @@ export function runChecks(ctx, level, explicitFeature) {
|
|
|
333
333
|
checkScope(report, features, config, files, level);
|
|
334
334
|
const policy = level === 'ci' ? checkPolicy(report, root, config, files, base) : [];
|
|
335
335
|
if (level !== 'staged') {
|
|
336
|
+
checkBranchName(report, root, config, base, level);
|
|
336
337
|
checkManaged(report, ctx);
|
|
337
338
|
// The baseline describes the application; changes to watched files make it stale.
|
|
338
339
|
const drift = features.some((f) => f.kind === 'map') ? null : baselineDrift(root, config);
|
|
@@ -343,6 +344,21 @@ export function runChecks(ctx, level, explicitFeature) {
|
|
|
343
344
|
return { report, slugs, features, files, policy };
|
|
344
345
|
}
|
|
345
346
|
|
|
347
|
+
/**
|
|
348
|
+
* git.branch.pattern (design decision 62): a branch with work on it must match. A warning
|
|
349
|
+
* locally, an error in CI. The base branch itself and a detached HEAD are not judged.
|
|
350
|
+
*/
|
|
351
|
+
function checkBranchName(report, root, config, base, level) {
|
|
352
|
+
const pattern = config.git?.branch?.pattern;
|
|
353
|
+
if (!pattern) return;
|
|
354
|
+
const branch = currentBranch(root);
|
|
355
|
+
if (!branch || branch === base?.replace(/^origin\//, '')) return;
|
|
356
|
+
if (new RegExp(pattern).test(branch)) return;
|
|
357
|
+
const message = `branch '${branch}' does not match the branch pattern ${pattern} (git.branch.pattern)`;
|
|
358
|
+
if (level === 'ci') report.error('git', message);
|
|
359
|
+
else report.warn('git', message);
|
|
360
|
+
}
|
|
361
|
+
|
|
346
362
|
/** `--base <ref>` overrides git.base for this run, for CI where the base ref is known. */
|
|
347
363
|
export function overrideBase(ctx, base) {
|
|
348
364
|
if (base) ctx.config.git = { ...ctx.config.git, base };
|
package/src/commands/setup.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { homedir } from 'node:os';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { parseArgs } from 'node:util';
|
|
7
|
-
import { CONFIG_FILE, loadConfig, loadDomain } from '../config.mjs';
|
|
7
|
+
import { CONFIG_FILE, RECOMMENDED_ALLOW, loadConfig, loadDomain } from '../config.mjs';
|
|
8
8
|
import { readJson, writeJson } from '../json-file.mjs';
|
|
9
9
|
import { applyPlan, planStatus } from '../managed.mjs';
|
|
10
10
|
import { ADAPTERS, buildPlan, unsupportedHosts } from '../plan.mjs';
|
|
@@ -58,8 +58,11 @@ function doSync(ctx, { force }) {
|
|
|
58
58
|
return results;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
|
|
61
|
+
/**
|
|
62
|
+
* agjan init [--domains btp] [--hosts claude-code] [--language en] [--base <ref>] [--no-hook] [--no-ci]
|
|
63
|
+
* [--prepare] [--agent-allow | --no-agent-allow]
|
|
64
|
+
*/
|
|
65
|
+
export async function init(ctx, argv) {
|
|
63
66
|
const { values } = parseArgs({
|
|
64
67
|
args: argv,
|
|
65
68
|
options: {
|
|
@@ -70,6 +73,8 @@ export function init(ctx, argv) {
|
|
|
70
73
|
'no-hook': { type: 'boolean' },
|
|
71
74
|
'no-ci': { type: 'boolean' },
|
|
72
75
|
prepare: { type: 'boolean' },
|
|
76
|
+
'agent-allow': { type: 'boolean' },
|
|
77
|
+
'no-agent-allow': { type: 'boolean' },
|
|
73
78
|
},
|
|
74
79
|
});
|
|
75
80
|
const root = ctx.root;
|
|
@@ -87,12 +92,17 @@ export function init(ctx, argv) {
|
|
|
87
92
|
language: values.language ?? 'en',
|
|
88
93
|
};
|
|
89
94
|
if (values.base) config.git = { base: values.base };
|
|
95
|
+
// Opt-in (design decision 61): asked once; without a terminal, nothing is allowed.
|
|
96
|
+
let agentAllow = values['agent-allow'] ? true : values['no-agent-allow'] ? false : null;
|
|
97
|
+
agentAllow ??= ctx.ask(`Let agents run these commands without a prompt: ${RECOMMENDED_ALLOW.join(', ')}?\n(agjan approve, accept and reject stay blocked; edit agent.allow in ${CONFIG_FILE} later.)`) ?? false;
|
|
98
|
+
if (agentAllow) config.agent = { allow: RECOMMENDED_ALLOW };
|
|
90
99
|
writeJson(join(root, CONFIG_FILE), config);
|
|
91
100
|
const s = ctx.style;
|
|
92
101
|
for (const line of banner(s, ctx.kit)) ctx.out(line);
|
|
93
102
|
ctx.out(`${s.bold('agjan init')}: ${CONFIG_FILE} (domains ${domains.join(', ')}; hosts ${hosts.join(', ')})`);
|
|
94
103
|
|
|
95
104
|
printResults(ctx, doSync(ctx, { force: false }));
|
|
105
|
+
ctx.out(` ${pad(agentAllow ? tone(s, 'created') : s.gray('none'), agentAllow ? 'created' : 'none', 14)} agent.allow${agentAllow ? ` (${RECOMMENDED_ALLOW.length} commands)` : ''}`);
|
|
96
106
|
|
|
97
107
|
if (!values['no-hook']) {
|
|
98
108
|
const hook = installHook(root);
|
|
@@ -255,6 +265,8 @@ export function doctor(ctx) {
|
|
|
255
265
|
if (trust === 'trusted') ok('claude code trust', 'project folder trusted');
|
|
256
266
|
else warn('claude code trust', `${trust}; open the folder in Claude Code once and trust it, or the reviewer has no agjan tools`);
|
|
257
267
|
}
|
|
268
|
+
const allow = config.agent?.allow ?? [];
|
|
269
|
+
ok('agent allow list', allow.length ? `${allow.length} command(s) without a prompt: ${allow.join(', ')}` : 'none (the hosts ask for every command)');
|
|
258
270
|
const ignored = git(root, ['check-ignore', '-q', '.agjan/x'], { allowFail: true }) !== null;
|
|
259
271
|
if (!ignored) warn('.gitignore', '.agjan/ is not ignored; run: npx agjan sync');
|
|
260
272
|
}
|
package/src/commands/status.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
-
import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature } from '../feature.mjs';
|
|
2
|
+
import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature, stillBlocked } from '../feature.mjs';
|
|
3
3
|
import { UsageError } from '../errors.mjs';
|
|
4
4
|
import { buildProgress, verifyState } from '../progress.mjs';
|
|
5
5
|
import { gateReadiness, pendingGate } from './gates.mjs';
|
|
@@ -57,7 +57,8 @@ function findingCount(ctx, open) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** A fix or a map run: its checks, its review, and the next step. */
|
|
60
|
-
function describeRecord(ctx, unit) {
|
|
60
|
+
function describeRecord(ctx, unit, onBase = false) {
|
|
61
|
+
if (onBase) return describeRecordOnBase(ctx, unit);
|
|
61
62
|
heading(ctx, unit, ctx.style.magenta(unit.kind));
|
|
62
63
|
const problems = unit.kind === 'fix' ? fixRules(ctx.root, ctx.config).problems : projectProblems(ctx.root, ctx.config);
|
|
63
64
|
for (const p of problems) row(ctx, 'blocks', p);
|
|
@@ -82,7 +83,7 @@ function describeOnBase(ctx, feature) {
|
|
|
82
83
|
const s = ctx.style;
|
|
83
84
|
const progress = buildProgress(ctx.root, ctx.config, feature, { history: true });
|
|
84
85
|
const verify = feature.reviews.records.filter((r) => r.step === 'verify').at(-1);
|
|
85
|
-
const merged = progress.complete && verify && verify
|
|
86
|
+
const merged = progress.complete && verify && !stillBlocked(feature, verify);
|
|
86
87
|
heading(ctx, feature, merged ? `stage: ${s.green('merged')}` : `stage: ${s.magenta(feature.stage)} (on the base branch)`);
|
|
87
88
|
row(ctx, 'spec', tone(s, feature.state.spec));
|
|
88
89
|
row(ctx, 'design', `${tone(s, feature.state.design)}${feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : ''}`);
|
|
@@ -94,8 +95,20 @@ function describeOnBase(ctx, feature) {
|
|
|
94
95
|
if (!merged) row(ctx, 'next', 'continue on a feature branch, or start follow-up work as a new feature');
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
/** A fix or a map run already on the base branch: merged once its last review passed. */
|
|
99
|
+
function describeRecordOnBase(ctx, unit) {
|
|
100
|
+
const s = ctx.style;
|
|
101
|
+
const last = unit.reviews.records.at(-1);
|
|
102
|
+
const merged = last && !stillBlocked(unit, last);
|
|
103
|
+
heading(ctx, unit, `${s.magenta(unit.kind)} ${merged ? `stage: ${s.green('merged')}` : '(on the base branch)'}`);
|
|
104
|
+
row(ctx, 'review', last ? `${last.id} ${tone(s, last.verdict)}` : 'none');
|
|
105
|
+
const open = unit.findings.filter((f) => f.status === 'open');
|
|
106
|
+
if (open.length) row(ctx, 'findings', findingCount(ctx, open));
|
|
107
|
+
if (!merged) row(ctx, 'next', `start follow-up work on a branch (/agjan-${unit.kind === 'fix' ? 'fix' : 'map'})`);
|
|
108
|
+
}
|
|
109
|
+
|
|
97
110
|
function describe(ctx, feature, onBase = false) {
|
|
98
|
-
if (feature.kind !== 'feature') return describeRecord(ctx, feature);
|
|
111
|
+
if (feature.kind !== 'feature') return describeRecord(ctx, feature, onBase);
|
|
99
112
|
if (onBase) return describeOnBase(ctx, feature);
|
|
100
113
|
heading(ctx, feature, `stage: ${ctx.style.magenta(feature.stage)}`);
|
|
101
114
|
row(ctx, 'spec', tone(ctx.style, feature.state.spec));
|
|
@@ -149,7 +162,9 @@ export function run(ctx, argv) {
|
|
|
149
162
|
slugs = values.all ? listFeatures(root) : changedFeatures(root, ctx.config);
|
|
150
163
|
}
|
|
151
164
|
const c = ctx.config;
|
|
152
|
-
|
|
165
|
+
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';
|
|
166
|
+
const pattern = c.git?.branch?.pattern ? `, names matching ${c.git.branch.pattern}` : '';
|
|
167
|
+
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}`));
|
|
153
168
|
if (slugs.length === 0) {
|
|
154
169
|
ctx.out(values.all ? `no features in ${FEATURES_DIR}` : 'no changed feature on this branch (agjan status --all lists every feature)');
|
|
155
170
|
return 0;
|
package/src/config.mjs
CHANGED
|
@@ -6,12 +6,18 @@ export const CONFIG_FILE = 'agjan.config.json';
|
|
|
6
6
|
|
|
7
7
|
const KIT_DIR = new URL('../kit/', import.meta.url);
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The commands `agjan init` offers for `agent.allow`: agjan itself (approve, accept and
|
|
11
|
+
* reject stay denied by the guard), the tests, and the git commands of the workflow.
|
|
12
|
+
*/
|
|
13
|
+
export const RECOMMENDED_ALLOW = ['npx agjan', 'npm test', 'git status', 'git diff', 'git log', 'git add', 'git commit'];
|
|
14
|
+
|
|
9
15
|
/** Package defaults. Domain defaults and project overrides are layered on top. */
|
|
10
16
|
const DEFAULTS = {
|
|
11
17
|
domains: ['btp'],
|
|
12
18
|
hosts: ['claude-code'],
|
|
13
19
|
language: 'en',
|
|
14
|
-
git: { base: null },
|
|
20
|
+
git: { base: null, branch: { create: 'agent', pattern: null } },
|
|
15
21
|
scope: { implicit: {} },
|
|
16
22
|
risk_paths: [],
|
|
17
23
|
tests: {},
|
package/src/context.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { repoRoot, userEmail } from './git.mjs';
|
|
3
3
|
import { loadConfig } from './config.mjs';
|
|
4
|
-
import { confirmOnTerminal, editOnTerminal } from './terminal.mjs';
|
|
4
|
+
import { askOnTerminal, confirmOnTerminal, editOnTerminal } from './terminal.mjs';
|
|
5
5
|
import { createStyle } from './ui.mjs';
|
|
6
6
|
|
|
7
7
|
export const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
@@ -24,6 +24,7 @@ export function createContext({
|
|
|
24
24
|
now = utcNow,
|
|
25
25
|
confirm = confirmOnTerminal,
|
|
26
26
|
edit = editOnTerminal,
|
|
27
|
+
ask = askOnTerminal,
|
|
27
28
|
} = {}) {
|
|
28
29
|
let root;
|
|
29
30
|
let config;
|
|
@@ -35,6 +36,8 @@ export function createContext({
|
|
|
35
36
|
confirm,
|
|
36
37
|
/** Asks the human for one line, prefilled with `initial` (async). */
|
|
37
38
|
edit,
|
|
39
|
+
/** Asks the human a yes/no question; null without a terminal. */
|
|
40
|
+
ask,
|
|
38
41
|
kit: pkg.version,
|
|
39
42
|
get root() {
|
|
40
43
|
root ??= repoRoot(cwd);
|
package/src/feature.mjs
CHANGED
|
@@ -111,6 +111,17 @@ function validateApprovals(data, slug) {
|
|
|
111
111
|
return data;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Whether a review still blocks: its verdict is blocked and the human has not accepted
|
|
116
|
+
* every blocker it raised (design 7.4: no open blocker, unless accepted). An accepted
|
|
117
|
+
* blocker leaves the correction loop, so the step needs no further round for it.
|
|
118
|
+
*/
|
|
119
|
+
export function stillBlocked(feature, record) {
|
|
120
|
+
if (record?.verdict !== 'blocked') return false;
|
|
121
|
+
const status = new Map(feature.findings.map((f) => [f.id, f.status]));
|
|
122
|
+
return (record.findings ?? []).some((f) => f.severity === 'blocker' && status.get(f.id) !== 'accepted');
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
/**
|
|
115
126
|
* Findings with their current status. A finding is resolved when a later record lists
|
|
116
127
|
* it in `resolves`, accepted when the human accepted it, and open otherwise.
|
|
@@ -206,7 +217,7 @@ export function gateReview(feature, gate) {
|
|
|
206
217
|
if (gate === 'design' && docs.design !== feature.designHash) {
|
|
207
218
|
problems.push(`the latest ${record.step} review (${record.id}) did not review the current design.md and tasks.md`);
|
|
208
219
|
}
|
|
209
|
-
if (record
|
|
220
|
+
if (stillBlocked(feature, record)) problems.push(`the latest ${record.step} review (${record.id}) is blocked`);
|
|
210
221
|
}
|
|
211
222
|
const blockers = feature.findings.filter((f) => f.status === 'open' && f.severity === 'blocker' && steps.includes(f.step));
|
|
212
223
|
for (const f of blockers) problems.push(`open blocker ${f.id}: ${f.issue}`);
|
package/src/fix.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { git, mergeBase, resolveBase } from './git.mjs';
|
|
4
|
-
import { FEATURES_DIR, latestReview } from './feature.mjs';
|
|
4
|
+
import { FEATURES_DIR, latestReview, stillBlocked } from './feature.mjs';
|
|
5
5
|
import { treeHash } from './review.mjs';
|
|
6
6
|
import { matcher } from './scope.mjs';
|
|
7
7
|
|
|
@@ -100,7 +100,7 @@ export function fixRules(root, config) {
|
|
|
100
100
|
export function freshReview(root, config, unit, step) {
|
|
101
101
|
const record = latestReview(unit.reviews, [step]);
|
|
102
102
|
if (!record) return { problem: `no ${step} review recorded` };
|
|
103
|
-
if (record
|
|
103
|
+
if (stillBlocked(unit, record)) return { record, problem: `the latest ${step} review ${record.id} is blocked` };
|
|
104
104
|
if (record.tree_hash !== treeHash(root, config, unit.slug)) {
|
|
105
105
|
return { record, problem: `the latest ${step} review ${record.id} is stale: files changed after it` };
|
|
106
106
|
}
|
package/src/git.mjs
CHANGED
|
@@ -36,6 +36,15 @@ export function resolveBase(root, configured) {
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The checked-out branch: the local branch name, or in a pull request job (detached HEAD)
|
|
41
|
+
* the PR's head branch from the CI environment. Null when there is none.
|
|
42
|
+
*/
|
|
43
|
+
export function currentBranch(root, env = process.env) {
|
|
44
|
+
const name = git(root, ['symbolic-ref', '--quiet', '--short', 'HEAD'], { allowFail: true })?.trim();
|
|
45
|
+
return name || env.GITHUB_HEAD_REF || env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || null;
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
/** The merge-base commit with the base branch, or null when there is none yet. */
|
|
40
49
|
export function mergeBase(root, base) {
|
|
41
50
|
if (!base) return null;
|
package/src/progress.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { git, mergeBase, resolveBase } from './git.mjs';
|
|
2
2
|
import { resolveArea } from './config.mjs';
|
|
3
3
|
import { matcher } from './scope.mjs';
|
|
4
|
-
import { latestReview } from './feature.mjs';
|
|
4
|
+
import { latestReview, stillBlocked } from './feature.mjs';
|
|
5
5
|
import { treeHash } from './review.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -35,7 +35,7 @@ function isAncestor(root, ancestor, descendant) {
|
|
|
35
35
|
|
|
36
36
|
/** A passing review of `step` that saw the given commit (its head contains the commit). */
|
|
37
37
|
function reviewedSince(root, feature, step, sha) {
|
|
38
|
-
return feature.reviews.records.some((r) => r.step === step && r
|
|
38
|
+
return feature.reviews.records.some((r) => r.step === step && !stillBlocked(feature, r) && isAncestor(root, sha, r.head_commit));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -79,7 +79,7 @@ export function buildProgress(root, config, feature, options = {}) {
|
|
|
79
79
|
export function verifyState(root, config, feature) {
|
|
80
80
|
const record = latestReview(feature.reviews, ['verify']);
|
|
81
81
|
if (!record) return { state: 'none', record: null };
|
|
82
|
-
if (record
|
|
82
|
+
if (stillBlocked(feature, record)) return { state: 'blocked', record };
|
|
83
83
|
if (record.tree_hash !== treeHash(root, config, feature.slug)) return { state: 'stale', record };
|
|
84
84
|
return { state: 'current', record };
|
|
85
85
|
}
|
package/src/review-policy.mjs
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* (`build.fix_attempts`). `agjan status` shows them; the skills follow `status`.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { stillBlocked } from './feature.mjs';
|
|
9
|
+
|
|
8
10
|
/** Default tier per kind of review step. */
|
|
9
11
|
export const DEFAULT_TIERS = {
|
|
10
12
|
spec: 'balanced',
|
|
@@ -45,5 +47,5 @@ export function roundState(feature, config, step) {
|
|
|
45
47
|
const last = records.at(-1) ?? null;
|
|
46
48
|
const limit = roundLimit(config);
|
|
47
49
|
const round = last?.round ?? 0;
|
|
48
|
-
return { last, round, limit, exhausted: last
|
|
50
|
+
return { last, round, limit, exhausted: stillBlocked(feature, last) && round >= limit };
|
|
49
51
|
}
|
package/src/review.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { stringify as toYaml } from 'yaml';
|
|
5
5
|
import { git, changedFiles, mergeBase, resolveBase } from './git.mjs';
|
|
@@ -13,6 +13,7 @@ import { watchedHashes } from './baseline.mjs';
|
|
|
13
13
|
import { acResults, loadResults, resultLabel } from './test-results.mjs';
|
|
14
14
|
import { LOG_FILE, appendLog } from './log.mjs';
|
|
15
15
|
import { AgjanError } from './errors.mjs';
|
|
16
|
+
import { designProblems, documentProblems } from './validate.mjs';
|
|
16
17
|
|
|
17
18
|
export const REVIEW_MD = 'review.md';
|
|
18
19
|
const CONTEXT_DIR = '.agjan/review-contexts';
|
|
@@ -26,6 +27,22 @@ function scriptOwned(slug) {
|
|
|
26
27
|
return new Set([APPROVALS_FILE, REVIEWS_FILE, REVIEW_MD, LOG_FILE, 'report.md', 'fix.json', 'fix.md'].map((f) => `${FEATURES_DIR}/${slug}/${f}`));
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* What a changed path holds now: the file's bytes, a symbolic link's target, or null when
|
|
32
|
+
* it is deleted. A folder (an untracked link to one, a nested repository) is never read.
|
|
33
|
+
*/
|
|
34
|
+
function currentContent(path) {
|
|
35
|
+
let stat;
|
|
36
|
+
try {
|
|
37
|
+
stat = lstatSync(path);
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (stat.isSymbolicLink()) return Buffer.from(`symbolic link to ${readlinkSync(path)}`);
|
|
42
|
+
if (!stat.isFile()) return Buffer.from(stat.isDirectory() ? '(folder)' : '(not a regular file)');
|
|
43
|
+
return readFileSync(path);
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
/**
|
|
30
47
|
* Hash of the change as it stands: every file changed relative to the merge-base
|
|
31
48
|
* (committed, staged, unstaged, untracked) with its current content, except the
|
|
@@ -36,9 +53,9 @@ export function treeHash(root, config, slug) {
|
|
|
36
53
|
const hash = createHash('sha256');
|
|
37
54
|
for (const file of changedFiles(root, resolveBase(root, config.git?.base))) {
|
|
38
55
|
if (skip.has(file) || file.startsWith('.agjan/')) continue;
|
|
39
|
-
const
|
|
56
|
+
const content = currentContent(join(root, file));
|
|
40
57
|
hash.update(file).update('\0');
|
|
41
|
-
hash.update(
|
|
58
|
+
hash.update(content ? createHash('sha256').update(content).digest('hex') : 'deleted').update('\0');
|
|
42
59
|
}
|
|
43
60
|
return `sha256:${hash.digest('hex')}`;
|
|
44
61
|
}
|
|
@@ -78,7 +95,7 @@ function diffOf(root, base, patterns) {
|
|
|
78
95
|
let out = git(root, ['diff', '--no-color', '--no-ext-diff', from, '--', ...specs], { allowFail: true }) ?? '';
|
|
79
96
|
const untracked = git(root, ['ls-files', '--others', '--exclude-standard', '--', ...specs]).split('\n').filter(Boolean);
|
|
80
97
|
for (const file of untracked) {
|
|
81
|
-
out += `\n--- new file: ${file}\n${
|
|
98
|
+
out += `\n--- new file: ${file}\n${currentContent(join(root, file))?.toString('utf8') ?? '(deleted)'}`;
|
|
82
99
|
}
|
|
83
100
|
return capped(out || '(no changes)\n');
|
|
84
101
|
}
|
|
@@ -122,12 +139,35 @@ const CHECKLISTS = {
|
|
|
122
139
|
spec: 'No unrequested technical decisions. Technical questions listed under Open technical questions are expected and are not decisions: never ask to remove that section; Design answers them. Every AC testable and complete; an AC without a Verification line is automated, which is the default and not a finding; flag only ACs that cannot be tested automatically but are not marked manual. Non-functional and authorization requirements considered. Scope consistent.',
|
|
123
140
|
'design:light': 'The spec checks, plus: light mode is justified (nothing new: no new service, application, BTP service, authorization or deployment change). Tasks: paths plausible, every AC covered.',
|
|
124
141
|
design: 'Every AC covered by tasks. Areas and app types justified with alternatives. Open technical questions answered. Nothing beyond the spec.',
|
|
125
|
-
build: 'Each covered AC is met by the diff. Tests exist and carry the AC id in their names. Project conventions. Security basics (authorization, input validation, no secrets).',
|
|
142
|
+
build: 'Each covered AC is met by the diff. Tests exist and carry the AC id in their names. Project conventions. Security basics (authorization, input validation, no secrets; test or mocked users and other development settings only in a development profile, never active in production). Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope.',
|
|
126
143
|
fix: 'The change does exactly what the fix description says and nothing else. It is correct and complete. A test covers it where practical. No hidden scope: anything that changes behaviour beyond the description, or needs a business decision, is a blocker (it belongs in /agjan-spec).',
|
|
127
144
|
map: 'Every claim in project.md is traceable to the files it points to. Services, applications and BTP services are complete. The do-not-touch list is plausible and uses real paths. Short: one to two pages, pointers instead of copies.',
|
|
128
|
-
verify: 'Cross-task consistency. Every AC covered by a passing test or marked manual. The baseline (project.md) updated if a service, application or BTP service was added. Do not re-review each task.',
|
|
145
|
+
verify: 'Cross-task consistency. Every AC covered by a passing test or marked manual. Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope. The baseline (project.md) updated if a service, application or BTP service was added. Do not re-review each task.',
|
|
129
146
|
};
|
|
130
147
|
|
|
148
|
+
/**
|
|
149
|
+
* What the given tasks may change (design 6.5), as `agjan check` judges it: the task paths,
|
|
150
|
+
* the implicit paths of their areas (lockfiles, i18n, fixtures, package.json), and approved
|
|
151
|
+
* amendments. The reviewer sees the same scope as the script.
|
|
152
|
+
*/
|
|
153
|
+
function scopeOf(config, feature, tasks) {
|
|
154
|
+
const taskIds = new Set(tasks.map((t) => t.id));
|
|
155
|
+
const own = tasks.flatMap((t) => t.paths);
|
|
156
|
+
const areas = [...new Set(tasks.map((t) => resolveArea(config, t.area ?? '')?.name).filter(Boolean))];
|
|
157
|
+
const implicit = [...new Set(areas.flatMap((a) => config.scope.implicit[a] ?? []))];
|
|
158
|
+
const amended = feature.amendments.filter((a) => a.status === 'approved' && taskIds.has(a.task)).flatMap((a) => a.paths);
|
|
159
|
+
return { own, implicit, amended, all: [...new Set([...own, ...implicit, ...amended])] };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function scopeText(scope) {
|
|
163
|
+
const list = (items) => (items.length ? items.map((p) => `\`${p}\``).join(', ') : '(none)');
|
|
164
|
+
return [
|
|
165
|
+
`- Task paths: ${list(scope.own)}`,
|
|
166
|
+
`- Implicit for the tasks' areas: ${list(scope.implicit)}`,
|
|
167
|
+
`- Approved amendments: ${list(scope.amended)}`,
|
|
168
|
+
].join('\n');
|
|
169
|
+
}
|
|
170
|
+
|
|
131
171
|
/** Builds the reviewer's input for a step: the only material the reviewer should read. */
|
|
132
172
|
export function buildContextText(root, config, feature, parsed) {
|
|
133
173
|
const base = resolveBase(root, config.git?.base);
|
|
@@ -161,12 +201,11 @@ export function buildContextText(root, config, feature, parsed) {
|
|
|
161
201
|
parts.push(section('tasks.md', fence(feature.tasks.text, 'md')));
|
|
162
202
|
} else if (parsed.kind === 'build') {
|
|
163
203
|
const ids = new Set(parsed.tasks.flatMap((t) => t.covers));
|
|
164
|
-
const
|
|
165
|
-
const taskIds = new Set(parsed.tasks.map((t) => t.id));
|
|
166
|
-
for (const a of feature.amendments) if (a.status === 'approved' && taskIds.has(a.task)) paths.push(...a.paths);
|
|
204
|
+
const scope = scopeOf(config, feature, parsed.tasks);
|
|
167
205
|
parts.push(section('Tasks', fence(toYaml(parsed.tasks.map(({ verify, ...t }) => (verify ? { ...t, verify } : t))), 'yaml')));
|
|
206
|
+
parts.push(section('Allowed paths (scope, enforced by agjan check)', scopeText(scope)));
|
|
168
207
|
parts.push(section('Acceptance criteria covered', acsText(feature, ids)));
|
|
169
|
-
parts.push(section('Diff of the
|
|
208
|
+
parts.push(section('Diff of the allowed paths', fence(diffOf(root, base, scope.all), 'diff')));
|
|
170
209
|
} else if (parsed.kind === 'verify') {
|
|
171
210
|
if (!feature.design || !feature.tasks) throw new AgjanError('design.md and tasks.md must exist for the verify review');
|
|
172
211
|
const areaNames = [...new Set(feature.tasks.parsed.tasks.map((t) => resolveArea(config, t.area)?.name).filter(Boolean))];
|
|
@@ -181,6 +220,7 @@ export function buildContextText(root, config, feature, parsed) {
|
|
|
181
220
|
parts.push(section('AC coverage (test files mentioning the AC id, and test results)', `| AC | verification | test files | result |\n|---|---|---|---|\n${coverage}`));
|
|
182
221
|
parts.push(section('design.md', fence(feature.design.text, 'md')));
|
|
183
222
|
parts.push(section('tasks.md', fence(feature.tasks.text, 'md')));
|
|
223
|
+
parts.push(section('Allowed paths (scope, enforced by agjan check)', scopeText(scopeOf(config, feature, feature.tasks.parsed.tasks))));
|
|
184
224
|
parts.push(section('Changed files', changed.map((f) => `- ${f}`).join('\n') || '(none)'));
|
|
185
225
|
parts.push(section('Full diff', fence(diffOf(root, base, changed), 'diff')));
|
|
186
226
|
}
|
|
@@ -199,9 +239,48 @@ export function buildContextText(root, config, feature, parsed) {
|
|
|
199
239
|
}
|
|
200
240
|
|
|
201
241
|
/** review_context: builds the context, stores its metadata, returns id and text. */
|
|
242
|
+
/**
|
|
243
|
+
* A new round of a step is pointless when nothing changed since its last round raised
|
|
244
|
+
* findings: the reviewer would see the same files. It happens when a writer starts the
|
|
245
|
+
* review before (or in parallel with) its edits, and it costs one of the step's rounds.
|
|
246
|
+
*/
|
|
247
|
+
function unchangedSinceFindings(feature, step, tree) {
|
|
248
|
+
const last = feature.reviews.records.filter((r) => r.step === step).at(-1);
|
|
249
|
+
if (!last || last.verdict === 'pass' || last.tree_hash !== tree) return;
|
|
250
|
+
throw new AgjanError(
|
|
251
|
+
`nothing changed since ${last.id} (${last.verdict}); address its findings and save the changes before the next round. ` +
|
|
252
|
+
'A finding that needs no change is accepted by the human (agjan accept), not reviewed again.',
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Spec and design reviews need complete documents: the same structural checks the gate
|
|
258
|
+
* runs (sections, areas, every AC covered by a task with a title and paths). A review of
|
|
259
|
+
* an unfinished template only reports that and costs one of the step's rounds.
|
|
260
|
+
*/
|
|
261
|
+
function unfinishedDocuments(feature, config, step) {
|
|
262
|
+
if (!['spec', 'design', 'design:light'].includes(step)) return;
|
|
263
|
+
const problems = [];
|
|
264
|
+
if (!feature.spec) problems.push('spec.md does not exist');
|
|
265
|
+
if (step !== 'spec') {
|
|
266
|
+
if (!feature.design) problems.push('design.md does not exist');
|
|
267
|
+
if (!feature.tasks) problems.push('tasks.md does not exist');
|
|
268
|
+
}
|
|
269
|
+
const names = step === 'spec' ? ['spec.md'] : ['spec.md', 'design.md', 'tasks.md'];
|
|
270
|
+
problems.push(...documentProblems(feature).filter((p) => names.some((n) => p.startsWith(n))));
|
|
271
|
+
if (step !== 'spec') problems.push(...designProblems(feature, config));
|
|
272
|
+
if (problems.length === 0) return;
|
|
273
|
+
throw new AgjanError(
|
|
274
|
+
`the documents are not ready for the ${step} review; complete them first:\n${problems.map((p) => ` - ${p}`).join('\n')}`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
202
278
|
export function createReviewContext(root, config, { feature: slug, step }) {
|
|
203
279
|
const feature = loadFeature(root, slug);
|
|
204
280
|
const parsed = parseStep(step, feature, config);
|
|
281
|
+
unfinishedDocuments(feature, config, parsed.step);
|
|
282
|
+
const tree = treeHash(root, config, feature.slug);
|
|
283
|
+
unchangedSinceFindings(feature, parsed.step, tree);
|
|
205
284
|
const text = buildContextText(root, config, feature, parsed);
|
|
206
285
|
const id = `${feature.key}-C${randomBytes(4).toString('hex')}`;
|
|
207
286
|
const base = resolveBase(root, config.git?.base);
|
|
@@ -211,7 +290,7 @@ export function createReviewContext(root, config, { feature: slug, step }) {
|
|
|
211
290
|
step: parsed.step,
|
|
212
291
|
documents: { spec: feature.spec?.hash, design: feature.designHash ?? undefined },
|
|
213
292
|
inputs_hash: sha256(text),
|
|
214
|
-
tree_hash:
|
|
293
|
+
tree_hash: tree,
|
|
215
294
|
base_commit: mergeBase(root, base),
|
|
216
295
|
head_commit: git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true })?.trim() ?? null,
|
|
217
296
|
};
|
package/src/terminal.mjs
CHANGED
|
@@ -58,6 +58,22 @@ export function confirmOnTerminal(summary, expected) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Asks a yes/no question on the controlling terminal. Returns true or false, or null when
|
|
63
|
+
* there is no terminal (a script, CI or an agent): the caller then keeps its default.
|
|
64
|
+
*/
|
|
65
|
+
export function askOnTerminal(question) {
|
|
66
|
+
const tty = openTerminal();
|
|
67
|
+
if (!tty) return null;
|
|
68
|
+
try {
|
|
69
|
+
writeSync(tty.output, `${question} [y/N] `);
|
|
70
|
+
return /^y(es)?$/i.test(readLine(tty.input).trim());
|
|
71
|
+
} finally {
|
|
72
|
+
closeSync(tty.input);
|
|
73
|
+
if (tty.output !== tty.input) closeSync(tty.output);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
/**
|
|
62
78
|
* Asks for one line on the controlling terminal with `initial` already typed, so the human
|
|
63
79
|
* can edit it in place (cursor keys, backspace) or press Enter to keep it. Without line
|