chore: remove debug scripts
This commit is contained in:
@@ -1,102 +0,0 @@
|
|||||||
import { chmod, mkdtemp, readFile, writeFile } from 'node:fs/promises';
|
|
||||||
import { spawn } from 'node:child_process';
|
|
||||||
import { tmpdir } from 'node:os';
|
|
||||||
import { dirname, join } from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
|
|
||||||
function waitForExit(child, timeoutMs = 1500) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
child.kill('SIGKILL');
|
|
||||||
reject(new Error(`wrapper did not exit within ${timeoutMs}ms`));
|
|
||||||
}, timeoutMs);
|
|
||||||
|
|
||||||
child.on('error', (error) => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
child.on('close', (code) => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve(code ?? 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runWrapperWithFakePi(requestedModel) {
|
|
||||||
const dir = await mkdtemp(join(tmpdir(), 'pi-subagents-wrapper-'));
|
|
||||||
const metaPath = join(dir, 'meta.json');
|
|
||||||
const resultPath = join(dir, 'result.json');
|
|
||||||
const capturePath = join(dir, 'capture.json');
|
|
||||||
const piPath = join(dir, 'pi');
|
|
||||||
|
|
||||||
const resolved = requestedModel;
|
|
||||||
await writeFile(
|
|
||||||
piPath,
|
|
||||||
[
|
|
||||||
`#!${process.execPath}`,
|
|
||||||
"const fs = require('fs');",
|
|
||||||
`const capturePath = ${JSON.stringify(capturePath)};`,
|
|
||||||
"const obj = {",
|
|
||||||
" PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR: process.env.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR || '',",
|
|
||||||
" PI_SUBAGENTS_CHILD: process.env.PI_SUBAGENTS_CHILD || '',",
|
|
||||||
" argv: process.argv.slice(2)",
|
|
||||||
"};",
|
|
||||||
"fs.writeFileSync(capturePath, JSON.stringify(obj), 'utf8');",
|
|
||||||
"console.log(JSON.stringify({type:'message_end',message:{role:'assistant',content:[{type:'text',text:'done'}],model:'github-copilot/gpt-4o',stopReason:'stop'}}));",
|
|
||||||
].join('\n'),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
await chmod(piPath, 0o755);
|
|
||||||
|
|
||||||
await writeFile(
|
|
||||||
metaPath,
|
|
||||||
JSON.stringify(
|
|
||||||
{
|
|
||||||
runId: 'run-1',
|
|
||||||
mode: 'single',
|
|
||||||
task: 'inspect auth',
|
|
||||||
cwd: dir,
|
|
||||||
requestedModel,
|
|
||||||
resolvedModel: resolved,
|
|
||||||
startedAt: '2026-04-09T00:00:00.000Z',
|
|
||||||
sessionPath: join(dir, 'child-session.jsonl'),
|
|
||||||
eventsPath: join(dir, 'events.jsonl'),
|
|
||||||
resultPath,
|
|
||||||
stdoutPath: join(dir, 'stdout.log'),
|
|
||||||
stderrPath: join(dir, 'stderr.log'),
|
|
||||||
transcriptPath: join(dir, 'transcript.log'),
|
|
||||||
tools: ['read', 'grep'],
|
|
||||||
systemPromptPath: join(dir, 'system-prompt.md'),
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapperPath = join(dirname(fileURLToPath(import.meta.url)), 'src/wrapper/cli.mjs');
|
|
||||||
const child = spawn(process.execPath, [wrapperPath, metaPath], {
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
PATH: dir,
|
|
||||||
},
|
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
|
||||||
});
|
|
||||||
|
|
||||||
const exitCode = await waitForExit(child);
|
|
||||||
console.log('exitCode', exitCode);
|
|
||||||
|
|
||||||
const captureJson = JSON.parse(await readFile(capturePath, 'utf8'));
|
|
||||||
return { flags: captureJson };
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const captured = await runWrapperWithFakePi('github-copilot/gpt-4o');
|
|
||||||
console.log('captured', captured);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('error', err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import { mkdtemp, writeFile, chmod } from 'node:fs/promises';
|
|
||||||
import { tmpdir } from 'node:os';
|
|
||||||
import { join } from 'node:path';
|
|
||||||
import { spawn } from 'node:child_process';
|
|
||||||
import { dirname } from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
const dir = await mkdtemp(join(tmpdir(), 'pi-subagents-wrapper-'));
|
|
||||||
const metaPath = join(dir, 'meta.json');
|
|
||||||
const resultPath = join(dir, 'result.json');
|
|
||||||
const capturePath = join(dir, 'capture.json');
|
|
||||||
const piPath = join(dir, 'pi');
|
|
||||||
|
|
||||||
await writeFile(piPath, `#!${process.execPath}\nconst fs = require('fs');\nconst capturePath = ${JSON.stringify(capturePath)};\nconst obj = { PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR: process.env.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR || '', PI_SUBAGENTS_CHILD: process.env.PI_SUBAGENTS_CHILD || '', argv: process.argv.slice(2) }; fs.writeFileSync(capturePath, JSON.stringify(obj), 'utf8'); console.log(JSON.stringify({type:'message_end',message:{role:'assistant',content:[{type:'text',text:'done'}],model:'github-copilot/gpt-4o',stopReason:'stop'}}));`, 'utf8');
|
|
||||||
await chmod(piPath, 0o755);
|
|
||||||
|
|
||||||
const meta = {
|
|
||||||
runId: 'run-1',
|
|
||||||
mode: 'single',
|
|
||||||
task: 'inspect auth',
|
|
||||||
cwd: dir,
|
|
||||||
requestedModel: 'github-copilot/gpt-4o',
|
|
||||||
resolvedModel: 'github-copilot/gpt-4o',
|
|
||||||
startedAt: '2026-04-09T00:00:00.000Z',
|
|
||||||
sessionPath: join(dir, 'child-session.jsonl'),
|
|
||||||
eventsPath: join(dir, 'events.jsonl'),
|
|
||||||
resultPath,
|
|
||||||
stdoutPath: join(dir, 'stdout.log'),
|
|
||||||
stderrPath: join(dir, 'stderr.log'),
|
|
||||||
transcriptPath: join(dir, 'transcript.log'),
|
|
||||||
tools: ['read', 'grep'],
|
|
||||||
systemPromptPath: join(dir, 'system-prompt.md'),
|
|
||||||
};
|
|
||||||
|
|
||||||
await writeFile(metaPath, JSON.stringify(meta, null, 2), 'utf8');
|
|
||||||
|
|
||||||
const wrapperPath = join(dirname(fileURLToPath(import.meta.url)), 'src/wrapper/cli.mjs');
|
|
||||||
console.log('wrapperPath', wrapperPath, 'metaPath', metaPath);
|
|
||||||
const child = spawn(process.execPath, [wrapperPath, metaPath], { env: { ...process.env, PATH: dir }, stdio: ['ignore','pipe','pipe'] });
|
|
||||||
|
|
||||||
child.stdout.on('data', (c) => console.log('wrapper stdout:', c.toString()));
|
|
||||||
child.stderr.on('data', (c) => console.error('wrapper stderr:', c.toString()));
|
|
||||||
|
|
||||||
child.on('close', (code) => { console.log('wrapper exited', code); process.exit(code ?? 0); });
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch(err => { console.error(err); process.exit(1); });
|
|
||||||
Reference in New Issue
Block a user