Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ Inside a session:
| `/model`, `/models` | switch the model (saved), list what nodes serve |
| `/todos`, `/compact`, `/clear`, `/cost`, `/key`, `/cwd` | checklist, shrink context, fresh chat, usage, key, directory |

The session also takes every command c0mpute.com/chat does, out of the box. Media
jobs run in the background (keep working; `/tasks` shows them) and save to
`./c0mpute-media/`:

| | |
|---|---|
| `/image <prompt>` | a picture from a c0mpute CPU worker (also `/img`, `/draw`) |
| `/video <prompt> [--model wan2.2-ti2v-5b]` | a short clip (also `/clip`, `/vid`) |
| `/music <style> [lyrics: …]` | a song; lyrics add vocals (also `/song`) |
| `/album <idea>` | a band, 8 named songs with lyrics, cover art, all in a zip (also `/lp`) |
| `/promo <url> [pixar\|anime\|claymation\|flat] [vertical]` | a promo video of a site with narration and music |
| `/push hosting <name>` · `ls` · `rm <name>` | publish the session's media and transcript as a site on the c0mpute network |
| `/connect hosting [node]` | list your hosting nodes, or pick the one `/push` uses |
| `/plugin add <url\|name>` · `ls` · `on`/`off`/`rm <name>` | chat plugins (remote MCP servers) on your c0mpute.com account |
| `/login` | sign in to c0mpute.com |

With no sign-in, media runs on the open network with your `ik_live_` key (or the
free tier). After `/login` (or `c0mpute chat login` on the same machine, or
`C0MPUTE_CHAT_KEY=c0k_…`) it runs on your c0mpute.com account, and `/push`,
`/connect` and `/plugin` work. In print mode a media line waits for the result and
prints the saved paths: `moshcode agents c0mpute -p "/image a red bicycle"`.

The lead agent can call `task` to hand a self-contained job to a subagent. Several
`task` calls in one reply run in parallel. Subagents start with a fresh
conversation, their own system prompt and their own tool list, and cannot spawn
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moshcode",
"version": "0.125.3",
"version": "0.126.0",
"type": "module",
"description": "moshcode — a metal wrapper for coding engines and native UGig/CoinPay workflow CLIs, with OpenPRD and moshscript",
"repository": {
Expand Down
42 changes: 40 additions & 2 deletions src/c0agent-repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
ALL_TOOLS, READ_ONLY_TOOLS, agentDirs, findAgent, loadAgents, normalizeTool, removeAgent, renderAgentFile, saveAgent, validName,
} from "./c0agent-defs.mjs";
import { createTaskBoard, liveSummary, readTasks, renderTasks, tasksFile } from "./c0agent-tasks.mjs";
import { chatKeyConfig, parseChatCommand } from "./c0chat-commands.mjs";
import { CHAT_HELP_ROWS, createChatHandler, runChatPrint } from "./c0chat-handler.mjs";
import { acid, amber, ash, bone, danger, dim, err, info, ok, warn } from "./ui.mjs";

const MODES = ["ask", "auto-edit", "plan"];
Expand Down Expand Up @@ -345,6 +347,10 @@ async function readStdin() {
}

