@relipa/ai-flow-kit 0.0.9-beta.0 → 0.0.9-beta.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.
- package/bin/aiflow.js +474 -408
- package/custom/templates/shared/gate-workflow.md +8 -8
- package/custom/templates/tools/gemini.md +22 -12
- package/package.json +1 -1
- package/scripts/prompt.js +21 -0
- package/scripts/telemetry/cli.js +19 -8
- package/scripts/telemetry/record.js +6 -3
package/bin/aiflow.js
CHANGED
|
@@ -1,409 +1,475 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { program } = require('commander');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
const packageJson = require('../package.json');
|
|
6
|
-
const initCommand = require('../scripts/init');
|
|
7
|
-
const updateCommand = require('../scripts/update');
|
|
8
|
-
const doctorCommand = require('../scripts/doctor');
|
|
9
|
-
const useCommand = require('../scripts/use');
|
|
10
|
-
const TaskDetector = require('../scripts/detect');
|
|
11
|
-
const validateCommand = require('../scripts/validate');
|
|
12
|
-
const memoryCommand = require('../scripts/memory');
|
|
13
|
-
const contextCommand = require('../scripts/context');
|
|
14
|
-
const promptCommand = require('../scripts/prompt');
|
|
15
|
-
const removeCommand = require('../scripts/remove');
|
|
16
|
-
const guideCommand = require('../scripts/guide');
|
|
17
|
-
const telemetryCommand= require('../scripts/telemetry/cli');
|
|
18
|
-
const taskCommand = require('../scripts/task');
|
|
19
|
-
const checkpointCommand = require('../scripts/checkpoint');
|
|
20
|
-
const { record } = require('../scripts/telemetry/record');
|
|
21
|
-
const { updateTaskGateState } = require('../scripts/task');
|
|
22
|
-
|
|
23
|
-
// ── DEPRECATION WARNING ───────────────────────────────────────
|
|
24
|
-
if (!process.env.AIFLOW_IS_AK) {
|
|
25
|
-
console.warn(chalk.yellow('\n⚠ Warning: "aiflow" command is deprecated and will be removed in future versions.'));
|
|
26
|
-
console.warn(chalk.yellow('Please use the shorter "ak" command instead.\n'));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
program
|
|
30
|
-
.version(packageJson.version)
|
|
31
|
-
.description('AI Flow Kit CLI - AI-powered development workflows for teams');
|
|
32
|
-
|
|
33
|
-
// ── GLOBAL TELEMETRY HOOK ────────────────────────────────────
|
|
34
|
-
// We intercept raw argv here so we can catch --version, --help,
|
|
35
|
-
// and invalid commands *before* Commander exits the process.
|
|
36
|
-
// Also alias `-v` to commander's `-V` at the root only — subcommands still
|
|
37
|
-
// keep `-v` as `--verbose`. And alias `--fw` to `--framework`.
|
|
38
|
-
(() => {
|
|
39
|
-
if (process.argv[2] === '-v') process.argv[2] = '-V';
|
|
40
|
-
for (let i = 3; i < process.argv.length; i++) {
|
|
41
|
-
if (process.argv[i] === '--fw') process.argv[i] = '--framework';
|
|
42
|
-
}
|
|
43
|
-
const args = process.argv.slice(2);
|
|
44
|
-
let cmd = 'help';
|
|
45
|
-
if (args.length > 0) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
.
|
|
134
|
-
.
|
|
135
|
-
.
|
|
136
|
-
.option('-
|
|
137
|
-
.option('-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.
|
|
158
|
-
.
|
|
159
|
-
.
|
|
160
|
-
.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
.
|
|
164
|
-
.
|
|
165
|
-
.
|
|
166
|
-
.option('
|
|
167
|
-
.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
.
|
|
177
|
-
.
|
|
178
|
-
.
|
|
179
|
-
.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.command('
|
|
189
|
-
.alias('
|
|
190
|
-
.description('
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
.command('
|
|
206
|
-
.alias('
|
|
207
|
-
.description('
|
|
208
|
-
.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
.
|
|
212
|
-
.
|
|
213
|
-
.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
.
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.
|
|
225
|
-
.
|
|
226
|
-
.
|
|
227
|
-
.action((
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
.
|
|
237
|
-
.
|
|
238
|
-
.
|
|
239
|
-
.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
.
|
|
261
|
-
.
|
|
262
|
-
.
|
|
263
|
-
.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
.command('
|
|
273
|
-
.alias('
|
|
274
|
-
.description('
|
|
275
|
-
.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
.
|
|
279
|
-
.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
.
|
|
286
|
-
.
|
|
287
|
-
.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
.
|
|
305
|
-
.
|
|
306
|
-
.
|
|
307
|
-
.action((
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
.
|
|
337
|
-
.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
.
|
|
405
|
-
.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const packageJson = require('../package.json');
|
|
6
|
+
const initCommand = require('../scripts/init');
|
|
7
|
+
const updateCommand = require('../scripts/update');
|
|
8
|
+
const doctorCommand = require('../scripts/doctor');
|
|
9
|
+
const useCommand = require('../scripts/use');
|
|
10
|
+
const TaskDetector = require('../scripts/detect');
|
|
11
|
+
const validateCommand = require('../scripts/validate');
|
|
12
|
+
const memoryCommand = require('../scripts/memory');
|
|
13
|
+
const contextCommand = require('../scripts/context');
|
|
14
|
+
const promptCommand = require('../scripts/prompt');
|
|
15
|
+
const removeCommand = require('../scripts/remove');
|
|
16
|
+
const guideCommand = require('../scripts/guide');
|
|
17
|
+
const telemetryCommand= require('../scripts/telemetry/cli');
|
|
18
|
+
const taskCommand = require('../scripts/task');
|
|
19
|
+
const checkpointCommand = require('../scripts/checkpoint');
|
|
20
|
+
const { record } = require('../scripts/telemetry/record');
|
|
21
|
+
const { updateTaskGateState } = require('../scripts/task');
|
|
22
|
+
|
|
23
|
+
// ── DEPRECATION WARNING ───────────────────────────────────────
|
|
24
|
+
if (!process.env.AIFLOW_IS_AK) {
|
|
25
|
+
console.warn(chalk.yellow('\n⚠ Warning: "aiflow" command is deprecated and will be removed in future versions.'));
|
|
26
|
+
console.warn(chalk.yellow('Please use the shorter "ak" command instead.\n'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
program
|
|
30
|
+
.version(packageJson.version)
|
|
31
|
+
.description('AI Flow Kit CLI - AI-powered development workflows for teams');
|
|
32
|
+
|
|
33
|
+
// ── GLOBAL TELEMETRY HOOK ────────────────────────────────────
|
|
34
|
+
// We intercept raw argv here so we can catch --version, --help,
|
|
35
|
+
// and invalid commands *before* Commander exits the process.
|
|
36
|
+
// Also alias `-v` to commander's `-V` at the root only — subcommands still
|
|
37
|
+
// keep `-v` as `--verbose`. And alias `--fw` to `--framework`.
|
|
38
|
+
(() => {
|
|
39
|
+
if (process.argv[2] === '-v') process.argv[2] = '-V';
|
|
40
|
+
for (let i = 3; i < process.argv.length; i++) {
|
|
41
|
+
if (process.argv[i] === '--fw') process.argv[i] = '--framework';
|
|
42
|
+
}
|
|
43
|
+
const args = process.argv.slice(2);
|
|
44
|
+
let cmd = 'help';
|
|
45
|
+
if (args.length > 0) {
|
|
46
|
+
let first = args[0];
|
|
47
|
+
|
|
48
|
+
// 1. Phân giải alias cho root commands
|
|
49
|
+
const aliases = {
|
|
50
|
+
'i': 'init',
|
|
51
|
+
'u': 'use',
|
|
52
|
+
'p': 'prompt',
|
|
53
|
+
'd': 'detect',
|
|
54
|
+
't': 'task',
|
|
55
|
+
'ctx': 'context',
|
|
56
|
+
'cp': 'checkpoint',
|
|
57
|
+
'vl': 'validate',
|
|
58
|
+
'mem': 'memory',
|
|
59
|
+
'g': 'guide',
|
|
60
|
+
'rm': 'remove',
|
|
61
|
+
'up': 'update',
|
|
62
|
+
'sync': 'sync-skills',
|
|
63
|
+
'dr': 'doctor',
|
|
64
|
+
'tel': 'telemetry'
|
|
65
|
+
};
|
|
66
|
+
if (aliases[first]) {
|
|
67
|
+
first = aliases[first];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (['-V', '-v', '--version'].includes(first)) {
|
|
71
|
+
cmd = 'version';
|
|
72
|
+
} else if (['-h', '--help'].includes(first)) {
|
|
73
|
+
cmd = 'help';
|
|
74
|
+
} else if (first.startsWith('-')) {
|
|
75
|
+
cmd = 'unknown_flag';
|
|
76
|
+
if (args.includes('--help') || args.includes('-h')) cmd = 'help';
|
|
77
|
+
} else if (first === 'memory') {
|
|
78
|
+
const sec = args[1];
|
|
79
|
+
// Phân giải alias cho memory subcommands
|
|
80
|
+
let sub = sec;
|
|
81
|
+
if (sec && !sec.startsWith('-')) {
|
|
82
|
+
const memAliases = {
|
|
83
|
+
's': 'save',
|
|
84
|
+
'g': 'get',
|
|
85
|
+
'ls': 'list',
|
|
86
|
+
'sr': 'search',
|
|
87
|
+
'd': 'delete',
|
|
88
|
+
'cl': 'clear'
|
|
89
|
+
};
|
|
90
|
+
if (memAliases[sec]) sub = memAliases[sec];
|
|
91
|
+
cmd = `memory.${sub}`;
|
|
92
|
+
} else {
|
|
93
|
+
cmd = 'memory';
|
|
94
|
+
}
|
|
95
|
+
} else if (first === 'task') {
|
|
96
|
+
const sec = args[1];
|
|
97
|
+
// Phân giải alias subcommand của task
|
|
98
|
+
let sub = sec;
|
|
99
|
+
if (sec && !sec.startsWith('-')) {
|
|
100
|
+
const subAliases = {
|
|
101
|
+
'st': 'status',
|
|
102
|
+
'ls': 'list',
|
|
103
|
+
'p': 'pause',
|
|
104
|
+
'sw': 'switch',
|
|
105
|
+
'r': 'resume',
|
|
106
|
+
'rst': 'reset',
|
|
107
|
+
'rm': 'remove',
|
|
108
|
+
'n': 'next'
|
|
109
|
+
};
|
|
110
|
+
if (subAliases[sec]) sub = subAliases[sec];
|
|
111
|
+
cmd = `task.${sub}`;
|
|
112
|
+
} else {
|
|
113
|
+
cmd = 'task';
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
cmd = first;
|
|
117
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
118
|
+
cmd = `${first}.help`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Record everything except telemetry and gate actions (gate records its own rich event)
|
|
123
|
+
if (cmd !== 'telemetry' && !cmd.startsWith('telemetry.') && cmd !== 'gate') {
|
|
124
|
+
record('command.invoked', { command: cmd });
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
// ── init ──────────────────────────────────────────────────────
|
|
130
|
+
program
|
|
131
|
+
.command('init')
|
|
132
|
+
.alias('i')
|
|
133
|
+
.description('Initialize AI Flow Kit in your project')
|
|
134
|
+
.option('-f, --framework <types>', 'framework(s), comma-separated (e.g. spring-boot,reactjs)')
|
|
135
|
+
.option('-a, --adapter <types>', 'adapter(s), comma-separated (e.g. backlog,jira)')
|
|
136
|
+
.option('-e, --env <types>', 'AI environment(s)/tool(s), comma-separated (e.g. cursor,gemini,copilot)')
|
|
137
|
+
.option('--with-rtk', 'force enable RTK token compression hook')
|
|
138
|
+
.option('--no-rtk', 'skip RTK setup even if RTK is detected')
|
|
139
|
+
.action((options) => {
|
|
140
|
+
options.frameworks = options.framework
|
|
141
|
+
? options.framework.split(',').map(s => s.trim()).filter(Boolean)
|
|
142
|
+
: [];
|
|
143
|
+
options.adapters = options.adapter
|
|
144
|
+
? options.adapter.split(',').map(s => s.trim()).filter(Boolean)
|
|
145
|
+
: [];
|
|
146
|
+
options.aiTools = options.env
|
|
147
|
+
? options.env.split(',').map(s => s.trim()).filter(Boolean)
|
|
148
|
+
: Object.keys(require('../scripts/init').AI_TOOL_FILES || {}).filter(t => t !== 'generic');
|
|
149
|
+
|
|
150
|
+
initCommand(options);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// ── use ───────────────────────────────────────────────────────
|
|
154
|
+
program
|
|
155
|
+
.command('use [target]')
|
|
156
|
+
.alias('u')
|
|
157
|
+
.description('Load context from ticket, version, or file')
|
|
158
|
+
.option('-m, --manual', 'manual context entry')
|
|
159
|
+
.option('-f, --file <path>', 'load from file')
|
|
160
|
+
.option('-s, --save <name>', 'save as named context')
|
|
161
|
+
.option('-c, --coms', 'load all comments (alias for --with-comments)')
|
|
162
|
+
.option('--with-comments', 'load all comments')
|
|
163
|
+
.option('--cid <id>', 'load a specific comment by ID')
|
|
164
|
+
.option('--clast <n>', 'load the last N comments', parseInt)
|
|
165
|
+
.option('--cfrom <id>', 'load comments from ID N onward', parseInt)
|
|
166
|
+
.option('--cto <id>', 'load comments up to ID N', parseInt)
|
|
167
|
+
.option('-F, --fast', 'fast mode: minimal Q&A, concise requirement doc (Default)')
|
|
168
|
+
.option('-U, --full', 'full mode: force complete analysis with Q&A (default)')
|
|
169
|
+
.action((target, options) => {
|
|
170
|
+
useCommand(target, options);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ── prompt ────────────────────────────────────────────────────
|
|
174
|
+
program
|
|
175
|
+
.command('prompt [type]')
|
|
176
|
+
.alias('p')
|
|
177
|
+
.description('Generate AI prompt with context and rules')
|
|
178
|
+
.option('-l, --list', 'list available prompt types')
|
|
179
|
+
.option('-o, --output <file>', 'save to file')
|
|
180
|
+
.option('-L, --lang <lang>', 'language: english (default) or vietnamese')
|
|
181
|
+
.option('-d, --detail <level>', 'detail level: minimal | standard (default) | comprehensive')
|
|
182
|
+
.action((type, options) => {
|
|
183
|
+
promptCommand(type, options);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// ── detect ────────────────────────────────────────────────────
|
|
187
|
+
program
|
|
188
|
+
.command('detect [description]')
|
|
189
|
+
.alias('d')
|
|
190
|
+
.description('Auto-detect task type from description')
|
|
191
|
+
.option('-v, --verbose', 'show detection details')
|
|
192
|
+
.option('-t, --threshold <number>', 'confidence threshold (0-100)')
|
|
193
|
+
.action((description, options) => {
|
|
194
|
+
const detector = new TaskDetector();
|
|
195
|
+
const threshold = options.threshold ? parseInt(options.threshold) / 100 : 0.8;
|
|
196
|
+
const result = detector.detect(description, threshold);
|
|
197
|
+
console.log(chalk.cyan('\nTask Detection Results:\n'));
|
|
198
|
+
console.log(detector.formatOutput(result, options.verbose));
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// ── task ─────────────────────────────────────────────────────
|
|
202
|
+
const taskCmd = program.command('task').alias('t').description('Manage multiple tasks — pause, switch, resume');
|
|
203
|
+
|
|
204
|
+
taskCmd
|
|
205
|
+
.command('status')
|
|
206
|
+
.alias('st')
|
|
207
|
+
.description('Show active task and pending tasks')
|
|
208
|
+
.action(() => { taskCommand('status'); });
|
|
209
|
+
|
|
210
|
+
taskCmd
|
|
211
|
+
.command('list')
|
|
212
|
+
.alias('ls')
|
|
213
|
+
.description('List all saved tasks')
|
|
214
|
+
.action(() => { taskCommand('list'); });
|
|
215
|
+
|
|
216
|
+
taskCmd
|
|
217
|
+
.command('pause')
|
|
218
|
+
.alias('p')
|
|
219
|
+
.description('Pause current task and save progress')
|
|
220
|
+
.option('-n, --note <text>', 'note about why you are pausing')
|
|
221
|
+
.action((opts) => { taskCommand('pause', { note: opts.note }); });
|
|
222
|
+
|
|
223
|
+
taskCmd
|
|
224
|
+
.command('switch <ticket-id>')
|
|
225
|
+
.alias('sw')
|
|
226
|
+
.description('Pause current task and switch to another')
|
|
227
|
+
.action((ticketId) => { taskCommand('switch', { taskId: ticketId }); });
|
|
228
|
+
|
|
229
|
+
taskCmd
|
|
230
|
+
.command('resume <ticket-id>')
|
|
231
|
+
.alias('r')
|
|
232
|
+
.description('Resume a paused task')
|
|
233
|
+
.action((ticketId) => { taskCommand('resume', { taskId: ticketId }); });
|
|
234
|
+
|
|
235
|
+
taskCmd
|
|
236
|
+
.command('reset <ticket-id>')
|
|
237
|
+
.alias('rst')
|
|
238
|
+
.description('Reset task to Gate 1 (keeps ticket context, clears gate progress)')
|
|
239
|
+
.action((ticketId) => { taskCommand('reset', { taskId: ticketId }); });
|
|
240
|
+
|
|
241
|
+
taskCmd
|
|
242
|
+
.command('remove <ticket-id>')
|
|
243
|
+
.alias('rm')
|
|
244
|
+
.description('Permanently delete all saved data for a task')
|
|
245
|
+
.action((ticketId) => { taskCommand('remove', { taskId: ticketId }); });
|
|
246
|
+
|
|
247
|
+
taskCmd
|
|
248
|
+
.command('next')
|
|
249
|
+
.alias('n')
|
|
250
|
+
.description('Approve current gate and prepare next session (saves state for resume)')
|
|
251
|
+
.option('-t, --ticket <id>', 'ticket ID (defaults to active task)')
|
|
252
|
+
.action((opts) => {
|
|
253
|
+
taskCommand('next', { taskId: opts.ticket });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// ── context ───────────────────────────────────────────────────
|
|
257
|
+
program
|
|
258
|
+
.command('context [action]')
|
|
259
|
+
.alias('ctx')
|
|
260
|
+
.description('Manage task contexts (list|show|save <name>|clear)')
|
|
261
|
+
.option('-s, --save <name>', 'save current context with name')
|
|
262
|
+
.option('-l, --load <name>', 'load saved context by name')
|
|
263
|
+
.option('-d, --delete <name>', 'delete saved context')
|
|
264
|
+
.option('--clear', 'clear all saved contexts')
|
|
265
|
+
.option('--show', 'show current context')
|
|
266
|
+
.action((action, options) => {
|
|
267
|
+
contextCommand(action, options);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// ── checkpoint ────────────────────────────────────────────────
|
|
271
|
+
program
|
|
272
|
+
.command('checkpoint')
|
|
273
|
+
.alias('cp')
|
|
274
|
+
.description('Record token usage checkpoint (called by AI during gate work)')
|
|
275
|
+
.requiredOption('-g, --gate <n>', 'gate number (1–5)', parseInt)
|
|
276
|
+
.requiredOption('-s, --step <name>', 'step name (e.g. "tests-written")')
|
|
277
|
+
.requiredOption('-n, --tokens <n>', 'estimated token count', parseInt)
|
|
278
|
+
.option('-t, --ticket <id>', 'ticket ID (defaults to active task)')
|
|
279
|
+
.action((opts) => {
|
|
280
|
+
checkpointCommand({ gate: opts.gate, step: opts.step, tokens: opts.tokens, ticket: opts.ticket });
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// ── validate ──────────────────────────────────────────────────
|
|
284
|
+
program
|
|
285
|
+
.command('validate <file>')
|
|
286
|
+
.alias('vl')
|
|
287
|
+
.description('Validate output against team rules')
|
|
288
|
+
.option('-r, --ruleset <set>', 'rule set: default | strict | lenient', 'default')
|
|
289
|
+
.option('-v, --verbose', 'detailed report')
|
|
290
|
+
.option('-x, --fix', 'auto-fix trailing whitespace')
|
|
291
|
+
.action((file, options) => {
|
|
292
|
+
validateCommand(file, {
|
|
293
|
+
ruleset: options.ruleset,
|
|
294
|
+
verbose: options.verbose,
|
|
295
|
+
fix: options.fix
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// ── memory ────────────────────────────────────────────────────
|
|
300
|
+
// Sub-commands to avoid the ambiguous "memory <action> --save key" pattern
|
|
301
|
+
const memCmd = program.command('memory').alias('mem').description('Manage team knowledge and memory');
|
|
302
|
+
|
|
303
|
+
memCmd
|
|
304
|
+
.command('save <key> <value>')
|
|
305
|
+
.alias('s')
|
|
306
|
+
.description('Save a memory entry')
|
|
307
|
+
.action((key, value) => { memoryCommand('save', { key, value }); });
|
|
308
|
+
|
|
309
|
+
memCmd
|
|
310
|
+
.command('get <key>')
|
|
311
|
+
.alias('g')
|
|
312
|
+
.description('Retrieve a memory entry')
|
|
313
|
+
.action((key) => { memoryCommand('get', { key }); });
|
|
314
|
+
|
|
315
|
+
memCmd
|
|
316
|
+
.command('list')
|
|
317
|
+
.alias('ls')
|
|
318
|
+
.description('List all memories')
|
|
319
|
+
.action(() => { memoryCommand('list'); });
|
|
320
|
+
|
|
321
|
+
memCmd
|
|
322
|
+
.command('search <query>')
|
|
323
|
+
.alias('sr')
|
|
324
|
+
.description('Search memories by keyword')
|
|
325
|
+
.action((query) => { memoryCommand('search', { query }); });
|
|
326
|
+
|
|
327
|
+
memCmd
|
|
328
|
+
.command('delete <key>')
|
|
329
|
+
.alias('d')
|
|
330
|
+
.description('Delete a memory entry')
|
|
331
|
+
.action((key) => { memoryCommand('delete', { key }); });
|
|
332
|
+
|
|
333
|
+
memCmd
|
|
334
|
+
.command('clear')
|
|
335
|
+
.alias('cl')
|
|
336
|
+
.description('Clear all memories')
|
|
337
|
+
.action(() => { memoryCommand('clear'); });
|
|
338
|
+
|
|
339
|
+
// ── guide ─────────────────────────────────────────────────────
|
|
340
|
+
program
|
|
341
|
+
.command('guide')
|
|
342
|
+
.alias('g')
|
|
343
|
+
.description('Show quickstart guide, architecture, and command reference')
|
|
344
|
+
.option('-f, --flow', 'show architecture & flow diagram only')
|
|
345
|
+
.option('-c, --commands', 'show command reference only')
|
|
346
|
+
.action((options) => {
|
|
347
|
+
guideCommand(options);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// ── telemetry feedback helper ─────────────────────────────────
|
|
351
|
+
function showTelResult(result, label) {
|
|
352
|
+
try {
|
|
353
|
+
if (!result) return;
|
|
354
|
+
if (result.ok) {
|
|
355
|
+
console.log(chalk.green(` [tel] ✓ ${label} logged`));
|
|
356
|
+
} else if (result.reason === 'disabled') {
|
|
357
|
+
console.log(chalk.yellow(` [tel] ⚠ skipped — telemetry is disabled (run 'aiflow telemetry enable')`));
|
|
358
|
+
} else if (result.reason === 'opted-out') {
|
|
359
|
+
console.log(chalk.yellow(` [tel] ⚠ skipped — repo has .aiflow/no-telemetry opt-out`));
|
|
360
|
+
} else if (result.reason === 'no-url') {
|
|
361
|
+
console.log(chalk.yellow(` [tel] ⚠ skipped — no server URL configured (run 'aiflow telemetry enable')`));
|
|
362
|
+
} else if (result.error) {
|
|
363
|
+
console.log(chalk.yellow(` [tel] ⚠ error logging '${label}': ${result.error}`));
|
|
364
|
+
}
|
|
365
|
+
} catch (e) { /* never block main flow */ }
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ── gate (telemetry for gate workflow events) ─────────────────
|
|
369
|
+
program
|
|
370
|
+
.command('gate <number> <action>')
|
|
371
|
+
.description('Log a gate workflow event (start|approved) — called by AI during gate workflow')
|
|
372
|
+
.option('--ticket <id>', 'ticket ID')
|
|
373
|
+
.option('--ai-tool <tool>', 'AI tool name')
|
|
374
|
+
.action((number, action, options) => {
|
|
375
|
+
const gateNum = parseInt(number);
|
|
376
|
+
if (isNaN(gateNum) || gateNum < 1 || gateNum > 5) return;
|
|
377
|
+
if (!['start', 'approved'].includes(action)) return;
|
|
378
|
+
|
|
379
|
+
const ticketId = options.ticket || '';
|
|
380
|
+
|
|
381
|
+
const telResult = record(`gate.${action}`, {
|
|
382
|
+
gate: gateNum,
|
|
383
|
+
ticket_id: ticketId,
|
|
384
|
+
command: `gate${gateNum}.${action}`,
|
|
385
|
+
ai_tool: options.aiTool || ''
|
|
386
|
+
});
|
|
387
|
+
showTelResult(telResult, `gate${gateNum}.${action}`);
|
|
388
|
+
|
|
389
|
+
// Keep task-state.json currentGate in sync (silent — never blocks the AI)
|
|
390
|
+
if (ticketId) {
|
|
391
|
+
updateTaskGateState(ticketId, gateNum, action).catch(() => {});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (action === 'approved') {
|
|
395
|
+
console.log(chalk.cyan(`\n Gate ${gateNum} approved!`));
|
|
396
|
+
console.log(chalk.yellow(` Pro-Tip: To avoid context pollution, it's recommended to start a fresh chat session.`));
|
|
397
|
+
console.log(chalk.gray(` Run: aiflow task next${ticketId ? ` --ticket ${ticketId}` : ''} to save progress,`));
|
|
398
|
+
console.log(chalk.gray(` then open a NEW chatbox and type "continue".\n`));
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// ── remove ────────────────────────────────────────────────────
|
|
403
|
+
program
|
|
404
|
+
.command('remove')
|
|
405
|
+
.alias('rm')
|
|
406
|
+
.description('Remove ai-flow-kit from project, a cached version, or uninstall globally')
|
|
407
|
+
.option('--version <ver>', 'remove a specific cached version from .aiflow/versions/')
|
|
408
|
+
.option('-g, --global', 'uninstall the global npm package (removes `aiflow` command)')
|
|
409
|
+
.action((options) => {
|
|
410
|
+
removeCommand(options);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// ── update ────────────────────────────────────────────────────
|
|
414
|
+
program
|
|
415
|
+
.command('update')
|
|
416
|
+
.alias('up')
|
|
417
|
+
.description('Update to latest version')
|
|
418
|
+
.option('-f, --force', 'force update even if already on latest')
|
|
419
|
+
.action((options) => {
|
|
420
|
+
updateCommand(options);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// ── sync-skills ───────────────────────────────────────────────
|
|
424
|
+
program
|
|
425
|
+
.command('sync-skills')
|
|
426
|
+
.alias('sync')
|
|
427
|
+
.description('Manually synchronize AI Instruction files with local custom skills')
|
|
428
|
+
.action(async () => {
|
|
429
|
+
const projectDir = process.cwd();
|
|
430
|
+
const { setupFramework, AI_TOOL_FILES, ensureAiflowGitignored } = require('../scripts/init');
|
|
431
|
+
const fs = require('fs-extra');
|
|
432
|
+
const path = require('path');
|
|
433
|
+
const chalk = require('chalk');
|
|
434
|
+
|
|
435
|
+
const stateFile = path.join(projectDir, '.aiflow', 'state.json');
|
|
436
|
+
if (!(await fs.pathExists(stateFile))) {
|
|
437
|
+
console.log(chalk.red('Project is not initialized. Please run `aiflow init` first.'));
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const state = await fs.readJson(stateFile);
|
|
442
|
+
const frameworks = state.frameworks || [];
|
|
443
|
+
const selectedTools = state.aiTools || Object.keys(AI_TOOL_FILES);
|
|
444
|
+
|
|
445
|
+
console.log(chalk.cyan('⟳ Syncing AI Instruction files...'));
|
|
446
|
+
for (const fw of frameworks) {
|
|
447
|
+
await setupFramework(projectDir, fw, frameworks.length > 1, selectedTools);
|
|
448
|
+
}
|
|
449
|
+
await ensureAiflowGitignored(projectDir);
|
|
450
|
+
console.log(chalk.green('✨ Sync completed!'));
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// ── doctor ────────────────────────────────────────────────────
|
|
454
|
+
program
|
|
455
|
+
.command('doctor')
|
|
456
|
+
.alias('dr')
|
|
457
|
+
.description('Health check of AI Flow Kit setup')
|
|
458
|
+
.option('-t, --ticket <id>', 'show token breakdown for specific ticket')
|
|
459
|
+
.option('-v, --verbose', 'detailed output')
|
|
460
|
+
.action((opts) => {
|
|
461
|
+
doctorCommand({ ticket: opts.ticket, verbose: opts.verbose });
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// ── telemetry ──────────────────────────────────────────────────
|
|
465
|
+
program
|
|
466
|
+
.command('telemetry [action]')
|
|
467
|
+
.alias('tel')
|
|
468
|
+
.description('Manage telemetry logging (enable|disable|status|log)')
|
|
469
|
+
.option('--event <event>', 'event name (for log action)')
|
|
470
|
+
.option('--detail <detail>', 'detail string (for log action)')
|
|
471
|
+
.action((action, options) => {
|
|
472
|
+
telemetryCommand(action || 'status', options);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
program.parse(process.argv);
|
|
@@ -29,8 +29,8 @@ AI actively reads ticket + source code to understand the requirement:
|
|
|
29
29
|
|
|
30
30
|
DO NOT just check format — **understand the content and propose solutions**.
|
|
31
31
|
|
|
32
|
-
> **Telemetry:** Run `
|
|
33
|
-
> Run `
|
|
32
|
+
> **Telemetry:** Run `ak gate 1 start --ticket [ticket-id]` when starting this gate (auto-start or when developer types "start"/"Gate 1").
|
|
33
|
+
> Run `ak gate 1 approved --ticket [ticket-id]` immediately when APPROVED is received.
|
|
34
34
|
|
|
35
35
|
---
|
|
36
36
|
|
|
@@ -43,8 +43,8 @@ DO NOT just check format — **understand the content and propose solutions**.
|
|
|
43
43
|
- Display: "GATE 2 PAUSED: type APPROVED to start coding".
|
|
44
44
|
- CODE WILL NOT BE GENERATED until "APPROVED" is received.
|
|
45
45
|
|
|
46
|
-
> **Telemetry:** Run `
|
|
47
|
-
> Run `
|
|
46
|
+
> **Telemetry:** Run `ak gate 2 start --ticket [ticket-id]` when starting this gate.
|
|
47
|
+
> Run `ak gate 2 approved --ticket [ticket-id]` immediately when APPROVED is received.
|
|
48
48
|
|
|
49
49
|
---
|
|
50
50
|
|
|
@@ -57,7 +57,7 @@ Only runs after Gate 2 has been APPROVED.
|
|
|
57
57
|
- Write tests FIRST — run to confirm FAIL -> implement -> PASS.
|
|
58
58
|
- Bug fix EXTRA: `superpowers:systematic-debugging` + `investigate-bug` skill first.
|
|
59
59
|
|
|
60
|
-
> **Telemetry:** Run `
|
|
60
|
+
> **Telemetry:** Run `ak gate 3 start --ticket [ticket-id]` when starting this gate.
|
|
61
61
|
|
|
62
62
|
---
|
|
63
63
|
|
|
@@ -75,8 +75,8 @@ Then: "GATE 4 PAUSED: type APPROVED or BUG: [description]"
|
|
|
75
75
|
- Coding bug -> fix -> repeat Gate 4.
|
|
76
76
|
- Requirement bug -> return to Gate 1.
|
|
77
77
|
|
|
78
|
-
> **Telemetry:** Run `
|
|
79
|
-
> Run `
|
|
78
|
+
> **Telemetry:** Run `ak gate 4 start --ticket [ticket-id]` when starting this gate.
|
|
79
|
+
> Run `ak gate 4 approved --ticket [ticket-id]` immediately when APPROVED is received.
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
@@ -87,4 +87,4 @@ Only runs after Gate 4 has been APPROVED.
|
|
|
87
87
|
**INVOKE:** `superpowers:requesting-code-review`
|
|
88
88
|
Guide on creating a Pull Request with the ticket link.
|
|
89
89
|
|
|
90
|
-
> **Telemetry:** Run `
|
|
90
|
+
> **Telemetry:** Run `ak gate 5 start --ticket [ticket-id]` when starting this gate.
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
# Gemini AI System Instructions
|
|
2
|
-
|
|
3
|
-
You are an expert AI assistant specialized in this project's stack. Follow the Gate Workflow and Team Rules strictly.
|
|
4
|
-
|
|
5
|
-
> **Important:** When starting a session, always read `.aiflow/context/current.json` to load ticket context and check the `plan/` directory for existing progress.
|
|
6
|
-
|
|
7
|
-
If no instructions are automatically followed, wait for the developer to type **"start"** or **"Gate 1"** to start the analysis.
|
|
8
|
-
|
|
9
|
-
## Interaction Rules:
|
|
10
|
-
- **COLLABORATIVE SKILLS:** When a skill (like `read-study-requirement`) says to "ask one question at a time", you MUST stop and wait for the developer's reply before proceeding.
|
|
11
|
-
- **NEVER BATCH QUESTIONS:** Only ask one question per message.
|
|
12
|
-
- **WAIT FOR APPROVAL:** Do not move to the next Gate until you receive "APPROVED".
|
|
1
|
+
# Gemini AI System Instructions
|
|
2
|
+
|
|
3
|
+
You are an expert AI assistant specialized in this project's stack. Follow the Gate Workflow and Team Rules strictly.
|
|
4
|
+
|
|
5
|
+
> **Important:** When starting a session, always read `.aiflow/context/current.json` to load ticket context and check the `plan/` directory for existing progress.
|
|
6
|
+
|
|
7
|
+
If no instructions are automatically followed, wait for the developer to type **"start"** or **"Gate 1"** to start the analysis.
|
|
8
|
+
|
|
9
|
+
## Interaction Rules:
|
|
10
|
+
- **COLLABORATIVE SKILLS:** When a skill (like `read-study-requirement`) says to "ask one question at a time", you MUST stop and wait for the developer's reply before proceeding.
|
|
11
|
+
- **NEVER BATCH QUESTIONS:** Only ask one question per message.
|
|
12
|
+
- **WAIT FOR APPROVAL:** Do not move to the next Gate until you receive "APPROVED".
|
|
13
|
+
- **PROJECT CONVENTIONS:** Before writing any output file (plan, requirement, summary), read `custom/rules/project-conventions.md`. These rules override upstream skill defaults.
|
|
14
|
+
|
|
15
|
+
## Telemetry Command (detect once, use everywhere)
|
|
16
|
+
|
|
17
|
+
Before the first gate, run this to detect the correct `ak` command for your environment:
|
|
18
|
+
```bash
|
|
19
|
+
command -v ak >/dev/null 2>&1 && echo "USE: ak" || echo "USE: ak.cmd"
|
|
20
|
+
```
|
|
21
|
+
Use whichever prints (e.g. `ak` on native Linux/Mac/Windows, `ak.cmd` on WSL without ak installed).
|
|
22
|
+
All `ak gate ...` examples below assume the detected command. Substitute accordingly.
|
package/package.json
CHANGED
package/scripts/prompt.js
CHANGED
|
@@ -335,6 +335,12 @@ function buildPrompt(template, ctx, rules, options, env = 'claude') {
|
|
|
335
335
|
lines.push('');
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
// ── Telemetry instructions ─────────────────────────────────
|
|
339
|
+
const ticketArg = ctx?.taskId ? ` --ticket ${ctx.taskId}` : '';
|
|
340
|
+
const akCmd = isWSL() ? 'ak.cmd' : 'ak';
|
|
341
|
+
lines.push(`> **Telemetry (required):** When **starting** each gate run \`${akCmd} gate N start${ticketArg}\`. When **APPROVED** run \`${akCmd} gate N approved${ticketArg}\`. Replace N with the gate number (1–5).`);
|
|
342
|
+
lines.push('');
|
|
343
|
+
|
|
338
344
|
// ── Context section ────────────────────────────────────────
|
|
339
345
|
if (ctx) {
|
|
340
346
|
lines.push('## Context');
|
|
@@ -409,6 +415,14 @@ function buildPrompt(template, ctx, rules, options, env = 'claude') {
|
|
|
409
415
|
return lines.join('\n');
|
|
410
416
|
}
|
|
411
417
|
|
|
418
|
+
function isWSL() {
|
|
419
|
+
if (process.platform !== 'linux') return false;
|
|
420
|
+
try {
|
|
421
|
+
const version = require('fs').readFileSync('/proc/version', 'utf-8');
|
|
422
|
+
return /microsoft|wsl/i.test(version);
|
|
423
|
+
} catch (_) { return false; }
|
|
424
|
+
}
|
|
425
|
+
|
|
412
426
|
function copyToClipboard(text) {
|
|
413
427
|
try {
|
|
414
428
|
if (process.platform === 'win32') {
|
|
@@ -420,6 +434,13 @@ function copyToClipboard(text) {
|
|
|
420
434
|
);
|
|
421
435
|
} else if (process.platform === 'darwin') {
|
|
422
436
|
spawnSync('pbcopy', [], { input: text, encoding: 'utf8', stdio: ['pipe', 'ignore', 'ignore'] });
|
|
437
|
+
} else if (isWSL()) {
|
|
438
|
+
spawnSync(
|
|
439
|
+
'powershell.exe',
|
|
440
|
+
['-NoProfile', '-NonInteractive', '-Command',
|
|
441
|
+
'[Console]::InputEncoding = [System.Text.Encoding]::UTF8; Set-Clipboard -Value ([Console]::In.ReadToEnd())'],
|
|
442
|
+
{ input: text, encoding: 'utf8', stdio: ['pipe', 'ignore', 'ignore'] }
|
|
443
|
+
);
|
|
423
444
|
} else {
|
|
424
445
|
const r = spawnSync('xclip', ['-selection', 'clipboard'], { input: text, encoding: 'utf8', stdio: ['pipe', 'ignore', 'ignore'] });
|
|
425
446
|
if (r.error) spawnSync('xsel', ['--clipboard', '--input'], { input: text, encoding: 'utf8', stdio: ['pipe', 'ignore', 'ignore'] });
|
package/scripts/telemetry/cli.js
CHANGED
|
@@ -232,12 +232,23 @@ module.exports = function telemetryCommand(action, options) {
|
|
|
232
232
|
};
|
|
233
233
|
|
|
234
234
|
function logEvent(options) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
record(event);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
235
|
+
try {
|
|
236
|
+
const { record } = require('./record');
|
|
237
|
+
const event = (options && options.event) || 'custom_event';
|
|
238
|
+
const detail = (options && options.detail) || '';
|
|
239
|
+
const result = detail ? record(event, { detail }) : record(event);
|
|
240
|
+
|
|
241
|
+
if (!result) return;
|
|
242
|
+
if (result.ok) {
|
|
243
|
+
console.log(chalk.green(` [tel] ✓ '${event}' logged`));
|
|
244
|
+
} else if (result.reason === 'disabled') {
|
|
245
|
+
console.log(chalk.yellow(` [tel] ⚠ skipped — telemetry is disabled (run 'aiflow telemetry enable')`));
|
|
246
|
+
} else if (result.reason === 'opted-out') {
|
|
247
|
+
console.log(chalk.yellow(` [tel] ⚠ skipped — repo has .aiflow/no-telemetry opt-out`));
|
|
248
|
+
} else if (result.reason === 'no-url') {
|
|
249
|
+
console.log(chalk.yellow(` [tel] ⚠ skipped — no server URL configured (run 'aiflow telemetry enable')`));
|
|
250
|
+
} else if (result.error) {
|
|
251
|
+
console.log(chalk.yellow(` [tel] ⚠ error logging '${event}': ${result.error}`));
|
|
252
|
+
}
|
|
253
|
+
} catch (e) { /* never block main flow */ }
|
|
243
254
|
}
|
|
@@ -61,8 +61,9 @@ function logInternalError(err) {
|
|
|
61
61
|
function record(eventType, payload = {}) {
|
|
62
62
|
try {
|
|
63
63
|
const cfg = loadConfig();
|
|
64
|
-
if (!cfg.enabled) return;
|
|
65
|
-
if (isRepoOptedOut()) return;
|
|
64
|
+
if (!cfg.enabled) return { ok: false, reason: 'disabled' };
|
|
65
|
+
if (isRepoOptedOut()) return { ok: false, reason: 'opted-out' };
|
|
66
|
+
if (!cfg.apps_script_url) return { ok: false, reason: 'no-url' };
|
|
66
67
|
|
|
67
68
|
ensureDirectories();
|
|
68
69
|
|
|
@@ -90,7 +91,7 @@ function record(eventType, payload = {}) {
|
|
|
90
91
|
|
|
91
92
|
const lineStr = signEvent(event, cfg.team_secret);
|
|
92
93
|
fs.appendFileSync(BUFFER_PATH, lineStr + '\n');
|
|
93
|
-
|
|
94
|
+
|
|
94
95
|
// Check if buffer is getting huge (> 10MB cap). Simple clear
|
|
95
96
|
try {
|
|
96
97
|
if (fs.statSync(BUFFER_PATH).size > 10 * 1024 * 1024) {
|
|
@@ -99,8 +100,10 @@ function record(eventType, payload = {}) {
|
|
|
99
100
|
} catch (e) {}
|
|
100
101
|
|
|
101
102
|
maybeSpawnFlusher(cfg);
|
|
103
|
+
return { ok: true };
|
|
102
104
|
} catch (err) {
|
|
103
105
|
logInternalError(err);
|
|
106
|
+
return { ok: false, error: err.message };
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
|