shennian 0.3.43 → 0.3.45

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.
@@ -306,8 +306,8 @@
306
306
  },
307
307
  {
308
308
  "file": "src/native-fusion/codex-parser.js",
309
- "beforeBytes": 28990,
310
- "afterBytes": 12133
309
+ "beforeBytes": 29910,
310
+ "afterBytes": 12631
311
311
  },
312
312
  {
313
313
  "file": "src/native-fusion/config.js",
@@ -321,8 +321,8 @@
321
321
  },
322
322
  {
323
323
  "file": "src/native-fusion/local-repository.js",
324
- "beforeBytes": 11197,
325
- "afterBytes": 5755
324
+ "beforeBytes": 13247,
325
+ "afterBytes": 6702
326
326
  },
327
327
  {
328
328
  "file": "src/native-fusion/opencode-parser.js",
@@ -556,8 +556,8 @@
556
556
  },
557
557
  {
558
558
  "file": "src/session/index-publisher.js",
559
- "beforeBytes": 1469,
560
- "afterBytes": 731
559
+ "beforeBytes": 1896,
560
+ "afterBytes": 838
561
561
  },
562
562
  {
563
563
  "file": "src/session/manager.js",
@@ -1,6 +1,6 @@
1
- import b from"node:fs";import I from"node:os";import C from"node:path";import{buildApprovalPendingPayload as Z,buildUserMessagePayload as N,isSystemControlPayload as v,isToolPayload as q}from"@shennian/wire";import{buildImagePayload as P,buildToolPayload as D,inferMimeType as W,makeCursor as U,makeEventKey as $,normalizeText as h,parseStructuredString as K,readJsonlLines as w,readTimestamp as O,safeParse as k}from"./parser-common.js";function tt(t){if(typeof t=="string"){const i=t.trim();return i?{path:i,name:C.basename(i)||"image.png",mimeType:W(i),kind:"image"}:null}if(typeof t!="object"||t===null)return null;const r=t,n=typeof r.path=="string"?r.path:typeof r.file_path=="string"?r.file_path:typeof r.saved_path=="string"?r.saved_path:"";if(!n.trim())return null;const e=typeof r.name=="string"&&r.name.trim()?r.name:C.basename(n)||"image.png",o=typeof r.mimeType=="string"&&r.mimeType.trim()?r.mimeType:W(n);return{path:n,name:e,mimeType:o,kind:"image"}}function F(t){return Array.isArray(t)?t.map(n=>{if(typeof n=="string")return n;if(typeof n=="object"&&n!==null){const e=n;return typeof e.text=="string"?e.text:""}return""}).map(n=>h(n)).filter(Boolean).join(`
1
+ import j from"node:fs";import $ from"node:os";import I from"node:path";import{createHash as Z}from"node:crypto";import{buildApprovalPendingPayload as P,buildUserMessagePayload as N,isSystemControlPayload as M,isToolPayload as q}from"@shennian/wire";import{buildImagePayload as D,buildToolPayload as K,inferMimeType as W,makeCursor as U,makeEventKey as w,normalizeText as h,parseStructuredString as O,readJsonlLines as F,readTimestamp as tt,safeParse as k}from"./parser-common.js";function et(e){if(typeof e=="string"){const i=e.trim();return i?{path:i,name:I.basename(i)||"image.png",mimeType:W(i),kind:"image"}:null}if(typeof e!="object"||e===null)return null;const r=e,n=typeof r.path=="string"?r.path:typeof r.file_path=="string"?r.file_path:typeof r.saved_path=="string"?r.saved_path:"";if(!n.trim())return null;const t=typeof r.name=="string"&&r.name.trim()?r.name:I.basename(n)||"image.png",o=typeof r.mimeType=="string"&&r.mimeType.trim()?r.mimeType:W(n);return{path:n,name:t,mimeType:o,kind:"image"}}function H(e){return Array.isArray(e)?e.map(n=>{if(typeof n=="string")return n;if(typeof n=="object"&&n!==null){const t=n;return typeof t.text=="string"?t.text:""}return""}).map(n=>h(n)).filter(Boolean).join(`
2
2
 
3
- `):""}function z(t){const r=h(t);if(!r)return{text:"",strippedWrapper:!1};const n=r.match(/My request for Codex:\s*([\s\S]*)$/i);return n&&n[1]?{text:et(n[1]),strippedWrapper:!0}:{text:r,strippedWrapper:!1}}function et(t){return h(t.replace(/<image>\s*<\/image>/gi,""))}function B(t){const r=h(t);if(!r)return!1;if(v(r)||/^<environment_context>[\s\S]*<\/environment_context>$/i.test(r)&&r.includes("<current_date>")&&r.includes("<timezone>")&&r.includes("<workspace_roots>"))return!0;const n=r.startsWith("<recommended_plugins>")&&r.includes("</recommended_plugins>"),e=r.includes("# AGENTS.md instructions for ")&&r.includes("<INSTRUCTIONS>")&&r.includes("</INSTRUCTIONS>"),o=r.includes("<environment_context>")&&r.includes("</environment_context>");return e&&o&&(r.startsWith("# AGENTS.md instructions for ")||n)}function H(t){const r=F(t.text_elements),n=Array.isArray(t.input)?F(t.input):"",e=typeof t.message=="string"?z(t.message):{text:"",strippedWrapper:!1},o=e.text,i=r||n||o,c=e.strippedWrapper?"codex_app_context_wrapper":void 0,f=Array.isArray(t.local_images)?t.local_images.map(tt).filter(a=>a!=null):[];return!i&&f.length===0||v(i)&&f.length===0||B(i)&&f.length===0?null:f.length>0?{payload:N(i,f),titleText:i,repairHint:c}:{payload:i,titleText:i,repairHint:c}}function nt(t){return t==="turn_completed"||t==="turn_complete"||t==="task_complete"}function rt(t){return/approval|permission|confirm|user[_-]?input|input[_-]?required/i.test(t)}function ot(t){const r=typeof t.command=="string"?t.command:Array.isArray(t.command)?t.command.join(" "):"",n=typeof t.prompt=="string"?t.prompt:typeof t.reason=="string"?t.reason:typeof t.message=="string"?t.message:r?`Codex \u8BF7\u6C42\u6267\u884C\u547D\u4EE4\uFF1A${r}`:"Codex \u6B63\u5728\u7B49\u5F85\u7528\u6237\u786E\u8BA4\u540E\u7EE7\u7EED\u3002";return Z({title:"\u9700\u8981\u7528\u6237\u786E\u8BA4",content:n,source:"codex",actionHint:"\u5F53\u524D\u795E\u5FF5\u6682\u4E0D\u652F\u6301\u8FDC\u7A0B\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230\u8FD0\u884C Codex \u7684\u7535\u8111/\u7EC8\u7AEF\u5B8C\u6210\u786E\u8BA4\u3002"})}function L(t,r){return Array.isArray(t)?h(t.map(n=>{if(typeof n=="string")return n;if(typeof n!="object"||n===null)return"";const e=n;return e.type!==r?"":typeof e.text=="string"?e.text:""}).filter(Boolean).join(`
3
+ `):""}function z(e){const r=h(e);if(!r)return{text:"",strippedWrapper:!1};const n=r.match(/My request for Codex:\s*([\s\S]*)$/i);return n&&n[1]?{text:nt(n[1]),strippedWrapper:!0}:{text:r,strippedWrapper:!1}}function nt(e){return h(e.replace(/<image>\s*<\/image>/gi,""))}function B(e){const r=h(e);if(!r)return!1;if(M(r)||/^<environment_context>[\s\S]*<\/environment_context>$/i.test(r)&&r.includes("<current_date>")&&r.includes("<timezone>")&&r.includes("<workspace_roots>"))return!0;const n=r.startsWith("<recommended_plugins>")&&r.includes("</recommended_plugins>"),t=r.includes("# AGENTS.md instructions for ")&&r.includes("<INSTRUCTIONS>")&&r.includes("</INSTRUCTIONS>"),o=r.includes("<environment_context>")&&r.includes("</environment_context>");return t&&o&&(r.startsWith("# AGENTS.md instructions for ")||n)}function L(e){const r=H(e.text_elements),n=Array.isArray(e.input)?H(e.input):"",t=typeof e.message=="string"?z(e.message):{text:"",strippedWrapper:!1},o=t.text,i=r||n||o,u=t.strippedWrapper?"codex_app_context_wrapper":void 0,a=Array.isArray(e.local_images)?e.local_images.map(et).filter(f=>f!=null):[];return!i&&a.length===0||M(i)&&a.length===0||B(i)&&a.length===0?null:a.length>0?{payload:N(i,a),titleText:i,repairHint:u}:{payload:i,titleText:i,repairHint:u}}function rt(e){return e==="turn_completed"||e==="turn_complete"||e==="task_complete"}function ot(e){return/approval|permission|confirm|user[_-]?input|input[_-]?required/i.test(e)}function it(e){const r=typeof e.command=="string"?e.command:Array.isArray(e.command)?e.command.join(" "):"",n=typeof e.prompt=="string"?e.prompt:typeof e.reason=="string"?e.reason:typeof e.message=="string"?e.message:r?`Codex \u8BF7\u6C42\u6267\u884C\u547D\u4EE4\uFF1A${r}`:"Codex \u6B63\u5728\u7B49\u5F85\u7528\u6237\u786E\u8BA4\u540E\u7EE7\u7EED\u3002";return P({title:"\u9700\u8981\u7528\u6237\u786E\u8BA4",content:n,source:"codex",actionHint:"\u5F53\u524D\u795E\u5FF5\u6682\u4E0D\u652F\u6301\u8FDC\u7A0B\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230\u8FD0\u884C Codex \u7684\u7535\u8111/\u7EC8\u7AEF\u5B8C\u6210\u786E\u8BA4\u3002"})}function G(e,r){return Array.isArray(e)?h(e.map(n=>{if(typeof n=="string")return n;if(typeof n!="object"||n===null)return"";const t=n;return t.type!==r?"":typeof t.text=="string"?t.text:""}).filter(Boolean).join(`
4
4
 
5
- `)):""}function it(t){if(!Array.isArray(t))return[];const r=[];for(const n of t){if(typeof n!="object"||n===null)continue;const e=n;if(e.type!=="input_image")continue;const o=typeof e.path=="string"?e.path:typeof e.file_path=="string"?e.file_path:typeof e.saved_path=="string"?e.saved_path:typeof e.image_path=="string"?e.image_path:"";o.trim()&&r.push({path:o,name:C.basename(o)||"image.png",mimeType:W(o),kind:"image"})}return r}function G(t){if(t.type!=="message")return null;const r=t.role==="assistant"?"agent":t.role==="user"?"user":null;if(!r)return null;if(r==="agent"){const i=L(t.content,"output_text");return v(i)?null:i?{role:r,payload:i,titleText:i}:null}const n=z(L(t.content,"input_text")),e=n.text,o=it(t.content);return!e&&o.length===0||v(e)&&o.length===0||B(e)&&o.length===0?null:{role:r,payload:o.length>0?N(e,o):e,titleText:e,repairHint:n.strippedWrapper?"codex_app_context_wrapper":void 0}}function J(t){if(!t)return"";try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null){const n=r;if(n.type==="user"&&typeof n.content=="string")return h(n.content)}}catch{}return h(t)}function st(t,r,n,e){return t.agentType!=="codex"||t.role!==r||q(t.payload)||Math.abs(t.ts-e)>300*1e3?!1:J(t.payload)===J(n)}function R(t,r,n,e){for(let o=t.length-1;o>=0;o-=1){const i=t[o];if(i){if(st(i,r,n,e))return o;if(i.agentType==="codex"&&Math.abs(i.ts-e)>300*1e3)break}}return-1}function M(t,r,n,e,o,i,c,f,a,u,s="agent",m=!1,l){c&&t.push({agentType:"codex",sourceMode:"codex_rollout_import",sourceSessionKey:o,sourceEventKey:$(r,n,e),cursor:U(r,n),role:s,ts:i,payload:c,title:f,modelId:a,workDir:u,terminal:m,repairHint:l})}function _(t,r,n,e,o,i,c,f,a,u,s,m){const l=$(r,n,e),A=`native:${l}`,y=1,j=m!==void 0?"completed":"running";t.push({agentType:"codex",sourceMode:"codex_rollout_import",sourceSessionKey:o,sourceEventKey:l,cursor:U(r,n),role:"agent",ts:i,payload:D({name:c,toolCallId:A,detailRevision:y,status:j}),title:f,modelId:a,workDir:u,localToolDetail:{toolCallId:A,detailRevision:y,name:c,...s!==void 0?{args:s}:{},...m!==void 0?{result:m}:{},status:j}})}function ut(t,r,n,e,o,i,c,f,a){const u=typeof e.type=="string"?e.type:"";if(u){if(u==="message"){const s=G(e);if(!s||R(t,s.role,s.payload,i)>=0)return;M(t,r,n,`${u}:${s.role}`,o,i,s.payload,c,f,a,s.role,!1,s.repairHint);return}if(u==="function_call"){const s=typeof e.name=="string"?e.name:"function_call";_(t,r,n,u,o,i,s,c,f,a,K(e.arguments));return}if(u==="function_call_output"){_(t,r,n,u,o,i,"function_call_output",c,f,a,e.call_id,e.output);return}if(u==="custom_tool_call"){const s=typeof e.name=="string"?e.name:"custom_tool_call",m=e.input!==void 0?{input:e.input}:void 0;_(t,r,n,u,o,i,s,c,f,a,m);return}if(u==="custom_tool_call_output"){const s=typeof e.name=="string"?e.name:"custom_tool_call_output",m=e.output??e.result??e.content;_(t,r,n,u,o,i,s,c,f,a,e.call_id,m);return}if(u==="web_search_call"){const s=typeof e.action=="object"&&e.action!==null?e.action:null;_(t,r,n,u,o,i,"web_search",c,f,a,s??e.query);return}}}function ct(t,r,n,e,o,i,c,f,a){const u=typeof e.type=="string"?e.type:"";if(u){if(u==="user_message"){const s=H(e);if(!s)return;M(t,r,n,u,o,i,s.payload,c,f,a,"user",!1,s.repairHint);return}if(u==="agent_message"){const s=typeof e.message=="string"?h(e.message):"";if(!s||v(s))return;M(t,r,n,u,o,i,s,c,f,a);return}if(u==="turn_aborted"||u==="error"){const s=typeof e.message=="string"?h(e.message):typeof e.error=="string"?h(e.error):"";if(!s)return;M(t,r,n,u,o,i,s,c,f,a,"agent",!0);return}if(rt(u)){M(t,r,n,u,o,i,ot(e),c,f,a,"agent");return}if(u==="exec_command_end"){const s=Array.isArray(e.command)?e.command:e.parsed_cmd??e.command,m=e.exit_code??e.exitCode,l=[typeof e.aggregated_output=="string"?e.aggregated_output:"",m!=null?`
6
- (exit ${String(m)})`:""].join("");_(t,r,n,u,o,i,"command_execution",c,f,a,{command:s},l);return}if(u==="patch_apply_end"){_(t,r,n,u,o,i,"apply_patch",c,f,a,e.changes,{success:e.success,stdout:e.stdout,stderr:e.stderr});return}if(u==="mcp_tool_call_end"){const s=typeof e.invocation=="object"&&e.invocation!==null?e.invocation:null,m=typeof s?.tool=="string"?s.tool:"mcp_tool_call",l={server:s?.server,...typeof s?.arguments=="object"&&s.arguments!==null?s.arguments:{}};_(t,r,n,u,o,i,m,c,f,a,l,e.result);return}if(u==="dynamic_tool_call_request"){const s=typeof e.tool=="string"?e.tool:"dynamic_tool_call";_(t,r,n,u,o,i,s,c,f,a,e.arguments);return}if(u==="dynamic_tool_call_response"){const s=typeof e.tool=="string"?e.tool:"dynamic_tool_call";_(t,r,n,u,o,i,s,c,f,a,e.callId??e.call_id,e.result??e.output);return}if(u==="web_search_end"){const s=typeof e.action=="object"&&e.action!==null?e.action:null;_(t,r,n,u,o,i,"web_search",c,f,a,s??e.query,e.query);return}if(u==="image_generation_end"){const s=typeof e.saved_path=="string"?e.saved_path.trim():"";if(!s)return;M(t,r,n,u,o,i,P(s),c,f,a);return}u==="view_image_tool_call"&&_(t,r,n,u,o,i,"view_image",c,f,a,e.path??e.image_path??e)}}function E(t=!1){return{sourceSessionKey:"",workDir:"",modelId:null,title:"",skipImport:t}}function Q(t){if((typeof t.thread_source=="string"?t.thread_source.trim().toLowerCase():"")==="subagent")return!0;const n=typeof t.source=="object"&&t.source!==null?t.source:null;if(n&&typeof n.subagent=="object"&&n.subagent!==null)return!0;const e=typeof t.parent_thread_id=="string"&&t.parent_thread_id.trim().length>0,o=typeof t.agent_nickname=="string"||typeof t.agent_role=="string"||typeof t.multi_agent_version=="string";return e&&o}function ft(t){const r=b.openSync(t,"r");try{const n=[];let e=0,o="";for(;e<1024*1024;){const a=Buffer.alloc(16384),u=b.readSync(r,a,0,a.length,e);if(u<=0)break;const s=a.subarray(0,u);n.push(s),e+=u;const m=Buffer.concat(n),l=m.indexOf(10);if(l>=0){o=m.subarray(0,l).toString("utf8");break}}!o&&n.length>0&&(o=Buffer.concat(n).toString("utf8"));const i=k(o);if(!i||i.type!=="session_meta")return E();const c=typeof i.payload=="object"&&i.payload!==null?i.payload:null;if(!c)return E();if(Q(c))return E(!0);const f=typeof c.id=="string"?c.id:"";return{sourceSessionKey:f,workDir:typeof c.cwd=="string"?c.cwd:"",modelId:V(c),title:X(f)??"",skipImport:!1}}finally{b.closeSync(r)}return E()}function V(t){return(typeof t.model=="string"?t.model.trim():"")||null}function at(t,r){if((typeof t.id=="string"?t.id:typeof t.thread_id=="string"?t.thread_id:typeof t.session_id=="string"?t.session_id:"")!==r)return null;const o=(typeof t.thread_name=="string"?t.thread_name:typeof t.title=="string"?t.title:"").trim();return o?o.slice(0,120):null}function X(t){if(!t)return null;const r=C.join(I.homedir(),".codex","session_index.jsonl");if(!b.existsSync(r))return null;let n=null;return w(r,0,e=>{if(!e.trim())return;const o=k(e);if(!o)return;const i=at(o,t);i&&(n=i)}),n}function _t(){const t=[C.join(I.homedir(),".codex","sessions"),C.join(I.homedir(),".codex","archived_sessions")],r=[],n=e=>{for(const o of b.readdirSync(e,{withFileTypes:!0})){const i=C.join(e,o.name);o.isDirectory()?n(i):o.isFile()&&o.name.endsWith(".jsonl")&&r.push(i)}};for(const e of t)b.existsSync(e)&&n(e);return[...new Set(r)].sort()}function xt(t,r){const n=[],e=ft(t);let{sourceSessionKey:o,workDir:i,modelId:c,title:f,skipImport:a}=e,u=e.title;if(a)return{nextOffset:b.statSync(t).size,events:[]};let s=!1;const m=w(t,r,(l,A)=>{const y=k(l);if(!y)return;const j=typeof y.type=="string"?y.type:"",p=typeof y.payload=="object"&&y.payload!==null?y.payload:null,S=O(y.timestamp);if(!(!p||!S)){if(j==="session_meta"){if(Q(p)){n.length=0,a=!0;return}o=typeof p.id=="string"?p.id:o,i=typeof p.cwd=="string"?p.cwd:i,c=V(p)??c;const x=X(o);x&&(u=x,f=x);return}if(!a&&o){if(j==="response_item"){const x=G(p);x?.role==="user"&&x.titleText&&!f&&(f=x.titleText.slice(0,80)),ut(n,t,A,p,o,S,f,c,i);return}if(j==="event_msg"){const x=typeof p.type=="string"?p.type:"";if(nt(x)){let g=!1;for(let d=n.length-1;d>=0;d-=1){const T=n[d];if(T?.agentType==="codex"&&T.role==="agent"&&!q(T.payload)){T.terminal=!0,g=!0,s=!1;break}}if(!g)for(let d=n.length-1;d>=0;d-=1){const T=n[d];if(!(T?.agentType!=="codex"||T.role!=="agent")){T.terminal=!0,g=!0,s=!1;break}}g||(s=!0);return}if(x==="user_message"){const g=H(p);if(g?.titleText&&!f&&(f=g.titleText.slice(0,80)),g){const d=R(n,"user",g.payload,S);d>=0&&n.splice(d,1)}}else if(x==="agent_message"){const g=typeof p.message=="string"?h(p.message):"";if(g&&!v(g)){const d=R(n,"agent",g,S);d>=0&&n.splice(d,1)}}const Y=n.length;ct(n,t,A,p,o,S,f,c,i),s&&n.length>Y&&(n[n.length-1].terminal=!0,s=!1)}}}});for(const l of n)l.titleSource=u&&l.title===u?"agent_native":"first_user_fallback";return{nextOffset:m,events:n}}export{_t as listCodexRolloutFiles,X as lookupCodexThreadName,xt as parseCodexRolloutChunk};
5
+ `)):""}function st(e){if(!Array.isArray(e))return[];const r=[];for(const n of e){if(typeof n!="object"||n===null)continue;const t=n;if(t.type!=="input_image")continue;const o=typeof t.path=="string"?t.path:typeof t.file_path=="string"?t.file_path:typeof t.saved_path=="string"?t.saved_path:typeof t.image_path=="string"?t.image_path:"";o.trim()&&r.push({path:o,name:I.basename(o)||"image.png",mimeType:W(o),kind:"image"})}return r}function J(e){if(e.type!=="message")return null;const r=e.role==="assistant"?"agent":e.role==="user"?"user":null;if(!r)return null;if(r==="agent"){const i=G(e.content,"output_text");return M(i)?null:i?{role:r,payload:i,titleText:i}:null}const n=z(G(e.content,"input_text")),t=n.text,o=st(e.content);return!t&&o.length===0||M(t)&&o.length===0||B(t)&&o.length===0?null:{role:r,payload:o.length>0?N(t,o):t,titleText:t,repairHint:n.strippedWrapper?"codex_app_context_wrapper":void 0}}function Q(e){if(!e)return"";try{const r=JSON.parse(e);if(typeof r=="object"&&r!==null){const n=r;if(n.type==="user"&&typeof n.content=="string")return h(n.content)}}catch{}return h(e)}function ct(e,r,n,t){return e.agentType!=="codex"||e.role!==r||q(e.payload)||Math.abs(e.ts-t)>300*1e3?!1:Q(e.payload)===Q(n)}function R(e,r,n,t){for(let o=e.length-1;o>=0;o-=1){const i=e[o];if(i){if(ct(i,r,n,t))return o;if(i.agentType==="codex"&&Math.abs(i.ts-t)>300*1e3)break}}return-1}function v(e,r,n,t,o,i,u,a,f,c,s="agent",l=!1,m){u&&e.push({agentType:"codex",sourceMode:"codex_rollout_import",sourceSessionKey:o,sourceEventKey:w(r,n,t),cursor:U(r,n),role:s,ts:i,payload:u,title:a,modelId:f,workDir:c,terminal:l,repairHint:m})}function x(e,r,n,t,o,i,u,a,f,c,s,l,m){const A=w(r,n,t),y=typeof m?.callId=="string"&&m.callId.trim()?m.callId.trim():null,T=y?Z("sha256").update(`${o}\0${y}`).digest("hex").slice(0,32):null,p=T?`tool:${T}`:void 0,b=T?`native:tool:${T}`:`native:${A}`,g=m?.completed&&T?2:1,S=l!==void 0?"completed":"running";e.push({agentType:"codex",sourceMode:"codex_rollout_import",sourceSessionKey:o,sourceEventKey:A,cursor:U(r,n),role:"agent",ts:i,payload:K({name:u,toolCallId:b,detailRevision:g,status:S}),title:a,modelId:f,workDir:c,...p?{canonicalMessageKey:p,canonicalMutation:m?.completed?"upsert":"append"}:{},localToolDetail:{toolCallId:b,detailRevision:g,name:u,...s!==void 0?{args:s}:{},...l!==void 0?{result:l}:{},status:S}})}function ut(e,r,n,t,o,i,u,a,f){const c=typeof t.type=="string"?t.type:"";if(c){if(c==="message"){const s=J(t);if(!s||R(e,s.role,s.payload,i)>=0)return;v(e,r,n,`${c}:${s.role}`,o,i,s.payload,u,a,f,s.role,!1,s.repairHint);return}if(c==="function_call"){const s=typeof t.name=="string"?t.name:"function_call";x(e,r,n,c,o,i,s,u,a,f,O(t.arguments),void 0,{callId:t.call_id});return}if(c==="function_call_output"){x(e,r,n,c,o,i,"function_call_output",u,a,f,void 0,t.output,{callId:t.call_id,completed:!0});return}if(c==="custom_tool_call"){const s=typeof t.name=="string"?t.name:"custom_tool_call",l=t.input!==void 0?{input:t.input}:void 0;x(e,r,n,c,o,i,s,u,a,f,l,void 0,{callId:t.call_id});return}if(c==="custom_tool_call_output"){const s=typeof t.name=="string"?t.name:"custom_tool_call_output",l=t.output??t.result??t.content;x(e,r,n,c,o,i,s,u,a,f,void 0,l,{callId:t.call_id,completed:!0});return}if(c==="web_search_call"){const s=typeof t.action=="object"&&t.action!==null?t.action:null;x(e,r,n,c,o,i,"web_search",u,a,f,s??t.query);return}}}function at(e,r,n,t,o,i,u,a,f){const c=typeof t.type=="string"?t.type:"";if(c){if(c==="user_message"){const s=L(t);if(!s)return;v(e,r,n,c,o,i,s.payload,u,a,f,"user",!1,s.repairHint);return}if(c==="agent_message"){const s=typeof t.message=="string"?h(t.message):"";if(!s||M(s))return;v(e,r,n,c,o,i,s,u,a,f);return}if(c==="turn_aborted"||c==="error"){const s=typeof t.message=="string"?h(t.message):typeof t.error=="string"?h(t.error):"";if(!s)return;v(e,r,n,c,o,i,s,u,a,f,"agent",!0);return}if(ot(c)){v(e,r,n,c,o,i,it(t),u,a,f,"agent");return}if(c==="exec_command_end"){const s=Array.isArray(t.command)?t.command:t.parsed_cmd??t.command,l=t.exit_code??t.exitCode,m=[typeof t.aggregated_output=="string"?t.aggregated_output:"",l!=null?`
6
+ (exit ${String(l)})`:""].join("");x(e,r,n,c,o,i,"command_execution",u,a,f,{command:s},m);return}if(c==="patch_apply_end"){x(e,r,n,c,o,i,"apply_patch",u,a,f,t.changes,{success:t.success,stdout:t.stdout,stderr:t.stderr});return}if(c==="mcp_tool_call_end"){const s=typeof t.invocation=="object"&&t.invocation!==null?t.invocation:null,l=typeof s?.tool=="string"?s.tool:"mcp_tool_call",m={server:s?.server,...typeof s?.arguments=="object"&&s.arguments!==null?s.arguments:{}};x(e,r,n,c,o,i,l,u,a,f,m,t.result);return}if(c==="dynamic_tool_call_request"){const s=typeof t.tool=="string"?t.tool:"dynamic_tool_call";x(e,r,n,c,o,i,s,u,a,f,t.arguments,void 0,{callId:t.callId??t.call_id});return}if(c==="dynamic_tool_call_response"){const s=typeof t.tool=="string"?t.tool:"dynamic_tool_call";x(e,r,n,c,o,i,s,u,a,f,void 0,t.result??t.output,{callId:t.callId??t.call_id,completed:!0});return}if(c==="web_search_end"){const s=typeof t.action=="object"&&t.action!==null?t.action:null;x(e,r,n,c,o,i,"web_search",u,a,f,s??t.query,t.query);return}if(c==="image_generation_end"){const s=typeof t.saved_path=="string"?t.saved_path.trim():"";if(!s)return;v(e,r,n,c,o,i,D(s),u,a,f);return}c==="view_image_tool_call"&&x(e,r,n,c,o,i,"view_image",u,a,f,t.path??t.image_path??t)}}function E(e=!1){return{sourceSessionKey:"",workDir:"",modelId:null,title:"",skipImport:e}}function V(e){if((typeof e.thread_source=="string"?e.thread_source.trim().toLowerCase():"")==="subagent")return!0;const n=typeof e.source=="object"&&e.source!==null?e.source:null;if(n&&typeof n.subagent=="object"&&n.subagent!==null)return!0;const t=typeof e.parent_thread_id=="string"&&e.parent_thread_id.trim().length>0,o=typeof e.agent_nickname=="string"||typeof e.agent_role=="string"||typeof e.multi_agent_version=="string";return t&&o}function ft(e){const r=j.openSync(e,"r");try{const n=[];let t=0,o="";for(;t<1024*1024;){const f=Buffer.alloc(16384),c=j.readSync(r,f,0,f.length,t);if(c<=0)break;const s=f.subarray(0,c);n.push(s),t+=c;const l=Buffer.concat(n),m=l.indexOf(10);if(m>=0){o=l.subarray(0,m).toString("utf8");break}}!o&&n.length>0&&(o=Buffer.concat(n).toString("utf8"));const i=k(o);if(!i||i.type!=="session_meta")return E();const u=typeof i.payload=="object"&&i.payload!==null?i.payload:null;if(!u)return E();if(V(u))return E(!0);const a=typeof u.id=="string"?u.id:"";return{sourceSessionKey:a,workDir:typeof u.cwd=="string"?u.cwd:"",modelId:X(u),title:Y(a)??"",skipImport:!1}}finally{j.closeSync(r)}return E()}function X(e){return(typeof e.model=="string"?e.model.trim():"")||null}function lt(e,r){if((typeof e.id=="string"?e.id:typeof e.thread_id=="string"?e.thread_id:typeof e.session_id=="string"?e.session_id:"")!==r)return null;const o=(typeof e.thread_name=="string"?e.thread_name:typeof e.title=="string"?e.title:"").trim();return o?o.slice(0,120):null}function Y(e){if(!e)return null;const r=I.join($.homedir(),".codex","session_index.jsonl");if(!j.existsSync(r))return null;let n=null;return F(r,0,t=>{if(!t.trim())return;const o=k(t);if(!o)return;const i=lt(o,e);i&&(n=i)}),n}function ht(){const e=[I.join($.homedir(),".codex","sessions"),I.join($.homedir(),".codex","archived_sessions")],r=[],n=t=>{for(const o of j.readdirSync(t,{withFileTypes:!0})){const i=I.join(t,o.name);o.isDirectory()?n(i):o.isFile()&&o.name.endsWith(".jsonl")&&r.push(i)}};for(const t of e)j.existsSync(t)&&n(t);return[...new Set(r)].sort()}function yt(e,r){const n=[],t=ft(e);let{sourceSessionKey:o,workDir:i,modelId:u,title:a,skipImport:f}=t,c=t.title;if(f)return{nextOffset:j.statSync(e).size,events:[]};let s=!1;const l=F(e,r,(m,A)=>{const y=k(m);if(!y)return;const T=typeof y.type=="string"?y.type:"",p=typeof y.payload=="object"&&y.payload!==null?y.payload:null,b=tt(y.timestamp);if(!(!p||!b)){if(T==="session_meta"){if(V(p)){n.length=0,f=!0;return}o=typeof p.id=="string"?p.id:o,i=typeof p.cwd=="string"?p.cwd:i,u=X(p)??u;const g=Y(o);g&&(c=g,a=g);return}if(!f&&o){if(T==="response_item"){const g=J(p);g?.role==="user"&&g.titleText&&!a&&(a=g.titleText.slice(0,80)),ut(n,e,A,p,o,b,a,u,i);return}if(T==="event_msg"){const g=typeof p.type=="string"?p.type:"";if(rt(g)){let d=!1;for(let _=n.length-1;_>=0;_-=1){const C=n[_];if(C?.agentType==="codex"&&C.role==="agent"&&!q(C.payload)){C.terminal=!0,d=!0,s=!1;break}}if(!d)for(let _=n.length-1;_>=0;_-=1){const C=n[_];if(!(C?.agentType!=="codex"||C.role!=="agent")){C.terminal=!0,d=!0,s=!1;break}}d||(s=!0);return}if(g==="user_message"){const d=L(p);if(d?.titleText&&!a&&(a=d.titleText.slice(0,80)),d){const _=R(n,"user",d.payload,b);_>=0&&n.splice(_,1)}}else if(g==="agent_message"){const d=typeof p.message=="string"?h(p.message):"";if(d&&!M(d)){const _=R(n,"agent",d,b);_>=0&&n.splice(_,1)}}const S=n.length;at(n,e,A,p,o,b,a,u,i),s&&n.length>S&&(n[n.length-1].terminal=!0,s=!1)}}}});for(const m of n)m.titleSource=c&&m.title===c?"agent_native":"first_user_fallback";return{nextOffset:l,events:n}}export{ht as listCodexRolloutFiles,Y as lookupCodexThreadName,yt as parseCodexRolloutChunk};
@@ -36,6 +36,7 @@ export declare class NativeFusionLocalRepository {
36
36
  recordLocalSession?: (input: RecordSessionInput) => unknown;
37
37
  listLocalSessions?: typeof listSessionRecords;
38
38
  writeLocalToolDetail?: (detail: Omit<LocalToolDetail, 'schemaVersion'>) => void;
39
+ readLocalToolDetail?: (sessionId: string, toolCallId: string) => LocalToolDetail | null;
39
40
  });
