shine-code-submit 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/install.cjs +2 -2
- package/package.json +1 -1
- package/src/install/deploy.ts +9 -6
package/README.md
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
# Shine Code Submit
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
登录npm官方地址: npm login --registry=https://registry.npmjs.org/
|
|
5
|
-
|
|
6
|
-
npm config set //registry.npmjs.org/:_authToken "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" 粘贴你的新token
|
|
7
3
|
Claude Code Hook → 本地常驻 Daemon 的状态/持久化底座。Hook 只做「采集 + 落盘 + 转发」立即退出,重活交给后台 Daemon 异步处理,不拖慢 Claude Code。详见 [`设计文档.md`](./设计文档.md)。
|
|
8
4
|
|
|
9
5
|
以 **Claude Code Plugin** 形式分发——`/plugin install` 一键安装,跨平台(Windows/macOS/Linux × x64/arm64)。
|
package/dist/install.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var T=require("node:fs"),Z1=require("node:path"),$1=require("node:child_process");var m=require("node:fs"),S=require("node:os"),I=require("node:path"),v=require("node:child_process"),W1=[1,1,0],J1=300000;function y(){let b=v.spawnSync("bun",["--version"],{shell:process.platform==="win32",encoding:"utf8"});if(b.status===0&&(b.stdout??"").trim())return"bun";let q=S.homedir(),z=process.platform==="win32"?[I.join(q,".bun","bin","bun.exe")]:[I.join(q,".bun","bin","bun"),"/usr/local/bin/bun","/opt/homebrew/bin/bun"];for(let Q of z)if(m.existsSync(Q))return Q;return null}function F1(b){return b.trim().split(".").map((q)=>parseInt(q,10)||0)}function K1(b,q){let z=F1(b);for(let Q=0;Q<q.length;Q++){let X=z[Q]??0,J=q[Q]??0;if(X>J)return!0;if(X<J)return!1}return!0}function V1(){let b=process.env.npm_config_registry??"";return/npmmirror|taobao/i.test(b)}function M(b){return v.spawnSync(b,{shell:!0,encoding:"utf8",timeout:J1,stdio:"inherit"}).status??1}async function p(){let b=y();if(b){let z=v.spawnSync(b,["--version"],{shell:process.platform==="win32",encoding:"utf8"}).stdout?.trim()??"";if(z&&K1(z,W1))return console.log(`[shine-code-submit] bun ${z} detected`),b}if(console.log("[shine-code-submit] bun 未找到或版本过低,开始自动安装..."),V1()){if(console.log("[shine-code-submit] 检测到国内 npm 镜像,先尝试 npm install -g bun"),M("npm install -g bun")===0){let z=y();if(z)return console.log("[shine-code-submit] ✓ bun 安装成功(via npm 镜像)"),z}console.log("[shine-code-submit] npm 镜像方式失败,回退官方脚本")}if(process.platform==="win32")M('powershell -c "irm bun.sh/install.ps1 | iex"');else M("curl -fsSL https://bun.sh/install | bash");let q=y();if(!q)throw console.error("[shine-code-submit] bun 自动安装失败。请手动安装后重试:"),console.error(" Windows: winget install Oven-sh.Bun 或 npm install -g bun"),console.error(" macOS: brew install oven-sh/bun/bun"),console.error(" Linux: curl -fsSL https://bun.sh/install | bash"),Error("bun installation failed");return console.log("[shine-code-submit] ✓ bun 安装成功"),q}var Z=require("node:fs"),G=require("node:path"),d=require("node:url"),L=require("node:child_process");var E=require("node:os"),V=require("node:path");function A(){return process.env.CLAUDE_CONFIG_DIR||V.join(E.homedir(),".claude")}function U(){return V.join(A(),"plugins")}function j(){return V.join(U(),"known_marketplaces.json")}function O(){return V.join(U(),"installed_plugins.json")}function B(){return V.join(A(),"settings.json")}var P={name:"shine-code-submit",version:"0.2.0",private:!1,type:"module",description:"Claude Code Hook -> 本地常驻 Daemon 的状态/持久化底座",author:"renguifeng",license:"MIT",repository:{type:"git",url:"http://8.130.168.121:9001/AI/shine-code-submit.git"},homepage:"http://8.130.168.121:9001/AI/shine-code-submit",bugs:{url:"http://8.130.168.121:9001/AI/shine-code-submit/issues"},keywords:["claude","claude-code","plugin","hooks","daemon","dashboard"],bin:{"shine-code-submit":"dist/install.cjs"},files:["dist/install.cjs",".claude-plugin","hooks/hooks.json","bin/launcher.cjs","src","ui","package.json","bun.lock","README.md"],engines:{node:">=18"},publishConfig:{access:"public",registry:"https://registry.npmjs.org/"},scripts:{daemon:"bun run src/daemon/main.ts",hook:"bun run src/hook/main.ts",cli:"bun run src/cli/main.ts",build:"bun run scripts/build.ts","build:all":"bun run scripts/build.ts --all","build:install":"bun run scripts/build-install.ts","build:dist":"bun run scripts/build.ts && bun run scripts/build-install.ts",prepublishOnly:"bun run build:dist",typecheck:"tsc --noEmit"},devDependencies:{"@types/bun":"^1.3.14","@types/react":"^19.2.17","@types/react-dom":"^19.2.3",typescript:"^6.0.3"},dependencies:{marked:"^18.0.5",react:"^19.2.7","react-dom":"^19.2.7"}};var h=require("node:os"),c="shine-code-submit",W=P.version,f1=process.env.SHINE_CODE_SUBMIT_HOST??"0.0.0.0",C1="127.0.0.1",l=36666,N=`http://${C1}:${l}`;function x1(){let b=["vethernet","vmware","virtualbox","docker","veth","br-","virbr","vnet","utun"],q=(z)=>{let Q=z.toLowerCase();return b.some((X)=>Q.includes(X))};try{let z=h.networkInterfaces();for(let Q of Object.keys(z)){if(q(Q))continue;for(let X of z[Q]??[])if(X.family==="IPv4"&&!X.internal)return X.address}for(let Q of Object.keys(z))for(let X of z[Q]??[])if(X.family==="IPv4"&&!X.internal)return X.address}catch{}return"localhost"}var u=`http://${x1()}:${l}`;var $="shine-code-submit",g="shine-code-submit";function R(b=W){return G.join(U(),"cache",$,g,b)}function v1(){let b=G.dirname(d.fileURLToPath("file:///C:/Users/ren/Desktop/workspace/livesetting/src/install/deploy.ts")),q=b;for(let z=0;z<10;z++){if(Z.existsSync(G.join(q,"package.json"))&&Z.existsSync(G.join(q,".claude-plugin")))return q;let Q=G.dirname(q);if(Q===q)break;q=Q}return b}var j1=[".claude-plugin","hooks","bin","src","ui","package.json","bun.lock","README.md"];function s(b){let q=R();if(Z.existsSync(q))Z.rmSync(q,{recursive:!0,force:!0});Z.mkdirSync(q,{recursive:!0});let z=v1();console.log(`[shine-code-submit] 部署源:${z}`);for(let X of j1){let J=G.join(z,X);if(!Z.existsSync(J))continue;Z.cpSync(J,G.join(q,X),{recursive:!0})}console.log("[shine-code-submit] 安装运行时依赖(bun install)...");let Q=L.spawnSync(b,["install","--frozen-lockfile"],{cwd:q,shell:process.platform==="win32",encoding:"utf8",stdio:"inherit"}).status;if(Q!==0){if(console.log("[shine-code-submit] --frozen-lockfile 失败,重试普通 bun install"),Q=L.spawnSync(b,["install"],{cwd:q,shell:process.platform==="win32",encoding:"utf8",stdio:"inherit"}).status,Q!==0)throw Error(`bun install 失败(exit ${Q})。请手动在 ${q} 跑 bun install`)}return Z.writeFileSync(G.join(q,".install-version"),JSON.stringify({version:W,installedAt:Date.now()}),"utf8"),console.log(`[shine-code-submit] 已部署到 ${q}`),q}var k=require("node:path");var Y=require("node:fs"),o=require("node:path");function F(b,q){if(!Y.existsSync(b))return q;let z;try{z=Y.readFileSync(b,"utf8")}catch{return q}try{return JSON.parse(z)}catch{let Q=`${b}.bak-corrupt-${Date.now()}`;try{Y.copyFileSync(b,Q),console.error(`[shine-code-submit] WARNING: ${b} JSON 损坏,已备份到 ${Q},用默认值继续`)}catch{}return q}}function K(b,q){let z=`${b}.bak-pre-install`;if(Y.existsSync(b)&&!Y.existsSync(z))try{Y.copyFileSync(b,z)}catch{}Y.mkdirSync(o.dirname(b),{recursive:!0});let Q=`${b}.tmp-${process.pid}`;Y.writeFileSync(Q,JSON.stringify(q,null,2),"utf8"),Y.renameSync(Q,b)}function _(){return`${g}@${$}`}function r(b){let q=j(),z=F(q,{}),Q=k.join(b,".claude-plugin"),X=z[$];if(X?.source&&X.source.source!=="directory")console.log(`[shine-code-submit] WARNING: marketplace "${$}" 已存在(source=${X.source.source}),将覆盖为 directory 源(原文件已备份)`);z[$]={source:{source:"directory",path:Q},installLocation:k.join(U(),"marketplaces",$),lastUpdated:new Date().toISOString(),autoUpdate:!1},K(q,z),console.log(`[shine-code-submit] marketplace 已注册 → ${q}`)}function t(b){let q=O(),z=F(q,{version:2,plugins:{}});if(!z.version)z.version=2;if(!z.plugins)z.plugins={};let Q=_(),X=new Date().toISOString(),J=z.plugins[Q]?.[0];z.plugins[Q]=[{scope:"user",installPath:b,version:W,installedAt:J?.installedAt??X,lastUpdated:X}],K(q,z),console.log(`[shine-code-submit] plugin 已注册 → ${q}`)}function i(b){let q=B(),z=F(q,{});if(!z.enabledPlugins)z.enabledPlugins={};let Q=_();if(z.enabledPlugins[Q]=!0,!z.extraKnownMarketplaces)z.extraKnownMarketplaces={};if(!z.extraKnownMarketplaces[$])z.extraKnownMarketplaces[$]={source:{source:"directory",path:k.join(b,".claude-plugin")}};K(q,z),console.log(`[shine-code-submit] 已启用(enabledPlugins)→ ${q}`)}function n(){let b=_(),q=F(j(),{});if(q[$])delete q[$],K(j(),q);let z=F(O(),{plugins:{}});if(z.plugins&&z.plugins[b])delete z.plugins[b],K(O(),z);let Q=F(B(),{}),X=!1;if(Q.enabledPlugins&&Q.enabledPlugins[b])delete Q.enabledPlugins[b],X=!0;if(Q.extraKnownMarketplaces&&Q.extraKnownMarketplaces[$])delete Q.extraKnownMarketplaces[$],X=!0;if(X)K(B(),Q);console.log("[shine-code-submit] 已从三处 JSON 移除注册")}var a=require("node:child_process"),f=require("node:fs");async function C(b=400){try{let q=await fetch(`${N}/api/health`,{signal:AbortSignal.timeout(b)});if(!q.ok)return!1;return(await q.json())?.service===c}catch{return!1}}function e(b){let q=process.platform,z,Q;if(q==="win32")z="cmd",Q=["/c","start","",b];else if(q==="darwin")z="open",Q=[b];else if(O1())z="cmd.exe",Q=["/c","start","",b];else z="xdg-open",Q=[b];try{a.spawn(z,Q,{detached:!0,stdio:"ignore"}).unref()}catch{}}function O1(){if(process.platform!=="linux")return!1;try{return f.readFileSync("/proc/version","utf8").toLowerCase().includes("microsoft")}catch{return!1}}var H=require("node:path"),b1=require("node:fs"),q1=require("node:os"),B1=process.env.LOCALAPPDATA??H.join(q1.homedir(),".local","share"),x=H.join(B1,"shine-code-submit"),N1=H.join(x,"spool"),z1=H.join(x,"log"),Q1=H.join(x,"db"),X1=H.join(x,"daemon.pid"),i1=H.join(z1,"daemon.log"),n1=H.join(Q1,"events.sqlite");function Y1(){for(let b of[x,N1,z1,Q1])b1.mkdirSync(b,{recursive:!0})}var w=require("node:fs");function D(){try{let b=w.readFileSync(X1,"utf8");return JSON.parse(b)}catch{return null}}var[,,G1]=process.argv;u1().catch((b)=>{console.error(`[shine-code-submit] ${b instanceof Error?b.message:String(b)}`),process.exit(1)});async function u1(){switch(G1){case void 0:case"install":await k1();break;case"uninstall":await w1();break;case"status":await D1();break;case"--version":case"-v":console.log(W);break;default:I1()}}async function k1(){console.log(`=== shine-code-submit installer v${W} ===`);let b=await p(),q=s(b);r(q),t(q),i(q),Y1(),await T1(b,q),M1(),console.log(""),console.log("✓ 安装完成。"),console.log(" · 重启 Claude Code 后,/plugin 列表会显示 shine-code-submit(已启用)。"),console.log(" · 开新会话即触发 SessionStart hook,事件出现在 dashboard。")}async function w1(){console.log("=== shine-code-submit uninstaller ==="),await y1(),n();let b=R();if(T.existsSync(b))T.rmSync(b,{recursive:!0,force:!0}),console.log(`[shine-code-submit] 已删除 ${b}`);console.log("✓ 已卸载。重启 Claude Code 后 /plugin 不再显示。")}async function D1(){let b=await C(),q=D();if(b&&q)console.log(`daemon: running pid=${q.pid} ${u}`);else console.log("daemon: not running")}async function T1(b,q){if(await C()){console.log("[shine-code-submit] daemon 已在运行,跳过启动");return}let z=Z1.join(q,"src","daemon","main.ts");console.log("[shine-code-submit] 启动 daemon...");try{$1.spawn(b,["run",z],{detached:!0,stdio:"ignore",windowsHide:!0,cwd:q,shell:process.platform==="win32"}).unref()}catch(X){console.error(`[shine-code-submit] 启动 daemon 失败:${X instanceof Error?X.message:X}`),console.error(" plugin 已注册,Claude Code 重启后 hook 会自动拉起 daemon");return}let Q=Date.now()+1e4;while(Date.now()<Q)if(await H1(200),await C()){console.log("[shine-code-submit] daemon 已就绪");return}console.error("[shine-code-submit] daemon 启动超时(10s)。plugin 已注册,可稍后手动 `shine-code-submit start` 或重启 claude。")}async function y1(){let b=D();if(!b){console.log("[shine-code-submit] daemon 未运行(无 pid 文件)");return}if(await C()){try{await fetch(`${N}/api/shutdown`,{method:"POST",headers:{authorization:`Bearer ${b.token}`}})}catch{}if(await H1(1000),await C())try{process.kill(b.pid)}catch{}}console.log("[shine-code-submit] daemon 已停止")}function M1(){let b=D(),q=b?`${u}/ui?t=${b.token}`:`${u}/ui`;console.log(`[shine-code-submit] Dashboard: ${q}`);try{e(q)}catch{}}function H1(b){return new Promise((q)=>setTimeout(q,b))}function I1(){console.log(`shine-code-submit <command>
|
|
2
|
+
var D=require("node:fs"),Y1=require("node:path"),Z1=require("node:child_process");var m=require("node:fs"),S=require("node:os"),I=require("node:path"),j=require("node:child_process"),H1=[1,1,0],W1=300000;function y(){let b=j.spawnSync("bun",["--version"],{shell:process.platform==="win32",encoding:"utf8"});if(b.status===0&&(b.stdout??"").trim())return"bun";let q=S.homedir(),z=process.platform==="win32"?[I.join(q,".bun","bin","bun.exe")]:[I.join(q,".bun","bin","bun"),"/usr/local/bin/bun","/opt/homebrew/bin/bun"];for(let Q of z)if(m.existsSync(Q))return Q;return null}function J1(b){return b.trim().split(".").map((q)=>parseInt(q,10)||0)}function F1(b,q){let z=J1(b);for(let Q=0;Q<q.length;Q++){let X=z[Q]??0,J=q[Q]??0;if(X>J)return!0;if(X<J)return!1}return!0}function K1(){let b=process.env.npm_config_registry??"";return/npmmirror|taobao/i.test(b)}function M(b){return j.spawnSync(b,{shell:!0,encoding:"utf8",timeout:W1,stdio:"inherit"}).status??1}async function p(){let b=y();if(b){let z=j.spawnSync(b,["--version"],{shell:process.platform==="win32",encoding:"utf8"}).stdout?.trim()??"";if(z&&F1(z,H1))return console.log(`[shine-code-submit] bun ${z} detected`),b}if(console.log("[shine-code-submit] bun 未找到或版本过低,开始自动安装..."),K1()){if(console.log("[shine-code-submit] 检测到国内 npm 镜像,先尝试 npm install -g bun"),M("npm install -g bun")===0){let z=y();if(z)return console.log("[shine-code-submit] ✓ bun 安装成功(via npm 镜像)"),z}console.log("[shine-code-submit] npm 镜像方式失败,回退官方脚本")}if(process.platform==="win32")M('powershell -c "irm bun.sh/install.ps1 | iex"');else M("curl -fsSL https://bun.sh/install | bash");let q=y();if(!q)throw console.error("[shine-code-submit] bun 自动安装失败。请手动安装后重试:"),console.error(" Windows: winget install Oven-sh.Bun 或 npm install -g bun"),console.error(" macOS: brew install oven-sh/bun/bun"),console.error(" Linux: curl -fsSL https://bun.sh/install | bash"),Error("bun installation failed");return console.log("[shine-code-submit] ✓ bun 安装成功"),q}var $=require("node:fs"),Z=require("node:path"),L=require("node:child_process");var E=require("node:os"),V=require("node:path");function A(){return process.env.CLAUDE_CONFIG_DIR||V.join(E.homedir(),".claude")}function U(){return V.join(A(),"plugins")}function v(){return V.join(U(),"known_marketplaces.json")}function O(){return V.join(U(),"installed_plugins.json")}function B(){return V.join(A(),"settings.json")}var P={name:"shine-code-submit",version:"0.2.1",private:!1,type:"module",description:"Claude Code Hook -> 本地常驻 Daemon 的状态/持久化底座",author:"renguifeng",license:"MIT",repository:{type:"git",url:"http://8.130.168.121:9001/AI/shine-code-submit.git"},homepage:"http://8.130.168.121:9001/AI/shine-code-submit",bugs:{url:"http://8.130.168.121:9001/AI/shine-code-submit/issues"},keywords:["claude","claude-code","plugin","hooks","daemon","dashboard"],bin:{"shine-code-submit":"dist/install.cjs"},files:["dist/install.cjs",".claude-plugin","hooks/hooks.json","bin/launcher.cjs","src","ui","package.json","bun.lock","README.md"],engines:{node:">=18"},publishConfig:{access:"public",registry:"https://registry.npmjs.org/"},scripts:{daemon:"bun run src/daemon/main.ts",hook:"bun run src/hook/main.ts",cli:"bun run src/cli/main.ts",build:"bun run scripts/build.ts","build:all":"bun run scripts/build.ts --all","build:install":"bun run scripts/build-install.ts","build:dist":"bun run scripts/build.ts && bun run scripts/build-install.ts",prepublishOnly:"bun run build:dist",typecheck:"tsc --noEmit"},devDependencies:{"@types/bun":"^1.3.14","@types/react":"^19.2.17","@types/react-dom":"^19.2.3",typescript:"^6.0.3"},dependencies:{marked:"^18.0.5",react:"^19.2.7","react-dom":"^19.2.7"}};var h=require("node:os"),c="shine-code-submit",W=P.version,_1=process.env.SHINE_CODE_SUBMIT_HOST??"0.0.0.0",U1="127.0.0.1",l=36666,N=`http://${U1}:${l}`;function C1(){let b=["vethernet","vmware","virtualbox","docker","veth","br-","virbr","vnet","utun"],q=(z)=>{let Q=z.toLowerCase();return b.some((X)=>Q.includes(X))};try{let z=h.networkInterfaces();for(let Q of Object.keys(z)){if(q(Q))continue;for(let X of z[Q]??[])if(X.family==="IPv4"&&!X.internal)return X.address}for(let Q of Object.keys(z))for(let X of z[Q]??[])if(X.family==="IPv4"&&!X.internal)return X.address}catch{}return"localhost"}var u=`http://${C1()}:${l}`;var G="shine-code-submit",R="shine-code-submit";function g(b=W){return Z.join(U(),"cache",G,R,b)}function x1(){let b=process.argv[1],q=b?Z.dirname(Z.resolve(b)):process.cwd(),z=q;for(let Q=0;Q<10;Q++){if($.existsSync(Z.join(z,"package.json"))&&$.existsSync(Z.join(z,".claude-plugin")))return z;let X=Z.dirname(z);if(X===z)break;z=X}return Z.dirname(q)}var j1=[".claude-plugin","hooks","bin","src","ui","package.json","bun.lock","README.md"];function d(b){let q=g();if($.existsSync(q))$.rmSync(q,{recursive:!0,force:!0});$.mkdirSync(q,{recursive:!0});let z=x1();console.log(`[shine-code-submit] 部署源:${z}`);for(let X of j1){let J=Z.join(z,X);if(!$.existsSync(J))continue;$.cpSync(J,Z.join(q,X),{recursive:!0})}console.log("[shine-code-submit] 安装运行时依赖(bun install)...");let Q=L.spawnSync(b,["install","--frozen-lockfile"],{cwd:q,shell:process.platform==="win32",encoding:"utf8",stdio:"inherit"}).status;if(Q!==0){if(console.log("[shine-code-submit] --frozen-lockfile 失败,重试普通 bun install"),Q=L.spawnSync(b,["install"],{cwd:q,shell:process.platform==="win32",encoding:"utf8",stdio:"inherit"}).status,Q!==0)throw Error(`bun install 失败(exit ${Q})。请手动在 ${q} 跑 bun install`)}return $.writeFileSync(Z.join(q,".install-version"),JSON.stringify({version:W,installedAt:Date.now()}),"utf8"),console.log(`[shine-code-submit] 已部署到 ${q}`),q}var k=require("node:path");var Y=require("node:fs"),o=require("node:path");function F(b,q){if(!Y.existsSync(b))return q;let z;try{z=Y.readFileSync(b,"utf8")}catch{return q}try{return JSON.parse(z)}catch{let Q=`${b}.bak-corrupt-${Date.now()}`;try{Y.copyFileSync(b,Q),console.error(`[shine-code-submit] WARNING: ${b} JSON 损坏,已备份到 ${Q},用默认值继续`)}catch{}return q}}function K(b,q){let z=`${b}.bak-pre-install`;if(Y.existsSync(b)&&!Y.existsSync(z))try{Y.copyFileSync(b,z)}catch{}Y.mkdirSync(o.dirname(b),{recursive:!0});let Q=`${b}.tmp-${process.pid}`;Y.writeFileSync(Q,JSON.stringify(q,null,2),"utf8"),Y.renameSync(Q,b)}function _(){return`${R}@${G}`}function s(b){let q=v(),z=F(q,{}),Q=k.join(b,".claude-plugin"),X=z[G];if(X?.source&&X.source.source!=="directory")console.log(`[shine-code-submit] WARNING: marketplace "${G}" 已存在(source=${X.source.source}),将覆盖为 directory 源(原文件已备份)`);z[G]={source:{source:"directory",path:Q},installLocation:k.join(U(),"marketplaces",G),lastUpdated:new Date().toISOString(),autoUpdate:!1},K(q,z),console.log(`[shine-code-submit] marketplace 已注册 → ${q}`)}function r(b){let q=O(),z=F(q,{version:2,plugins:{}});if(!z.version)z.version=2;if(!z.plugins)z.plugins={};let Q=_(),X=new Date().toISOString(),J=z.plugins[Q]?.[0];z.plugins[Q]=[{scope:"user",installPath:b,version:W,installedAt:J?.installedAt??X,lastUpdated:X}],K(q,z),console.log(`[shine-code-submit] plugin 已注册 → ${q}`)}function t(b){let q=B(),z=F(q,{});if(!z.enabledPlugins)z.enabledPlugins={};let Q=_();if(z.enabledPlugins[Q]=!0,!z.extraKnownMarketplaces)z.extraKnownMarketplaces={};if(!z.extraKnownMarketplaces[G])z.extraKnownMarketplaces[G]={source:{source:"directory",path:k.join(b,".claude-plugin")}};K(q,z),console.log(`[shine-code-submit] 已启用(enabledPlugins)→ ${q}`)}function i(){let b=_(),q=F(v(),{});if(q[G])delete q[G],K(v(),q);let z=F(O(),{plugins:{}});if(z.plugins&&z.plugins[b])delete z.plugins[b],K(O(),z);let Q=F(B(),{}),X=!1;if(Q.enabledPlugins&&Q.enabledPlugins[b])delete Q.enabledPlugins[b],X=!0;if(Q.extraKnownMarketplaces&&Q.extraKnownMarketplaces[G])delete Q.extraKnownMarketplaces[G],X=!0;if(X)K(B(),Q);console.log("[shine-code-submit] 已从三处 JSON 移除注册")}var n=require("node:child_process"),f=require("node:fs");async function C(b=400){try{let q=await fetch(`${N}/api/health`,{signal:AbortSignal.timeout(b)});if(!q.ok)return!1;return(await q.json())?.service===c}catch{return!1}}function a(b){let q=process.platform,z,Q;if(q==="win32")z="cmd",Q=["/c","start","",b];else if(q==="darwin")z="open",Q=[b];else if(v1())z="cmd.exe",Q=["/c","start","",b];else z="xdg-open",Q=[b];try{n.spawn(z,Q,{detached:!0,stdio:"ignore"}).unref()}catch{}}function v1(){if(process.platform!=="linux")return!1;try{return f.readFileSync("/proc/version","utf8").toLowerCase().includes("microsoft")}catch{return!1}}var H=require("node:path"),e=require("node:fs"),b1=require("node:os"),O1=process.env.LOCALAPPDATA??H.join(b1.homedir(),".local","share"),x=H.join(O1,"shine-code-submit"),B1=H.join(x,"spool"),q1=H.join(x,"log"),z1=H.join(x,"db"),Q1=H.join(x,"daemon.pid"),t1=H.join(q1,"daemon.log"),i1=H.join(z1,"events.sqlite");function X1(){for(let b of[x,B1,q1,z1])e.mkdirSync(b,{recursive:!0})}var w=require("node:fs");function T(){try{let b=w.readFileSync(Q1,"utf8");return JSON.parse(b)}catch{return null}}var[,,$1]=process.argv;N1().catch((b)=>{console.error(`[shine-code-submit] ${b instanceof Error?b.message:String(b)}`),process.exit(1)});async function N1(){switch($1){case void 0:case"install":await u1();break;case"uninstall":await k1();break;case"status":await w1();break;case"--version":case"-v":console.log(W);break;default:M1()}}async function u1(){console.log(`=== shine-code-submit installer v${W} ===`);let b=await p(),q=d(b);s(q),r(q),t(q),X1(),await T1(b,q),y1(),console.log(""),console.log("✓ 安装完成。"),console.log(" · 重启 Claude Code 后,/plugin 列表会显示 shine-code-submit(已启用)。"),console.log(" · 开新会话即触发 SessionStart hook,事件出现在 dashboard。")}async function k1(){console.log("=== shine-code-submit uninstaller ==="),await D1(),i();let b=g();if(D.existsSync(b))D.rmSync(b,{recursive:!0,force:!0}),console.log(`[shine-code-submit] 已删除 ${b}`);console.log("✓ 已卸载。重启 Claude Code 后 /plugin 不再显示。")}async function w1(){let b=await C(),q=T();if(b&&q)console.log(`daemon: running pid=${q.pid} ${u}`);else console.log("daemon: not running")}async function T1(b,q){if(await C()){console.log("[shine-code-submit] daemon 已在运行,跳过启动");return}let z=Y1.join(q,"src","daemon","main.ts");console.log("[shine-code-submit] 启动 daemon...");try{Z1.spawn(b,["run",z],{detached:!0,stdio:"ignore",windowsHide:!0,cwd:q,shell:process.platform==="win32"}).unref()}catch(X){console.error(`[shine-code-submit] 启动 daemon 失败:${X instanceof Error?X.message:X}`),console.error(" plugin 已注册,Claude Code 重启后 hook 会自动拉起 daemon");return}let Q=Date.now()+1e4;while(Date.now()<Q)if(await G1(200),await C()){console.log("[shine-code-submit] daemon 已就绪");return}console.error("[shine-code-submit] daemon 启动超时(10s)。plugin 已注册,可稍后手动 `shine-code-submit start` 或重启 claude。")}async function D1(){let b=T();if(!b){console.log("[shine-code-submit] daemon 未运行(无 pid 文件)");return}if(await C()){try{await fetch(`${N}/api/shutdown`,{method:"POST",headers:{authorization:`Bearer ${b.token}`}})}catch{}if(await G1(1000),await C())try{process.kill(b.pid)}catch{}}console.log("[shine-code-submit] daemon 已停止")}function y1(){let b=T(),q=b?`${u}/ui?t=${b.token}`:`${u}/ui`;console.log(`[shine-code-submit] Dashboard: ${q}`);try{a(q)}catch{}}function G1(b){return new Promise((q)=>setTimeout(q,b))}function M1(){console.log(`shine-code-submit <command>
|
|
3
3
|
|
|
4
4
|
install 安装插件(自动装 bun + 部署 + 注册 + 启 daemon + 开 dashboard)
|
|
5
5
|
uninstall 卸载(停 daemon + 反注册 + 删文件)
|
|
6
6
|
status 显示 daemon 状态
|
|
7
7
|
|
|
8
|
-
通常通过 npx 跑:npx shine-code-submit install`),process.exit(
|
|
8
|
+
通常通过 npx 跑:npx shine-code-submit install`),process.exit($1?1:0)}
|
package/package.json
CHANGED
package/src/install/deploy.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// 部署 plugin 文件到 claude cache 目录,并跑 bun install 装运行时依赖(marked/react)。
|
|
2
2
|
import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
4
|
import { spawnSync } from "node:child_process";
|
|
6
5
|
import { pluginsRoot } from "./paths";
|
|
7
6
|
import { SERVICE_VERSION } from "../shared/config";
|
|
@@ -14,17 +13,21 @@ export function cacheDir(version: string = SERVICE_VERSION): string {
|
|
|
14
13
|
return join(pluginsRoot(), "cache", MARKETPLACE_NAME, PLUGIN_NAME, version);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
/** 找 npm
|
|
16
|
+
/** 找 npm 包根:运行入口(dist/install.cjs)所在目录上溯到含 package.json + .claude-plugin 的目录。
|
|
17
|
+
* 不能用 import.meta.url —— Bun 打 cjs 单文件 bundle 时会把它静态固化为构建机的源码绝对路径,
|
|
18
|
+
* 换台机器就指向不存在的目录,部署白名单全拷不到、bun install 必失败。
|
|
19
|
+
* 改用 process.argv[1](node 入口脚本运行时绝对路径),跨机器 / npx / npm-g 全稳定。 */
|
|
18
20
|
function findPackageRoot(): string {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
+
const entry = process.argv[1];
|
|
22
|
+
const start = entry ? dirname(resolve(entry)) : process.cwd();
|
|
23
|
+
let dir = start;
|
|
21
24
|
for (let i = 0; i < 10; i++) {
|
|
22
25
|
if (existsSync(join(dir, "package.json")) && existsSync(join(dir, ".claude-plugin"))) return dir;
|
|
23
26
|
const parent = dirname(dir);
|
|
24
27
|
if (parent === dir) break;
|
|
25
28
|
dir = parent;
|
|
26
29
|
}
|
|
27
|
-
return
|
|
30
|
+
return dirname(start);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/** 要部署的文件/目录白名单(plugin 运行必需;不含 dist/install.cjs——install CLI 本身不进 plugin)。 */
|