@raytrace-cli/cli 0.20.3 → 0.21.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.
- package/dist/dashboard/assets/{index-BwQ16X6S.js → index-BUzKpPr2.js} +3 -3
- package/dist/dashboard/assets/{index-_SXHv625.css → index-CKf_5Rwt.css} +1 -1
- package/dist/dashboard/index.html +2 -2
- package/package.json +1 -1
- package/proxy/evidence-store.mjs +5 -0
- package/proxy/raytace-proxy.mjs +13 -2
- package/proxy/star-prompt.mjs +62 -0
- package/proxy/star-prompt.test.mjs +134 -0
- package/src/commands.mjs +0 -2
- package/src/local-sandbox.mjs +3 -0
- package/src/proxy-process.mjs +1 -1
- package/src/star.mjs +100 -29
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<title>RayTrace — Agent trace forensics</title>
|
|
7
7
|
<meta name="description" content="Evidence-backed traces and live counterfactual forks for coding agents." />
|
|
8
8
|
<link rel="icon" href="/favicon.svg?v=raytrace-cube" type="image/svg+xml" />
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-BUzKpPr2.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CKf_5Rwt.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body class="antialiased">
|
|
13
13
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytrace-cli/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"mcpName": "io.github.Godcreatebugs/raytrace",
|
|
5
5
|
"description": "See what your coding agent did: traces, tool calls, cost and step-by-step evidence for Claude Code and Codex.",
|
|
6
6
|
"license": "MIT",
|
package/proxy/evidence-store.mjs
CHANGED
|
@@ -967,6 +967,11 @@ export function openEvidenceStore(file, { readOnly = false } = {}) {
|
|
|
967
967
|
});
|
|
968
968
|
},
|
|
969
969
|
|
|
970
|
+
/** Total number of recorded prompt turns across all agents. */
|
|
971
|
+
turnCount() {
|
|
972
|
+
return Number(q('SELECT COUNT(*) AS n FROM agent_turns').get()?.n ?? 0);
|
|
973
|
+
},
|
|
974
|
+
|
|
970
975
|
close() { db.close(); },
|
|
971
976
|
};
|
|
972
977
|
|
package/proxy/raytace-proxy.mjs
CHANGED
|
@@ -33,6 +33,7 @@ import { promptContext, contextItemText, contextSummaryRequest, parseContextSumm
|
|
|
33
33
|
import { recapOutline, recapRequest, recapText, parseRecap, DEFAULT_OBSERVER } from './run-recap.mjs';
|
|
34
34
|
import { groupByCall, assessmentRequests, combineGroup, rulesOnly, withProbabilities } from './call-assessment.mjs';
|
|
35
35
|
import { prepareStep, attributionKey, proposerRequest, parseProposals, candidates, jevRequests, combine, withoutJev } from './step-attribution.mjs';
|
|
36
|
+
import { STAR_ACTIONS, recordStarPromptState, starPromptStatus } from './star-prompt.mjs';
|
|
36
37
|
|
|
37
38
|
try { loadEnvFile(); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
38
39
|
const routing = providerConfig();
|
|
@@ -43,7 +44,7 @@ const summaryModel = process.env.RAYTACE_SUMMARY_MODEL
|
|
|
43
44
|
: (routing.models.oss || routing.defaultModel);
|
|
44
45
|
// Bumped whenever the dashboard needs endpoints an older proxy lacks; the
|
|
45
46
|
// CLI restarts a proxy it started that reports less (src/proxy-process.mjs).
|
|
46
|
-
const PROXY_API =
|
|
47
|
+
const PROXY_API = 6;
|
|
47
48
|
const fallbackSession = { session_id: randomUUID(), session_started_at: new Date().toISOString() };
|
|
48
49
|
|
|
49
50
|
const port = Number(process.env.RAYTACE_PORT || 8797);
|
|
@@ -581,6 +582,7 @@ const server = createServer(async (req, res) => {
|
|
|
581
582
|
// Which proxy this is, so the CLI can tell an outdated one still running
|
|
582
583
|
// after an upgrade (src/proxy-process.mjs PROXY_API) and replace it.
|
|
583
584
|
if (req.method === 'GET' && req.url === '/raytace/version') return json(200, { api: PROXY_API });
|
|
585
|
+
if (req.method === 'GET' && req.url === '/raytace/star-prompt') return json(200, starPromptStatus({ dataDir, prompts: db.turnCount() }));
|
|
584
586
|
if (req.method === 'GET' && req.url === '/raytace/account') return json(200, { signed_in: false, plan: 'free', features: [] });
|
|
585
587
|
if (req.method === 'GET' && req.url === '/raytace/models') return json(200, { models: routing.mode === 'openrouter' ? Object.entries(routing.models).map(([alias, id]) => ({ alias, id })) : [], execution_available: routing.mode === 'openrouter' });
|
|
586
588
|
const stepRoute = req.url?.match(/^\/raytace\/steps\/([a-f0-9-]+)\/(\d+)$/);
|
|
@@ -690,11 +692,20 @@ const server = createServer(async (req, res) => {
|
|
|
690
692
|
ingestClaudeCode(path, { final: CLAUDE_CODE_FINAL_EVENTS.has(note.hook_event_name) && note.more !== true });
|
|
691
693
|
return;
|
|
692
694
|
}
|
|
693
|
-
if (localApi && (req.method !== 'POST' || !['/raytace/experiments', '/raytace/step-runs','/raytace/explanations', '/raytace/attribution', '/raytace/summaries', '/raytace/prompt-context/summary', '/raytace/forks', '/raytace/recap'].includes(req.url))) return json(404, { error: 'Unknown local endpoint.' });
|
|
695
|
+
if (localApi && (req.method !== 'POST' || !['/raytace/experiments', '/raytace/step-runs','/raytace/explanations', '/raytace/attribution', '/raytace/summaries', '/raytace/prompt-context/summary', '/raytace/forks', '/raytace/recap', '/raytace/star-prompt'].includes(req.url))) return json(404, { error: 'Unknown local endpoint.' });
|
|
694
696
|
if (localApi && (req.headers['x-raytace-experiment'] !== '1' || !req.headers['content-type']?.includes('application/json'))) return json(403, { error: 'Use the experiment control in the dashboard.' });
|
|
695
697
|
const parts = []; let bytes = 0;
|
|
696
698
|
for await (const part of req) { bytes += part.length; if (bytes > (localApi ? 600_000 : 20_000_000)) return json(413, { error: 'Request too large.' }); parts.push(part); }
|
|
697
699
|
const requestBody = Buffer.concat(parts);
|
|
700
|
+
if (req.method === 'POST' && req.url === '/raytace/star-prompt') {
|
|
701
|
+
try {
|
|
702
|
+
const body = JSON.parse(requestBody);
|
|
703
|
+
const action = String(body?.action ?? '');
|
|
704
|
+
if (!STAR_ACTIONS.has(action)) return json(400, { error: 'Unknown star prompt action.' });
|
|
705
|
+
const source = body?.source === 'sidebar' ? 'sidebar' : 'dashboard';
|
|
706
|
+
return json(200, { ok: true, state: recordStarPromptState(dataDir, action, source) });
|
|
707
|
+
} catch (error) { return json(400, { error: error.message }); }
|
|
708
|
+
}
|
|
698
709
|
if (req.method === 'POST' && req.url === '/raytace/forks') {
|
|
699
710
|
try { return json(202, await playground.create(JSON.parse(requestBody))); }
|
|
700
711
|
catch (error) { return json(400, { error: error.message }); }
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Shared state for the one-time GitHub star prompt across the CLI and the
|
|
2
|
+
// local dashboard. Kept in ~/.raytrace/star-prompt.json so acting on either
|
|
3
|
+
// surface permanently remembers the choice for both, with zero outbound calls.
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
export const STAR_URL = 'https://github.com/Godcreatebugs/raytrace-cli';
|
|
8
|
+
export const WEBSITE_URL = 'https://raytracer.si';
|
|
9
|
+
export const STAR_PROMPT_THRESHOLD = 3;
|
|
10
|
+
export const STAR_PROMPT_FILE = 'star-prompt.json';
|
|
11
|
+
export const STAR_ACTIONS = new Set(['opened', 'already_starred', 'dismissed']);
|
|
12
|
+
const STAR_SOURCES = new Set(['cli', 'dashboard', 'sidebar']);
|
|
13
|
+
|
|
14
|
+
export function starPromptOptedOut(env = process.env) {
|
|
15
|
+
const value = env?.RAYTRACE_NO_STAR_PROMPT;
|
|
16
|
+
return value === '1' || value === 'true';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Read the saved star-prompt state from `dataDir`, or null when pending/missing. */
|
|
20
|
+
export function readStarPromptState(dataDir) {
|
|
21
|
+
if (!dataDir) return null;
|
|
22
|
+
const file = join(dataDir, STAR_PROMPT_FILE);
|
|
23
|
+
if (!existsSync(file)) return null;
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
26
|
+
if (!parsed || typeof parsed !== 'object' || !STAR_ACTIONS.has(parsed.status)) return null;
|
|
27
|
+
return {
|
|
28
|
+
status: parsed.status,
|
|
29
|
+
source: STAR_SOURCES.has(parsed.source) ? parsed.source : 'cli',
|
|
30
|
+
at: typeof parsed.at === 'string' ? parsed.at : null,
|
|
31
|
+
};
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Persist the user's star-prompt choice in `dataDir` with owner-only permissions. */
|
|
38
|
+
export function recordStarPromptState(dataDir, action, source = 'cli', now = Date.now()) {
|
|
39
|
+
if (!STAR_ACTIONS.has(action)) throw new Error(`Invalid star prompt action: ${action}`);
|
|
40
|
+
const safeSource = STAR_SOURCES.has(source) ? source : 'cli';
|
|
41
|
+
const state = { status: action, source: safeSource, at: new Date(now).toISOString() };
|
|
42
|
+
mkdirSync(dataDir, { recursive: true });
|
|
43
|
+
const file = join(dataDir, STAR_PROMPT_FILE);
|
|
44
|
+
writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
45
|
+
try { chmodSync(file, 0o600); } catch { /* filesystem without POSIX modes */ }
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Eligibility and metadata for the star prompt given `dataDir` and recorded prompt count. */
|
|
50
|
+
export function starPromptStatus({ dataDir, prompts = 0, threshold = STAR_PROMPT_THRESHOLD, env = process.env } = {}) {
|
|
51
|
+
const count = Math.max(0, Math.floor(Number(prompts) || 0));
|
|
52
|
+
const state = readStarPromptState(dataDir);
|
|
53
|
+
const eligible = !starPromptOptedOut(env) && !state && count >= threshold;
|
|
54
|
+
return {
|
|
55
|
+
eligible,
|
|
56
|
+
prompts: count,
|
|
57
|
+
threshold,
|
|
58
|
+
status: state?.status ?? 'pending',
|
|
59
|
+
url: STAR_URL,
|
|
60
|
+
website_url: WEBSITE_URL,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { once } from 'node:events';
|
|
5
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { readToken } from './local-token.mjs';
|
|
9
|
+
import { openEvidenceStore } from './evidence-store.mjs';
|
|
10
|
+
import { readStarPromptState, STAR_URL, WEBSITE_URL } from './star-prompt.mjs';
|
|
11
|
+
|
|
12
|
+
test('proxy /raytace/star-prompt: enforces auth, checks 3-prompt threshold, and persists choice', { timeout: 20000 }, async (t) => {
|
|
13
|
+
const directory = await mkdtemp(join(tmpdir(), 'raytace-star-proxy-'));
|
|
14
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
15
|
+
|
|
16
|
+
const dbFile = join(directory, 'evidence.db');
|
|
17
|
+
const seed = (count) => {
|
|
18
|
+
const store = openEvidenceStore(dbFile);
|
|
19
|
+
try {
|
|
20
|
+
for (let i = 1; i <= count; i++) {
|
|
21
|
+
store.recordExchange({
|
|
22
|
+
event_type: 'model.exchange',
|
|
23
|
+
span_id: `ex-star-${i}`,
|
|
24
|
+
trace_id: `trace-star-${i}`,
|
|
25
|
+
session_id: i === 3 ? 'session-codex' : 'session-claude',
|
|
26
|
+
session_started_at: '2026-11-26T12:00:00.000Z',
|
|
27
|
+
provider: i === 3 ? 'openai' : 'anthropic',
|
|
28
|
+
route: i === 3 ? '/v1/responses' : '/v1/messages',
|
|
29
|
+
method: 'POST',
|
|
30
|
+
timestamp: new Date(1_790_000_000_000 + i * 1000).toISOString(),
|
|
31
|
+
completed_at: new Date(1_790_000_000_400 + i * 1000).toISOString(),
|
|
32
|
+
request: {
|
|
33
|
+
headers: { 'content-type': 'application/json' },
|
|
34
|
+
bytes: 10,
|
|
35
|
+
sha256: `req-star-${i}`,
|
|
36
|
+
payload: i === 3
|
|
37
|
+
? { model: 'gpt-5', input: [{ role: 'user', type: 'message', content: `Prompt number ${i}` }] }
|
|
38
|
+
: { model: 'claude-sonnet', messages: [{ role: 'user', content: `Prompt number ${i}` }] },
|
|
39
|
+
},
|
|
40
|
+
response: {
|
|
41
|
+
status: 200,
|
|
42
|
+
headers: {},
|
|
43
|
+
bytes: 20,
|
|
44
|
+
sha256: `res-star-${i}`,
|
|
45
|
+
payload: i === 3
|
|
46
|
+
? { output: [{ type: 'message', content: [{ type: 'output_text', text: 'ok' }] }] }
|
|
47
|
+
: { content: [{ type: 'text', text: 'ok' }] },
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
store.close();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
seed(2);
|
|
56
|
+
|
|
57
|
+
const env = {
|
|
58
|
+
...process.env,
|
|
59
|
+
RAYTACE_PORT: '0',
|
|
60
|
+
RAYTACE_DATA_DIR: directory,
|
|
61
|
+
RAYTACE_DB: dbFile,
|
|
62
|
+
};
|
|
63
|
+
delete env.RAYTRACE_NO_STAR_PROMPT;
|
|
64
|
+
|
|
65
|
+
const child = spawn(process.execPath, ['--disable-warning=ExperimentalWarning', 'proxy/raytace-proxy.mjs'], {
|
|
66
|
+
cwd: join(import.meta.dirname, '..'),
|
|
67
|
+
env,
|
|
68
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
69
|
+
});
|
|
70
|
+
const exited = once(child, 'exit');
|
|
71
|
+
t.after(async () => { if (child.exitCode === null) child.kill('SIGTERM'); await exited; });
|
|
72
|
+
const url = await new Promise((resolve, reject) => {
|
|
73
|
+
child.stdout.on('data', (chunk) => {
|
|
74
|
+
const match = String(chunk).match(/http:\/\/127\.0\.0\.1:\d+/);
|
|
75
|
+
if (match) resolve(match[0]);
|
|
76
|
+
});
|
|
77
|
+
child.stderr.on('data', (chunk) => reject(new Error(String(chunk))));
|
|
78
|
+
child.on('exit', (code) => reject(new Error(`Proxy exited before startup (${code})`)));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Unauthenticated access is rejected.
|
|
82
|
+
const unauth = await fetch(`${url}/raytace/star-prompt`);
|
|
83
|
+
assert.equal(unauth.status, 401);
|
|
84
|
+
|
|
85
|
+
const signedIn = { authorization: `Bearer ${readToken(directory)}` };
|
|
86
|
+
|
|
87
|
+
// With 2 prompts, not yet eligible.
|
|
88
|
+
const two = await fetch(`${url}/raytace/star-prompt`, { headers: signedIn }).then((r) => r.json());
|
|
89
|
+
assert.equal(two.eligible, false);
|
|
90
|
+
assert.equal(two.prompts, 2);
|
|
91
|
+
assert.equal(two.status, 'pending');
|
|
92
|
+
|
|
93
|
+
// After a 3rd prompt is recorded, eligible becomes true.
|
|
94
|
+
seed(3);
|
|
95
|
+
const three = await fetch(`${url}/raytace/star-prompt`, { headers: signedIn }).then((r) => r.json());
|
|
96
|
+
assert.equal(three.eligible, true);
|
|
97
|
+
assert.equal(three.prompts, 3);
|
|
98
|
+
assert.equal(three.url, STAR_URL);
|
|
99
|
+
assert.equal(three.website_url, WEBSITE_URL);
|
|
100
|
+
|
|
101
|
+
// POST without dashboard CSRF header is rejected.
|
|
102
|
+
const noCsrf = await fetch(`${url}/raytace/star-prompt`, {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
headers: { ...signedIn, 'content-type': 'application/json' },
|
|
105
|
+
body: JSON.stringify({ action: 'opened' }),
|
|
106
|
+
});
|
|
107
|
+
assert.equal(noCsrf.status, 403);
|
|
108
|
+
|
|
109
|
+
// POST with invalid action returns 400.
|
|
110
|
+
const badAction = await fetch(`${url}/raytace/star-prompt`, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: { ...signedIn, 'content-type': 'application/json', 'x-raytace-experiment': '1' },
|
|
113
|
+
body: JSON.stringify({ action: 'bogus' }),
|
|
114
|
+
});
|
|
115
|
+
assert.equal(badAction.status, 400);
|
|
116
|
+
|
|
117
|
+
// POST with valid action persists to star-prompt.json and disables eligibility permanently.
|
|
118
|
+
const saved = await fetch(`${url}/raytace/star-prompt`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: { ...signedIn, 'content-type': 'application/json', 'x-raytace-experiment': '1' },
|
|
121
|
+
body: JSON.stringify({ action: 'opened', source: 'dashboard' }),
|
|
122
|
+
});
|
|
123
|
+
assert.equal(saved.status, 200);
|
|
124
|
+
const savedJson = await saved.json();
|
|
125
|
+
assert.equal(savedJson.ok, true);
|
|
126
|
+
assert.equal(savedJson.state.status, 'opened');
|
|
127
|
+
assert.equal(savedJson.state.source, 'dashboard');
|
|
128
|
+
|
|
129
|
+
assert.equal(readStarPromptState(directory)?.status, 'opened');
|
|
130
|
+
|
|
131
|
+
const after = await fetch(`${url}/raytace/star-prompt`, { headers: signedIn }).then((r) => r.json());
|
|
132
|
+
assert.equal(after.eligible, false);
|
|
133
|
+
assert.equal(after.status, 'opened');
|
|
134
|
+
});
|
package/src/commands.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { portOf, proxyEnv, readConfig, writeConfig } from './config.mjs';
|
|
|
7
7
|
import { checkRunningPid, dashboardLink, healthy, portInUse, PROXY_API, proxyApi, runningPid, start, status, stop } from './proxy-process.mjs';
|
|
8
8
|
import { HOOK_COMMAND, hookState, setHook } from './claude-code.mjs';
|
|
9
9
|
import { askSecret, confirm, interactive } from './prompt.mjs';
|
|
10
|
-
import { maybeStarPrompt } from './star.mjs';
|
|
11
10
|
|
|
12
11
|
const say = (line = '') => console.log(line);
|
|
13
12
|
const CLOUD_URL = 'https://app.raytracer.si';
|
|
@@ -70,7 +69,6 @@ export async function setup(flags) {
|
|
|
70
69
|
else if (await healthy(port)) say(`\nA RayTrace proxy started outside this CLI is answering on :${port}; stop it to use these settings.`);
|
|
71
70
|
else if (flags['no-start'] || (!yes && !(await confirm('\nStart RayTrace now?', true)))) say('\nRun `raytrace start` when you are ready.');
|
|
72
71
|
else await startCommand({ open: !yes });
|
|
73
|
-
maybeStarPrompt(flags);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
// --------------------------------------------------------- start / stop / status
|
package/src/local-sandbox.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { portOf, readConfig } from './config.mjs';
|
|
|
21
21
|
import { ensureToken } from '../proxy/local-token.mjs';
|
|
22
22
|
import { viewerTokenFor } from '../proxy/request-policy.mjs';
|
|
23
23
|
import { LIMA_VERSION, canDownload, checks, downloadLima, findLima } from './lima.mjs';
|
|
24
|
+
import { maybeStarPrompt } from './star.mjs';
|
|
24
25
|
|
|
25
26
|
const say = (line = '') => console.log(line);
|
|
26
27
|
const VM = 'raytrace';
|
|
@@ -344,6 +345,7 @@ export async function stop(id) {
|
|
|
344
345
|
id = pickId(id);
|
|
345
346
|
if (vmStatus() === 'Running') projects(['stop', id]);
|
|
346
347
|
say(`${registry()[id].name} stopped; its files are kept`);
|
|
348
|
+
await maybeStarPrompt();
|
|
347
349
|
}
|
|
348
350
|
|
|
349
351
|
const stamp = () => new Date().toISOString().replace(/[-:]/g, '').replace('T', '-').slice(0, 15);
|
|
@@ -455,4 +457,5 @@ export async function shell(id, { agent } = {}) {
|
|
|
455
457
|
say('Recorded commands, files and connections: raytrace open, then Sandbox evidence\n');
|
|
456
458
|
projects(['shell', id, ...(agent ? ['--agent', agent] : [])], { inherit: true, check: false });
|
|
457
459
|
say(`\nLeft ${name}. It is still running. Back in: raytrace connect ${name} Stop it: raytrace sandbox stop ${name}`);
|
|
460
|
+
await maybeStarPrompt();
|
|
458
461
|
}
|
package/src/proxy-process.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { readToken } from '../proxy/local-token.mjs';
|
|
|
13
13
|
|
|
14
14
|
// The proxy API this CLI's dashboard needs (proxy/raytace-proxy.mjs PROXY_API).
|
|
15
15
|
// A proxy from an older install answers without it, or with less.
|
|
16
|
-
export const PROXY_API =
|
|
16
|
+
export const PROXY_API = 6;
|
|
17
17
|
|
|
18
18
|
/** The running proxy's API version: 0 for one from before it said. */
|
|
19
19
|
export async function proxyApi(port) {
|
package/src/star.mjs
CHANGED
|
@@ -1,61 +1,132 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
7
|
-
import { join } from 'node:path';
|
|
1
|
+
// Interactive one-time GitHub star prompt shown once a user has recorded at
|
|
2
|
+
// least STAR_PROMPT_THRESHOLD prompts across all agents. State lives in
|
|
3
|
+
// ~/.raytrace/star-prompt.json and is shared with the local dashboard popup.
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
8
6
|
import { paths } from './paths.mjs';
|
|
7
|
+
import { confirm as promptConfirm } from './prompt.mjs';
|
|
8
|
+
import {
|
|
9
|
+
STAR_ACTIONS,
|
|
10
|
+
STAR_PROMPT_FILE,
|
|
11
|
+
STAR_PROMPT_THRESHOLD,
|
|
12
|
+
STAR_URL,
|
|
13
|
+
WEBSITE_URL,
|
|
14
|
+
readStarPromptState,
|
|
15
|
+
recordStarPromptState,
|
|
16
|
+
starPromptOptedOut,
|
|
17
|
+
} from '../proxy/star-prompt.mjs';
|
|
9
18
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
export {
|
|
20
|
+
STAR_ACTIONS,
|
|
21
|
+
STAR_PROMPT_FILE,
|
|
22
|
+
STAR_PROMPT_THRESHOLD,
|
|
23
|
+
STAR_URL,
|
|
24
|
+
WEBSITE_URL,
|
|
25
|
+
readStarPromptState,
|
|
26
|
+
recordStarPromptState,
|
|
27
|
+
};
|
|
18
28
|
|
|
19
29
|
// Any non-empty CI value counts, including "false": the variable being set is
|
|
20
|
-
// the signal that this run is not a person sitting at
|
|
30
|
+
// the signal that this run is not a person sitting at an interactive terminal.
|
|
21
31
|
function ciSet(env) {
|
|
22
32
|
return typeof env.CI === 'string' && env.CI !== '';
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
function machineReadable(flags) {
|
|
26
36
|
if (!flags) return false;
|
|
27
|
-
if (flags.json || flags.quiet || flags.silent) return true;
|
|
37
|
+
if (flags.yes || flags.json || flags.quiet || flags.silent) return true;
|
|
28
38
|
return String(flags.format || '').toLowerCase() === 'json';
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
function suppressed(flags, env, stdout, stdin) {
|
|
32
|
-
if (
|
|
42
|
+
if (starPromptOptedOut(env)) return true;
|
|
33
43
|
if (ciSet(env)) return true;
|
|
34
44
|
if (!stdout?.isTTY || !stdin?.isTTY) return true;
|
|
35
45
|
return machineReadable(flags);
|
|
36
46
|
}
|
|
37
47
|
|
|
48
|
+
/** Count all recorded prompt turns in the local evidence database; 0 if unavailable. */
|
|
49
|
+
export async function recordedPromptCount(dbFile = paths.database) {
|
|
50
|
+
if (!dbFile || !existsSync(dbFile)) return 0;
|
|
51
|
+
let db;
|
|
52
|
+
try {
|
|
53
|
+
// Lazy-import node:sqlite so CLI commands do not emit Node 22's
|
|
54
|
+
// ExperimentalWarning on stderr at startup.
|
|
55
|
+
const { DatabaseSync } = await import('node:sqlite');
|
|
56
|
+
db = new DatabaseSync(dbFile, { readOnly: true });
|
|
57
|
+
return Number(db.prepare('SELECT COUNT(*) AS n FROM agent_turns').get()?.n ?? 0);
|
|
58
|
+
} catch {
|
|
59
|
+
return 0;
|
|
60
|
+
} finally {
|
|
61
|
+
try { db?.close(); } catch { /* ignore */ }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Open `url` in the user's default browser, falling back to printing it. */
|
|
66
|
+
export function openBrowser(url, say = console.log) {
|
|
67
|
+
const [command, args] = process.platform === 'darwin' ? ['open', [url]]
|
|
68
|
+
: process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
|
|
69
|
+
try {
|
|
70
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
71
|
+
child.on('error', () => say(`Open ${url} in your browser.`));
|
|
72
|
+
child.unref();
|
|
73
|
+
} catch {
|
|
74
|
+
say(`Open ${url} in your browser.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const starQuestion = (prompts) =>
|
|
79
|
+
`You've recorded ${prompts} prompts in RayTrace. If it's been useful, open GitHub to star the repo?`;
|
|
80
|
+
|
|
38
81
|
/**
|
|
39
|
-
*
|
|
40
|
-
* interactive terminal
|
|
82
|
+
* Ask once (when >= STAR_PROMPT_THRESHOLD prompts are recorded and this run is
|
|
83
|
+
* an interactive terminal) whether to open the GitHub repo to star it.
|
|
84
|
+
* Never throws. Returns whether the prompt was shown. `deps` is for tests.
|
|
41
85
|
*/
|
|
42
|
-
export function maybeStarPrompt(flags = {}, deps = {}) {
|
|
86
|
+
export async function maybeStarPrompt(flags = {}, deps = {}) {
|
|
43
87
|
const env = deps.env ?? process.env;
|
|
44
88
|
const stdout = deps.stdout ?? process.stdout;
|
|
45
89
|
const stdin = deps.stdin ?? process.stdin;
|
|
46
90
|
const log = deps.log ?? ((line) => console.log(line));
|
|
47
91
|
const home = deps.home ?? paths.home;
|
|
92
|
+
const dbFile = deps.database ?? paths.database;
|
|
93
|
+
const threshold = deps.threshold ?? STAR_PROMPT_THRESHOLD;
|
|
94
|
+
const confirm = deps.confirm ?? promptConfirm;
|
|
95
|
+
const openUrl = deps.openUrl ?? ((url) => openBrowser(url, log));
|
|
96
|
+
const now = deps.now ?? Date.now;
|
|
97
|
+
|
|
48
98
|
if (suppressed(flags, env, stdout, stdin)) return false;
|
|
49
|
-
|
|
50
|
-
|
|
99
|
+
if (readStarPromptState(home)) return false;
|
|
100
|
+
|
|
101
|
+
const prompts = deps.prompts !== undefined ? Math.max(0, Math.floor(Number(deps.prompts) || 0)) : await recordedPromptCount(dbFile);
|
|
102
|
+
if (prompts < threshold) return false;
|
|
103
|
+
|
|
104
|
+
// Verify the home directory is usable before prompting so we never nag on every run.
|
|
105
|
+
try { mkdirSync(home, { recursive: true }); } catch { return false; }
|
|
106
|
+
|
|
107
|
+
let accepted = false;
|
|
51
108
|
try {
|
|
52
|
-
|
|
53
|
-
writeFileSync(flag, '1\n', { flag: 'wx' });
|
|
109
|
+
accepted = Boolean(await confirm(`\n${starQuestion(prompts)}`, false));
|
|
54
110
|
} catch {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
111
|
+
try { recordStarPromptState(home, 'dismissed', 'cli', now()); } catch { /* ignore */ }
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const action = accepted ? 'opened' : 'dismissed';
|
|
116
|
+
try {
|
|
117
|
+
recordStarPromptState(home, action, 'cli', now());
|
|
118
|
+
} catch {
|
|
119
|
+
// Do not fail the user's command if ~/.raytrace is not writable.
|
|
120
|
+
if (accepted) {
|
|
121
|
+
openUrl(STAR_URL);
|
|
122
|
+
log(`Opening ${STAR_URL} — thanks for supporting RayTrace!`);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (accepted) {
|
|
128
|
+
openUrl(STAR_URL);
|
|
129
|
+
log(`Opening ${STAR_URL} — thanks for supporting RayTrace!`);
|
|
58
130
|
}
|
|
59
|
-
log(STAR_LINE);
|
|
60
131
|
return true;
|
|
61
132
|
}
|