amorphous-cli 0.1.0

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/mcp.mjs ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Local MCP: each tool runs the same CLI entrypoint as `cli/index.mjs`.
4
+ */
5
+ import { spawn } from 'node:child_process'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { dirname, join } from 'node:path'
8
+ import { createInterface } from 'node:readline'
9
+ import { COMMAND_HELP } from './lib/help.mjs'
10
+
11
+ const cliPath = join(dirname(fileURLToPath(import.meta.url)), 'index.mjs')
12
+
13
+ function runCli(args) {
14
+ return new Promise((resolve, reject) => {
15
+ const child = spawn(process.execPath, [cliPath, ...args], {
16
+ stdio: ['ignore', 'pipe', 'pipe'],
17
+ env: process.env,
18
+ })
19
+ let out = ''
20
+ let err = ''
21
+ child.stdout.on('data', (d) => {
22
+ out += d
23
+ })
24
+ child.stderr.on('data', (d) => {
25
+ err += d
26
+ })
27
+ child.on('close', (code) => {
28
+ if (code !== 0) reject(new Error(err || out || `exit ${code}`))
29
+ else resolve(out.trim())
30
+ })
31
+ })
32
+ }
33
+
34
+ const tools = [
35
+ 'login',
36
+ 'list',
37
+ 'create',
38
+ 'open',
39
+ 'preview',
40
+ 'pull',
41
+ 'push',
42
+ 'publish',
43
+ 'live',
44
+ 'visibility',
45
+ 'invite',
46
+ 'remove',
47
+ 'people',
48
+ 'tag',
49
+ 'untag',
50
+ 'move',
51
+ 'archive',
52
+ 'restore',
53
+ 'star',
54
+ 'unstar',
55
+ 'suggest-folder',
56
+ 'folder',
57
+ 'rename',
58
+ ]
59
+
60
+ function send(msg) {
61
+ process.stdout.write(`${JSON.stringify(msg)}\n`)
62
+ }
63
+
64
+ send({
65
+ jsonrpc: '2.0',
66
+ id: 1,
67
+ result: {
68
+ protocolVersion: '2024-11-05',
69
+ capabilities: { tools: {} },
70
+ serverInfo: { name: 'amorphous-cli', version: '0.1.0' },
71
+ },
72
+ })
73
+
74
+ const rl = createInterface({ input: process.stdin })
75
+ rl.on('line', async (line) => {
76
+ if (!line.trim()) return
77
+ let msg
78
+ try {
79
+ msg = JSON.parse(line)
80
+ } catch {
81
+ return
82
+ }
83
+ if (msg.method === 'tools/list') {
84
+ send({
85
+ jsonrpc: '2.0',
86
+ id: msg.id,
87
+ result: {
88
+ tools: tools.map((name) => ({
89
+ name,
90
+ description: (COMMAND_HELP[name] || `amorphous ${name}`).split('\n')[0],
91
+ inputSchema: {
92
+ type: 'object',
93
+ properties: {
94
+ args: {
95
+ type: 'array',
96
+ items: { type: 'string' },
97
+ description: 'CLI arguments after the command name',
98
+ },
99
+ },
100
+ },
101
+ })),
102
+ },
103
+ })
104
+ return
105
+ }
106
+ if (msg.method === 'tools/call') {
107
+ const name = msg.params?.name
108
+ const args = msg.params?.arguments?.args || []
109
+ try {
110
+ const out = await runCli([name, ...args])
111
+ send({
112
+ jsonrpc: '2.0',
113
+ id: msg.id,
114
+ result: { content: [{ type: 'text', text: out || '(ok)' }] },
115
+ })
116
+ } catch (e) {
117
+ send({
118
+ jsonrpc: '2.0',
119
+ id: msg.id,
120
+ result: {
121
+ content: [
122
+ {
123
+ type: 'text',
124
+ text: e instanceof Error ? e.message : String(e),
125
+ },
126
+ ],
127
+ isError: true,
128
+ },
129
+ })
130
+ }
131
+ }
132
+ })
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "amorphous-cli",
3
+ "version": "0.1.0",
4
+ "description": "Command line for Amorphous",
5
+ "type": "module",
6
+ "bin": {
7
+ "amorphous": "index.mjs",
8
+ "amorphous-mcp": "mcp.mjs"
9
+ },
10
+ "files": [
11
+ "index.mjs",
12
+ "mcp.mjs",
13
+ "lib"
14
+ ],
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "dependencies": {
19
+ "@supabase/supabase-js": "^2.117.2"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/djaxho/amorphous.git",
27
+ "directory": "cli"
28
+ },
29
+ "homepage": "https://amorphous.one"
30
+ }