@botbotgo/agent-harness 0.0.475 → 0.0.476
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/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
package/dist/cli/main.js
CHANGED
|
@@ -1,429 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import { isTopLevelCliCommand, parseChatOptions, parseInitOptions, parseTopLevelManagedServiceOptions, renderUsage, } from "./options.js";
|
|
24
|
-
import { resolveCliWorkspaceRoot, validateCliWorkspaceRoot, } from "./workspace.js";
|
|
25
|
-
export { renderChatBanner, renderChatPromptLine } from "./chat-ui.js";
|
|
26
|
-
export { probeChatWorkspace, renderChatRuntimeFailure } from "./chat-workspace.js";
|
|
27
|
-
async function stopClientWithTimeout(client, stderr, timeoutMs = 5000) {
|
|
28
|
-
if (!client) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
let timeoutHandle;
|
|
32
|
-
try {
|
|
33
|
-
await Promise.race([
|
|
34
|
-
client.stop(),
|
|
35
|
-
new Promise((_, reject) => {
|
|
36
|
-
timeoutHandle = setTimeout(() => {
|
|
37
|
-
reject(new Error(`Timed out after ${timeoutMs}ms while stopping the chat client.`));
|
|
38
|
-
}, timeoutMs);
|
|
39
|
-
}),
|
|
40
|
-
]);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
44
|
-
if (!/^Timed out after \d+ms while stopping the chat client\.$/.test(message)) {
|
|
45
|
-
stderr(`${message}\n`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
if (timeoutHandle) {
|
|
50
|
-
clearTimeout(timeoutHandle);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export { installChatSubprocessExitGuard, isChatServerNoiseLine } from "./process-guards.js";
|
|
55
|
-
function isObject(value) {
|
|
56
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57
|
-
}
|
|
58
|
-
function formatTimestamp(value) {
|
|
59
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
60
|
-
}
|
|
61
|
-
function renderPlanResultSummary(result) {
|
|
62
|
-
if (typeof result === "string" && result.trim().length > 0) {
|
|
63
|
-
return result.trim();
|
|
64
|
-
}
|
|
65
|
-
if (!isObject(result)) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
const summary = typeof result.summary === "string" && result.summary.trim().length > 0
|
|
69
|
-
? result.summary.trim()
|
|
70
|
-
: typeof result.message === "string" && result.message.trim().length > 0
|
|
71
|
-
? result.message.trim()
|
|
72
|
-
: undefined;
|
|
73
|
-
if (summary) {
|
|
74
|
-
return summary;
|
|
75
|
-
}
|
|
76
|
-
const serialized = JSON.stringify(result);
|
|
77
|
-
return serialized && serialized !== "{}" ? serialized : undefined;
|
|
78
|
-
}
|
|
79
|
-
function renderChatPlanState(planState) {
|
|
80
|
-
const lines = [`[plan v${planState.version}] ${planState.summary.total} todo(s)`];
|
|
81
|
-
if (planState.summary.total === 0) {
|
|
82
|
-
lines.push("No todos tracked yet.");
|
|
83
|
-
return `${lines.join("\n")}\n`;
|
|
84
|
-
}
|
|
85
|
-
for (const [index, item] of planState.items.entries()) {
|
|
86
|
-
lines.push(`${index + 1}. [${item.status}] ${item.content}`);
|
|
87
|
-
const resultSummary = renderPlanResultSummary(item.result);
|
|
88
|
-
if (resultSummary) {
|
|
89
|
-
lines.push(` result: ${resultSummary}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return `${lines.join("\n")}\n`;
|
|
93
|
-
}
|
|
94
|
-
export async function runCli(argv, io = {}, deps = {}) {
|
|
95
|
-
const cwd = io.cwd ?? process.cwd();
|
|
96
|
-
const stdin = io.stdin ?? process.stdin;
|
|
97
|
-
const stdout = io.stdout ?? ((message) => process.stdout.write(message));
|
|
98
|
-
const stderr = io.stderr ?? ((message) => process.stderr.write(message));
|
|
99
|
-
const stdoutStream = io.stdout === undefined ? process.stdout : undefined;
|
|
100
|
-
const stderrStream = io.stderr === undefined ? process.stderr : undefined;
|
|
101
|
-
const [command, projectName, ...rest] = argv;
|
|
102
|
-
const probeWorkspace = deps.probeChatWorkspace ?? probeChatWorkspace;
|
|
103
|
-
const createChatLineReader = deps.createReadlineInterface ?? createReadlineInterface;
|
|
104
|
-
const createHarness = deps.createAgentHarness ?? createAgentHarness;
|
|
105
|
-
const serveA2a = deps.serveA2aOverHttp ?? serveA2aOverHttp;
|
|
106
|
-
const serveAgUi = deps.serveAgUiOverHttp ?? serveAgUiOverHttp;
|
|
107
|
-
const serveAcpHttp = deps.serveAcpOverHttp ?? serveAcpOverHttp;
|
|
108
|
-
const serveAcp = deps.serveAcpOverStdio ?? serveAcpOverStdio;
|
|
109
|
-
const serveRuntimeMcp = deps.serveRuntimeMcpOverStdio ?? serveRuntimeMcpOverStdio;
|
|
110
|
-
const serveRuntimeMcpStreamableHttp = deps.serveRuntimeMcpOverStreamableHttp ?? serveRuntimeMcpOverStreamableHttp;
|
|
111
|
-
const spawnManagedCliProcess = deps.spawnManagedCliProcess ?? defaultSpawnManagedCliProcess;
|
|
112
|
-
const isManagedProcessRunning = deps.isManagedProcessRunning ?? defaultIsManagedProcessRunning;
|
|
113
|
-
const signalManagedProcess = deps.signalManagedProcess ?? defaultSignalManagedProcess;
|
|
114
|
-
const createChatClient = deps.createChatClient ?? (async (input) => {
|
|
115
|
-
if (input.transport === "http") {
|
|
116
|
-
return createAcpHttpHarnessClient({
|
|
117
|
-
rpcUrl: `http://${input.hostname ?? "127.0.0.1"}:${input.port ?? 8787}/rpc`,
|
|
118
|
-
eventsUrl: `http://${input.hostname ?? "127.0.0.1"}:${input.port ?? 8787}/events`,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (deps.createAgentHarness) {
|
|
122
|
-
const runtime = await createHarness(input.workspaceRoot);
|
|
123
|
-
return createInProcessHarnessClient(runtime);
|
|
124
|
-
}
|
|
125
|
-
return createAgentHarnessClient(input.workspaceRoot);
|
|
126
|
-
});
|
|
127
|
-
const executeChat = async (parsed) => {
|
|
128
|
-
const workspacePath = resolveCliWorkspaceRoot(cwd, parsed.workspaceRoot);
|
|
129
|
-
const workspaceError = validateCliWorkspaceRoot(workspacePath, parsed.workspaceRoot);
|
|
130
|
-
if (workspaceError) {
|
|
131
|
-
stderr(`${workspaceError}\n`);
|
|
132
|
-
return 1;
|
|
133
|
-
}
|
|
134
|
-
const workspaceModelInfo = readChatWorkspaceModelInfo(workspacePath, parsed.agentId);
|
|
135
|
-
const chatStdinStream = stdin;
|
|
136
|
-
let client;
|
|
137
|
-
let restoreWriteListenerGuard;
|
|
138
|
-
let restoreEmitterListenerGuard;
|
|
139
|
-
let restoreStderrNoiseFilter;
|
|
140
|
-
let restoreWarningFilter;
|
|
141
|
-
try {
|
|
142
|
-
restoreEmitterListenerGuard = installCliEmitterListenerGuard();
|
|
143
|
-
restoreStderrNoiseFilter = installCliStderrNoiseFilter(io.stderr === undefined);
|
|
144
|
-
restoreWarningFilter = installCliWarningFilter();
|
|
145
|
-
client = await createChatClient({
|
|
146
|
-
workspaceRoot: workspacePath,
|
|
147
|
-
transport: parsed.transport,
|
|
148
|
-
hostname: parsed.hostname,
|
|
149
|
-
port: parsed.port,
|
|
150
|
-
stderr,
|
|
151
|
-
});
|
|
152
|
-
restoreWriteListenerGuard = installCliWriteListenerGuard([stdoutStream, stderrStream]);
|
|
153
|
-
let activeAgentId = parsed.agentId;
|
|
154
|
-
let activeSessionId = parsed.sessionId;
|
|
155
|
-
let latestRequestId;
|
|
156
|
-
const useColor = false;
|
|
157
|
-
const preflightWarning = parsed.message
|
|
158
|
-
? undefined
|
|
159
|
-
: await probeWorkspace({
|
|
160
|
-
workspaceRoot: workspacePath,
|
|
161
|
-
agentId: activeAgentId,
|
|
162
|
-
});
|
|
163
|
-
if (parsed.message) {
|
|
164
|
-
await streamChatMessage({
|
|
165
|
-
client,
|
|
166
|
-
stdout,
|
|
167
|
-
stdoutStream,
|
|
168
|
-
stderr,
|
|
169
|
-
stderrStream,
|
|
170
|
-
agentId: activeAgentId,
|
|
171
|
-
sessionId: activeSessionId,
|
|
172
|
-
message: parsed.message,
|
|
173
|
-
modelInfo: workspaceModelInfo,
|
|
174
|
-
requestEvents: parsed.requestEvents,
|
|
175
|
-
liveRequestTree: parsed.requestEvents && chatStdinStream.isTTY === true,
|
|
176
|
-
colorRequestTree: useColor,
|
|
177
|
-
showToolResults: parsed.requestEvents,
|
|
178
|
-
showRunningState: false,
|
|
179
|
-
});
|
|
180
|
-
await stopClientWithTimeout(client, stderr);
|
|
181
|
-
restoreWriteListenerGuard?.();
|
|
182
|
-
restoreEmitterListenerGuard?.();
|
|
183
|
-
restoreStderrNoiseFilter?.();
|
|
184
|
-
restoreWarningFilter?.();
|
|
185
|
-
return 0;
|
|
186
|
-
}
|
|
187
|
-
stdout(renderChatBanner({
|
|
188
|
-
workspacePath,
|
|
189
|
-
transport: parsed.transport,
|
|
190
|
-
agentId: activeAgentId,
|
|
191
|
-
sessionId: activeSessionId,
|
|
192
|
-
color: useColor,
|
|
193
|
-
}));
|
|
194
|
-
if (preflightWarning) {
|
|
195
|
-
stdout(`${preflightWarning}\n\n`);
|
|
196
|
-
}
|
|
197
|
-
const stdoutSink = new Writable({
|
|
198
|
-
decodeStrings: false,
|
|
199
|
-
write(chunk, _encoding, callback) {
|
|
200
|
-
stdout(typeof chunk === "string" ? chunk : String(chunk));
|
|
201
|
-
callback();
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
const lineReader = createChatLineReader({
|
|
205
|
-
input: stdin,
|
|
206
|
-
output: stdoutSink,
|
|
207
|
-
crlfDelay: Infinity,
|
|
208
|
-
terminal: chatStdinStream.isTTY === true,
|
|
209
|
-
});
|
|
210
|
-
const interactiveState = await runInteractiveChatLoop({
|
|
211
|
-
client,
|
|
212
|
-
lineReader,
|
|
213
|
-
stdout,
|
|
214
|
-
stderr,
|
|
215
|
-
stdoutStream,
|
|
216
|
-
stderrStream,
|
|
217
|
-
workspacePath,
|
|
218
|
-
workspaceModelInfo,
|
|
219
|
-
requestEvents: parsed.requestEvents,
|
|
220
|
-
chatIsTty: chatStdinStream.isTTY === true,
|
|
221
|
-
useColor,
|
|
222
|
-
agentFilter: parsed.agentId,
|
|
223
|
-
activeAgentId,
|
|
224
|
-
activeSessionId,
|
|
225
|
-
});
|
|
226
|
-
await stopClientWithTimeout(client, stderr);
|
|
227
|
-
restoreWriteListenerGuard?.();
|
|
228
|
-
restoreEmitterListenerGuard?.();
|
|
229
|
-
restoreStderrNoiseFilter?.();
|
|
230
|
-
restoreWarningFilter?.();
|
|
231
|
-
return 0;
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
restoreWriteListenerGuard?.();
|
|
235
|
-
restoreEmitterListenerGuard?.();
|
|
236
|
-
restoreStderrNoiseFilter?.();
|
|
237
|
-
restoreWarningFilter?.();
|
|
238
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
239
|
-
stderr(`${message}\n`);
|
|
240
|
-
if (client) {
|
|
241
|
-
await stopClientWithTimeout(client, () => undefined);
|
|
242
|
-
}
|
|
243
|
-
return 1;
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
if (command === "init") {
|
|
247
|
-
if (!projectName?.trim()) {
|
|
248
|
-
stderr(renderUsage());
|
|
249
|
-
return 1;
|
|
250
|
-
}
|
|
251
|
-
const parsed = parseInitOptions(rest);
|
|
252
|
-
if (parsed.error) {
|
|
253
|
-
stderr(`${parsed.error}\n`);
|
|
254
|
-
stderr(renderUsage());
|
|
255
|
-
return 1;
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
const projectRoot = path.resolve(cwd, projectName);
|
|
259
|
-
const result = await initProject(projectRoot, projectName, parsed.options);
|
|
260
|
-
stdout(`Created ${result.projectSlug} at ${result.projectRoot}\n`);
|
|
261
|
-
stdout("Next steps:\n");
|
|
262
|
-
stdout(` cd ${projectName}\n`);
|
|
263
|
-
stdout(" npm install\n");
|
|
264
|
-
if ((parsed.options?.provider ?? "openai") === "openai") {
|
|
265
|
-
stdout(" export OPENAI_API_KEY=your_key_here\n");
|
|
266
|
-
}
|
|
267
|
-
stdout(' npm run start -- "Research a topic"\n');
|
|
268
|
-
return 0;
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
272
|
-
stderr(`${message}\n`);
|
|
273
|
-
return 1;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (command === "chat") {
|
|
277
|
-
const parsed = parseChatOptions([projectName, ...rest].filter((item) => typeof item === "string"));
|
|
278
|
-
if (parsed.error) {
|
|
279
|
-
stderr(`${parsed.error}\n`);
|
|
280
|
-
stderr(renderUsage());
|
|
281
|
-
return 1;
|
|
282
|
-
}
|
|
283
|
-
return executeChat(parsed);
|
|
284
|
-
}
|
|
285
|
-
const runManagedServiceLifecycle = async (lifecycle, rawArgs) => {
|
|
286
|
-
const parsed = parseTopLevelManagedServiceOptions(rawArgs);
|
|
287
|
-
if (parsed.error) {
|
|
288
|
-
stderr(`${parsed.error}\n`);
|
|
289
|
-
stderr(renderUsage());
|
|
290
|
-
return 1;
|
|
291
|
-
}
|
|
292
|
-
const startOrder = ["acp", "a2a", "mcp", "ag-ui"];
|
|
293
|
-
const stopOrder = ["ag-ui", "mcp", "a2a", "acp"];
|
|
294
|
-
const serviceOrder = lifecycle === "start" ? startOrder : stopOrder;
|
|
295
|
-
const selectedServices = serviceOrder.filter((service) => parsed.services.includes(service));
|
|
296
|
-
for (const service of selectedServices) {
|
|
297
|
-
const commandArgs = [
|
|
298
|
-
lifecycle,
|
|
299
|
-
"--workspace",
|
|
300
|
-
parsed.workspaceRoot ?? ".",
|
|
301
|
-
];
|
|
302
|
-
if (lifecycle === "start" && parsed.hostname) {
|
|
303
|
-
commandArgs.push("--host", parsed.hostname);
|
|
304
|
-
}
|
|
305
|
-
const resolvedPort = service === "acp"
|
|
306
|
-
? parsed.acpPort
|
|
307
|
-
: service === "a2a"
|
|
308
|
-
? parsed.a2aPort
|
|
309
|
-
: service === "mcp"
|
|
310
|
-
? parsed.mcpPort
|
|
311
|
-
: parsed.agUiPort;
|
|
312
|
-
if (lifecycle === "start" && typeof resolvedPort === "number") {
|
|
313
|
-
commandArgs.push("--port", String(resolvedPort));
|
|
314
|
-
}
|
|
315
|
-
const exitCode = service === "acp"
|
|
316
|
-
? await handleAcpCommand(commandArgs, { cwd, stderr }, {
|
|
317
|
-
createHarness,
|
|
318
|
-
serveAcp,
|
|
319
|
-
serveAcpHttp,
|
|
320
|
-
spawnManagedCliProcess,
|
|
321
|
-
isManagedProcessRunning,
|
|
322
|
-
signalManagedProcess,
|
|
323
|
-
serveA2a,
|
|
324
|
-
serveAgUi,
|
|
325
|
-
serveRuntimeMcp,
|
|
326
|
-
serveRuntimeMcpStreamableHttp,
|
|
327
|
-
})
|
|
328
|
-
: service === "a2a"
|
|
329
|
-
? await handleA2aCommand(commandArgs, { cwd, stderr }, {
|
|
330
|
-
createHarness,
|
|
331
|
-
serveA2a,
|
|
332
|
-
spawnManagedCliProcess,
|
|
333
|
-
isManagedProcessRunning,
|
|
334
|
-
signalManagedProcess,
|
|
335
|
-
})
|
|
336
|
-
: service === "mcp"
|
|
337
|
-
? await handleMcpCommand(commandArgs, { cwd, stderr }, {
|
|
338
|
-
createHarness,
|
|
339
|
-
serveRuntimeMcp,
|
|
340
|
-
serveRuntimeMcpStreamableHttp,
|
|
341
|
-
spawnManagedCliProcess,
|
|
342
|
-
isManagedProcessRunning,
|
|
343
|
-
signalManagedProcess,
|
|
344
|
-
})
|
|
345
|
-
: await handleAgUiCommand(commandArgs, { cwd, stderr }, {
|
|
346
|
-
createHarness,
|
|
347
|
-
serveAgUi,
|
|
348
|
-
spawnManagedCliProcess,
|
|
349
|
-
isManagedProcessRunning,
|
|
350
|
-
signalManagedProcess,
|
|
351
|
-
});
|
|
352
|
-
if (exitCode !== 0) {
|
|
353
|
-
return exitCode;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return 0;
|
|
357
|
-
};
|
|
358
|
-
if (!isTopLevelCliCommand(command)) {
|
|
359
|
-
const parsed = parseChatOptions(argv);
|
|
360
|
-
if (parsed.error) {
|
|
361
|
-
stderr(`${parsed.error}\n`);
|
|
362
|
-
stderr(renderUsage());
|
|
363
|
-
return 1;
|
|
364
|
-
}
|
|
365
|
-
return executeChat(parsed);
|
|
366
|
-
}
|
|
367
|
-
if (command === "start" || command === "stop") {
|
|
368
|
-
return runManagedServiceLifecycle(command, [projectName, ...rest].filter((item) => typeof item === "string"));
|
|
369
|
-
}
|
|
370
|
-
if (command === "acp") {
|
|
371
|
-
return handleAcpCommand([projectName, ...rest], { cwd, stderr }, {
|
|
372
|
-
createHarness,
|
|
373
|
-
serveAcp,
|
|
374
|
-
serveAcpHttp,
|
|
375
|
-
spawnManagedCliProcess,
|
|
376
|
-
isManagedProcessRunning,
|
|
377
|
-
signalManagedProcess,
|
|
378
|
-
serveA2a,
|
|
379
|
-
serveAgUi,
|
|
380
|
-
serveRuntimeMcp,
|
|
381
|
-
serveRuntimeMcpStreamableHttp,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
if (command === "ag-ui") {
|
|
385
|
-
return handleAgUiCommand([projectName, ...rest], { cwd, stderr }, {
|
|
386
|
-
createHarness,
|
|
387
|
-
serveAgUi,
|
|
388
|
-
spawnManagedCliProcess,
|
|
389
|
-
isManagedProcessRunning,
|
|
390
|
-
signalManagedProcess,
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
if (command === "a2a") {
|
|
394
|
-
return handleA2aCommand([projectName, ...rest], { cwd, stderr }, {
|
|
395
|
-
createHarness,
|
|
396
|
-
serveA2a,
|
|
397
|
-
spawnManagedCliProcess,
|
|
398
|
-
isManagedProcessRunning,
|
|
399
|
-
signalManagedProcess,
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
if (command === "mcp" || command === "runtime-mcp") {
|
|
403
|
-
return handleMcpCommand([projectName, ...rest], { cwd, stderr }, {
|
|
404
|
-
createHarness,
|
|
405
|
-
serveRuntimeMcp,
|
|
406
|
-
serveRuntimeMcpStreamableHttp,
|
|
407
|
-
spawnManagedCliProcess,
|
|
408
|
-
isManagedProcessRunning,
|
|
409
|
-
signalManagedProcess,
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
if (command === "runtime") {
|
|
413
|
-
return handleRuntimeCommand([projectName, ...rest], { cwd, stdout, stderr }, {
|
|
414
|
-
createHarness,
|
|
415
|
-
...(deps.createAgentHarness ? {} : { createClient: createAgentHarnessClient }),
|
|
416
|
-
sleep,
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
stderr(renderUsage());
|
|
420
|
-
return 1;
|
|
421
|
-
}
|
|
422
|
-
export function resolveInvokedCliHref(argvPath) {
|
|
423
|
-
if (!argvPath) {
|
|
424
|
-
return "";
|
|
425
|
-
}
|
|
426
|
-
const resolved = path.resolve(argvPath);
|
|
427
|
-
const realPath = existsSync(resolved) ? realpathSync(resolved) : resolved;
|
|
428
|
-
return pathToFileURL(realPath).href;
|
|
429
|
-
}
|
|
2
|
+
import{existsSync as ee,realpathSync as te}from"node:fs";import{createInterface as re}from"node:readline";import{Writable as ne}from"node:stream";import N from"node:path";import{pathToFileURL as oe}from"node:url";import{createAgentHarness as se}from"../api.js";import{installCliEmitterListenerGuard as ae,installCliStderrNoiseFilter as ie,installCliWarningFilter as ce,installCliWriteListenerGuard as me}from"./process-guards.js";import{createAgentHarnessClient as F,createAcpHttpHarnessClient as pe,createInProcessHarnessClient as ue}from"../client.js";import{initProject as fe}from"../init-project.js";import{serveA2aOverHttp as de}from"../protocol/a2a/http.js";import{serveAgUiOverHttp as le}from"../protocol/ag-ui/http.js";import{serveAcpOverHttp as ge}from"../protocol/acp/http.js";import{serveAcpOverStdio as he}from"../protocol/acp/stdio.js";import{serveRuntimeMcpOverStdio as ve,serveRuntimeMcpOverStreamableHttp as Ce}from"../mcp.js";import{renderChatBanner as we}from"./chat-ui.js";import{runInteractiveChatLoop as ye}from"./chat-interactive.js";import{streamChatMessage as Re}from"./chat-stream.js";import{probeChatWorkspace as Se,readChatWorkspaceModelInfo as Ae}from"./chat-workspace.js";import{handleA2aCommand as _,handleAcpCommand as G,handleAgUiCommand as Y,handleMcpCommand as B}from"./server-commands.js";import{handleRuntimeCommand as Ie}from"./runtime-commands.js";import{defaultIsManagedProcessRunning as $e,defaultSignalManagedProcess as Oe,defaultSpawnManagedCliProcess as Pe,sleep as He}from"./managed-service.js";import{isTopLevelCliCommand as ke,parseChatOptions as z,parseInitOptions as Me,parseTopLevelManagedServiceOptions as Te,renderUsage as A}from"./options.js";import{resolveCliWorkspaceRoot as Ee,validateCliWorkspaceRoot as We}from"./workspace.js";import{renderChatBanner as lt,renderChatPromptLine as gt}from"./chat-ui.js";import{probeChatWorkspace as vt,renderChatRuntimeFailure as Ct}from"./chat-workspace.js";async function x(t,o,n=5e3){if(!t)return;let s;try{await Promise.race([t.stop(),new Promise((l,c)=>{s=setTimeout(()=>{c(new Error(`Timed out after ${n}ms while stopping the chat client.`))},n)})])}catch(l){const c=l instanceof Error?l.message:String(l);/^Timed out after \d+ms while stopping the chat client\.$/.test(c)||o(`${c}
|
|
3
|
+
`)}finally{s&&clearTimeout(s)}}import{installChatSubprocessExitGuard as yt,isChatServerNoiseLine as Rt}from"./process-guards.js";function be(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ct(t){return typeof t=="string"&&t.trim().length>0?t.trim():null}function xe(t){if(typeof t=="string"&&t.trim().length>0)return t.trim();if(!be(t))return;const o=typeof t.summary=="string"&&t.summary.trim().length>0?t.summary.trim():typeof t.message=="string"&&t.message.trim().length>0?t.message.trim():void 0;if(o)return o;const n=JSON.stringify(t);return n&&n!=="{}"?n:void 0}function mt(t){const o=[`[plan v${t.version}] ${t.summary.total} todo(s)`];if(t.summary.total===0)return o.push("No todos tracked yet."),`${o.join(`
|
|
4
|
+
`)}
|
|
5
|
+
`;for(const[n,s]of t.items.entries()){o.push(`${n+1}. [${s.status}] ${s.content}`);const l=xe(s.result);l&&o.push(` result: ${l}`)}return`${o.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`}async function pt(t,o={},n={}){const s=o.cwd??process.cwd(),l=o.stdin??process.stdin,c=o.stdout??(e=>process.stdout.write(e)),r=o.stderr??(e=>process.stderr.write(e)),M=o.stdout===void 0?process.stdout:void 0,T=o.stderr===void 0?process.stderr:void 0,[p,u,...h]=t,D=n.probeChatWorkspace??Se,J=n.createReadlineInterface??re,g=n.createAgentHarness??se,$=n.serveA2aOverHttp??de,O=n.serveAgUiOverHttp??le,L=n.serveAcpOverHttp??ge,j=n.serveAcpOverStdio??he,P=n.serveRuntimeMcpOverStdio??ve,H=n.serveRuntimeMcpOverStreamableHttp??Ce,v=n.spawnManagedCliProcess??Pe,C=n.isManagedProcessRunning??$e,w=n.signalManagedProcess??Oe,K=n.createChatClient??(async e=>{if(e.transport==="http")return pe({rpcUrl:`http://${e.hostname??"127.0.0.1"}:${e.port??8787}/rpc`,eventsUrl:`http://${e.hostname??"127.0.0.1"}:${e.port??8787}/events`});if(n.createAgentHarness){const a=await g(e.workspaceRoot);return ue(a)}return F(e.workspaceRoot)}),q=async e=>{const a=Ee(s,e.workspaceRoot),i=We(a,e.workspaceRoot);if(i)return r(`${i}
|
|
8
|
+
`),1;const E=Ae(a,e.agentId),k=l;let y,S,m,f,R;try{m=ae(),f=ie(o.stderr===void 0),R=ce(),y=await K({workspaceRoot:a,transport:e.transport,hostname:e.hostname,port:e.port,stderr:r}),S=me([M,T]);let d=e.agentId,I=e.sessionId,Le;const W=!1,U=e.message?void 0:await D({workspaceRoot:a,agentId:d});if(e.message)return await Re({client:y,stdout:c,stdoutStream:M,stderr:r,stderrStream:T,agentId:d,sessionId:I,message:e.message,modelInfo:E,requestEvents:e.requestEvents,liveRequestTree:e.requestEvents&&k.isTTY===!0,colorRequestTree:W,showToolResults:e.requestEvents,showRunningState:!1}),await x(y,r),S?.(),m?.(),f?.(),R?.(),0;c(we({workspacePath:a,transport:e.transport,agentId:d,sessionId:I,color:W})),U&&c(`${U}
|
|
9
|
+
|
|
10
|
+
`);const V=new ne({decodeStrings:!1,write(b,qe,Z){c(typeof b=="string"?b:String(b)),Z()}}),X=J({input:l,output:V,crlfDelay:1/0,terminal:k.isTTY===!0}),je=await ye({client:y,lineReader:X,stdout:c,stderr:r,stdoutStream:M,stderrStream:T,workspacePath:a,workspaceModelInfo:E,requestEvents:e.requestEvents,chatIsTty:k.isTTY===!0,useColor:W,agentFilter:e.agentId,activeAgentId:d,activeSessionId:I});return await x(y,r),S?.(),m?.(),f?.(),R?.(),0}catch(d){S?.(),m?.(),f?.(),R?.();const I=d instanceof Error?d.message:String(d);return r(`${I}
|
|
11
|
+
`),y&&await x(y,()=>{}),1}};if(p==="init"){if(!u?.trim())return r(A()),1;const e=Me(h);if(e.error)return r(`${e.error}
|
|
12
|
+
`),r(A()),1;try{const a=N.resolve(s,u),i=await fe(a,u,e.options);return c(`Created ${i.projectSlug} at ${i.projectRoot}
|
|
13
|
+
`),c(`Next steps:
|
|
14
|
+
`),c(` cd ${u}
|
|
15
|
+
`),c(` npm install
|
|
16
|
+
`),(e.options?.provider??"openai")==="openai"&&c(` export OPENAI_API_KEY=your_key_here
|
|
17
|
+
`),c(` npm run start -- "Research a topic"
|
|
18
|
+
`),0}catch(a){const i=a instanceof Error?a.message:String(a);return r(`${i}
|
|
19
|
+
`),1}}if(p==="chat"){const e=z([u,...h].filter(a=>typeof a=="string"));return e.error?(r(`${e.error}
|
|
20
|
+
`),r(A()),1):q(e)}const Q=async(e,a)=>{const i=Te(a);if(i.error)return r(`${i.error}
|
|
21
|
+
`),r(A()),1;const S=(e==="start"?["acp","a2a","mcp","ag-ui"]:["ag-ui","mcp","a2a","acp"]).filter(m=>i.services.includes(m));for(const m of S){const f=[e,"--workspace",i.workspaceRoot??"."];e==="start"&&i.hostname&&f.push("--host",i.hostname);const R=m==="acp"?i.acpPort:m==="a2a"?i.a2aPort:m==="mcp"?i.mcpPort:i.agUiPort;e==="start"&&typeof R=="number"&&f.push("--port",String(R));const d=m==="acp"?await G(f,{cwd:s,stderr:r},{createHarness:g,serveAcp:j,serveAcpHttp:L,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w,serveA2a:$,serveAgUi:O,serveRuntimeMcp:P,serveRuntimeMcpStreamableHttp:H}):m==="a2a"?await _(f,{cwd:s,stderr:r},{createHarness:g,serveA2a:$,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w}):m==="mcp"?await B(f,{cwd:s,stderr:r},{createHarness:g,serveRuntimeMcp:P,serveRuntimeMcpStreamableHttp:H,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w}):await Y(f,{cwd:s,stderr:r},{createHarness:g,serveAgUi:O,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w});if(d!==0)return d}return 0};if(!ke(p)){const e=z(t);return e.error?(r(`${e.error}
|
|
22
|
+
`),r(A()),1):q(e)}return p==="start"||p==="stop"?Q(p,[u,...h].filter(e=>typeof e=="string")):p==="acp"?G([u,...h],{cwd:s,stderr:r},{createHarness:g,serveAcp:j,serveAcpHttp:L,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w,serveA2a:$,serveAgUi:O,serveRuntimeMcp:P,serveRuntimeMcpStreamableHttp:H}):p==="ag-ui"?Y([u,...h],{cwd:s,stderr:r},{createHarness:g,serveAgUi:O,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w}):p==="a2a"?_([u,...h],{cwd:s,stderr:r},{createHarness:g,serveA2a:$,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w}):p==="mcp"||p==="runtime-mcp"?B([u,...h],{cwd:s,stderr:r},{createHarness:g,serveRuntimeMcp:P,serveRuntimeMcpStreamableHttp:H,spawnManagedCliProcess:v,isManagedProcessRunning:C,signalManagedProcess:w}):p==="runtime"?Ie([u,...h],{cwd:s,stdout:c,stderr:r},{createHarness:g,...n.createAgentHarness?{}:{createClient:F},sleep:He}):(r(A()),1)}function ut(t){if(!t)return"";const o=N.resolve(t),n=ee(o)?te(o):o;return oe(n).href}export{yt as installChatSubprocessExitGuard,Rt as isChatServerNoiseLine,vt as probeChatWorkspace,lt as renderChatBanner,gt as renderChatPromptLine,Ct as renderChatRuntimeFailure,ut as resolveInvokedCliHref,pt as runCli};
|
|
@@ -1,63 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
const stdoutPath = managedServiceLogPath(input.workspacePath, input.service, "stdout");
|
|
12
|
-
const stderrPath = managedServiceLogPath(input.workspacePath, input.service, "stderr");
|
|
13
|
-
const spawned = await input.spawnManagedCliProcess({
|
|
14
|
-
args: input.args,
|
|
15
|
-
cwd: input.workspacePath,
|
|
16
|
-
stdoutPath,
|
|
17
|
-
stderrPath,
|
|
18
|
-
});
|
|
19
|
-
if (!spawned.pid || spawned.pid <= 0) {
|
|
20
|
-
input.stderr(`Failed to start ${input.service.toUpperCase()} service for ${input.workspacePath}.\n`);
|
|
21
|
-
return 1;
|
|
22
|
-
}
|
|
23
|
-
await writeManagedServiceState({
|
|
24
|
-
pid: spawned.pid,
|
|
25
|
-
service: input.service,
|
|
26
|
-
workspaceRoot: input.workspacePath,
|
|
27
|
-
transport: input.service === "mcp" ? "streamable-http" : "http",
|
|
28
|
-
startedAt: new Date().toISOString(),
|
|
29
|
-
stdoutPath,
|
|
30
|
-
stderrPath,
|
|
31
|
-
});
|
|
32
|
-
await sleep(250);
|
|
33
|
-
if (!input.isManagedProcessRunning(spawned.pid)) {
|
|
34
|
-
await clearManagedServiceState(input.workspacePath, input.service);
|
|
35
|
-
input.stderr(`Failed to keep ${input.service.toUpperCase()} service running for ${input.workspacePath}. Check ${stderrPath}.\n`);
|
|
36
|
-
return 1;
|
|
37
|
-
}
|
|
38
|
-
input.stderr(`Started ${input.service.toUpperCase()} service for ${input.workspacePath} (pid ${spawned.pid}). Logs: ${stdoutPath}, ${stderrPath}\n`);
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
export async function stopManagedHttpService(input) {
|
|
42
|
-
const existing = await readManagedServiceState(input.workspacePath, input.service);
|
|
43
|
-
if (!existing) {
|
|
44
|
-
input.stderr(`No managed ${input.service.toUpperCase()} service is recorded for ${input.workspacePath}.\n`);
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
if (!input.isManagedProcessRunning(existing.pid)) {
|
|
48
|
-
await clearManagedServiceState(input.workspacePath, input.service);
|
|
49
|
-
input.stderr(`Managed ${input.service.toUpperCase()} service for ${input.workspacePath} is already stopped.\n`);
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
input.signalManagedProcess(existing.pid, "SIGTERM");
|
|
53
|
-
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
54
|
-
await sleep(100);
|
|
55
|
-
if (!input.isManagedProcessRunning(existing.pid)) {
|
|
56
|
-
await clearManagedServiceState(input.workspacePath, input.service);
|
|
57
|
-
input.stderr(`Stopped ${input.service.toUpperCase()} service for ${input.workspacePath}.\n`);
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
input.stderr(`Timed out while stopping ${input.service.toUpperCase()} service for ${input.workspacePath} (pid ${existing.pid}).\n`);
|
|
62
|
-
return 1;
|
|
63
|
-
}
|
|
1
|
+
import{clearManagedServiceState as o,managedServiceLogPath as t,readManagedServiceState as d,sleep as i,writeManagedServiceState as w}from"./managed-service.js";async function g(e){const r=await d(e.workspacePath,e.service);if(r&&e.isManagedProcessRunning(r.pid))return e.stderr(`${e.service.toUpperCase()} service is already running for ${e.workspacePath} (pid ${r.pid}).
|
|
2
|
+
`),0;r&&await o(e.workspacePath,e.service);const a=t(e.workspacePath,e.service,"stdout"),c=t(e.workspacePath,e.service,"stderr"),s=await e.spawnManagedCliProcess({args:e.args,cwd:e.workspacePath,stdoutPath:a,stderrPath:c});return!s.pid||s.pid<=0?(e.stderr(`Failed to start ${e.service.toUpperCase()} service for ${e.workspacePath}.
|
|
3
|
+
`),1):(await w({pid:s.pid,service:e.service,workspaceRoot:e.workspacePath,transport:e.service==="mcp"?"streamable-http":"http",startedAt:new Date().toISOString(),stdoutPath:a,stderrPath:c}),await i(250),e.isManagedProcessRunning(s.pid)?(e.stderr(`Started ${e.service.toUpperCase()} service for ${e.workspacePath} (pid ${s.pid}). Logs: ${a}, ${c}
|
|
4
|
+
`),0):(await o(e.workspacePath,e.service),e.stderr(`Failed to keep ${e.service.toUpperCase()} service running for ${e.workspacePath}. Check ${c}.
|
|
5
|
+
`),1))}async function P(e){const r=await d(e.workspacePath,e.service);if(!r)return e.stderr(`No managed ${e.service.toUpperCase()} service is recorded for ${e.workspacePath}.
|
|
6
|
+
`),0;if(!e.isManagedProcessRunning(r.pid))return await o(e.workspacePath,e.service),e.stderr(`Managed ${e.service.toUpperCase()} service for ${e.workspacePath} is already stopped.
|
|
7
|
+
`),0;e.signalManagedProcess(r.pid,"SIGTERM");for(let a=0;a<20;a+=1)if(await i(100),!e.isManagedProcessRunning(r.pid))return await o(e.workspacePath,e.service),e.stderr(`Stopped ${e.service.toUpperCase()} service for ${e.workspacePath}.
|
|
8
|
+
`),0;return e.stderr(`Timed out while stopping ${e.service.toUpperCase()} service for ${e.workspacePath} (pid ${r.pid}).
|
|
9
|
+
`),1}export{g as startManagedHttpService,P as stopManagedHttpService};
|