@tech-leads-club/harness-toolkit 0.16.0 → 0.16.1

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.
@@ -157,6 +157,6 @@ description: Harness-learned lessons (auto-synced from gate failures)
157
157
  alwaysApply: true
158
158
  ---
159
159
 
160
- ${J}`;return XV(Q,q,"utf8"),Q}function g3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function u3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:g3("deny",$),exitCode:0};case"ask":return{stdout:g3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function h3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as zV}from"node:path";function p3(){return zV(Z9(),"hooks.json")}function c3(){return[p3()]}var VV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:5,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function d3($){let J=[$.launcherPath],Q=VV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:p3(),strategy:"replace",entries:Q}}var l3={name:"cursor",detect:b3,capabilities:S3,policyDefaults:h3,toEvent:f3,render:u3,wiring:d3,wiringTargets:c3,lessonsView:m3};var f$=[l3,x3];function r5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}var i3=O.observability.DEFAULT_OBS,WO={...i3,debugEnabled:!0};function n3($,Z=i3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function a3($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}function r3($,Z){return[...O.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}var BV=6000;function UV($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return _8($.toolName)}function HV($){return $ instanceof Error?$.message:String($)}function r($,Z,J,Q="unknown",q={}){try{D(GV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function MV($){return $.event==="shell.before"||$.event==="mcp.before"}function KV($){if(!MV($))return;r($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:O.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function FV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;O.observability.recordObs($.projectDir,n3(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function CV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function OV($,Z={}){let J=Z.readStdin??E9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return r(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return r(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=r5(Y,f$);if(!z.provider)return r(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)r(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(CV(Y));if(!G)return r(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();KV(G);try{let M=O.policy.loadPolicy(G.projectDir);if(G.model)O.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},r3(M.subagents.blockedPatterns,V));O.presence.heartbeat(G.projectDir,{provider:G.provider,session:a3(G),...UV(G)?{file:G.filePath}:{},now:Q});let B=f$.flatMap((E)=>E.wiringTargets()),T=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),S=d8(T,G,U,{contextBudgetChars:BV});FV(G,M,S);let d=V.render(S,G);return{event:G,decision:S,rendered:d}}catch(M){r(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:HV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function s3($){let Z=await OV($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
160
+ ${J}`;return XV(Q,q,"utf8"),Q}function g3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function u3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:g3("deny",$),exitCode:0};case"ask":return{stdout:g3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function h3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as zV}from"node:path";function p3(){return zV(Z9(),"hooks.json")}function c3(){return[p3()]}var VV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function d3($){let J=[$.launcherPath],Q=VV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:p3(),strategy:"replace",entries:Q}}var l3={name:"cursor",detect:b3,capabilities:S3,policyDefaults:h3,toEvent:f3,render:u3,wiring:d3,wiringTargets:c3,lessonsView:m3};var f$=[l3,x3];function r5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}var i3=O.observability.DEFAULT_OBS,WO={...i3,debugEnabled:!0};function n3($,Z=i3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function a3($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}function r3($,Z){return[...O.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}var BV=6000;function UV($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return _8($.toolName)}function HV($){return $ instanceof Error?$.message:String($)}function r($,Z,J,Q="unknown",q={}){try{D(GV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function MV($){return $.event==="shell.before"||$.event==="mcp.before"}function KV($){if(!MV($))return;r($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:O.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function FV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;O.observability.recordObs($.projectDir,n3(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function CV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function OV($,Z={}){let J=Z.readStdin??E9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return r(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return r(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=r5(Y,f$);if(!z.provider)return r(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)r(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(CV(Y));if(!G)return r(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();KV(G);try{let M=O.policy.loadPolicy(G.projectDir);if(G.model)O.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},r3(M.subagents.blockedPatterns,V));O.presence.heartbeat(G.projectDir,{provider:G.provider,session:a3(G),...UV(G)?{file:G.filePath}:{},now:Q});let B=f$.flatMap((E)=>E.wiringTargets()),T=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),S=d8(T,G,U,{contextBudgetChars:BV});FV(G,M,S);let d=V.render(S,G);return{event:G,decision:S,rendered:d}}catch(M){r(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:HV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function s3($){let Z=await OV($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
161
161
  `)?J:`${J}
162
162
  `)}process.exit(Z.rendered.exitCode)}var _V=async($,Z)=>{let J=$.text??"";if(Z.policy.planGate.enabled){let q=O.plan.detectPlan(J),X=O.plan.detectDeviations(J);if(q)await O.handoff.patchHandoff($.projectDir,$.provider,$.sessionKey,{slice:{plan_paths:q.paths,plan_at:Z.now.toISOString(),plan_snippet:q.snippet,plan_deviations:[]}});if(X.length>0){let Y=O.handoff.readHandoff($.projectDir,$.provider,$.sessionKey).plan_deviations??[],z=X.filter((V)=>!Y.some((G)=>G.path===V.path));if(z.length>0)await O.handoff.patchHandoff($.projectDir,$.provider,$.sessionKey,{slice:{plan_deviations:[...Y,...z]}})}}let Q=O.ship.detectShipClaim(J);if(Q)await O.handoff.patchHandoff($.projectDir,$.provider,$.sessionKey,{slice:{last_ship_claim_at:Z.now.toISOString(),last_ship_claim_snippet:Q.snippet,last_ship_claim_kind:Q.kind}}),O.ship.appendShipLedger($.projectDir,{provider:$.provider,event:"claim",claimKind:Q.kind,detail:Q.snippet});return{kind:"abstain"}};if(o5.main==o5.module)await s3(_V);export{_V as responseAfterHandler};
package/dist/run.mjs CHANGED
@@ -157,6 +157,6 @@ description: Harness-learned lessons (auto-synced from gate failures)
157
157
  alwaysApply: true
158
158
  ---
159
159
 
160
- ${J}`;return JV(Q,q,"utf8"),Q}function m3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function g3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:m3("deny",$),exitCode:0};case"ask":return{stdout:m3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function u3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as XV}from"node:path";function h3(){return XV($9(),"hooks.json")}function p3(){return[h3()]}var WV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:5,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function c3($){let J=[$.launcherPath],Q=WV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:h3(),strategy:"replace",entries:Q}}var d3={name:"cursor",detect:S3,capabilities:x3,policyDefaults:u3,toEvent:f3,render:g3,wiring:c3,wiringTargets:p3,lessonsView:v3};var y$=[d3,k3];function r5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}var l3=x.observability.DEFAULT_OBS,$O={...l3,debugEnabled:!0};function i3($,Z=l3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function n3($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}function a3($,Z){return[...x.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}var zV=6000;function VV($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return w$($.toolName)}function GV($){return $ instanceof Error?$.message:String($)}function r($,Z,J,Q="unknown",q={}){try{L(YV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function BV($){return $.event==="shell.before"||$.event==="mcp.before"}function UV($){if(!BV($))return;r($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:x.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function HV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;x.observability.recordObs($.projectDir,i3(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function MV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function KV($,Z={}){let J=Z.readStdin??T9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return r(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return r(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=r5(Y,y$);if(!z.provider)return r(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)r(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(MV(Y));if(!G)return r(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();UV(G);try{let M=x.policy.loadPolicy(G.projectDir);if(G.model)x.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},a3(M.subagents.blockedPatterns,V));x.presence.heartbeat(G.projectDir,{provider:G.provider,session:n3(G),...VV(G)?{file:G.filePath}:{},now:Q});let B=y$.flatMap((T)=>T.wiringTargets()),P=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),S=d8(P,G,U,{contextBudgetChars:zV});HV(G,M,S);let d=V.render(S,G);return{event:G,decision:S,rendered:d}}catch(M){r(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:GV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function GO($){let Z=await KV($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
160
+ ${J}`;return JV(Q,q,"utf8"),Q}function m3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function g3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:m3("deny",$),exitCode:0};case"ask":return{stdout:m3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function u3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as XV}from"node:path";function h3(){return XV($9(),"hooks.json")}function p3(){return[h3()]}var WV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function c3($){let J=[$.launcherPath],Q=WV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:h3(),strategy:"replace",entries:Q}}var d3={name:"cursor",detect:S3,capabilities:x3,policyDefaults:u3,toEvent:f3,render:g3,wiring:c3,wiringTargets:p3,lessonsView:v3};var y$=[d3,k3];function r5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}var l3=x.observability.DEFAULT_OBS,$O={...l3,debugEnabled:!0};function i3($,Z=l3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function n3($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}function a3($,Z){return[...x.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}var zV=6000;function VV($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return w$($.toolName)}function GV($){return $ instanceof Error?$.message:String($)}function r($,Z,J,Q="unknown",q={}){try{L(YV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function BV($){return $.event==="shell.before"||$.event==="mcp.before"}function UV($){if(!BV($))return;r($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:x.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function HV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;x.observability.recordObs($.projectDir,i3(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function MV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function KV($,Z={}){let J=Z.readStdin??T9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return r(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return r(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=r5(Y,y$);if(!z.provider)return r(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)r(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(MV(Y));if(!G)return r(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();UV(G);try{let M=x.policy.loadPolicy(G.projectDir);if(G.model)x.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},a3(M.subagents.blockedPatterns,V));x.presence.heartbeat(G.projectDir,{provider:G.provider,session:n3(G),...VV(G)?{file:G.filePath}:{},now:Q});let B=y$.flatMap((T)=>T.wiringTargets()),P=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),S=d8(P,G,U,{contextBudgetChars:zV});HV(G,M,S);let d=V.render(S,G);return{event:G,decision:S,rendered:d}}catch(M){r(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:GV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function GO($){let Z=await KV($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
161
161
  `)?J:`${J}
162
162
  `)}process.exit(Z.rendered.exitCode)}export{KV as runHandler,GO as main,VV as claimsFile,zV as CONTEXT_BUDGET_CHARS};
@@ -157,6 +157,6 @@ description: Harness-learned lessons (auto-synced from gate failures)
157
157
  alwaysApply: true
158
158
  ---
159
159
 
160
- ${J}`;return WV(Q,q,"utf8"),Q}function u3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function h3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:u3("deny",$),exitCode:0};case"ask":return{stdout:u3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function p3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as VV}from"node:path";function c3(){return VV(J9(),"hooks.json")}function d3(){return[c3()]}var GV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:5,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function l3($){let J=[$.launcherPath],Q=GV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:c3(),strategy:"replace",entries:Q}}var i3={name:"cursor",detect:f3,capabilities:b3,policyDefaults:p3,toEvent:w3,render:h3,wiring:l3,wiringTargets:d3,lessonsView:g3};var B$=[i3,S3];function s5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}var n3=C.observability.DEFAULT_OBS,YO={...n3,debugEnabled:!0};function a3($,Z=n3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function l8($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}function r3($,Z){return[...C.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}function s3($,Z,J=B$){return J.find((q)=>q.name===$)?.lessonsView(Z)??null}var UV=6000;function HV($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return _8($.toolName)}function MV($){return $ instanceof Error?$.message:String($)}function r($,Z,J,Q="unknown",q={}){try{D(BV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function KV($){return $.event==="shell.before"||$.event==="mcp.before"}function FV($){if(!KV($))return;r($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:C.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function CV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;C.observability.recordObs($.projectDir,a3(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function OV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function _V($,Z={}){let J=Z.readStdin??R9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return r(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return r(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=s5(Y,B$);if(!z.provider)return r(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)r(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(OV(Y));if(!G)return r(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();FV(G);try{let M=C.policy.loadPolicy(G.projectDir);if(G.model)C.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},r3(M.subagents.blockedPatterns,V));C.presence.heartbeat(G.projectDir,{provider:G.provider,session:l8(G),...HV(G)?{file:G.filePath}:{},now:Q});let B=B$.flatMap((E)=>E.wiringTargets()),T=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),S=d8(T,G,U,{contextBudgetChars:UV});CV(G,M,S);let d=V.render(S,G);return{event:G,decision:S,rendered:d}}catch(M){r(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:MV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function o3($){let Z=await _V($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
160
+ ${J}`;return WV(Q,q,"utf8"),Q}function u3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function h3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:u3("deny",$),exitCode:0};case"ask":return{stdout:u3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function p3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as VV}from"node:path";function c3(){return VV(J9(),"hooks.json")}function d3(){return[c3()]}var GV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function l3($){let J=[$.launcherPath],Q=GV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:c3(),strategy:"replace",entries:Q}}var i3={name:"cursor",detect:f3,capabilities:b3,policyDefaults:p3,toEvent:w3,render:h3,wiring:l3,wiringTargets:d3,lessonsView:g3};var B$=[i3,S3];function s5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}var n3=C.observability.DEFAULT_OBS,YO={...n3,debugEnabled:!0};function a3($,Z=n3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function l8($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}function r3($,Z){return[...C.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}function s3($,Z,J=B$){return J.find((q)=>q.name===$)?.lessonsView(Z)??null}var UV=6000;function HV($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return _8($.toolName)}function MV($){return $ instanceof Error?$.message:String($)}function r($,Z,J,Q="unknown",q={}){try{D(BV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function KV($){return $.event==="shell.before"||$.event==="mcp.before"}function FV($){if(!KV($))return;r($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:C.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function CV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;C.observability.recordObs($.projectDir,a3(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function OV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function _V($,Z={}){let J=Z.readStdin??R9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return r(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return r(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=s5(Y,B$);if(!z.provider)return r(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)r(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(OV(Y));if(!G)return r(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();FV(G);try{let M=C.policy.loadPolicy(G.projectDir);if(G.model)C.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},r3(M.subagents.blockedPatterns,V));C.presence.heartbeat(G.projectDir,{provider:G.provider,session:l8(G),...HV(G)?{file:G.filePath}:{},now:Q});let B=B$.flatMap((E)=>E.wiringTargets()),T=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),S=d8(T,G,U,{contextBudgetChars:UV});CV(G,M,S);let d=V.render(S,G);return{event:G,decision:S,rendered:d}}catch(M){r(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:MV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function o3($){let Z=await _V($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
161
161
  `)?J:`${J}
162
162
  `)}process.exit(Z.rendered.exitCode)}var IV=async($,Z)=>{let{policy:J}=Z,Q=$.projectDir,q=l8($);if(await C.handoff.patchHandoff(Q,$.provider,$.sessionKey,{slice:{next_action:"Session ended. Run `tlc harness handoff` before resuming."}}),C.presence.release(Q,$.provider,q),C.turn.resetLoop(Q,$.sessionKey),J.intelligence.lessons.enabled&&J.intelligence.lessons.gardenOnSessionEnd){let Y=C.lesson.durableViewVerdict(J.intelligence.lessons.syncRulesFile,Z.capabilities.sessionStartContextReliable);if((await C.lesson.gardenAndPersistLessons(Q,J.intelligence.lessons,{writeDurableView:Y.writes})).markdownPath)s3($.provider,Q)}let X=C.observability.getRollup(Q,$.sessionKey),W=C.policy.policySourceFingerprint(Q);return C.attest.appendAttestation(Q,{ts:new Date().toISOString(),provider:$.provider,session:q,policyFingerprint:C.attest.fingerprintOf(W),policyDiverged:C.policy.checkPolicyBaseline(Q,$.sessionKey).kind!=="allow",railsActive:C.policy.activeRails(J),decisionsByRule:X?.railsByRule??{},gates:X?.gates??{pass:0,fail:0}}),{kind:"abstain"}};if(t5.main==t5.module)await o3(IV);export{IV as sessionEndHandler};
@@ -157,7 +157,7 @@ description: Harness-learned lessons (auto-synced from gate failures)
157
157
  alwaysApply: true
158
158
  ---
159
159
 
160
- ${J}`;return GV(Q,q,"utf8"),Q}function h3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function p3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:h3("deny",$),exitCode:0};case"ask":return{stdout:h3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function c3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as HV}from"node:path";function d3(){return HV(Q9(),"hooks.json")}function l3(){return[d3()]}var MV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:5,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function i3($){let J=[$.launcherPath],Q=MV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:d3(),strategy:"replace",entries:Q}}var n3={name:"cursor",detect:f3,capabilities:y3,policyDefaults:c3,toEvent:v3,render:p3,wiring:i3,wiringTargets:l3,lessonsView:u3};var U$=[n3,b3];function o5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}import{statSync as KV}from"node:fs";var a3=K.observability.DEFAULT_OBS,MO={...a3,debugEnabled:!0};function l8($,Z=a3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function r3($){try{return KV($).size}catch{return 0}}function i8($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}async function s3($){let Z=await v($);if(Z===null)return null;let J=await n({command:["git","rev-parse","--abbrev-ref","HEAD"],cwd:Z});if(J.exitCode!==0)return null;let Q=J.stdout.trim();return Q.length>0?Q:null}async function o3($){let Z=await v($);if(Z===null)return null;let J=await n({command:["git","rev-parse","--short","HEAD"],cwd:Z});if(J.exitCode!==0)return null;let Q=J.stdout.trim();return Q.length>0?Q:null}function t3($,Z){return[...K.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}function FV($){return K.lesson.renderLessonBlock($)}function e3($,Z,J=U$){return J.find((q)=>q.name===$)?.lessonsView(Z)??null}function $1($,Z,J=0){if($.length===0)return"";let Q=[Z,...$.map(FV)];if(J>0){let q=J===1?"lesson":"lessons";Q.push(` (${J} more eligible ${q} omitted under the char budget — raise maxCharsSession to see them)`)}return Q.join(`
160
+ ${J}`;return GV(Q,q,"utf8"),Q}function h3($,Z){let J={permission:$};if(Z.userNote!==void 0)J.user_message=Z.userNote;return J.agent_message=Z.reason,JSON.stringify(J)}function p3($,Z){switch($.kind){case"abstain":return{stdout:"{}",exitCode:0};case"allow":return{stdout:JSON.stringify({permission:"allow"}),exitCode:0};case"deny":return{stdout:h3("deny",$),exitCode:0};case"ask":return{stdout:h3("ask",$),exitCode:0};case"context":{let J={};if($.env!==void 0)J.env=$.env;return J.additional_context=$.text,{stdout:JSON.stringify(J),exitCode:0}}case"continue":return{stdout:JSON.stringify({followup_message:$.text}),exitCode:0};case"rewriteInput":return{stdout:JSON.stringify({updated_input:$.input}),exitCode:0};case"rewriteOutput":return{stdout:JSON.stringify({updated_mcp_tool_output:{result_json:$.output}}),exitCode:0};default:throw Error(`unreachable decision kind: ${JSON.stringify($)}`)}}function c3(){return{blockedPatterns:["-fast(?:$|[^a-z0-9])","/fast(?:$|[^a-z0-9])","composer-2\\.5-fast"],minEffort:null,untrustedTools:["Fetch","WebSearch"]}}import{join as HV}from"node:path";function d3(){return HV(Q9(),"hooks.json")}function l3(){return[d3()]}var MV=[{hookEvent:"sessionStart",handler:"session-start",timeoutSeconds:10},{hookEvent:"sessionEnd",handler:"session-end",timeoutSeconds:10},{hookEvent:"beforeSubmitPrompt",handler:"prompt-submit",timeoutSeconds:5},{hookEvent:"afterAgentThought",handler:"tool-after",timeoutSeconds:5},{hookEvent:"preCompact",handler:"compact-before",timeoutSeconds:5},{hookEvent:"subagentStart",handler:"subagent-start",timeoutSeconds:5,failClosed:!0},{hookEvent:"subagentStop",handler:"subagent-stop",timeoutSeconds:5},{hookEvent:"preToolUse",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"postToolUse",handler:"tool-after",timeoutSeconds:5},{hookEvent:"postToolUseFailure",handler:"tool-failure",timeoutSeconds:5},{hookEvent:"beforeShellExecution",handler:"tool-before",timeoutSeconds:10,failClosed:!0},{hookEvent:"afterShellExecution",handler:"tool-after",timeoutSeconds:10},{hookEvent:"beforeMCPExecution",handler:"tool-before",timeoutSeconds:10},{hookEvent:"afterMCPExecution",handler:"tool-after",timeoutSeconds:5},{hookEvent:"beforeReadFile",handler:"tool-before",timeoutSeconds:5},{hookEvent:"afterFileEdit",handler:"tool-after",timeoutSeconds:30,matcher:"Write"},{hookEvent:"stop",handler:"stop",timeoutSeconds:120,loopLimit:5},{hookEvent:"afterAgentResponse",handler:"response-after",timeoutSeconds:5,matcher:"AgentResponse"}];function i3($){let J=[$.launcherPath],Q=MV.map((q)=>({hookEvent:q.hookEvent,handler:q.handler,command:"node",args:[...J,q.handler],timeoutSeconds:q.timeoutSeconds,...q.failClosed!==void 0?{failClosed:q.failClosed}:{},...q.matcher!==void 0?{matcher:q.matcher}:{},...q.loopLimit!==void 0?{loopLimit:q.loopLimit}:{}}));return{target:d3(),strategy:"replace",entries:Q}}var n3={name:"cursor",detect:f3,capabilities:y3,policyDefaults:c3,toEvent:v3,render:p3,wiring:i3,wiringTargets:l3,lessonsView:u3};var U$=[n3,b3];function o5($,Z){let J=Z.filter((Q)=>Q.detect($));if(J.length===0)return{provider:null,ambiguous:!1,matchedNames:[]};return{provider:J[0]??null,ambiguous:J.length>1,matchedNames:J.map((Q)=>Q.name)}}import{statSync as KV}from"node:fs";var a3=K.observability.DEFAULT_OBS,MO={...a3,debugEnabled:!0};function l8($,Z=a3){return{...Z,globalSpool:$.obs.globalSpool,includePayloads:$.obs.includePayloads,maxAttrChars:$.obs.maxAttrChars,sessionCostAlertUsd:$.obs.sessionCostAlertUsd,retentionDays:$.obs.retentionDays}}function r3($){try{return KV($).size}catch{return 0}}function i8($){let Z=`${$.provider}-`;return $.sessionKey.startsWith(Z)?$.sessionKey.slice(Z.length):$.sessionKey}async function s3($){let Z=await v($);if(Z===null)return null;let J=await n({command:["git","rev-parse","--abbrev-ref","HEAD"],cwd:Z});if(J.exitCode!==0)return null;let Q=J.stdout.trim();return Q.length>0?Q:null}async function o3($){let Z=await v($);if(Z===null)return null;let J=await n({command:["git","rev-parse","--short","HEAD"],cwd:Z});if(J.exitCode!==0)return null;let Q=J.stdout.trim();return Q.length>0?Q:null}function t3($,Z){return[...K.policy.forProvider($,Z.name)??[],...Z.policyDefaults().blockedPatterns]}function FV($){return K.lesson.renderLessonBlock($)}function e3($,Z,J=U$){return J.find((q)=>q.name===$)?.lessonsView(Z)??null}function $1($,Z,J=0){if($.length===0)return"";let Q=[Z,...$.map(FV)];if(J>0){let q=J===1?"lesson":"lessons";Q.push(` (${J} more eligible ${q} omitted under the char budget — raise maxCharsSession to see them)`)}return Q.join(`
161
161
  `)}var OV=6000;function _V($){if($.filePath===void 0)return!1;if($.event==="edit.after")return!0;return _8($.toolName)}function IV($){return $ instanceof Error?$.message:String($)}function o($,Z,J,Q="unknown",q={}){try{T(CV(H($),"obs.jsonl"),{schema:"harness.observability.v1",provider:Q,kind:Z,level:"signal",ts:new Date().toISOString(),...q,attrs:J})}catch{}}function jV($){return $.event==="shell.before"||$.event==="mcp.before"}function NV($){if(!jV($))return;o($.projectDir,"hook.enter",{event:$.event,toolName:$.toolName??"none",sessionKey:$.sessionKey},$.provider,{trace_id:K.observability.deriveTraceId($.sessionKey),session_id:$.sessionKey})}function LV($,Z,J){if(J.kind!=="deny"&&J.kind!=="ask")return;if($.event==="shell.before")return;K.observability.recordObs($.projectDir,l8(Z),{provider:$.provider,kind:"policy.deny",sessionKey:$.sessionKey,attrs:{event:$.event,tool_name:$.toolName,permission:J.kind,rule:J.rule??"none",diagnostic:J.diagnostic??"none"}})}function DV($){return $!==null&&typeof $==="object"&&!Array.isArray($)?$:{}}async function AV($,Z={}){let J=Z.readStdin??k9,Q=Z.now?Z.now():new Date,q={stdout:null,exitCode:0},W=(await J()).trim();if(!W)return o(process.cwd(),"adapter.unrecognized",{reason:"empty-stdin"}),{event:null,decision:{kind:"abstain"},rendered:q};let Y;try{Y=JSON.parse(W)}catch{return o(process.cwd(),"adapter.unrecognized",{reason:"invalid-json"}),{event:null,decision:{kind:"abstain"},rendered:q}}let z=o5(Y,U$);if(!z.provider)return o(process.cwd(),"adapter.unrecognized",{reason:"no-provider-match"}),{event:null,decision:{kind:"abstain"},rendered:q};if(z.ambiguous)o(process.cwd(),"adapter.ambiguous",{matched:z.matchedNames});let V=z.provider,G=V.toEvent(DV(Y));if(!G)return o(process.cwd(),"adapter.unrecognized",{reason:"unrecognized-event",provider:V.name}),{event:null,decision:{kind:"abstain"},rendered:q};let U=V.capabilities();NV(G);try{let M=K.policy.loadPolicy(G.projectDir);if(G.model)K.subagentPolicy.upsertParentModelState(G.projectDir,G.sessionKey,{model:G.model},t3(M.subagents.blockedPatterns,V));K.presence.heartbeat(G.projectDir,{provider:G.provider,session:i8(G),..._V(G)?{file:G.filePath}:{},now:Q});let B=U$.flatMap((P)=>P.wiringTargets()),C=await $(G,{policy:M,capabilities:U,provider:V,now:Q,protectedPaths:B}),E=d8(C,G,U,{contextBudgetChars:OV});LV(G,M,E);let k=V.render(E,G);return{event:G,decision:E,rendered:k}}catch(M){o(G.projectDir,"adapter.error",{provider:G.provider,event:G.event,message:IV(M)});let B={kind:"abstain"};return{event:G,decision:B,rendered:V.render(B,G)}}}async function Z1($){let Z=await AV($);if(Z.rendered.stdout!==null){let J=Z.rendered.stdout;process.stdout.write(J.endsWith(`
162
162
  `)?J:`${J}
163
163
  `)}process.exit(Z.rendered.exitCode)}var PV=async($,Z)=>{let{policy:J}=Z,Q=i8($),q=$.projectDir;K.policy.recordPolicyBaseline(q,$.sessionKey);let X=0;if(K.turn.markBooted(q,$.sessionKey).alreadyBooted)return{kind:"context",text:"",env:{HARNESS_ACTIVE:"1"}};let Y=await s3(q),z=await o3(q);K.presence.sweepStale(q),K.presence.register(q,{provider:$.provider,session:Q,pid:process.pid,branch:Y??"unknown"}),K.handoff.pruneDeadHandoffSessions(q),K.gate.pruneGateSessions(q),await K.handoff.patchHandoff(q,$.provider,$.sessionKey,{shared:{mode:J.mode,project_name:J.projectName,git_branch:Y??void 0,git_sha:z??void 0},slice:{next_action:"Run `tlc harness handoff` if resuming; otherwise start from the user request."}});let V=K.handoff.handoffInjectable(q,$.sessionKey),G=K.lesson.projectLessonsInjectable(q),U=V.ok?K.handoff.readHandoff(q,$.provider,$.sessionKey):{},M=V.ok?K.handoff.readForeignSlices(q,$.provider):[],B=[...[V.note,G.note].filter((C)=>C!==null),...K.policy.operatorBootstrapLines(J,H(q)),"",`Project root: ${q}`];if(J.projectName)B.push(`Project: ${J.projectName}`);if(Y)B.push(`Git branch: ${Y}`);if(z)B.push(`Git HEAD: ${z}`);if(U.blockers)B.push(`Handoff blocker: ${U.blockers}`);if(U.next_action)B.push(`Handoff next: ${U.next_action}`);if(J.intelligence.progressiveHandoff){let C=K.turn.formatCarriedGaps(U.previous_gaps??[]);if(C)B.push("",C)}for(let C of M){if(B.push("",`Foreign slice (${C.provider}):`),C.next_action)B.push(` next_action: ${C.next_action}`);if(C.blockers)B.push(` blockers: ${C.blockers}`)}if(J.intelligence.lessons.enabled&&G.ok){let C=J.intelligence.lessons,E=await K.lesson.selectLessons({projectDir:q,config:C,mode:"session",text:[U.blockers,U.next_action].filter(Boolean).join(" ")}),k=$1(E.lessons,"Lessons (ranked; follow these — do not repeat known failures):",E.omitted);if(k)B.push("",k);if(K.lesson.durableViewVerdict(C.syncRulesFile,Z.capabilities.sessionStartContextReliable).writes){K.lesson.renderLessonsMarkdown(q,K.lesson.allLessons(q),C);let P=e3($.provider,q);X=P===null?0:r3(P)}}B.push(J.grind.enabled?"Grind ON: stop hook runs configured lint/test gates and auto-continues on failure.":"Grind OFF (default).");let L=B.join(`