"use strict";const _=require("./prompts-CEn2UsN4.cjs"),x=require("./get-user-input-D6l3Y8vJ.cjs"),B=require("zod"),n=require("./shared-types-B8BH5zz1.cjs"),h=require("./tool-usage-meter-rkJwRGsZ.cjs"),w=require("./telemetry-C8yrvnwb.cjs"),g=require("./tool-tags-D59Uxdr-.cjs"),y=require("./workspace-object-ChjgKU0j.cjs"),U=require("./unknown-error-DoEketMA.cjs"),T=require("./spec-platform-B-vK5eNN.cjs");function L(i){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(s,t,a.get?a:{enumerable:!0,get:()=>i[t]})}}return s.default=i,Object.freeze(s)}const l=L(B);var $=Object.defineProperty,M=Object.getOwnPropertyDescriptor,A=(i,s,t,a)=>{for(var e=M(s,t),r=i.length-1,o;r>=0;r--)(o=i[r])&&(e=o(s,t,e)||e);return e&&$(s,t,e),e};const j=w.getMetricReporterOrNoOp(n.TelemetryNamespace.Tool,"Tool.Prework.Detailed"),S={id:"prework",description:`Performs acceptance criteria testing prework for a feature design.
This tool stores prework analysis in context for later use in generating correctness properties.
For each criterion, you should determine if it's testable as a property, example, edge case, or not testable.

Use this tool BEFORE writing correctness properties in the design document.

The tool will store your analysis in context following this format:

X.Y Criteria Name
  Thoughts: step by step thoughts on whether or not this requirement is testable
  Testable: yes - property, yes - example, no, or edge-case

Example Usage:
- Analyze requirements: featureName="user-auth", preworkAnalysis="1.1 User login\\n  Thoughts: This is testable...\\n  Testable: yes - property"

Rules:
1. Complete the prework analysis BEFORE writing correctness properties in the design document
2. Each acceptance criterion must be analyzed for testability
3. Use the prework analysis to inform property generation`,schema:l.object({featureName:l.string().describe("The name of the feature being designed"),preworkAnalysis:l.string().describe("The complete prework analysis content following the required format")})};function R(i,s){try{const t=T.getSpecPlatformProvider().parseMarkdownRequirements(s),a=i.split(".");if(a.length===1){const e=t.find(r=>r.number===a[0]);if(e)return{startLine:e.startLine,endLine:e.endLine,text:e.userStory?.text||e.text}}else if(a.length===2){const e=t.find(r=>r.number===a[0]);if(e){const r=e.acceptanceCriteria.find(o=>o.number===a[1]);return r?{startLine:r.startLine,endLine:r.endLine,text:r.text}:{startLine:e.startLine,endLine:e.endLine,text:e.userStory?.text||e.text}}}}catch{}}function C(i,s){const t=[],a=i.split(`
`);let e=1;for(let r=0;r<a.length;r++){const c=a[r].trim().match(/^(\d+\.\d+)\s+(.+)$/);if(c){const u=c[1],k=c[2];let d=!1,m="";for(let p=r+1;p<Math.min(r+5,a.length);p++){const f=a[p].trim();if(f.startsWith("Thoughts:")&&(m=f.replace("Thoughts:","").trim()),f.match(/^Testable:\s*yes\s*-\s*property/i)){d=!0;break}if(f.match(/^\d+\.\d+\s+/))break}if(d){const p=s?R(u,s):void 0;t.push({number:e++,title:k,description:m||void 0,validates:`Requirements ${u}`,requirementRange:p?{startLine:p.startLine,endLine:p.endLine}:void 0,requirementText:p?.text})}}}return t}class P extends x.SyncTool{constructor(){super({id:S.id,description:S.description,schema:S.schema,tags:[g.ToolTags.SPEC,g.ToolTags.BUILTIN]})}async isBugfixSpec(s,t){try{const a=`.kiro/specs/${t}/.config.kiro`,e=await y.WorkspaceObject.fromRelativePath(s.execution.workspace,a),{content:r}=await s.execution.workspace.readFile({file:e});return JSON.parse(r.text).specType===n.SpecType.Bugfix}catch{return!1}}async handle({actionId:s,input:t,state:a,toolUse:e}){return j.callWithTrace("handleInput",async()=>{const r=h.ToolRecorder.start(h.Tool.Prework);a.execution.emit({type:"AgentExecutionAction",executionId:a.execution.executionId,actionId:s,actionState:n.OperationStatus.Running,actionType:"preWork"});try{const{featureName:o,preworkAnalysis:c}=t;if(!o)throw new Error("Feature name is required");if(!c)throw new Error("Prework analysis is required");const k=await this.isBugfixSpec(a,o)?"bugfix.md":"requirements.md",d=`.kiro/specs/${o}/${k}`;let m;try{const f=await y.WorkspaceObject.fromRelativePath(a.execution.workspace,d),{content:q}=await a.execution.workspace.readFile({file:f});m=q.text}catch{}const p=C(c,m);return a.execution.emit({type:"AgentExecutionAction",executionId:a.execution.executionId,actionId:s,actionState:n.OperationStatus.Success,actionType:"preWork",output:{message:c,properties:p,requirementsPath:d}}),r.recordToolSuccess(),this.withSyncToolMessage(a,e,`Prework analysis completed for feature "${o}". The analysis has been stored in context and can now be used to generate correctness properties in the design document.`,!0)}catch(o){const c=h.isAbortError(o),u=o instanceof Error?o:new U.UnknownError(String(o));return c?r.recordToolSuccess():r.recordToolFault(u),a.execution.emit({type:"AgentExecutionAction",executionId:a.execution.executionId,errorMessage:c?"":u.message,actionId:s,actionState:c?n.OperationStatus.Canceled:n.OperationStatus.Error,actionType:"preWork"}),this.withSyncToolMessage(a,e,`Error processing prework analysis: ${u.message}`,!1)}})}}A([w.Telemetry.Trace("Tool.Prework")],P.prototype,"handle");class O extends n.KiroError{get userFacingSessionErrorMessage(){return this.message}}class b extends n.KiroError{constructor(s){super(`Invalid PBT status: ${s}`)}get userFacingSessionErrorMessage(){return"Invalid PBT status parameters provided"}}var N=Object.defineProperty,W=Object.getOwnPropertyDescriptor,D=(i,s,t,a)=>{for(var e=W(s,t),r=i.length-1,o;r>=0;r--)(o=i[r])&&(e=o(s,t,e)||e);return e&&N(s,t,e),e};const z=l.enum(["passed","failed","not_run","unexpected_pass"]),I={id:"updatePBTStatus",description:`This tool updates the status of Property-Based Test (PBT) tasks after running tests.

Tool instructions:
- Use this tool after executing a PBT task and running the property-based test
- Set status to "passed" when the test passes successfully
- Set status to "failed" when the test fails, and include the failing example from the PBT library
- Set status to "unexpected_pass" when a bugfix exploration test passes unexpectedly (indicating the bug may not be properly reproduced)
- Set status to "not_run" to reset the test status (rarely used)
- The failing example should be the exact output provided by the PBT library (e.g., QuickCheck, Hypothesis, fast-check)
- Only use this tool on tasks that are identified as PBT tasks in the task list`,tags:[g.ToolTags.SPEC,g.ToolTags.BUILTIN],schema:l.object({taskFilePath:l.string().describe("The path to the `tasks.md` file for the spec/plan containing the PBT task. This path should be relative to the workspace root."),taskId:l.string().describe("The PBT task that you are updating the status of. It must match the text in the task file exactly. For example if the task file has the text `  - [ ] 2.1 Write property test for task creation`, you should call this tool with `2.1 Write property test for task creation`"),status:z.describe('The test execution status: "passed" if test succeeded, "failed" if test failed, "unexpected_pass" if test passed unexpectedly (for bugfix tests), "not_run" to reset status.'),failingExample:l.string().optional().nullable().describe('The failing example provided by the PBT library when the test fails. Include the exact counterexample that caused the test to fail. Required when status is "failed".')})};class F extends x.SyncTool{static id=I.id;constructor(){super(I)}async handle(s){const{state:t,actionId:a,input:e}=s,r=h.ToolRecorder.start(h.Tool.PBTStatus);try{T.getSpecPlatformProvider().validateFileAccess(e.taskFilePath),this.validateInput(e),this.emitEvent({state:t,actionId:a,actionState:n.OperationStatus.PendingAction,taskId:e.taskId,taskListUri:e.taskFilePath,pbtStatus:e.status,failingExample:e.failingExample??void 0});const o=await y.WorkspaceObject.fromRelativePath(t.execution.workspace,e.taskFilePath);await t.execution.workspace.updatePBTStatus({tasksPath:o,taskId:e.taskId,status:e.status,failingExample:e.failingExample??void 0,executionId:t.execution.executionId,chatSessionId:t.execution.chatSessionId}),this.emitEvent({state:t,actionId:a,actionState:n.OperationStatus.Success,taskId:e.taskId,taskListUri:e.taskFilePath,pbtStatus:e.status,failingExample:e.failingExample??void 0}),r.recordToolSuccess();const c=this.formatStatusMessage(e.status,e.failingExample??void 0);return this.withSyncToolMessage(t,s.toolUse,`PBT task "${e.taskId}" ${c}`,!0)}catch(o){return this.emitEvent({state:t,actionId:a,actionState:n.OperationStatus.Error,taskId:e.taskId,taskListUri:e.taskFilePath,pbtStatus:e.status,failingExample:e.failingExample??void 0}),r.recordToolFault(o),this.withSyncToolMessage(t,s.toolUse,`Caught error updating PBT status: ${o instanceof Error?o.message:String(o)}`,!1)}}validateInput(s){if(s.status==="failed"&&!s.failingExample)throw new b('Failing example is required when status is "failed"');if(s.status==="unexpected_pass"&&!s.failingExample)throw new b('Failing example is required when status is "unexpected_pass"')}formatStatusMessage(s,t){switch(s){case"passed":return"test passed successfully";case"failed":return`test failed${t?` with example: ${t}`:""}`;case"unexpected_pass":return"test passed unexpectedly (may not properly reproduce the bug)";case"not_run":return"test status reset to not run";default:return`status updated to ${s}`}}emitEvent({state:s,actionId:t,actionState:a,...e}){s.execution.emit({type:"AgentExecutionAction",executionId:s.execution.executionId,actionId:t,actionState:a,actionType:"pbtStatus",...e})}}D([w.Telemetry.Trace("Tool.PBTStatus")],F.prototype,"handle");var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,K=(i,s,t,a)=>{for(var e=H(s,t),r=i.length-1,o;r>=0;r--)(o=i[r])&&(e=o(s,t,e)||e);return e&&G(s,t,e),e};const E={id:"taskStatus",description:`This tool updates the status of tasks from the task list in the user's specs.

Tool instructions:
- Use this tool whenever you are executing a task from a spec/plan
- Always set the task status to in progress before you start making changes
- Always set the task status to complete when the task is fully complete
- When executing a task with sub-tasks, always start with the sub tasks. When all sub-tasks are complete, update the parent task to complete as well.
- If the model is not implementing an optional sub-task, then the sub-task should not be marked as completed.
- Never try to use this tool with tasks that are not defined in the spec/plan`,tags:[g.ToolTags.SPEC,g.ToolTags.BUILTIN],schema:l.object({taskFilePath:l.string().describe("The path to the `tasks.md` file for the spec/plan you are executing. This path should be relative to the workspace root."),task:l.string().describe("The task that you are updating the status of. It must match the text in the task file exactly. For example if the task file has the text `  - [-] 3.2 This is my task`, you should call this tool with `3.2 This is my task`"),status:l.nativeEnum(n.TaskStatus).describe("The status you are setting the task to.")})};class v extends x.SyncTool{static id=E.id;constructor(){super(E)}async handle(s){let{state:t}=s;const{actionId:a,input:e}=s,r=h.ToolRecorder.start(h.Tool.TaskStatus);try{T.getSpecPlatformProvider().validateFileAccess(e.taskFilePath),this.emitEvent({state:t,actionId:a,actionState:n.OperationStatus.PendingAction,taskId:e.task,taskListUri:e.taskFilePath,taskStatus:e.status});const o=await y.WorkspaceObject.fromRelativePath(t.execution.workspace,e.taskFilePath),c=e.task,u=await t.execution.workspace.validateTaskStatusChange({tasksPath:o,taskId:c,newStatus:e.status});if(!u.valid)throw new O(u.reason||"Cannot change task status");const k=await t.execution.workspace.getTaskMetadata({tasksPath:o,taskId:c});let d="";return u.warnings&&u.warnings.length>0&&(d=` Warning: ${u.warnings.join(" ")}`),await t.execution.workspace.updateTaskStatus({tasksPath:await y.WorkspaceObject.fromRelativePath(t.execution.workspace,e.taskFilePath),status:e.status,executionId:t.execution.executionId,chatSessionId:t.execution.chatSessionId,taskId:e.task}),this.emitEvent({state:t,actionId:a,actionState:n.OperationStatus.Success,taskId:e.task,taskListUri:e.taskFilePath,taskStatus:e.status}),r.recordToolSuccess(),e.status===n.TaskStatus.InProgress&&(t=await T.getSpecPlatformProvider().runPreTaskExecutionHooks(e.task,e.taskFilePath,t,s.toolUse?.requestMessageId)),e.status===n.TaskStatus.Completed&&(t=await T.getSpecPlatformProvider().runPostTaskExecutionHooks(e.task,e.taskFilePath,t,s.toolUse?.requestMessageId)),this.withSyncToolMessage({...t,specTaskId:k.isLeaf?e.task:void 0},s.toolUse,`Task "${e.task}" set to status "${e.status}"${d}`,!0)}catch(o){return this.emitEvent({state:t,actionId:a,actionState:n.OperationStatus.Error,taskId:e.task,taskListUri:e.taskFilePath,taskStatus:e.status}),r.recordToolFault(o),this.withSyncToolMessage(t,s.toolUse,`Caught error updating task status: ${o instanceof Error?o.message:String(o)}`,!1)}}emitEvent({state:s,actionId:t,actionState:a,...e}){s.execution.emit({type:"AgentExecutionAction",executionId:s.execution.executionId,actionId:t,actionState:a,actionType:"taskStatus",...e})}}K([w.Telemetry.Trace("Tool.TaskStatus")],v.prototype,"handle");const V=i=>_.isEmptyWorkspace(i)?[new x.GetUserInput,new P]:[new x.GetUserInput,new v,new F,new P];exports.InvalidPBTStatusError=b;exports.TaskStatusValidationError=O;exports.UpdateTaskStatus=v;exports.getSpecTools=V;
//# sourceMappingURL=index-_uSxrVd8.cjs.map