40
41
  commitEvents(events: readonly ParsedNativeEvent[]): NativeLocalCommitResult[];
41
42
  commitEvent(event: ParsedNativeEvent): NativeLocalCommitResult;
@@ -1,2 +1,2 @@
1
- import d from"node:crypto";import a from"node:fs";import w from"node:path";import{resolvePersonalSyncV1Path as M}from"../personal-sync/paths.js";import{getCanonicalSessionStore as F,getDaemonInstallationId as _,listSessionRecords as k,recordSession as K}from"../session/store.js";import{writeToolDetail as B}from"../session/tool-detail-store.js";const S=1;class C extends Error{code="missing_user_boundary";constructor(e){super(`native source ${e} does not start at a visible user boundary`),this.name="MissingUserBoundaryError"}}class W{options;constructor(e={}){this.options=e}commitEvents(e){return[...e].sort((o,t)=>o.ts-t.ts).map(o=>this.commitEvent(o))}commitEvent(e){O(e);const o=this.installationId(),t=this.readSources(),i=x(e.agentType,e.sourceSessionKey),r=t.sources[i],l=A(e),u=this.ledgerFile(e.agentType,e.sourceEventKey),n=a.existsSync(u)?D(u):null;if(n&&n.eventFingerprint!==l)throw new Error(`native event identity conflict: ${e.sourceEventKey}`);if(!r&&!n&&e.role!=="user")throw new C(e.sourceSessionKey);const g=e.claimSessionId??null,c=r?.sessionId??n?.sessionId??g??H(o,e.agentType,e.sourceSessionKey);if(g&&r&&r.sessionId!==g)throw new Error(`managed claim session conflicts with source binding ${e.sourceSessionKey}`);const f=this.canonicalStore(),p=e.claimCanonicalMessageId??R(o,e.agentType,e.sourceEventKey);let y=f.getManifest(c)?.bodyRevision??0,E=!!n;const m=!!e.claimCanonicalMessageId;if(m){const h=f.getMessageState(c,p);if(!h||h.tombstoned)throw new Error(`managed echo claim target is not durable: ${p}`)}if(!n&&!m){const h={id:p,sessionId:c,role:e.role,ts:e.ts,payload:e.payload},$=f.append(c,h);y=$.bodyRevision,E=$.duplicate,e.localToolDetail&&(this.options.writeLocalToolDetail??B)({sessionId:c,...e.localToolDetail,ts:e.ts,detailRef:{toolIndex:0}})}n||this.recordIndex(e,c);const I=new Date().toISOString();return n||b(u,{schemaVersion:S,daemonInstallationId:o,sessionId:c,agentType:e.agentType,sourceSessionKey:e.sourceSessionKey,sourceEventKey:e.sourceEventKey,eventFingerprint:l,canonicalMessageId:p,canonicalRevision:y,cursor:e.cursor??null,mappedBy:m?"managed_echo_claim":e.sourceMode,eventTs:e.ts,createdAt:I}),t.sources[i]={schemaVersion:S,daemonInstallationId:o,sessionId:c,agentType:e.agentType,sourceSessionKey:e.sourceSessionKey,sourceMode:n?r?.sourceMode??e.sourceMode:e.sourceMode,lastCursor:n?r?.lastCursor??n.cursor:e.cursor??r?.lastCursor??null,bodyRevision:y,createdAt:r?.createdAt??I,updatedAt:I},b(this.sourcesFile(),t),{sessionId:c,messageId:p,bodyRevision:y,duplicate:E,claimed:m}}listSourceBindings(){return Object.values(this.readSources().sources)}observeNativeTitle(e,o,t){const i=t.trim().slice(0,120);if(!i)return!1;const r=this.readSources().sources[x(e,o)];if(!r)return!1;const l=(this.options.listLocalSessions??k)().find(g=>g.sessionId===r.sessionId);if(l?.titleLockedByUser||l?.titleSource==="agent_native"&&l.title===i)return!1;const u=d.createHash("sha256").update(`${e}\0${o}\0${i}`).digest("hex");return(this.options.recordLocalSession??K)({sessionId:r.sessionId,agentType:r.agentType,workDir:l?.workDir??"",agentSessionId:o,title:i,titleSource:"agent_native",titleOriginEventId:`agent-native:${u}`}),!0}recordIndex(e,o){(this.options.recordLocalSession??K)({sessionId:o,agentType:e.agentType,workDir:e.workDir??"",agentSessionId:e.sourceSessionKey,modelId:e.modelId??null,status:e.terminal?"completed":"active",lastActivityAt:new Date(e.ts).toISOString(),lastMessagePreview:e.role==="user"?T(e.payload):void 0,title:e.title?.trim()||(e.role==="user"?T(e.payload)??"":void 0),titleSource:e.title?.trim()?e.titleSource??"first_user_fallback":"first_user_fallback",titleOriginEventId:e.sourceEventKey})}readSources(){const e=this.sourcesFile();if(!a.existsSync(e))return{schemaVersion:S,daemonInstallationId:this.installationId(),sources:{}};const o=D(e);if(o.schemaVersion!==S||o.daemonInstallationId!==this.installationId()||!o.sources)throw new Error("invalid native source binding store");return o}installationId(){return this.options.daemonInstallationId??_()}canonicalStore(){return this.options.canonicalStore??F()}rootDir(){return this.options.rootDir??M("native-fusion")}sourcesFile(){return w.join(this.rootDir(),"sources.json")}ledgerFile(e,o){const t=d.createHash("sha256").update(`${e}\0${o}`).digest("hex");return w.join(this.rootDir(),"ledger",`${t}.json`)}}function O(s){if(!s.agentType||!s.sourceSessionKey||!s.sourceEventKey||!s.payload)throw new Error("invalid native event");if(!Number.isFinite(s.ts))throw new Error("invalid native event timestamp")}function x(s,e){return d.createHash("sha256").update(`${s}\0${e}`).digest("hex")}function H(s,e,o){return`native-session-${d.createHash("sha256").update(`${s}\0${e}\0${o}`).digest("hex").slice(0,32)}`}function R(s,e,o){return`native-${d.createHash("sha256").update(`${s}\0${e}\0${o}`).digest("hex").slice(0,32)}`}function A(s){return d.createHash("sha256").update(JSON.stringify({agentType:s.agentType,sourceSessionKey:s.sourceSessionKey,sourceEventKey:s.sourceEventKey,role:s.role,ts:s.ts,payload:s.payload,claimCanonicalMessageId:s.claimCanonicalMessageId??null,claimSessionId:s.claimSessionId??null})).digest("hex")}function T(s){const e=s.replace(/\s+/g," ").trim();return e?e.length>120?`${e.slice(0,120)}...`:e:null}function b(s,e){const o=w.dirname(s);a.mkdirSync(o,{recursive:!0,mode:448});const t=`${s}.tmp-${process.pid}-${d.randomBytes(6).toString("hex")}`;let i;try{i=a.openSync(t,"wx",384),a.writeFileSync(i,`${JSON.stringify(e,null,2)}
2
- `,"utf8"),a.fsyncSync(i),a.closeSync(i),i=void 0,a.renameSync(t,s)}finally{i!==void 0&&a.closeSync(i);try{a.unlinkSync(t)}catch{}}}function D(s){return JSON.parse(a.readFileSync(s,"utf8"))}export{C as MissingUserBoundaryError,W as NativeFusionLocalRepository};
1
+ import d from"node:crypto";import c from"node:fs";import w from"node:path";import{resolvePersonalSyncV1Path as N}from"../personal-sync/paths.js";import{getCanonicalSessionStore as O,getDaemonInstallationId as k,listSessionRecords as B,recordSession as T}from"../session/store.js";import{readToolDetail as H,writeToolDetail as J}from"../session/tool-detail-store.js";const h=1;class L extends Error{code="missing_user_boundary";constructor(e){super(`native source ${e} does not start at a visible user boundary`),this.name="MissingUserBoundaryError"}}class Y{options;constructor(e={}){this.options=e}commitEvents(e){return[...e].sort((t,o)=>t.ts-o.ts).map(t=>this.commitEvent(t))}commitEvent(e){R(e);const t=this.installationId(),o=this.readSources(),i=K(e.agentType,e.sourceSessionKey),r=o.sources[i],l=j(e),g=this.ledgerFile(e.agentType,e.sourceEventKey),n=c.existsSync(g)?b(g):null;if(n&&n.eventFingerprint!==l)throw new Error(`native event identity conflict: ${e.sourceEventKey}`);if(!r&&!n&&e.role!=="user")throw new L(e.sourceSessionKey);const p=e.claimSessionId??null,a=r?.sessionId??n?.sessionId??p??A(t,e.agentType,e.sourceSessionKey);if(p&&r&&r.sessionId!==p)throw new Error(`managed claim session conflicts with source binding ${e.sourceSessionKey}`);const m=this.canonicalStore(),u=e.claimCanonicalMessageId??V(t,e.agentType,e.canonicalMessageKey??e.sourceEventKey);let f=m.getManifest(a)?.bodyRevision??0,$=!!n;const S=!!e.claimCanonicalMessageId;if(S){const y=m.getMessageState(a,u);if(!y||y.tombstoned)throw new Error(`managed echo claim target is not durable: ${u}`)}if(!n&&!S){const y=e.canonicalMutation==="upsert"?m.getMessageState(a,u):null,E={id:u,sessionId:a,role:e.role,ts:y?.message?.ts??e.ts,payload:U(y?.message?.payload,e.payload)},M=e.canonicalMutation==="upsert"?m.upsert(a,E):m.append(a,E);if(f=M.bodyRevision,$=M.duplicate,e.localToolDetail){const _=this.options.writeLocalToolDetail??J,C=this.options.readLocalToolDetail??H,F=P(C(a,e.localToolDetail.toolCallId),e.localToolDetail);_({sessionId:a,...F,ts:e.ts,detailRef:{toolIndex:0}})}}n||this.recordIndex(e,a);const I=new Date().toISOString();return n||x(g,{schemaVersion:h,daemonInstallationId:t,sessionId:a,agentType:e.agentType,sourceSessionKey:e.sourceSessionKey,sourceEventKey:e.sourceEventKey,eventFingerprint:l,canonicalMessageId:u,canonicalRevision:f,cursor:e.cursor??null,mappedBy:S?"managed_echo_claim":e.sourceMode,eventTs:e.ts,createdAt:I}),o.sources[i]={schemaVersion:h,daemonInstallationId:t,sessionId:a,agentType:e.agentType,sourceSessionKey:e.sourceSessionKey,sourceMode:n?r?.sourceMode??e.sourceMode:e.sourceMode,lastCursor:n?r?.lastCursor??n.cursor:e.cursor??r?.lastCursor??null,bodyRevision:f,createdAt:r?.createdAt??I,updatedAt:I},x(this.sourcesFile(),o),{sessionId:a,messageId:u,bodyRevision:f,duplicate:$,claimed:S}}listSourceBindings(){return Object.values(this.readSources().sources)}observeNativeTitle(e,t,o){const i=o.trim().slice(0,120);if(!i)return!1;const r=this.readSources().sources[K(e,t)];if(!r)return!1;const l=(this.options.listLocalSessions??B)().find(p=>p.sessionId===r.sessionId);if(l?.titleLockedByUser||l?.titleSource==="agent_native"&&l.title===i)return!1;const g=d.createHash("sha256").update(`${e}\0${t}\0${i}`).digest("hex");return(this.options.recordLocalSession??T)({sessionId:r.sessionId,agentType:r.agentType,workDir:l?.workDir??"",agentSessionId:t,title:i,titleSource:"agent_native",titleOriginEventId:`agent-native:${g}`}),!0}recordIndex(e,t){(this.options.recordLocalSession??T)({sessionId:t,agentType:e.agentType,workDir:e.workDir??"",agentSessionId:e.sourceSessionKey,modelId:e.modelId??null,status:e.terminal?"completed":"active",lastActivityAt:new Date(e.ts).toISOString(),lastMessagePreview:e.role==="user"?D(e.payload):void 0,title:e.title?.trim()||(e.role==="user"?D(e.payload)??"":void 0),titleSource:e.title?.trim()?e.titleSource??"first_user_fallback":"first_user_fallback",titleOriginEventId:e.sourceEventKey})}readSources(){const e=this.sourcesFile();if(!c.existsSync(e))return{schemaVersion:h,daemonInstallationId:this.installationId(),sources:{}};const t=b(e);if(t.schemaVersion!==h||t.daemonInstallationId!==this.installationId()||!t.sources)throw new Error("invalid native source binding store");return t}installationId(){return this.options.daemonInstallationId??k()}canonicalStore(){return this.options.canonicalStore??O()}rootDir(){return this.options.rootDir??N("native-fusion")}sourcesFile(){return w.join(this.rootDir(),"sources.json")}ledgerFile(e,t){const o=d.createHash("sha256").update(`${e}\0${t}`).digest("hex");return w.join(this.rootDir(),"ledger",`${o}.json`)}}function R(s){if(!s.agentType||!s.sourceSessionKey||!s.sourceEventKey||!s.payload)throw new Error("invalid native event");if(!Number.isFinite(s.ts))throw new Error("invalid native event timestamp")}function K(s,e){return d.createHash("sha256").update(`${s}\0${e}`).digest("hex")}function A(s,e,t){return`native-session-${d.createHash("sha256").update(`${s}\0${e}\0${t}`).digest("hex").slice(0,32)}`}function V(s,e,t){return`native-${d.createHash("sha256").update(`${s}\0${e}\0${t}`).digest("hex").slice(0,32)}`}function j(s){return d.createHash("sha256").update(JSON.stringify({agentType:s.agentType,sourceSessionKey:s.sourceSessionKey,sourceEventKey:s.sourceEventKey,role:s.role,ts:s.ts,payload:s.payload,claimCanonicalMessageId:s.claimCanonicalMessageId??null,claimSessionId:s.claimSessionId??null,canonicalMessageKey:s.canonicalMessageKey??null,canonicalMutation:s.canonicalMutation??"append"})).digest("hex")}function U(s,e){if(!s)return e;try{const t=JSON.parse(s),o=JSON.parse(e);if(t.type!=="tool"||o.type!=="tool"||t.toolCallId!==o.toolCallId)return e;const i=typeof o.name=="string"?o.name:"",r=/(?:_output|_result)$/.test(i);return JSON.stringify({...t,...o,...r&&typeof t.name=="string"?{name:t.name}:{}})}catch{return e}}function P(s,e){if(!s||s.toolCallId!==e.toolCallId)return e;const t=/(?:_output|_result)$/.test(e.name);return{...e,name:t?s.name:e.name,...e.args===void 0&&s.args!==void 0?{args:s.args}:{},...e.result===void 0&&s.result!==void 0?{result:s.result}:{}}}function D(s){const e=s.replace(/\s+/g," ").trim();return e?e.length>120?`${e.slice(0,120)}...`:e:null}function x(s,e){const t=w.dirname(s);c.mkdirSync(t,{recursive:!0,mode:448});const o=`${s}.tmp-${process.pid}-${d.randomBytes(6).toString("hex")}`;let i;try{i=c.openSync(o,"wx",384),c.writeFileSync(i,`${JSON.stringify(e,null,2)}
2
+ `,"utf8"),c.fsyncSync(i),c.closeSync(i),i=void 0,c.renameSync(o,s)}finally{i!==void 0&&c.closeSync(i);try{c.unlinkSync(o)}catch{}}}function b(s){return JSON.parse(c.readFileSync(s,"utf8"))}export{L as MissingUserBoundaryError,Y as NativeFusionLocalRepository};
@@ -24,6 +24,8 @@ export type ParsedNativeEvent = NativeSessionEventPayload & {
24
24
  repairHint?: NativeRepairHint;
25
25
  sourceSessionCreatedAtMs?: number;
26
26
  claimSessionId?: string | null;
27
+ canonicalMessageKey?: string;
28
+ canonicalMutation?: 'append' | 'upsert';
27
29
  titleSource?: Extract<SessionTitleSource, 'agent_native' | 'first_user_fallback'>;
28
30
  localToolDetail?: {
29
31
  toolCallId: string;
@@ -1 +1 @@
1
- import{acknowledgeSessionIndexUpdate as d,listPendingSessionIndexUpdates as r}from"./store.js";const i=new WeakMap,t=new WeakSet;function a(s){const e=s,n=i.get(e);if(n)return t.add(e),n;const o=c(s).finally(()=>{i.get(e)===o&&i.delete(e),t.delete(e)&&f(s)});return i.set(e,o),o}async function c(s){const e=r();for(const n of e)await s.sendBufferedEvent({type:"event",event:"session.index.updated",id:`session-index-${n.daemonInstallationId}-${n.session.id}-${n.session.indexRevision}`,payload:n},6e4),d(n.session.id,n.session.indexRevision)}function f(s){a(s).catch(e=>{console.error("[session-index] sync failed; dirty revisions retained for retry",e)})}export{a as publishPendingSessionIndexes,f as requestSessionIndexPublish};
1
+ import{acknowledgeSessionIndexUpdate as r,listPendingSessionIndexUpdates as a}from"./store.js";const o=new WeakMap,t=new WeakSet;function c(s){const e=s,i=o.get(e);if(i)return t.add(e),i;const n=f(s).finally(()=>{o.get(e)===n&&o.delete(e),t.delete(e)&&u(s)});return o.set(e,n),n}async function f(s){const e=a(),i=[];for(const n of e)try{await s.sendBufferedEvent({type:"event",event:"session.index.updated",id:`session-index-${n.daemonInstallationId}-${n.session.id}-${n.session.indexRevision}`,payload:n},6e4),r(n.session.id,n.session.indexRevision)}catch(d){i.push(d)}if(i.length>0)throw new AggregateError(i,"one or more session indexes failed")}function u(s){c(s).catch(e=>{console.error("[session-index] sync failed; dirty revisions retained for retry",e)})}export{c as publishPendingSessionIndexes,u as requestSessionIndexPublish};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shennian",
3
- "version": "0.3.43",
3
+ "version": "0.3.45",
4
4
  "description": "Shennian — AI Agent Control Plane CLI",
5
5
  "type": "module",
6
6
  "bin": {