agjan 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agjan",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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",
@@ -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 (exec form: no shell, the same on every OS). It also
27
- * catches wrapped forms the prefix deny rules miss (`sh -c "agjan approve …"`). If it
28
- * cannot start (agjan not installed), Claude Code treats the error as non-blocking.
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
- return (data.hooks?.PreToolUse ?? []).some((group) =>
39
- (group.hooks ?? []).some((h) => JSON.stringify(h) === JSON.stringify(GUARD_HOOK)),
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
- hooks = { ...hooks, PreToolUse: [...(hooks.PreToolUse ?? []), { matcher: 'Bash', hooks: [GUARD_HOOK] }] };
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
  },
@@ -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);
@@ -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 && last.verdict !== 'blocked';
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));
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';
@@ -26,6 +26,22 @@ function scriptOwned(slug) {
26
26
  return new Set([APPROVALS_FILE, REVIEWS_FILE, REVIEW_MD, LOG_FILE, 'report.md', 'fix.json', 'fix.md'].map((f) => `${FEATURES_DIR}/${slug}/${f}`));
27
27
  }
28
28
 
29
+ /**
30
+ * What a changed path holds now: the file's bytes, a symbolic link's target, or null when
31
+ * it is deleted. A folder (an untracked link to one, a nested repository) is never read.
32
+ */
33
+ function currentContent(path) {
34
+ let stat;
35
+ try {
36
+ stat = lstatSync(path);
37
+ } catch {
38
+ return null;
39
+ }
40
+ if (stat.isSymbolicLink()) return Buffer.from(`symbolic link to ${readlinkSync(path)}`);
41
+ if (!stat.isFile()) return Buffer.from(stat.isDirectory() ? '(folder)' : '(not a regular file)');
42
+ return readFileSync(path);
43
+ }
44
+
29
45
  /**
30
46
  * Hash of the change as it stands: every file changed relative to the merge-base
31
47
  * (committed, staged, unstaged, untracked) with its current content, except the
@@ -36,9 +52,9 @@ export function treeHash(root, config, slug) {
36
52
  const hash = createHash('sha256');
37
53
  for (const file of changedFiles(root, resolveBase(root, config.git?.base))) {
38
54
  if (skip.has(file) || file.startsWith('.agjan/')) continue;
39
- const path = join(root, file);
55
+ const content = currentContent(join(root, file));
40
56
  hash.update(file).update('\0');
41
- hash.update(existsSync(path) ? createHash('sha256').update(readFileSync(path)).digest('hex') : 'deleted').update('\0');
57
+ hash.update(content ? createHash('sha256').update(content).digest('hex') : 'deleted').update('\0');
42
58
  }
43
59
  return `sha256:${hash.digest('hex')}`;
44
60
  }
@@ -78,7 +94,7 @@ function diffOf(root, base, patterns) {
78
94
  let out = git(root, ['diff', '--no-color', '--no-ext-diff', from, '--', ...specs], { allowFail: true }) ?? '';
79
95
  const untracked = git(root, ['ls-files', '--others', '--exclude-standard', '--', ...specs]).split('\n').filter(Boolean);
80
96
  for (const file of untracked) {
81
- out += `\n--- new file: ${file}\n${readFileSync(join(root, file), 'utf8')}`;
97
+ out += `\n--- new file: ${file}\n${currentContent(join(root, file))?.toString('utf8') ?? '(deleted)'}`;
82
98
  }
83
99
  return capped(out || '(no changes)\n');
84
100
  }