karajan-code 4.6.1 → 4.6.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": "karajan-code",
3
- "version": "4.6.1",
3
+ "version": "4.6.2",
4
4
  "description": "Local multi-agent coding orchestrator with TDD, SonarQube, and code review pipeline",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0",
@@ -113,14 +113,26 @@ export async function reviewGateCommand({ config, logger = null, flags = {} }) {
113
113
  // single test change warn (block via method_gates.tests_with_code).
114
114
  const changedFiles = (await rawDiff(flags.range, ["--name-only"])).split("\n").map((f) => f.trim()).filter(Boolean);
115
115
 
116
- // KJC-TSK-0688 (MG-C): oversized-diff nudge — informative only; the
117
- // project's CI owns any hard budget. Sums additions from --numstat.
116
+ // KJC-TSK-0688 (MG-C) + KJC-TSK-0691 (MG-E): oversized-diff policy.
117
+ // Field case: a 522-line PR sailed past the warning with a
118
+ // rationalization — where the project wants teeth, pr_size: "block"
119
+ // rejects deterministically with a NAMED escape. Default stays warn.
118
120
  const sizeWarn = config?.method_gates?.pr_size_warn ?? 150;
119
121
  if (sizeWarn > 0) {
120
122
  const numstat = await rawDiff(flags.range, ["--numstat"]);
121
123
  const added = numstat.split("\n").reduce((acc, l) => acc + (Number(l.split("\t")[0]) || 0), 0);
122
124
  if (added > sizeWarn) {
123
- console.log(`⚠ pr-size: ${added} lines added (guideline ~${sizeWarn}) — atomic PRs review better; consider splitting (method_gates.pr_size_warn to tune)`);
125
+ const sizePolicy = config?.method_gates?.pr_size || "warn";
126
+ if (process.env.KJ_ALLOW_LARGE_PR === "1") {
127
+ console.log(`⚠ pr-size exempt: ${added} lines added — KJ_ALLOW_LARGE_PR=1 (explicit escape hatch)`);
128
+ } else if (sizePolicy === "block") {
129
+ const reason = `${added} lines added exceeds the ${sizeWarn}-line budget (method_gates.pr_size: block) — partition the work, or get your user's explicit OK and re-run with KJ_ALLOW_LARGE_PR=1`;
130
+ console.log(`✗ pr-size gate: ${reason}`);
131
+ process.exitCode = 1;
132
+ return { verdict: "rejected", reviewer: "pr-size", issues: [{ severity: "high", description: reason }] };
133
+ } else {
134
+ console.log(`⚠ pr-size: ${added} lines added (guideline ~${sizeWarn}) — an oversized warning is not an opinion: partition, or ask your user (method_gates.pr_size: block to harden)`);
135
+ }
124
136
  }
125
137
  }
126
138
  const tests = checkTestsWithCode({ config, stagedFiles: changedFiles });
@@ -66,6 +66,10 @@ Invariants (the git gates enforce these — they are not suggestions):
66
66
  and it must be reviewed again. Disagree with a rejection? \`kj solomon\`.
67
67
  - Security findings are never overridable — not even by arbitration. You
68
68
  absorb the security role: \`kj brief security\` states what must be true.
69
+ - A design decision the card's AC don't cover belongs to the USER: record
70
+ it as a proposed ADR (\`kj adr add\`) and ask — never bury it in a PR
71
+ bullet. An oversized-diff warning is not an opinion either: partition,
72
+ or get an explicit OK.
69
73
  - Branch first: never commit on the base branch — every change reaches it
70
74
  through an atomic PR (~150 net lines, Conventional Commits). More than one
71
75
  task, or the base tree must stay untouched? \`kj worktree start <slug>\`
@@ -16,8 +16,8 @@ export const SHEBANG = "#!/usr/bin/env sh";
16
16
  /** Hooks enabled per profile. */
17
17
  export const PROFILE_HOOKS = {
18
18
  minimal: ["commit-msg"],
19
- standard: ["pre-commit", "commit-msg", "pre-push", "post-merge"],
20
- strict: ["pre-commit", "commit-msg", "pre-push", "post-merge"],
19
+ standard: ["pre-commit", "prepare-commit-msg", "commit-msg", "pre-push", "post-merge"],
20
+ strict: ["pre-commit", "prepare-commit-msg", "commit-msg", "pre-push", "post-merge"],
21
21
  };
22
22
 
23
23
  /** Build the managed body for a single hook. */
@@ -99,6 +99,37 @@ export function hookBody(hook, cmds = {}, { globalHooksDir = null, baseBranch =
99
99
  else lines.push("# (no test command detected for this stack)");
100
100
  return [...lines, ...chain].join("\n");
101
101
  }
102
+ case "prepare-commit-msg":
103
+ // KJC-TSK-0692 (MG-F): the branch already carries the card ref
104
+ // (validated by the card-first gate) — the subject inherits it
105
+ // automatically. A convention that enforces itself needs no adoption.
106
+ return [
107
+ 'msg_file="$1"',
108
+ 'branch=$(git symbolic-ref --short HEAD 2>/dev/null || echo "")',
109
+ "# POSIX-safe extraction (no grep -o): the ref is the leading",
110
+ "# card-shaped token of the branch's last segment (feat/REF-desc).",
111
+ "seg=$(printf '%s' \"$branch\" | tr '[:upper:]' '[:lower:]'); seg=\"${seg##*/}\"",
112
+ "ref=$(printf '%s' \"$seg\" | sed -nE 's/^([a-z][a-z0-9]{1,9}(-[a-z][a-z0-9]{1,9})*-[0-9]{1,6})(-.*)?$/\\1/p')",
113
+ 'header=$(head -n1 "$msg_file")',
114
+ 'if [ -n "$ref" ] && [ -n "$header" ]; then',
115
+ ' case "$header" in',
116
+ " Merge*|fixup!*|squash!*) ;;",
117
+ " *)",
118
+ " # Boundary match — a header mentioning KJW-TSK-00011 must not",
119
+ " # suppress the KJW-TSK-0001 stamp. $ref is [a-z0-9-] only by",
120
+ " # construction (sed extraction above), safe inside the ERE.",
121
+ ' if ! printf \'%s\' "$header" | grep -qiE "(^|[^a-zA-Z0-9-])$ref([^a-zA-Z0-9-]|$)"; then',
122
+ " stamp=$(printf '%s' \"$ref\" | tr '[:lower:]' '[:upper:]')",
123
+ ' new_header="$header ($stamp)"',
124
+ ' if [ "${#new_header}" -le 100 ]; then',
125
+ " { printf '%s\\n' \"$new_header\"; tail -n +2 \"$msg_file\"; } > \"$msg_file.kjtmp\" && mv \"$msg_file.kjtmp\" \"$msg_file\"",
126
+ " fi",
127
+ " fi",
128
+ " ;;",
129
+ " esac",
130
+ "fi",
131
+ ...chain,
132
+ ].join("\n");
102
133
  case "post-merge":
103
134
  return [
104
135
  "# Refresh the local RAG index so retrieval never serves stale code.",