@linzumi/cli 1.0.231 → 1.0.233

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.
@@ -1,14 +1,14 @@
1
1
  import { createRequire as __linzumiBundleCreateRequire } from 'node:module';
2
2
  const require = __linzumiBundleCreateRequire(import.meta.url);
3
- import{randomUUID as ce}from"node:crypto";import{mkdir as me,realpath as pe,writeFile as _e}from"node:fs/promises";import{homedir as J}from"node:os";import{join as L}from"node:path";function $(e){return e===void 0?{BS_PRIVATE_NESTED_SOME_NONE:0}:e!==null&&e.BS_PRIVATE_NESTED_SOME_NONE!==void 0?{BS_PRIVATE_NESTED_SOME_NONE:e.BS_PRIVATE_NESTED_SOME_NONE+1|0}:e}function _(e){if(e===null||e.BS_PRIVATE_NESTED_SOME_NONE===void 0)return e;let t=e.BS_PRIVATE_NESTED_SOME_NONE;if(t!==0)return{BS_PRIVATE_NESTED_SOME_NONE:t-1|0}}function h(e,t){let r=e.length,i=new Array(r),n=0;for(let s=0;s<r;++s){let o=e[s],m=t(o);m!==void 0&&(i[n]=_(m),n=n+1|0)}return i.length=n,i}function g(e,t,r){return e!==void 0?r(_(e)):t}function k(e,t){if(e!==void 0)return $(t(_(e)))}function v(e,t){if(e!==void 0)return t(_(e))}function E(e,t){return e!==void 0?_(e):t}var R=["codex","claude-code","pi","opencode"];function M(e){return e}function D(e,t){let r=e[t];if(typeof r=="object"&&r!==null&&!Array.isArray(r))return r}function d(e,t){let r=e[t];if(typeof r=="string")return r}function T(e,t){let r=e[t];if(Array.isArray(r))return r}function I(e){return h(e,t=>{if(typeof t!="object"||t===null||Array.isArray(t))return;if(d(t,"type")==="text")return d(t,"text")}).join(`
4
- `)}function j(e,t,r,i){return e+":"+t+":"+r+":"+i}function N(e,t){let r=t.split(":"),i=r[0],n=r[1],s=r[2];if(i===void 0||n===void 0||s===void 0||!(i===e&&n!==""&&s!==""&&r.length>=4))return;let o=r.slice(3,r.length).join(":");if(o!=="")return{keySessionId:n,keyTurnId:s,keyItemId:o}}function W(e,t){return{threadId:e,threadTitle:void 0,nodes:t,hasMore:!1,cursor:void 0,budget:void 0,session:void 0}}var V="codex";function ne(e,t,r){return j(V,e,t,r)}function ie(e){if(e===void 0)return"system_notice";switch(e){case"agentMessage":return"assistant_message";case"commandExecution":return"command_execution";case"fileChange":return"file_change";case"collabAgentToolCall":case"dynamicToolCall":case"mcpToolCall":return"tool_call";case"reasoning":return"reasoning";case"plan":case"subAgentActivity":return"agent_status";case"terminalInput":return"terminal_input";case"userMessage":return"user_message";default:return"system_notice"}}function B(e){return h(e,t=>{if(typeof t=="string")return t})}function se(e){let t=d(e,"type");if(t===void 0)return"";switch(t){case"collabAgentToolCall":return E(d(e,"prompt"),"");case"commandExecution":return E(d(e,"aggregatedOutput"),"");case"dynamicToolCall":return g(T(e,"contentItems"),"",I);case"fileChange":return g(T(e,"changes"),[],n=>h(n,s=>{if(typeof s=="object"&&s!==null&&!Array.isArray(s))return d(s,"path")})).join(`
5
- `);case"mcpToolCall":return g(v(D(e,"result"),n=>T(n,"content")),"",I);case"reasoning":let r=g(T(e,"summary"),[],B),i=g(T(e,"content"),[],B);return r.concat(i).filter(n=>n!=="").join(`
3
+ import{randomUUID as fe}from"node:crypto";import{mkdir as ce,realpath as me,writeFile as pe}from"node:fs/promises";import{homedir as G}from"node:os";import{join as U}from"node:path";function F(e){return e===void 0?{BS_PRIVATE_NESTED_SOME_NONE:0}:e!==null&&e.BS_PRIVATE_NESTED_SOME_NONE!==void 0?{BS_PRIVATE_NESTED_SOME_NONE:e.BS_PRIVATE_NESTED_SOME_NONE+1|0}:e}function _(e){if(e===null||e.BS_PRIVATE_NESTED_SOME_NONE===void 0)return e;let t=e.BS_PRIVATE_NESTED_SOME_NONE;if(t!==0)return{BS_PRIVATE_NESTED_SOME_NONE:t-1|0}}function h(e,t){let r=e.length,i=new Array(r),n=0;for(let o=0;o<r;++o){let s=e[o],u=t(s);u!==void 0&&(i[n]=_(u),n=n+1|0)}return i.length=n,i}function g(e,t,r){return e!==void 0?r(_(e)):t}function E(e,t){if(e!==void 0)return F(t(_(e)))}function S(e,t){if(e!==void 0)return t(_(e))}function O(e,t){return e!==void 0?_(e):t}var N=["codex","claude-code","pi","opencode"];function w(e){return e}function x(e,t){let r=e[t];if(typeof r=="object"&&r!==null&&!Array.isArray(r))return r}function m(e,t){let r=e[t];if(typeof r=="string")return r}function T(e,t){let r=e[t];if(Array.isArray(r))return r}function A(e){return h(e,t=>{if(typeof t!="object"||t===null||Array.isArray(t))return;if(m(t,"type")==="text")return m(t,"text")}).join(`
4
+ `)}function C(e,t,r,i){return e+":"+t+":"+r+":"+i}function b(e,t){let r=t.split(":"),i=r[0],n=r[1],o=r[2];if(i===void 0||n===void 0||o===void 0||!(i===e&&n!==""&&o!==""&&r.length>=4))return;let s=r.slice(3,r.length).join(":");if(s!=="")return{keySessionId:n,keyTurnId:o,keyItemId:s}}function H(e,t){return{threadId:e,threadTitle:void 0,nodes:t,hasMore:!1,cursor:void 0,budget:void 0,session:void 0}}var D="codex";function te(e,t,r){return C(D,e,t,r)}function re(e){if(e===void 0)return"system_notice";switch(e){case"agentMessage":return"assistant_message";case"commandExecution":return"command_execution";case"fileChange":return"file_change";case"collabAgentToolCall":case"dynamicToolCall":case"mcpToolCall":return"tool_call";case"reasoning":return"reasoning";case"plan":case"subAgentActivity":return"agent_status";case"terminalInput":return"terminal_input";case"userMessage":return"user_message";default:return"system_notice"}}function j(e){return h(e,t=>{if(typeof t=="string")return t})}function ne(e){let t=m(e,"type");if(t===void 0)return"";switch(t){case"collabAgentToolCall":return O(m(e,"prompt"),"");case"commandExecution":return O(m(e,"aggregatedOutput"),"");case"dynamicToolCall":return g(T(e,"contentItems"),"",A);case"fileChange":return g(T(e,"changes"),[],n=>h(n,o=>{if(typeof o=="object"&&o!==null&&!Array.isArray(o))return m(o,"path")})).join(`
5
+ `);case"mcpToolCall":return g(S(x(e,"result"),n=>T(n,"content")),"",A);case"reasoning":let r=g(T(e,"summary"),[],j),i=g(T(e,"content"),[],j);return r.concat(i).filter(n=>n!=="").join(`
6
6
 
7
- `);case"subAgentActivity":return E(d(e,"agentPath"),"");case"agentMessage":case"plan":case"terminalInput":return E(d(e,"text"),"");case"userMessage":return g(T(e,"content"),"",I);default:return""}}function oe(e){return new Date(e).toISOString()}function K(e,t){let r=[];return t.turns.forEach(i=>{i.items.forEach(n=>{let s=n.item,o;o=typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{};let m=E(d(o,"id"),"");r.push({kind:ie(d(o,"type")),seq:r.length+1|0,at:k(n.completedAtMs,oe),harness:V,body:se(o),structured:n.item,actor:void 0,attachments:[],sourceSeq:void 0,streamKey:ne(t.harnessSessionId,i.turnId,m)})})}),W(e,r)}var ue="claude-code";function le(e){return"rehydrated-"+e.toString()}var ae="rehydrated-marker";function de(e,t){switch(e){case"agent_status":return"[status] "+t;case"approval_request":return"[approval] "+t;case"command_execution":return`[command]
7
+ `);case"subAgentActivity":return O(m(e,"agentPath"),"");case"agentMessage":case"plan":case"terminalInput":return O(m(e,"text"),"");case"userMessage":return g(T(e,"content"),"",A);default:return""}}function ie(e){return new Date(e).toISOString()}function q(e,t){let r=[];return t.turns.forEach(i=>{i.items.forEach(n=>{let o=n.item,s;s=typeof o=="object"&&o!==null&&!Array.isArray(o)?o:{};let u=O(m(s,"id"),"");r.push({kind:re(m(s,"type")),seq:r.length+1|0,at:E(n.completedAtMs,ie),harness:D,body:ne(s),structured:n.item,actor:void 0,attachments:[],sourceSeq:void 0,streamKey:te(t.harnessSessionId,i.turnId,u)})})}),H(e,r)}var se="claude-code";function oe(e){return"rehydrated-"+e.toString()}var ue="rehydrated-marker";function le(e,t){switch(e){case"agent_status":return"[status] "+t;case"approval_request":return"[approval] "+t;case"command_execution":return`[command]
8
8
  `+t;case"error":return"[error] "+t;case"file_change":return`[file change]
9
9
  `+t;case"system_notice":return"[notice] "+t;case"terminal_input":return`[terminal input]
10
10
  `+t;case"tool_call":return`[tool call]
11
11
  `+t;case"tool_result":return`[tool result]
12
- `+t;default:return"["+e+"] "+t}}function U(e,t,r,i){let n={};n.type="text",n.text=i;let s={};s.role=e,s.content=[n];let o={};return o.type=e,o.session_id=t,o.uuid=r,o.message=s,o}function fe(e,t,r,i,n){return"[linzumi cross-harness resume] This session continues linzumi thread "+r+", "+("imported from the "+e+" session "+t+". ")+(i.toString()+" activity records follow verbatim; ")+(n.toString()+" reasoning records were redacted ")+"(provider-private reasoning is never forged across harnesses)."}function z(e,t){let r={contents:void 0},i=a=>{if(r.contents===void 0){r.contents=a;return}};e===""?i("the caller-bound target session identity must be non-empty"):e.includes(":")&&i("the caller-bound target session identity must be colon-free"),r.contents===void 0&&t.nodes.length===0&&i("an empty page rehydrates nothing - the source session must carry content");let n={contents:void 0},s={contents:void 0};t.nodes.forEach(a=>{if(r.contents===void 0){let l=s.contents;l!==void 0&&a.seq<=l?i("page nodes must ascend by seq"):s.contents=a.seq}if(r.contents===void 0){let l=h(R.map(M),f=>k(v(a.streamKey,c=>N(f,c)),c=>[f,c.keySessionId]))[0];if(l!==void 0){let f=l[1],c=l[0];if(c===ue)i("the page was minted by the claude harness - same-harness resume rides the native session store, never rehydration");else{let b=n.contents;b!==void 0&&(b[0]!==c||b[1]!==f)?i("page mixes two harness session identities"):n.contents=[c,f]}}else i("node carries no parseable minted stream_key identity of a catalog harness")}if(r.contents!==void 0)return;let u=a.structured;if(!(typeof u=="object"&&u!==null&&!Array.isArray(u)))return i("node carries no verbatim native passthrough")});let o=r.contents,m=n.contents;if(o!==void 0)return{TAG:"Error",_0:o};if(m===void 0)return{TAG:"Error",_0:"page carries no source harness identity"};let A=m[1];if(A===e)return{TAG:"Error",_0:"the caller-bound target session identity must be distinct from the source session identity"};let O=m[0],y=[],S=[],p={contents:0};t.nodes.forEach(a=>{let u=a.kind;if(u==="reasoning"){p.contents=p.contents+1|0;return}let l;switch(u){case"assistant_message":l=["assistant",a.body];break;case"user_message":l=["user",a.body];break;default:l=["assistant",de(u,a.body)]}let f=l[0],c=le(a.seq);y.push({sourceSeq:a.seq,sourceKind:u,uuid:c,role:f}),S.push(U(f,e,c,l[1]))});let w=[U("user",e,ae,fe(O,A,t.threadId,S.length,p.contents))].concat(S);return{TAG:"Ok",_0:{session:{harnessSessionId:e,messages:w},report:{sourceHarness:O,sourceSessionId:A,sessionMessageCount:w.length,redactedReasoningCount:p.contents,emissions:y}}}}function he(e,t){if(e.TAG!=="Ok")throw new Error(`${t}: ${JSON.stringify(e._0)}`);return e._0}function ge(e,t=J()){let r=e.replace(/[^a-zA-Z0-9]/g,"-");return L(t,".claude","projects",r)}async function $e({activity:e,codexThreadId:t,kandanThreadId:r,targetSessionId:i=ce(),cwd:n,home:s=J()}){try{let o=(e?.turns??[]).filter(u=>u.items.length>0);if(o.reduce((u,l)=>u+l.items.length,0)===0)return{ok:!1,failure:"no recorded harness activity to carry over (the failover journal is empty)"};let A=K(r,{harnessSessionId:t,turns:o}),O=he(z(i,A),"claude rehydration refused the exported page"),y=n;try{y=await pe(n)}catch{return{ok:!1,failure:`the thread's working directory is not resolvable: ${n}`}}let S=ge(y,s);await me(S,{recursive:!0});let p=L(S,`${i}.jsonl`),G=null,w=Date.now(),a=O.session.messages.map((u,l)=>{let f={parentUuid:G,isSidechain:!1,userType:"external",cwd:y,sessionId:i,version:"0.0.0-linzumi-cross-harness-failover",type:u.type,message:u.message,uuid:u.uuid,timestamp:new Date(w+l).toISOString()};return G=u.uuid,f});return await _e(p,a.map(u=>JSON.stringify(u)).join(`
12
+ `+t;default:return"["+e+"] "+t}}function W(e,t,r,i){let n={};n.type="text",n.text=i;let o={};o.role=e,o.content=[n];let s={};return s.type=e,s.session_id=t,s.uuid=r,s.message=o,s}function ae(e,t,r,i,n){return"[linzumi cross-harness resume] This session continues linzumi thread "+r+", imported from the "+e+" session "+t+". "+i.toString()+" activity records follow verbatim; "+n.toString()+" reasoning records were redacted (provider-private reasoning is never forged across harnesses)."}function de(e,t,r,i){return"[linzumi session rebuild] This Claude Code session continues Linzumi thread "+e+". Its local session store was missing ("+t+"), so the durable server transcript was restored under the persisted session identity. "+r.toString()+" activity records follow; "+i.toString()+" reasoning records were redacted (provider-private reasoning is never forged)."}function B(e,t,r,i,n){let o=[],s=[],u={contents:0};n.nodes.forEach(d=>{let p=d.kind;if(p==="reasoning"){u.contents=u.contents+1|0;return}let c;switch(p){case"assistant_message":c=["assistant",d.body];break;case"user_message":c=["user",d.body];break;default:c=["assistant",le(p,d.body)]}let y=c[0],I=oe(d.seq);o.push({sourceSeq:d.seq,sourceKind:p,uuid:I,role:y}),s.push(W(y,e,I,c[1]))});let f;f=typeof i!="object"?ae(t,r,n.threadId,s.length,u.contents):de(n.threadId,i._0,s.length,u.contents);let a=[W("user",e,ue,f)].concat(s);return{session:{harnessSessionId:e,messages:a},report:{sourceHarness:t,sourceSessionId:r,sessionMessageCount:a.length,redactedReasoningCount:u.contents,emissions:o}}}function K(e,t,r){let i={contents:void 0},n=f=>{if(i.contents===void 0){i.contents=f;return}},o=r.nodes.length;e===""?n("the persisted target session identity must be non-empty"):e.includes(":")?n("the persisted target session identity must be colon-free"):o!==0||n("an empty server transcript rehydrates nothing");let s={contents:void 0};r.nodes.forEach(f=>{let l=i.contents,a=s.contents;if(l===void 0){if(a!==void 0&&f.seq<=a)return n("server transcript nodes must ascend by seq");s.contents=f.seq;return}});let u=i.contents;return u!==void 0?{TAG:"Error",_0:u}:{TAG:"Ok",_0:B(e,"linzumi-server",r.threadId,{TAG:"ServerTranscript",_0:t},r)}}function V(e,t){let r={contents:void 0},i=l=>{if(r.contents===void 0){r.contents=l;return}};e===""?i("the caller-bound target session identity must be non-empty"):e.includes(":")&&i("the caller-bound target session identity must be colon-free"),r.contents===void 0&&t.nodes.length===0&&i("an empty page rehydrates nothing - the source session must carry content");let n={contents:void 0},o={contents:void 0};t.nodes.forEach(l=>{if(r.contents===void 0){let d=o.contents;d!==void 0&&l.seq<=d?i("page nodes must ascend by seq"):o.contents=l.seq}if(r.contents===void 0){let d=h(N.map(w),p=>E(S(l.streamKey,c=>b(p,c)),c=>[p,c.keySessionId]))[0];if(d!==void 0){let p=d[1],c=d[0];if(c===se)i("the page was minted by the claude harness - same-harness resume rides the native session store, never rehydration");else{let y=n.contents;y!==void 0&&(y[0]!==c||y[1]!==p)?i("page mixes two harness session identities"):n.contents=[c,p]}}else i("node carries no parseable minted stream_key identity of a catalog harness")}if(r.contents!==void 0)return;let a=l.structured;if(!(typeof a=="object"&&a!==null&&!Array.isArray(a)))return i("node carries no verbatim native passthrough")});let s=r.contents,u=n.contents;if(s!==void 0)return{TAG:"Error",_0:s};if(u===void 0)return{TAG:"Error",_0:"page carries no source harness identity"};let f=u[1];return f===e?{TAG:"Error",_0:"the caller-bound target session identity must be distinct from the source session identity"}:{TAG:"Ok",_0:B(e,u[0],f,"CrossHarness",t)}}function _e(e,t=G()){let r=e.replace(/[^a-zA-Z0-9]/g,"-");return U(t,".claude","projects",r)}async function z({rehydrated:e,targetSessionId:t,cwd:r,home:i}){let n;try{n=await me(r)}catch{return{ok:!1,failure:`the thread's working directory is not resolvable: ${r}`}}let o=_e(n,i);await ce(o,{recursive:!0});let s=U(o,`${t}.jsonl`),u=Date.now(),f=e.session.messages.map((l,a,d)=>({parentUuid:a===0?null:d[a-1]?.uuid??null,isSidechain:!1,userType:"external",cwd:n,sessionId:t,version:"0.0.0-linzumi-cross-harness-failover",type:l.type,message:l.message,uuid:l.uuid,timestamp:new Date(u+a).toISOString()}));return await pe(s,f.map(l=>JSON.stringify(l)).join(`
13
13
  `)+`
14
- `),{ok:!0,targetSessionId:i,sessionFile:p,transpiledItemCount:O.report.emissions.length,redactedReasoningCount:O.report.redactedReasoningCount}}catch(o){return{ok:!1,failure:o instanceof Error?o.message:String(o)}}}export{ge as claudeSessionStoreDir,$e as transpileAndSeedClaudeSession};
14
+ `),{ok:!0,targetSessionId:t,sessionFile:s,transpiledItemCount:e.report.emissions.length,redactedReasoningCount:e.report.redactedReasoningCount}}function he({transcript:e,kandanThreadId:t}){return{threadId:t,threadTitle:e.threadTitle,nodes:e.nodes.map(r=>({kind:r.kind,seq:r.seq,at:r.at,harness:r.engine,body:r.body,structured:r.structured,actor:r.actor,attachments:r.attachments,sourceSeq:r.sourceSeq,streamKey:r.streamKey})),hasMore:!1,cursor:void 0,budget:e.budget,session:void 0}}async function Ne({transcript:e,kandanThreadId:t,targetSessionId:r,cwd:i,resumeFailure:n="local Claude Code session store entry was missing",home:o=G()}){try{if(r===""||t===""||!Array.isArray(e?.nodes)||e.nodes.length===0)return{ok:!1,failure:"canonical Claude rehydration requires non-empty thread/session identities and transcript nodes"};let s=he({transcript:e,kandanThreadId:t}),u=K(r,n,s);return u.TAG!=="Ok"?{ok:!1,failure:`Claude rehydration refused the canonical server transcript: ${JSON.stringify(u._0)}`}:await z({rehydrated:u._0,targetSessionId:r,cwd:i,home:o})}catch(s){return{ok:!1,failure:s instanceof Error?s.message:String(s)}}}async function $e({activity:e,codexThreadId:t,kandanThreadId:r,targetSessionId:i=fe(),cwd:n,home:o=G()}){try{let s=(e?.turns??[]).filter(a=>a.items.length>0);if(s.reduce((a,d)=>a+d.items.length,0)===0)return{ok:!1,failure:"no recorded harness activity to carry over (the failover journal is empty)"};let f=q(r,{harnessSessionId:t,turns:s}),l=V(i,f);return l.TAG!=="Ok"?{ok:!1,failure:`claude rehydration refused the exported page: ${JSON.stringify(l._0)}`}:await z({rehydrated:l._0,targetSessionId:i,cwd:n,home:o})}catch(s){return{ok:!1,failure:s instanceof Error?s.message:String(s)}}}export{_e as claudeSessionStoreDir,Ne as seedCanonicalTranscriptIntoClaudeSession,$e as transpileAndSeedClaudeSession};