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
11 changes: 3 additions & 8 deletions packages/codeblog/src/cli/cmd/agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const AgentCommand: CommandModule = {
Expand All @@ -13,11 +14,8 @@ export const AgentCommand: CommandModule = {
describe: "List all your agents",
handler: async () => {
try {
const text = await McpBridge.callTool("manage_agents", { action: "list" })
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("manage_agents", { action: "list" })
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down Expand Up @@ -56,11 +54,8 @@ export const AgentCommand: CommandModule = {
}
if (args.description) mcpArgs.description = args.description

const text = await McpBridge.callTool("manage_agents", mcpArgs)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("manage_agents", mcpArgs)
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
7 changes: 2 additions & 5 deletions packages/codeblog/src/cli/cmd/comment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const CommentCommand: CommandModule = {
Expand Down Expand Up @@ -56,11 +56,8 @@ export const CommentCommand: CommandModule = {
}
if (args.reply) mcpArgs.parent_id = args.reply

const text = await McpBridge.callTool("comment_on_post", mcpArgs)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("comment_on_post", mcpArgs)
console.log("")
} catch (err) {
UI.error(`Comment failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
8 changes: 2 additions & 6 deletions packages/codeblog/src/cli/cmd/feed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const FeedCommand: CommandModule = {
Expand Down Expand Up @@ -35,16 +35,12 @@ export const FeedCommand: CommandModule = {
}
if (args.tag) mcpArgs.tag = args.tag

const text = await McpBridge.callTool("browse_posts", mcpArgs)

const tagFilter = args.tag ? ` ${UI.Style.TEXT_INFO}#${args.tag}${UI.Style.TEXT_NORMAL}` : ""
console.log("")
console.log(` ${UI.Style.TEXT_NORMAL_BOLD}Posts${UI.Style.TEXT_NORMAL}${tagFilter} ${UI.Style.TEXT_DIM}page ${args.page}${UI.Style.TEXT_NORMAL}`)
console.log("")

for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("browse_posts", mcpArgs)
console.log("")

console.log(` ${UI.Style.TEXT_DIM}Next page: codeblog feed --page ${(args.page as number) + 1}${UI.Style.TEXT_NORMAL}`)
Expand Down
35 changes: 9 additions & 26 deletions packages/codeblog/src/cli/cmd/forum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const ForumCommand: CommandModule = {
Expand All @@ -13,11 +13,8 @@ export const ForumCommand: CommandModule = {
describe: "Top posts, most discussed, active agents, trending tags",
handler: async () => {
try {
const text = await McpBridge.callTool("trending_topics")
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("trending_topics")
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
Expand All @@ -36,24 +33,16 @@ export const ForumCommand: CommandModule = {
}),
handler: async (args) => {
try {
console.log("")
if (args.tag) {
const text = await McpBridge.callTool("browse_by_tag", {
await mcpPrint("browse_by_tag", {
action: "posts",
tag: args.tag,
})
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
console.log("")
} else {
const text = await McpBridge.callTool("browse_by_tag", { action: "trending" })
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
console.log("")
await mcpPrint("browse_by_tag", { action: "trending" })
}
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
process.exitCode = 1
Expand Down Expand Up @@ -91,25 +80,19 @@ export const ForumCommand: CommandModule = {
process.exitCode = 1
return
}
const text = await McpBridge.callTool("join_debate", {
console.log("")
await mcpPrint("join_debate", {
action: "create",
title: args.title,
pro_label: args.pro,
con_label: args.con,
})
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
console.log("")
} else {
const text = await McpBridge.callTool("join_debate", { action: "list" })
console.log("")
console.log(` ${UI.Style.TEXT_NORMAL_BOLD}Tech Arena — Active Debates${UI.Style.TEXT_NORMAL}`)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("join_debate", { action: "list" })
console.log("")
}
} catch (err) {
Expand Down
28 changes: 7 additions & 21 deletions packages/codeblog/src/cli/cmd/me.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const MeCommand: CommandModule = {
Expand All @@ -13,11 +14,8 @@ export const MeCommand: CommandModule = {
describe: "Your stats, top posts, recent activity",
handler: async () => {
try {
const text = await McpBridge.callTool("my_dashboard")
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("my_dashboard")
console.log("")
} catch (err) {
UI.error(`Dashboard failed: ${err instanceof Error ? err.message : String(err)}`)
Expand All @@ -42,15 +40,12 @@ export const MeCommand: CommandModule = {
}),
handler: async (args) => {
try {
const text = await McpBridge.callTool("my_posts", {
console.log("")
await mcpPrint("my_posts", {
sort: args.sort,
limit: args.limit,
})
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
process.exitCode = 1
Expand Down Expand Up @@ -78,11 +73,8 @@ export const MeCommand: CommandModule = {
const action = args.read ? "read_all" : "list"
const mcpArgs: Record<string, unknown> = { action }
if (!args.read) mcpArgs.limit = args.limit
const text = await McpBridge.callTool("my_notifications", mcpArgs)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("my_notifications", mcpArgs)
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
Expand All @@ -96,11 +88,8 @@ export const MeCommand: CommandModule = {
describe: "Your bookmarked posts",
handler: async () => {
try {
const text = await McpBridge.callTool("bookmark_post", { action: "list" })
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("bookmark_post", { action: "list" })
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down Expand Up @@ -137,11 +126,8 @@ export const MeCommand: CommandModule = {
describe: "Users you follow",
handler: async () => {
try {
const text = await McpBridge.callTool("follow_agent", { action: "list_following" })
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("follow_agent", { action: "list_following" })
console.log("")
} catch (err) {
UI.error(`Failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
8 changes: 2 additions & 6 deletions packages/codeblog/src/cli/cmd/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const PostCommand: CommandModule = {
Expand All @@ -14,12 +14,8 @@ export const PostCommand: CommandModule = {
}),
handler: async (args) => {
try {
const text = await McpBridge.callTool("read_post", { post_id: args.id })

console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("read_post", { post_id: args.id })
console.log("")
} catch (err) {
UI.error(`Failed to fetch post: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
12 changes: 3 additions & 9 deletions packages/codeblog/src/cli/cmd/publish.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const PublishCommand: CommandModule = {
Expand Down Expand Up @@ -39,11 +39,8 @@ export const PublishCommand: CommandModule = {
if (args.language) mcpArgs.language = args.language
if (args.dryRun === false) mcpArgs.post = true

const text = await McpBridge.callTool("weekly_digest", mcpArgs)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("weekly_digest", mcpArgs)
console.log("")
return
}
Expand All @@ -56,11 +53,8 @@ export const PublishCommand: CommandModule = {
if (args.language) mcpArgs.language = args.language
if (args.style) mcpArgs.style = args.style

const text = await McpBridge.callTool("auto_post", mcpArgs)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("auto_post", mcpArgs)
console.log("")
} catch (err) {
UI.error(`Publish failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
6 changes: 2 additions & 4 deletions packages/codeblog/src/cli/cmd/scan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const ScanCommand: CommandModule = {
Expand All @@ -24,13 +25,10 @@ export const ScanCommand: CommandModule = {
handler: async (args) => {
try {
if (args.status) {
const text = await McpBridge.callTool("codeblog_status")
console.log("")
console.log(` ${UI.Style.TEXT_NORMAL_BOLD}CodeBlog Status${UI.Style.TEXT_NORMAL}`)
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("codeblog_status")
console.log("")
return
}
Expand Down
15 changes: 5 additions & 10 deletions packages/codeblog/src/cli/cmd/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const SearchCommand: CommandModule = {
Expand All @@ -19,18 +19,13 @@ export const SearchCommand: CommandModule = {
}),
handler: async (args) => {
try {
const text = await McpBridge.callTool("search_posts", {
query: args.query,
limit: args.limit,
})

console.log("")
console.log(` ${UI.Style.TEXT_NORMAL_BOLD}Results for "${args.query}"${UI.Style.TEXT_NORMAL}`)
console.log("")

for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("search_posts", {
query: args.query,
limit: args.limit,
})
console.log("")
} catch (err) {
UI.error(`Search failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
7 changes: 2 additions & 5 deletions packages/codeblog/src/cli/cmd/whoami.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import type { CommandModule } from "yargs"
import { McpBridge } from "../../mcp/client"
import { mcpPrint } from "../mcp-print"
import { UI } from "../ui"

export const WhoamiCommand: CommandModule = {
command: "whoami",
describe: "Show current auth status",
handler: async () => {
try {
const text = await McpBridge.callTool("codeblog_status")
console.log("")
for (const line of text.split("\n")) {
console.log(` ${line}`)
}
await mcpPrint("codeblog_status")
console.log("")
} catch (err) {
UI.error(`Status check failed: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
6 changes: 6 additions & 0 deletions packages/codeblog/src/cli/mcp-print.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { McpBridge } from "../mcp/client"

export async function mcpPrint(tool: string, args: Record<string, unknown> = {}) {
const text = await McpBridge.callTool(tool, args)
for (const line of text.split("\n")) console.log(` ${line}`)
}
Loading
Loading