2026-04-05 21:09:33 -05:00
|
|
|
/**
|
|
|
|
|
* Agent CLI commands.
|
|
|
|
|
*
|
|
|
|
|
* Python reference: trustgraph-cli/trustgraph/cli/invoke_agent.py
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-02 00:22:04 -05:00
|
|
|
import { Effect } from "effect";
|
2026-06-06 10:33:10 -05:00
|
|
|
import * as Argument from "effect/unstable/cli/Argument";
|
|
|
|
|
import * as Command from "effect/unstable/cli/Command";
|
2026-06-02 00:22:04 -05:00
|
|
|
import { cliCommandError, withSocket } from "./util.js";
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-06 10:33:10 -05:00
|
|
|
export const agentCommand = Command.make("agent", {
|
|
|
|
|
question: Argument.string("question").pipe(Argument.withDescription("Question to ask")),
|
|
|
|
|
}, ({ question }) =>
|
|
|
|
|
withSocket((socket, opts) =>
|
|
|
|
|
Effect.gen(function* () {
|
2026-04-05 22:44:45 -05:00
|
|
|
const flow = socket.flow(opts.flow);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-06 10:33:10 -05:00
|
|
|
yield* Effect.callback<void, ReturnType<typeof cliCommandError>>((resume) => {
|
2026-04-05 22:44:45 -05:00
|
|
|
flow.agent(
|
|
|
|
|
question,
|
|
|
|
|
(chunk) => {
|
|
|
|
|
// think — show thought process
|
2026-05-12 08:06:58 -05:00
|
|
|
if (chunk.length > 0) process.stderr.write(chunk);
|
2026-04-05 22:44:45 -05:00
|
|
|
},
|
|
|
|
|
(chunk) => {
|
|
|
|
|
// observe — show observations
|
2026-05-12 08:06:58 -05:00
|
|
|
if (chunk.length > 0) process.stderr.write(chunk);
|
2026-04-05 22:44:45 -05:00
|
|
|
},
|
|
|
|
|
(chunk, complete) => {
|
|
|
|
|
// answer — print to stdout
|
2026-05-12 08:06:58 -05:00
|
|
|
if (chunk.length > 0) process.stdout.write(chunk);
|
2026-04-05 22:44:45 -05:00
|
|
|
if (complete) {
|
|
|
|
|
process.stdout.write("\n");
|
2026-06-02 00:22:04 -05:00
|
|
|
resume(Effect.void);
|
2026-04-05 22:44:45 -05:00
|
|
|
}
|
|
|
|
|
},
|
2026-06-02 00:22:04 -05:00
|
|
|
(err) => resume(Effect.fail(cliCommandError("agent", err))),
|
2026-04-05 22:44:45 -05:00
|
|
|
);
|
|
|
|
|
});
|
2026-06-06 10:33:10 -05:00
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
).pipe(Command.withDescription("Ask the TrustGraph agent a question"));
|