@aaac/runtime 0.2.5 → 0.2.6

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.
Files changed (42) hide show
  1. package/dist/adapters/adk-sdk.d.ts +1 -1
  2. package/dist/adapters/adk-sdk.js +1 -1
  3. package/dist/adapters/claude-agent-sdk.d.ts +1 -1
  4. package/dist/adapters/claude-agent-sdk.js +4 -1
  5. package/dist/adapters/claude-agent-sdk.js.map +1 -1
  6. package/dist/adapters/openai-agents-sdk.d.ts +1 -1
  7. package/dist/adapters/openai-agents-sdk.js +1 -1
  8. package/dist/{chunk-3DDB34BU.js → chunk-D2UXESPT.js} +2 -2
  9. package/dist/chunk-D2UXESPT.js.map +1 -0
  10. package/dist/{chunk-MG2ULUX6.js → chunk-DEBCJKRX.js} +2 -2
  11. package/dist/{chunk-2INQL5TG.js → chunk-GWNXNSGL.js} +6 -5
  12. package/dist/chunk-GWNXNSGL.js.map +1 -0
  13. package/dist/{chunk-MSVIEEGR.js → chunk-HR2Q64AO.js} +29 -5
  14. package/dist/chunk-HR2Q64AO.js.map +1 -0
  15. package/dist/{chunk-FKAI54OM.js → chunk-QVMLALPF.js} +2 -2
  16. package/dist/{chunk-F5R46S7I.js → chunk-Y7NORFFM.js} +2 -2
  17. package/dist/claude-bundles/full.js +134 -133
  18. package/dist/claude-bundles/lean.js +5 -4
  19. package/dist/generator/index.d.ts +2 -2
  20. package/dist/generator/index.js +2 -2
  21. package/dist/{guardrail-hooks-CB23nhZV.d.ts → guardrail-hooks-B-qe4ebW.d.ts} +16 -3
  22. package/dist/{hook-protocol-CFnNudiV.d.ts → hook-protocol-BH86kCQB.d.ts} +2 -0
  23. package/dist/{hooks-lite-CoWWnCRH.d.ts → hooks-lite-DvZu9Jhx.d.ts} +2 -2
  24. package/dist/{index-BlSepCSZ.d.ts → index-C2DHitGz.d.ts} +9 -1
  25. package/dist/index.d.ts +5 -5
  26. package/dist/index.js +27 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/lib/claude-native/hooks-lite.d.ts +3 -3
  29. package/dist/lib/claude-native/hooks-lite.js +3 -3
  30. package/dist/lib/claude-native/hooks-prompt.d.ts +4 -4
  31. package/dist/lib/claude-native/hooks-prompt.js +3 -3
  32. package/dist/lib/claude-native/index.d.ts +7 -7
  33. package/dist/lib/claude-native/index.js +6 -6
  34. package/dist/{navigation-context-B-RpUg3_.d.ts → navigation-context-D1NbiipT.d.ts} +1 -1
  35. package/dist/{workspace-user-prompt-submit-D11Iu0zO.d.ts → workspace-user-prompt-submit-aErGPoX4.d.ts} +2 -2
  36. package/package.json +4 -4
  37. package/dist/chunk-2INQL5TG.js.map +0 -1
  38. package/dist/chunk-3DDB34BU.js.map +0 -1
  39. package/dist/chunk-MSVIEEGR.js.map +0 -1
  40. /package/dist/{chunk-MG2ULUX6.js.map → chunk-DEBCJKRX.js.map} +0 -0
  41. /package/dist/{chunk-FKAI54OM.js.map → chunk-QVMLALPF.js.map} +0 -0
  42. /package/dist/{chunk-F5R46S7I.js.map → chunk-Y7NORFFM.js.map} +0 -0
@@ -1,6 +1,7 @@
1
1
  import { createRequire as __aaacCreateRequire } from 'node:module';
2
2
  const require = __aaacCreateRequire(import.meta.url);