async function runPrint(prompt, { cfg, opts }) {
// The c0mpute chat's own commands (/image, /music, /album, /promo, /video,
// /push, …) run as they do in the chat, not through the model.
const chatCmd = parseChatCommand(prompt);
if (chatCmd) return runChatPrint(chatCmd, { cfg, cwd: opts.cwd || process.cwd() });
const provider = await createProvider(cfg);
const mode = opts.mode || "ask";
const session = createSession({
Expand Down Expand Up @@ -472,6 +478,7 @@ async function repl({ cfg, opts, write }) {
completer: (line) => {
if (shiftTab) { shiftTab = false; return [[], line]; }
const words = ["/agents", "/tasks", "/bg", "/model", "/models", "/permissions", "/todos", "/compact", "/clear", "/cost", "/key", "/cwd", "/exit", "/help",
"/image", "/video", "/music", "/album", "/promo", "/push", "/connect", "/plugin", "/login",
...loadAgents({ cwd: session.cwd }).map((a) => `@${a.name}`)];
const last = line.split(/\s+/).pop();
const hits = words.filter((w) => w.startsWith(last));
Expand Down Expand Up @@ -629,6 +636,25 @@ async function repl({ cfg, opts, write }) {
const lead = opts.agent ? findAgent(opts.agent, { cwd: session.cwd }) : LEAD_AGENT;
if (!lead) { write(err(`no agent named "${opts.agent}"`)); rl.close(); return 1; }
let messages = [];
// What the c0mpute chat commands need: a transcript for /push's page and
// every media result this session made.
const transcript = [];
const media = [];
const chatHandle = createChatHandler({
cfg,
cwd: () => session.cwd,
log: (l) => log(l),
board,
transcript,
media,
pushNode: () => { try { return JSON.parse(fs.readFileSync(configFile(), "utf8")).pushNode ?? null; } catch { return null; } },
status: (l) => spinner.label(l),
foreground: async (fn) => {
busy = new AbortController();
spinner.start("working…");
try { return await fn(busy.signal); } finally { spinner.stop(); busy = null; }
},
});

const prompt = () => {
flushNotes();
Expand All @@ -654,6 +680,7 @@ async function repl({ cfg, opts, write }) {
log(` ${ash("key")} ${cfg.apiKey ? `${cfg.apiKey.slice(0, 8)}… ${ash(`(${cfg.keySource})`)}` : amber("none: free tier, 10 prompts a day — /key ik_live_… to add one")}`);
log(` ${ash("prompts and tool output go to the peer node that takes each job; keep secrets out")}`);
if (session.permissionMode === "yolo") log(` ${warn("permissions bypassed: every edit and command runs without asking")}`);
{ const chat = chatKeyConfig(); log(` ${ash("media")} /image /music /album /promo /video ${ash(chat.key ? "· c0mpute.com account (/push, /plugin ready)" : "· /login for /push, /connect, /plugin")}`); }
log(` ${ash("/help for commands · /agents for subagents · @agent to run one")}`);
log("");

Expand All @@ -675,6 +702,7 @@ async function repl({ cfg, opts, write }) {
messages.push({ role: "user", content });
res = await runAgent({ session, agent, messages, signal: busy.signal, onEvent });
renderer.finish();
transcript.push({ role: "user", content }, ...(res?.text ? [{ role: "assistant", content: res.text }] : []));
}
} catch (e) {
res = { error: String(e?.message || e) };
Expand All @@ -693,7 +721,13 @@ async function repl({ cfg, opts, write }) {
};

const commands = {
help: () => { for (const [c, d] of HELP) log(` ${acid(c.padEnd(22))} ${ash(d)}`); },
help: () => {
for (const [c, d] of HELP) log(` ${acid(c.padEnd(22))} ${ash(d)}`);
log("");
log(bone(" c0mpute chat commands"));
for (const [c, d] of CHAT_HELP_ROWS) log(` ${acid(c)}\n ${ash(d)}`);
log(ash(" anything else is a task for the agent"));
},
clear: () => { messages = []; session.todos = []; log(ok("new conversation")); },
cost: () => log(` ${session.usage.calls} model calls · ~${session.usage.inputTokens.toLocaleString()} in / ~${session.usage.outputTokens.toLocaleString()} out tokens ${ash("(estimated)")}`),
todos: () => (session.todos.length ? renderTodos(session.todos, log) : log(ash(" no todos"))),
Expand Down Expand Up @@ -904,7 +938,11 @@ async function repl({ cfg, opts, write }) {
if (item.queued) { process.stdout.write("\r\x1b[2K"); log(`${acid(">")} ${line.length > 100 ? `${line.slice(0, 100)}…` : line}`); }
appendHistory(line);
try {
if (line.startsWith("/")) {
const chatCmd = line.startsWith("@") || line.startsWith("&") ? null : parseChatCommand(line);
if (chatCmd) {
exitWarned = false;
try { await chatHandle(chatCmd); } catch (e) { spinner.stop(); log(err(String(e?.message || e))); }
} else if (line.startsWith("/")) {
const [c, ...args] = line.slice(1).split(/\s+/);
if (c === "exit" || c === "quit" || c === "q") {
const live = liveBackground();
Expand Down
Loading
Loading