@vectorasystems/cli 0.1.2 → 0.2.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.
@@ -0,0 +1,79 @@
1
+ // TUI hook — phase execution + SSE progress streaming
2
+ import { useState, useCallback } from 'react';
3
+ import { runPhase } from '../../lib/api-client.js';
4
+ import { streamPhaseProgress } from '../../lib/sse-client.js';
5
+ import { getConfig } from '../../lib/config-store.js';
6
+ import { requireToken } from '../../lib/auth-store.js';
7
+ import { collectWorkspaceSnapshot } from '../../lib/workspace-scanner.js';
8
+
9
+ export function usePhaseRun(projectId) {
10
+ const [status, setStatus] = useState('idle'); // idle | running | completed | failed
11
+ const [step, setStep] = useState('');
12
+ const [pct, setPct] = useState(0);
13
+ const [artifactCount, setArtifactCount] = useState(0);
14
+ const [error, setError] = useState(null);
15
+
16
+ const reset = useCallback(() => {
17
+ setStatus('idle');
18
+ setStep('');
19
+ setPct(0);
20
+ setArtifactCount(0);
21
+ setError(null);
22
+ }, []);
23
+
24
+ const run = useCallback(async (phase) => {
25
+ if (!projectId) return;
26
+ setStatus('running');
27
+ setStep('Starting…');
28
+ setPct(0);
29
+ setError(null);
30
+
31
+ try {
32
+ const { apiUrl } = getConfig();
33
+ const token = await requireToken();
34
+ const options = {};
35
+
36
+ if (phase === 'analyze-codebase') {
37
+ setStep('Scanning workspace…');
38
+ const snapshot = await collectWorkspaceSnapshot(process.cwd());
39
+ options.snapshot = snapshot;
40
+ }
41
+
42
+ const result = await runPhase(projectId, phase, options);
43
+ const { jobId } = result;
44
+
45
+ setStep('Queued');
46
+
47
+ for await (const { event, data } of streamPhaseProgress(apiUrl, jobId, token)) {
48
+ if (event === 'job:status') {
49
+ setStep(data.status ?? 'processing');
50
+ } else if (event === 'job:progress') {
51
+ setStep(data.step ?? data.message ?? '');
52
+ if (data.pct != null) setPct(data.pct);
53
+ } else if (event === 'job:completed') {
54
+ setArtifactCount(data.output?.artifacts?.length ?? 0);
55
+ setPct(100);
56
+ setStatus('completed');
57
+ return;
58
+ } else if (event === 'job:failed') {
59
+ setError(data.error ?? 'Phase failed');
60
+ setStatus('failed');
61
+ return;
62
+ } else if (event === 'job:timeout') {
63
+ setError('Timed out — phase may still be running on server');
64
+ setStatus('failed');
65
+ return;
66
+ }
67
+ }
68
+
69
+ // Stream ended without terminal event
70
+ setError('Stream ended unexpectedly — check status with vectora status');
71
+ setStatus('failed');
72
+ } catch (err) {
73
+ setError(err.message ?? 'Unknown error');
74
+ setStatus('failed');
75
+ }
76
+ }, [projectId]);
77
+
78
+ return { status, step, pct, artifactCount, error, run, reset };
79
+ }