3
- var V=["block","warn","shadow","info","unresolved"],K="unresolved";function w(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.guardrail_id=="string"&&typeof t.pattern=="string"&&V.includes(t.action)&&typeof t.message=="string"&&(t.file_glob===void 0||typeof t.file_glob=="string")&&(t.exclude_glob===void 0||typeof t.exclude_glob=="string")}function I(e){if(typeof e!="object"||e===null)return!1;let t=e;return Array.isArray(t.commandRules)&&t.commandRules.every(w)&&Array.isArray(t.fileRules)&&t.fileRules.every(w)&&Array.isArray(t.contentRules)&&t.contentRules.every(w)}function J(e){let t="";for(let r of e)r==="*"?t+="[^/]*":r==="?"?t+="[^/]":".+^$|()[]\\".includes(r)?t+="\\"+r:t+=r;return t}function Y(e){return e.endsWith("/")?`${e}**`:e}function h(e,t){let r=Y(e),n="",a=0;for(;a<r.length;)if(r[a]==="*"&&r[a+1]==="*"&&r[a+2]==="/")n+="(?:.+/)?",a+=3;else if(r[a]==="*"&&r[a+1]==="*")n+=".*",a+=2;else if(r[a]==="*")n+="[^/]*",a+=1;else if(r[a]==="?")n+="[^/]",a+=1;else if(r[a]==="{"){let o=r.indexOf("}",a);if(o!==-1){let i=r.slice(a+1,o).split(",").map(J);n+="(?:"+i.join("|")+")",a=o+1}else n+="\\{",a+=1}else".+^$|()[]\\".includes(r[a])?(n+="\\"+r[a],a+=1):(n+=r[a],a+=1);return new RegExp("^"+n+"$").test(t)}function z(e){return e==="path"||e==="file"||e==="filename"||e.endsWith("_path")}function X(e){return e==="content"||e.startsWith("new_")}function $(e,t){if(!e)return"";for(let r of Object.keys(e).sort()){if(!t(r))continue;let n=e[r];if(typeof n=="string"&&n)return n}return""}function Q(e){return $(e,z)}var Z=new Set(["Read","Glob","Grep","LSP","Task","Agent","Skill","WebFetch","WebSearch","TodoWrite","AskUserQuestion","ToolSearch","EnterPlanMode","ExitPlanMode"]);function k(e,t){return Z.has(e??"")?"":Q(t)}function v(e){return $(e,X)}function ee(e){return e==="block"||e===K}function F(e){return e.filter(t=>!t.passed&&ee(t.action))}function te(e){return e.filter(t=>!t.passed&&t.action==="warn")}function j(e){return e.map(t=>`[${t.guardrail_id}] ${t.message}`).join(`
4
- `)}function D(e){let t=j(e);return{permission:"deny",user_message:t,agent_message:t}}function re(...e){function t(i){let c=[];if(i.command)for(let s of e)c.push(...s.checkCommand(i.command));if(i.filePath)for(let s of e)c.push(...s.checkFilePath(i.filePath));if(i.filePath&&i.content)for(let s of e)c.push(...s.checkContent(i.filePath,i.content));return c}function r(i){let c=i.command??"";if(!c)return{};let s=t({command:c}),u=F(s),f=te(s);return u.length>0?D(u):f.length>0?{additionalContext:j(f)}:{}}function n(i,c){if(!i)return{};let s=F(t({filePath:i,content:c}));return s.length>0?D(s):{}}function a(i){return n(k(i.tool_name,i.tool_input),v(i.tool_input))}function o(i){return n(i.file_path??"",i.content??"")}return{beforeShellExecution:r,preToolUse:a,afterFileEdit:o,runChecks:t}}function N(e){return e.startsWith("(?i)")?new RegExp(e.slice(4),"i"):new RegExp(e)}function P(e,...t){let r=e.commandRules.map(o=>({guardrail_id:o.guardrail_id,pattern:N(o.pattern),action:o.action,message:o.message})),n=e.fileRules,a=e.contentRules.map(o=>({guardrail_id:o.guardrail_id,pattern:N(o.pattern),action:o.action,message:o.message,file_glob:o.file_glob,exclude_glob:o.exclude_glob}));return re({checkCommand(o){let i=[];for(let c of r){let s=!c.pattern.test(o);i.push({guardrail_id:c.guardrail_id,passed:s,action:c.action,message:s?"":c.message})}return i},checkFilePath(o){let i=[];for(let c of n){if(c.exclude_glob&&h(c.exclude_glob,o))continue;let s=h(c.pattern,o);i.push({guardrail_id:c.guardrail_id,passed:!s,action:c.action,message:s?c.message:""})}return i},checkContent(o,i){let c=[];for(let s of a){if(s.file_glob&&!h(s.file_glob,o)||s.exclude_glob&&h(s.exclude_glob,o))continue;let u=s.pattern.test(i);c.push({guardrail_id:s.guardrail_id,passed:!u,action:s.action,message:u?s.message:""})}return c}},...t)}import{readFile as le,writeFile as U,rename as fe,stat as de,mkdir as pe}from"fs/promises";import{join as me}from"path";import{randomBytes as he}from"crypto";import{stat as _e}from"fs/promises";var ne=["SessionStart","UserPromptSubmit","PreToolUse"],A=e=>new Error(`Not a hook payload: ${e.slice(0,100)}`),m=e=>e===void 0||typeof e=="string";function oe(e){if(e===void 0)return!0;if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e;return m(t.file_path)&&m(t.path)&&m(t.command)&&m(t.content)}function ie(e){if(!m(e.session_id))return!1;switch(e.hookEventName){case"SessionStart":return e.type===void 0||typeof e.type=="string"&&["new","resume","clear","compact"].includes(e.type);case"UserPromptSubmit":return m(e.prompt);case"PreToolUse":return m(e.tool_name)&&oe(e.tool_input);default:return!1}}function ae(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw A(e);let r=t;if(typeof r.hook_event_name=="string"&&r.hookEventName===void 0&&(r.hookEventName=r.hook_event_name),!ne.includes(r.hookEventName)){if(typeof r.hookEventName=="string")return;throw A(e)}if(!ie(r))throw A(e);return r}async function se(){let e=[];for await(let r of process.stdin)e.push(Buffer.isBuffer(r)?r:Buffer.from(r));let t=Buffer.concat(e).toString("utf-8").trim();if(!t)throw new Error("Empty stdin \u2014 no hook input received");return ae(t)}function ce(e){process.stdout.write(JSON.stringify(e)+`
5
- `)}function ue(e,t){return{hookSpecificOutput:{hookEventName:e,additionalContext:t}}}function p(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}}function g(){return{}}var y=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ge(e,t){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let r=e;return typeof r.writtenAt=="string"&&typeof r.sourceHash=="string"&&(r.sourceFiles===void 0||Array.isArray(r.sourceFiles)&&r.sourceFiles.every(n=>typeof n=="string"))&&t(r.data)}function _(e){let{cacheDir:t}=e;function r(o){return me(t,`${o}.json`)}async function n(){await pe(t,{recursive:!0})}return{async read(o,i){let c;try{c=JSON.parse(await le(r(o),"utf-8"))}catch{return null}return ge(c,i)?c:null},async write(o,i,c,s){await n();let u={data:i,writtenAt:new Date().toISOString(),sourceHash:c,...s?{sourceFiles:s}:{}},f=JSON.stringify(u,null,2),d=r(o),l=`${d}.${he(4).toString("hex")}.tmp`;await U(l,f,"utf-8");try{await fe(l,d)}catch{await U(d,f,"utf-8")}},async getFileMtime(o){try{return(await de(o)).mtimeMs}catch{return null}}}}function ye(e){return e.map(String).join(":")}var be=".guardrails";function we(e){return`${e}${be}`}var H="navigation-index";async function ke(e){let t=[];for(let r of e)try{let n=await _e(r);t.push(n.mtimeMs)}catch{t.push(`missing:${r}`)}return ye(t)}async function S(e){let t=e.cacheKey??H,r=_({cacheDir:e.cacheDir}),n=await r.read(t,y);if(!n?.sourceFiles||await ke(n.sourceFiles)!==n.sourceHash)return;let o=await r.read(we(t),I);if(o?.sourceHash===n.sourceHash)return{navigationIndex:n.data,guardrailRules:o.data}}function R(e,t){let r=t.artifacts??{},n=[];for(let[a,o]of Object.entries(r)){let i=o?.files?.path_patterns;if(Array.isArray(i)){for(let c of i)if(typeof c=="string"&&h(c,e)){n.push({artifactId:a,artifact:o,matchedPattern:c});break}}}return n}function C(e){let t=e.artifact.properties??{};if(t.authority==="generated"){let r=e.artifact.routes?.regenerate,n=r?` Run '${r}' to regenerate.`:" Edit the source artifact and regenerate instead.";return{protected:!0,reason:`File belongs to generated artifact '${e.artifactId}'. Direct editing is not allowed.${n}`}}return t.manual_edit==="forbidden"?{protected:!0,reason:`File belongs to artifact '${e.artifactId}' which has manual_edit: forbidden. This artifact must not be edited directly.`}:{protected:!1,reason:""}}function x(e){let t=e.artifacts??{};return Object.entries(t).map(([r,n])=>({id:r,artifact:n}))}import{resolve as q}from"path";function E(e){return e.tool_input?.command!==void 0}function L(e){return k(e.tool_name,e.tool_input)}var ve={"navigation-index":"the artifact edit guard","guardrail-rules":"the DSL guardrails"};function b(e,t){let r=t?` for ${t}`:"";return`[guard-unavailable] ${ve[e]} cannot run: the \`${e}\` cache entry${r} is absent or was built from sources that have since changed, so this operation gets no verdict and is refused rather than judged by superseded rules or silently allowed. Run \`.claude/bin/ensure-navigation-index\` (SessionStart and every prompt submission do this automatically \u2014 if it keeps failing, that failure is the bug).`}function Pe(e){let t=e.guardrailRules?P(e.guardrailRules):null;return async function(n){let a=L(n);if(!t&&(E(n)||a))return p(b("guardrail-rules"));if(t){if(E(n)){let i=t.beforeShellExecution({command:n.tool_input?.command});if(i.permission==="deny")return p(i.user_message)}let o=t.preToolUse({tool_name:n.tool_name,tool_input:n.tool_input});if(o.permission==="deny")return p(o.user_message)}if(a){if(!e.navigationIndex)return p(b("navigation-index"));for(let o of R(a,e.navigationIndex)){let i=C(o);if(i.protected)return p(i.reason)}}return g()}}var G=100;function M(e,t){let{navigationIndex:r,maxCandidates:n=G}=t,a=x(r),o=[],i=e.toLowerCase(),c=s=>Ae(t.pathPrefix,s);for(let{id:s,artifact:u}of a){let f=u.properties??{},d=u.files?.path_patterns??[];(!e||s.toLowerCase().includes(i))&&o.push({label:s,path:c(d.length>0?String(d[0]):s),kind:"artifact",authority:f.authority,manual_edit:f.manual_edit,score:Se(s,u,e)});for(let l of d)typeof l=="string"&&(l.includes("*")||l.includes("?")||(!e||l.toLowerCase().includes(i))&&o.push({label:l,path:c(l),kind:"file",artifact:s,authority:f.authority,manual_edit:f.manual_edit,score:Re(l,e)}))}return o.sort((s,u)=>u.score!==s.score?u.score-s.score:s.label.localeCompare(u.label)),o.slice(0,n)}function Ae(e,t){if(!e)return t;let r=e.replace(/^\.\//,"").replace(/\/+$/,"");return r?`${r}/${t}`:t}function B(e){return e.map(t=>JSON.stringify(t)).join(`
6
- `)}function Se(e,t,r){let n=50,a=t.properties??{};return a.authority==="canonical"&&(n+=20),a.manual_edit==="allowed"&&(n+=10),a.type==="source"&&(n+=15),a.authority==="generated"&&(n-=20),a.manual_edit==="forbidden"&&(n-=10),r&&e.toLowerCase().startsWith(r.toLowerCase())&&(n+=20),n}function Re(e,t){let r=40;return t&&e.toLowerCase().startsWith(t.toLowerCase())&&(r+=30),r+=Math.max(0,20-e.split("/").length*2),r}async function Ce(e,t){let r=t.trim(),n=M(r,{navigationIndex:e});return B(n)}async function xe(e,t,r,n=G){let a=r.trim(),o=_({cacheDir:e}),i=[];for(let c of t){let s=await o.read(c.cacheKey,y);s&&i.push(...M(a,{navigationIndex:s.data,pathPrefix:c.memberPath,maxCandidates:Number.POSITIVE_INFINITY}))}return i.sort((c,s)=>s.score!==c.score?s.score-c.score:c.label.localeCompare(s.label)),B(i.slice(0,n))}function W(e,t,r){if(!e)return null;let n=e.startsWith("/")?e:q(r,e),a=null,o=0;for(let i of t){let c=i.root,s=c.endsWith("/")?c:c+"/";n.startsWith(s)&&s.length>o&&(a=i,o=s.length)}return a}function Ee(e,t,r){let n=e.startsWith("/")?e:q(r,e),a=t.endsWith("/")?t:t+"/";return n.startsWith(a)?n.slice(a.length):e}function Te(e){let t=[];for(let r of e.split(/\s+/)){let n=r.replace(/^['"]+|['"]+$/g,"");n&&(n.includes("/")||n.includes("\\"))&&t.push(n)}return t}function Oe(e){let t=new Map;async function r(a){if(t.has(a.name))return t.get(a.name);let o=await S({cacheDir:e.cacheDir,cacheKey:a.cacheKey}),i=o?{...o,hooks:P(o.guardrailRules)}:void 0;return t.set(a.name,i),i}function n(a){for(let o of Te(a)){let i=W(o,e.members,e.workspaceRoot);if(i)return[i]}return e.members}return async function(o){if(E(o)){let d=o.tool_input?.command??"";for(let l of n(d)){let T=await r(l);if(!T)return p(b("guardrail-rules",`member "${l.name}"`));let O=T.hooks.beforeShellExecution({command:d});if(O.permission==="deny")return p(O.user_message)}}let i=L(o);if(!i)return g();let c=W(i,e.members,e.workspaceRoot);if(!c)return g();let s=await r(c);if(!s)return p(b("navigation-index",`member "${c.name}"`));let u=Ee(i,c.root,e.workspaceRoot),f=s.hooks.afterFileEdit({file_path:u,content:v(o.tool_input)});if(f.permission==="deny")return p(f.user_message);for(let d of R(u,s.navigationIndex)){let l=C(d);if(l.protected)return p(l.reason)}return g()}}export{H as DEFAULT_CACHE_KEY,ue as buildContextResponse,_ as createCacheStore,Pe as createPreToolUseHandler,Oe as createWorkspacePreToolUseHandler,ce as emitHookOutput,Ce as handleFileSuggestion,xe as handleWorkspaceFileSuggestion,y as isCachedRecord,x as listArtifacts,S as readFreshNavigationBuild,se as readHookInput};
3
+ import{readFileSync as V,statSync as K}from"fs";import{resolve as J}from"path";var Y=/(?:^|\s)(?:--body-file|--notes-file|--file|-F)(?:=|\s+)(?:'([^']*)'|"([^"]*)"|([^\s;|&]+))/g;function z(e,t){let r=[];for(let n of e.matchAll(Y)){let a=n[1]??n[2]??n[3];if(!a||a==="-")continue;let o=J(t??process.cwd(),a);try{if(!K(o).isFile())continue;r.push(V(o,"utf8"))}catch{continue}}return r.length===0?e:[e,...r].join(`
4
+ `)}var X=["block","warn","shadow","info","unresolved"],Q="unresolved";function w(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.guardrail_id=="string"&&typeof t.pattern=="string"&&X.includes(t.action)&&typeof t.message=="string"&&(t.file_glob===void 0||typeof t.file_glob=="string")&&(t.exclude_glob===void 0||typeof t.exclude_glob=="string")}function I(e){if(typeof e!="object"||e===null)return!1;let t=e;return Array.isArray(t.commandRules)&&t.commandRules.every(w)&&Array.isArray(t.fileRules)&&t.fileRules.every(w)&&Array.isArray(t.contentRules)&&t.contentRules.every(w)}function Z(e){let t="";for(let r of e)r==="*"?t+="[^/]*":r==="?"?t+="[^/]":".+^$|()[]\\".includes(r)?t+="\\"+r:t+=r;return t}function ee(e){return e.endsWith("/")?`${e}**`:e}function h(e,t){let r=ee(e),n="",a=0;for(;a<r.length;)if(r[a]==="*"&&r[a+1]==="*"&&r[a+2]==="/")n+="(?:.+/)?",a+=3;else if(r[a]==="*"&&r[a+1]==="*")n+=".*",a+=2;else if(r[a]==="*")n+="[^/]*",a+=1;else if(r[a]==="?")n+="[^/]",a+=1;else if(r[a]==="{"){let o=r.indexOf("}",a);if(o!==-1){let c=r.slice(a+1,o).split(",").map(Z);n+="(?:"+c.join("|")+")",a=o+1}else n+="\\{",a+=1}else".+^$|()[]\\".includes(r[a])?(n+="\\"+r[a],a+=1):(n+=r[a],a+=1);return new RegExp("^"+n+"$").test(t)}function te(e){return e==="path"||e==="file"||e==="filename"||e.endsWith("_path")}function re(e){return e==="content"||e.startsWith("new_")}function $(e,t){if(!e)return"";for(let r of Object.keys(e).sort()){if(!t(r))continue;let n=e[r];if(typeof n=="string"&&n)return n}return""}function ne(e){return $(e,te)}var oe=new Set(["Read","Glob","Grep","LSP","Task","Agent","Skill","WebFetch","WebSearch","TodoWrite","AskUserQuestion","ToolSearch","EnterPlanMode","ExitPlanMode"]);function k(e,t){return oe.has(e??"")?"":ne(t)}function v(e){return $(e,re)}function ie(e){return e==="block"||e===Q}function O(e){return e.filter(t=>!t.passed&&ie(t.action))}function ae(e){return e.filter(t=>!t.passed&&t.action==="warn")}function j(e){return e.map(t=>`[${t.guardrail_id}] ${t.message}`).join(`
5
+ `)}function D(e){let t=j(e);return{permission:"deny",user_message:t,agent_message:t}}function se(...e){function t(i){let s=[];if(i.command)for(let u of e)s.push(...u.checkCommand(i.command));if(i.filePath)for(let u of e)s.push(...u.checkFilePath(i.filePath));if(i.filePath&&i.content)for(let u of e)s.push(...u.checkContent(i.filePath,i.content));return s}function r(i){let s=i.command??"";return s?t({command:z(s,i.cwd)}):[]}function n(i){let s=r(i);if(s.length===0)return{};let u=O(s),f=ae(s);return u.length>0?D(u):f.length>0?{additionalContext:j(f)}:{}}function a(i,s){if(!i)return{};let u=O(t({filePath:i,content:s}));return u.length>0?D(u):{}}function o(i){return a(k(i.tool_name,i.tool_input),v(i.tool_input))}function c(i){return a(i.file_path??"",i.content??"")}return{beforeShellExecution:n,checkShellCommand:r,preToolUse:o,afterFileEdit:c,runChecks:t}}function N(e){return e.startsWith("(?i)")?new RegExp(e.slice(4),"i"):new RegExp(e)}function P(e,...t){let r=e.commandRules.map(o=>({guardrail_id:o.guardrail_id,pattern:N(o.pattern),action:o.action,message:o.message})),n=e.fileRules,a=e.contentRules.map(o=>({guardrail_id:o.guardrail_id,pattern:N(o.pattern),action:o.action,message:o.message,file_glob:o.file_glob,exclude_glob:o.exclude_glob}));return se({checkCommand(o){let c=[];for(let i of r){let s=!i.pattern.test(o);c.push({guardrail_id:i.guardrail_id,passed:s,action:i.action,message:s?"":i.message})}return c},checkFilePath(o){let c=[];for(let i of n){if(i.exclude_glob&&h(i.exclude_glob,o))continue;let s=h(i.pattern,o);c.push({guardrail_id:i.guardrail_id,passed:!s,action:i.action,message:s?i.message:""})}return c},checkContent(o,c){let i=[];for(let s of a){if(s.file_glob&&!h(s.file_glob,o)||s.exclude_glob&&h(s.exclude_glob,o))continue;let u=s.pattern.test(c);i.push({guardrail_id:s.guardrail_id,passed:!u,action:s.action,message:u?s.message:""})}return i}},...t)}import{readFile as he,writeFile as U,rename as ge,stat as ye,mkdir as _e}from"fs/promises";import{join as be}from"path";import{randomBytes as we}from"crypto";import{stat as Pe}from"fs/promises";var ce=["SessionStart","UserPromptSubmit","PreToolUse"],S=e=>new Error(`Not a hook payload: ${e.slice(0,100)}`),m=e=>e===void 0||typeof e=="string";function ue(e){if(e===void 0)return!0;if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e;return m(t.file_path)&&m(t.path)&&m(t.command)&&m(t.content)}function le(e){if(!m(e.session_id))return!1;switch(e.hookEventName){case"SessionStart":return e.type===void 0||typeof e.type=="string"&&["new","resume","clear","compact"].includes(e.type);case"UserPromptSubmit":return m(e.prompt);case"PreToolUse":return m(e.tool_name)&&ue(e.tool_input);default:return!1}}function fe(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw S(e);let r=t;if(typeof r.hook_event_name=="string"&&r.hookEventName===void 0&&(r.hookEventName=r.hook_event_name),!ce.includes(r.hookEventName)){if(typeof r.hookEventName=="string")return;throw S(e)}if(!le(r))throw S(e);return r}async function de(){let e=[];for await(let r of process.stdin)e.push(Buffer.isBuffer(r)?r:Buffer.from(r));let t=Buffer.concat(e).toString("utf-8").trim();if(!t)throw new Error("Empty stdin \u2014 no hook input received");return fe(t)}function pe(e){process.stdout.write(JSON.stringify(e)+`
6
+ `)}function me(e,t){return{hookSpecificOutput:{hookEventName:e,additionalContext:t}}}function p(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}}function g(){return{}}var y=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ke(e,t){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let r=e;return typeof r.writtenAt=="string"&&typeof r.sourceHash=="string"&&(r.sourceFiles===void 0||Array.isArray(r.sourceFiles)&&r.sourceFiles.every(n=>typeof n=="string"))&&t(r.data)}function _(e){let{cacheDir:t}=e;function r(o){return be(t,`${o}.json`)}async function n(){await _e(t,{recursive:!0})}return{async read(o,c){let i;try{i=JSON.parse(await he(r(o),"utf-8"))}catch{return null}return ke(i,c)?i:null},async write(o,c,i,s){await n();let u={data:c,writtenAt:new Date().toISOString(),sourceHash:i,...s?{sourceFiles:s}:{}},f=JSON.stringify(u,null,2),d=r(o),l=`${d}.${we(4).toString("hex")}.tmp`;await U(l,f,"utf-8");try{await ge(l,d)}catch{await U(d,f,"utf-8")}},async getFileMtime(o){try{return(await ye(o)).mtimeMs}catch{return null}}}}function ve(e){return e.map(String).join(":")}var Se=".guardrails";function Ae(e){return`${e}${Se}`}var H="navigation-index";async function Ce(e){let t=[];for(let r of e)try{let n=await Pe(r);t.push(n.mtimeMs)}catch{t.push(`missing:${r}`)}return ve(t)}async function A(e){let t=e.cacheKey??H,r=_({cacheDir:e.cacheDir}),n=await r.read(t,y);if(!n?.sourceFiles||await Ce(n.sourceFiles)!==n.sourceHash)return;let o=await r.read(Ae(t),I);if(o?.sourceHash===n.sourceHash)return{navigationIndex:n.data,guardrailRules:o.data}}function C(e,t){let r=t.artifacts??{},n=[];for(let[a,o]of Object.entries(r)){let c=o?.files?.path_patterns;if(Array.isArray(c)){for(let i of c)if(typeof i=="string"&&h(i,e)){n.push({artifactId:a,artifact:o,matchedPattern:i});break}}}return n}function R(e){let t=e.artifact.properties??{};if(t.authority==="generated"){let r=e.artifact.routes?.regenerate,n=r?` Run '${r}' to regenerate.`:" Edit the source artifact and regenerate instead.";return{protected:!0,reason:`File belongs to generated artifact '${e.artifactId}'. Direct editing is not allowed.${n}`}}return t.manual_edit==="forbidden"?{protected:!0,reason:`File belongs to artifact '${e.artifactId}' which has manual_edit: forbidden. This artifact must not be edited directly.`}:{protected:!1,reason:""}}function x(e){let t=e.artifacts??{};return Object.entries(t).map(([r,n])=>({id:r,artifact:n}))}import{resolve as q}from"path";function E(e){return e.tool_input?.command!==void 0}function L(e){return k(e.tool_name,e.tool_input)}var Re={"navigation-index":"the artifact edit guard","guardrail-rules":"the DSL guardrails"};function b(e,t){let r=t?` for ${t}`:"";return`[guard-unavailable] ${Re[e]} cannot run: the \`${e}\` cache entry${r} is absent or was built from sources that have since changed, so this operation gets no verdict and is refused rather than judged by superseded rules or silently allowed. Run \`.claude/bin/ensure-navigation-index\` (SessionStart and every prompt submission do this automatically \u2014 if it keeps failing, that failure is the bug).`}function xe(e){let t=e.guardrailRules?P(e.guardrailRules):null;return async function(n){let a=L(n);if(!t&&(E(n)||a))return p(b("guardrail-rules"));if(t){if(E(n)){let c=t.beforeShellExecution({command:n.tool_input?.command,cwd:n.cwd});if(c.permission==="deny")return p(c.user_message)}let o=t.preToolUse({tool_name:n.tool_name,tool_input:n.tool_input});if(o.permission==="deny")return p(o.user_message)}if(a){if(!e.navigationIndex)return p(b("navigation-index"));for(let o of C(a,e.navigationIndex)){let c=R(o);if(c.protected)return p(c.reason)}}return g()}}var G=100;function M(e,t){let{navigationIndex:r,maxCandidates:n=G}=t,a=x(r),o=[],c=e.toLowerCase(),i=s=>Ee(t.pathPrefix,s);for(let{id:s,artifact:u}of a){let f=u.properties??{},d=u.files?.path_patterns??[];(!e||s.toLowerCase().includes(c))&&o.push({label:s,path:i(d.length>0?String(d[0]):s),kind:"artifact",authority:f.authority,manual_edit:f.manual_edit,score:Te(s,u,e)});for(let l of d)typeof l=="string"&&(l.includes("*")||l.includes("?")||(!e||l.toLowerCase().includes(c))&&o.push({label:l,path:i(l),kind:"file",artifact:s,authority:f.authority,manual_edit:f.manual_edit,score:Fe(l,e)}))}return o.sort((s,u)=>u.score!==s.score?u.score-s.score:s.label.localeCompare(u.label)),o.slice(0,n)}function Ee(e,t){if(!e)return t;let r=e.replace(/^\.\//,"").replace(/\/+$/,"");return r?`${r}/${t}`:t}function B(e){return e.map(t=>JSON.stringify(t)).join(`
7
+ `)}function Te(e,t,r){let n=50,a=t.properties??{};return a.authority==="canonical"&&(n+=20),a.manual_edit==="allowed"&&(n+=10),a.type==="source"&&(n+=15),a.authority==="generated"&&(n-=20),a.manual_edit==="forbidden"&&(n-=10),r&&e.toLowerCase().startsWith(r.toLowerCase())&&(n+=20),n}function Fe(e,t){let r=40;return t&&e.toLowerCase().startsWith(t.toLowerCase())&&(r+=30),r+=Math.max(0,20-e.split("/").length*2),r}async function Oe(e,t){let r=t.trim(),n=M(r,{navigationIndex:e});return B(n)}async function De(e,t,r,n=G){let a=r.trim(),o=_({cacheDir:e}),c=[];for(let i of t){let s=await o.read(i.cacheKey,y);s&&c.push(...M(a,{navigationIndex:s.data,pathPrefix:i.memberPath,maxCandidates:Number.POSITIVE_INFINITY}))}return c.sort((i,s)=>s.score!==i.score?s.score-i.score:i.label.localeCompare(s.label)),B(c.slice(0,n))}function W(e,t,r){if(!e)return null;let n=e.startsWith("/")?e:q(r,e),a=null,o=0;for(let c of t){let i=c.root,s=i.endsWith("/")?i:i+"/";n.startsWith(s)&&s.length>o&&(a=c,o=s.length)}return a}function Ne(e,t,r){let n=e.startsWith("/")?e:q(r,e),a=t.endsWith("/")?t:t+"/";return n.startsWith(a)?n.slice(a.length):e}function Ie(e){let t=[];for(let r of e.split(/\s+/)){let n=r.replace(/^['"]+|['"]+$/g,"");n&&(n.includes("/")||n.includes("\\"))&&t.push(n)}return t}function $e(e){let t=new Map;async function r(a){if(t.has(a.name))return t.get(a.name);let o=await A({cacheDir:e.cacheDir,cacheKey:a.cacheKey}),c=o?{...o,hooks:P(o.guardrailRules)}:void 0;return t.set(a.name,c),c}function n(a){for(let o of Ie(a)){let c=W(o,e.members,e.workspaceRoot);if(c)return[c]}return e.members}return async function(o){if(E(o)){let d=o.tool_input?.command??"";for(let l of n(d)){let T=await r(l);if(!T)return p(b("guardrail-rules",`member "${l.name}"`));let F=T.hooks.beforeShellExecution({command:d,cwd:o.cwd});if(F.permission==="deny")return p(F.user_message)}}let c=L(o);if(!c)return g();let i=W(c,e.members,e.workspaceRoot);if(!i)return g();let s=await r(i);if(!s)return p(b("navigation-index",`member "${i.name}"`));let u=Ne(c,i.root,e.workspaceRoot),f=s.hooks.afterFileEdit({file_path:u,content:v(o.tool_input)});if(f.permission==="deny")return p(f.user_message);for(let d of C(u,s.navigationIndex)){let l=R(d);if(l.protected)return p(l.reason)}return g()}}export{H as DEFAULT_CACHE_KEY,me as buildContextResponse,_ as createCacheStore,xe as createPreToolUseHandler,$e as createWorkspacePreToolUseHandler,pe as emitHookOutput,Oe as handleFileSuggestion,De as handleWorkspaceFileSuggestion,y as isCachedRecord,x as listArtifacts,A as readFreshNavigationBuild,de as readHookInput};
@@ -1,3 +1,3 @@
1
- export { c as GuardrailCheckEntry, G as GuardrailContext, a as GuardrailDiagnostic, d as ProjectConfig, e as ProjectConfigSchema, R as ResolvedConfig, f as buildGuardrailContext, l as loadProjectConfig, p as parseProjectManifest, r as readProjectManifest } from '../index-BlSepCSZ.js';
1
+ export { c as GuardrailCheckEntry, G as GuardrailContext, a as GuardrailDiagnostic, d as ProjectConfig, e as ProjectConfigSchema, R as ResolvedConfig, f as buildGuardrailContext, l as loadProjectConfig, p as parseProjectManifest, r as readProjectManifest } from '../index-C2DHitGz.js';
2
2
  import 'zod';
3
- import '../guardrail-hooks-CB23nhZV.js';
3
+ import '../guardrail-hooks-B-qe4ebW.js';
@@ -4,8 +4,8 @@ import {
4
4
  loadProjectConfig,
5
5
  parseProjectManifest,
6
6
  readProjectManifest
7
- } from "../chunk-F5R46S7I.js";
8
- import "../chunk-MSVIEEGR.js";
7
+ } from "../chunk-Y7NORFFM.js";
8
+ import "../chunk-HR2Q64AO.js";
9
9
  import "../chunk-BJ7B4R26.js";
10
10
  export {
11
11
  ProjectConfigSchema,
@@ -134,11 +134,24 @@ interface HookContext {
134
134
  * works in never consulted them, and no type or single-route test could say so
135
135
  * (#316).
136
136
  */
137
+ /**
138
+ * A shell command about to run, and the directory it runs in — which resolves a
139
+ * message body the command passes by file (`commandScanText`). Without `cwd`
140
+ * the hook process's own directory is used.
141
+ */
142
+ interface ShellCommandInput {
143
+ command?: string;
144
+ cwd?: string;
145
+ }
137
146
  interface GuardrailHooks {
138
147
  /** A command about to run. Claude Code PreToolUse (both routes), `guard evaluate`. */
139
- beforeShellExecution: (input: {
140
- command?: string;
141
- }) => HookResponse;
148
+ beforeShellExecution: (input: ShellCommandInput) => HookResponse;
149
+ /**
150
+ * The checks {@link GuardrailHooks.beforeShellExecution} decides on — the
151
+ * command plus any body it passes by file. `guard evaluate` reports these, so
152
+ * the list it prints is the one its verdict came from.
153
+ */
154
+ checkShellCommand: (input: ShellCommandInput) => GuardrailCheckResult[];
142
155
  /**
143
156
  * A TOOL INPUT, verbatim: `toolTargetPath` reads the file out of it and
144
157
  * `toolPendingContent` the text about to go in. The single-component Claude
@@ -23,6 +23,8 @@ interface UserPromptSubmitInput {
23
23
  interface PreToolUseInput {
24
24
  hookEventName: "PreToolUse";
25
25
  session_id?: string;
26
+ /** The session's working directory, where a Bash command runs. */
27
+ cwd?: string;
26
28
  tool_name?: string;
27
29
  tool_input?: {
28
30
  file_path?: string;
@@ -1,5 +1,5 @@
1
- import { c as PreToolUseInput, H as HookOutput } from './hook-protocol-CFnNudiV.js';
2
- import { a as GuardrailRuleData } from './guardrail-hooks-CB23nhZV.js';
1
+ import { c as PreToolUseInput, H as HookOutput } from './hook-protocol-BH86kCQB.js';
2
+ import { a as GuardrailRuleData } from './guardrail-hooks-B-qe4ebW.js';
3
3
 
4
4
  /**
5
5
  * Cache Store — read/write `.claude/cache/` directory.
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { d as GuardrailAction } from './guardrail-hooks-CB23nhZV.js';
2
+ import { d as GuardrailAction } from './guardrail-hooks-B-qe4ebW.js';
3
3
 
4
4
  /**
5
5
  * Generator configuration — loads and validates the project manifest
@@ -105,6 +105,14 @@ declare const ProjectConfigSchema: z.ZodObject<{
105
105
  endpoint: z.ZodString;
106
106
  }, z.core.$strict>>;
107
107
  }, z.core.$strict>>;
108
+ claude: z.ZodOptional<z.ZodObject<{
109
+ emit: z.ZodOptional<z.ZodObject<{
110
+ workflows: z.ZodOptional<z.ZodBoolean>;
111
+ commands: z.ZodOptional<z.ZodBoolean>;
112
+ agents: z.ZodOptional<z.ZodBoolean>;
113
+ harness: z.ZodOptional<z.ZodBoolean>;
114
+ }, z.core.$strict>>;
115
+ }, z.core.$strict>>;
108
116
  }, z.core.$strict>>;
109
117
  active_guardrail_policy: z.ZodOptional<z.ZodString>;
110
118
  plugins: z.ZodOptional<z.ZodArray<z.ZodString>>;
package/dist/index.d.ts CHANGED
@@ -3,13 +3,13 @@ export { A as AdapterSendOptions, a as AgentExecutionRequest, j as AgentProgress
3
3
  import { ProjectModelMapping, ModelClass, ComponentIR, OperationIR } from '@aaac/contracts';
4
4
  export { ModelClass } from '@aaac/contracts';
5
5
  import { z } from 'zod';
6
- import { b as GuardrailCheckFunctions, a as GuardrailRuleData, G as GuardrailHooks, H as HookResponse, c as GuardrailCheckResult } from './guardrail-hooks-CB23nhZV.js';
7
- export { d as GuardrailAction, e as GuardrailRule, f as HookContext, U as UNRESOLVED_GUARDRAIL_ACTION, g as createGuardrailHooks, h as createGuardrailHooksFromRules, i as getBlockingViolations, j as getWarnings, k as hasBlockingViolation } from './guardrail-hooks-CB23nhZV.js';
8
- import { G as GuardrailContext, P as ProgressLogConfig, R as ResolvedConfig, a as GuardrailDiagnostic } from './index-BlSepCSZ.js';
9
- export { b as PROJECT_CONFIG_FILENAME } from './index-BlSepCSZ.js';
6
+ import { b as GuardrailCheckFunctions, a as GuardrailRuleData, G as GuardrailHooks, H as HookResponse, c as GuardrailCheckResult } from './guardrail-hooks-B-qe4ebW.js';
7
+ export { d as GuardrailAction, e as GuardrailRule, f as HookContext, U as UNRESOLVED_GUARDRAIL_ACTION, g as createGuardrailHooks, h as createGuardrailHooksFromRules, i as getBlockingViolations, j as getWarnings, k as hasBlockingViolation } from './guardrail-hooks-B-qe4ebW.js';
8
+ import { G as GuardrailContext, P as ProgressLogConfig, R as ResolvedConfig, a as GuardrailDiagnostic } from './index-C2DHitGz.js';
9
+ export { b as PROJECT_CONFIG_FILENAME } from './index-C2DHitGz.js';
10
10
  import { OtelEmitter } from '@aaac/observability';
11
11
  export { ExecutionEnvelope } from '@aaac/observability';
12
- export { a as NavigationContext, N as NavigationContextOptions, b as buildNavigationContext } from './navigation-context-B-RpUg3_.js';
12
+ export { a as NavigationContext, N as NavigationContextOptions, b as buildNavigationContext } from './navigation-context-D1NbiipT.js';
13
13
  export { i as isNavigationIndex, r as renderNavigationIndexPrompt } from './navigation-index-prompt-CbrS5laO.js';
14
14
 
15
15
  /**
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  resolveGuardrailContext,
15
15
  resolveNavigationDsl,
16
16
  resolveNavigationSources
17
- } from "./chunk-MG2ULUX6.js";
17
+ } from "./chunk-DEBCJKRX.js";
18
18
  import {
19
19
  jsonSchemaToZod
20
20
  } from "./chunk-ET6TGQRT.js";
@@ -47,8 +47,9 @@ import {
47
47
  import {
48
48
  PROJECT_CONFIG_FILENAME,
49
49
  loadProjectConfig,
50
- loadWorkspaceMembers
51
- } from "./chunk-F5R46S7I.js";
50
+ loadWorkspaceMembers,
51
+ readProjectManifest
52
+ } from "./chunk-Y7NORFFM.js";
52
53
  import {
53
54
  isNavigationIndex,
54
55
  renderNavigationIndexPrompt
@@ -61,7 +62,7 @@ import {
61
62
  getWarnings,
62
63
  hasBlockingViolation,
63
64
  toolTargetPath
64
- } from "./chunk-MSVIEEGR.js";
65
+ } from "./chunk-HR2Q64AO.js";
65
66
  import {
66
67
  __commonJS,
67
68
  __require,
@@ -9173,8 +9174,9 @@ async function evaluateGuardrail(opts) {
9173
9174
  let checks = [];
9174
9175
  const shellCommand = command ?? toolInput?.command;
9175
9176
  if (shellCommand !== void 0) {
9176
- response = hooks.beforeShellExecution({ command: shellCommand });
9177
- checks = hooks.runChecks({ command: shellCommand });
9177
+ const shell = { command: shellCommand, cwd: hookInput.cwd };
9178
+ response = hooks.beforeShellExecution(shell);
9179
+ checks = hooks.checkShellCommand(shell);
9178
9180
  } else if (toolName !== void 0 || toolInput !== void 0) {
9179
9181
  response = hooks.preToolUse({ tool_name: toolName, tool_input: toolInput });
9180
9182
  const checkFilePath = toolTargetPath(toolInput);
@@ -9343,6 +9345,17 @@ var ClaudeConfigSchema = z3.object({
9343
9345
  function parseClaudeConfig(raw) {
9344
9346
  return ClaudeConfigSchema.parse(raw ?? {});
9345
9347
  }
9348
+ function applyProjectEmit(config, project) {
9349
+ if (!project) return config;
9350
+ const emit = { ...config.emit };
9351
+ if (project.workflows !== void 0) emit.workflows = project.workflows;
9352
+ if (project.agents !== void 0) emit.agents = project.agents;
9353
+ if (project.harness !== void 0) emit.harness = project.harness;
9354
+ if (project.commands !== void 0) {
9355
+ emit.commands = project.commands ? config.emit.commands ?? {} : void 0;
9356
+ }
9357
+ return { ...config, emit };
9358
+ }
9346
9359
 
9347
9360
  // src/lib/claude-materialize/workflow-render.ts
9348
9361
  import { resolveSchemaRefs } from "agent-contracts";
@@ -10603,9 +10616,15 @@ function checkHookBin(file, existing) {
10603
10616
  const onDisk = recomputeMarkerFromDisk(existing);
10604
10617
  return stored !== expected || stored !== onDisk ? "changed" : null;
10605
10618
  }
10619
+ function effectiveClaudeConfig(root, raw) {
10620
+ const config = parseClaudeConfig(raw);
10621
+ const manifestPath = join7(root, PROJECT_CONFIG_FILENAME);
10622
+ if (!existsSync5(manifestPath)) return config;
10623
+ return applyProjectEmit(config, readProjectManifest(manifestPath).bindings?.claude?.emit);
10624
+ }
10606
10625
  async function syncClaude(opts) {
10607
- const config = parseClaudeConfig(opts.config);
10608
10626
  const root = resolve6(opts.projectRoot);
10627
+ const config = effectiveClaudeConfig(root, opts.config);
10609
10628
  const result = { files: [] };
10610
10629
  const sources = await resolveDslSources(root, opts.dsl, config);
10611
10630
  const rendered = await renderFiles(root, opts.dsl, config, entryAgentPromptFor(sources, config));
@@ -10669,8 +10688,8 @@ async function syncClaude(opts) {
10669
10688
  return result;
10670
10689
  }
10671
10690
  async function checkClaude(opts) {
10672
- const config = parseClaudeConfig(opts.config);
10673
10691
  const root = resolve6(opts.projectRoot);
10692
+ const config = effectiveClaudeConfig(root, opts.config);
10674
10693
  const drift = [];
10675
10694
  const sources = await resolveDslSources(root, opts.dsl, config);
10676
10695
  const rendered = await renderFiles(root, opts.dsl, config, entryAgentPromptFor(sources, config));