@1agents/acp-service 0.1.0 → 0.1.1

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.
@@ -1,7 +1,82 @@
1
1
  #!/usr/bin/env node
2
+ import { execFileSync, spawn } from 'node:child_process';
3
+ import { createRequire } from 'node:module';
4
+ import path from 'node:path';
5
+ import fs from 'node:fs';
2
6
  import { serveAcpService } from '../src/server.js';
3
7
  import { attachProcessSignalHandlers } from '../src/bridge.js';
4
- function parseArgs(args) {
8
+ const require = createRequire(import.meta.url);
9
+ const rawArgs = process.argv.slice(2);
10
+ const invokedBin = path.basename(process.argv[1] || 'acp-service', path.extname(process.argv[1] || ''));
11
+ function getAcpxCliPath() {
12
+ return require.resolve('@scottzx/1acp/dist/cli.js');
13
+ }
14
+ function getPackageVersion() {
15
+ try {
16
+ const pkgPath = new URL('../package.json', import.meta.url);
17
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
18
+ return pkg.version || '0.1.1';
19
+ }
20
+ catch {
21
+ return '0.1.1';
22
+ }
23
+ }
24
+ function printServeHelp(binName) {
25
+ console.log(`用法: ${binName} serve [选项]
26
+
27
+ 启动 DreamMate Network ACP Agent 运行时常驻服务(HTTP + WebSocket)
28
+
29
+ 选项:
30
+ --port, -p <n> 指定监听端口(默认: 36812)
31
+ --host <ip> 指定绑定 IP(默认: 0.0.0.0)
32
+ --no-report 不向本机 node agent (36908) 报备
33
+ -h, --help 显示帮助信息
34
+ `);
35
+ }
36
+ function printUnifiedHelp(binName) {
37
+ let baseHelp = '';
38
+ try {
39
+ const cliPath = getAcpxCliPath();
40
+ baseHelp = execFileSync(process.execPath, [cliPath, '--help'], { encoding: 'utf-8' });
41
+ }
42
+ catch (err) {
43
+ baseHelp = String(err);
44
+ }
45
+ let help = baseHelp
46
+ .replace(/^Usage:\s+acpx/m, `Usage: ${binName}`)
47
+ .replace(/Headless CLI client for the Agent Client Protocol/, 'Headless CLI client & DreamMate Network runtime service for the Agent Client Protocol (ACP)');
48
+ const serverCommands = `Commands:
49
+ serve [options] Start DreamMate Network ACP runtime daemon (HTTP + WS)`;
50
+ help = help.replace(/^Commands:/m, serverCommands);
51
+ const serverOptions = `Options:
52
+ --port, -p <n> Server listen port (for serve, default: 36812)
53
+ --host <ip> Server bind IP (for serve, default: 0.0.0.0)
54
+ --no-report Do not report to local dreammate-node (36908)`;
55
+ help = help.replace(/^Options:/m, serverOptions);
56
+ help = help.replaceAll(/acpx /g, `${binName} `);
57
+ help = help.replace(/^Examples:\n/m, `Examples:\n ${binName} serve --port 36812\n`);
58
+ console.log(help);
59
+ }
60
+ function forwardToCli(args) {
61
+ const cliPath = getAcpxCliPath();
62
+ const child = spawn(process.execPath, [cliPath, ...args], {
63
+ stdio: 'inherit',
64
+ env: process.env,
65
+ });
66
+ child.on('exit', (code, signal) => {
67
+ if (signal) {
68
+ process.kill(process.pid, signal);
69
+ }
70
+ else {
71
+ process.exit(code ?? 0);
72
+ }
73
+ });
74
+ child.on('error', (err) => {
75
+ console.error(`[${invokedBin}] 进程启动失败:`, err.message);
76
+ process.exit(1);
77
+ });
78
+ }
79
+ function parseServerArgs(args) {
5
80
  const options = {};
6
81
  for (let i = 0; i < args.length; i++) {
7
82
  const arg = args[i];
@@ -10,32 +85,73 @@ function parseArgs(args) {
10
85
  if (val)
11
86
  options.port = Number.parseInt(val, 10);
12
87
  }
13
- else if (arg === '--host' || arg === '-h') {
88
+ else if (arg === '--host') {
14
89
  options.host = args[++i];
15
90
  }
16
91
  else if (arg === '--no-report') {
17
92
  options.report = false;
18
93
  }
19
- else if (arg === '--help') {
20
- console.log(`用法: acp-service [选项]
21
-
22
- 选项:
23
- --port, -p <n> 指定监听端口(默认: 36812)
24
- --host, -h <ip> 指定绑定 IP(默认: 0.0.0.0)
25
- --no-report 不向本机 node agent (36908) 报备
26
- --help 显示帮助信息
27
- `);
28
- process.exit(0);
29
- }
30
94
  }
31
95
  return options;
32
96
  }
33
- const options = parseArgs(process.argv.slice(2));
34
- try {
97
+ async function runServer(options) {
35
98
  attachProcessSignalHandlers();
36
- await serveAcpService(options);
99
+ try {
100
+ await serveAcpService(options);
101
+ }
102
+ catch (error) {
103
+ console.error(`[${invokedBin}] 启动失败:`, error instanceof Error ? error.message : error);
104
+ process.exit(1);
105
+ }
37
106
  }
38
- catch (error) {
39
- console.error('[acp-service] 启动失败:', error instanceof Error ? error.message : error);
40
- process.exit(1);
107
+ async function main() {
108
+ const isServe = rawArgs[0] === 'serve' || rawArgs[0] === 'run';
109
+ const hasServerExplicitFlag = rawArgs[0] === '--port' ||
110
+ rawArgs[0] === '-p' ||
111
+ rawArgs[0] === '--host' ||
112
+ rawArgs[0] === '--no-report';
113
+ // 1. Version
114
+ if (rawArgs[0] === '-V' || rawArgs[0] === '--version') {
115
+ const version = getPackageVersion();
116
+ console.log(`@1agents/acp-service v${version}`);
117
+ return;
118
+ }
119
+ // 2. Help
120
+ if (rawArgs[0] === '--help' ||
121
+ (rawArgs[0] === '-h' && rawArgs.length === 1) ||
122
+ rawArgs[0] === 'help') {
123
+ printUnifiedHelp(invokedBin);
124
+ return;
125
+ }
126
+ // 3. Serve command explicit
127
+ if (isServe) {
128
+ const serveArgs = rawArgs.slice(1);
129
+ if (serveArgs.includes('--help') || serveArgs.includes('-h')) {
130
+ printServeHelp(invokedBin);
131
+ return;
132
+ }
133
+ const options = parseServerArgs(serveArgs);
134
+ await runServer(options);
135
+ return;
136
+ }
137
+ // 4. Server explicit flags e.g. `acp-service --port 36812`
138
+ if (hasServerExplicitFlag) {
139
+ const options = parseServerArgs(rawArgs);
140
+ await runServer(options);
141
+ return;
142
+ }
143
+ // 5. No arguments
144
+ if (rawArgs.length === 0) {
145
+ // If invoked as acp-service without arguments, default to running the server!
146
+ if (invokedBin === 'acp-service') {
147
+ await runServer({});
148
+ return;
149
+ }
150
+ // If invoked as 1acp or acpx with no arguments, forward to cli which displays help
151
+ forwardToCli(rawArgs);
152
+ return;
153
+ }
154
+ // 6. Any other subcommand or arguments -> forward directly to @scottzx/1acp CLI
155
+ forwardToCli(rawArgs);
41
156
  }
157
+ await main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/acp-service",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "DreamMate Network ACP Agent Runtime Service: cross-agent execution runtime for Claude Code, Grok, Codex and ACP-compatible agents.",
5
5
  "keywords": [
6
6
  "dreammate",
@@ -30,7 +30,9 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "bin": {
33
- "acp-service": "dist/bin/acp-service.js"
33
+ "acp-service": "dist/bin/acp-service.js",
34
+ "1acp": "dist/bin/acp-service.js",
35
+ "acpx": "dist/bin/acp-service.js"
34
36
  },
35
37
  "files": [
36
38
  "dist",