@systemfsoftware/omp-claude-compat 1.2.0 → 1.2.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.
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{A as e,B as t,C as n,Cn as r,D as i,Dn as a,E as o,En as s,F as c,Ft as l,H as u,I as d,N as f,O as ee,On as p,P as m,S as h,Sn as g,St as _,T as v,U as y,V as b,b as x,bn as te,bt as S,jt as C,k as w,kn as T,kt as E,mt as ne,pt as re,r as D,s as O,w as k,wn as A,xt as j,y as M,z as N}from"./esm-DxC3o46t.js";import{f as ie,l as ae,o as oe,p as se,s as ce,t as le,u as ue}from"./CommandExecutor-B_nJZc9B.js";import{a as P,d as de,i as F,o as I,r as fe,s as L}from"./dist-DQtXO3Ic.js";import{homedir as R}from"node:os";o({code:n,stdout:v,stderr:v});var z=class extends i()(`Block`,{reason:v}){},B=class extends i()(`Allow`,{updatedInput:m(k({key:v,value:e}))}){},V=class extends i()(`Warning`,{message:v}){};w(z,B,V);var H=class extends i()(`Blocked`,{reason:v}){},U=class extends i()(`Continue`,{warning:m(v),updatedInput:m(k({key:v,value:e}))}){};w(H,U);const pe=o({type:h(`command`),command:v,async:m(x),timeout:m(n)}),W=o({matcher:m(v),hooks:M(pe)}),G=o({PreToolUse:c(M(W),{exact:!0,default:()=>[]}),PostToolUse:c(M(W),{exact:!0,default:()=>[]}),UserPromptSubmit:c(M(W),{exact:!0,default:()=>[]}),Stop:c(M(W),{exact:!0,default:()=>[]}),SessionStart:c(M(W),{exact:!0,default:()=>[]}),SessionEnd:c(M(W),{exact:!0,default:()=>[]})}),me=f(w(o({hooks:G,disableAllHooks:m(x)}),o({...G.fields,disableAllHooks:m(x)})));function he(e){return a(me(e),e=>{if(`hooks`in e)return e;let{disableAllHooks:t,...n}=e;return{hooks:n,disableAllHooks:t}})}const ge=[`PreToolUse`,`PostToolUse`,`UserPromptSubmit`,`SessionStart`,`SessionEnd`,`Stop`];function _e(e){let t={hooks:{PreToolUse:[],PostToolUse:[],UserPromptSubmit:[],SessionStart:[],SessionEnd:[],Stop:[]}};for(let n of e){for(let e of ge)t.hooks[e]=(t.hooks[e]??[]).concat(Array.from(n.hooks[e]));n.disableAllHooks!==void 0&&(t.disableAllHooks=n.disableAllHooks)}return t}function K(e){return e.disableAllHooks===!0}const ve=f(d(o({decision:m(v),reason:m(v),hookSpecificOutput:m(o({permissionDecision:m(v),permissionDecisionReason:m(v),updatedInput:m(k({key:v,value:e}))}))})));var ye=class extends ee()(`HookVerdictError`,{raw:v}){},q=class extends i()(`ExitBlock`,{}){},J=class extends i()(`ExitDecisionJson`,{}){},Y=class extends i()(`ExitNoDecision`,{}){},X=class extends i()(`ExitOther`,{}){};w(q,J,Y,X);const be=e=>u(e.trim()).pipe(y(e=>e.startsWith(`{`),()=>new J({})),t(()=>new Y({}))),xe=e=>u(e.code).pipe(y(2,()=>new q({})),y(0,()=>be(e.stdout)),t(()=>new X({}))),Se=(e,n)=>u(e.trim()).pipe(y(``,()=>`Blocked by ${n} hook`),t(e=>e)),Ce=(e,n)=>u(e.hookSpecificOutput?.permissionDecision??e.decision).pipe(y(`deny`,()=>new z({reason:e.hookSpecificOutput?.permissionDecisionReason??`Blocked by ${n} hook`})),y(`block`,()=>new z({reason:e.reason??`Blocked by ${n} hook`})),t(()=>new B({updatedInput:e.hookSpecificOutput?.updatedInput}))),we=e=>u(e.trim()).pipe(y(``,()=>new B({})),t(e=>new V({message:e}))),Te=(e,t)=>u(xe(e)).pipe(b(`ExitBlock`,()=>T(new z({reason:Se(e.stderr,t)}))),b(`ExitNoDecision`,()=>T(new B({}))),b(`ExitDecisionJson`,()=>p(ve(e.stdout),{onLeft:()=>s(new ye({raw:e.stdout})),onRight:e=>T(Ce(e,t))})),b(`ExitOther`,()=>T(we(e.stderr))),N);function Ee(e,t){let n=e.replace(/"\$OMP_PROJECT_DIR"|'\$OMP_PROJECT_DIR'/g,JSON.stringify(t)).replace(/"\$\{OMP_PROJECT_DIR\}"|'\$\{OMP_PROJECT_DIR\}'/g,JSON.stringify(t)).replace(/"\$CLAUDE_PROJECT_DIR"|'\$CLAUDE_PROJECT_DIR'/g,JSON.stringify(t)).replace(/"\$\{CLAUDE_PROJECT_DIR\}"|'\$\{CLAUDE_PROJECT_DIR\}'/g,JSON.stringify(t)).replace(/\$OMP_PROJECT_DIR|\$\{OMP_PROJECT_DIR\}/g,JSON.stringify(t)).replace(/\$CLAUDE_PROJECT_DIR|\$\{CLAUDE_PROJECT_DIR\}/g,JSON.stringify(t)).trim();return{cmd:`sh`,args:[`-c`,n.startsWith(`"`)&&n.endsWith(`"`)?n.slice(1,-1):n]}}const De=S(`loadSettingsFile`)(function*(t){let n=yield*(yield*de).readFileString(t).pipe(re(()=>C(``)));if(n===``)return null;let r=f(d(k({key:v,value:e})))(n);if(A(r))return null;let i=r.right,a=he(i);return A(a)?null:a.right}),Oe=S(`loadSettings`)(function*(e){let t=[`${R()}/.claude/settings.json`,`${e}/.claude/settings.json`,`${e}/.claude/settings.local.json`,`/etc/claude-code/managed-settings.json`];return yield*ke(t)}),ke=S(`loadSettingsWithPaths`)(function*(e){let t=[];for(let n of e){let e=yield*De(n);e!==null&&t.push(e)}return t.length===0?null:_e(t)}),Z=S(`runHookScript`)(function*(e,t,n,r){let i=yield*le,{cmd:a,args:o}=Ee(e,n),s=JSON.stringify(t),c=ae(a,...o).pipe(se(n),oe({OMP_PROJECT_DIR:n,CLAUDE_PROJECT_DIR:n}),ce(s),ie(`pipe`),ue(`pipe`));return yield*E(_(function*(){let e=yield*i.start(c),t=yield*e.stdout.pipe(D(),O),n=yield*e.stderr.pipe(D(),O),r=yield*e.exitCode;return{code:typeof r==`number`?r:Number(r),stdout:t,stderr:n}})).pipe(l(r),ne(`TimeoutException`,()=>C({code:-1,stdout:``,stderr:`timeout after ${r}ms`})))}),Q=S(`runHooksForEvent`)(function*(e,t,n,i,a){let o=i.cwd,s,c=!1,l=n;for(let n of e)if(F(t,n.matcher))for(let e of n.hooks){let t=(e.timeout??10)*1e3;if(e.async){yield*j(Z(e.command,l,o,t));continue}let n=u(u(p(Te(yield*Z(e.command,l,o,t),a),{onLeft:e=>u(e).pipe(b(`HookVerdictError`,e=>new V({message:`Hook exited 0 but produced invalid JSON: ${e.raw.slice(0,200)}`})),N),onRight:e=>e})).pipe(b(`Block`,e=>new H({reason:e.reason})),b(`Warning`,e=>new U({warning:e.message})),b(`Allow`,e=>new U({updatedInput:e.updatedInput})),N)).pipe(b(`Blocked`,e=>r({block:!0,reason:e.reason})),b(`Continue`,e=>(e.warning!==void 0&&s===void 0&&(s=e.warning),e.updatedInput!==void 0&&(l={...l,...e.updatedInput},c=!0),g())),N);if(te(n))return n.value}return{...c?{updatedInput:l}:{},...s===void 0?{}:{warning:s}}}),Ae=S(`runPreToolUseHooks`)(function*(e,t,n){if(K(e))return;let r=I(t.toolName),i=L(()=>n.sessionManager.getSessionId()),a={...i,tool_name:r,tool_input:P(r,t.input),tool_call_id:t.toolCallId},o=fe(t.toolName,t.input);if(o!==void 0&&o.length>0){let r={...i,tool_name:`Bash`,tool_input:{command:o},tool_call_id:t.toolCallId},a=yield*Q(e.hooks.PreToolUse,`Bash`,r,n,`PreToolUse`);if(a.block)return a.reason===void 0?{block:!0}:{block:!0,reason:a.reason}}let s=yield*Q(e.hooks.PreToolUse,r,a,n,`PreToolUse`);if(s.block)return s.reason===void 0?{block:!0}:{block:!0,reason:s.reason};if(s.updatedInput&&typeof s.updatedInput==`object`&&`tool_input`in s.updatedInput&&s.updatedInput.tool_input&&typeof s.updatedInput.tool_input==`object`){let e=s.updatedInput.tool_input;for(let[n,r]of Object.entries(e))t.input[n]=r}}),$=S(`runPostToolUseHooks`)(function*(e,t,n){let r=I(t.toolName);if(K(e))return;let i={...L(()=>n.sessionManager.getSessionId()),tool_name:r,tool_input:P(r,t.input),tool_call_id:t.toolCallId,output:t.content,is_error:t.isError??!1};return yield*Q(e.hooks.PostToolUse,r,i,n,`PostToolUse`)}),je=S(`runUserPromptSubmitHooks`)(function*(e,t,n){let r=e.hooks.UserPromptSubmit;if(K(e)||r.length===0)return;let i=n.cwd,a=``,o={...L(()=>n.sessionManager.getSessionId()),prompt:t.text,source:t.source};for(let e of r)for(let t of e.hooks){let e=yield*Z(t.command,o,i,(t.timeout??10)*1e3);if(e.code!==0)continue;let n=e.stdout.trim();n.length>0&&(a+=(a.length>0?`
|
|
2
|
+
|
|
3
|
+
`:``)+n)}if(a.length===0)return;let s={text:`${a}\n\n${t.text}`};return t.images!==void 0&&(s.images=t.images),s}),Me=S(`runSessionStartHooks`)(function*(e,t,n){if(K(e))return;let r=e.hooks.SessionStart;if(r.length===0)return;let i=n.cwd,a={...L(()=>n.sessionManager.getSessionId()),reason:t};for(let e of r)if(!(e.matcher&&!F(t,e.matcher)))for(let t of e.hooks){let e=(t.timeout??10)*1e3;if(t.async){yield*j(Z(t.command,a,i,e));continue}yield*Z(t.command,a,i,e)}}),Ne=S(`runLifecycleHooks`)(function*(e,t){if(e.length===0)return;let n=t.cwd,r={...L(()=>t.sessionManager.getSessionId())};for(let t of e)for(let e of t.hooks){let t=(e.timeout??10)*1e3;e.async?yield*j(Z(e.command,r,n,t)):yield*Z(e.command,r,n,t)}});export{Oe as loadSettings,Ne as runLifecycleHooks,$ as runPostToolUseHooks,Ae as runPreToolUseHooks,Me as runSessionStartHooks,je as runUserPromptSubmitHooks};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,t)=>{e(e=>{e.setTimeout(()=>{t()},0)});let n=()=>{t().then(({default:e})=>e.dispose())};process.on(`SIGINT`,n),process.on(`SIGTERM`,n)},t=e=>{let t=async e=>{let[t,n]=await Promise.all([import(`./runtime-D3PIHvF6.js`).then(e=>e.default),import(`./esm-DxC3o46t.js`)]),{Cause:r,Effect:i,Exit:a}=n,o=e.pipe(i.exit),s=await t.runPromise(o);if(a.isFailure(s))throw r.squash(s.cause);return s.value};e.on(`tool_call`,async(e,n)=>{let{loadSettings:r,runPreToolUseHooks:i}=await import(`./hook-dispatcher.executor-
|
|
1
|
+
const e=(e,t)=>{e(e=>{e.setTimeout(()=>{t()},0)});let n=()=>{t().then(({default:e})=>e.dispose())};process.on(`SIGINT`,n),process.on(`SIGTERM`,n)},t=e=>{let t=async e=>{let[t,n]=await Promise.all([import(`./runtime-D3PIHvF6.js`).then(e=>e.default),import(`./esm-DxC3o46t.js`)]),{Cause:r,Effect:i,Exit:a}=n,o=e.pipe(i.exit),s=await t.runPromise(o);if(a.isFailure(s))throw r.squash(s.cause);return s.value};e.on(`tool_call`,async(e,n)=>{let{loadSettings:r,runPreToolUseHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let t=yield*r(n.cwd);if(t)return yield*i(t,e,n)}))}),e.on(`tool_result`,async(e,n)=>{let{loadSettings:r,runPostToolUseHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let t=yield*r(n.cwd);if(!t)return;let a=yield*i(t,e,n);if(a?.block)return{isError:!0,content:[{type:`text`,text:a.reason??`Blocked by PostToolUse hook`}]};if(a?.warning)return{content:[...e.content??[],{type:`text`,text:a.warning}],isError:e.isError}}))}),e.on(`input`,async(e,n)=>{let{loadSettings:r,runUserPromptSubmitHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let t=yield*r(n.cwd);if(t)return yield*i(t,e,n)}))}),e.on(`session_start`,async(e,n)=>{let{loadSettings:r,runSessionStartHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let e=yield*r(n.cwd);e&&(yield*i(e,`start`,n))}))}),e.on(`session_compact`,async(e,n)=>{let{loadSettings:r,runSessionStartHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let e=yield*r(n.cwd);e&&(yield*i(e,`compact`,n))}))}),e.on(`agent_start`,async(e,n)=>{let{loadSettings:r,runSessionStartHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let e=yield*r(n.cwd);e&&(yield*i(e,`resume`,n))}))}),e.on(`session_shutdown`,async(e,n)=>{let{loadSettings:r,runLifecycleHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let e=yield*r(n.cwd);e&&(e.disableAllHooks||(yield*i(e.hooks.SessionEnd,n)))}))}),e.on(`session_stop`,async(e,n)=>{let{loadSettings:r,runLifecycleHooks:i}=await import(`./hook-dispatcher.executor-ZArVQNkp.js`),{Effect:a}=await import(`./esm-DxC3o46t.js`);return t(a.gen(function*(){let e=yield*r(n.cwd);e&&(e.disableAllHooks||(yield*i(e.hooks.Stop,n)))}))})},n=e=>{e.on(`before_agent_start`,async(e,t)=>{let n=await import(`./runtime-D3PIHvF6.js`).then(e=>e.default),{loadReferencedContent:r}=await import(`./inject-instructions.executor-CcZyWYa6.js`),{Cause:i,Config:a,Effect:o,Exit:s}=await import(`./esm-DxC3o46t.js`),c=await n.runPromise(o.gen(function*(){let e=yield*a.string(`CLAUDE_PROJECT_DIR`).pipe(a.withDefault(process.cwd()));return yield*r(e)}).pipe(o.exit));if(s.isFailure(c))throw i.squash(c.cause);let l=c.value;if(l!==``)return{systemPrompt:[...e.systemPrompt,``,l]}})};function r(r){t(r),n(r),e(e=>r.on(`session_start`,(t,n)=>e(n)),()=>import(`./runtime-D3PIHvF6.js`))}export{r as default};
|
package/dist/{inject-instructions.executor-BdtS86PG.js → inject-instructions.executor-CcZyWYa6.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{Cn as e,D as t,E as n,H as r,Sn as i,T as a,Tn as o,V as s,bn as c,bt as l,gt as u,jt as d,pt as f,vn as p,wn as m,y as h,z as g}from"./esm-DxC3o46t.js";import{c as _,d as v,t as y}from"./dist-DQtXO3Ic.js";const b=[`AGENTS.md`];var x=class extends t()(`Inject`,{}){},S=class extends t()(`Skip`,{matched:a}){};n({
|
|
2
|
-
`)){let e=s.trim().replace(/^[-*+]\s+/,``);if(!e.startsWith(`@`))continue;let c=e.slice(1).trim();if(!c||c.includes(` `)||i.isAbsolute(c))continue;let l=i.resolve(t,c);if(l.startsWith(n+`/`)||l===n){let e=yield*u(r.exists(l));if(o(e)&&e.right){a.push({sourcePath:t,resolvedPath:l});continue}}let d=i.resolve(n,c);(d.startsWith(n+`/`)||d===n)&&d!==l&&a.push({sourcePath:n,resolvedPath:d})}return a}),E=l(`loadReferencedContent`)(function*(t){let n=yield*v,a=yield*_,l=yield*y,p=[a.resolve(t,`CLAUDE.md`),a.resolve(t,`.claude`,`CLAUDE.md`)],h=[];for(let e of p){let r=yield*u(n.readFileString(e,`utf-8`));if(o(r)){let n=yield*T(r.right,a.dirname(e),t);h.push(...n)}}let x=new Set,S=[];for(let e of h)x.has(e.resolvedPath)||(x.add(e.resolvedPath),S.push(e));let C=(yield*l.load(t).pipe(f(()=>d(void 0))))?.no_inject_refs??b,E=[];for(let
|
|
1
|
+
import{Cn as e,D as t,E as n,H as r,Sn as i,T as a,Tn as o,V as s,bn as c,bt as l,gt as u,jt as d,pt as f,vn as p,wn as m,y as h,z as g}from"./esm-DxC3o46t.js";import{c as _,d as v,t as y}from"./dist-DQtXO3Ic.js";const b=[`AGENTS.md`];var x=class extends t()(`Inject`,{}){},S=class extends t()(`Skip`,{matched:a}){};n({relativePath:a,skipList:h(a)});const C=e=>p(e.skipList.find(t=>t===e.relativePath)),w=e=>r(C(e)).pipe(s(`None`,()=>new x),s(`Some`,e=>new S({matched:e.value})),g),T=l(`extractRefs`)(function*(e,t,n){let r=yield*v,i=yield*_,a=[];for(let s of e.split(`
|
|
2
|
+
`)){let e=s.trim().replace(/^[-*+]\s+/,``);if(!e.startsWith(`@`))continue;let c=e.slice(1).trim();if(!c||c.includes(` `)||i.isAbsolute(c))continue;let l=i.resolve(t,c);if(l.startsWith(n+`/`)||l===n){let e=yield*u(r.exists(l));if(o(e)&&e.right){a.push({sourcePath:t,resolvedPath:l});continue}}let d=i.resolve(n,c);(d.startsWith(n+`/`)||d===n)&&d!==l&&a.push({sourcePath:n,resolvedPath:d})}return a}),E=l(`loadReferencedContent`)(function*(t){let n=yield*v,a=yield*_,l=yield*y,p=[a.resolve(t,`CLAUDE.md`),a.resolve(t,`.claude`,`CLAUDE.md`)],h=[];for(let e of p){let r=yield*u(n.readFileString(e,`utf-8`));if(o(r)){let n=yield*T(r.right,a.dirname(e),t);h.push(...n)}}let x=new Set,S=[];for(let e of h)x.has(e.resolvedPath)||(x.add(e.resolvedPath),S.push(e));let C=(yield*l.load(t).pipe(f(()=>d(void 0))))?.no_inject_refs??b,E=[];for(let a of S){let o=a.resolvedPath.slice(t.length+1);if(c(r(w({relativePath:o,skipList:C})).pipe(s(`Skip`,t=>e(t.matched)),s(`Inject`,()=>i()),g)))continue;let l=yield*u(n.readFileString(a.resolvedPath,`utf-8`));m(l)||E.push(`## ${o}\n${l.right}\n`)}return E.length===0?``:[`# Injected @-references from CLAUDE.md`,`The following files were @-imported by CLAUDE.md and contain project rules.`,``,...E].join(`
|
|
3
3
|
`)});export{E as loadReferencedContent};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/omp-claude-compat",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"description": "OMP Claude Code compatibility: dispatch .claude/settings.json hooks + inject CLAUDE.md @-references",
|
|
7
7
|
"type": "module",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"tsdown": "^0.22.9",
|
|
31
31
|
"typescript": "^7",
|
|
32
32
|
"vitest": "^4",
|
|
33
|
-
"@systemfsoftware/effect-gherkin-spec": "^0.
|
|
33
|
+
"@systemfsoftware/effect-gherkin-spec": "^0.4.0",
|
|
34
34
|
"@systemfsoftware/effect-memfs": "^1.0.7",
|
|
35
|
-
"@systemfsoftware/
|
|
35
|
+
"@systemfsoftware/omp-utils": "^0.0.0",
|
|
36
36
|
"@systemfsoftware/oxlint-config": "^0.1.0",
|
|
37
|
-
"@systemfsoftware/
|
|
37
|
+
"@systemfsoftware/tsconfig": "^1.2.6"
|
|
38
38
|
},
|
|
39
39
|
"omp": {
|
|
40
40
|
"extensions": [
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{A as e,B as t,C as n,Cn as r,D as i,Dn as a,E as o,En as s,F as c,Ft as l,H as u,I as d,N as f,O as p,On as m,P as h,S as ee,Sn as te,St as ne,T as g,Tn as _,U as v,V as y,b,bn as x,bt as S,jt as C,k as w,kn as T,kt as re,mt as ie,pt as ae,r as E,s as D,w as O,wn as k,xt as A,y as j,z as M}from"./esm-DxC3o46t.js";import{f as oe,l as se,o as ce,p as le,s as ue,t as de,u as fe}from"./CommandExecutor-B_nJZc9B.js";import{a as N,d as pe,i as P,o as F,r as I,s as L}from"./dist-DQtXO3Ic.js";import{homedir as R}from"node:os";o({code:n,stdout:g,stderr:g});var z=class extends i()(`Block`,{reason:g}){},B=class extends i()(`Allow`,{}){},V=class extends i()(`Warning`,{message:g}){};w(z,B,V);var H=class extends i()(`Blocked`,{reason:g}){},U=class extends i()(`Continue`,{warning:h(g),updatedInput:h(O({key:g,value:e}))}){};w(H,U);const W=f(d(o({decision:h(g),reason:h(g),hookSpecificOutput:h(o({permissionDecision:h(g),permissionDecisionReason:h(g),updatedInput:h(O({key:g,value:e}))}))}))),me=o({type:ee(`command`),command:g,async:h(b),timeout:h(n)}),G=o({matcher:h(g),hooks:j(me)}),K=o({PreToolUse:c(j(G),{exact:!0,default:()=>[]}),PostToolUse:c(j(G),{exact:!0,default:()=>[]}),UserPromptSubmit:c(j(G),{exact:!0,default:()=>[]}),Stop:c(j(G),{exact:!0,default:()=>[]}),SessionStart:c(j(G),{exact:!0,default:()=>[]}),SessionEnd:c(j(G),{exact:!0,default:()=>[]})}),he=f(w(o({hooks:K,disableAllHooks:h(b)}),o({...K.fields,disableAllHooks:h(b)})));function ge(e){return a(he(e),e=>{if(`hooks`in e)return e;let{disableAllHooks:t,...n}=e;return{hooks:n,disableAllHooks:t}})}const _e=[`PreToolUse`,`PostToolUse`,`UserPromptSubmit`,`SessionStart`,`SessionEnd`,`Stop`];function ve(e){let t={hooks:{PreToolUse:[],PostToolUse:[],UserPromptSubmit:[],SessionStart:[],SessionEnd:[],Stop:[]}};for(let n of e){for(let e of _e)t.hooks[e]=(t.hooks[e]??[]).concat(Array.from(n.hooks[e]));n.disableAllHooks!==void 0&&(t.disableAllHooks=n.disableAllHooks)}return t}function q(e){return e.disableAllHooks===!0}var ye=class extends p()(`HookVerdictError`,{raw:g}){},J=class extends i()(`ExitBlock`,{}){},Y=class extends i()(`ExitParse`,{}){},X=class extends i()(`ExitOther`,{}){};w(J,Y,X);const be=e=>u(e).pipe(v(2,()=>new J({})),v(0,()=>new Y({})),t(()=>new X({}))),xe=(e,n)=>u(e.trim()).pipe(v(``,()=>`Blocked by ${n} hook`),t(e=>e)),Se=(e,n)=>u(e.hookSpecificOutput?.permissionDecision??e.decision).pipe(v(`deny`,()=>new z({reason:e.hookSpecificOutput?.permissionDecisionReason??`Blocked by ${n} hook`})),v(`block`,()=>new z({reason:e.reason??`Blocked by ${n} hook`})),t(()=>new B({}))),Ce=e=>u(e.trim()).pipe(v(``,()=>new B({})),t(e=>new V({message:e}))),we=(e,t)=>u(be(e.code)).pipe(y(`ExitBlock`,()=>T(new z({reason:xe(e.stderr,t)}))),y(`ExitParse`,()=>m(W(e.stdout),{onLeft:()=>s(new ye({raw:e.stdout})),onRight:e=>T(Se(e,t))})),y(`ExitOther`,()=>T(Ce(e.stderr))),M);function Te(e,t){let n=e.replace(/"\$OMP_PROJECT_DIR"|'\$OMP_PROJECT_DIR'/g,JSON.stringify(t)).replace(/"\$\{OMP_PROJECT_DIR\}"|'\$\{OMP_PROJECT_DIR\}'/g,JSON.stringify(t)).replace(/"\$CLAUDE_PROJECT_DIR"|'\$CLAUDE_PROJECT_DIR'/g,JSON.stringify(t)).replace(/"\$\{CLAUDE_PROJECT_DIR\}"|'\$\{CLAUDE_PROJECT_DIR\}'/g,JSON.stringify(t)).replace(/\$OMP_PROJECT_DIR|\$\{OMP_PROJECT_DIR\}/g,JSON.stringify(t)).replace(/\$CLAUDE_PROJECT_DIR|\$\{CLAUDE_PROJECT_DIR\}/g,JSON.stringify(t)).trim();return{cmd:`sh`,args:[`-c`,n.startsWith(`"`)&&n.endsWith(`"`)?n.slice(1,-1):n]}}const Z=S(`loadSettingsFile`)(function*(t){let n=yield*(yield*pe).readFileString(t).pipe(ae(()=>C(``)));if(n===``)return null;let r=f(d(O({key:g,value:e})))(n);if(k(r))return null;let i=r.right,a=ge(i);return k(a)?null:a.right}),Ee=S(`loadSettings`)(function*(e){let t=[`${R()}/.claude/settings.json`,`${e}/.claude/settings.json`,`${e}/.claude/settings.local.json`,`/etc/claude-code/managed-settings.json`];return yield*De(t)}),De=S(`loadSettingsWithPaths`)(function*(e){let t=[];for(let n of e){let e=yield*Z(n);e!==null&&t.push(e)}return t.length===0?null:ve(t)}),Q=S(`runHookScript`)(function*(e,t,n,r){let i=yield*de,{cmd:a,args:o}=Te(e,n),s=JSON.stringify(t),c=se(a,...o).pipe(le(n),ce({OMP_PROJECT_DIR:n,CLAUDE_PROJECT_DIR:n}),ue(s),oe(`pipe`),fe(`pipe`));return yield*re(ne(function*(){let e=yield*i.start(c),t=yield*e.stdout.pipe(E(),D),n=yield*e.stderr.pipe(E(),D),r=yield*e.exitCode;return{code:typeof r==`number`?r:Number(r),stdout:t,stderr:n}})).pipe(l(r),ie(`TimeoutException`,()=>C({code:-1,stdout:``,stderr:`timeout after ${r}ms`})))}),$=S(`runHooksForEvent`)(function*(e,t,n,i,a){let o=i.cwd,s,c=!1,l=n;for(let n of e)if(P(t,n.matcher))for(let e of n.hooks){let t=(e.timeout??10)*1e3;if(e.async){yield*A(Q(e.command,l,o,t));continue}let n=yield*Q(e.command,l,o,t),i=u(u(m(we(n,a),{onLeft:e=>u(e).pipe(y(`HookVerdictError`,e=>new V({message:`Hook exited 0 but produced invalid JSON: ${e.raw.slice(0,200)}`})),M),onRight:e=>e})).pipe(y(`Block`,e=>new H({reason:e.reason})),y(`Warning`,e=>new U({warning:e.message})),y(`Allow`,()=>{let e=W(n.stdout);return new U({updatedInput:_(e)?e.right.hookSpecificOutput?.updatedInput:void 0})}),M)).pipe(y(`Blocked`,e=>r({block:!0,reason:e.reason})),y(`Continue`,e=>(e.warning!==void 0&&s===void 0&&(s=e.warning),e.updatedInput!==void 0&&(l={...l,...e.updatedInput},c=!0),te())),M);if(x(i))return i.value}return{...c?{updatedInput:l}:{},...s===void 0?{}:{warning:s}}}),Oe=S(`runPreToolUseHooks`)(function*(e,t,n){if(q(e))return;let r=F(t.toolName),i=L(()=>n.sessionManager.getSessionId()),a={...i,tool_name:r,tool_input:N(r,t.input),tool_call_id:t.toolCallId},o=I(t.toolName,t.input);if(o!==void 0&&o.length>0){let r={...i,tool_name:`Bash`,tool_input:{command:o},tool_call_id:t.toolCallId},a=yield*$(e.hooks.PreToolUse,`Bash`,r,n,`PreToolUse`);if(a.block)return a.reason===void 0?{block:!0}:{block:!0,reason:a.reason}}let s=yield*$(e.hooks.PreToolUse,r,a,n,`PreToolUse`);if(s.block)return s.reason===void 0?{block:!0}:{block:!0,reason:s.reason};if(s.updatedInput&&typeof s.updatedInput==`object`&&`tool_input`in s.updatedInput&&s.updatedInput.tool_input&&typeof s.updatedInput.tool_input==`object`){let e=s.updatedInput.tool_input;for(let[n,r]of Object.entries(e))t.input[n]=r}}),ke=S(`runPostToolUseHooks`)(function*(e,t,n){let r=F(t.toolName);if(q(e))return;let i={...L(()=>n.sessionManager.getSessionId()),tool_name:r,tool_input:N(r,t.input),tool_call_id:t.toolCallId,output:t.content,is_error:t.isError??!1};return yield*$(e.hooks.PostToolUse,r,i,n,`PostToolUse`)}),Ae=S(`runUserPromptSubmitHooks`)(function*(e,t,n){let r=e.hooks.UserPromptSubmit;if(q(e)||r.length===0)return;let i=n.cwd,a=``,o={...L(()=>n.sessionManager.getSessionId()),prompt:t.text,source:t.source};for(let e of r)for(let t of e.hooks){let e=yield*Q(t.command,o,i,(t.timeout??10)*1e3);if(e.code!==0)continue;let n=e.stdout.trim();n.length>0&&(a+=(a.length>0?`
|
|
2
|
-
|
|
3
|
-
`:``)+n)}if(a.length===0)return;let s={text:`${a}\n\n${t.text}`};return t.images!==void 0&&(s.images=t.images),s}),je=S(`runSessionStartHooks`)(function*(e,t,n){if(q(e))return;let r=e.hooks.SessionStart;if(r.length===0)return;let i=n.cwd,a={...L(()=>n.sessionManager.getSessionId()),reason:t};for(let e of r)if(!(e.matcher&&!P(t,e.matcher)))for(let t of e.hooks){let e=(t.timeout??10)*1e3;if(t.async){yield*A(Q(t.command,a,i,e));continue}yield*Q(t.command,a,i,e)}}),Me=S(`runLifecycleHooks`)(function*(e,t){if(e.length===0)return;let n=t.cwd,r={...L(()=>t.sessionManager.getSessionId())};for(let t of e)for(let e of t.hooks){let t=(e.timeout??10)*1e3;e.async?yield*A(Q(e.command,r,n,t)):yield*Q(e.command,r,n,t)}});export{Ee as loadSettings,Me as runLifecycleHooks,ke as runPostToolUseHooks,Oe as runPreToolUseHooks,je as runSessionStartHooks,Ae as runUserPromptSubmitHooks};
|