@rpamis/comet 0.4.0-beta.13 → 0.4.0-beta.14

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 (87) hide show
  1. package/assets/manifest.json +1 -1
  2. package/assets/skills/comet/scripts/comet-archive.mjs +66 -66
  3. package/assets/skills/comet/scripts/comet-entry-runtime.mjs +1 -1
  4. package/assets/skills/comet/scripts/comet-guard.mjs +88 -88
  5. package/assets/skills/comet/scripts/comet-handoff.mjs +68 -68
  6. package/assets/skills/comet/scripts/comet-hook-guard.mjs +62 -62
  7. package/assets/skills/comet/scripts/comet-hook-router.mjs +64 -64
  8. package/assets/skills/comet/scripts/comet-resume-probe.mjs +55 -55
  9. package/assets/skills/comet/scripts/comet-runtime.mjs +134 -134
  10. package/assets/skills/comet/scripts/comet-state.mjs +67 -67
  11. package/assets/skills/comet/scripts/comet-yaml-validate.mjs +6 -6
  12. package/assets/skills/comet-native/scripts/comet-native-archive.mjs +39 -39
  13. package/assets/skills/comet-native/scripts/comet-native-check.mjs +45 -45
  14. package/assets/skills/comet-native/scripts/comet-native-checkpoint.mjs +35 -35
  15. package/assets/skills/comet-native/scripts/comet-native-doctor.mjs +33 -33
  16. package/assets/skills/comet-native/scripts/comet-native-evidence.mjs +7 -7
  17. package/assets/skills/comet-native/scripts/comet-native-hook-guard.mjs +7 -7
  18. package/assets/skills/comet-native/scripts/comet-native-init.mjs +6 -6
  19. package/assets/skills/comet-native/scripts/comet-native-new.mjs +44 -44
  20. package/assets/skills/comet-native/scripts/comet-native-next.mjs +27 -27
  21. package/assets/skills/comet-native/scripts/comet-native-receipt.mjs +24 -24
  22. package/assets/skills/comet-native/scripts/comet-native-root.mjs +31 -31
  23. package/assets/skills/comet-native/scripts/comet-native-runtime.mjs +43 -43
  24. package/assets/skills/comet-native/scripts/comet-native-select.mjs +41 -41
  25. package/assets/skills/comet-native/scripts/comet-native-show.mjs +7 -7
  26. package/assets/skills/comet-native/scripts/comet-native-spec.mjs +51 -51
  27. package/assets/skills/comet-native/scripts/comet-native-status.mjs +39 -39
  28. package/dist/app/commands/i18n.d.ts +1 -1
  29. package/dist/app/commands/i18n.d.ts.map +1 -1
  30. package/dist/app/commands/i18n.js +90 -0
  31. package/dist/app/commands/i18n.js.map +1 -1
  32. package/dist/app/commands/init.d.ts.map +1 -1
  33. package/dist/app/commands/init.js +2 -0
  34. package/dist/app/commands/init.js.map +1 -1
  35. package/dist/app/commands/project-scope-selection.d.ts +2 -1
  36. package/dist/app/commands/project-scope-selection.d.ts.map +1 -1
  37. package/dist/app/commands/project-scope-selection.js +5 -7
  38. package/dist/app/commands/project-scope-selection.js.map +1 -1
  39. package/dist/app/commands/uninstall.d.ts +6 -0
  40. package/dist/app/commands/uninstall.d.ts.map +1 -1
  41. package/dist/app/commands/uninstall.js +197 -110
  42. package/dist/app/commands/uninstall.js.map +1 -1
  43. package/dist/app/commands/update.d.ts.map +1 -1
  44. package/dist/app/commands/update.js +39 -1
  45. package/dist/app/commands/update.js.map +1 -1
  46. package/dist/domains/comet-classic/classic-layout-initialization.d.ts.map +1 -1
  47. package/dist/domains/comet-classic/classic-layout-initialization.js +8 -4
  48. package/dist/domains/comet-classic/classic-layout-initialization.js.map +1 -1
  49. package/dist/domains/comet-classic/classic-layout.d.ts.map +1 -1
  50. package/dist/domains/comet-classic/classic-layout.js +1 -0
  51. package/dist/domains/comet-classic/classic-layout.js.map +1 -1
  52. package/dist/domains/comet-entry/init-workflow.d.ts.map +1 -1
  53. package/dist/domains/comet-entry/init-workflow.js +2 -3
  54. package/dist/domains/comet-entry/init-workflow.js.map +1 -1
  55. package/dist/domains/integrations/openspec.d.ts.map +1 -1
  56. package/dist/domains/integrations/openspec.js +5 -2
  57. package/dist/domains/integrations/openspec.js.map +1 -1
  58. package/dist/domains/skill/platform-install.d.ts.map +1 -1
  59. package/dist/domains/skill/platform-install.js +32 -0
  60. package/dist/domains/skill/platform-install.js.map +1 -1
  61. package/dist/domains/skill/uninstall.d.ts +6 -2
  62. package/dist/domains/skill/uninstall.d.ts.map +1 -1
  63. package/dist/domains/skill/uninstall.js +142 -18
  64. package/dist/domains/skill/uninstall.js.map +1 -1
  65. package/dist/domains/workflow-contract/contained-atomic-write.d.ts +3 -0
  66. package/dist/domains/workflow-contract/contained-atomic-write.d.ts.map +1 -1
  67. package/dist/domains/workflow-contract/contained-atomic-write.js +15 -2
  68. package/dist/domains/workflow-contract/contained-atomic-write.js.map +1 -1
  69. package/dist/domains/workflow-contract/index.d.ts +1 -1
  70. package/dist/domains/workflow-contract/index.d.ts.map +1 -1
  71. package/dist/domains/workflow-contract/index.js +1 -1
  72. package/dist/domains/workflow-contract/index.js.map +1 -1
  73. package/dist/domains/workflow-contract/project-config-reader.d.ts +2 -0
  74. package/dist/domains/workflow-contract/project-config-reader.d.ts.map +1 -1
  75. package/dist/domains/workflow-contract/project-config-reader.js.map +1 -1
  76. package/dist/domains/workflow-contract/project-config-writer.d.ts.map +1 -1
  77. package/dist/domains/workflow-contract/project-config-writer.js +3 -2
  78. package/dist/domains/workflow-contract/project-config-writer.js.map +1 -1
  79. package/dist/domains/workflow-contract/project-config.d.ts +1 -0
  80. package/dist/domains/workflow-contract/project-config.d.ts.map +1 -1
  81. package/dist/domains/workflow-contract/project-config.js +9 -4
  82. package/dist/domains/workflow-contract/project-config.js.map +1 -1
  83. package/dist/platform/install/platforms.d.ts +2 -0
  84. package/dist/platform/install/platforms.d.ts.map +1 -1
  85. package/dist/platform/install/platforms.js +1 -0
  86. package/dist/platform/install/platforms.js.map +1 -1
  87. package/package.json +1 -1
