feat(okr): UserPromptSubmit emne-guard + test (SC6) [skip-docs]
This commit is contained in:
parent
b594eeb88c
commit
c7a0323a81
3 changed files with 116 additions and 3 deletions
|
|
@ -13,6 +13,34 @@ const cwd = process.cwd();
|
|||
const projectConfigPath = join(cwd, '.claude', 'okr.local.md');
|
||||
const homeConfigPath = join(homedir(), '.claude', 'okr', 'org', 'profil.md');
|
||||
|
||||
// Topic guard (UserPromptSubmit): only inject OKR context when the user's
|
||||
// prompt is plausibly OKR-related. The stdin read is non-blocking here -- under
|
||||
// execFileSync (Claude Code's hook call and the tests) stdin is a closed pipe
|
||||
// so EOF is immediate; the isTTY guard avoids blocking in an interactive shell.
|
||||
// Default to PASS (inject) on any doubt -- empty/unparseable stdin, missing
|
||||
// prompt field, or TTY -- so we never drop a legitimate OKR prompt. Only an
|
||||
// explicit non-matching prompt is suppressed. No network.
|
||||
let rawPrompt = '';
|
||||
try {
|
||||
if (!process.stdin.isTTY) rawPrompt = readFileSync(0, 'utf8');
|
||||
} catch {
|
||||
rawPrompt = '';
|
||||
}
|
||||
if (rawPrompt) {
|
||||
let promptText = null;
|
||||
try {
|
||||
promptText = JSON.parse(rawPrompt).prompt;
|
||||
} catch {
|
||||
promptText = null;
|
||||
}
|
||||
if (typeof promptText === 'string' && promptText.length > 0) {
|
||||
const okrPattern = /\bokr\b|objective|key result|n[oø]kkelresultat|noekkelresultat|\bkr\b|\bm[aå]l\b|\bmaal\b|tildelingsbrev|kaskade|syklus|tertial|kvartal/i;
|
||||
if (!okrPattern.test(promptText)) {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hybrid org-profile resolution (most-specific-wins): project-local overrides
|
||||
// the machine-global home profile. The home path is the Fase 3 migration target;
|
||||
// this read is forward-compatible and stays inert until that file exists.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue