agent-trace-capture 0.0.0-stage → 0.5.0
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/CAPTURE.md +12 -0
- package/COVERAGE.md +40 -0
- package/README.md +11 -2
- package/THIRD_PARTY_NOTICES.txt +1041 -0
- package/bin/archive.cjs +142 -0
- package/bin/cli.cjs +143 -0
- package/bin/desktop.cjs +61 -0
- package/binaries/darwin-arm64/agent-trace-capture +0 -0
- package/binaries/darwin-x64/agent-trace-capture +0 -0
- package/binaries/linux-arm64/agent-trace-capture +0 -0
- package/binaries/linux-x64/agent-trace-capture +0 -0
- package/binaries/win32-arm64/agent-trace-capture.exe +0 -0
- package/binaries/win32-x64/agent-trace-capture.exe +0 -0
- package/package.json +34 -4
package/bin/archive.cjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const fsp = fs.promises;
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const crypto = require('node:crypto');
|
|
7
|
+
const { pipeline } = require('node:stream/promises');
|
|
8
|
+
const http = require('node:http');
|
|
9
|
+
const https = require('node:https');
|
|
10
|
+
const { setTimeout: delay } = require('node:timers/promises');
|
|
11
|
+
const yazl = require('yazl');
|
|
12
|
+
const yauzl = require('yauzl');
|
|
13
|
+
const { promisify } = require('node:util');
|
|
14
|
+
|
|
15
|
+
async function hashes(file) {
|
|
16
|
+
const sha = crypto.createHash('sha256'), md5 = crypto.createHash('md5');
|
|
17
|
+
for await (const chunk of fs.createReadStream(file)) { sha.update(chunk); md5.update(chunk); }
|
|
18
|
+
return { sha256: sha.digest('hex'), md5: md5.digest('base64') };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function participant(options) {
|
|
22
|
+
const file = path.resolve(options['identity-file'] || path.join(os.homedir(), '.agent-trace-capture', 'participant-id'));
|
|
23
|
+
let id = options['participant-id'] || process.env.AGENT_TRACE_PARTICIPANT_ID;
|
|
24
|
+
if (!id) {
|
|
25
|
+
await fsp.mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
26
|
+
try { id = (await fsp.readFile(file, 'utf8')).trim(); }
|
|
27
|
+
catch (e) {
|
|
28
|
+
if (e.code !== 'ENOENT') throw e;
|
|
29
|
+
const tmp = file + '.' + crypto.randomUUID();
|
|
30
|
+
id = crypto.randomUUID();
|
|
31
|
+
await fsp.writeFile(tmp, id + '\n', { flag: 'wx', mode: 0o600 });
|
|
32
|
+
try { await fsp.link(tmp, file); }
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err.code !== 'EEXIST') throw err;
|
|
35
|
+
id = (await fsp.readFile(file, 'utf8')).trim();
|
|
36
|
+
} finally { await fsp.unlink(tmp); }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!/^[A-Za-z0-9_-]{1,128}$/.test(id)) throw new Error('Invalid participant ID');
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
function checkedUrl(input) {
|
|
43
|
+
const u = new URL(input);
|
|
44
|
+
if (u.username || u.password || (u.protocol !== 'https:' &&
|
|
45
|
+
!(u.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(u.hostname))))
|
|
46
|
+
throw new Error('Expected an HTTPS URL');
|
|
47
|
+
return u;
|
|
48
|
+
}
|
|
49
|
+
async function upload(part, server, id, token) {
|
|
50
|
+
const base = checkedUrl(server);
|
|
51
|
+
if (base.search || base.hash) throw new Error('Invalid capture server URL');
|
|
52
|
+
const ticket = await fetch(base.href.replace(/\/$/, '') + (token ? '/v1/uploads' : '/v1/public/uploads'), {
|
|
53
|
+
method: 'POST', redirect: 'error', headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: 'Bearer ' + token } : {}) },
|
|
54
|
+
body: JSON.stringify({ participant_id: id, bytes: part.bytes, md5: part.md5, sha256: part.sha256 })
|
|
55
|
+
});
|
|
56
|
+
if (ticket.status !== 201) throw new Error('Upload ticket HTTP ' + ticket.status);
|
|
57
|
+
const t = await ticket.json();
|
|
58
|
+
if (String(t.headers['Content-Length']) !== String(part.bytes) || t.headers['Content-MD5'] !== part.md5)
|
|
59
|
+
throw new Error('Upload ticket checksum or length mismatch');
|
|
60
|
+
const target=checkedUrl(t.upload_url);
|
|
61
|
+
const transport=target.protocol==='https:'?https:http;
|
|
62
|
+
for(let attempt=0;;attempt++) {
|
|
63
|
+
try {
|
|
64
|
+
await new Promise((resolve,reject)=>{
|
|
65
|
+
const input=fs.createReadStream(part.file);
|
|
66
|
+
const request=transport.request(target,{method:'PUT',headers:t.headers},res=>{
|
|
67
|
+
res.on('error',reject);
|
|
68
|
+
res.on('end',()=>res.statusCode>=200 && res.statusCode<300 ? resolve() : reject(Error('Storage HTTP '+res.statusCode)));
|
|
69
|
+
res.resume();
|
|
70
|
+
});
|
|
71
|
+
request.setTimeout(180000,()=>request.destroy(Error('Storage connection timed out')));
|
|
72
|
+
request.on('error',reject);
|
|
73
|
+
request.on('close',()=>input.destroy());
|
|
74
|
+
input.on('error',e=>request.destroy(e)); input.pipe(request);
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
} catch(e) {
|
|
78
|
+
if(attempt>=2) throw e;
|
|
79
|
+
await delay(1000*2**attempt);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return t.object_uri;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class Archives {
|
|
86
|
+
constructor(output, tmp, version) {
|
|
87
|
+
this.output = path.resolve(output); this.tmp = tmp; this.version = version;
|
|
88
|
+
this.pending = []; this.size = 0; this.parts = [];
|
|
89
|
+
}
|
|
90
|
+
async add(file, entry) {
|
|
91
|
+
if (this.pending.length && (this.size + entry.bytes > 128 * 1024 ** 2 || this.pending.length >= 300)) await this.flush();
|
|
92
|
+
this.pending.push({file,entry}); this.size += entry.bytes;
|
|
93
|
+
}
|
|
94
|
+
async flush() {
|
|
95
|
+
if (!this.pending.length) return;
|
|
96
|
+
const n = this.parts.length + 1;
|
|
97
|
+
const name = n === 1 ? this.output : this.output.replace(/(\.zip)?$/i, '.part-' + n + '.zip');
|
|
98
|
+
await fsp.mkdir(path.dirname(name), { recursive:true, mode:0o700 });
|
|
99
|
+
const handle = await fsp.open(name, 'wx', 0o600);
|
|
100
|
+
const zip = new yazl.ZipFile();
|
|
101
|
+
const dest = handle.createWriteStream();
|
|
102
|
+
const written = pipeline(zip.outputStream, dest);
|
|
103
|
+
zip.on('error', e => dest.destroy(e));
|
|
104
|
+
try {
|
|
105
|
+
const files = this.pending.map(x => x.entry);
|
|
106
|
+
for (const {file,entry} of this.pending) zip.addFile(file,entry.path,{mode:0o100600});
|
|
107
|
+
zip.addBuffer(Buffer.from(JSON.stringify({ schema_version:1, client_version:this.version, created_at:new Date().toISOString(),
|
|
108
|
+
status:'complete', platform:process.platform, providers:[...new Set(files.map(x=>x.provider))], files, errors:[] })), 'manifest.json');
|
|
109
|
+
zip.end();
|
|
110
|
+
await written;
|
|
111
|
+
} catch (e) { dest.destroy(); await written.catch(()=>{}); await fsp.rm(name,{force:true}); throw e; }
|
|
112
|
+
this.parts.push({file:name, sources:this.pending.length,bytes:(await fsp.stat(name)).size,...await hashes(name)});
|
|
113
|
+
for (const {file} of this.pending) await fsp.unlink(file);
|
|
114
|
+
this.pending = []; this.size = 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function importNative(file, archives, covered, report) {
|
|
119
|
+
const z = await promisify(yauzl.open)(file,{lazyEntries:true,autoClose:false});
|
|
120
|
+
try {
|
|
121
|
+
const entries = new Map();
|
|
122
|
+
await new Promise((resolve,reject)=>{
|
|
123
|
+
z.on('error',reject); z.on('end',resolve);
|
|
124
|
+
z.on('entry',entry=>{ entries.set(entry.fileName,entry); z.readEntry(); }); z.readEntry();
|
|
125
|
+
});
|
|
126
|
+
const stream = promisify(z.openReadStream.bind(z));
|
|
127
|
+
const chunks = [];
|
|
128
|
+
for await (const c of await stream(entries.get('manifest.json'))) chunks.push(c);
|
|
129
|
+
const manifest = JSON.parse(Buffer.concat(chunks));
|
|
130
|
+
if (manifest.status !== 'complete' || manifest.errors?.length) throw new Error('Native reader reported an incomplete capture');
|
|
131
|
+
for (const item of manifest.files) {
|
|
132
|
+
const key = item.provider + '/' + item.sha256;
|
|
133
|
+
if (covered.has(key)) { report.matched_sources.push({source:item.source, uri:covered.get(key)}); continue; }
|
|
134
|
+
const tmp = path.join(archives.tmp,crypto.randomUUID());
|
|
135
|
+
await pipeline(await stream(entries.get(item.path)),fs.createWriteStream(tmp,{flags:'wx',mode:0o600}));
|
|
136
|
+
if ((await hashes(tmp)).sha256 !== item.sha256) throw new Error('Native member checksum mismatch');
|
|
137
|
+
await archives.add(tmp,{...item,reader:'custom'});
|
|
138
|
+
report.custom.push({source:item.source,provider:item.provider});
|
|
139
|
+
}
|
|
140
|
+
} finally { z.close(); }
|
|
141
|
+
}
|
|
142
|
+
module.exports = { hashes, participant, upload, Archives, importNative };
|
package/bin/cli.cjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const fs = require('node:fs/promises');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const crypto = require('node:crypto');
|
|
7
|
+
const { execFile, spawnSync } = require('node:child_process');
|
|
8
|
+
const exec = require('node:util').promisify(execFile);
|
|
9
|
+
const { hashes, participant, upload, Archives, importNative } = require('./archive.cjs');
|
|
10
|
+
const { desktopSources, captureDesktop } = require('./desktop.cjs');
|
|
11
|
+
const version = require('../package.json').version;
|
|
12
|
+
const native = path.join(__dirname,'../binaries',process.platform+'-'+process.arch,'agent-trace-capture'+(process.platform==='win32'?'.exe':''));
|
|
13
|
+
const natives='claude,codex,cursor,opencode,kimi,gemini,copilot,cline,roo,continue,aider'.split(',');
|
|
14
|
+
const canonical = p => ({'claudecode':'claude','claude-code':'claude','gemini-cli':'gemini'}[p] || p);
|
|
15
|
+
const run = (bin,args,cwd) => exec(bin,args,{cwd,maxBuffer:128*1024**2,windowsHide:true});
|
|
16
|
+
function delegate(args) {
|
|
17
|
+
const r=spawnSync(native,args,{stdio:'inherit'}); if(r.error) throw r.error; process.exitCode=r.status ?? 1;
|
|
18
|
+
}
|
|
19
|
+
function parse(args) {
|
|
20
|
+
const options={}, values=['output','o','identity-file','participant-id','server-url','upload-token'];
|
|
21
|
+
for(let i=0;i<args.length;i++) {
|
|
22
|
+
const m=/^--?([\w-]+)(?:=(.*))?$/.exec(args[i]);
|
|
23
|
+
if(!m) throw Error('Unexpected argument: '+args[i]);
|
|
24
|
+
const [,k,v]=m;
|
|
25
|
+
if(k==='providers') {
|
|
26
|
+
const items=v===undefined?[]:[v];
|
|
27
|
+
if(v===undefined) while(i+1<args.length && !args[i+1].startsWith('-')) items.push(args[++i]);
|
|
28
|
+
const providers=items.join(',').split(/[,\s]+/).filter(Boolean).map(canonical);
|
|
29
|
+
if(!providers.length) throw Error('Missing providers');
|
|
30
|
+
options.providers=new Set(providers);
|
|
31
|
+
} else if(['local-only','dry-run'].includes(k) && (v===undefined || /^(true|false)$/.test(v))) options[k]=v!=='false';
|
|
32
|
+
else if(values.includes(k)) { options[k==='o'?'output':k]=v ?? args[++i]; if(!(v ?? args[i]) || (v===undefined && args[i].startsWith('-'))) throw Error('Missing value for '+k); }
|
|
33
|
+
else throw Error('Unknown argument: '+k);
|
|
34
|
+
}
|
|
35
|
+
return options;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function main(args) {
|
|
39
|
+
if(args.some(x=>/^--?version$/.test(x))) { console.log(version); return; }
|
|
40
|
+
// Explicit storage overrides retain native discovery boundaries, even on a developer's own workstation.
|
|
41
|
+
if(args.some(x=>/^--?(?:home|[\w-]+-home|editor-user-dir|cursor-user-dir|project-dir|opencode-db|h|help)(?:=|$)/.test(x))) return delegate(args);
|
|
42
|
+
const options=parse(args);
|
|
43
|
+
let dump;
|
|
44
|
+
try { dump=require('@agent-dump/cli/lib/resolve-binary.cjs').resolveBinary(); }
|
|
45
|
+
catch { console.error('Agent Dump binary unavailable. Using the bundled readers.'); }
|
|
46
|
+
const privateDir=await fs.mkdtemp(path.join(os.tmpdir(),'agent-trace-capture-'));
|
|
47
|
+
try { await capture(options,dump,privateDir); } finally { await fs.rm(privateDir,{recursive:true,force:true}); }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function capture(o,dump,tmp) {
|
|
51
|
+
const report={version,started:new Date().toISOString(),agent_dump:[],matched_sources:[],custom:[],errors:[],parts:[]};
|
|
52
|
+
const output=path.resolve(o.output || 'agent-traces-'+new Date().toISOString().replace(/[:.]/g,'-')+'.zip');
|
|
53
|
+
const receipt=output+'.receipt.json';
|
|
54
|
+
const selected=o.providers, dry=o['dry-run'];
|
|
55
|
+
const nativeProviders=natives.filter(p=>!selected||selected.has(p));
|
|
56
|
+
const desktop=await desktopSources(selected);
|
|
57
|
+
const caps=dump ? JSON.parse((await run(dump,['providers','--json'],tmp)).stdout).data : [];
|
|
58
|
+
const active=caps.filter(p=>!selected||selected.has(canonical(p.provider)));
|
|
59
|
+
if(selected) {
|
|
60
|
+
const extra='pi openclaw kimi-code claude-desktop-code claude-cowork kiro windsurf antigravity mini-swe-agent void'.split(' ');
|
|
61
|
+
for(const p of selected) if(!natives.includes(p)&&!caps.some(c=>canonical(c.provider)===p)&&!extra.includes(p)&&!p.startsWith('vscode-chat-')) throw Error('Unknown provider: '+p);
|
|
62
|
+
}
|
|
63
|
+
let sessions=[];
|
|
64
|
+
if(active.length) {
|
|
65
|
+
const args=['list','--days','365000','--json'];
|
|
66
|
+
if(selected) args.push('--query','provider:'+active.map(x=>x.provider).join(','));
|
|
67
|
+
const result=JSON.parse((await run(dump,args,tmp)).stdout);
|
|
68
|
+
sessions=result.data.filter(s=>active.some(p=>p.provider===s.provider));
|
|
69
|
+
for(const e of [...(result.failed_providers||[]),...(result.failed_sessions||[])]) report.errors.push({phase:'discovery',provider:e.provider});
|
|
70
|
+
}
|
|
71
|
+
if(dump) console.log('Agent Dump discovered '+sessions.length+' sessions.');
|
|
72
|
+
const sources=new Map();
|
|
73
|
+
for(const p of nativeProviders) {
|
|
74
|
+
const {stdout}=await run(native,['--dry-run','--providers',p],process.cwd());
|
|
75
|
+
sources.set(p,[...stdout.matchAll(/^ \[([^\]]+)\] (.+)$/gm)].map(m=>({kind:m[1],source:m[2].trimEnd()})));
|
|
76
|
+
}
|
|
77
|
+
if(dry) {
|
|
78
|
+
for(const [p,ss] of sources) for(const s of ss) console.log(p+' ['+s.kind+'] '+s.source);
|
|
79
|
+
for(const s of desktop) console.log(s.provider+' ['+s.kind+'] '+s.source);
|
|
80
|
+
for(const s of sessions) console.log(s.uri);
|
|
81
|
+
if(report.errors.length) process.exitCode=1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
await fs.mkdir(path.dirname(output),{recursive:true,mode:0o700});
|
|
85
|
+
await fs.writeFile(receipt,JSON.stringify(report),{flag:'wx',mode:0o600});
|
|
86
|
+
const save=async()=>{const temp=receipt+'.'+crypto.randomUUID(); await fs.writeFile(temp,JSON.stringify(report),{mode:0o600}); await fs.rename(temp,receipt);};
|
|
87
|
+
const archives=new Archives(output,tmp,version), covered=new Map();
|
|
88
|
+
const formats=new Map(caps.map(p=>[p.provider,p.formats.includes('raw')?'raw':'json']));
|
|
89
|
+
// Start with a small conversation that can be opened independently in the viewer.
|
|
90
|
+
const sample=sessions.findIndex(s=>s.provider==='codex' && s.message_count>1 && s.message_count<10);
|
|
91
|
+
if(sample>0) sessions.unshift(sessions.splice(sample,1)[0]);
|
|
92
|
+
for(const s of sessions) {
|
|
93
|
+
const dir=await fs.mkdtemp(path.join(tmp,'export-')), format=formats.get(s.provider), provider=canonical(s.provider);
|
|
94
|
+
try {
|
|
95
|
+
await run(dump,['export',s.uri,'--format',format,'--output',dir],tmp);
|
|
96
|
+
const entries=await require('fast-glob')('**/*',{cwd:dir,onlyFiles:true,followSymbolicLinks:false});
|
|
97
|
+
if(!entries.length) throw Error('No export files');
|
|
98
|
+
for(const rel of entries) {
|
|
99
|
+
const file=path.join(tmp,crypto.randomUUID());
|
|
100
|
+
await fs.rename(path.join(dir,rel),file);
|
|
101
|
+
const {sha256}=await hashes(file), bytes=(await fs.stat(file)).size;
|
|
102
|
+
const key=crypto.createHash('sha256').update(s.uri).digest('hex');
|
|
103
|
+
await archives.add(file,{provider,source:s.uri,reader:'agent-dump',kind:'agent-dump-'+format,path:'agent-dump/'+key+'/'+rel,bytes,sha256,modified_at:s.updated_at||s.created_at});
|
|
104
|
+
if(format==='raw') covered.set(provider+'/'+sha256,s.uri);
|
|
105
|
+
}
|
|
106
|
+
report.agent_dump.push({uri:s.uri,provider,format});
|
|
107
|
+
if(report.agent_dump.length===1) await archives.flush();
|
|
108
|
+
} catch(e) {
|
|
109
|
+
if(!e.cmd && e.message!=='No export files') throw e;
|
|
110
|
+
report.errors.push({phase:'export',uri:s.uri,code:e.code||'empty'});
|
|
111
|
+
} finally { await fs.rm(dir,{recursive:true,force:true}); }
|
|
112
|
+
if((report.agent_dump.length+report.errors.length)%100===0) { console.log('Exported '+report.agent_dump.length+' sessions'); await save(); }
|
|
113
|
+
}
|
|
114
|
+
for(const [p,ss] of sources) {
|
|
115
|
+
if(!ss.length) continue;
|
|
116
|
+
if(ss.every(s=>s.kind==='file')) {
|
|
117
|
+
const matches=[];
|
|
118
|
+
for(const s of ss) {const uri=covered.get(p+'/'+(await hashes(s.source)).sha256); if(!uri) break; matches.push({source:s.source,uri});}
|
|
119
|
+
if(matches.length===ss.length) {report.matched_sources.push(...matches); continue;}
|
|
120
|
+
}
|
|
121
|
+
console.log('Checking bundled reader for '+p);
|
|
122
|
+
const file=path.join(tmp,crypto.randomUUID()+'.zip');
|
|
123
|
+
await run(native,['--local-only','--output',file,'--providers',p],process.cwd());
|
|
124
|
+
await importNative(file,archives,covered,report); await fs.unlink(file);
|
|
125
|
+
}
|
|
126
|
+
for(const s of desktop) await captureDesktop(s,archives,covered,report);
|
|
127
|
+
await archives.flush();
|
|
128
|
+
report.parts=archives.parts;
|
|
129
|
+
await save();
|
|
130
|
+
if(!report.parts.length) {console.log('No traces found.');return;}
|
|
131
|
+
if(!o['local-only']) {
|
|
132
|
+
const server=o['server-url']||process.env.AGENT_TRACE_SERVER_URL||'https://agent-trace-capture.vercel.app';
|
|
133
|
+
const token=o['upload-token']||process.env.AGENT_TRACE_UPLOAD_TOKEN;
|
|
134
|
+
const id=await participant(o);
|
|
135
|
+
for(const part of report.parts) {
|
|
136
|
+
part.object_uri=await upload(part,server,id,token); await save(); console.log('Uploaded '+part.object_uri);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
report.finished=new Date().toISOString();await save();
|
|
140
|
+
console.log('Capture receipt: '+receipt);
|
|
141
|
+
if(report.errors.length) {console.error(report.errors.length+' session discovery/export errors. See receipt.');process.exitCode=1;}
|
|
142
|
+
}
|
|
143
|
+
main(process.argv.slice(2)).catch(e=>{console.error(e.cmd?'Reader failed (exit '+e.code+')':e.message);process.exitCode=1;});
|
package/bin/desktop.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs/promises');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
6
|
+
const glob = require('fast-glob');
|
|
7
|
+
const { execFile } = require('node:child_process');
|
|
8
|
+
const exec = require('node:util').promisify(execFile);
|
|
9
|
+
const { hashes } = require('./archive.cjs');
|
|
10
|
+
|
|
11
|
+
async function desktopSources(selected) {
|
|
12
|
+
const sources = [];
|
|
13
|
+
const home = os.homedir(), apps = path.join(home, 'Library/Application Support');
|
|
14
|
+
async function scan(provider, root, patterns, kind = 'file') {
|
|
15
|
+
if (selected && !selected.has(provider)) return;
|
|
16
|
+
// Skip symlinked roots as well as symlink entries below them.
|
|
17
|
+
if (await fs.realpath(root).catch(() => '') !== root) return;
|
|
18
|
+
for (const rel of await glob(patterns, { cwd:root, dot:true, followSymbolicLinks:false, onlyFiles:true })) {
|
|
19
|
+
if (await fs.realpath(path.join(root,rel)) !== path.join(root,rel)) continue;
|
|
20
|
+
sources.push({provider, source:path.join(root,rel), path:provider+'/'+rel+(kind==='void-chat-rows'?'.jsonl':''), kind});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
await scan('pi',path.join(home,'.pi/agent/sessions'),'*/*.jsonl');
|
|
24
|
+
await scan('openclaw',path.join(home,'.openclaw/agents'),'*/sessions/*.jsonl');
|
|
25
|
+
await scan('kimi-code',path.join(home,'.kimi-code'),'user-history/*.jsonl');
|
|
26
|
+
await scan('kimi-code',path.resolve(process.env.KIMI_CODE_HOME || path.join(home,'.kimi-code')),'sessions/*/*/agents/*/wire.jsonl');
|
|
27
|
+
if (process.platform !== 'darwin') return sources;
|
|
28
|
+
await scan('claude-desktop-code',path.join(apps,'Claude/claude-code-sessions'),'*/*/local_*.json','session-metadata');
|
|
29
|
+
await scan('claude-cowork',path.join(apps,'Claude/local-agent-mode-sessions'),['*/*/local_*/.claude/projects/*/**/*.jsonl','*/*/local_*/audit.jsonl']);
|
|
30
|
+
for (const app of ['Code','Code - Insiders','Cursor','VSCodium','Windsurf','Kiro','Antigravity','Trae']) {
|
|
31
|
+
await scan('vscode-chat-'+app.toLowerCase().replaceAll(' ','-'),path.join(apps,app,'User'),[
|
|
32
|
+
'workspaceStorage/*/chatSessions/*.{json,jsonl}','globalStorage/emptyWindowChatSessions/*.{json,jsonl}',
|
|
33
|
+
'profiles/*/globalStorage/emptyWindowChatSessions/*.{json,jsonl}']);
|
|
34
|
+
}
|
|
35
|
+
await scan('kiro',path.join(apps,'Kiro/User/globalStorage/kiro.kiroagent'),['*/*.chat','workspace-sessions/*/*.json']);
|
|
36
|
+
await scan('windsurf',path.join(home,'.codeium/windsurf/cascade'),'*.pb','native-protobuf');
|
|
37
|
+
await scan('antigravity',path.join(home,'.gemini/antigravity/conversations'),'*.pb','native-protobuf');
|
|
38
|
+
await scan('mini-swe-agent',path.join(apps,'mini-swe-agent'),['*.traj.json','interactive_history.txt']);
|
|
39
|
+
await scan('void',path.join(apps,'Void/User'),['globalStorage/state.vscdb','workspaceStorage/*/state.vscdb'],'void-chat-rows');
|
|
40
|
+
return sources;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function captureDesktop(entry, archives, covered, report) {
|
|
44
|
+
const file=path.join(archives.tmp,crypto.randomUUID());
|
|
45
|
+
const stat=await fs.stat(entry.source);
|
|
46
|
+
if (entry.kind === 'session-metadata') {
|
|
47
|
+
const data=JSON.parse(await fs.readFile(entry.source,'utf8'));
|
|
48
|
+
const keys=['sessionId','cliSessionId','createdAt','lastActivityAt','model','title','completedTurns','isArchived'];
|
|
49
|
+
await fs.writeFile(file,JSON.stringify(Object.fromEntries(keys.filter(k=>Object.hasOwn(data,k)).map(k=>[k,data[k]]))),{mode:0o600});
|
|
50
|
+
} else if (entry.kind === 'void-chat-rows') {
|
|
51
|
+
const {stdout} = await exec('/usr/bin/sqlite3',['-readonly',entry.source,"SELECT value FROM ItemTable WHERE key='void.chatThreadStorageII'"],{maxBuffer:128*1024**2});
|
|
52
|
+
if (!stdout.trim()) return;
|
|
53
|
+
await fs.writeFile(file,JSON.stringify({key:'void.chatThreadStorageII',value:JSON.parse(stdout)})+'\n',{mode:0o600});
|
|
54
|
+
} else await fs.copyFile(entry.source,file);
|
|
55
|
+
const {sha256}=await hashes(file);
|
|
56
|
+
const uri=covered.get(entry.provider+'/'+sha256);
|
|
57
|
+
if (uri) { report.matched_sources.push({source:entry.source,uri}); await fs.unlink(file); return; }
|
|
58
|
+
await archives.add(file,{...entry,reader:'custom',sha256,bytes:(await fs.stat(file)).size,modified_at:stat.mtime.toISOString()});
|
|
59
|
+
report.custom.push({source:entry.source,provider:entry.provider});
|
|
60
|
+
}
|
|
61
|
+
module.exports={desktopSources,captureDesktop};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-trace-capture",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Capture local coding-agent histories with Agent Dump and native fallback readers",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=18"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"agent-trace-capture": "bin/cli.cjs"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/*.cjs",
|
|
14
|
+
"binaries/",
|
|
15
|
+
"README.md",
|
|
16
|
+
"CAPTURE.md",
|
|
17
|
+
"COVERAGE.md",
|
|
18
|
+
"THIRD_PARTY_NOTICES.txt"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test tests/npm.test.cjs",
|
|
22
|
+
"prepack": "node scripts/check-package.cjs"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"fast-glob": "3.3.3",
|
|
30
|
+
"yauzl": "3.4.0",
|
|
31
|
+
"yazl": "3.3.1"
|
|
32
|
+
},
|
|
33
|
+
"optionalDependencies": {
|
|
34
|
+
"@agent-dump/cli": "1.2.12"
|
|
35
|
+
}
|
|
36
|
+
}
|