@yuandc/aica 0.1.1 → 0.1.3
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/dist/acp/agent.js +1 -54
- package/dist/acp/client/acp-client.js +1 -102
- package/dist/acp/client/acp-content.js +1 -13
- package/dist/acp/client/acp-events.js +1 -106
- package/dist/acp/client/acp-process.js +1 -34
- package/dist/acp/client/acp-runtime-pool.js +1 -248
- package/dist/acp/client/context-usage.js +1 -29
- package/dist/acp/client/json-rpc.js +4 -128
- package/dist/acp/provider-types.js +0 -1
- package/dist/acp/providers/codex/codex-path.js +1 -0
- package/dist/acp/providers/codex/codex-process.js +1 -51
- package/dist/acp/providers/codex/events.js +28 -1473
- package/dist/acp/providers/codex/permissions.js +1 -49
- package/dist/acp/providers/codex/provider.js +1 -376
- package/dist/acp/providers/codex-acp/adapter.js +5 -947
- package/dist/acp/providers/codex-acp/context-maintenance.js +5 -148
- package/dist/acp/providers/codex-acp/launch.js +1 -35
- package/dist/acp/providers/codex-acp/provider.js +1 -486
- package/dist/acp/providers/mimo/provider.js +5 -448
- package/dist/acp/providers/opencode/provider.js +4 -489
- package/dist/acp/providers/registry.js +1 -23
- package/dist/acp/standard-events.js +1 -167
- package/dist/commands/start.js +1 -137
- package/dist/commands/worker-auth.js +4 -100
- package/dist/commands/worker-project.js +1 -57
- package/dist/core/aca-config.js +1 -74
- package/dist/core/aca-server-client.js +1 -57
- package/dist/core/acp-event-coalescer.js +1 -108
- package/dist/core/acp-event-upload-filter.js +1 -16
- package/dist/core/acp-orphan-cleanup.js +1 -91
- package/dist/core/affected-files.js +2 -268
- package/dist/core/auth.js +1 -36
- package/dist/core/file-transfer-worker.js +1 -169
- package/dist/core/fs.js +2 -28
- package/dist/core/heartbeat.js +3 -578
- package/dist/core/job-permission-policy.js +1 -42
- package/dist/core/job-worker.js +6 -749
- package/dist/core/logger.js +3 -42
- package/dist/core/long-poll-worker.js +1 -26
- package/dist/core/machine-filesystem-worker.js +3 -352
- package/dist/core/paths.js +1 -26
- package/dist/core/process-identity.js +1 -34
- package/dist/core/process.js +2 -33
- package/dist/core/provider-health.js +1 -54
- package/dist/core/runtime-options.js +1 -38
- package/dist/core/worktree.js +1 -95
- package/dist/worker-cli.js +1 -28
- package/dist/worker-single-cli.js +1 -16
- package/package.json +1 -1
|
@@ -1,128 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
lineBuffer = "";
|
|
6
|
-
pending = new Map();
|
|
7
|
-
peerName;
|
|
8
|
-
includeJsonRpc;
|
|
9
|
-
notifications = [];
|
|
10
|
-
stdout = "";
|
|
11
|
-
stderr = "";
|
|
12
|
-
exitCode = null;
|
|
13
|
-
signal = null;
|
|
14
|
-
constructor(child, handlers = {}) {
|
|
15
|
-
this.child = child;
|
|
16
|
-
this.handlers = handlers;
|
|
17
|
-
this.peerName = handlers.peerName || "JSON-RPC peer";
|
|
18
|
-
this.includeJsonRpc = handlers.includeJsonRpc === true;
|
|
19
|
-
child.stdout.on("data", (chunk) => this.handleStdout(String(chunk)));
|
|
20
|
-
child.stderr.on("data", (chunk) => {
|
|
21
|
-
this.stderr += String(chunk);
|
|
22
|
-
});
|
|
23
|
-
child.on("close", (code, signal) => {
|
|
24
|
-
this.exitCode = code;
|
|
25
|
-
this.signal = signal;
|
|
26
|
-
for (const [id, pending] of this.pending) {
|
|
27
|
-
clearTimeout(pending.timer);
|
|
28
|
-
pending.reject(new Error(`${this.peerName} exited before ${pending.method} completed (code=${code}, signal=${signal})`));
|
|
29
|
-
this.pending.delete(id);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
child.on("error", (error) => {
|
|
33
|
-
for (const [id, pending] of this.pending) {
|
|
34
|
-
clearTimeout(pending.timer);
|
|
35
|
-
pending.reject(error);
|
|
36
|
-
this.pending.delete(id);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
request(method, params, timeoutMs = 120_000) {
|
|
41
|
-
const id = this.nextId++;
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
const timer = this.createRequestTimeout(id, method, timeoutMs, reject);
|
|
44
|
-
timer.unref();
|
|
45
|
-
this.pending.set(id, { method, resolve, reject, timer, timeoutMs });
|
|
46
|
-
this.write({ ...(this.includeJsonRpc ? { jsonrpc: "2.0" } : {}), id, method, ...(params === undefined ? {} : { params }) });
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
notify(method, params) {
|
|
50
|
-
this.write({ ...(this.includeJsonRpc ? { jsonrpc: "2.0" } : {}), method, ...(params === undefined ? {} : { params }) });
|
|
51
|
-
}
|
|
52
|
-
refreshPendingRequestTimeout(method) {
|
|
53
|
-
for (const [id, pending] of this.pending) {
|
|
54
|
-
if (pending.method !== method)
|
|
55
|
-
continue;
|
|
56
|
-
clearTimeout(pending.timer);
|
|
57
|
-
pending.timer = this.createRequestTimeout(id, pending.method, pending.timeoutMs, pending.reject);
|
|
58
|
-
pending.timer.unref();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
respond(id, result) {
|
|
62
|
-
this.write({ ...(this.includeJsonRpc ? { jsonrpc: "2.0" } : {}), id, result });
|
|
63
|
-
}
|
|
64
|
-
respondError(id, error) {
|
|
65
|
-
this.write({ ...(this.includeJsonRpc ? { jsonrpc: "2.0" } : {}), id, error: { code: -32603, message: error.message } });
|
|
66
|
-
}
|
|
67
|
-
createRequestTimeout(id, method, timeoutMs, reject) {
|
|
68
|
-
return setTimeout(() => {
|
|
69
|
-
this.pending.delete(id);
|
|
70
|
-
reject(new Error(`${this.peerName} request timed out while waiting for ${method}`));
|
|
71
|
-
}, timeoutMs);
|
|
72
|
-
}
|
|
73
|
-
handleStdout(chunk) {
|
|
74
|
-
this.stdout += chunk;
|
|
75
|
-
this.lineBuffer += chunk;
|
|
76
|
-
const lines = this.lineBuffer.split("\n");
|
|
77
|
-
this.lineBuffer = lines.pop() ?? "";
|
|
78
|
-
for (const line of lines) {
|
|
79
|
-
const trimmed = line.trim();
|
|
80
|
-
if (!trimmed)
|
|
81
|
-
continue;
|
|
82
|
-
let message;
|
|
83
|
-
try {
|
|
84
|
-
message = JSON.parse(trimmed);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
this.stderr += `\n[non-json stdout] ${trimmed}`;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
void this.handleMessage(message);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async handleMessage(message) {
|
|
94
|
-
if ("id" in message && ("result" in message || "error" in message) && typeof message.method !== "string") {
|
|
95
|
-
const id = Number(message.id);
|
|
96
|
-
const pending = this.pending.get(id);
|
|
97
|
-
if (!pending)
|
|
98
|
-
return;
|
|
99
|
-
this.pending.delete(id);
|
|
100
|
-
clearTimeout(pending.timer);
|
|
101
|
-
if ("error" in message) {
|
|
102
|
-
const error = message.error;
|
|
103
|
-
pending.reject(new Error(error?.message || `${this.peerName} error ${error?.code ?? "unknown"}`));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
pending.resolve(message.result);
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (typeof message.method !== "string")
|
|
111
|
-
return;
|
|
112
|
-
if ("id" in message) {
|
|
113
|
-
try {
|
|
114
|
-
const result = await this.handlers.onRequest?.(message.method, message.params, message);
|
|
115
|
-
this.respond(message.id, result ?? null);
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
this.respondError(message.id, error instanceof Error ? error : new Error(String(error)));
|
|
119
|
-
}
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
this.notifications.push(message);
|
|
123
|
-
await this.handlers.onNotification?.(message.method, message.params, message);
|
|
124
|
-
}
|
|
125
|
-
write(message) {
|
|
126
|
-
this.child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
1
|
+
class c{child;handlers;nextId=1;lineBuffer="";pending=new Map;peerName;includeJsonRpc;notifications=[];stdout="";stderr="";exitCode=null;signal=null;constructor(e,t={}){this.child=e,this.handlers=t,this.peerName=t.peerName||"JSON-RPC peer",this.includeJsonRpc=t.includeJsonRpc===!0,e.stdout.on("data",i=>this.handleStdout(String(i))),e.stderr.on("data",i=>{this.stderr+=String(i)}),e.on("close",(i,n)=>{this.exitCode=i,this.signal=n;for(const[r,o]of this.pending)clearTimeout(o.timer),o.reject(new Error(`${this.peerName} exited before ${o.method} completed (code=${i}, signal=${n})`)),this.pending.delete(r)}),e.on("error",i=>{for(const[n,r]of this.pending)clearTimeout(r.timer),r.reject(i),this.pending.delete(n)})}request(e,t,i=12e4){const n=this.nextId++;return new Promise((r,o)=>{const s=this.createRequestTimeout(n,e,i,o);s.unref(),this.pending.set(n,{method:e,resolve:r,reject:o,timer:s,timeoutMs:i}),this.write({...this.includeJsonRpc?{jsonrpc:"2.0"}:{},id:n,method:e,...t===void 0?{}:{params:t}})})}notify(e,t){this.write({...this.includeJsonRpc?{jsonrpc:"2.0"}:{},method:e,...t===void 0?{}:{params:t}})}refreshPendingRequestTimeout(e){for(const[t,i]of this.pending)i.method===e&&(clearTimeout(i.timer),i.timer=this.createRequestTimeout(t,i.method,i.timeoutMs,i.reject),i.timer.unref())}respond(e,t){this.write({...this.includeJsonRpc?{jsonrpc:"2.0"}:{},id:e,result:t})}respondError(e,t){this.write({...this.includeJsonRpc?{jsonrpc:"2.0"}:{},id:e,error:{code:-32603,message:t.message}})}createRequestTimeout(e,t,i,n){return setTimeout(()=>{this.pending.delete(e),n(new Error(`${this.peerName} request timed out while waiting for ${t}`))},i)}handleStdout(e){this.stdout+=e,this.lineBuffer+=e;const t=this.lineBuffer.split(`
|
|
2
|
+
`);this.lineBuffer=t.pop()??"";for(const i of t){const n=i.trim();if(!n)continue;let r;try{r=JSON.parse(n)}catch{this.stderr+=`
|
|
3
|
+
[non-json stdout] ${n}`;continue}this.handleMessage(r)}}async handleMessage(e){if("id"in e&&("result"in e||"error"in e)&&typeof e.method!="string"){const t=Number(e.id),i=this.pending.get(t);if(!i)return;if(this.pending.delete(t),clearTimeout(i.timer),"error"in e){const n=e.error;i.reject(new Error(n?.message||`${this.peerName} error ${n?.code??"unknown"}`))}else i.resolve(e.result);return}if(typeof e.method=="string"){if("id"in e){try{const t=await this.handlers.onRequest?.(e.method,e.params,e);this.respond(e.id,t??null)}catch(t){this.respondError(e.id,t instanceof Error?t:new Error(String(t)))}return}this.notifications.push(e),await this.handlers.onNotification?.(e.method,e.params,e)}}write(e){this.child.stdin.write(`${JSON.stringify(e)}
|
|
4
|
+
`)}}export{c as JsonLineRpcClient};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import d from"node:fs";import T from"node:os";import y from"node:path";function k(n={}){const e=n.env??process.env,o=n.platform??process.platform,t=n.arch??process.arch,c=n.homeDir??T.homedir(),i=n.execPath??process.execPath,r=o==="win32"?y.win32:y.posix,s=l(e.CODEX_PATH);if(s){const u=D(s,e,o,r);return u?P(u,o,t,r)??u:s}const f=w([D("codex",e,o,r),...F(e,o,c,i,r)]);let a=null;for(const u of f){if(!u||!b(u,o))continue;const x=P(u,o,t,r);if(x)return x;if(!N(u))return u;a??=u}for(const u of O(e,o,c,i,r)){const x=m(u,o,t,r);if(x)return x}return a??"codex"}function F(n,e,o,t,c){const i=e==="win32"?"codex.exe":"codex",r=e==="win32"?"codex.cmd":"codex",s=l(n.npm_config_prefix),f=l(n.APPDATA),a=l(n.LOCALAPPDATA);return w([c.join(o,".codex","packages","standalone","current","bin",i),n.NVM_BIN?c.join(n.NVM_BIN,i):null,n.VOLTA_HOME?c.join(n.VOLTA_HOME,"bin",i):null,s?c.join(s,e==="win32"?"":"bin",r):null,c.join(c.dirname(t),r),e==="win32"&&f?c.join(f,"npm",r):null,e==="win32"&&a?c.join(a,"npm",r):null,e!=="win32"?c.join(o,".local","bin",i):null,e==="darwin"?"/opt/homebrew/bin/codex":null,e!=="win32"?"/usr/local/bin/codex":null,e!=="win32"?"/usr/bin/codex":null])}function O(n,e,o,t,c){const i=w([l(n.npm_config_prefix),l(n.NVM_BIN)?c.dirname(l(n.NVM_BIN)):null,c.dirname(c.dirname(t)),e==="win32"?l(n.APPDATA):null,e==="win32"?l(n.LOCALAPPDATA):null,e!=="win32"?c.join(o,".local"):null,e!=="win32"?"/usr/local":null,e!=="win32"?"/usr":null]);return w(i.flatMap(r=>_(r,e,c)))}function P(n,e,o,t){const c=g(n,e,t);for(const i of c){const r=m(i,e,o,t);if(r)return r}return null}function g(n,e,o){const t=[];let c=C(n)??n;c=o.dirname(c);for(let i=0;i<8;i+=1){o.basename(c)==="codex"&&o.basename(o.dirname(c))==="@openai"&&t.push(c),t.push(..._(c,e,o));const r=o.dirname(c);if(r===c)break;c=r}return w(t)}function _(n,e,o){return e==="win32"?[o.join(n,"node_modules","@openai","codex")]:[o.join(n,"lib","node_modules","@openai","codex"),o.join(n,"node_modules","@openai","codex")]}function m(n,e,o,t){if(!L(n))return null;const c=`codex-${e}-${o==="x64"?"x64":o}`,i=t.join(n,"node_modules","@openai",c);return j(i,e,t)??j(n,e,t)}function j(n,e,o,t=0){if(t>8||!L(n))return null;let c;try{c=d.readdirSync(n,{withFileTypes:!0})}catch{return null}const i=e==="win32"?"codex.exe":"codex";for(const r of c){const s=o.join(n,r.name);if(r.isFile()&&r.name.toLowerCase()===i&&b(s,e)&&!N(s))return s}for(const r of c){if(!r.isDirectory())continue;const s=j(o.join(n,r.name),e,o,t+1);if(s)return s}return null}function D(n,e,o,t){if(t.isAbsolute(n)||n.includes("/")||n.includes("\\"))return b(n,o)?n:null;const c=o==="win32"?n.includes(".")?[""]:(e.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";").map(r=>r.toLowerCase()):[""],i=o==="win32"?";":":";for(const r of(e.PATH||"").split(i)){const s=l(r);if(s)for(const f of c){const a=t.join(s,`${n}${f}`);if(b(a,o))return a}}return null}function b(n,e){try{return d.accessSync(n,e==="win32"?d.constants.F_OK:d.constants.X_OK),d.statSync(n).isFile()}catch{return!1}}function L(n){try{return d.statSync(n).isDirectory()}catch{return!1}}function N(n){const e=C(n)??n;if(/\.(?:js|mjs|cjs|cmd|bat)$/i.test(e))return!0;try{const o=d.readFileSync(e,{encoding:"utf8",flag:"r"}).slice(0,256);return/^#!.*\bnode\b/m.test(o)}catch{return!1}}function C(n){try{return d.realpathSync(n)}catch{return null}}function l(n){return n?.trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2")||null}function w(n){return[...new Set(n.filter(e=>e!=null))]}export{k as resolveCodexPath};
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import { acpChildEnvironment } from "../../../core/process-identity.js";
|
|
4
|
-
export function startCodexAppServer(cwd) {
|
|
5
|
-
const command = resolveCodexPath();
|
|
6
|
-
const args = ["app-server", "--stdio"];
|
|
7
|
-
const child = spawn(command, args, {
|
|
8
|
-
cwd,
|
|
9
|
-
env: acpChildEnvironment({ CODEX_PATH: command }),
|
|
10
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
11
|
-
});
|
|
12
|
-
child.stdout.setEncoding("utf8");
|
|
13
|
-
child.stderr.setEncoding("utf8");
|
|
14
|
-
return { command, args, child };
|
|
15
|
-
}
|
|
16
|
-
export function resolveCodexPath() {
|
|
17
|
-
const explicit = process.env.CODEX_PATH;
|
|
18
|
-
if (explicit?.trim() && !isNodeWrapperCodexPath(explicit))
|
|
19
|
-
return explicit;
|
|
20
|
-
const nativeCandidates = [
|
|
21
|
-
"/usr/local/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin/codex"
|
|
22
|
-
];
|
|
23
|
-
const native = nativeCandidates.find((candidate) => isExecutableFile(candidate));
|
|
24
|
-
if (native)
|
|
25
|
-
return native;
|
|
26
|
-
const fallbackCandidates = [
|
|
27
|
-
...(explicit?.trim() ? [explicit] : []),
|
|
28
|
-
"/usr/local/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin/codex",
|
|
29
|
-
"/usr/local/bin/codex",
|
|
30
|
-
"codex"
|
|
31
|
-
];
|
|
32
|
-
return fallbackCandidates.find((candidate) => candidate === "codex" || isExecutableFile(candidate)) ?? "codex";
|
|
33
|
-
}
|
|
34
|
-
function isExecutableFile(filePath) {
|
|
35
|
-
try {
|
|
36
|
-
fs.accessSync(filePath, fs.constants.X_OK);
|
|
37
|
-
return fs.statSync(filePath).isFile();
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function isNodeWrapperCodexPath(filePath) {
|
|
44
|
-
try {
|
|
45
|
-
const realPath = fs.realpathSync(filePath);
|
|
46
|
-
return realPath.endsWith(".js");
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
import{spawn as p}from"node:child_process";import{acpChildEnvironment as n}from"../../../core/process-identity.js";import{resolveCodexPath as s}from"./codex-path.js";import{resolveCodexPath as v}from"./codex-path.js";function c(r){const o=s(),e=["app-server","--stdio"],t=p(o,e,{cwd:r,env:n({CODEX_PATH:o}),stdio:["pipe","pipe","pipe"]});return t.stdout.setEncoding("utf8"),t.stderr.setEncoding("utf8"),{command:o,args:e,child:t}}export{v as resolveCodexPath,c as startCodexAppServer};
|