ronds_ai 0.1.13 → 0.1.14

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/bin/ronds_ai.js CHANGED
@@ -1,265 +1,265 @@
1
- #!/usr/bin/env node
2
-
3
- const { runCodeRecord, saveCliError } = require('../lib/code_record');
4
- const {
5
- ENVIRONMENT_VARIABLE_NAME,
6
- getRefreshNotice,
7
- getPersistentWorkerHint,
8
- isPersistentWorkerUpdateSupported,
9
- runCheckRecord,
10
- savePersistentWorkerId,
11
- } = require('../lib/check_record');
12
- const { runDoctor } = require('../lib/doctor');
13
- const { deployHooks } = require('../lib/hooks_deploy');
14
- const { promptForText, promptYesNo } = require('../lib/skills_prompt');
15
-
16
- function writeWorkerSummary(result) {
17
- process.stderr.write(`${ENVIRONMENT_VARIABLE_NAME}: ${result.workerId.value || '(空)'}\n`);
18
- process.stderr.write(`来源: ${result.workerId.source || '未设置'}\n`);
19
- }
20
-
21
- async function maybeUpdateWorkerId() {
22
- const initialResult = runCheckRecord(process.cwd());
23
- writeWorkerSummary(initialResult);
24
- process.stderr.write(`${getPersistentWorkerHint()}\n`);
25
-
26
- if (!isPersistentWorkerUpdateSupported()) {
27
- return;
28
- }
29
-
30
- const shouldModify = await promptYesNo(`是否要修改 ${ENVIRONMENT_VARIABLE_NAME}?`);
31
- if (!shouldModify) {
32
- return;
33
- }
34
-
35
- const nextValue = await promptForText(`请输入新的 ${ENVIRONMENT_VARIABLE_NAME}:`, initialResult.workerId.value);
36
- if (!nextValue) {
37
- process.stderr.write(`输入为空,已跳过更新 ${ENVIRONMENT_VARIABLE_NAME}。\n`);
38
- return;
39
- }
40
-
41
- const saveResult = savePersistentWorkerId(nextValue);
42
- process.stderr.write(`${ENVIRONMENT_VARIABLE_NAME} 已保存到 ${saveResult.location}。\n`);
43
-
44
- const refreshNotice = getRefreshNotice();
45
- if (refreshNotice) {
46
- process.stderr.write(`${refreshNotice}\n`);
47
- }
48
-
49
- writeWorkerSummary(runCheckRecord(process.cwd()));
50
- }
51
-
52
- function shouldPromptWorkerUpdate(args) {
53
- return !args.includes('--no-prompt');
54
- }
55
-
56
- function stripCheckFlags(args) {
57
- return args.filter((value) => value !== '--no-prompt');
58
- }
59
-
60
- const SUPPORTED_SOURCES = new Set(['claude', 'cursor', 'codex']);
61
-
62
- function printUsage() {
63
- process.stderr.write([
64
- 'Usage:',
65
- ' ronds_ai record <tool>',
66
- ' ronds_ai check record',
67
- ' ronds_ai doctor <tool>',
68
- ' ronds_ai hooks deploy',
69
- ' ronds_ai skills install <name> [--tool claude,codex,cursor] [--scope project|global] [--project-dir <path>] [--force]',
70
- '',
71
- 'Supported tools:',
72
- ' claude',
73
- ' cursor',
74
- ' codex',
75
- '',
76
- 'Examples:',
77
- ' npx ronds_ai@latest record claude',
78
- ' npx ronds_ai@latest record cursor',
79
- ' npx ronds_ai@latest check record',
80
- ' npx ronds_ai@latest doctor claude',
81
- ' npx ronds_ai@latest doctor cursor',
82
- ' npx ronds_ai@latest hooks deploy',
83
- ' npx ronds_ai@latest skills install demo-skill',
84
- ' npx ronds_ai@latest skills install demo-skill --tool claude --scope global',
85
- ' npx ronds_ai@latest skills install demo-skill --tool codex,cursor --scope project',
86
- ].join('\n'));
87
- process.stderr.write('\n');
88
- }
89
-
90
- async function runHooksCommand(args) {
91
- const [action] = args;
92
-
93
- if (action !== 'deploy') {
94
- throw new Error('Unsupported hooks command');
95
- }
96
-
97
- const result = deployHooks(process.cwd());
98
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
99
- }
100
-
101
- async function runCheckCommand(args) {
102
- const filteredArgs = stripCheckFlags(args);
103
- const [target] = filteredArgs;
104
-
105
- if (target !== 'record') {
106
- throw new Error('Unsupported check command');
107
- }
108
-
109
- const result = runCheckRecord(process.cwd());
110
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
111
-
112
- if (shouldPromptWorkerUpdate(args)) {
113
- await maybeUpdateWorkerId();
114
- }
115
-
116
- if (!result.ok) {
117
- process.exitCode = 1;
118
- }
119
- }
120
-
121
- function parseSkillsInstallArgs(args) {
122
- const options = {
123
- tool: '',
124
- scope: '',
125
- projectDir: '',
126
- force: false,
127
- };
128
- const positional = [];
129
-
130
- for (let index = 0; index < args.length; index += 1) {
131
- const value = args[index];
132
-
133
- if (value === '--force') {
134
- options.force = true;
135
- continue;
136
- }
137
-
138
- if (value === '--tool') {
139
- index += 1;
140
- options.tool = args[index] || '';
141
- continue;
142
- }
143
-
144
- if (value.startsWith('--tool=')) {
145
- options.tool = value.slice('--tool='.length);
146
- continue;
147
- }
148
-
149
- if (value === '--scope') {
150
- index += 1;
151
- options.scope = args[index] || '';
152
- continue;
153
- }
154
-
155
- if (value.startsWith('--scope=')) {
156
- options.scope = value.slice('--scope='.length);
157
- continue;
158
- }
159
-
160
- if (value === '--project-dir') {
161
- index += 1;
162
- options.projectDir = args[index] || '';
163
- continue;
164
- }
165
-
166
- if (value.startsWith('--project-dir=')) {
167
- options.projectDir = value.slice('--project-dir='.length);
168
- continue;
169
- }
170
-
171
- if (value.startsWith('--')) {
172
- throw new Error(`Unsupported option: ${value}`);
173
- }
174
-
175
- positional.push(value);
176
- }
177
-
178
- const [name] = positional;
179
- if (!name) {
180
- throw new Error('Missing skill name');
181
- }
182
-
183
- return {
184
- name,
185
- options,
186
- };
187
- }
188
-
189
- async function runSkillsCommand(args) {
190
- const { runSkillsInstall } = require('../lib/skills_install');
191
- const [action, ...rest] = args;
192
-
193
- if (action !== 'install') {
194
- throw new Error('Unsupported skills command');
195
- }
196
-
197
- const { name, options } = parseSkillsInstallArgs(rest);
198
- const result = await runSkillsInstall(name, options);
199
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
200
- }
201
-
202
- async function run() {
203
- const [, , command, ...args] = process.argv;
204
-
205
- if (command === 'record') {
206
- const [source] = args;
207
- const normalizedSource = String(source || '').trim().toLowerCase();
208
-
209
- if (!SUPPORTED_SOURCES.has(normalizedSource)) {
210
- throw new Error(`Unsupported record tool: ${source || ''}`);
211
- }
212
-
213
- await runCodeRecord(normalizedSource);
214
- return;
215
- }
216
-
217
- if (command === 'doctor') {
218
- const [tool] = args;
219
- const normalizedTool = String(tool || '').trim().toLowerCase();
220
-
221
- if (!SUPPORTED_SOURCES.has(normalizedTool)) {
222
- throw new Error(`Unsupported doctor tool: ${tool || ''}`);
223
- }
224
-
225
- const result = runDoctor(normalizedTool, process.cwd());
226
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
227
- return;
228
- }
229
-
230
- if (command === 'check') {
231
- await runCheckCommand(args);
232
- return;
233
- }
234
-
235
- if (command === 'hooks') {
236
- await runHooksCommand(args);
237
- return;
238
- }
239
-
240
- if (command === 'skills') {
241
- await runSkillsCommand(args);
242
- return;
243
- }
244
-
245
- throw new Error(`Unsupported command: ${command || ''}`);
246
- }
247
-
248
- run().catch((error) => {
249
- const [, , command, ...args] = process.argv;
250
- let savedPath = '';
251
-
252
- try {
253
- savedPath = saveCliError(error, { command: command || '', args });
254
- } catch {
255
- savedPath = '';
256
- }
257
-
258
- printUsage();
259
- const message = error instanceof Error ? error.stack || error.message : String(error);
260
- process.stderr.write(`${message}\n`);
261
- if (savedPath) {
262
- process.stderr.write(`cli error saved to ${savedPath}\n`);
263
- }
264
- process.exitCode = 1;
265
- });
1
+ #!/usr/bin/env node
2
+
3
+ const { runCodeRecord, saveCliError } = require('../lib/code_record');
4
+ const {
5
+ ENVIRONMENT_VARIABLE_NAME,
6
+ getRefreshNotice,
7
+ getPersistentWorkerHint,
8
+ isPersistentWorkerUpdateSupported,
9
+ runCheckRecord,
10
+ savePersistentWorkerId,
11
+ } = require('../lib/check_record');
12
+ const { runDoctor } = require('../lib/doctor');
13
+ const { deployHooks } = require('../lib/hooks_deploy');
14
+ const { promptForText, promptYesNo } = require('../lib/skills_prompt');
15
+
16
+ function writeWorkerSummary(result) {
17
+ process.stderr.write(`${ENVIRONMENT_VARIABLE_NAME}: ${result.workerId.value || '(空)'}\n`);
18
+ process.stderr.write(`来源: ${result.workerId.source || '未设置'}\n`);
19
+ }
20
+
21
+ async function maybeUpdateWorkerId() {
22
+ const initialResult = runCheckRecord(process.cwd());
23
+ writeWorkerSummary(initialResult);
24
+ process.stderr.write(`${getPersistentWorkerHint()}\n`);
25
+
26
+ if (!isPersistentWorkerUpdateSupported()) {
27
+ return;
28
+ }
29
+
30
+ const shouldModify = await promptYesNo(`是否要修改 ${ENVIRONMENT_VARIABLE_NAME}?`);
31
+ if (!shouldModify) {
32
+ return;
33
+ }
34
+
35
+ const nextValue = await promptForText(`请输入新的 ${ENVIRONMENT_VARIABLE_NAME}:`, initialResult.workerId.value);
36
+ if (!nextValue) {
37
+ process.stderr.write(`输入为空,已跳过更新 ${ENVIRONMENT_VARIABLE_NAME}。\n`);
38
+ return;
39
+ }
40
+
41
+ const saveResult = savePersistentWorkerId(nextValue);
42
+ process.stderr.write(`${ENVIRONMENT_VARIABLE_NAME} 已保存到 ${saveResult.location}。\n`);
43
+
44
+ const refreshNotice = getRefreshNotice();
45
+ if (refreshNotice) {
46
+ process.stderr.write(`${refreshNotice}\n`);
47
+ }
48
+
49
+ writeWorkerSummary(runCheckRecord(process.cwd()));
50
+ }
51
+
52
+ function shouldPromptWorkerUpdate(args) {
53
+ return !args.includes('--no-prompt');
54
+ }
55
+
56
+ function stripCheckFlags(args) {
57
+ return args.filter((value) => value !== '--no-prompt');
58
+ }
59
+
60
+ const SUPPORTED_SOURCES = new Set(['claude', 'cursor', 'codex']);
61
+
62
+ function printUsage() {
63
+ process.stderr.write([
64
+ 'Usage:',
65
+ ' ronds_ai record <tool>',
66
+ ' ronds_ai check record',
67
+ ' ronds_ai doctor <tool>',
68
+ ' ronds_ai hooks deploy',
69
+ ' ronds_ai skills install <name> [--tool claude,codex,cursor] [--scope project|global] [--project-dir <path>] [--force]',
70
+ '',
71
+ 'Supported tools:',
72
+ ' claude',
73
+ ' cursor',
74
+ ' codex',
75
+ '',
76
+ 'Examples:',
77
+ ' npx ronds_ai@latest record claude',
78
+ ' npx ronds_ai@latest record cursor',
79
+ ' npx ronds_ai@latest check record',
80
+ ' npx ronds_ai@latest doctor claude',
81
+ ' npx ronds_ai@latest doctor cursor',
82
+ ' npx ronds_ai@latest hooks deploy',
83
+ ' npx ronds_ai@latest skills install demo-skill',
84
+ ' npx ronds_ai@latest skills install demo-skill --tool claude --scope global',
85
+ ' npx ronds_ai@latest skills install demo-skill --tool codex,cursor --scope project',
86
+ ].join('\n'));
87
+ process.stderr.write('\n');
88
+ }
89
+
90
+ async function runHooksCommand(args) {
91
+ const [action] = args;
92
+
93
+ if (action !== 'deploy') {
94
+ throw new Error('Unsupported hooks command');
95
+ }
96
+
97
+ const result = deployHooks(process.cwd());
98
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
99
+ }
100
+
101
+ async function runCheckCommand(args) {
102
+ const filteredArgs = stripCheckFlags(args);
103
+ const [target] = filteredArgs;
104
+
105
+ if (target !== 'record') {
106
+ throw new Error('Unsupported check command');
107
+ }
108
+
109
+ const result = runCheckRecord(process.cwd());
110
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
111
+
112
+ if (shouldPromptWorkerUpdate(args)) {
113
+ await maybeUpdateWorkerId();
114
+ }
115
+
116
+ if (!result.ok) {
117
+ process.exitCode = 1;
118
+ }
119
+ }
120
+
121
+ function parseSkillsInstallArgs(args) {
122
+ const options = {
123
+ tool: '',
124
+ scope: '',
125
+ projectDir: '',
126
+ force: false,
127
+ };
128
+ const positional = [];
129
+
130
+ for (let index = 0; index < args.length; index += 1) {
131
+ const value = args[index];
132
+
133
+ if (value === '--force') {
134
+ options.force = true;
135
+ continue;
136
+ }
137
+
138
+ if (value === '--tool') {
139
+ index += 1;
140
+ options.tool = args[index] || '';
141
+ continue;
142
+ }
143
+
144
+ if (value.startsWith('--tool=')) {
145
+ options.tool = value.slice('--tool='.length);
146
+ continue;
147
+ }
148
+
149
+ if (value === '--scope') {
150
+ index += 1;
151
+ options.scope = args[index] || '';
152
+ continue;
153
+ }
154
+
155
+ if (value.startsWith('--scope=')) {
156
+ options.scope = value.slice('--scope='.length);
157
+ continue;
158
+ }
159
+
160
+ if (value === '--project-dir') {
161
+ index += 1;
162
+ options.projectDir = args[index] || '';
163
+ continue;
164
+ }
165
+
166
+ if (value.startsWith('--project-dir=')) {
167
+ options.projectDir = value.slice('--project-dir='.length);
168
+ continue;
169
+ }
170
+
171
+ if (value.startsWith('--')) {
172
+ throw new Error(`Unsupported option: ${value}`);
173
+ }
174
+
175
+ positional.push(value);
176
+ }
177
+
178
+ const [name] = positional;
179
+ if (!name) {
180
+ throw new Error('Missing skill name');
181
+ }
182
+
183
+ return {
184
+ name,
185
+ options,
186
+ };
187
+ }
188
+
189
+ async function runSkillsCommand(args) {
190
+ const { runSkillsInstall } = require('../lib/skills_install');
191
+ const [action, ...rest] = args;
192
+
193
+ if (action !== 'install') {
194
+ throw new Error('Unsupported skills command');
195
+ }
196
+
197
+ const { name, options } = parseSkillsInstallArgs(rest);
198
+ const result = await runSkillsInstall(name, options);
199
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
200
+ }
201
+
202
+ async function run() {
203
+ const [, , command, ...args] = process.argv;
204
+
205
+ if (command === 'record') {
206
+ const [source] = args;
207
+ const normalizedSource = String(source || '').trim().toLowerCase();
208
+
209
+ if (!SUPPORTED_SOURCES.has(normalizedSource)) {
210
+ throw new Error(`Unsupported record tool: ${source || ''}`);
211
+ }
212
+
213
+ await runCodeRecord(normalizedSource);
214
+ return;
215
+ }
216
+
217
+ if (command === 'doctor') {
218
+ const [tool] = args;
219
+ const normalizedTool = String(tool || '').trim().toLowerCase();
220
+
221
+ if (!SUPPORTED_SOURCES.has(normalizedTool)) {
222
+ throw new Error(`Unsupported doctor tool: ${tool || ''}`);
223
+ }
224
+
225
+ const result = runDoctor(normalizedTool, process.cwd());
226
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
227
+ return;
228
+ }
229
+
230
+ if (command === 'check') {
231
+ await runCheckCommand(args);
232
+ return;
233
+ }
234
+
235
+ if (command === 'hooks') {
236
+ await runHooksCommand(args);
237
+ return;
238
+ }
239
+
240
+ if (command === 'skills') {
241
+ await runSkillsCommand(args);
242
+ return;
243
+ }
244
+
245
+ throw new Error(`Unsupported command: ${command || ''}`);
246
+ }
247
+
248
+ run().catch((error) => {
249
+ const [, , command, ...args] = process.argv;
250
+ let savedPath = '';
251
+
252
+ try {
253
+ savedPath = saveCliError(error, { command: command || '', args });
254
+ } catch {
255
+ savedPath = '';
256
+ }
257
+
258
+ printUsage();
259
+ const message = error instanceof Error ? error.stack || error.message : String(error);
260
+ process.stderr.write(`${message}\n`);
261
+ if (savedPath) {
262
+ process.stderr.write(`cli error saved to ${savedPath}\n`);
263
+ }
264
+ process.exitCode = 1;
265
+ });