agjan 0.0.3 → 0.0.4
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 +7 -0
- package/kit/hooks/guard.mjs +32 -0
- package/kit/skills/cap-developer/references/validation-security.md +4 -0
- package/package.json +1 -1
- package/schemas/config.schema.json +4 -0
- package/src/commands/setup.mjs +1 -0
- package/src/commands/status.mjs +1 -1
- package/src/review-policy.mjs +27 -1
- package/src/review.mjs +5 -4
package/docs/guide.md
CHANGED
|
@@ -214,6 +214,13 @@ settings remove the routine prompts without giving up control:
|
|
|
214
214
|
edit prompt with "don't ask again for file operations in this repo". agjan's scope
|
|
215
215
|
check, the pre-commit hook and the reviewer cover what the agent changes.
|
|
216
216
|
|
|
217
|
+
**Script edits are denied.** Agents sometimes edit files with small scripts
|
|
218
|
+
(`python3 - <<EOF … open(p, 'w')`, `sed -i`, `cat > file <<EOF`) instead of their edit
|
|
219
|
+
tool. Such an edit fails silently when the text it replaces does not match, and you do
|
|
220
|
+
not see the change. agjan's guard denies these commands and tells the agent to use its
|
|
221
|
+
edit tool; reading (`cat`, `sed -n`, `grep`) and running project scripts stay allowed.
|
|
222
|
+
Set `agent.script_edits` to `"allow"` in `agjan.config.json` to turn this off.
|
|
223
|
+
|
|
217
224
|
Copilot keeps your own "don't ask again" answers per folder in
|
|
218
225
|
`~/.copilot/permissions-config.json`; that file is personal and not part of the project.
|
|
219
226
|
|
package/kit/hooks/guard.mjs
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
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 denies file edits by shell or script commands (python/node scripts that write files,
|
|
9
|
+
* sed -i, cat > file, …) so that agents use their file edit tool, unless the project sets
|
|
10
|
+
* `agent.script_edits` to "allow" (design decision 63).
|
|
11
|
+
*
|
|
8
12
|
* It also approves, without a prompt, shell commands the project lists in `agent.allow`
|
|
9
13
|
* of agjan.config.json (opt-in, design decision 61): a single simple command that starts
|
|
10
14
|
* with a listed command. Anything with `;`, `&&`, `|`, `$(…)`, backticks or redirections is
|
|
@@ -44,6 +48,33 @@ const BRANCH_CREATE = new RegExp(
|
|
|
44
48
|
String.raw`|worktree\s+add\s+(?:\S+\s+)*?-[bB]\b)`,
|
|
45
49
|
);
|
|
46
50
|
|
|
51
|
+
const EDIT_REASON =
|
|
52
|
+
'Edit files with your file edit tool, not with shell or script commands: the edit tool shows the change to the user and fails visibly when the text to replace does not match. If you have no edit tool, ask the user.';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Shell commands that write files as a script (design decision 63): interpreter scripts
|
|
56
|
+
* that open files for writing, in-place stream edits, and cat/echo/printf/tee into a file.
|
|
57
|
+
* Reading (cat file, sed -n, grep, running a project script) is not matched.
|
|
58
|
+
*/
|
|
59
|
+
const SCRIPT_EDITS = [
|
|
60
|
+
// python3 - <<EOF … / python -c "…" that writes a file (the script is inside quotes or a heredoc)
|
|
61
|
+
(c) => /\bpython[0-9.]*\b/.test(c) && /(<<|\s-c\s)/.test(c) && /open\([^,)]*,\s*(?:mode\s*=\s*)?['"][wax]b?\+?['"]|\.write_(text|bytes)\(/.test(c),
|
|
62
|
+
// node -e / node <<EOF that writes a file
|
|
63
|
+
(c) => /\bnode\b/.test(c) && /(<<|\s(-e|--eval|-p|--print)\s)/.test(c) && /\b(writeFileSync|appendFileSync|writeFile|appendFile|createWriteStream)\b/.test(c),
|
|
64
|
+
// The rest looks at the command line itself, with quoted text (messages, patterns) masked.
|
|
65
|
+
(c) => /\bsed\s+(?:[^|;&]*\s)?(?:-[a-zA-Z]*i\b|--in-place)/.test(unquoted(c)),
|
|
66
|
+
(c) => /\bperl\s+(?:[^|;&]*\s)?-[a-zA-Z]*i/.test(unquoted(c)),
|
|
67
|
+
// cat / echo / printf redirected into a file (not /dev/null, not 2>&1)
|
|
68
|
+
(c) => /\b(cat|echo|printf)\b[^|;&]*?(?<![0-9&])>>?\s*(?!&|\/dev\/null\b)[\w./~-]/.test(unquoted(c)),
|
|
69
|
+
// tee into a file
|
|
70
|
+
(c) => /\btee\s+(?:-a\s+)?(?!\/dev\/)[\w./~]/.test(unquoted(c)),
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
/** The command with every quoted string replaced by Q, so quoted text is not read as syntax. */
|
|
74
|
+
function unquoted(command) {
|
|
75
|
+
return command.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, 'Q');
|
|
76
|
+
}
|
|
77
|
+
|
|
47
78
|
/** Characters that chain, substitute or redirect: such commands are never auto-approved. */
|
|
48
79
|
const COMPOUND = /[;&|`$<>(){}\n\r]/;
|
|
49
80
|
|
|
@@ -74,6 +105,7 @@ export function decide(payload, config = {}) {
|
|
|
74
105
|
if (typeof command !== 'string') return null;
|
|
75
106
|
if (HUMAN_ONLY.test(command)) return answer(payload, 'deny', REASON);
|
|
76
107
|
if (config?.git?.branch?.create === 'confirm' && BRANCH_CREATE.test(command)) return answer(payload, 'deny', BRANCH_REASON);
|
|
108
|
+
if (config?.agent?.script_edits !== 'allow' && SCRIPT_EDITS.some((matches) => matches(command))) return answer(payload, 'deny', EDIT_REASON);
|
|
77
109
|
const allow = config?.agent?.allow ?? [];
|
|
78
110
|
const shell = /^(bash|powershell|shell)$/i.test(payload.toolName ?? payload.tool_name ?? '');
|
|
79
111
|
if (shell && allowed(command, allow)) return answer(payload, 'allow', 'listed in agent.allow of agjan.config.json');
|
|
@@ -28,6 +28,10 @@ Default messages use the codes `ASSERT_MANDATORY`, `ASSERT_RANGE`, `ASSERT_ENUM`
|
|
|
28
28
|
|
|
29
29
|
## Authorization
|
|
30
30
|
|
|
31
|
+
- A service, entity or operation without `@requires` or `@restrict` is open to every
|
|
32
|
+
user, anonymous requests included (CAP does not restrict services by default). Every
|
|
33
|
+
entity and operation the spec's roles cover needs one, and tests for a user without
|
|
34
|
+
the role (403) and an anonymous request (401).
|
|
31
35
|
- `@requires: 'Role'` (or a list, meaning any of them) on a service, entity or
|
|
32
36
|
operation. Pseudo roles: `authenticated-user`, `system-user`, `any`. A service with
|
|
33
37
|
`@requires` also protects its `$metadata` and service root.
|
package/package.json
CHANGED
|
@@ -96,6 +96,10 @@
|
|
|
96
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
97
|
"type": "array",
|
|
98
98
|
"items": { "type": "string", "minLength": 1 }
|
|
99
|
+
},
|
|
100
|
+
"script_edits": {
|
|
101
|
+
"description": "Whether agents may edit files with shell or script commands (python/node scripts that write files, sed -i, cat > file, tee). Default 'deny': the agjan guard hook sends them to their file edit tool.",
|
|
102
|
+
"enum": ["deny", "allow"]
|
|
99
103
|
}
|
|
100
104
|
},
|
|
101
105
|
"additionalProperties": false
|
package/src/commands/setup.mjs
CHANGED
|
@@ -267,6 +267,7 @@ export function doctor(ctx) {
|
|
|
267
267
|
}
|
|
268
268
|
const allow = config.agent?.allow ?? [];
|
|
269
269
|
ok('agent allow list', allow.length ? `${allow.length} command(s) without a prompt: ${allow.join(', ')}` : 'none (the hosts ask for every command)');
|
|
270
|
+
ok('script edits', config.agent?.script_edits === 'allow' ? 'allowed (agent.script_edits)' : 'denied by the guard: agents edit files with their edit tool');
|
|
270
271
|
const ignored = git(root, ['check-ignore', '-q', '.agjan/x'], { allowFail: true }) !== null;
|
|
271
272
|
if (!ignored) warn('.gitignore', '.agjan/ is not ignored; run: npx agjan sync');
|
|
272
273
|
}
|
package/src/commands/status.mjs
CHANGED
|
@@ -28,7 +28,7 @@ function reviewNext(ctx, feature, step) {
|
|
|
28
28
|
if (state.exhausted) {
|
|
29
29
|
return `the ${step} review is still blocked after ${state.round} of ${state.limit} rounds: stop and hand over to the human (fix with them, accept findings, or change the documents)`;
|
|
30
30
|
}
|
|
31
|
-
const round = state.round ? `, round ${state.
|
|
31
|
+
const round = state.round ? `, round ${state.next} of ${state.limit}` : '';
|
|
32
32
|
return `review step ${step} with ${reviewerFor(ctx.config, step)}${round}`;
|
|
33
33
|
}
|
|
34
34
|
|
package/src/review-policy.mjs
CHANGED
|
@@ -38,6 +38,32 @@ export function fixAttempts(config) {
|
|
|
38
38
|
return config.build?.fix_attempts ?? 3;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** The gate approvals that close a correction loop of a review step. */
|
|
42
|
+
const CLOSING_APPROVALS = { spec: ['spec'], design: ['design'], 'design:light': ['spec', 'design'] };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The round the next review of `step` gets (design 7.4). Rounds count within one
|
|
46
|
+
* correction loop: a loop ends with a review without findings (`pass`), with the gate's
|
|
47
|
+
* approval after its last review, or, for build steps, with a passing verify review after
|
|
48
|
+
* it. A later change, for example after the human's Gate 3 review, starts a new loop at
|
|
49
|
+
* round 1.
|
|
50
|
+
*/
|
|
51
|
+
export function nextRound(feature, step) {
|
|
52
|
+
const records = feature.reviews.records.filter((r) => r.step === step);
|
|
53
|
+
const approvals = (CLOSING_APPROVALS[step] ?? []).map((gate) => feature.approvals.approvals[gate]?.at_utc).filter(Boolean);
|
|
54
|
+
if (step.startsWith('build:')) {
|
|
55
|
+
const verified = feature.reviews.records.filter((r) => r.step === 'verify' && !stillBlocked(feature, r));
|
|
56
|
+
approvals.push(...verified.map((r) => r.at_utc));
|
|
57
|
+
}
|
|
58
|
+
let round = 1;
|
|
59
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
60
|
+
const r = records[i];
|
|
61
|
+
if (r.verdict === 'pass' || approvals.some((at) => at >= r.at_utc)) break;
|
|
62
|
+
round += 1;
|
|
63
|
+
}
|
|
64
|
+
return round;
|
|
65
|
+
}
|
|
66
|
+
|
|
41
67
|
/**
|
|
42
68
|
* The state of one review step: its latest round and verdict, and whether the round limit
|
|
43
69
|
* is reached with the step still blocked (design 7.4: stop and hand over to the human).
|
|
@@ -47,5 +73,5 @@ export function roundState(feature, config, step) {
|
|
|
47
73
|
const last = records.at(-1) ?? null;
|
|
48
74
|
const limit = roundLimit(config);
|
|
49
75
|
const round = last?.round ?? 0;
|
|
50
|
-
return { last, round, limit, exhausted: stillBlocked(feature, last) && round >= limit };
|
|
76
|
+
return { last, round, next: nextRound(feature, step), limit, exhausted: stillBlocked(feature, last) && round >= limit };
|
|
51
77
|
}
|
package/src/review.mjs
CHANGED
|
@@ -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 { nextRound } from './review-policy.mjs';
|
|
16
17
|
import { designProblems, documentProblems } from './validate.mjs';
|
|
17
18
|
|
|
18
19
|
export const REVIEW_MD = 'review.md';
|
|
@@ -138,11 +139,11 @@ function openFindings(feature, steps) {
|
|
|
138
139
|
const CHECKLISTS = {
|
|
139
140
|
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.',
|
|
140
141
|
'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.',
|
|
141
|
-
design: 'Every AC covered by tasks. Areas and app types justified with alternatives. Open technical questions answered. Nothing beyond the spec.',
|
|
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.',
|
|
142
|
+
design: 'Every AC covered by tasks. Areas and app types justified with alternatives. Open technical questions answered. Every rule of the spec\'s Authorization section has a decision on how it is enforced. Nothing beyond the spec.',
|
|
143
|
+
build: 'Each covered AC is met by the diff. Tests exist and carry the AC id in their names. Project conventions. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request. 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.',
|
|
143
144
|
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).',
|
|
144
145
|
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.',
|
|
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.',
|
|
146
|
+
verify: 'Cross-task consistency. Every AC covered by a passing test or marked manual. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request. 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.',
|
|
146
147
|
};
|
|
147
148
|
|
|
148
149
|
/**
|
|
@@ -350,7 +351,7 @@ export function recordReview(root, config, { context_id: contextId, verdict, fin
|
|
|
350
351
|
const record = {
|
|
351
352
|
id: `${feature.key}-R${records.length + 1}`,
|
|
352
353
|
step: meta.step,
|
|
353
|
-
round:
|
|
354
|
+
round: nextRound(feature, meta.step),
|
|
354
355
|
at_utc: now(),
|
|
355
356
|
reviewer: { host, model: null, isolation },
|
|
356
357
|
context: contextId,
|