@vibeapi/api-helper 0.0.127 → 0.0.128
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.
|
@@ -29,6 +29,13 @@ export declare function currentCodexProvider(): string;
|
|
|
29
29
|
export declare function setCodexProcessCheckForTests(fake: () => number[]): void;
|
|
30
30
|
/** PIDs of this user's running Codex processes (CLI, desktop app, background app-server) on this CODEX_HOME; they would overwrite the edits. */
|
|
31
31
|
export declare function runningCodexPids(): number[];
|
|
32
|
+
/**
|
|
33
|
+
* Where Codex keeps `state_*.sqlite`: `sqlite_home` in config.toml, else the
|
|
34
|
+
* `CODEX_SQLITE_HOME` environment variable (relative to the current directory),
|
|
35
|
+
* else CODEX_HOME (codex-rs/core/src/config/mod.rs). Codex++ sets the variable
|
|
36
|
+
* for its extra instances.
|
|
37
|
+
*/
|
|
38
|
+
export declare function codexSqliteHome(): string;
|
|
32
39
|
/** `dbSkipped` when Codex has no state DB yet: nothing to update, not a problem to report. */
|
|
33
40
|
export declare const NO_STATE_DB = "no state DB";
|
|
34
41
|
/** Move every local session under `target`. `dryRun` only counts. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawnSync as e}from"child_process";import{closeSync as t,copyFileSync as r,createReadStream as o,createWriteStream as n,existsSync as s,mkdirSync as i,openSync as
|
|
1
|
+
import{spawnSync as e}from"child_process";import{closeSync as t,copyFileSync as r,createReadStream as o,createWriteStream as n,existsSync as s,mkdirSync as i,openSync as c,readFileSync as a,readSync as f,readdirSync as l,realpathSync as u,renameSync as p,statSync as d,utimesSync as m,writeFileSync as h}from"fs";import{join as g,resolve as y}from"path";import{pipeline as v}from"stream/promises";import*as S from"@iarna/toml";import{codexHome as b,toolHome as _}from"./tools/types.js";import{CLI_NAME as x}from"./brand.js";export{b as codexHome};export function currentCodexProvider(){try{const e=S.parse(a(g(b(),"config.toml"),"utf-8"));return"string"==typeof e.model_provider&&e.model_provider.trim()?e.model_provider.trim():"openai"}catch{return"openai"}}let E=()=>{if("win32"===process.platform)return`${e("powershell.exe",["-NoProfile","-NonInteractive","-Command","(Get-Process -Name codex -ErrorAction SilentlyContinue).Id"],{encoding:"utf-8",windowsHide:!0}).stdout??""}`.split(/\s+/).filter(Boolean).map(Number);const t=process.getuid?.(),r=`${e("pgrep",["-x","-i",...void 0===t?[]:["-u",String(t)],"codex"],{encoding:"utf-8"}).stdout??""}`.split(/\s+/).filter(Boolean).map(Number);if("linux"!==process.platform)return r;const o=O(b());return r.filter(e=>{let t;try{t=a(`/proc/${e}/environ`,"utf-8")}catch{return!0}const r=new Map(t.split("\0").map(e=>[e.slice(0,e.indexOf("=")),e.slice(e.indexOf("=")+1)])),n=r.get("CODEX_HOME")?.trim()||(r.get("HOME")?g(r.get("HOME"),".codex"):null);return null===n||O(n)===o})};function O(e){try{return u(e)}catch{return e}}export function setCodexProcessCheckForTests(e){E=e}export function runningCodexPids(){try{return E()}catch{return[]}}function w(e){const r=c(e,"r");try{const e=[],t=Buffer.alloc(65536);for(;;){const o=f(r,t,0,t.length,null);if(o<=0)break;const n=t.subarray(0,o).indexOf(10);if(n>=0){e.push(Buffer.from(t.subarray(0,n)));break}e.push(Buffer.from(t.subarray(0,o)))}return Buffer.concat(e).toString("utf-8")}finally{t(r)}}async function N(e,t,r){const{atime:s,mtime:i}=d(e),c=`${e}.${x}-tmp`,a=n(c);a.write(t),await v(o(e,{start:r}),a),p(c,e),m(e,s,i)}export function codexSqliteHome(){const e=b();try{const t=S.parse(a(g(e,"config.toml"),"utf-8")),r="string"==typeof t.sqlite_home?t.sqlite_home.trim():"";if(r)return"~"===r||r.startsWith("~/")?g(_(),r.slice(1)):y(e,r)}catch{}const t=process.env.CODEX_SQLITE_HOME?.trim();return t?y(t):e}async function T(e){try{return new((await import("node:sqlite")).DatabaseSync)(e)}catch(e){return`node:sqlite unavailable (Node ${process.versions.node}; needs 22.13+): ${e instanceof Error?e.message:String(e)}`}}export const NO_STATE_DB="no state DB";export async function moveSessionsToProvider(e,t={}){const o=function(){const e=[],t=r=>{if(s(r))for(const o of l(r,{withFileTypes:!0})){const n=g(r,o.name);o.isDirectory()?t(n):o.isFile()&&o.name.endsWith(".jsonl")&&e.push(n)}};return t(g(b(),"sessions")),t(g(b(),"archived_sessions")),e}(),n=[];for(const t of o){let r,o;try{r=w(t)}catch{continue}try{o=JSON.parse(r)}catch{continue}const s=o.payload?.model_provider;"session_meta"===o.type&&"string"==typeof s&&s!==e&&(o.payload.model_provider=e,n.push({file:t,from:s,line:JSON.stringify(o),length:Buffer.byteLength(r,"utf-8")}))}const c=function(){const e=codexSqliteHome();if(!s(e))return null;const t=l(e).map(e=>/^state_(\d+)\.sqlite$/.exec(e)).filter(e=>!!e).sort((e,t)=>Number(t[1])-Number(e[1]));return t.length>0?g(e,t[0][0]):null}();let a=c?null:NO_STATE_DB,f=[],u=null;if(c){const t=await T(c);"string"==typeof t?a=t:(u=t,f=u.prepare('SELECT id, model_provider AS "from" FROM threads WHERE model_provider <> ?').all(e).map(e=>({id:String(e.id),from:String(e.from)})))}const p={target:e,scanned:o.length,moved:n.map(({file:e,from:t})=>({file:e,from:t})),dbRows:f.length,dbSkipped:a,backupDir:null};if(t.dryRun||0===n.length&&0===f.length)return u?.close(),p;const d=g(b(),"backups",`${x}-sessions-${(new Date).toISOString().replace(/[:.]/g,"-")}`);if(i(d,{recursive:!0}),c)for(const e of["","-wal","-shm"])s(c+e)&&r(c+e,g(d,`state.sqlite${e}`));const m={target:e,moved:p.moved,threads:f,db:c};h(g(d,"manifest.json"),JSON.stringify(m,null,2)+"\n");for(const e of n)await N(e.file,e.line,e.length);return u&&(u.prepare("UPDATE threads SET model_provider = ? WHERE model_provider <> ?").run(e,e),u.close()),p.backupDir=d,p}export async function undoSessionMove(e){const t=JSON.parse(a(g(e,"manifest.json"),"utf-8"));let r=0;for(const{file:e,from:o}of t.moved){if(!s(e))continue;const t=w(e),n=JSON.parse(t);n.payload&&(n.payload.model_provider=o,await N(e,JSON.stringify(n),Buffer.byteLength(t,"utf-8")),r+=1)}let o=0;if(t.db&&s(t.db)&&t.threads.length>0){const e=await T(t.db);if("string"!=typeof e){const r=e.prepare("UPDATE threads SET model_provider = ? WHERE id = ?");for(const{id:e,from:n}of t.threads)o+=Number(r.run(n,e).changes);e.close()}}return{files:r,dbRows:o}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeapi/api-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.128",
|
|
4
4
|
"description": "CLI tool for managing AI coding assistants (Claude Code, Codex, OpenClaw, Hermes, AtomCode, Grok Build) with one unified config",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|