@@ -139,12 +139,12 @@ ${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.pus
139
139
  `)+1;for(;t!==0;)this.onNewLine(this.offset+t),t=this.source.indexOf(`
140
140
  `,t)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,t.value){let n="end"in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type==="comment"?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){pi(r,t.start),r.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let n=!this.onKeyLine&&this.indent===e.indent,r=n&&(t.sep||t.explicitKey)&&this.type!=="seq-item-ind",s=[];if(r&&t.sep&&!t.value){let o=[];for(let a=0;a<t.sep.length;++a){let c=t.sep[a];switch(c.type){case"newline":o.push(a);break;case"space":break;case"comment":c.indent>e.indent&&(o.length=0);break;default:o.length=0}}o.length>=2&&(s=t.sep.splice(o[1]))}switch(this.type){case"anchor":case"tag":r||t.value?(s.push(this.sourceToken),e.items.push({start:s}),this.onKeyLine=!0):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"explicit-key-ind":!t.sep&&!t.explicitKey?(t.start.push(this.sourceToken),t.explicitKey=!0):r||t.value?(s.push(this.sourceToken),e.items.push({start:s,explicitKey:!0})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case"map-value-ind":if(t.explicitKey)if(t.sep)if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(te(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:null,sep:[this.sourceToken]}]});else if(sa(t.key)&&!te(t.sep,"newline")){let o=Pe(t.start),a=t.key,c=t.sep;c.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:a,sep:c}]})}else s.length>0?t.sep=t.sep.concat(s,this.sourceToken):t.sep.push(this.sourceToken);else if(te(t.start,"newline"))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let o=Pe(t.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:null,sep:[this.sourceToken]}]})}else t.sep?t.value||r?e.items.push({start:s,key:null,sep:[this.sourceToken]}):te(t.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let o=this.flowScalar(this.type);r||t.value?(e.items.push({start:s,key:o,sep:[]}),this.onKeyLine=!0):t.sep?this.stack.push(o):(Object.assign(t,{key:o,sep:[]}),this.onKeyLine=!0);return}default:{let o=this.startBlockValue(e);if(o){if(o.type==="block-seq"){if(!t.explicitKey&&t.sep&&!te(t.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else n&&e.items.push({start:s});this.stack.push(o);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let t=e.items[e.items.length-1];switch(this.type){case"newline":if(t.value){let n="end"in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type==="comment"?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){pi(r,t.start),r.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return;case"anchor":case"tag":if(t.value||this.indent<=e.indent)break;t.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==e.indent)break;t.value||te(t.start,"seq-item-ind")?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return}if(this.indent>e.indent){let n=this.startBlockValue(e);if(n){this.stack.push(n);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type==="flow-error-end"){let n;do yield*this.pop(),n=this.peek(1);while(n?.type==="flow-collection")}else if(e.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":!t||t.sep?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return;case"map-value-ind":!t||t.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":!t||t.value?e.items.push({start:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let r=this.flowScalar(this.type);!t||t.value?e.items.push({start:[],key:r,sep:[]}):t.sep?this.stack.push(r):Object.assign(t,{key:r,sep:[]});return}case"flow-map-end":case"flow-seq-end":e.end.push(this.sourceToken);return}let n=this.startBlockValue(e);n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let n=this.peek(2);if(n.type==="block-map"&&(this.type==="map-value-ind"&&n.indent===e.indent||this.type==="newline"&&!n.items[n.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&n.type!=="flow-collection"){let r=di(n),s=Pe(r);ra(e);let o=e.end.splice(1,e.end.length);o.push(this.sourceToken);let a={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:s,key:e,sep:o}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=a}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let t=this.source.indexOf(`
141
141
  `)+1;for(;t!==0;)this.onNewLine(this.offset+t),t=this.source.indexOf(`
142
- `,t)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let t=di(e),n=Pe(t);return n.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let t=di(e),n=Pe(t);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!=="comment"||this.indent<=t?!1:e.every(n=>n.type==="newline"||n.type==="space")}*documentEnd(e){this.type!=="doc-mode"&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}};oa.Parser=nr});var fa=y(it=>{"use strict";var aa=Yn(),Zf=Je(),tt=Ge(),ed=Fi(),td=_(),id=ir(),ca=rr();function la(i){let e=i.prettyErrors!==!1;return{lineCounter:i.lineCounter||e&&new id.LineCounter||null,prettyErrors:e}}function nd(i,e={}){let{lineCounter:t,prettyErrors:n}=la(e),r=new ca.Parser(t?.addNewLine),s=new aa.Composer(e),o=Array.from(s.compose(r.parse(i)));if(n&&t)for(let a of o)a.errors.forEach(tt.prettifyError(i,t)),a.warnings.forEach(tt.prettifyError(i,t));return o.length>0?o:Object.assign([],{empty:!0},s.streamInfo())}function ua(i,e={}){let{lineCounter:t,prettyErrors:n}=la(e),r=new ca.Parser(t?.addNewLine),s=new aa.Composer(e),o=null;for(let a of s.compose(r.parse(i),!0,i.length))if(!o)o=a;else if(o.options.logLevel!=="silent"){o.errors.push(new tt.YAMLParseError(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return n&&t&&(o.errors.forEach(tt.prettifyError(i,t)),o.warnings.forEach(tt.prettifyError(i,t))),o}function rd(i,e,t){let n;typeof e=="function"?n=e:t===void 0&&e&&typeof e=="object"&&(t=e);let r=ua(i,t);if(!r)return null;if(r.warnings.forEach(s=>ed.warn(r.options.logLevel,s)),r.errors.length>0){if(r.options.logLevel!=="silent")throw r.errors[0];r.errors=[]}return r.toJS(Object.assign({reviver:n},t))}function sd(i,e,t){let n=null;if(typeof e=="function"||Array.isArray(e)?n=e:t===void 0&&e&&(t=e),typeof t=="string"&&(t=t.length),typeof t=="number"){let r=Math.round(t);t=r<1?void 0:r>8?{indent:8}:{indent:r}}if(i===void 0){let{keepUndefined:r}=t??e??{};if(!r)return}return td.isDocument(i)&&!n?i.toString(t):new Zf.Document(i,n,t).toString(t)}it.parse=rd;it.parseAllDocuments=nd;it.parseDocument=ua;it.stringify=sd});var or=y(P=>{"use strict";var od=Yn(),ad=Je(),cd=En(),sr=Ge(),ld=Ie(),ie=_(),ud=Q(),fd=O(),dd=Z(),pd=ee(),md=ui(),hd=er(),gd=ir(),wd=rr(),mi=fa(),da=Ne();P.Composer=od.Composer;P.Document=ad.Document;P.Schema=cd.Schema;P.YAMLError=sr.YAMLError;P.YAMLParseError=sr.YAMLParseError;P.YAMLWarning=sr.YAMLWarning;P.Alias=ld.Alias;P.isAlias=ie.isAlias;P.isCollection=ie.isCollection;P.isDocument=ie.isDocument;P.isMap=ie.isMap;P.isNode=ie.isNode;P.isPair=ie.isPair;P.isScalar=ie.isScalar;P.isSeq=ie.isSeq;P.Pair=ud.Pair;P.Scalar=fd.Scalar;P.YAMLMap=dd.YAMLMap;P.YAMLSeq=pd.YAMLSeq;P.CST=md;P.Lexer=hd.Lexer;P.LineCounter=gd.LineCounter;P.Parser=wd.Parser;P.parse=mi.parse;P.parseAllDocuments=mi.parseAllDocuments;P.parseDocument=mi.parseDocument;P.stringify=mi.stringify;P.visit=da.visit;P.visitAsync=da.visitAsync});var ht=Cr(or(),1);import qa from"path";import{promises as Hd}from"fs";import Ei from"path";import{promises as Md}from"fs";import x from"path";import{promises as yd}from"fs";async function ar(i){try{return await yd.access(i),!0}catch(e){if(vd(e))return!1;throw e}}function vd(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}var fr=Cr(or(),1);import hi from"path";var wi=64*1024,lr=1024,ur=64,bd=5,kd=[".agents/skills/**",".amazonq/skills/**",".augment/skills/**",".bob/skills/**",".claude/skills/**",".cline/skills/**",".codebuddy/skills/**",".continue/skills/**",".cospec/skills/**",".crush/skills/**",".cursor/skills/**",".factory/skills/**",".forge/skills/**",".gemini/skills/**",".github/skills/**",".iflow/skills/**",".junie/skills/**",".kilocode/skills/**",".kimi-code/skills/**",".kiro/skills/**",".lingma/skills/**",".mimocode/skills/**",".opencode/skills/**",".pi/skills/**",".qoder/skills/**",".qwen/skills/**",".roo/skills/**",".trae-cn/skills/**",".trae/skills/**",".windsurf/skills/**",".zcode/skills/**"],Y={include:["**/*"],exclude:[...kd],max_files:1e4,max_total_bytes:256*1024*1024,max_duration_ms:6e4};function Sd(i,e){if(typeof i!="string")throw new Error(`${e} must be a string`);let t=i.trim();if(t.length===0||hi.posix.isAbsolute(t)||hi.win32.isAbsolute(t)||/^(?:~|[\\/])/u.test(t))throw new Error(`${e} must be a project-relative path`);if(t===".")return[];let n=t.replaceAll("\\","/").split("/");if(n.some(r=>r===".."))throw new Error(`${e} must stay inside the project root`);if(n.some(r=>r===""||r==="."))throw new Error(`${e} must not contain empty or dot path segments`);return n}function gi(i){let e=Sd(i,"native.artifact_root");return e.length===0?".":e.join("/")}function ma(i,e="docs"){let t=i??e;if(t!=="legacy"&&t!=="docs")throw new Error("classic.artifact_layout must be legacy or docs");return t}function rt(i,e,t=!1){if(typeof i!="string")throw new Error(`${e} must be a string`);let n=i.trim().replaceAll("\\","/");if(n.length===0||hi.posix.isAbsolute(n)||hi.win32.isAbsolute(n)||/^(?:~|[\\/])/u.test(n))throw new Error(`${e} must be relative to its declared path base`);let r=n.split("/");if(r.some(s=>s===".."))throw new Error(`${e} must stay inside its declared path base`);if(r.some(s=>s===""||s==="."))throw new Error(`${e} must not contain empty or dot path segments`);if(!t&&/[*?]/u.test(n))throw new Error(`${e} cannot contain wildcards`);return r.join("/")}function nt(i,e){if(!i||typeof i!="object"||Array.isArray(i))throw new Error(`${e} must be a mapping`);return i}function ha(i,e,t){let n=i??e;if(n!=="en"&&n!=="zh-CN")throw new Error(`${t} must be en or zh-CN`);return n}function ga(i,e){if(typeof i!="string"||i.length===0||i.includes("\\")||i.includes("\0")||i.startsWith("/")||i.split("/").includes(".."))throw new Error(`${e} contains an unsafe pattern`);if(i.length>lr)throw new Error(`${e} exceeds ${lr} characters`);let t=0;for(let n=0;n<i.length;n+=1)i[n]==="?"?t+=1:i[n]==="*"&&(t+=1,i[n+1]==="*"&&(n+=1));if(t>ur)throw new Error(`${e} contains more than ${ur} wildcard tokens`);return i}function pa(i,e,t){if(i===void 0)return[...t];if(!Array.isArray(i))throw new Error(`${e} contains an unsafe pattern`);return[...new Set(i.map(n=>ga(n,e)))].sort((n,r)=>n.localeCompare(r,"en"))}function cr(i,e,t){let n=i??e;if(!Number.isSafeInteger(n)||n<1)throw new Error(`${t} must be a positive integer`);return n}function Cd(i){if(i===void 0)return{...Y,include:[...Y.include],exclude:[...Y.exclude]};let e=nt(i,"native.snapshot");return{include:pa(e.include,"native.snapshot.include",Y.include),exclude:pa(e.exclude,"native.snapshot.exclude",Y.exclude),max_files:cr(e.max_files,Y.max_files,"native.snapshot.max_files"),max_total_bytes:cr(e.max_total_bytes,Y.max_total_bytes,"native.snapshot.max_total_bytes"),max_duration_ms:cr(e.max_duration_ms,Y.max_duration_ms,"native.snapshot.max_duration_ms")}}function Ed(i){if(i===void 0)return;let e=nt(i,"native.pending_root_move"),t=e.id,n=e.from_artifact_root,r=e.to_artifact_root,s=e.stage;if(typeof t!="string"||!/^[a-f0-9-]{8,}$/u.test(t))throw new Error("native.pending_root_move.id is invalid");if(typeof n!="string"||typeof r!="string")throw new Error("native.pending_root_move roots must be strings");if(s!=="copying"&&s!=="ready"&&s!=="switched")throw new Error("native.pending_root_move.stage is invalid");let o;if(e.cleanup!==void 0){let a=nt(e.cleanup,"native.pending_root_move.cleanup"),c=a.kind,l=a.state,m=a.manifest_hash;if(c!=="forward-source"&&c!=="restart-staging"&&c!=="rollback-destination"&&c!=="rollback-staging")throw new Error("native.pending_root_move.cleanup.kind is invalid");if(l!=="prepared"&&l!=="quarantined"&&l!=="deleting")throw new Error("native.pending_root_move.cleanup.state is invalid");if(typeof m!="string"||!/^[a-f0-9]{64}$/u.test(m))throw new Error("native.pending_root_move.cleanup.manifest_hash is invalid");o={kind:c,state:l,manifestHash:m}}return{id:t,fromArtifactRoot:gi(n),toArtifactRoot:gi(r),stage:s,...o?{cleanup:o}:{}}}function _d(i){let e=nt(i,"native");if(typeof e.artifact_root!="string")throw new Error("native.artifact_root must be a string");let t=e.clarification_mode??"sequential";if(t!=="sequential"&&t!=="batch")throw new Error("native.clarification_mode must be sequential or batch");let n=e.archive_confirmation??"automatic";if(n!=="automatic"&&n!=="required")throw new Error("native.archive_confirmation must be automatic or required");let r=e.max_verify_failures??bd;if(!Number.isSafeInteger(r)||r<1)throw new Error("native.max_verify_failures must be a positive integer");let s=Ed(e.pending_root_move);return{artifact_root:gi(e.artifact_root),language:ha(e.language,"en","native.language"),clarification_mode:t,archive_confirmation:n,max_verify_failures:r,snapshot:Cd(e.snapshot),...s?{pending_root_move:s}:{}}}function Pd(i){let e=nt(i,"classic"),t=e.context_compression??"off";if(t!=="off"&&t!=="beta")throw new Error("classic.context_compression must be off or beta");let n=e.review_mode??"standard";if(n!=="off"&&n!=="standard"&&n!=="thorough")throw new Error("classic.review_mode must be off, standard, or thorough");let r=e.auto_transition??!0;if(typeof r!="boolean")throw new Error("classic.auto_transition must be true or false");return{artifact_layout:ma(e.artifact_layout),language:ha(e.language,"zh-CN","classic.language"),context_compression:t,review_mode:n,auto_transition:r}}function Nd(i){let e=i??!0;if(typeof e!="boolean")throw new Error("ambient_resume must be true or false");return e}function Od(i,e,t,n,r){let s=i.schema!==void 0;if(!(s||i.default_workflow!==void 0||i.workflows!==void 0||!r.allowPartialProject&&i.native!==void 0)||r.allowPartialProject&&!s)return null;if(i.schema!=="comet.project.v1")throw new Error("Unsupported Comet project schema");if(i.default_workflow!=="native"&&i.default_workflow!=="classic")throw new Error("default_workflow must be native or classic");let a=i.workflows??[i.default_workflow];if(!Array.isArray(a)||a.length===0||a.some(l=>l!=="native"&&l!=="classic"))throw new Error("workflows must contain native and/or classic");let c=[...new Set(a)];if(!c.includes(i.default_workflow))throw new Error("workflows must include default_workflow");if(c.includes("native")&&!e)throw new Error("native must be a mapping");return{schema:"comet.project.v1",default_workflow:i.default_workflow,workflows:c,ambient_resume:n,...e?{native:e}:{},...t?{classic:t}:{}}}function st(i,e={}){let t=(0,fr.parseDocument)(i,{uniqueKeys:!0});if(t.errors.length>0)throw new Error(`Invalid .comet/config.yaml: ${t.errors[0].message}`);let n=t.toJS();if(n==null)return{value:{},config:null,ambient_resume:!0};if(typeof n!="object"||Array.isArray(n))throw new Error("Invalid .comet/config.yaml: root must be a mapping");let r=n,s=Nd(r.ambient_resume),o=r.native===void 0?void 0:_d(r.native),a=r.classic===void 0?void 0:Pd(r.classic),c=Od(r,o,a,s,{allowPartialProject:e.allowPartialProject??!1});return{value:r,config:c,ambient_resume:s,...o?{native:o}:{},...a?{classic:a}:{}}}import{createHash as Ad}from"crypto";import{promises as bi}from"fs";import se from"path";import{constants as yi,promises as pe}from"fs";function ne(i){return i!==0&&i!==0n&&i!=="0"}function dr(i,e){return ne(i.dev)&&ne(e.dev)&&ne(i.ino)&&ne(e.ino)}function ot(i,e){let t=ne(i.dev)&&ne(e.dev);if(t&&i.dev!==e.dev)return!1;let n=ne(i.ino)&&ne(e.ino);return n&&i.ino!==e.ino?!1:t&&n?!0:i.birthtime===e.birthtime}var re=class extends Error{reason;constructor(e,t,n){super(t,n),this.name="RaceSafeReadError",this.reason=e}};function pr(i){return"birthtimeNs"in i&&typeof i.birthtimeNs=="bigint"?i.birthtimeNs:i.birthtimeMs}function wa(i){return"ctimeNs"in i&&typeof i.ctimeNs=="bigint"?i.ctimeNs:i.ctimeMs}function at(i){return{dev:i.dev,ino:i.ino,birthtime:pr(i)}}function vi(i,e){let t=at(i),n=at(e);return dr(t,n)?ot(t,n):ot(t,n)&&pr(i)===pr(e)&&wa(i)===wa(e)&&i.size===e.size}async function ya(i,e,t={}){if(!Number.isSafeInteger(e)||e<1)throw new Error("race-safe read byte limit must be a positive integer");let n=t.label??"file",r=t.bigint===!0,s=await pe.lstat(i,{bigint:r});if(!s.isFile()||s.isSymbolicLink())throw new re("not-regular-file",`${n} must be a regular file`);if(BigInt(s.size)>BigInt(e))throw new re("too-large",`${n} exceeds ${e} bytes`);let o=await pe.realpath(i);await t.verify?.("pre-open",{realPath:o,identity:at(s)});let a=process.platform==="win32"?yi.O_RDONLY:yi.O_RDONLY|yi.O_NOFOLLOW|yi.O_NONBLOCK,c;try{c=await pe.open(i,a)}catch(l){throw l.code==="ELOOP"?new re("not-regular-file",`${n} must be a regular file`,{cause:l}):l}try{let[l,m,u]=await Promise.all([c.stat({bigint:r}),pe.lstat(i,{bigint:r}),pe.realpath(i)]);if(!l.isFile()||!m.isFile()||m.isSymbolicLink()||u!==o||!vi(s,l)||!vi(s,m))throw new re("changed",`${n} changed while opening`);await t.verify?.("post-open",{realPath:u,identity:at(l)}),await t.hooks?.afterOpen?.();let d=[],h=0,w=Buffer.allocUnsafe(Math.min(64*1024,e+1));for(;;){let v=e+1-h,{bytesRead:k}=await c.read(w,0,Math.min(w.length,v),null);if(k===0)break;if(h+=k,h>e)throw new re("too-large",`${n} exceeds ${e} bytes`);d.push(Buffer.from(w.subarray(0,k)))}await t.hooks?.beforeFinalCheck?.();let[f,p,g]=await Promise.all([c.stat({bigint:r}),pe.lstat(i,{bigint:r}),pe.realpath(i)]);if(!p.isFile()||p.isSymbolicLink()||g!==o||!vi(s,f)||!vi(s,p))throw new re("changed",`${n} changed while reading`);return await t.verify?.("post-read",{realPath:g,identity:at(f)}),{bytes:Buffer.concat(d,h),stat:f,realPath:g}}finally{await c.close()}}function xd(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}function mr(i,e){let t=se.relative(i,e);return t===""||!se.isAbsolute(t)&&t!==".."&&!t.startsWith(`..${se.sep}`)}async function va(i,e){let t=se.resolve(i),n=await bi.lstat(t);if(!n.isDirectory()||n.isSymbolicLink())throw new Error(`${e} project root must be a real directory`);return bi.realpath(t)}async function ba(i,e,t,n){let r=i;for(let s=0;s<t.length;s++){r=se.join(r,t[s]);let o;try{o=await bi.lstat(r)}catch(m){if(xd(m))return{exists:!1,kind:"missing"};throw m}let a=se.relative(i,r).replaceAll("\\","/");if(o.isSymbolicLink())throw new Error(`${n.label} crosses a symbolic link or junction at ${a}`);let c=s===t.length-1;if(!c&&!o.isDirectory())throw new Error(`${n.label} ancestor ${a} must be a real directory`);if(c&&(n.expected==="file"&&!o.isFile()||n.expected==="directory"&&!o.isDirectory()||n.expected==="any"&&!o.isFile()&&!o.isDirectory()))throw new Error(`${n.label} must be a real ${n.expected}`);let l=await bi.realpath(r);if(!mr(e,l))throw new Error(`${n.label} resolves outside the project root`);if(c)return{exists:!0,kind:o.isFile()?"file":o.isDirectory()?"directory":"missing"}}return{exists:!0,kind:"directory"}}async function D(i,e,t){let n=rt(e,t.label),r=se.resolve(i),s=await va(r,t.label),o=n.split("/"),a=se.resolve(r,...o);if(!mr(r,a))throw new Error(`${t.label} must stay inside the project root`);let c=await ba(r,s,o,t);return{projectRoot:r,target:a,relative:n,exists:c.exists,kind:c.kind}}async function oe(i,e,t,n){let r=await D(i,e,{label:n.label,expected:"file"});if(!r.exists){let o=new Error(`${n.label} does not exist`);throw o.code="ENOENT",o}let s=await va(r.projectRoot,n.label);return ya(r.target,t,{...n,verify:async(o,a)=>{if(!mr(s,a.realPath))throw new Error(`${n.label} resolves outside the project root`);await ba(r.projectRoot,s,r.relative.split("/"),{label:n.label,expected:"file"})}})}var ct=".comet/config.yaml";function Id(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}async function ki(i,e={}){return(await Si(i,e)).document}async function Rd(i){try{return(await oe(i,ct,wi,{label:ct})).bytes}catch(e){if(Id(e))return null;throw e}}function jd(i){return i?{exists:!0,sha256:Ad("sha256").update(i).digest("hex")}:{exists:!1,sha256:null}}async function Si(i,e={}){let t=await Rd(i);return{document:t?st(t.toString("utf8"),e):null,identity:jd(t)}}var ih=16*1024;var lt=class extends Error{code="classic-layout-unavailable";constructor(e="Classic artifact layout is unavailable from .comet/config.yaml"){super(e),this.name="ClassicLayoutUnavailableError"}},hr=class extends Error{constructor(t,n,r){let s=U(r,t),o=U(r,n);super(`Classic layout conflict: both ${s}/ and ${o}/ exist; run comet doctor and resolve the conflict before writing`);this.configuredRoot=t;this.alternateRoot=n;this.name="ClassicLayoutConflictError"}configuredRoot;alternateRoot;code="classic-layout-conflict"},Ca=".comet/config.yaml";function Wd(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}async function Ea(i){await D(i,Ca,{label:Ca,expected:"file"})}function _a(i,e){let t=x.resolve(i),n=e==="docs"?x.join(t,"docs"):t,r=x.join(n,"openspec"),s=x.join(t,"docs","superpowers");return{projectRoot:t,artifactLayout:e,openSpecBase:n,openSpecRoot:r,changesDir:x.join(r,"changes"),archiveDir:x.join(r,"changes","archive"),specsDir:x.join(r,"specs"),superpowersRoot:s,superpowersSpecsDir:x.join(s,"specs"),superpowersPlansDir:x.join(s,"plans"),superpowersReportsDir:x.join(s,"reports")}}async function Fd(i){await Ea(i);let e=await ki(i,{allowPartialProject:!0});if(!e?.config)throw new lt;if(!(e.config.workflows??[e.config.default_workflow]).includes("classic"))throw new lt("Classic artifact layout is unavailable because Classic is not enabled");return e.classic?.artifact_layout??"legacy"}async function Bd(i,e){return _a(i,e??await Fd(i))}async function Kd(i,e){let t=await Bd(i,e),n=t.artifactLayout==="legacy"?"docs":"legacy",r=_a(i,n).openSpecRoot,[s,o]=await Promise.all([D(t.projectRoot,U(t.projectRoot,t.openSpecRoot),{label:"Configured Classic OpenSpec root",expected:"directory"}),D(t.projectRoot,U(t.projectRoot,r),{label:"Alternate Classic OpenSpec root",expected:"directory"})]),a=s.exists,c=o.exists;return{paths:t,configuredRootExists:a,alternateRoot:r,alternateRootExists:c,dualRoots:a&&c}}async function Yd(i,e){let t=[i.openSpecRoot,i.changesDir,i.archiveDir,i.specsDir,e,i.superpowersRoot,i.superpowersSpecsDir,i.superpowersPlansDir,i.superpowersReportsDir];for(let n of t){let r=U(i.projectRoot,n);await D(i.projectRoot,r,{label:`Classic managed physical path ${r}`,expected:"directory"})}}async function Pa(i,e,t={}){let n=await Kd(i,e);if(await Yd(n.paths,n.alternateRoot),n.dualRoots&&!t.allowAlternateRoot)throw new hr(n.paths.openSpecRoot,n.alternateRoot,n.paths.projectRoot);if(!n.configuredRootExists){let r=U(n.paths.projectRoot,n.paths.openSpecRoot),s=U(n.paths.projectRoot,n.alternateRoot);throw new lt(`Configured Classic OpenSpec root is missing: ${r} (alternate ${s} is ${n.alternateRootExists?"present":"missing"})`)}return n.paths}async function Na(i){let e=x.resolve(i),t=null;try{(await Md.lstat(e)).isDirectory()||(e=x.dirname(e))}catch(n){if(!Wd(n))throw n}for(;;){x.basename(e)==="openspec"&&(t=x.dirname(e));let n=x.join(e,".comet","config.yaml"),r=!1;if(await ar(n))try{await Ea(e);let o=(await ki(e))?.value;r=!!o&&typeof o=="object"&&!Array.isArray(o)&&(o.schema==="comet.project.v1"||o.default_workflow!==void 0||o.native!==void 0)}catch{}if(r||await ar(x.join(e,".git")))return e;let s=x.dirname(e);if(s===e)return t??x.resolve(i);e=s}}function U(i,e){return x.relative(x.resolve(i),e).replaceAll("\\","/")}import ut from"path";var Vd=2*1024*1024;function Oa(i,e,t){let n=ut.resolve(i),r=ut.isAbsolute(e)?ut.resolve(e):ut.resolve(n,e),s=ut.relative(n,r).replaceAll("\\","/");return{root:n,relative:rt(s,t),target:r}}async function ft(i,e,t){let n=Oa(i,e,t.label);return D(n.root,n.relative,t)}async function xa(i,e,t){return(await ft(i,e,{label:t.label,expected:t.expected??"any"})).exists}async function Aa(i,e,t){return(await Jd(i,e,t)).toString("utf8")}async function Jd(i,e,t){let n=Oa(i,e,t.label);return(await oe(n.root,n.relative,t.maxBytes??Vd,{label:t.label,hooks:t.hooks})).bytes}function wr(i){return i?/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(i)?i.includes("..")?"Change name cannot contain '..' (path traversal not allowed)":null:`Invalid change name: '${i}'
143
- Valid format: lowercase kebab-case (a-z, 0-9, single hyphens)`:"Change name cannot be empty"}function zd(i){let e=wr(i);if(e)throw new Error(e)}function Gd(i,e){return{label:U(i,e),directory:e}}async function gr(i,e,t){let n=Gd(i,e);if(!(await ft(i,e,{label:t,expected:"directory"})).exists)return{change:n,exists:!1,stateExists:!1};let s=await ft(i,Ei.join(e,".comet.yaml"),{label:`${t} state`,expected:"file"});return{change:n,exists:!0,stateExists:s.exists}}function Qd(i,e){let t=e.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&");return new RegExp(`^\\d{4}-\\d{2}-\\d{2}-${t}$`,"u").test(i)}async function Xd(i,e,t,n={}){if(!n.skipExactCompatibility){let o=await gr(i,Ei.join(e,t),`Classic archived change ${t}`);if(o.exists)return o.change}if(!(await ft(i,e,{label:"Classic archive directory",expected:"directory"})).exists)return null;let s=[];for(let o of await Hd.readdir(e,{withFileTypes:!0})){if(!Qd(o.name,t))continue;let a=await gr(i,Ei.join(e,o.name),`Classic archived change ${o.name}`);a.exists&&a.stateExists&&s.push(a.change)}return s.sort((o,a)=>a.directory.localeCompare(o.directory))[0]??null}async function Ia(i,e=process.cwd()){zd(i);let t=await Pa(e),n=await gr(t.projectRoot,Ei.join(t.changesDir,i),`Classic active change ${i}`);if(n.exists)return n.change;let r=await Xd(t.projectRoot,t.archiveDir,i);return r||n.change}var bg=256*1024;var yr=["workflow","language","phase","context_compression","build_mode","build_pause","subagent_dispatch","tdd_mode","review_mode","isolation","bound_branch","verify_mode","auto_transition","base_ref","design_doc","plan","verify_result","verify_failures","verification_report","branch_status","created_at","verified_at","archive_confirmation","archived","direct_override","handoff_context","handoff_hash","classic_profile","classic_migration"],vr=["run_id"],Eg=new Set([...yr,...vr]);import{AsyncLocalStorage as sp}from"async_hooks";import{promises as Ra}from"fs";import dt from"path";var br=new sp;function op(i,e){let t=dt.relative(i,e);return t===""||!dt.isAbsolute(t)&&t!==".."&&!t.startsWith(`..${dt.sep}`)}async function ap(i){let e=dt.resolve(i.invocationCwd??process.cwd()),t=dt.resolve(i.projectRoot??await Na(e)),[n,r]=await Promise.all([Ra.realpath(e),Ra.realpath(t)]);if(!op(r,n))throw new Error(`Classic command invocation cwd is outside the discovered project: ${e}`);return{invocationCwd:e,projectRoot:t}}async function ja(i,e){let t=br.getStore();if(t)return e(t);let n=await ap(i);return br.run(n,()=>e(n))}function Ta(){let i=br.getStore();if(!i)throw new Error("Classic command project context is unavailable");return i.projectRoot}var cp="\x1B[32m",pt="\x1B[31m",lp="\x1B[33m",up="\x1B[0m",fp=["workflow","phase","design_doc","plan","build_mode","isolation","verify_mode","verify_result","verified_at","archived"],dp={workflow:["full","hotfix","tweak"],language:["en","zh-CN"],phase:["open","design","build","verify","archive"],context_compression:["off","beta"],build_mode:["subagent-driven-development","executing-plans","direct"],build_pause:["plan-ready"],subagent_dispatch:["confirmed"],tdd_mode:["tdd","direct"],review_mode:["off","standard","thorough"],isolation:["current","branch","worktree"],verify_mode:["light","full"],auto_transition:["true","false"],verify_result:["pending","pass","fail"],branch_status:["pending","handled"],archive_confirmation:["pending","confirmed"],archived:["true","false"],direct_override:["true","false"],classic_profile:["full","hotfix","tweak"],classic_migration:["1"]},pp=new Set([...yr,...vr,"classic_profile","classic_migration"]);function me(i,e){return`${i}${e}${up}`}function mt(i){return i==null?"":typeof i=="object"?JSON.stringify(i):String(i)}var La=async(i,e)=>ja(e,async()=>{let t=i[0],n=wr(t);if(n)return{exitCode:1,stderr:me(pt,`ERROR: ${n}`)};let r=Ta(),{directory:s,label:o}=await Ia(t,r),a=qa.join(s,".comet.yaml"),c=[`[VALIDATE] ${o}/.comet.yaml`],l=0,m=0,u=p=>{l+=1,c.push(me(pt,` FAIL: ${p}`))},d=p=>{m+=1,c.push(me(lp,` WARN: ${p}`))},h;try{h=await Aa(r,a,{label:`Classic state ${o}/.comet.yaml`})}catch(p){if(p.code==="ENOENT")return u(".comet.yaml does not exist"),c.push("",me(pt,`${l} error(s), ${m} warning(s) — validation FAILED`)),{exitCode:1,stderr:c.join(`
142
+ `,t)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let t=di(e),n=Pe(t);return n.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let t=di(e),n=Pe(t);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!=="comment"||this.indent<=t?!1:e.every(n=>n.type==="newline"||n.type==="space")}*documentEnd(e){this.type!=="doc-mode"&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}};oa.Parser=nr});var fa=y(it=>{"use strict";var aa=Yn(),Zf=Je(),tt=Ge(),ed=Fi(),td=_(),id=ir(),ca=rr();function la(i){let e=i.prettyErrors!==!1;return{lineCounter:i.lineCounter||e&&new id.LineCounter||null,prettyErrors:e}}function nd(i,e={}){let{lineCounter:t,prettyErrors:n}=la(e),r=new ca.Parser(t?.addNewLine),s=new aa.Composer(e),o=Array.from(s.compose(r.parse(i)));if(n&&t)for(let a of o)a.errors.forEach(tt.prettifyError(i,t)),a.warnings.forEach(tt.prettifyError(i,t));return o.length>0?o:Object.assign([],{empty:!0},s.streamInfo())}function ua(i,e={}){let{lineCounter:t,prettyErrors:n}=la(e),r=new ca.Parser(t?.addNewLine),s=new aa.Composer(e),o=null;for(let a of s.compose(r.parse(i),!0,i.length))if(!o)o=a;else if(o.options.logLevel!=="silent"){o.errors.push(new tt.YAMLParseError(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return n&&t&&(o.errors.forEach(tt.prettifyError(i,t)),o.warnings.forEach(tt.prettifyError(i,t))),o}function rd(i,e,t){let n;typeof e=="function"?n=e:t===void 0&&e&&typeof e=="object"&&(t=e);let r=ua(i,t);if(!r)return null;if(r.warnings.forEach(s=>ed.warn(r.options.logLevel,s)),r.errors.length>0){if(r.options.logLevel!=="silent")throw r.errors[0];r.errors=[]}return r.toJS(Object.assign({reviver:n},t))}function sd(i,e,t){let n=null;if(typeof e=="function"||Array.isArray(e)?n=e:t===void 0&&e&&(t=e),typeof t=="string"&&(t=t.length),typeof t=="number"){let r=Math.round(t);t=r<1?void 0:r>8?{indent:8}:{indent:r}}if(i===void 0){let{keepUndefined:r}=t??e??{};if(!r)return}return td.isDocument(i)&&!n?i.toString(t):new Zf.Document(i,n,t).toString(t)}it.parse=rd;it.parseAllDocuments=nd;it.parseDocument=ua;it.stringify=sd});var or=y(P=>{"use strict";var od=Yn(),ad=Je(),cd=En(),sr=Ge(),ld=Ie(),ie=_(),ud=Q(),fd=O(),dd=Z(),pd=ee(),md=ui(),hd=er(),gd=ir(),wd=rr(),mi=fa(),da=Ne();P.Composer=od.Composer;P.Document=ad.Document;P.Schema=cd.Schema;P.YAMLError=sr.YAMLError;P.YAMLParseError=sr.YAMLParseError;P.YAMLWarning=sr.YAMLWarning;P.Alias=ld.Alias;P.isAlias=ie.isAlias;P.isCollection=ie.isCollection;P.isDocument=ie.isDocument;P.isMap=ie.isMap;P.isNode=ie.isNode;P.isPair=ie.isPair;P.isScalar=ie.isScalar;P.isSeq=ie.isSeq;P.Pair=ud.Pair;P.Scalar=fd.Scalar;P.YAMLMap=dd.YAMLMap;P.YAMLSeq=pd.YAMLSeq;P.CST=md;P.Lexer=hd.Lexer;P.LineCounter=gd.LineCounter;P.Parser=wd.Parser;P.parse=mi.parse;P.parseAllDocuments=mi.parseAllDocuments;P.parseDocument=mi.parseDocument;P.stringify=mi.stringify;P.visit=da.visit;P.visitAsync=da.visitAsync});var ht=Cr(or(),1);import qa from"path";import{promises as zd}from"fs";import Ei from"path";import{promises as Wd}from"fs";import x from"path";import{promises as yd}from"fs";async function ar(i){try{return await yd.access(i),!0}catch(e){if(vd(e))return!1;throw e}}function vd(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}var fr=Cr(or(),1);import hi from"path";var wi=64*1024,lr=1024,ur=64,bd=5,kd=[".agents/skills/**",".amazonq/skills/**",".augment/skills/**",".bob/skills/**",".claude/skills/**",".cline/skills/**",".codebuddy/skills/**",".continue/skills/**",".cospec/skills/**",".crush/skills/**",".cursor/skills/**",".factory/skills/**",".forge/skills/**",".gemini/skills/**",".github/skills/**",".iflow/skills/**",".junie/skills/**",".kilocode/skills/**",".kimi-code/skills/**",".kiro/skills/**",".lingma/skills/**",".mimocode/skills/**",".opencode/skills/**",".pi/skills/**",".qoder/skills/**",".qwen/skills/**",".roo/skills/**",".trae-cn/skills/**",".trae/skills/**",".windsurf/skills/**",".zcode/skills/**"],Y={include:["**/*"],exclude:[...kd],max_files:1e4,max_total_bytes:256*1024*1024,max_duration_ms:6e4};function Sd(i,e){if(typeof i!="string")throw new Error(`${e} must be a string`);let t=i.trim();if(t.length===0||hi.posix.isAbsolute(t)||hi.win32.isAbsolute(t)||/^(?:~|[\\/])/u.test(t))throw new Error(`${e} must be a project-relative path`);if(t===".")return[];let n=t.replaceAll("\\","/").split("/");if(n.some(r=>r===".."))throw new Error(`${e} must stay inside the project root`);if(n.some(r=>r===""||r==="."))throw new Error(`${e} must not contain empty or dot path segments`);return n}function gi(i){let e=Sd(i,"native.artifact_root");return e.length===0?".":e.join("/")}function ma(i,e="docs"){let t=i??e;if(t!=="legacy"&&t!=="docs")throw new Error("classic.artifact_layout must be legacy or docs");return t}function rt(i,e,t=!1){if(typeof i!="string")throw new Error(`${e} must be a string`);let n=i.trim().replaceAll("\\","/");if(n.length===0||hi.posix.isAbsolute(n)||hi.win32.isAbsolute(n)||/^(?:~|[\\/])/u.test(n))throw new Error(`${e} must be relative to its declared path base`);let r=n.split("/");if(r.some(s=>s===".."))throw new Error(`${e} must stay inside its declared path base`);if(r.some(s=>s===""||s==="."))throw new Error(`${e} must not contain empty or dot path segments`);if(!t&&/[*?]/u.test(n))throw new Error(`${e} cannot contain wildcards`);return r.join("/")}function nt(i,e){if(!i||typeof i!="object"||Array.isArray(i))throw new Error(`${e} must be a mapping`);return i}function ha(i,e,t){let n=i??e;if(n!=="en"&&n!=="zh-CN")throw new Error(`${t} must be en or zh-CN`);return n}function ga(i,e){if(typeof i!="string"||i.length===0||i.includes("\\")||i.includes("\0")||i.startsWith("/")||i.split("/").includes(".."))throw new Error(`${e} contains an unsafe pattern`);if(i.length>lr)throw new Error(`${e} exceeds ${lr} characters`);let t=0;for(let n=0;n<i.length;n+=1)i[n]==="?"?t+=1:i[n]==="*"&&(t+=1,i[n+1]==="*"&&(n+=1));if(t>ur)throw new Error(`${e} contains more than ${ur} wildcard tokens`);return i}function pa(i,e,t){if(i===void 0)return[...t];if(!Array.isArray(i))throw new Error(`${e} contains an unsafe pattern`);return[...new Set(i.map(n=>ga(n,e)))].sort((n,r)=>n.localeCompare(r,"en"))}function cr(i,e,t){let n=i??e;if(!Number.isSafeInteger(n)||n<1)throw new Error(`${t} must be a positive integer`);return n}function Cd(i){if(i===void 0)return{...Y,include:[...Y.include],exclude:[...Y.exclude]};let e=nt(i,"native.snapshot");return{include:pa(e.include,"native.snapshot.include",Y.include),exclude:pa(e.exclude,"native.snapshot.exclude",Y.exclude),max_files:cr(e.max_files,Y.max_files,"native.snapshot.max_files"),max_total_bytes:cr(e.max_total_bytes,Y.max_total_bytes,"native.snapshot.max_total_bytes"),max_duration_ms:cr(e.max_duration_ms,Y.max_duration_ms,"native.snapshot.max_duration_ms")}}function Ed(i){if(i===void 0)return;let e=nt(i,"native.pending_root_move"),t=e.id,n=e.from_artifact_root,r=e.to_artifact_root,s=e.stage;if(typeof t!="string"||!/^[a-f0-9-]{8,}$/u.test(t))throw new Error("native.pending_root_move.id is invalid");if(typeof n!="string"||typeof r!="string")throw new Error("native.pending_root_move roots must be strings");if(s!=="copying"&&s!=="ready"&&s!=="switched")throw new Error("native.pending_root_move.stage is invalid");let o;if(e.cleanup!==void 0){let a=nt(e.cleanup,"native.pending_root_move.cleanup"),c=a.kind,l=a.state,m=a.manifest_hash;if(c!=="forward-source"&&c!=="restart-staging"&&c!=="rollback-destination"&&c!=="rollback-staging")throw new Error("native.pending_root_move.cleanup.kind is invalid");if(l!=="prepared"&&l!=="quarantined"&&l!=="deleting")throw new Error("native.pending_root_move.cleanup.state is invalid");if(typeof m!="string"||!/^[a-f0-9]{64}$/u.test(m))throw new Error("native.pending_root_move.cleanup.manifest_hash is invalid");o={kind:c,state:l,manifestHash:m}}return{id:t,fromArtifactRoot:gi(n),toArtifactRoot:gi(r),stage:s,...o?{cleanup:o}:{}}}function _d(i,e={}){let t=nt(i,"native"),n=t.artifact_root??(e.allowMissingArtifactRoot?"docs":void 0);if(typeof n!="string")throw new Error("native.artifact_root must be a string");let r=t.clarification_mode??"sequential";if(r!=="sequential"&&r!=="batch")throw new Error("native.clarification_mode must be sequential or batch");let s=t.archive_confirmation??"automatic";if(s!=="automatic"&&s!=="required")throw new Error("native.archive_confirmation must be automatic or required");let o=t.max_verify_failures??bd;if(!Number.isSafeInteger(o)||o<1)throw new Error("native.max_verify_failures must be a positive integer");let a=Ed(t.pending_root_move);return{artifact_root:gi(n),language:ha(t.language,"en","native.language"),clarification_mode:r,archive_confirmation:s,max_verify_failures:o,snapshot:Cd(t.snapshot),...a?{pending_root_move:a}:{}}}function Pd(i){let e=nt(i,"classic"),t=e.context_compression??"off";if(t!=="off"&&t!=="beta")throw new Error("classic.context_compression must be off or beta");let n=e.review_mode??"standard";if(n!=="off"&&n!=="standard"&&n!=="thorough")throw new Error("classic.review_mode must be off, standard, or thorough");let r=e.auto_transition??!0;if(typeof r!="boolean")throw new Error("classic.auto_transition must be true or false");return{artifact_layout:ma(e.artifact_layout),language:ha(e.language,"zh-CN","classic.language"),context_compression:t,review_mode:n,auto_transition:r}}function Nd(i){let e=i??!0;if(typeof e!="boolean")throw new Error("ambient_resume must be true or false");return e}function Od(i,e,t,n,r){let s=i.schema!==void 0;if(!(s||i.default_workflow!==void 0||i.workflows!==void 0||!r.allowPartialProject&&i.native!==void 0)||r.allowPartialProject&&!s)return null;if(i.schema!=="comet.project.v1")throw new Error("Unsupported Comet project schema");if(i.default_workflow!=="native"&&i.default_workflow!=="classic")throw new Error("default_workflow must be native or classic");let a=i.workflows??[i.default_workflow];if(!Array.isArray(a)||a.length===0||a.some(l=>l!=="native"&&l!=="classic"))throw new Error("workflows must contain native and/or classic");let c=[...new Set(a)];if(!c.includes(i.default_workflow))throw new Error("workflows must include default_workflow");if(c.includes("native")&&!e)throw new Error("native must be a mapping");return{schema:"comet.project.v1",default_workflow:i.default_workflow,workflows:c,ambient_resume:n,...e?{native:e}:{},...t?{classic:t}:{}}}function st(i,e={}){let t=(0,fr.parseDocument)(i,{uniqueKeys:!0});if(t.errors.length>0)throw new Error(`Invalid .comet/config.yaml: ${t.errors[0].message}`);let n=t.toJS();if(n==null)return{value:{},config:null,ambient_resume:!0};if(typeof n!="object"||Array.isArray(n))throw new Error("Invalid .comet/config.yaml: root must be a mapping");let r=n,s=Nd(r.ambient_resume),o=r.native===void 0?void 0:_d(r.native,{allowMissingArtifactRoot:e.allowMissingNativeFields}),a=r.classic===void 0?void 0:Pd(r.classic),c=Od(r,o,a,s,{allowPartialProject:e.allowPartialProject??!1});return{value:r,config:c,ambient_resume:s,...o?{native:o}:{},...a?{classic:a}:{}}}import{createHash as Ad}from"crypto";import{promises as bi}from"fs";import se from"path";import{constants as yi,promises as pe}from"fs";function ne(i){return i!==0&&i!==0n&&i!=="0"}function dr(i,e){return ne(i.dev)&&ne(e.dev)&&ne(i.ino)&&ne(e.ino)}function ot(i,e){let t=ne(i.dev)&&ne(e.dev);if(t&&i.dev!==e.dev)return!1;let n=ne(i.ino)&&ne(e.ino);return n&&i.ino!==e.ino?!1:t&&n?!0:i.birthtime===e.birthtime}var re=class extends Error{reason;constructor(e,t,n){super(t,n),this.name="RaceSafeReadError",this.reason=e}};function pr(i){return"birthtimeNs"in i&&typeof i.birthtimeNs=="bigint"?i.birthtimeNs:i.birthtimeMs}function wa(i){return"ctimeNs"in i&&typeof i.ctimeNs=="bigint"?i.ctimeNs:i.ctimeMs}function at(i){return{dev:i.dev,ino:i.ino,birthtime:pr(i)}}function vi(i,e){let t=at(i),n=at(e);return dr(t,n)?ot(t,n):ot(t,n)&&pr(i)===pr(e)&&wa(i)===wa(e)&&i.size===e.size}async function ya(i,e,t={}){if(!Number.isSafeInteger(e)||e<1)throw new Error("race-safe read byte limit must be a positive integer");let n=t.label??"file",r=t.bigint===!0,s=await pe.lstat(i,{bigint:r});if(!s.isFile()||s.isSymbolicLink())throw new re("not-regular-file",`${n} must be a regular file`);if(BigInt(s.size)>BigInt(e))throw new re("too-large",`${n} exceeds ${e} bytes`);let o=await pe.realpath(i);await t.verify?.("pre-open",{realPath:o,identity:at(s)});let a=process.platform==="win32"?yi.O_RDONLY:yi.O_RDONLY|yi.O_NOFOLLOW|yi.O_NONBLOCK,c;try{c=await pe.open(i,a)}catch(l){throw l.code==="ELOOP"?new re("not-regular-file",`${n} must be a regular file`,{cause:l}):l}try{let[l,m,u]=await Promise.all([c.stat({bigint:r}),pe.lstat(i,{bigint:r}),pe.realpath(i)]);if(!l.isFile()||!m.isFile()||m.isSymbolicLink()||u!==o||!vi(s,l)||!vi(s,m))throw new re("changed",`${n} changed while opening`);await t.verify?.("post-open",{realPath:u,identity:at(l)}),await t.hooks?.afterOpen?.();let d=[],h=0,w=Buffer.allocUnsafe(Math.min(64*1024,e+1));for(;;){let v=e+1-h,{bytesRead:k}=await c.read(w,0,Math.min(w.length,v),null);if(k===0)break;if(h+=k,h>e)throw new re("too-large",`${n} exceeds ${e} bytes`);d.push(Buffer.from(w.subarray(0,k)))}await t.hooks?.beforeFinalCheck?.();let[f,p,g]=await Promise.all([c.stat({bigint:r}),pe.lstat(i,{bigint:r}),pe.realpath(i)]);if(!p.isFile()||p.isSymbolicLink()||g!==o||!vi(s,f)||!vi(s,p))throw new re("changed",`${n} changed while reading`);return await t.verify?.("post-read",{realPath:g,identity:at(f)}),{bytes:Buffer.concat(d,h),stat:f,realPath:g}}finally{await c.close()}}function xd(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}function mr(i,e){let t=se.relative(i,e);return t===""||!se.isAbsolute(t)&&t!==".."&&!t.startsWith(`..${se.sep}`)}async function va(i,e){let t=se.resolve(i),n=await bi.lstat(t);if(!n.isDirectory()||n.isSymbolicLink())throw new Error(`${e} project root must be a real directory`);return bi.realpath(t)}async function ba(i,e,t,n){let r=i;for(let s=0;s<t.length;s++){r=se.join(r,t[s]);let o;try{o=await bi.lstat(r)}catch(m){if(xd(m))return{exists:!1,kind:"missing"};throw m}let a=se.relative(i,r).replaceAll("\\","/");if(o.isSymbolicLink())throw new Error(`${n.label} crosses a symbolic link or junction at ${a}`);let c=s===t.length-1;if(!c&&!o.isDirectory())throw new Error(`${n.label} ancestor ${a} must be a real directory`);if(c&&(n.expected==="file"&&!o.isFile()||n.expected==="directory"&&!o.isDirectory()||n.expected==="any"&&!o.isFile()&&!o.isDirectory()))throw new Error(`${n.label} must be a real ${n.expected}`);let l=await bi.realpath(r);if(!mr(e,l))throw new Error(`${n.label} resolves outside the project root`);if(c)return{exists:!0,kind:o.isFile()?"file":o.isDirectory()?"directory":"missing"}}return{exists:!0,kind:"directory"}}async function D(i,e,t){let n=rt(e,t.label),r=se.resolve(i),s=await va(r,t.label),o=n.split("/"),a=se.resolve(r,...o);if(!mr(r,a))throw new Error(`${t.label} must stay inside the project root`);let c=await ba(r,s,o,t);return{projectRoot:r,target:a,relative:n,exists:c.exists,kind:c.kind}}async function oe(i,e,t,n){let r=await D(i,e,{label:n.label,expected:"file"});if(!r.exists){let o=new Error(`${n.label} does not exist`);throw o.code="ENOENT",o}let s=await va(r.projectRoot,n.label);return ya(r.target,t,{...n,verify:async(o,a)=>{if(!mr(s,a.realPath))throw new Error(`${n.label} resolves outside the project root`);await ba(r.projectRoot,s,r.relative.split("/"),{label:n.label,expected:"file"})}})}var ct=".comet/config.yaml";function Id(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}async function ki(i,e={}){return(await Si(i,e)).document}async function Rd(i){try{return(await oe(i,ct,wi,{label:ct})).bytes}catch(e){if(Id(e))return null;throw e}}function jd(i){return i?{exists:!0,sha256:Ad("sha256").update(i).digest("hex")}:{exists:!1,sha256:null}}async function Si(i,e={}){let t=await Rd(i);return{document:t?st(t.toString("utf8"),e):null,identity:jd(t)}}var nh=16*1024;var lt=class extends Error{code="classic-layout-unavailable";constructor(e="Classic artifact layout is unavailable from .comet/config.yaml"){super(e),this.name="ClassicLayoutUnavailableError"}},hr=class extends Error{constructor(t,n,r){let s=U(r,t),o=U(r,n);super(`Classic layout conflict: both ${s}/ and ${o}/ exist; run comet doctor and resolve the conflict before writing`);this.configuredRoot=t;this.alternateRoot=n;this.name="ClassicLayoutConflictError"}configuredRoot;alternateRoot;code="classic-layout-conflict"},Ca=".comet/config.yaml";function Fd(i){let e=i?.code;return e==="ENOENT"||e==="ENOTDIR"}async function Ea(i){await D(i,Ca,{label:Ca,expected:"file"})}function _a(i,e){let t=x.resolve(i),n=e==="docs"?x.join(t,"docs"):t,r=x.join(n,"openspec"),s=x.join(t,"docs","superpowers");return{projectRoot:t,artifactLayout:e,openSpecBase:n,openSpecRoot:r,changesDir:x.join(r,"changes"),archiveDir:x.join(r,"changes","archive"),specsDir:x.join(r,"specs"),superpowersRoot:s,superpowersSpecsDir:x.join(s,"specs"),superpowersPlansDir:x.join(s,"plans"),superpowersReportsDir:x.join(s,"reports")}}async function Bd(i){await Ea(i);let e=await ki(i,{allowPartialProject:!0,allowMissingNativeFields:!0});if(!e?.config)throw new lt;if(!(e.config.workflows??[e.config.default_workflow]).includes("classic"))throw new lt("Classic artifact layout is unavailable because Classic is not enabled");return e.classic?.artifact_layout??"legacy"}async function Kd(i,e){return _a(i,e??await Bd(i))}async function Yd(i,e){let t=await Kd(i,e),n=t.artifactLayout==="legacy"?"docs":"legacy",r=_a(i,n).openSpecRoot,[s,o]=await Promise.all([D(t.projectRoot,U(t.projectRoot,t.openSpecRoot),{label:"Configured Classic OpenSpec root",expected:"directory"}),D(t.projectRoot,U(t.projectRoot,r),{label:"Alternate Classic OpenSpec root",expected:"directory"})]),a=s.exists,c=o.exists;return{paths:t,configuredRootExists:a,alternateRoot:r,alternateRootExists:c,dualRoots:a&&c}}async function Ud(i,e){let t=[i.openSpecRoot,i.changesDir,i.archiveDir,i.specsDir,e,i.superpowersRoot,i.superpowersSpecsDir,i.superpowersPlansDir,i.superpowersReportsDir];for(let n of t){let r=U(i.projectRoot,n);await D(i.projectRoot,r,{label:`Classic managed physical path ${r}`,expected:"directory"})}}async function Pa(i,e,t={}){let n=await Yd(i,e);if(await Ud(n.paths,n.alternateRoot),n.dualRoots&&!t.allowAlternateRoot)throw new hr(n.paths.openSpecRoot,n.alternateRoot,n.paths.projectRoot);if(!n.configuredRootExists){let r=U(n.paths.projectRoot,n.paths.openSpecRoot),s=U(n.paths.projectRoot,n.alternateRoot);throw new lt(`Configured Classic OpenSpec root is missing: ${r} (alternate ${s} is ${n.alternateRootExists?"present":"missing"})`)}return n.paths}async function Na(i){let e=x.resolve(i),t=null;try{(await Wd.lstat(e)).isDirectory()||(e=x.dirname(e))}catch(n){if(!Fd(n))throw n}for(;;){x.basename(e)==="openspec"&&(t=x.dirname(e));let n=x.join(e,".comet","config.yaml"),r=!1;if(await ar(n))try{await Ea(e);let o=(await ki(e))?.value;r=!!o&&typeof o=="object"&&!Array.isArray(o)&&(o.schema==="comet.project.v1"||o.default_workflow!==void 0||o.native!==void 0)}catch{}if(r||await ar(x.join(e,".git")))return e;let s=x.dirname(e);if(s===e)return t??x.resolve(i);e=s}}function U(i,e){return x.relative(x.resolve(i),e).replaceAll("\\","/")}import ut from"path";var Jd=2*1024*1024;function Oa(i,e,t){let n=ut.resolve(i),r=ut.isAbsolute(e)?ut.resolve(e):ut.resolve(n,e),s=ut.relative(n,r).replaceAll("\\","/");return{root:n,relative:rt(s,t),target:r}}async function ft(i,e,t){let n=Oa(i,e,t.label);return D(n.root,n.relative,t)}async function xa(i,e,t){return(await ft(i,e,{label:t.label,expected:t.expected??"any"})).exists}async function Aa(i,e,t){return(await Hd(i,e,t)).toString("utf8")}async function Hd(i,e,t){let n=Oa(i,e,t.label);return(await oe(n.root,n.relative,t.maxBytes??Jd,{label:t.label,hooks:t.hooks})).bytes}function wr(i){return i?/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(i)?i.includes("..")?"Change name cannot contain '..' (path traversal not allowed)":null:`Invalid change name: '${i}'
143
+ Valid format: lowercase kebab-case (a-z, 0-9, single hyphens)`:"Change name cannot be empty"}function Gd(i){let e=wr(i);if(e)throw new Error(e)}function Qd(i,e){return{label:U(i,e),directory:e}}async function gr(i,e,t){let n=Qd(i,e);if(!(await ft(i,e,{label:t,expected:"directory"})).exists)return{change:n,exists:!1,stateExists:!1};let s=await ft(i,Ei.join(e,".comet.yaml"),{label:`${t} state`,expected:"file"});return{change:n,exists:!0,stateExists:s.exists}}function Xd(i,e){let t=e.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&");return new RegExp(`^\\d{4}-\\d{2}-\\d{2}-${t}$`,"u").test(i)}async function Zd(i,e,t,n={}){if(!n.skipExactCompatibility){let o=await gr(i,Ei.join(e,t),`Classic archived change ${t}`);if(o.exists)return o.change}if(!(await ft(i,e,{label:"Classic archive directory",expected:"directory"})).exists)return null;let s=[];for(let o of await zd.readdir(e,{withFileTypes:!0})){if(!Xd(o.name,t))continue;let a=await gr(i,Ei.join(e,o.name),`Classic archived change ${o.name}`);a.exists&&a.stateExists&&s.push(a.change)}return s.sort((o,a)=>a.directory.localeCompare(o.directory))[0]??null}async function Ia(i,e=process.cwd()){Gd(i);let t=await Pa(e),n=await gr(t.projectRoot,Ei.join(t.changesDir,i),`Classic active change ${i}`);if(n.exists)return n.change;let r=await Zd(t.projectRoot,t.archiveDir,i);return r||n.change}var kg=256*1024;var yr=["workflow","language","phase","context_compression","build_mode","build_pause","subagent_dispatch","tdd_mode","review_mode","isolation","bound_branch","verify_mode","auto_transition","base_ref","design_doc","plan","verify_result","verify_failures","verification_report","branch_status","created_at","verified_at","archive_confirmation","archived","direct_override","handoff_context","handoff_hash","classic_profile","classic_migration"],vr=["run_id"],_g=new Set([...yr,...vr]);import{AsyncLocalStorage as op}from"async_hooks";import{promises as Ra}from"fs";import dt from"path";var br=new op;function ap(i,e){let t=dt.relative(i,e);return t===""||!dt.isAbsolute(t)&&t!==".."&&!t.startsWith(`..${dt.sep}`)}async function cp(i){let e=dt.resolve(i.invocationCwd??process.cwd()),t=dt.resolve(i.projectRoot??await Na(e)),[n,r]=await Promise.all([Ra.realpath(e),Ra.realpath(t)]);if(!ap(r,n))throw new Error(`Classic command invocation cwd is outside the discovered project: ${e}`);return{invocationCwd:e,projectRoot:t}}async function ja(i,e){let t=br.getStore();if(t)return e(t);let n=await cp(i);return br.run(n,()=>e(n))}function Ta(){let i=br.getStore();if(!i)throw new Error("Classic command project context is unavailable");return i.projectRoot}var lp="\x1B[32m",pt="\x1B[31m",up="\x1B[33m",fp="\x1B[0m",dp=["workflow","phase","design_doc","plan","build_mode","isolation","verify_mode","verify_result","verified_at","archived"],pp={workflow:["full","hotfix","tweak"],language:["en","zh-CN"],phase:["open","design","build","verify","archive"],context_compression:["off","beta"],build_mode:["subagent-driven-development","executing-plans","direct"],build_pause:["plan-ready"],subagent_dispatch:["confirmed"],tdd_mode:["tdd","direct"],review_mode:["off","standard","thorough"],isolation:["current","branch","worktree"],verify_mode:["light","full"],auto_transition:["true","false"],verify_result:["pending","pass","fail"],branch_status:["pending","handled"],archive_confirmation:["pending","confirmed"],archived:["true","false"],direct_override:["true","false"],classic_profile:["full","hotfix","tweak"],classic_migration:["1"]},mp=new Set([...yr,...vr,"classic_profile","classic_migration"]);function me(i,e){return`${i}${e}${fp}`}function mt(i){return i==null?"":typeof i=="object"?JSON.stringify(i):String(i)}var La=async(i,e)=>ja(e,async()=>{let t=i[0],n=wr(t);if(n)return{exitCode:1,stderr:me(pt,`ERROR: ${n}`)};let r=Ta(),{directory:s,label:o}=await Ia(t,r),a=qa.join(s,".comet.yaml"),c=[`[VALIDATE] ${o}/.comet.yaml`],l=0,m=0,u=p=>{l+=1,c.push(me(pt,` FAIL: ${p}`))},d=p=>{m+=1,c.push(me(up,` WARN: ${p}`))},h;try{h=await Aa(r,a,{label:`Classic state ${o}/.comet.yaml`})}catch(p){if(p.code==="ENOENT")return u(".comet.yaml does not exist"),c.push("",me(pt,`${l} error(s), ${m} warning(s) — validation FAILED`)),{exitCode:1,stderr:c.join(`
144
144
  `)};throw p}let w=(0,ht.parseDocument)(h);if(w.errors.length>0||!(0,ht.isMap)(w.contents)){for(let p of w.errors)u(p.message);return(0,ht.isMap)(w.contents)||u("document root must be a mapping"),c.push("",me(pt,`${l} error(s), ${m} warning(s) — validation FAILED`)),{exitCode:1,stderr:c.join(`
145
- `)}}let f=w.toJS();for(let p of fp)Object.prototype.hasOwnProperty.call(f,p)||u(`missing required field '${p}'`);for(let[p,g]of Object.entries(dp)){if(!Object.prototype.hasOwnProperty.call(f,p))continue;let v=mt(f[p]);if(!v){p==="auto_transition"&&u(`${p}='' is not valid. Expected: ${g.join(" ")}`);continue}g.includes(v)||u(`${p}='${v}' is not valid. Expected: ${g.join(" ")}`)}if(Object.prototype.hasOwnProperty.call(f,"bound_branch")){let p=f.bound_branch;p!==null&&typeof p!="string"&&u(`bound_branch='${mt(p)}' is not a string or null`)}if(Object.prototype.hasOwnProperty.call(f,"verify_failures")){let p=f.verify_failures;(typeof p!="number"||!Number.isInteger(p)||p<0)&&u(`verify_failures='${mt(p)}' is not a non-negative integer`)}for(let p of["design_doc","plan","handoff_context","verification_report"]){let g=mt(f[p]);if(g){if(/^(?:[A-Za-z]:|[\\/]|~)/u.test(g)||g.split(/[\\/]/u).includes("..")){u(`${p}='${g}' must be a relative repository path`);continue}try{await xa(r,qa.resolve(r,g),{label:`${p} artifact pointer`,expected:"file"})||u(`${p}='${g}' does not exist on disk`)}catch(v){u(`${p}='${g}' is unsafe: ${v instanceof Error?v.message:String(v)}`)}}}for(let p of["handoff_hash"]){let g=mt(f[p]);g&&!/^[a-f0-9]{64}$/u.test(g)&&u(`${p}='${g}' is not a sha256 hex digest`)}for(let p of Object.keys(f))pp.has(p)||d(`unknown field '${p}' found`);return c.push(""),l>0?(c.push(me(pt,`${l} error(s), ${m} warning(s) — validation FAILED`)),{exitCode:1,stderr:c.join(`
146
- `)}):(c.push(me(cp,`0 errors, ${m} warning(s) — validation PASSED`)),{exitCode:0,stderr:c.join(`
147
- `)})});function mp(i,e){return{exitCode:e.exitCode,stdout:JSON.stringify({command:i,exitCode:e.exitCode,...e.stdout===void 0?{}:{stdout:e.stdout},...e.stderr===void 0?{}:{stderr:e.stderr}})+`
148
- `}}async function Da(i,e,t=process.argv.slice(2)){let n=t.includes("--json"),r=t.filter(a=>a!=="--json"),s;try{s=await e(r,{json:n})}catch(a){s={exitCode:70,stderr:a instanceof Error?a.message:String(a)}}let o=n?mp(i,s):s;return o.stdout&&process.stdout.write(o.stdout),o.stderr&&process.stderr.write(o.stderr+(o.stderr.endsWith(`
145
+ `)}}let f=w.toJS();for(let p of dp)Object.prototype.hasOwnProperty.call(f,p)||u(`missing required field '${p}'`);for(let[p,g]of Object.entries(pp)){if(!Object.prototype.hasOwnProperty.call(f,p))continue;let v=mt(f[p]);if(!v){p==="auto_transition"&&u(`${p}='' is not valid. Expected: ${g.join(" ")}`);continue}g.includes(v)||u(`${p}='${v}' is not valid. Expected: ${g.join(" ")}`)}if(Object.prototype.hasOwnProperty.call(f,"bound_branch")){let p=f.bound_branch;p!==null&&typeof p!="string"&&u(`bound_branch='${mt(p)}' is not a string or null`)}if(Object.prototype.hasOwnProperty.call(f,"verify_failures")){let p=f.verify_failures;(typeof p!="number"||!Number.isInteger(p)||p<0)&&u(`verify_failures='${mt(p)}' is not a non-negative integer`)}for(let p of["design_doc","plan","handoff_context","verification_report"]){let g=mt(f[p]);if(g){if(/^(?:[A-Za-z]:|[\\/]|~)/u.test(g)||g.split(/[\\/]/u).includes("..")){u(`${p}='${g}' must be a relative repository path`);continue}try{await xa(r,qa.resolve(r,g),{label:`${p} artifact pointer`,expected:"file"})||u(`${p}='${g}' does not exist on disk`)}catch(v){u(`${p}='${g}' is unsafe: ${v instanceof Error?v.message:String(v)}`)}}}for(let p of["handoff_hash"]){let g=mt(f[p]);g&&!/^[a-f0-9]{64}$/u.test(g)&&u(`${p}='${g}' is not a sha256 hex digest`)}for(let p of Object.keys(f))mp.has(p)||d(`unknown field '${p}' found`);return c.push(""),l>0?(c.push(me(pt,`${l} error(s), ${m} warning(s) — validation FAILED`)),{exitCode:1,stderr:c.join(`
146
+ `)}):(c.push(me(lp,`0 errors, ${m} warning(s) — validation PASSED`)),{exitCode:0,stderr:c.join(`
147
+ `)})});function hp(i,e){return{exitCode:e.exitCode,stdout:JSON.stringify({command:i,exitCode:e.exitCode,...e.stdout===void 0?{}:{stdout:e.stdout},...e.stderr===void 0?{}:{stderr:e.stderr}})+`
148
+ `}}async function Da(i,e,t=process.argv.slice(2)){let n=t.includes("--json"),r=t.filter(a=>a!=="--json"),s;try{s=await e(r,{json:n})}catch(a){s={exitCode:70,stderr:a instanceof Error?a.message:String(a)}}let o=n?hp(i,s):s;return o.stdout&&process.stdout.write(o.stdout),o.stderr&&process.stderr.write(o.stderr+(o.stderr.endsWith(`
149
149
  `)?"":`
150
150
  `)),o.exitCode}process.exitCode=await Da("validate",La);