@magclaw/cli-core 0.1.39 → 0.1.40
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/package.json +1 -1
- package/src/cli-core/args.js +50 -0
- package/src/cli-core/team-sharing-delegate.js +19 -0
- package/src/cli.js +10 -646
- package/src/team-memory-hooks.js +0 -319
- package/src/team-sharing.js +0 -664
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const DEFAULT_PROFILE = 'default';
|
|
2
|
+
|
|
3
|
+
function safeProfileName(value = DEFAULT_PROFILE) {
|
|
4
|
+
return String(value || DEFAULT_PROFILE).trim().replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || DEFAULT_PROFILE;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function parseFlagKey(item) {
|
|
8
|
+
return item
|
|
9
|
+
.replace(/^--/, '')
|
|
10
|
+
.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function parseCli(argv = process.argv, env = process.env) {
|
|
14
|
+
const args = argv.slice(2);
|
|
15
|
+
const command = args[0] && !args[0].startsWith('-') ? args.shift() : 'connect';
|
|
16
|
+
const flags = {};
|
|
17
|
+
const positionals = [];
|
|
18
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
19
|
+
const item = args[index];
|
|
20
|
+
if (item === '-h') {
|
|
21
|
+
flags.help = true;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (item === '-V') {
|
|
25
|
+
flags.version = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!item.startsWith('--')) {
|
|
29
|
+
positionals.push(item);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const equalsIndex = item.indexOf('=');
|
|
33
|
+
if (equalsIndex > 2) {
|
|
34
|
+
flags[parseFlagKey(item.slice(0, equalsIndex))] = item.slice(equalsIndex + 1);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const key = parseFlagKey(item);
|
|
38
|
+
const next = args[index + 1];
|
|
39
|
+
if (!next || next.startsWith('--')) {
|
|
40
|
+
flags[key] = true;
|
|
41
|
+
} else {
|
|
42
|
+
flags[key] = next;
|
|
43
|
+
index += 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
flags._ = positionals;
|
|
47
|
+
flags.profileExplicit = Boolean(flags.profile);
|
|
48
|
+
flags.profile = safeProfileName(flags.profile || env.MAGCLAW_DAEMON_PROFILE || DEFAULT_PROFILE);
|
|
49
|
+
return { command, flags };
|
|
50
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export async function runExternalTeamSharingCommand(args = [], env = process.env) {
|
|
4
|
+
const command = String(env.MAGCLAW_TEAM_SHARING_BIN || 'team-sharing').trim() || 'team-sharing';
|
|
5
|
+
const result = spawnSync(command, args, {
|
|
6
|
+
stdio: 'inherit',
|
|
7
|
+
env,
|
|
8
|
+
shell: process.platform === 'win32',
|
|
9
|
+
});
|
|
10
|
+
if (result.error) {
|
|
11
|
+
if (result.error.code === 'ENOENT') {
|
|
12
|
+
throw new Error('Team Sharing is packaged separately. Run `npx @magclaw/team-sharing@latest setup` or install it globally with `npm i -g @magclaw/team-sharing`.');
|
|
13
|
+
}
|
|
14
|
+
throw result.error;
|
|
15
|
+
}
|
|
16
|
+
if (typeof result.status === 'number' && result.status !== 0) {
|
|
17
|
+
process.exitCode = result.status;
|
|
18
|
+
}
|
|
19
|
+
}
|