comet-dsh-plugin 0.0.0-stage → 0.5.3

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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +176 -0
  3. package/README.md +152 -2
  4. package/client.js +349 -0
  5. package/cordis.patch.yml +4 -0
  6. package/icon.png +0 -0
  7. package/index.js +183 -0
  8. package/locale/en.json +7 -0
  9. package/locale/zh.json +7 -0
  10. package/package.json +57 -4
  11. package/rules/comet-workflow-guard.md +63 -0
  12. package/rules/migration-assets.json +218 -0
  13. package/server/comet-plugin-setup.mjs +192 -0
  14. package/skills/comet/SKILL.md +37 -0
  15. package/skills/comet/agents/openai.yaml +3 -0
  16. package/skills/comet/reference/change-walkthrough.md +77 -0
  17. package/skills/comet/reference/edit-review.md +26 -0
  18. package/skills/comet/reference/host-check.md +11 -0
  19. package/skills/comet/reference/platform-execution.md +34 -0
  20. package/skills/comet/reference/task-learning.md +39 -0
  21. package/skills/comet/runtime/classic/checks.yaml +6 -0
  22. package/skills/comet/runtime/classic/guardrails.yaml +13 -0
  23. package/skills/comet/runtime/classic/skill.yaml +122 -0
  24. package/skills/comet/scripts/comet-archive.mjs +310 -0
  25. package/skills/comet/scripts/comet-check.mjs +179 -0
  26. package/skills/comet/scripts/comet-entry-runtime.mjs +151 -0
  27. package/skills/comet/scripts/comet-env.mjs +15 -0
  28. package/skills/comet/scripts/comet-guard.mjs +335 -0
  29. package/skills/comet/scripts/comet-handoff.mjs +289 -0
  30. package/skills/comet/scripts/comet-hook-guard.mjs +294 -0
  31. package/skills/comet/scripts/comet-hook-router-guard.mjs +628 -0
  32. package/skills/comet/scripts/comet-hook-router.mjs +17 -0
  33. package/skills/comet/scripts/comet-intent.mjs +181 -0
  34. package/skills/comet/scripts/comet-plugin-hook.mjs +213 -0
  35. package/skills/comet/scripts/comet-resume-probe.mjs +205 -0
  36. package/skills/comet/scripts/comet-runtime.mjs +571 -0
  37. package/skills/comet/scripts/comet-state.mjs +381 -0
  38. package/skills/comet/scripts/comet-yaml-validate.mjs +182 -0
  39. package/skills/comet-any/SKILL.md +47 -0
  40. package/skills/comet-any/agents/openai.yaml +5 -0
  41. package/skills/comet-any/reference/sdk-creation.md +100 -0
  42. package/skills/comet-archive/SKILL.md +28 -0
  43. package/skills/comet-archive/agents/openai.yaml +5 -0
  44. package/skills/comet-archive/reference/compat.md +188 -0
  45. package/skills/comet-build/SKILL.md +35 -0
  46. package/skills/comet-build/agents/openai.yaml +5 -0
  47. package/skills/comet-build/reference/compat.md +191 -0
  48. package/skills/comet-classic/SKILL.md +98 -0
  49. package/skills/comet-classic/agents/openai.yaml +3 -0
  50. package/skills/comet-classic/reference/auto-transition.md +34 -0
  51. package/skills/comet-classic/reference/classic-layout.md +36 -0
  52. package/skills/comet-classic/reference/comet-yaml-fields.md +82 -0
  53. package/skills/comet-classic/reference/context-recovery.md +128 -0
  54. package/skills/comet-classic/reference/debug-gate.md +30 -0
  55. package/skills/comet-classic/reference/decision-point.md +109 -0
  56. package/skills/comet-classic/reference/dirty-worktree.md +59 -0
  57. package/skills/comet-classic/reference/file-structure.md +32 -0
  58. package/skills/comet-classic/reference/intent-frame.md +132 -0
  59. package/skills/comet-classic/reference/scripts.md +144 -0
  60. package/skills/comet-classic/reference/sdk-methods.md +136 -0
  61. package/skills/comet-classic/reference/subagent-dispatch.md +75 -0
  62. package/skills/comet-classic/reference/workspace.md +23 -0
  63. package/skills/comet-design/SKILL.md +25 -0
  64. package/skills/comet-design/agents/openai.yaml +5 -0
  65. package/skills/comet-design/reference/compat.md +191 -0
  66. package/skills/comet-hotfix/SKILL.md +46 -0
  67. package/skills/comet-hotfix/agents/openai.yaml +5 -0
  68. package/skills/comet-hotfix/reference/compat.md +240 -0
  69. package/skills/comet-memory/SKILL.md +68 -0
  70. package/skills/comet-memory/agents/openai.yaml +5 -0
  71. package/skills/comet-native/SKILL.md +139 -0
  72. package/skills/comet-native/agents/openai.yaml +3 -0
  73. package/skills/comet-native/reference/artifacts.md +118 -0
  74. package/skills/comet-native/reference/clarification.md +120 -0
  75. package/skills/comet-native/reference/commands.md +321 -0
  76. package/skills/comet-native/reference/edit-review.md +26 -0
  77. package/skills/comet-native/reference/recovery.md +64 -0
  78. package/skills/comet-native/reference/workspace.md +70 -0
  79. package/skills/comet-native/scripts/comet-native-archive.mjs +475 -0
  80. package/skills/comet-native/scripts/comet-native-cancel.mjs +461 -0
  81. package/skills/comet-native/scripts/comet-native-doctor.mjs +475 -0
  82. package/skills/comet-native/scripts/comet-native-hook-guard.mjs +470 -0
  83. package/skills/comet-native/scripts/comet-native-init.mjs +465 -0
  84. package/skills/comet-native/scripts/comet-native-new.mjs +478 -0
  85. package/skills/comet-native/scripts/comet-native-next.mjs +464 -0
  86. package/skills/comet-native/scripts/comet-native-root.mjs +472 -0
  87. package/skills/comet-native/scripts/comet-native-runtime.mjs +525 -0
  88. package/skills/comet-native/scripts/comet-native-select.mjs +468 -0
  89. package/skills/comet-native/scripts/comet-native-show.mjs +462 -0
  90. package/skills/comet-native/scripts/comet-native-spec.mjs +468 -0
  91. package/skills/comet-native/scripts/comet-native-status.mjs +467 -0
  92. package/skills/comet-native/scripts/comet-native-transfer.mjs +466 -0
  93. package/skills/comet-open/SKILL.md +265 -0
  94. package/skills/comet-open/agents/openai.yaml +5 -0
  95. package/skills/comet-open/reference/batch-changes.md +51 -0
  96. package/skills/comet-review/SKILL.md +121 -0
  97. package/skills/comet-review/agents/openai.yaml +5 -0
  98. package/skills/comet-tweak/SKILL.md +49 -0
  99. package/skills/comet-tweak/agents/openai.yaml +5 -0
  100. package/skills/comet-tweak/reference/compat.md +232 -0
  101. package/skills/comet-verify/SKILL.md +30 -0
  102. package/skills/comet-verify/agents/openai.yaml +5 -0
  103. package/skills/comet-verify/reference/compat.md +202 -0
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __cometCreateRequire } from 'module';
3
+ const require = __cometCreateRequire(import.meta.url);
4
+ import d from"path";import z from"os";import{promises as R,realpathSync as I}from"fs";import{fileURLToPath as G,pathToFileURL as K}from"url";import A from"node:path";import{fileURLToPath as L}from"node:url";function E(e){return e.charCodeAt(0)===65279?e.slice(1):e}async function N(e=2e3){return process.stdin.isTTY?{text:""}:!Number.isFinite(e)||e<1?{text:null}:process.stdin.readableEnded?{text:""}:await new Promise(t=>{let n=!1,o=0,r=[],i=setTimeout(()=>s({text:null}),Math.ceil(e)),s=a=>{n||(n=!0,clearTimeout(i),process.stdin.removeListener("data",f),process.stdin.removeListener("end",w),process.stdin.removeListener("close",p),process.stdin.removeListener("error",c),process.stdin.pause(),t(a))},f=a=>{let u=Buffer.isBuffer(a)?a:Buffer.from(a),l=1048576-o;if(l<=0){s({text:null});return}let g=u.subarray(0,l);r.push(g),o+=g.length,u.length>g.length&&s({text:null})},w=()=>s({text:Buffer.concat(r,o).toString("utf8")}),p=()=>{process.stdin.readableEnded||s({text:null})},c=()=>s({text:null});process.stdin.on("data",f),process.stdin.once("end",w),process.stdin.once("close",p),process.stdin.once("error",c),i.unref(),process.stdin.resume()})}var W=new Set(["applypatch","create","createfile","deletefile","edit","editfile","multiedit","patch","searchreplace","strreplaceeditor","write","writefile","writefiletool"]),j=new Set(["glob","grep","listfiles","read","readfile","search","view"]),S=["file_path","filePath","path","target_file","targetFile"],H=["file_paths","filePaths","paths","files","targets"],O=["operations","edits"],P=["patch","diff","patchText","patch_text","changes"],_=new Set(["claude","codex","windsurf","github-copilot","gemini","amazon-q","qwen","kiro","codebuddy","workbuddy","oh-my-pi","qoder","trae","trae-cn","grok","dsh","zcode"]);function h(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function y(e){return e.toLowerCase().replace(/[^a-z0-9]+/gu,"")}function U(e){for(let t of["tool_name","toolName","tool","name"]){let n=e[t];if(typeof n=="string"&&n.trim())return n.trim()}return null}function M(e){for(let t of["cwd","working_directory","workspaceRoot"]){let n=e[t];if(!(typeof n!="string"||!n.trim()||!A.isAbsolute(n.trim())))return n.trim()}}function B(e){for(let t of["session_id","sessionId","conversation_id","conversationId"]){let n=e[t];if(typeof n=="string"&&n.trim())return n.trim().slice(0,256)}}function $(e){for(let t of["hook_event_name","hookEventName","event_name","eventName"]){let n=e[t];if(typeof n=="string"&&n.trim())return y(n)}}function F(e){for(let t of["task","prompt","user_prompt","userPrompt"]){let n=e[t];if(typeof n=="string"&&n.trim())return n.trim()}}function q(e){if(typeof e!="string")return e;let t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return e;try{return JSON.parse(t)}catch{return e}}function Y(e){for(let t of["tool_input","toolInput","toolArgs","tool_args","arguments"])if(e[t]!==void 0)return q(e[t]);return e}function T(e){let t=[],n=[/^\*\*\* (?:Add|Update|Delete) File:\s+(.+?)\s*$/gmu,/^\+\+\+\s+(?:b\/)?(.+?)\s*$/gmu];for(let o of n)for(let r of e.matchAll(o)){let i=r[1]?.trim();i&&i!=="/dev/null"&&t.push(i)}return t}function C(e){return[...new Set(e.flatMap(t=>{let n=t.trim();if(!n)return[];if(/^file:/iu.test(n))try{return[L(n)]}catch{return[n]}return/^[A-Za-z]:/u.test(n)?[n]:/^[A-Za-z][A-Za-z0-9+.-]*:/u.test(n)?[]:[n]}))]}function m(e,t){if(typeof t=="string"){let n=t.trim();n&&e.push(n);return}if(Array.isArray(t)){for(let n of t)m(e,n);return}if(h(t)){for(let n of S)m(e,t[n]);for(let n of H)m(e,t[n]);for(let n of O)m(e,t[n])}}function J(e,t){let n=[],o=[t,e].filter(h);for(let r of o){for(let i of S)m(n,r[i]);for(let i of H)m(n,r[i]);for(let i of O)m(n,r[i]);for(let i of P){let s=r[i];typeof s=="string"&&n.push(...T(s))}}return typeof t=="string"&&n.push(...T(t)),n}function x(e){if(typeof e=="string"&&e.startsWith("*** Begin Patch")&&/^[- +].+/mu.test(e))return T(e).map(r=>({path:r,patch:e}));if(!h(e))return[];for(let r of P)if(typeof e[r]=="string")return x(e[r]);let t=S.map(r=>e[r]).find(r=>typeof r=="string");if(typeof t!="string")return[];if(typeof e.content=="string")return[{path:t,content:e.content}];let n=Array.isArray(e.edits)?e.edits:[e],o=[];for(let r of n){if(!h(r))return[];let i=r.old_string??r.oldString,s=r.new_string??r.newString;if(typeof i!="string"||!i||typeof s!="string")return[];o.push({oldText:i,newText:s,replaceAll:r.replace_all===!0})}return o.length?[{path:t,replacements:o}]:[]}function k(e,t){if(t?.trim()){let l=C([t]);return{intent:l.length>0?"write":"non-write",targets:l,toolName:null}}if(!e.trim())return{intent:"unknown",targets:[],toolName:null};let n;try{n=JSON.parse(E(e))}catch{let l=T(e);if(l.length>0){let g=C(l);return{intent:g.length>0?"write":"non-write",targets:g,toolName:"apply_patch",...x(e).length?{writes:x(e)}:{}}}return{intent:"unknown",targets:[],toolName:null}}if(!h(n))return{intent:"unknown",targets:[],toolName:null};let o=U(n),r=Y(n),i=o&&y(o)==="applypatch"&&h(r)&&typeof r.command=="string"?{...r,patch:r.command}:r,s=J(n,i),f=C(s),w=x(i),p=M(n),c=p?A.resolve(p):void 0,a=p!==c?p:void 0,u=B(n);if($(n)==="beforeagentstart"){let l=F(n);return{intent:"context",targets:[],toolName:null,...l?{task:l}:{},...c?{cwd:c}:{},...a?{rawCwd:a}:{},...u?{sessionId:u}:{}}}return s.length>0&&f.length===0?{intent:"non-write",targets:f,toolName:o,...c?{cwd:c}:{},...a?{rawCwd:a}:{},...u?{sessionId:u}:{}}:o&&W.has(y(o))?{intent:f.length>0?"write":"unknown",targets:f,toolName:o,...w.length?{writes:w}:{},...c?{cwd:c}:{},...a?{rawCwd:a}:{},...u?{sessionId:u}:{}}:o&&j.has(y(o))?{intent:"non-write",targets:[],toolName:o,...c?{cwd:c}:{},...a?{rawCwd:a}:{},...u?{sessionId:u}:{}}:o?{intent:"unknown",targets:f,toolName:o,...c?{cwd:c}:{},...a?{rawCwd:a}:{},...u?{sessionId:u}:{}}:{intent:f.length>0?"write":"unknown",targets:f,toolName:null,...c?{cwd:c}:{},...a?{rawCwd:a}:{},...u?{sessionId:u}:{}}}async function b(e={}){let t=process.env.FILE_PATH;if(t?.trim()||process.stdin.isTTY)return k("",t);let n=await(e.readStdin??N)();n.text===null&&(process.stderr.write(`[COMET-HOOK] stdin timeout: the host did not provide hook input within the expected window
5
+ `),process.exit(1));try{return k(n.text,t)}catch{return k("",t)}}function D(e,t,n={}){return _.has(e)?e==="github-copilot"?{exitCode:0,stdout:t.allowed?`${JSON.stringify(t.context?{additionalContext:t.context}:{})}
6
+ `:`${JSON.stringify({permissionDecision:"deny",permissionDecisionReason:t.reason})}
7
+ `,stderr:t.diagnostic?`${t.diagnostic}
8
+ `:""}:!t.allowed&&(e==="dsh"||e==="codex"&&n.denialOutput==="json")?{exitCode:0,stdout:`${JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:t.reason}})}
9
+ `,stderr:t.diagnostic?`${t.diagnostic}
10
+ `:""}:t.allowed&&t.context?{exitCode:0,stdout:`${JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:t.context}})}
11
+ `,stderr:t.diagnostic?`${t.diagnostic}
12
+ `:""}:t.allowed?{exitCode:0,stdout:"",stderr:t.diagnostic?`${t.diagnostic}
13
+ `:""}:{exitCode:2,stdout:"",stderr:`${t.reason}
14
+ `}:{exitCode:64,stdout:"",stderr:`Unsupported Comet Hook platform: ${e}
15
+ `}}var Z="Usage: comet-hook-router --platform <platform-id> [--project-root <project-root>]";function V(e){let t,n;for(let o=0;o<e.length;o++){let r=e[o];if(r==="--platform"){t=e[++o];continue}if(r==="--project-root"){n=e[++o];continue}throw new Error(`Unknown argument: ${r}`)}if(!t||t.startsWith("--"))throw new Error("--platform is required");if(!_.has(t))throw new Error(`unsupported Hook platform: ${t}`);if(n?.startsWith("--"))throw new Error("--project-root requires a value");return{platformId:t,...n?{projectRoot:d.resolve(n)}:{}}}async function Q(e){let t=d.resolve(e);try{(await R.stat(t)).isDirectory()||(t=d.dirname(t))}catch{t=d.dirname(t)}let n=t,o=d.resolve(z.homedir());for(;;){if(!(t===o&&n!==o))try{return await R.lstat(d.join(t,".comet")),!0}catch(s){if(s.code!=="ENOENT")throw s}try{return await R.lstat(d.join(t,".git")),!1}catch(s){if(s.code!=="ENOENT")throw s}let i=d.dirname(t);if(i===t)return!1;t=i}}var v;function X(){return v??=(async()=>{try{let{enableCompileCache:e}=await import("node:module");e?.()}catch{}return import("./comet-hook-router-guard.mjs")})(),v}async function tt(e){let t;try{t=V(e)}catch(r){return process.stderr.write(`${r instanceof Error?r.message:String(r)}
16
+ ${Z}
17
+ `),64}let n;try{let r=await b();r.intent==="non-write"?n={allowed:!0,reason:"Hook event is not a write"}:!t.projectRoot&&!r.cwd?n={allowed:!0,reason:"No Comet project discovered"}:r.intent!=="write"&&!t.projectRoot&&r.cwd&&!await Q(r.cwd)?n={allowed:!0,reason:"No Comet project discovered"}:n=await(await X()).runCometHookRouterGuard(t,r)}catch(r){n={allowed:!1,reason:`Comet Hook Router failed closed during project discovery: ${r instanceof Error?r.message:String(r)}`}}let o=D(t.platformId,n);return o.stdout&&process.stdout.write(o.stdout),o.stderr&&process.stderr.write(o.stderr),o.exitCode}async function et(e=process.argv.slice(2)){return tt(e)}function nt(e,t=import.meta.url){if(!e)return!1;try{return I(e)===I(G(t))}catch{return t===K(e).href}}var rt=process.argv[1];nt(rt)&&et().then(e=>{process.exitCode=e});export{nt as isDirectEntry,et as main,tt as runCometHookRouter};