refactor(okr): begge hooks bruker delt frontmatter-modul (SC2) [skip-docs]

This commit is contained in:
Kjell Tore Guttormsen 2026-06-26 14:21:58 +02:00
commit 9b85c0b436
3 changed files with 116 additions and 17 deletions

View file

@ -7,6 +7,7 @@
import { readFileSync, existsSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { parseFrontmatter } from '../../lib/frontmatter.mjs';
const cwd = process.cwd();
const configPath = join(cwd, '.claude', 'okr.local.md');
@ -17,14 +18,8 @@ if (!existsSync(configPath)) {
try {
const content = readFileSync(configPath, 'utf8');
const match = content.match(/^---\n([\s\S]*?)\n---/);
if (!match) process.exit(0);
const fm = match[1];
const get = (key) => {
const m = fm.match(new RegExp(`${key}:\\s*["']?([^"'\\n]+)["']?`));
return m ? m[1].trim() : null;
};
const { raw, get } = parseFrontmatter(content);
if (raw === null) process.exit(0);
const cycleId = get('id');
const fase = get('fase');

View file

@ -8,6 +8,7 @@
import { readFileSync, existsSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { homedir } from 'node:os';
import { parseFrontmatter } from '../../lib/frontmatter.mjs';
const cwd = process.cwd();
const projectConfigPath = join(cwd, '.claude', 'okr.local.md');
@ -56,20 +57,14 @@ if (!configPath) {
try {
const content = readFileSync(configPath, 'utf8');
const match = content.match(/^---\n([\s\S]*?)\n---/);
if (!match) process.exit(0);
const fm = match[1];
const get = (key) => {
const m = fm.match(new RegExp(`${key}:\\s*["']?([^"'\\n]+)["']?`));
return m ? m[1].trim() : null;
};
const { raw, get } = parseFrontmatter(content);
if (raw === null) process.exit(0);
// Core fields (backwards-compatible with old 4-field format)
const org = get('navn') || get('name');
const syklus = get('gjeldende') || get('id') || get('current_cycle');
const sektor = get('sektor') || get('sector') || get('domene');
const linear = fm.includes('aktivert: true') || fm.includes('enabled: true');
const linear = raw.includes('aktivert: true') || raw.includes('enabled: true');
// New v1.1 fields (silently skipped if absent)
const modenhet = get('modenhetsnivaa');