u-foo 1.9.7 → 2.1.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/bin/ufoo.js +5 -3
- package/package.json +2 -4
- package/src/agent/claudeEventTranslator.js +267 -0
- package/src/agent/claudeOauthTokenReader.js +52 -0
- package/src/agent/claudeThreadProvider.js +343 -0
- package/src/agent/cliRunner.js +10 -16
- package/src/agent/codexEventTranslator.js +78 -0
- package/src/agent/codexThreadProvider.js +181 -0
- package/src/agent/controllerToolExecutor.js +233 -0
- package/src/agent/credentials/claude.js +324 -0
- package/src/agent/credentials/codex.js +203 -0
- package/src/agent/credentials/index.js +106 -0
- package/src/agent/internalRunner.js +348 -3
- package/src/agent/loopObservability.js +190 -0
- package/src/agent/loopRuntime.js +457 -0
- package/src/agent/ptyRunner.js +8 -7
- package/src/agent/ufooAgent.js +178 -120
- package/src/agent/upstreamTransport.js +464 -0
- package/src/bus/utils.js +3 -2
- package/src/chat/dashboardView.js +51 -1
- package/src/chat/index.js +3 -1
- package/src/config.js +53 -17
- package/src/controller/flags.js +160 -0
- package/src/controller/gateRouter.js +201 -0
- package/src/controller/routerFastPath.js +22 -0
- package/src/controller/shadowGuard.js +280 -0
- package/src/daemon/index.js +2 -3
- package/src/daemon/promptLoop.js +33 -224
- package/src/daemon/promptRequest.js +360 -5
- package/src/daemon/status.js +2 -0
- package/src/history/inputTimeline.js +9 -4
- package/src/memory/index.js +24 -0
- package/src/providerapi/redactor.js +87 -0
- package/src/providerapi/shadowDiff.js +174 -0
- package/src/report/store.js +4 -3
- package/src/tools/handlers/ackBus.js +26 -0
- package/src/tools/handlers/common.js +64 -0
- package/src/tools/handlers/dispatchMessage.js +81 -0
- package/src/tools/handlers/listAgents.js +14 -0
- package/src/tools/handlers/readBusSummary.js +34 -0
- package/src/tools/handlers/readOpenDecisions.js +26 -0
- package/src/tools/handlers/readProjectRegistry.js +20 -0
- package/src/tools/handlers/readPromptHistory.js +123 -0
- package/src/tools/handlers/tier2.js +134 -0
- package/src/tools/index.js +55 -0
- package/src/tools/registry.js +69 -0
- package/src/tools/schemaFixtures.js +415 -0
- package/src/tools/tier0/listAgents.js +14 -0
- package/src/tools/tier0/readBusSummary.js +14 -0
- package/src/tools/tier0/readOpenDecisions.js +14 -0
- package/src/tools/tier0/readProjectRegistry.js +14 -0
- package/src/tools/tier0/readPromptHistory.js +14 -0
- package/src/tools/tier1/ackBus.js +14 -0
- package/src/tools/tier1/dispatchMessage.js +14 -0
- package/src/tools/tier1/routeAgent.js +14 -0
- package/src/tools/tier2/closeAgent.js +14 -0
- package/src/tools/tier2/launchAgent.js +14 -0
- package/src/tools/tier2/manageCron.js +14 -0
- package/src/tools/tier2/renameAgent.js +14 -0
- package/src/tools/types.js +75 -0
- package/src/tools/unimplemented.js +13 -0
- package/src/ufoo/paths.js +4 -0
- package/bin/ufoo-assistant-agent.js +0 -5
- package/bin/ufoo-engine.js +0 -25
- package/src/assistant/agent.js +0 -261
- package/src/assistant/bridge.js +0 -178
- package/src/assistant/constants.js +0 -15
- package/src/assistant/engine.js +0 -252
- package/src/assistant/stdio.js +0 -58
- package/src/assistant/ufooEngineCli.js +0 -312
package/src/assistant/bridge.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
const { spawn } = require("child_process");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const {
|
|
4
|
-
DEFAULT_ASSISTANT_TIMEOUT_MS,
|
|
5
|
-
DEFAULT_ASSISTANT_TIMEOUT_GRACE_MS,
|
|
6
|
-
normalizeAssistantTimeoutMs,
|
|
7
|
-
} = require("./constants");
|
|
8
|
-
|
|
9
|
-
function resolveAssistantCommand() {
|
|
10
|
-
const raw = String(process.env.UFOO_ASSISTANT_CMD || "ufoo-assistant-agent").trim();
|
|
11
|
-
if (!raw || raw === "ufoo-assistant-agent") {
|
|
12
|
-
return {
|
|
13
|
-
command: process.execPath,
|
|
14
|
-
args: [path.resolve(__dirname, "../../bin/ufoo-assistant-agent.js")],
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const parts = raw.split(/\s+/).filter(Boolean);
|
|
18
|
-
if (parts.length === 0) {
|
|
19
|
-
return {
|
|
20
|
-
command: process.execPath,
|
|
21
|
-
args: [path.resolve(__dirname, "../../bin/ufoo-assistant-agent.js")],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
return { command: parts[0], args: parts.slice(1) };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function parseAssistantOutput(stdout) {
|
|
28
|
-
const text = String(stdout || "").trim();
|
|
29
|
-
if (!text) return null;
|
|
30
|
-
try {
|
|
31
|
-
return JSON.parse(text);
|
|
32
|
-
} catch {
|
|
33
|
-
// Continue to line-based fallback.
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const lines = text.split(/\r?\n/).filter(Boolean);
|
|
37
|
-
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
38
|
-
try {
|
|
39
|
-
return JSON.parse(lines[i]);
|
|
40
|
-
} catch {
|
|
41
|
-
// ignore malformed line
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function normalizeResponse(parsed, fallbackError = "") {
|
|
48
|
-
if (!parsed || typeof parsed !== "object") {
|
|
49
|
-
return {
|
|
50
|
-
ok: false,
|
|
51
|
-
summary: "",
|
|
52
|
-
artifacts: [],
|
|
53
|
-
logs: [],
|
|
54
|
-
error: fallbackError || "assistant returned invalid JSON",
|
|
55
|
-
metrics: {},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
ok: parsed.ok !== false,
|
|
61
|
-
summary: typeof parsed.summary === "string" ? parsed.summary : "",
|
|
62
|
-
artifacts: Array.isArray(parsed.artifacts) ? parsed.artifacts : [],
|
|
63
|
-
logs: Array.isArray(parsed.logs) ? parsed.logs : [],
|
|
64
|
-
error: typeof parsed.error === "string" ? parsed.error : "",
|
|
65
|
-
metrics: parsed.metrics && typeof parsed.metrics === "object" ? parsed.metrics : {},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function runAssistantTask({
|
|
70
|
-
projectRoot,
|
|
71
|
-
provider = "",
|
|
72
|
-
fallbackProvider = "",
|
|
73
|
-
model = "",
|
|
74
|
-
task = "",
|
|
75
|
-
kind = "mixed",
|
|
76
|
-
context = "",
|
|
77
|
-
expect = "",
|
|
78
|
-
timeoutMs = DEFAULT_ASSISTANT_TIMEOUT_MS,
|
|
79
|
-
} = {}) {
|
|
80
|
-
return new Promise((resolve) => {
|
|
81
|
-
const startedAt = Date.now();
|
|
82
|
-
const effectiveTimeoutMs = normalizeAssistantTimeoutMs(timeoutMs, DEFAULT_ASSISTANT_TIMEOUT_MS);
|
|
83
|
-
const { command, args } = resolveAssistantCommand();
|
|
84
|
-
const payload = {
|
|
85
|
-
request_id: `assistant-${startedAt}`,
|
|
86
|
-
project_root: projectRoot,
|
|
87
|
-
provider,
|
|
88
|
-
fallback_provider: fallbackProvider,
|
|
89
|
-
model,
|
|
90
|
-
task,
|
|
91
|
-
kind,
|
|
92
|
-
context,
|
|
93
|
-
expect,
|
|
94
|
-
timeout_ms: effectiveTimeoutMs,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const child = spawn(command, args, {
|
|
98
|
-
cwd: projectRoot,
|
|
99
|
-
env: { ...process.env, UFOO_ASSISTANT_MODE: "private" },
|
|
100
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
let stdout = "";
|
|
104
|
-
let stderr = "";
|
|
105
|
-
let settled = false;
|
|
106
|
-
const finish = (result) => {
|
|
107
|
-
if (settled) return;
|
|
108
|
-
settled = true;
|
|
109
|
-
resolve(result);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const timer = setTimeout(() => {
|
|
113
|
-
try {
|
|
114
|
-
child.kill("SIGTERM");
|
|
115
|
-
} catch {
|
|
116
|
-
// ignore
|
|
117
|
-
}
|
|
118
|
-
finish({
|
|
119
|
-
ok: false,
|
|
120
|
-
summary: "",
|
|
121
|
-
artifacts: [],
|
|
122
|
-
logs: [],
|
|
123
|
-
error: "assistant timeout",
|
|
124
|
-
metrics: { duration_ms: Date.now() - startedAt },
|
|
125
|
-
});
|
|
126
|
-
}, effectiveTimeoutMs + DEFAULT_ASSISTANT_TIMEOUT_GRACE_MS);
|
|
127
|
-
|
|
128
|
-
child.on("error", (err) => {
|
|
129
|
-
clearTimeout(timer);
|
|
130
|
-
finish({
|
|
131
|
-
ok: false,
|
|
132
|
-
summary: "",
|
|
133
|
-
artifacts: [],
|
|
134
|
-
logs: [],
|
|
135
|
-
error: err && err.message ? err.message : "assistant spawn failed",
|
|
136
|
-
metrics: { duration_ms: Date.now() - startedAt },
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
child.stdout.on("data", (chunk) => {
|
|
141
|
-
stdout += chunk.toString("utf8");
|
|
142
|
-
});
|
|
143
|
-
child.stderr.on("data", (chunk) => {
|
|
144
|
-
stderr += chunk.toString("utf8");
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
child.on("close", (code) => {
|
|
148
|
-
clearTimeout(timer);
|
|
149
|
-
const parsed = parseAssistantOutput(stdout);
|
|
150
|
-
const fallbackError = code === 0
|
|
151
|
-
? ""
|
|
152
|
-
: (stderr || `assistant exited with code ${code}`);
|
|
153
|
-
const normalized = normalizeResponse(parsed, fallbackError);
|
|
154
|
-
normalized.metrics = {
|
|
155
|
-
...normalized.metrics,
|
|
156
|
-
duration_ms: Date.now() - startedAt,
|
|
157
|
-
};
|
|
158
|
-
if (!normalized.ok && !normalized.error) {
|
|
159
|
-
normalized.error = fallbackError || "assistant failed";
|
|
160
|
-
}
|
|
161
|
-
finish(normalized);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
child.stdin.write(`${JSON.stringify(payload)}\n`);
|
|
166
|
-
child.stdin.end();
|
|
167
|
-
} catch {
|
|
168
|
-
// stdin may already be closed.
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
module.exports = {
|
|
174
|
-
runAssistantTask,
|
|
175
|
-
parseAssistantOutput,
|
|
176
|
-
normalizeResponse,
|
|
177
|
-
resolveAssistantCommand,
|
|
178
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const DEFAULT_ASSISTANT_TIMEOUT_MS = 600000; // 10 minutes
|
|
2
|
-
const DEFAULT_ASSISTANT_TIMEOUT_GRACE_MS = 5000;
|
|
3
|
-
|
|
4
|
-
function normalizeAssistantTimeoutMs(value, fallback = DEFAULT_ASSISTANT_TIMEOUT_MS) {
|
|
5
|
-
const parsed = Number(value);
|
|
6
|
-
const base = Number.isFinite(parsed) ? parsed : fallback;
|
|
7
|
-
if (!Number.isFinite(base)) return DEFAULT_ASSISTANT_TIMEOUT_MS;
|
|
8
|
-
return Math.max(1000, Math.floor(base));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
DEFAULT_ASSISTANT_TIMEOUT_MS,
|
|
13
|
-
DEFAULT_ASSISTANT_TIMEOUT_GRACE_MS,
|
|
14
|
-
normalizeAssistantTimeoutMs,
|
|
15
|
-
};
|
package/src/assistant/engine.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
const { spawn } = require("child_process");
|
|
2
|
-
const { loadConfig, normalizeAssistantEngine } = require("../config");
|
|
3
|
-
const { DEFAULT_ASSISTANT_TIMEOUT_MS, normalizeAssistantTimeoutMs } = require("./constants");
|
|
4
|
-
|
|
5
|
-
function splitCommand(raw, fallback = "ufoo-engine") {
|
|
6
|
-
const text = String(raw || "").trim();
|
|
7
|
-
if (!text) return { command: fallback, args: [] };
|
|
8
|
-
const parts = text.split(/\s+/).filter(Boolean);
|
|
9
|
-
if (parts.length === 0) return { command: fallback, args: [] };
|
|
10
|
-
return { command: parts[0], args: parts.slice(1) };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function resolveAssistantEngine({
|
|
14
|
-
projectRoot,
|
|
15
|
-
requestedProvider = "",
|
|
16
|
-
requestedModel = "",
|
|
17
|
-
fallbackProvider = "",
|
|
18
|
-
} = {}) {
|
|
19
|
-
const config = loadConfig(projectRoot);
|
|
20
|
-
|
|
21
|
-
const requested = normalizeAssistantEngine(requestedProvider);
|
|
22
|
-
const fallback = normalizeAssistantEngine(fallbackProvider) || "codex";
|
|
23
|
-
|
|
24
|
-
let selected = requested;
|
|
25
|
-
// Omitted/auto assistant providers inherit the active ufoo-agent provider.
|
|
26
|
-
if (selected === "auto") selected = fallback;
|
|
27
|
-
if (selected === "auto") selected = "codex";
|
|
28
|
-
|
|
29
|
-
const model =
|
|
30
|
-
String(requestedModel || "").trim()
|
|
31
|
-
|| String(process.env.UFOO_ASSISTANT_MODEL || "").trim()
|
|
32
|
-
|| String(config.assistantModel || "").trim()
|
|
33
|
-
|| "";
|
|
34
|
-
|
|
35
|
-
if (selected === "claude") {
|
|
36
|
-
return {
|
|
37
|
-
engine: "claude",
|
|
38
|
-
kind: "cli",
|
|
39
|
-
provider: "claude-cli",
|
|
40
|
-
model,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (selected === "ufoo") {
|
|
45
|
-
const { command, args } = splitCommand(
|
|
46
|
-
process.env.UFOO_ASSISTANT_UFOO_CMD || config.assistantUfooCmd,
|
|
47
|
-
"ufoo-engine"
|
|
48
|
-
);
|
|
49
|
-
return {
|
|
50
|
-
engine: "ufoo",
|
|
51
|
-
kind: "external",
|
|
52
|
-
command,
|
|
53
|
-
args,
|
|
54
|
-
model,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
engine: "codex",
|
|
60
|
-
kind: "cli",
|
|
61
|
-
provider: "codex-cli",
|
|
62
|
-
model,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function parseEngineJson(stdout) {
|
|
67
|
-
const text = String(stdout || "").trim();
|
|
68
|
-
if (!text) return null;
|
|
69
|
-
try {
|
|
70
|
-
return JSON.parse(text);
|
|
71
|
-
} catch {
|
|
72
|
-
// continue to line fallback
|
|
73
|
-
}
|
|
74
|
-
const lines = text.split(/\r?\n/).filter(Boolean);
|
|
75
|
-
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
76
|
-
try {
|
|
77
|
-
return JSON.parse(lines[i]);
|
|
78
|
-
} catch {
|
|
79
|
-
// ignore bad lines
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function isUnsupportedArgError(errText) {
|
|
86
|
-
const text = String(errText || "").toLowerCase();
|
|
87
|
-
return text.includes("unknown option")
|
|
88
|
-
|| text.includes("unknown argument")
|
|
89
|
-
|| text.includes("unexpected argument")
|
|
90
|
-
|| text.includes("unrecognized option");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function buildExternalEngineArgs(engine = {}, payload = {}) {
|
|
94
|
-
const args = Array.isArray(engine.args) ? [...engine.args] : [];
|
|
95
|
-
args.push("--assistant-task", "--json");
|
|
96
|
-
if (payload.model) args.push("--model", String(payload.model));
|
|
97
|
-
if (payload.session_id) args.push("--session-id", String(payload.session_id));
|
|
98
|
-
if (payload.project_root) args.push("--cwd", String(payload.project_root));
|
|
99
|
-
if (payload.kind) args.push("--kind", String(payload.kind));
|
|
100
|
-
if (payload.context) args.push("--context", String(payload.context));
|
|
101
|
-
if (payload.expect) args.push("--expect", String(payload.expect));
|
|
102
|
-
if (Number.isFinite(payload.timeout_ms)) {
|
|
103
|
-
args.push("--timeout-ms", String(normalizeAssistantTimeoutMs(payload.timeout_ms)));
|
|
104
|
-
}
|
|
105
|
-
args.push(String(payload.task || ""));
|
|
106
|
-
return args;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function extractSessionId(parsed) {
|
|
110
|
-
if (!parsed || typeof parsed !== "object") return "";
|
|
111
|
-
return String(parsed.session_id || parsed.sessionId || parsed.session || "").trim();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function runExternalAssistantEngine({
|
|
115
|
-
engine,
|
|
116
|
-
payload,
|
|
117
|
-
timeoutMs = DEFAULT_ASSISTANT_TIMEOUT_MS,
|
|
118
|
-
}) {
|
|
119
|
-
const startedAt = Date.now();
|
|
120
|
-
const effectiveTimeoutMs = normalizeAssistantTimeoutMs(timeoutMs, DEFAULT_ASSISTANT_TIMEOUT_MS);
|
|
121
|
-
|
|
122
|
-
const runAttempt = (attempt = {}) => new Promise((resolve) => {
|
|
123
|
-
const child = spawn(engine.command, attempt.args || [], {
|
|
124
|
-
cwd: payload.project_root || process.cwd(),
|
|
125
|
-
env: { ...process.env, UFOO_ASSISTANT_ENGINE: engine.engine || "ufoo" },
|
|
126
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
let stdout = "";
|
|
130
|
-
let stderr = "";
|
|
131
|
-
let settled = false;
|
|
132
|
-
const finish = (result) => {
|
|
133
|
-
if (settled) return;
|
|
134
|
-
settled = true;
|
|
135
|
-
resolve(result);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const timer = setTimeout(() => {
|
|
139
|
-
try {
|
|
140
|
-
child.kill("SIGTERM");
|
|
141
|
-
} catch {
|
|
142
|
-
// ignore
|
|
143
|
-
}
|
|
144
|
-
finish({
|
|
145
|
-
ok: false,
|
|
146
|
-
mode: attempt.mode,
|
|
147
|
-
code: -1,
|
|
148
|
-
stdout,
|
|
149
|
-
stderr,
|
|
150
|
-
error: "assistant engine timeout",
|
|
151
|
-
});
|
|
152
|
-
}, effectiveTimeoutMs);
|
|
153
|
-
|
|
154
|
-
child.on("error", (err) => {
|
|
155
|
-
clearTimeout(timer);
|
|
156
|
-
finish({
|
|
157
|
-
ok: false,
|
|
158
|
-
mode: attempt.mode,
|
|
159
|
-
code: -1,
|
|
160
|
-
stdout,
|
|
161
|
-
stderr,
|
|
162
|
-
error: err && err.message ? err.message : "assistant engine spawn failed",
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
child.stdout.on("data", (chunk) => {
|
|
167
|
-
stdout += chunk.toString("utf8");
|
|
168
|
-
});
|
|
169
|
-
child.stderr.on("data", (chunk) => {
|
|
170
|
-
stderr += chunk.toString("utf8");
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
child.on("close", (code) => {
|
|
174
|
-
clearTimeout(timer);
|
|
175
|
-
finish({
|
|
176
|
-
ok: code === 0,
|
|
177
|
-
mode: attempt.mode,
|
|
178
|
-
code,
|
|
179
|
-
stdout,
|
|
180
|
-
stderr,
|
|
181
|
-
error: "",
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
if (attempt.input) child.stdin.write(attempt.input);
|
|
187
|
-
child.stdin.end();
|
|
188
|
-
} catch {
|
|
189
|
-
// ignore stdin errors
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
const argsAttempt = {
|
|
194
|
-
mode: "args",
|
|
195
|
-
args: buildExternalEngineArgs(engine, payload),
|
|
196
|
-
input: "",
|
|
197
|
-
};
|
|
198
|
-
let result = await runAttempt(argsAttempt);
|
|
199
|
-
|
|
200
|
-
if (!result.ok && isUnsupportedArgError(result.stderr || result.stdout || result.error)) {
|
|
201
|
-
result = await runAttempt({
|
|
202
|
-
mode: "stdin-json",
|
|
203
|
-
args: Array.isArray(engine.args) ? [...engine.args] : [],
|
|
204
|
-
input: `${JSON.stringify(payload)}\n`,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const parsed = parseEngineJson(result.stdout);
|
|
209
|
-
if (parsed && typeof parsed === "object") {
|
|
210
|
-
return {
|
|
211
|
-
...parsed,
|
|
212
|
-
sessionId: extractSessionId(parsed),
|
|
213
|
-
metrics: {
|
|
214
|
-
...(parsed.metrics && typeof parsed.metrics === "object" ? parsed.metrics : {}),
|
|
215
|
-
duration_ms: Date.now() - startedAt,
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (result.ok) {
|
|
221
|
-
const summary = String(result.stdout || "").trim();
|
|
222
|
-
return {
|
|
223
|
-
ok: true,
|
|
224
|
-
summary,
|
|
225
|
-
artifacts: [],
|
|
226
|
-
logs: [],
|
|
227
|
-
error: "",
|
|
228
|
-
sessionId: "",
|
|
229
|
-
metrics: { duration_ms: Date.now() - startedAt },
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return {
|
|
234
|
-
ok: false,
|
|
235
|
-
summary: "",
|
|
236
|
-
artifacts: [],
|
|
237
|
-
logs: [],
|
|
238
|
-
error: String(result.stderr || result.stdout || result.error || `assistant engine exited with code ${result.code}`).trim(),
|
|
239
|
-
sessionId: "",
|
|
240
|
-
metrics: { duration_ms: Date.now() - startedAt },
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
module.exports = {
|
|
245
|
-
resolveAssistantEngine,
|
|
246
|
-
runExternalAssistantEngine,
|
|
247
|
-
parseEngineJson,
|
|
248
|
-
splitCommand,
|
|
249
|
-
buildExternalEngineArgs,
|
|
250
|
-
isUnsupportedArgError,
|
|
251
|
-
extractSessionId,
|
|
252
|
-
};
|
package/src/assistant/stdio.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const { runAssistantAgentTask } = require("./agent");
|
|
2
|
-
|
|
3
|
-
function readStdin() {
|
|
4
|
-
return new Promise((resolve) => {
|
|
5
|
-
let data = "";
|
|
6
|
-
process.stdin.setEncoding("utf8");
|
|
7
|
-
process.stdin.on("data", (chunk) => {
|
|
8
|
-
data += chunk;
|
|
9
|
-
});
|
|
10
|
-
process.stdin.on("end", () => resolve(data));
|
|
11
|
-
process.stdin.resume();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function runAssistantStdio() {
|
|
16
|
-
const startedAt = Date.now();
|
|
17
|
-
try {
|
|
18
|
-
const input = await readStdin();
|
|
19
|
-
const line = String(input || "")
|
|
20
|
-
.split(/\r?\n/)
|
|
21
|
-
.map((part) => part.trim())
|
|
22
|
-
.find(Boolean);
|
|
23
|
-
|
|
24
|
-
if (!line) {
|
|
25
|
-
process.stdout.write(
|
|
26
|
-
`${JSON.stringify({
|
|
27
|
-
ok: false,
|
|
28
|
-
summary: "",
|
|
29
|
-
artifacts: [],
|
|
30
|
-
logs: [],
|
|
31
|
-
error: "missing request payload",
|
|
32
|
-
metrics: { duration_ms: Date.now() - startedAt },
|
|
33
|
-
})}\n`
|
|
34
|
-
);
|
|
35
|
-
process.exitCode = 1;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const payload = JSON.parse(line);
|
|
40
|
-
const result = await runAssistantAgentTask(payload);
|
|
41
|
-
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
42
|
-
process.exitCode = result.ok ? 0 : 1;
|
|
43
|
-
} catch (err) {
|
|
44
|
-
process.stdout.write(
|
|
45
|
-
`${JSON.stringify({
|
|
46
|
-
ok: false,
|
|
47
|
-
summary: "",
|
|
48
|
-
artifacts: [],
|
|
49
|
-
logs: [],
|
|
50
|
-
error: err && err.message ? err.message : "assistant stdio failed",
|
|
51
|
-
metrics: { duration_ms: Date.now() - startedAt },
|
|
52
|
-
})}\n`
|
|
53
|
-
);
|
|
54
|
-
process.exitCode = 1;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = { runAssistantStdio };
|