@dayzehq/cli 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +305 -2
- package/dist/add.d.ts +6 -0
- package/dist/add.js +72 -0
- package/dist/admin.d.ts +110 -0
- package/dist/admin.js +408 -0
- package/dist/agent-bridge.d.ts +50 -0
- package/dist/agent-bridge.js +146 -0
- package/dist/agent-mcp.d.ts +4 -0
- package/dist/agent-mcp.js +36 -0
- package/dist/ai-consent.d.ts +18 -0
- package/dist/ai-consent.js +93 -0
- package/dist/args.d.ts +5 -0
- package/dist/args.js +127 -0
- package/dist/auth.d.ts +20 -0
- package/dist/auth.js +198 -0
- package/dist/channel.d.ts +55 -0
- package/dist/channel.js +250 -0
- package/dist/chat.d.ts +67 -0
- package/dist/chat.js +170 -0
- package/dist/cli-errors.d.ts +13 -0
- package/dist/cli-errors.js +30 -0
- package/dist/coding-context.d.ts +12 -0
- package/dist/coding-context.js +130 -0
- package/dist/coding.d.ts +35 -0
- package/dist/coding.js +283 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +149 -0
- package/dist/day.d.ts +22 -0
- package/dist/day.js +54 -0
- package/dist/dayze-cli-runtime +0 -0
- package/dist/dayze-days.d.ts +56 -0
- package/dist/dayze-days.js +276 -0
- package/dist/doctor.d.ts +32 -0
- package/dist/doctor.js +225 -0
- package/dist/focus.d.ts +9 -0
- package/dist/focus.js +163 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +675 -0
- package/dist/inventory.d.ts +73 -0
- package/dist/inventory.js +1272 -0
- package/dist/life.d.ts +48 -0
- package/dist/life.js +146 -0
- package/dist/me.d.ts +94 -0
- package/dist/me.js +789 -0
- package/dist/people.d.ts +232 -0
- package/dist/people.js +2034 -0
- package/dist/projects.d.ts +21 -0
- package/dist/projects.js +132 -0
- package/dist/request-deadline.d.ts +11 -0
- package/dist/request-deadline.js +34 -0
- package/dist/runtime-build.json +1 -0
- package/dist/ui.d.ts +37 -0
- package/dist/ui.js +219 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +16 -0
- package/package.json +54 -4
package/dist/me.js
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-dossier — your life profile in the same shape as a contact detail card.
|
|
3
|
+
* Interactive: a agent · e edit · Esc quit
|
|
4
|
+
*/
|
|
5
|
+
import readline from 'node:readline/promises';
|
|
6
|
+
import { stdin as input, stdout as output } from 'node:process';
|
|
7
|
+
import { authHeader } from './config.js';
|
|
8
|
+
import { askAgent } from './chat.js';
|
|
9
|
+
import { printJson } from './cli-errors.js';
|
|
10
|
+
import * as ui from './ui.js';
|
|
11
|
+
import { CLI_USER_AGENT } from './version.js';
|
|
12
|
+
import { dayNumberFromBirthday, daysToNextBirthday, formatDayNumber, formatDaysToBday, formatTimeAlive, timeAliveFromBirth, } from './dayze-days.js';
|
|
13
|
+
/** True when `--public-ip` or `DAYZE_PUBLIC_IP=1` (also `true`/`yes`) is set. */
|
|
14
|
+
export function isPublicIpLookupEnabled(flag) {
|
|
15
|
+
if (flag === true)
|
|
16
|
+
return true;
|
|
17
|
+
const v = process.env.DAYZE_PUBLIC_IP?.trim().toLowerCase();
|
|
18
|
+
return v === '1' || v === 'true' || v === 'yes';
|
|
19
|
+
}
|
|
20
|
+
const LABEL_W = 16;
|
|
21
|
+
const EDITABLE_FIELDS = [
|
|
22
|
+
{ key: 'name', label: 'Display name', bucket: 'profile' },
|
|
23
|
+
{ key: 'legal_name', label: 'Legal name', bucket: 'profile' },
|
|
24
|
+
{ key: 'preferred_name', label: 'Preferred name', bucket: 'agent' },
|
|
25
|
+
{ key: 'bio', label: 'Bio', bucket: 'profile' },
|
|
26
|
+
{ key: 'birthday', label: 'Birthday', bucket: 'profile' },
|
|
27
|
+
{ key: 'birth_time', label: 'Birth time', bucket: 'profile' },
|
|
28
|
+
{ key: 'birth_location', label: 'Birth place', bucket: 'profile' },
|
|
29
|
+
{ key: 'location', label: 'Profile location', bucket: 'profile' },
|
|
30
|
+
{ key: 'current_city', label: 'Current city', bucket: 'agent' },
|
|
31
|
+
{ key: 'current_country', label: 'Current country', bucket: 'agent' },
|
|
32
|
+
{ key: 'home_location', label: 'Home', bucket: 'agent' },
|
|
33
|
+
{ key: 'work_location', label: 'Work', bucket: 'agent' },
|
|
34
|
+
{ key: 'timezone', label: 'Timezone', bucket: 'profile' },
|
|
35
|
+
{ key: 'instagram_handle', label: 'Instagram', bucket: 'profile' },
|
|
36
|
+
// Phone (imessage_phone_e164) is read-only here: link it by texting the pairing
|
|
37
|
+
// code from Settings → Account, so nobody can claim another person's number.
|
|
38
|
+
{ key: 'occupation', label: 'Occupation', bucket: 'agent' },
|
|
39
|
+
{ key: 'company', label: 'Company', bucket: 'agent' },
|
|
40
|
+
{ key: 'hobbies', label: 'Hobbies', bucket: 'agent', list: true },
|
|
41
|
+
{ key: 'interests', label: 'Interests', bucket: 'agent', list: true },
|
|
42
|
+
{ key: 'personality_notes', label: 'Notes', bucket: 'agent' },
|
|
43
|
+
{ key: 'communication_style', label: 'Style', bucket: 'agent' },
|
|
44
|
+
{ key: 'language', label: 'Language', bucket: 'agent' },
|
|
45
|
+
];
|
|
46
|
+
async function promptLine(question, draft) {
|
|
47
|
+
process.stdout.write('\x1b[?25h');
|
|
48
|
+
const rl = readline.createInterface({ input, output, terminal: true });
|
|
49
|
+
try {
|
|
50
|
+
const answer = rl.question(question);
|
|
51
|
+
if (draft !== undefined)
|
|
52
|
+
rl.write(draft);
|
|
53
|
+
return (await answer).trim();
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
rl.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function kv(label, value) {
|
|
60
|
+
console.log(` ${ui.c.dim(label.padEnd(LABEL_W))} ${value}`);
|
|
61
|
+
}
|
|
62
|
+
function section(title) {
|
|
63
|
+
console.log('');
|
|
64
|
+
console.log(ui.c.bold(` ${title}`));
|
|
65
|
+
}
|
|
66
|
+
function pad2(n) {
|
|
67
|
+
return String(n).padStart(2, '0');
|
|
68
|
+
}
|
|
69
|
+
function formatWhenDetail(iso) {
|
|
70
|
+
if (!iso)
|
|
71
|
+
return '—';
|
|
72
|
+
const d = new Date(iso);
|
|
73
|
+
if (!Number.isFinite(d.getTime()))
|
|
74
|
+
return String(iso);
|
|
75
|
+
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
76
|
+
}
|
|
77
|
+
function igHandle(ig) {
|
|
78
|
+
if (!ig)
|
|
79
|
+
return null;
|
|
80
|
+
const h = ig.replace(/^@/, '').trim();
|
|
81
|
+
return h ? `@${h}` : null;
|
|
82
|
+
}
|
|
83
|
+
function listJoin(vals) {
|
|
84
|
+
if (!vals?.length)
|
|
85
|
+
return null;
|
|
86
|
+
const cleaned = vals.map((v) => String(v).trim()).filter(Boolean);
|
|
87
|
+
return cleaned.length ? cleaned.join(', ') : null;
|
|
88
|
+
}
|
|
89
|
+
function fieldCurrent(profile, agent, field) {
|
|
90
|
+
if (field.bucket === 'profile') {
|
|
91
|
+
const v = profile[field.key];
|
|
92
|
+
return v == null ? '' : String(v);
|
|
93
|
+
}
|
|
94
|
+
const v = agent?.[field.key];
|
|
95
|
+
if (Array.isArray(v))
|
|
96
|
+
return v.join(', ');
|
|
97
|
+
return v == null ? '' : String(v);
|
|
98
|
+
}
|
|
99
|
+
/** Completeness of your own dossier (mirrors contact DOSSIER idea). */
|
|
100
|
+
function selfDossierScore(p, agent) {
|
|
101
|
+
const checks = [
|
|
102
|
+
Boolean(p.name || agent?.preferred_name),
|
|
103
|
+
Boolean(p.handle),
|
|
104
|
+
Boolean(p.birthday),
|
|
105
|
+
Boolean(p.email || p.imessage_phone_e164 || p.instagram_handle),
|
|
106
|
+
Boolean(p.location || agent?.home_location || agent?.current_city),
|
|
107
|
+
Boolean(p.bio || agent?.occupation || agent?.hobbies?.length || agent?.interests?.length),
|
|
108
|
+
];
|
|
109
|
+
const filled = checks.filter(Boolean).length;
|
|
110
|
+
const total = checks.length;
|
|
111
|
+
const bar = '●'.repeat(filled) + '○'.repeat(total - filled);
|
|
112
|
+
return { filled, total, bar };
|
|
113
|
+
}
|
|
114
|
+
const DOSSIER_TIMEOUT_MS = 15_000;
|
|
115
|
+
/** Keep the deadline active through body consumption, even if an adapter ignores abort. */
|
|
116
|
+
async function requestDossier(url, init, action) {
|
|
117
|
+
const controller = new AbortController();
|
|
118
|
+
const timeoutError = new Error(action === 'update'
|
|
119
|
+
? 'Updating your dossier timed out after 15 seconds. Your edit is kept locally; the save may have reached Dayze. Refresh your dossier before saving again.'
|
|
120
|
+
: 'Loading your dossier timed out after 15 seconds. Check your connection and try again.');
|
|
121
|
+
let timer;
|
|
122
|
+
const deadline = new Promise((_, reject) => {
|
|
123
|
+
timer = setTimeout(() => {
|
|
124
|
+
reject(timeoutError);
|
|
125
|
+
controller.abort(timeoutError);
|
|
126
|
+
}, DOSSIER_TIMEOUT_MS);
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
return await Promise.race([
|
|
130
|
+
(async () => {
|
|
131
|
+
const res = await fetch(url, { ...init, signal: controller.signal });
|
|
132
|
+
if (!res.ok) {
|
|
133
|
+
const text = await res.text().catch(() => '');
|
|
134
|
+
throw new Error(`Failed to ${action} dossier (${res.status}): ${text.slice(0, 240)}`);
|
|
135
|
+
}
|
|
136
|
+
return (await res.json());
|
|
137
|
+
})(),
|
|
138
|
+
deadline,
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export async function fetchSelfDossier(creds, options = {}) {
|
|
146
|
+
const header = authHeader(creds);
|
|
147
|
+
if (!header)
|
|
148
|
+
throw new Error('Not logged in. Run: dayze login');
|
|
149
|
+
const headers = {
|
|
150
|
+
Authorization: header,
|
|
151
|
+
Accept: 'application/json',
|
|
152
|
+
'User-Agent': CLI_USER_AGENT,
|
|
153
|
+
'Cache-Control': 'no-store',
|
|
154
|
+
};
|
|
155
|
+
// Opt-in only: default `dayze me` relies on server-inferred session IP (no third-party phone-home).
|
|
156
|
+
// Local Next may see 127.0.0.1 — use `--public-ip` or DAYZE_PUBLIC_IP=1 to report egress via ipify.
|
|
157
|
+
if (isPublicIpLookupEnabled(options.publicIp)) {
|
|
158
|
+
const publicIp = await discoverPublicIp().catch(() => null);
|
|
159
|
+
if (publicIp)
|
|
160
|
+
headers['X-Dayze-Client-Public-IP'] = publicIp;
|
|
161
|
+
}
|
|
162
|
+
return requestDossier(`${creds.apiBase}/api/cli/me?_=${Date.now()}`, {
|
|
163
|
+
headers,
|
|
164
|
+
cache: 'no-store',
|
|
165
|
+
}, 'load your');
|
|
166
|
+
}
|
|
167
|
+
/** Third-party egress lookup — only used when public-IP opt-in is enabled. */
|
|
168
|
+
export async function discoverPublicIp() {
|
|
169
|
+
try {
|
|
170
|
+
const res = await fetch('https://api.ipify.org?format=json', {
|
|
171
|
+
signal: AbortSignal.timeout(3500),
|
|
172
|
+
cache: 'no-store',
|
|
173
|
+
});
|
|
174
|
+
if (!res.ok)
|
|
175
|
+
return null;
|
|
176
|
+
const json = (await res.json());
|
|
177
|
+
return typeof json.ip === 'string' && json.ip.length <= 64 ? json.ip.trim() : null;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export async function patchSelfDossier(creds, patch) {
|
|
184
|
+
const header = authHeader(creds);
|
|
185
|
+
if (!header)
|
|
186
|
+
throw new Error('Not logged in');
|
|
187
|
+
return requestDossier(`${creds.apiBase}/api/cli/me`, {
|
|
188
|
+
method: 'PATCH',
|
|
189
|
+
headers: {
|
|
190
|
+
Authorization: header,
|
|
191
|
+
Accept: 'application/json',
|
|
192
|
+
'Content-Type': 'application/json',
|
|
193
|
+
'User-Agent': CLI_USER_AGENT,
|
|
194
|
+
},
|
|
195
|
+
body: JSON.stringify(patch),
|
|
196
|
+
}, 'update');
|
|
197
|
+
}
|
|
198
|
+
function goalsLabel(goals) {
|
|
199
|
+
if (!goals)
|
|
200
|
+
return null;
|
|
201
|
+
if (Array.isArray(goals)) {
|
|
202
|
+
const parts = goals
|
|
203
|
+
.map((g) => {
|
|
204
|
+
if (typeof g === 'string')
|
|
205
|
+
return g.trim();
|
|
206
|
+
if (g && typeof g === 'object' && 'title' in g)
|
|
207
|
+
return String(g.title);
|
|
208
|
+
if (g && typeof g === 'object' && 'text' in g)
|
|
209
|
+
return String(g.text);
|
|
210
|
+
return '';
|
|
211
|
+
})
|
|
212
|
+
.filter(Boolean);
|
|
213
|
+
return parts.length ? parts.join(', ') : null;
|
|
214
|
+
}
|
|
215
|
+
if (typeof goals === 'string' && goals.trim())
|
|
216
|
+
return goals.trim();
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function networkFlags(ls) {
|
|
220
|
+
const flags = [];
|
|
221
|
+
if (ls.vpn)
|
|
222
|
+
flags.push('VPN');
|
|
223
|
+
if (ls.proxy)
|
|
224
|
+
flags.push('proxy');
|
|
225
|
+
if (ls.tor)
|
|
226
|
+
flags.push('Tor');
|
|
227
|
+
return flags.length ? flags.join(' · ') : null;
|
|
228
|
+
}
|
|
229
|
+
/** Avoid "Singapore, Washington, Singapore" when VPN exit ≠ apparent locale. */
|
|
230
|
+
function formatSignInPlaces(ls) {
|
|
231
|
+
const city = (ls.city || '').trim();
|
|
232
|
+
const region = (ls.region || '').trim();
|
|
233
|
+
const country = (ls.country || '').trim();
|
|
234
|
+
const primaryParts = [];
|
|
235
|
+
if (city)
|
|
236
|
+
primaryParts.push(city);
|
|
237
|
+
if (country && country.toLowerCase() !== city.toLowerCase())
|
|
238
|
+
primaryParts.push(country);
|
|
239
|
+
const primary = primaryParts.length ? primaryParts.join(', ') : null;
|
|
240
|
+
if (!region)
|
|
241
|
+
return { primary, vpnExit: null };
|
|
242
|
+
const regionLower = region.toLowerCase();
|
|
243
|
+
const regionIsLocal = (city && regionLower.includes(city.toLowerCase())) ||
|
|
244
|
+
(country && regionLower.includes(country.toLowerCase()));
|
|
245
|
+
// VPN (or any geo mismatch): region is IP egress, not part of primary place
|
|
246
|
+
if (ls.vpn || !regionIsLocal) {
|
|
247
|
+
// Don't show VPN exit if it's redundant with primary
|
|
248
|
+
if (primary && regionLower === primary.toLowerCase()) {
|
|
249
|
+
return { primary, vpnExit: null };
|
|
250
|
+
}
|
|
251
|
+
return { primary, vpnExit: region };
|
|
252
|
+
}
|
|
253
|
+
// Aligned geo — include region between city and country when useful
|
|
254
|
+
const parts = [];
|
|
255
|
+
if (city)
|
|
256
|
+
parts.push(city);
|
|
257
|
+
if (region && !parts.some((p) => p.toLowerCase() === regionLower))
|
|
258
|
+
parts.push(region);
|
|
259
|
+
if (country && !parts.some((p) => p.toLowerCase() === country.toLowerCase()))
|
|
260
|
+
parts.push(country);
|
|
261
|
+
return { primary: parts.join(', ') || primary, vpnExit: null };
|
|
262
|
+
}
|
|
263
|
+
function normalizeIp(ip) {
|
|
264
|
+
if (!ip)
|
|
265
|
+
return null;
|
|
266
|
+
const s = ip.trim();
|
|
267
|
+
if (s.startsWith('::ffff:'))
|
|
268
|
+
return s.slice(7);
|
|
269
|
+
return s;
|
|
270
|
+
}
|
|
271
|
+
function shortUa(ua) {
|
|
272
|
+
if (!ua)
|
|
273
|
+
return null;
|
|
274
|
+
const s = ua.trim();
|
|
275
|
+
if (s.length <= 64)
|
|
276
|
+
return s;
|
|
277
|
+
return `${s.slice(0, 61)}…`;
|
|
278
|
+
}
|
|
279
|
+
export function printSelfDossier(profile, agent, footerHint = true, session = null) {
|
|
280
|
+
const score = selfDossierScore(profile, agent);
|
|
281
|
+
const dayN = dayNumberFromBirthday(profile.birthday ?? null);
|
|
282
|
+
const toBday = daysToNextBirthday(profile.birthday ?? null);
|
|
283
|
+
const displayName = agent?.preferred_name?.trim() || profile.name?.trim() || profile.handle || 'You';
|
|
284
|
+
console.log('');
|
|
285
|
+
console.log(`${ui.c.brandBold(displayName)} ${ui.c.dim(score.bar + ` ${score.filled}/${score.total}`)} ${ui.c.dim('you')}`);
|
|
286
|
+
if (profile.handle)
|
|
287
|
+
console.log(ui.c.dim(` @${profile.handle.replace(/^@/, '')}`));
|
|
288
|
+
if (profile.is_pro)
|
|
289
|
+
console.log(ui.c.dim(' pro'));
|
|
290
|
+
console.log(ui.c.dim('─'.repeat(52)));
|
|
291
|
+
section('Dayze');
|
|
292
|
+
kv('Day number', dayN != null ? ui.c.brandBold(formatDayNumber(dayN)) : '—');
|
|
293
|
+
const alive = formatTimeAlive(timeAliveFromBirth(profile.birthday, profile.birth_time, {
|
|
294
|
+
timezone: profile.timezone || agent?.timezone,
|
|
295
|
+
}));
|
|
296
|
+
if (alive)
|
|
297
|
+
kv('Alive', ui.c.brandBold(alive));
|
|
298
|
+
if (toBday != null) {
|
|
299
|
+
const label = toBday === 0
|
|
300
|
+
? ui.c.brandBold('today 🎂')
|
|
301
|
+
: `${toBday} day${toBday === 1 ? '' : 's'} (${formatDaysToBday(toBday)})`;
|
|
302
|
+
kv('→ Birthday', label);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
kv('→ Birthday', '—');
|
|
306
|
+
}
|
|
307
|
+
if (profile.birthday)
|
|
308
|
+
kv('Birthday', String(profile.birthday).slice(0, 10));
|
|
309
|
+
if (profile.birth_time)
|
|
310
|
+
kv('Birth time', String(profile.birth_time).slice(0, 8));
|
|
311
|
+
if (profile.birth_location)
|
|
312
|
+
kv('Birth place', profile.birth_location);
|
|
313
|
+
if (profile.dayze_coin != null)
|
|
314
|
+
kv('DayzeCoin', String(profile.dayze_coin));
|
|
315
|
+
section('Identity');
|
|
316
|
+
kv('Display name', profile.name?.trim() || '—');
|
|
317
|
+
kv('Legal name', profile.legal_name?.trim() || '—');
|
|
318
|
+
kv('Preferred', agent?.preferred_name?.trim() || '—');
|
|
319
|
+
kv('Handle', profile.handle ? `@${profile.handle.replace(/^@/, '')}` : '—');
|
|
320
|
+
if (profile.bio?.trim())
|
|
321
|
+
kv('Bio', profile.bio.trim());
|
|
322
|
+
section('Contact');
|
|
323
|
+
const contactRows = [
|
|
324
|
+
['Email', profile.email],
|
|
325
|
+
['Phone', profile.imessage_phone_e164],
|
|
326
|
+
['Instagram', igHandle(profile.instagram_handle)],
|
|
327
|
+
['User id', profile.id],
|
|
328
|
+
];
|
|
329
|
+
let anyContact = false;
|
|
330
|
+
for (const [label, val] of contactRows) {
|
|
331
|
+
if (val) {
|
|
332
|
+
anyContact = true;
|
|
333
|
+
kv(label, val);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!anyContact)
|
|
337
|
+
console.log(ui.c.dim(' (none)'));
|
|
338
|
+
section('Work');
|
|
339
|
+
const workRows = [
|
|
340
|
+
['Occupation', agent?.occupation],
|
|
341
|
+
['Company', agent?.company],
|
|
342
|
+
['Work place', agent?.work_location],
|
|
343
|
+
];
|
|
344
|
+
let anyWork = false;
|
|
345
|
+
for (const [label, val] of workRows) {
|
|
346
|
+
if (val) {
|
|
347
|
+
anyWork = true;
|
|
348
|
+
kv(label, String(val));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (!anyWork)
|
|
352
|
+
console.log(ui.c.dim(' (none)'));
|
|
353
|
+
section('Location');
|
|
354
|
+
kv('Profile', profile.location || '—');
|
|
355
|
+
kv('Current', [agent?.current_city, agent?.current_country].filter(Boolean).join(', ') || '—');
|
|
356
|
+
if (agent?.home_location)
|
|
357
|
+
kv('Home', agent.home_location);
|
|
358
|
+
if (agent?.work_location)
|
|
359
|
+
kv('Work', agent.work_location);
|
|
360
|
+
kv('Birth place', profile.birth_location || '—');
|
|
361
|
+
kv('Timezone', profile.timezone || agent?.timezone || '—');
|
|
362
|
+
if (profile.location_enabled != null) {
|
|
363
|
+
kv('GPS tracking', profile.location_enabled ? 'on' : 'off');
|
|
364
|
+
}
|
|
365
|
+
const hobbies = listJoin(agent?.hobbies);
|
|
366
|
+
const interests = listJoin(agent?.interests);
|
|
367
|
+
const diet = listJoin(agent?.dietary_preferences);
|
|
368
|
+
const music = listJoin(agent?.music_preferences);
|
|
369
|
+
const food = listJoin(agent?.food_preferences);
|
|
370
|
+
const goals = goalsLabel(agent?.goals);
|
|
371
|
+
if (hobbies ||
|
|
372
|
+
interests ||
|
|
373
|
+
diet ||
|
|
374
|
+
music ||
|
|
375
|
+
food ||
|
|
376
|
+
goals ||
|
|
377
|
+
agent?.personality_notes ||
|
|
378
|
+
agent?.communication_style ||
|
|
379
|
+
agent?.language) {
|
|
380
|
+
section('Context');
|
|
381
|
+
if (hobbies)
|
|
382
|
+
kv('Hobbies', hobbies);
|
|
383
|
+
if (interests)
|
|
384
|
+
kv('Interests', interests);
|
|
385
|
+
if (goals)
|
|
386
|
+
kv('Goals', goals);
|
|
387
|
+
if (diet)
|
|
388
|
+
kv('Diet', diet);
|
|
389
|
+
if (music)
|
|
390
|
+
kv('Music', music);
|
|
391
|
+
if (food)
|
|
392
|
+
kv('Food', food);
|
|
393
|
+
if (agent?.communication_style)
|
|
394
|
+
kv('Style', agent.communication_style);
|
|
395
|
+
if (agent?.language)
|
|
396
|
+
kv('Language', agent.language);
|
|
397
|
+
if (agent?.personality_notes?.trim())
|
|
398
|
+
kv('Notes', agent.personality_notes.trim());
|
|
399
|
+
}
|
|
400
|
+
const ls = session?.last_signin;
|
|
401
|
+
const now = session?.network_now;
|
|
402
|
+
const hasSession = session?.request_ip ||
|
|
403
|
+
session?.public_ip ||
|
|
404
|
+
now?.ip ||
|
|
405
|
+
ls?.ip ||
|
|
406
|
+
ls?.city ||
|
|
407
|
+
ls?.country ||
|
|
408
|
+
session?.user_agent ||
|
|
409
|
+
ls?.client_kind;
|
|
410
|
+
if (hasSession) {
|
|
411
|
+
section('Session');
|
|
412
|
+
const publicIp = normalizeIp(session?.public_ip || now?.ip);
|
|
413
|
+
const loopback = normalizeIp(session?.request_ip);
|
|
414
|
+
if (publicIp)
|
|
415
|
+
kv('Public IP', publicIp);
|
|
416
|
+
else if (loopback)
|
|
417
|
+
kv('This request', loopback);
|
|
418
|
+
if (now && (now.city || now.region || now.country || now.vpn != null)) {
|
|
419
|
+
const placeParts = [now.city, now.region, now.country]
|
|
420
|
+
.map((p) => (p || '').trim())
|
|
421
|
+
.filter(Boolean)
|
|
422
|
+
.filter((p, i, arr) => arr.findIndex((x) => x.toLowerCase() === p.toLowerCase()) === i);
|
|
423
|
+
const place = placeParts.join(', ') || null;
|
|
424
|
+
if (now.vpn) {
|
|
425
|
+
if (place)
|
|
426
|
+
kv('VPN exit', place);
|
|
427
|
+
}
|
|
428
|
+
else if (place) {
|
|
429
|
+
kv('Network', place);
|
|
430
|
+
}
|
|
431
|
+
const nowFlags = networkFlags({
|
|
432
|
+
vpn: now.vpn,
|
|
433
|
+
proxy: now.proxy,
|
|
434
|
+
tor: now.tor,
|
|
435
|
+
});
|
|
436
|
+
if (nowFlags)
|
|
437
|
+
kv('Network flags', nowFlags);
|
|
438
|
+
}
|
|
439
|
+
if (ls && (ls.ip || ls.city || ls.country)) {
|
|
440
|
+
const lastIp = normalizeIp(ls.ip);
|
|
441
|
+
if (lastIp && lastIp !== publicIp)
|
|
442
|
+
kv('Last sign-in IP', lastIp);
|
|
443
|
+
const places = formatSignInPlaces(ls);
|
|
444
|
+
if (places.primary)
|
|
445
|
+
kv('Last sign-in', places.primary);
|
|
446
|
+
// Only show stored VPN exit if we don't already have live VPN exit
|
|
447
|
+
if (places.vpnExit && !(now?.vpn && now.region))
|
|
448
|
+
kv('Prior VPN exit', places.vpnExit);
|
|
449
|
+
if (ls.client_kind)
|
|
450
|
+
kv('Client', ls.client_kind);
|
|
451
|
+
if (ls.updated_at)
|
|
452
|
+
kv('Recorded at', formatWhenDetail(ls.updated_at));
|
|
453
|
+
}
|
|
454
|
+
const ua = shortUa(session?.user_agent);
|
|
455
|
+
if (ua)
|
|
456
|
+
kv('User-Agent', ua);
|
|
457
|
+
}
|
|
458
|
+
section('Activity');
|
|
459
|
+
kv('Last updated', formatWhenDetail(profile.updated_at));
|
|
460
|
+
kv('Member since', formatWhenDetail(profile.created_at));
|
|
461
|
+
if (profile.polaris_enabled != null) {
|
|
462
|
+
kv('Dayze Agent', profile.polaris_enabled ? 'on' : 'off');
|
|
463
|
+
}
|
|
464
|
+
console.log('');
|
|
465
|
+
if (footerHint) {
|
|
466
|
+
console.log(ui.c.dim(' a agent · e edit · Esc quit'));
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
console.log(ui.c.dim(' your dossier · dayze me'));
|
|
470
|
+
}
|
|
471
|
+
console.log('');
|
|
472
|
+
}
|
|
473
|
+
export async function runMeCommand(credsIn, options = {}) {
|
|
474
|
+
let creds = credsIn;
|
|
475
|
+
const json = Boolean(options.json);
|
|
476
|
+
const publicIp = Boolean(options.publicIp);
|
|
477
|
+
const spinner = new ui.Spinner('Loading your dossier');
|
|
478
|
+
if (!json)
|
|
479
|
+
spinner.start();
|
|
480
|
+
let profile;
|
|
481
|
+
let agent;
|
|
482
|
+
let session = null;
|
|
483
|
+
try {
|
|
484
|
+
const me = await fetchSelfDossier(creds, { publicIp });
|
|
485
|
+
profile = me.profile;
|
|
486
|
+
agent = me.agent;
|
|
487
|
+
session = me.session || null;
|
|
488
|
+
}
|
|
489
|
+
finally {
|
|
490
|
+
spinner.stop();
|
|
491
|
+
}
|
|
492
|
+
if (json) {
|
|
493
|
+
printJson({ profile, agent, session });
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
497
|
+
printSelfDossier(profile, agent, false, session);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const { emitKeypressEvents } = await import('node:readline');
|
|
501
|
+
emitKeypressEvents(process.stdin);
|
|
502
|
+
process.stdin.setRawMode(true);
|
|
503
|
+
process.stdin.resume();
|
|
504
|
+
process.stdin.setEncoding('utf8');
|
|
505
|
+
let dirty = true;
|
|
506
|
+
let busy = false;
|
|
507
|
+
const editDrafts = new Map();
|
|
508
|
+
let editError = null;
|
|
509
|
+
let keyHandler = null;
|
|
510
|
+
let aliveTimer = null;
|
|
511
|
+
const clearScreen = () => {
|
|
512
|
+
process.stdout.write('\x1b[?25l\x1b[2J\x1b[H');
|
|
513
|
+
};
|
|
514
|
+
const enterRaw = () => {
|
|
515
|
+
try {
|
|
516
|
+
process.stdin.setRawMode(true);
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
/* ignore */
|
|
520
|
+
}
|
|
521
|
+
process.stdin.resume();
|
|
522
|
+
process.stdout.write('\x1b[?25l');
|
|
523
|
+
};
|
|
524
|
+
const leaveRaw = () => {
|
|
525
|
+
try {
|
|
526
|
+
process.stdin.setRawMode(false);
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
/* ignore */
|
|
530
|
+
}
|
|
531
|
+
process.stdout.write('\x1b[?25h');
|
|
532
|
+
};
|
|
533
|
+
const pauseKeys = () => {
|
|
534
|
+
if (aliveTimer) {
|
|
535
|
+
clearInterval(aliveTimer);
|
|
536
|
+
aliveTimer = null;
|
|
537
|
+
}
|
|
538
|
+
if (keyHandler)
|
|
539
|
+
process.stdin.removeListener('keypress', keyHandler);
|
|
540
|
+
leaveRaw();
|
|
541
|
+
};
|
|
542
|
+
const resumeKeys = () => {
|
|
543
|
+
enterRaw();
|
|
544
|
+
if (keyHandler)
|
|
545
|
+
process.stdin.on('keypress', keyHandler);
|
|
546
|
+
startAliveTick();
|
|
547
|
+
};
|
|
548
|
+
const cleanup = () => {
|
|
549
|
+
if (aliveTimer) {
|
|
550
|
+
clearInterval(aliveTimer);
|
|
551
|
+
aliveTimer = null;
|
|
552
|
+
}
|
|
553
|
+
try {
|
|
554
|
+
process.stdin.setRawMode(false);
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
/* ignore */
|
|
558
|
+
}
|
|
559
|
+
process.stdin.pause();
|
|
560
|
+
process.stdin.removeAllListeners('keypress');
|
|
561
|
+
process.stdout.write('\x1b[?25h');
|
|
562
|
+
};
|
|
563
|
+
const canTickAlive = () => Boolean(timeAliveFromBirth(profile.birthday, profile.birth_time, {
|
|
564
|
+
timezone: profile.timezone || agent?.timezone,
|
|
565
|
+
}));
|
|
566
|
+
const startAliveTick = () => {
|
|
567
|
+
if (aliveTimer) {
|
|
568
|
+
clearInterval(aliveTimer);
|
|
569
|
+
aliveTimer = null;
|
|
570
|
+
}
|
|
571
|
+
if (!canTickAlive())
|
|
572
|
+
return;
|
|
573
|
+
aliveTimer = setInterval(() => {
|
|
574
|
+
if (busy)
|
|
575
|
+
return;
|
|
576
|
+
dirty = true;
|
|
577
|
+
render();
|
|
578
|
+
}, 1000);
|
|
579
|
+
};
|
|
580
|
+
const render = () => {
|
|
581
|
+
if (!dirty)
|
|
582
|
+
return;
|
|
583
|
+
dirty = false;
|
|
584
|
+
clearScreen();
|
|
585
|
+
printSelfDossier(profile, agent, true, session);
|
|
586
|
+
if (editError)
|
|
587
|
+
ui.err(editError);
|
|
588
|
+
};
|
|
589
|
+
const runEdit = async () => {
|
|
590
|
+
pauseKeys();
|
|
591
|
+
console.log('');
|
|
592
|
+
console.log(ui.c.bold('Edit your dossier'));
|
|
593
|
+
EDITABLE_FIELDS.forEach((f, i) => {
|
|
594
|
+
const cur = fieldCurrent(profile, agent, f);
|
|
595
|
+
const preview = cur ? (cur.length > 48 ? `${cur.slice(0, 47)}…` : cur) : '—';
|
|
596
|
+
console.log(` ${ui.c.dim(String(i + 1).padStart(2))} ${f.label.padEnd(16)} ${ui.c.dim(preview)}`);
|
|
597
|
+
});
|
|
598
|
+
console.log('');
|
|
599
|
+
const pick = await promptLine('Field number (or name, blank cancel): ');
|
|
600
|
+
if (!pick) {
|
|
601
|
+
resumeKeys();
|
|
602
|
+
dirty = true;
|
|
603
|
+
render();
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
const byNum = /^\d+$/.test(pick) ? EDITABLE_FIELDS[parseInt(pick, 10) - 1] : undefined;
|
|
607
|
+
const byName = EDITABLE_FIELDS.find((f) => f.key === pick.toLowerCase() || f.label.toLowerCase() === pick.toLowerCase());
|
|
608
|
+
const field = byNum || byName;
|
|
609
|
+
if (!field) {
|
|
610
|
+
ui.err(`Unknown field “${pick}”`);
|
|
611
|
+
resumeKeys();
|
|
612
|
+
dirty = true;
|
|
613
|
+
render();
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const current = fieldCurrent(profile, agent, field);
|
|
617
|
+
console.log(ui.c.dim(`Current ${field.label}: ${current || '(empty)'}`));
|
|
618
|
+
const hint = field.key === 'birthday'
|
|
619
|
+
? 'YYYY-MM-DD'
|
|
620
|
+
: field.list
|
|
621
|
+
? 'comma-separated, empty clears, . keeps'
|
|
622
|
+
: 'empty clears, . keeps';
|
|
623
|
+
const next = await promptLine(`New ${field.label} (${hint}): `, editDrafts.get(field.key));
|
|
624
|
+
if (next === '.') {
|
|
625
|
+
resumeKeys();
|
|
626
|
+
dirty = true;
|
|
627
|
+
render();
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
editDrafts.set(field.key, next);
|
|
632
|
+
const value = next === '' ? null : next;
|
|
633
|
+
const patch = field.bucket === 'profile'
|
|
634
|
+
? { profile: { [field.key]: value } }
|
|
635
|
+
: { agent: { [field.key]: value } };
|
|
636
|
+
const me = await patchSelfDossier(creds, patch);
|
|
637
|
+
profile = me.profile;
|
|
638
|
+
agent = me.agent;
|
|
639
|
+
session = me.session || session;
|
|
640
|
+
editDrafts.delete(field.key);
|
|
641
|
+
editError = null;
|
|
642
|
+
ui.ok(`Updated ${field.label}`);
|
|
643
|
+
}
|
|
644
|
+
catch (err) {
|
|
645
|
+
editError = err instanceof Error ? err.message : String(err);
|
|
646
|
+
ui.err(editError);
|
|
647
|
+
}
|
|
648
|
+
resumeKeys();
|
|
649
|
+
dirty = true;
|
|
650
|
+
render();
|
|
651
|
+
};
|
|
652
|
+
const runAgent = async () => {
|
|
653
|
+
pauseKeys();
|
|
654
|
+
console.log('');
|
|
655
|
+
console.log(ui.c.dim('Dayze agent for you · e.g. “update my occupation…”, “add cycling to hobbies”, “I moved to …”'));
|
|
656
|
+
const instruction = await promptLine(ui.promptLabel());
|
|
657
|
+
if (!instruction) {
|
|
658
|
+
resumeKeys();
|
|
659
|
+
dirty = true;
|
|
660
|
+
render();
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
const agentSpinner = new ui.Spinner('Dayze');
|
|
664
|
+
agentSpinner.start();
|
|
665
|
+
let printedHeader = false;
|
|
666
|
+
let startedReply = false;
|
|
667
|
+
let didUpdate = false;
|
|
668
|
+
try {
|
|
669
|
+
const result = await askAgent(creds, instruction, [], undefined, {
|
|
670
|
+
onThinking: (step) => {
|
|
671
|
+
agentSpinner.stop();
|
|
672
|
+
ui.thinking(step);
|
|
673
|
+
},
|
|
674
|
+
onToolCall: (tool, d) => {
|
|
675
|
+
agentSpinner.stop();
|
|
676
|
+
ui.toolCall(tool, d);
|
|
677
|
+
},
|
|
678
|
+
onToolResult: (tool, d) => {
|
|
679
|
+
agentSpinner.stop();
|
|
680
|
+
ui.toolDone(tool, d);
|
|
681
|
+
},
|
|
682
|
+
onFirstText: () => {
|
|
683
|
+
agentSpinner.stop();
|
|
684
|
+
if (!printedHeader) {
|
|
685
|
+
printedHeader = true;
|
|
686
|
+
process.stdout.write(`${ui.agentLabel()}\n`);
|
|
687
|
+
}
|
|
688
|
+
startedReply = true;
|
|
689
|
+
},
|
|
690
|
+
onText: (chunk) => {
|
|
691
|
+
if (!startedReply) {
|
|
692
|
+
agentSpinner.stop();
|
|
693
|
+
if (!printedHeader) {
|
|
694
|
+
printedHeader = true;
|
|
695
|
+
process.stdout.write(`${ui.agentLabel()}\n`);
|
|
696
|
+
}
|
|
697
|
+
startedReply = true;
|
|
698
|
+
}
|
|
699
|
+
process.stdout.write(chunk);
|
|
700
|
+
},
|
|
701
|
+
}, {
|
|
702
|
+
pageContext: {
|
|
703
|
+
path: '/settings',
|
|
704
|
+
pathname: '/settings',
|
|
705
|
+
surface: 'dayze_cli_me',
|
|
706
|
+
client: 'dayze-cli',
|
|
707
|
+
area: 'me',
|
|
708
|
+
},
|
|
709
|
+
});
|
|
710
|
+
creds = result.creds;
|
|
711
|
+
agentSpinner.stop();
|
|
712
|
+
if (startedReply)
|
|
713
|
+
process.stdout.write('\n');
|
|
714
|
+
else
|
|
715
|
+
console.log(`${ui.agentLabel()}\n${result.reply}\n`);
|
|
716
|
+
didUpdate =
|
|
717
|
+
result.toolsUsed.includes('update_account_profile') ||
|
|
718
|
+
result.toolsUsed.includes('update_user_profile');
|
|
719
|
+
if (didUpdate)
|
|
720
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
721
|
+
const me = await fetchSelfDossier(creds, { publicIp });
|
|
722
|
+
profile = me.profile;
|
|
723
|
+
agent = me.agent;
|
|
724
|
+
session = me.session || session;
|
|
725
|
+
}
|
|
726
|
+
catch (err) {
|
|
727
|
+
agentSpinner.stop();
|
|
728
|
+
ui.err(err instanceof Error ? err.message : String(err));
|
|
729
|
+
try {
|
|
730
|
+
const me = await fetchSelfDossier(creds, { publicIp });
|
|
731
|
+
profile = me.profile;
|
|
732
|
+
agent = me.agent;
|
|
733
|
+
session = me.session || session;
|
|
734
|
+
}
|
|
735
|
+
catch {
|
|
736
|
+
/* keep prior */
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
resumeKeys();
|
|
740
|
+
clearScreen();
|
|
741
|
+
dirty = false;
|
|
742
|
+
printSelfDossier(profile, agent, true, session);
|
|
743
|
+
if (didUpdate)
|
|
744
|
+
ui.ok('Dossier updated');
|
|
745
|
+
};
|
|
746
|
+
dirty = true;
|
|
747
|
+
render();
|
|
748
|
+
startAliveTick();
|
|
749
|
+
await new Promise((resolve) => {
|
|
750
|
+
const onKey = async (_ch, key) => {
|
|
751
|
+
if (!key || busy)
|
|
752
|
+
return;
|
|
753
|
+
if (key.ctrl && key.name === 'c') {
|
|
754
|
+
cleanup();
|
|
755
|
+
console.log('');
|
|
756
|
+
resolve();
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
if (key.name === 'escape' || key.name === 'q') {
|
|
760
|
+
cleanup();
|
|
761
|
+
console.log('');
|
|
762
|
+
resolve();
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
const seq = key.sequence;
|
|
766
|
+
if (!key.ctrl && !key.meta && seq && (seq === 'a' || seq === 'A' || seq === '/')) {
|
|
767
|
+
busy = true;
|
|
768
|
+
try {
|
|
769
|
+
await runAgent();
|
|
770
|
+
}
|
|
771
|
+
finally {
|
|
772
|
+
busy = false;
|
|
773
|
+
}
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
if (!key.ctrl && !key.meta && seq && (seq === 'e' || seq === 'E')) {
|
|
777
|
+
busy = true;
|
|
778
|
+
try {
|
|
779
|
+
await runEdit();
|
|
780
|
+
}
|
|
781
|
+
finally {
|
|
782
|
+
busy = false;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
process.stdin.on('keypress', onKey);
|
|
787
|
+
keyHandler = onKey;
|
|
788
|
+
});
|
|
789
|
+
}
|