@leviyuan/lodestar 0.11.4 → 0.11.5
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/dist/lodestar.js +1 -1
- package/package.json +1 -1
package/dist/lodestar.js
CHANGED
|
@@ -331,7 +331,7 @@ ${z}`,card:VY({slug:"wt",branch:"work/*",status:Q,body:z,template:"red"})}}}asyn
|
|
|
331
331
|
|
|
332
332
|
${W} 报告发生了上下文压缩,但当前没有可写的对话卡片。`);return}if(this.startWorkingFooter(Z),Z.currentAssistantSegmentId)this.finalizeCurrentAssistantSegment();if(Z.openReadBatchI=null,this.maybeMidTurnRotate(),x.phase==="start"){let W=Z.contextCompactCount++,H=c$0(x);Z.contextCompactionPending.set(H,{i:W,cardId:Z.cardId,notice:x});let K=G0.contextCompact(W);u(`session "${this.sessionName}": context compaction start #${W+1} key=${H}`),px(Z.cardId,JY(W,x,K),{type:"insert_before",targetElementId:G0.footer}),jX(Z.cardId,`\uD83D\uDEA8 压缩×${Z.contextCompactCount}`);return}let Q=x.itemId&&Z.contextCompactionPending.has(x.itemId)?x.itemId:q$0(Z),J=Q?Z.contextCompactionPending.get(Q):void 0;if(Q)Z.contextCompactionPending.delete(Q);let X=b$0(J?.notice,x),z=J?.i??Z.contextCompactCount++,Y=J?.cardId??Z.cardId,G=G0.contextCompact(z);if(u(`session "${this.sessionName}": context compaction completed #${z+1}${Q?` key=${Q}`:""}`),J)zx(Y,G,JY(z,X,G));else px(Y,JY(z,X,G),{type:"insert_before",targetElementId:G0.footer});jX(Z.cardId,`\uD83D\uDEA8 压缩×${Z.contextCompactCount}`)}handleTurnPlanUpdated(x){let Z=this.currentTurn;if(!Z){u(`session "${this.sessionName}": turn/plan/updated with no current turn`);return}if(this.startWorkingFooter(Z),Z.currentAssistantSegmentId)this.finalizeCurrentAssistantSegment();if(Z.openReadBatchI=null,!Array.isArray(x.plan))u(`session "${this.sessionName}": turn/plan/updated missing plan array`),Z.planSteps=[];else Z.planSteps=x.plan.map((Q)=>({step:typeof Q.step==="string"&&Q.step?Q.step:"MISS",status:typeof Q.status==="string"&&Q.status?Q.status:"MISS"}));Z.planExplanation=typeof x.explanation==="string"?x.explanation:null,this.addPlanSnapshotOnCurrentTurn()}handlePlanDelta(x){if(typeof x.delta!=="string"||!x.delta){u(`session "${this.sessionName}": item/plan/delta missing delta text`);return}if(typeof x.itemId!=="string"||!x.itemId)u(`session "${this.sessionName}": item/plan/delta missing itemId`)}handleThreadGoalUpdated(x){if(!x||typeof x.objective!=="string"){u(`session "${this.sessionName}": thread/goal/updated missing objective`);return}if(x.tokenBudget!=null&&typeof x.tokenBudget!=="number")u(`session "${this.sessionName}": thread/goal/updated invalid tokenBudget`);let Z=this.currentGoal,Q={objective:x.objective,status:typeof x.status==="string"&&x.status?x.status:"MISS",tokenBudget:typeof x.tokenBudget==="number"?x.tokenBudget:x.tokenBudget===null?null:Number.NaN,tokensUsed:typeof x.tokensUsed==="number"?x.tokensUsed:Number.NaN,timeUsedSeconds:typeof x.timeUsedSeconds==="number"?x.timeUsedSeconds:Number.NaN};if(this.currentGoal=Q,Z&&lX(Z)===lX(Q))return;let J=this.currentTurn;if(J){if(this.startWorkingFooter(J),J.currentAssistantSegmentId)this.finalizeCurrentAssistantSegment();J.openReadBatchI=null}this.addGoalUpdateOnCurrentTurn(Q)}handleThreadGoalCleared(){if(!this.currentGoal)return;this.currentGoal=null;let x=this.currentTurn;if(!x)return;if(this.startWorkingFooter(x),x.currentAssistantSegmentId)this.finalizeCurrentAssistantSegment();x.openReadBatchI=null,this.addGoalClearedOnCurrentTurn()}appendAssistant(x){if(!this.currentTurn)return;let Z=this.currentTurn;if(this.startWritingFooter(Z),!Z.currentAssistantSegmentId){Z.openReadBatchI=null,this.maybeMidTurnRotate();let z=Z.assistantSegmentCount++,Y=G0.assistant(z);Z.currentAssistantSegmentId=Y,Z.currentAssistantText=""}Z.currentAssistantText+=x;let Q=Z.currentAssistantSegmentId;if(!Q)return;Z.segmentTexts.set(Q,Z.currentAssistantText),this.processOutboundMarkers(Z.currentAssistantText),this.processHostAskMarkers(Z.currentAssistantText,Z);let X=this.cleanAssistantTextForDisplay(Z.currentAssistantText).slice(-60);jX(Z.cardId,X)}completedAssistantElement(x,Z){return{tag:"markdown",element_id:x,content:this.cleanAssistantTextForDisplay(Z).trim()||" "}}addCompletedAssistantSegment(x,Z,Q){return px(x.cardId,this.completedAssistantElement(Z,Q),{type:"insert_before",targetElementId:G0.footer})}finalizeCurrentAssistantSegment(){let x=this.currentTurn;if(!x)return;if(x.rotating)return;let Z=x.currentAssistantSegmentId,Q=x.currentAssistantText??"";if(Z&&Q.trim())this.addCompletedAssistantSegment(x,Z,Q),this.startWorkingFooter(x);x.currentAssistantSegmentId=null,x.currentAssistantText=""}processOutboundMarkers(x){for(let Z of Qw(x))this.sendOutboundPath(Z,"send marker")}processHostAskMarkers(x,Z){if(this.proc?.provider!=="codex")return;for(let Q of Jw(x)){if(Z.hostAskMarkersSeen.has(Q.raw))continue;Z.hostAskMarkersSeen.add(Q.raw),mw(this,Q.payload,Q.raw)}}cleanAssistantTextForDisplay(x){let Z=this.proc?.provider==="codex"?`
|
|
333
333
|
|
|
334
|
-
_已发起澄清问题,请回答对应卡片。_`:"";return Xw(x,Z)}sendOutboundPath(x,Z){let Q=x.trim();if(!Q)return;let J=this.currentTurn;if(J?.outboundSeenPaths.has(Q))return;if(J?.outboundSeenPaths.add(Q),!I$0(Q)){u(`session "${this.sessionName}": ignore non-absolute outbound path from ${Z}: ${Q}`);return}J?.outboundSentPaths.add(Q),u(`session "${this.sessionName}": outbound send from ${Z}: ${Q}`),Au(this.chatId,Q)}startFooterStatus(x,Z){if(x.footerStatusHandle&&x.footerStatusLabel===Z)return;this.stopFooterStatus(x),x.footerStatusLabel=Z,x.footerStatusStartedAt=Date.now();let Q=()=>{if(x.footerStatusHandle==null||!x.footerStatusLabel)return;let J=Math.max(0,Math.floor((Date.now()-x.footerStatusStartedAt)/1000));this.replaceFooterContent(x.cardId,this.withModel(`${x.footerStatusLabel}(${J}s)`))};x.footerStatusHandle=setInterval(Q,bf),Q()}startThinkingFooter(x){this.startFooterStatus(x,A$0)}startWritingFooter(x){this.startFooterStatus(x,E$0)}startWorkingFooter(x){this.startFooterStatus(x,k$0)}stopFooterStatus(x){if(!x)return;if(x.footerStatusHandle)clearInterval(x.footerStatusHandle);x.footerStatusHandle=null,x.footerStatusStartedAt=0,x.footerStatusLabel=null}async footerFiveHourSuffix(){let x=null;if(this.proc?.provider==="claude"){let Z=await yU();if(Z.state==="ok")x=Z.fiveHour?.percent??null}else{let Z=sP();if(Z?.state==="ok")x=Z.fiveHour?.percent??null}return x!=null?` | 5h·${Math.round(x)}%`:""}async closeTurnCard(x,Z={}){let Q=this.currentTurn;if(!Q)return;this.currentTurn=null,this.stopFooterStatus(Q);let J=((Date.now()-Q.startedAt)/1000).toFixed(1),X=Q.cardId,z=Q.segmentTexts;if(await c4(X),Q.currentAssistantSegmentId&&Q.currentAssistantText.trim())await this.addCompletedAssistantSegment(Q,Q.currentAssistantSegmentId,Q.currentAssistantText),Q.currentAssistantSegmentId=null,Q.currentAssistantText="";for(let[D,O]of z)await zx(X,D,this.completedAssistantElement(D,O));let G=[`${x?x:"✅"} ⏱ ${J}s`];if(Z.hasFreshResult){let D=this.currentContextTokens(),O=this.contextLimitForDisplay(),v=this.proc?.provider==="claude",B=UU(D,O,v?0:void 0);if(B)G.push(`\uD83E\uDDE0 ${B}`);let j=this.lastTurnDelta?.costUsd??0;if(j>0)G.push(`\uD83D\uDCB0 $${j.toFixed(3)}`)}if(Q.contextCompactCount>0)G.push(`\uD83D\uDEA8 压缩×${Q.contextCompactCount}`);if(Q.outboundSentPaths.size>0)G.push(`\uD83D\uDCCE ${Q.outboundSentPaths.size}`);let W=this.modelLine();if(W)G.push(W);let H=G.join(" | "),K=Z.hasFreshResult?NU(this.lastTurnUsage)+await this.footerFiveHourSuffix():"",N=K?`${H}
|
|
334
|
+
_已发起澄清问题,请回答对应卡片。_`:"";return Xw(x,Z)}sendOutboundPath(x,Z){let Q=x.trim();if(!Q)return;let J=this.currentTurn;if(J?.outboundSeenPaths.has(Q))return;if(J?.outboundSeenPaths.add(Q),!I$0(Q)){u(`session "${this.sessionName}": ignore non-absolute outbound path from ${Z}: ${Q}`);return}J?.outboundSentPaths.add(Q),u(`session "${this.sessionName}": outbound send from ${Z}: ${Q}`),Au(this.chatId,Q)}startFooterStatus(x,Z){if(x.footerStatusHandle&&x.footerStatusLabel===Z)return;this.stopFooterStatus(x),x.footerStatusLabel=Z,x.footerStatusStartedAt=Date.now();let Q=()=>{if(x.footerStatusHandle==null||!x.footerStatusLabel)return;let J=Math.max(0,Math.floor((Date.now()-x.footerStatusStartedAt)/1000));this.replaceFooterContent(x.cardId,this.withModel(`${x.footerStatusLabel}(${J}s)`))};x.footerStatusHandle=setInterval(Q,bf),Q()}startThinkingFooter(x){this.startFooterStatus(x,A$0)}startWritingFooter(x){this.startFooterStatus(x,E$0)}startWorkingFooter(x){this.startFooterStatus(x,k$0)}stopFooterStatus(x){if(!x)return;if(x.footerStatusHandle)clearInterval(x.footerStatusHandle);x.footerStatusHandle=null,x.footerStatusStartedAt=0,x.footerStatusLabel=null}async footerFiveHourSuffix(){let x=null;if(this.proc?.provider==="claude"){let Z=await yU();if(Z.state==="ok")x=Z.fiveHour?.percent??null}else{let Z=sP();if(Z?.state==="ok")x=Z.fiveHour?.percent??null}return x!=null?` | 5h·${Math.round(x)}%`:""}async closeTurnCard(x,Z={}){let Q=this.currentTurn;if(!Q)return;if(this.currentTurn=null,this.stopFooterStatus(Q),Q.rotating)await Q.rotating;this.stopFooterStatus(Q);let J=((Date.now()-Q.startedAt)/1000).toFixed(1),X=Q.cardId,z=Q.segmentTexts;if(await c4(X),Q.currentAssistantSegmentId&&Q.currentAssistantText.trim())await this.addCompletedAssistantSegment(Q,Q.currentAssistantSegmentId,Q.currentAssistantText),Q.currentAssistantSegmentId=null,Q.currentAssistantText="";for(let[D,O]of z)await zx(X,D,this.completedAssistantElement(D,O));let G=[`${x?x:"✅"} ⏱ ${J}s`];if(Z.hasFreshResult){let D=this.currentContextTokens(),O=this.contextLimitForDisplay(),v=this.proc?.provider==="claude",B=UU(D,O,v?0:void 0);if(B)G.push(`\uD83E\uDDE0 ${B}`);let j=this.lastTurnDelta?.costUsd??0;if(j>0)G.push(`\uD83D\uDCB0 $${j.toFixed(3)}`)}if(Q.contextCompactCount>0)G.push(`\uD83D\uDEA8 压缩×${Q.contextCompactCount}`);if(Q.outboundSentPaths.size>0)G.push(`\uD83D\uDCCE ${Q.outboundSentPaths.size}`);let W=this.modelLine();if(W)G.push(W);let H=G.join(" | "),K=Z.hasFreshResult?NU(this.lastTurnUsage)+await this.footerFiveHourSuffix():"",N=K?`${H}
|
|
335
335
|
${K}`:H;if(await this.replaceFooterContent(X,N),K8(X),await W8(X,O6({durationSec:J,outputTokens:Z.hasFreshResult?this.lastTurnUsage?.output_tokens:void 0,suffix:x})),await q8(X),(Z.forcePush||!x)&&Q.userOpenId&&Q.messageId)z5(Q.messageId,[Q.userOpenId]);let L=[...this.currentBatchReactionIds.entries(),...this.pendingReactionIds.entries()];if(L.length>0){for(let[D,O]of L)if(O)B3(D,O);this.currentBatchReactionIds=new Map,this.pendingReactionIds=new Map}}}});function k4(x){return{card:{type:"raw",data:x}}}import{createServer as u$0}from"node:http";function w$0(x){let Z=x.level==="error"?"red":x.level==="warn"?"yellow":"blue",Q=x.level==="error"?"❌":x.level==="warn"?"⚠️":"\uD83D\uDD14",J=new Date,X=`${String(J.getHours()).padStart(2,"0")}:${String(J.getMinutes()).padStart(2,"0")}`;return{schema:"2.0",config:{},header:{title:{tag:"plain_text",content:`${Q} ${x.title}`},template:Z},body:{elements:[{tag:"markdown",content:x.text||"_(空消息)_"},{tag:"hr"},{tag:"markdown",content:`<font color='grey'>via notify · ${X}</font>`}]}}}function Pf(x){try{let Z=u$0((Q,J)=>{f$0(Q,J).catch((X)=>{if(u(`notify: handler crash: ${X?.message??X}`),!J.headersSent)J.statusCode=500,J.setHeader("content-type","text/plain; charset=utf-8"),J.end("internal error");else try{J.end()}catch{}})});Z.on("error",(Q)=>{u(`notify: server bind failed (${x.bind}:${x.port}): ${Q.message}`)}),Z.listen(x.port,x.bind,()=>{u(`notify: HTTP listening at http://${x.bind}:${x.port}/notify`)})}catch(Z){u(`notify: server bind failed (${x.bind}:${x.port}): ${Z}`)}}async function f$0(x,Z){let Q=new URL(x.url??"/",`http://${x.headers.host??"localhost"}`),J=(j,c)=>{Z.statusCode=j,Z.setHeader("content-type","text/plain; charset=utf-8"),Z.end(c)},X=(j,c)=>{Z.statusCode=j,Z.setHeader("content-type","application/json"),Z.end(JSON.stringify(c))};if(x.method==="GET"&&Q.pathname==="/")return J(200,`lodestar notify
|
|
336
336
|
`+`POST /notify body={project,text,title?,level?} → push card to group
|
|
337
337
|
`+`levels: info|warn|error (default info)
|