Skip to content

Commit 70b280c

Browse files
aRustyDevclaude
andcommitted
refactor: extract graph-viewer to packages/graph-viewer/ (ai-b2t)
Move client (Vite frontend), server (Bun backend), bin entrypoint, and vite config from @agents/cli into a standalone @agents/graph-viewer workspace package. CLI commands (graph-viewer serve/build/dev and serve --web) now delegate to the new package via workspace import. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0149222 commit 70b280c

36 files changed

Lines changed: 120 additions & 81 deletions

bun.lock

Lines changed: 38 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@agents/core": "workspace:*",
15+
"@agents/graph-viewer": "workspace:*",
1516
"@agents/kg": "workspace:*",
1617
"@agents/sdk": "workspace:*",
1718
"@bomb.sh/tab": "^0.0.14",
Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,42 @@
11
/**
22
* Graph Viewer commands — serve, build, dev.
33
*
4+
* Delegates to the @agents/graph-viewer package.
5+
*
46
* Subcommands:
57
* serve - Start the Bun server (production: serves built assets)
68
* build - Build the Vite client
79
* dev - Start both Vite dev server and Bun API server
810
*/
911

10-
import { currentDir } from '@agents/core/runtime'
1112
import { defineCommand } from 'citty'
1213

13-
const serveCommand = defineCommand({
14-
meta: { name: 'serve', description: 'Start the graph viewer server' },
15-
args: {
16-
port: { type: 'string', default: '3000', description: 'Server port' },
17-
},
18-
async run({ args }) {
19-
process.env.GV_PORT = args.port
20-
await import('../bin/graph-viewer')
21-
},
22-
})
23-
24-
const buildCommand = defineCommand({
25-
meta: { name: 'build', description: 'Build the graph viewer client' },
26-
async run() {
27-
const { execSync } = await import('node:child_process')
28-
const { resolve } = await import('node:path')
29-
const scriptsDir = resolve(currentDir(import.meta), '../..')
30-
execSync('npx vite build --config vite.graph-viewer.config.ts', {
31-
cwd: scriptsDir,
32-
stdio: 'inherit',
33-
})
34-
},
35-
})
36-
37-
const devCommand = defineCommand({
38-
meta: { name: 'dev', description: 'Start graph viewer in dev mode (Vite HMR + Bun API)' },
39-
args: {
40-
port: { type: 'string', default: '3000', description: 'API server port' },
41-
},
42-
async run({ args }) {
43-
const { execSync } = await import('node:child_process')
44-
const { resolve } = await import('node:path')
45-
const scriptsDir = resolve(currentDir(import.meta), '../..')
46-
process.env.GV_PORT = args.port
47-
execSync(
48-
`npx concurrently "bun --watch run src/bin/graph-viewer.ts" "npx vite --config vite.graph-viewer.config.ts"`,
49-
{
50-
cwd: scriptsDir,
51-
stdio: 'inherit',
52-
}
53-
)
54-
},
55-
})
56-
5714
export default defineCommand({
5815
meta: { name: 'graph-viewer', description: 'Interactive graph visualization tool' },
5916
subCommands: {
60-
serve: serveCommand,
61-
build: buildCommand,
62-
dev: devCommand,
17+
serve: defineCommand({
18+
meta: { name: 'serve', description: 'Start the graph viewer server' },
19+
args: {
20+
port: { type: 'string', default: '3000', description: 'Server port' },
21+
},
22+
async run({ args }) {
23+
process.env.GV_PORT = args.port
24+
await import('@agents/graph-viewer/bin')
25+
},
26+
}),
27+
build: defineCommand({
28+
meta: { name: 'build', description: 'Build the graph viewer client' },
29+
async run() {
30+
const { execSync } = await import('node:child_process')
31+
execSync('bun run build', { cwd: 'packages/graph-viewer', stdio: 'inherit' })
32+
},
33+
}),
34+
dev: defineCommand({
35+
meta: { name: 'dev', description: 'Start dev mode' },
36+
async run() {
37+
const { execSync } = await import('node:child_process')
38+
execSync('bun run dev', { cwd: 'packages/graph-viewer', stdio: 'inherit' })
39+
},
40+
}),
6341
},
6442
})

packages/cli/src/commands/serve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,6 @@ export default defineCommand({
155155
// Default: delegate to graph-viewer serve (web mode)
156156
process.env.GV_PORT = String(port)
157157
out.info(`Starting graph viewer on port ${port}...`)
158-
await import('../bin/graph-viewer')
158+
await import('@agents/graph-viewer/bin')
159159
},
160160
})

packages/graph-viewer/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@agents/graph-viewer",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"exports": {
7+
"./bin": "./src/bin.ts"
8+
},
9+
"scripts": {
10+
"serve": "bun run src/bin.ts",
11+
"dev": "concurrently \"bun run src/bin.ts\" \"npx vite --config vite.config.ts\"",
12+
"build": "npx vite build --config vite.config.ts"
13+
},
14+
"dependencies": {
15+
"@agents/core": "workspace:*",
16+
"@agents/kg": "workspace:*",
17+
"graphology": "^0.26.0",
18+
"graphology-layout": "^0.6.1",
19+
"graphology-layout-forceatlas2": "^0.10.1",
20+
"graphology-types": "^0.24.8",
21+
"sigma": "^3.0.2",
22+
"ws": "^8.19.0",
23+
"concurrently": "^9.2.1",
24+
"vite": "^8.0.1"
25+
},
26+
"devDependencies": {
27+
"@types/ws": "^8.18.1"
28+
}
29+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ import { createServer, type IncomingMessage, type ServerResponse } from 'node:ht
1616
import { extname, resolve } from 'node:path'
1717
import { currentDir } from '@agents/core/runtime'
1818
import { WebSocket, WebSocketServer } from 'ws'
19-
import { handleGitRoute } from '../server/graph-viewer/routes/git'
20-
import { handleGraphsRoute, handleSchemasRoute } from '../server/graph-viewer/routes/graphs'
21-
import { createWatcher, type FileChangeEvent } from '../server/graph-viewer/watcher'
19+
import { handleGitRoute } from './server/routes/git'
20+
import { handleGraphsRoute, handleSchemasRoute } from './server/routes/graphs'
21+
import { createWatcher, type FileChangeEvent } from './server/watcher'
2222

2323
// ---------------------------------------------------------------------------
2424
// Configuration
2525
// ---------------------------------------------------------------------------
2626

2727
const PORT = Number(process.env.GV_PORT) || 3000
2828
const __dir = currentDir(import.meta)
29-
const DIST_DIR = resolve(__dir, '../../dist/graph-viewer')
30-
const GRAPHS_DIR = resolve(__dir, '../../../../.data/graphs')
29+
const DIST_DIR = resolve(__dir, '../dist/graph-viewer')
30+
const GRAPHS_DIR = resolve(__dir, '../../../.data/graphs')
3131

3232
// ---------------------------------------------------------------------------
3333
// MIME types for static file serving
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/cli/src/client/graph-viewer/graph/serializer.ts renamed to packages/graph-viewer/src/client/graph/serializer.ts

File renamed without changes.

0 commit comments

Comments
 (0)