@zaferyalcin/agent-office 0.0.0-stage → 0.1.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 +476 -2
- package/bin/agent-office.js +64 -0
- package/package.json +25 -4
- package/public/app.css +1035 -0
- package/public/app.js +2034 -0
- package/public/favicon.svg +1 -0
- package/public/i18n.js +1119 -0
- package/public/index.html +141 -0
- package/public/studio.js +1951 -0
- package/public/vendor/three/LICENSE +21 -0
- package/public/vendor/three/three.core.js +61162 -0
- package/public/vendor/three/three.module.js +19537 -0
- package/src/collector.js +501 -0
- package/src/history.js +161 -0
- package/src/open.js +57 -0
- package/src/providers/antigravity-core.js +743 -0
- package/src/providers/antigravity.js +136 -0
- package/src/providers/claude-code.js +465 -0
- package/src/providers/codex.js +168 -0
- package/src/providers/demo.js +1379 -0
- package/src/providers/gemini-cli.js +115 -0
- package/src/server.js +201 -0
- package/src/state.js +142 -0
- package/src/update.js +99 -0
- package/src/util.js +139 -0
- package/src/workspace.js +112 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// OpenAI Codex CLI: $CODEX_HOME/sessions/YYYY/MM/DD/rollout-*.jsonl (default ~/.codex).
|
|
3
|
+
// Token counts and the exact rate-limit windows come from the "token_count" events Codex writes itself.
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { MIN, DAY, short, cut, tryJSON, statOrNull, listDir, readJSONFile, readText, JsonlTail, Samples, firstLine } = require('../util');
|
|
7
|
+
|
|
8
|
+
function textOf(content) {
|
|
9
|
+
if (typeof content === 'string') return content;
|
|
10
|
+
if (!Array.isArray(content)) return '';
|
|
11
|
+
return content.map((b) => (b && (b.text || b.input_text || b.output_text)) || '').join('\n');
|
|
12
|
+
}
|
|
13
|
+
function callArg(name, args) {
|
|
14
|
+
const a = typeof args === 'string' ? tryJSON(args) || args : args || {};
|
|
15
|
+
if (typeof a === 'string') return short(a, 200);
|
|
16
|
+
const cmd = Array.isArray(a.command) ? a.command.join(' ') : a.command;
|
|
17
|
+
return short(cmd || a.path || a.file_path || a.query || JSON.stringify(a), 200);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class Session {
|
|
21
|
+
constructor(id, file) { this.id = id; this.file = file; this.tail = new JsonlTail(file, { maxFirst: 24 * 1024 * 1024 }); this.reset(); }
|
|
22
|
+
reset() {
|
|
23
|
+
this.samples = new Samples(); this.models = {}; this.tokens = { in: 0, cache: 0, out: 0 };
|
|
24
|
+
this.first = 0; this.last = 0; this.steps = 0; this.cwd = ''; this.branch = ''; this.client = ''; this.model = '';
|
|
25
|
+
this.prompt = ''; this.end = ''; this.lastAction = ''; this.limits = null; this.limitsTs = 0; this.parent = null; this.role = '';
|
|
26
|
+
}
|
|
27
|
+
update() { const r = this.tail.update((l) => this.line(l)); if (r === 'reset') { this.reset(); this.tail.update((l) => this.line(l)); } }
|
|
28
|
+
line(text) {
|
|
29
|
+
const o = tryJSON(text); if (!o || typeof o !== 'object') return;
|
|
30
|
+
const ts = Date.parse(o.timestamp) || 0, p = o.payload || {};
|
|
31
|
+
if (ts) { if (!this.first || ts < this.first) this.first = ts; if (ts > this.last) this.last = ts; }
|
|
32
|
+
if (o.type === 'session_meta') {
|
|
33
|
+
if (p.cwd) this.cwd = p.cwd;
|
|
34
|
+
if (p.git && p.git.branch) this.branch = p.git.branch;
|
|
35
|
+
this.client = String(p.originator || 'cli').replace(/^codex_/, '').replace(/_rs$/, '');
|
|
36
|
+
const src = p.source && p.source.subagent;
|
|
37
|
+
if (src && src.parent_thread_id) { this.parent = src.parent_thread_id; this.role = src.agent_role || ''; }
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (o.type === 'turn_context') { if (p.model) this.model = p.model; if (p.cwd) this.cwd = p.cwd; return; }
|
|
41
|
+
if (o.type === 'response_item') {
|
|
42
|
+
if (p.type === 'message' && p.role === 'user') {
|
|
43
|
+
const t = textOf(p.content).trim();
|
|
44
|
+
if (t && !this.prompt && !/^<(environment_context|user_instructions|permissions)/.test(t)) this.prompt = t;
|
|
45
|
+
this.end = '';
|
|
46
|
+
} else if (p.type === 'function_call' || p.type === 'local_shell_call' || p.type === 'custom_tool_call') {
|
|
47
|
+
this.lastAction = (p.name || 'shell') + ': ' + callArg(p.name, p.arguments || p.action || p.input); this.end = 'tool';
|
|
48
|
+
} else if (p.type === 'function_call_output' || p.type === 'custom_tool_call_output') { this.end = ''; }
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (o.type === 'event_msg') {
|
|
52
|
+
if (p.type === 'user_message' && p.message && !this.prompt) this.prompt = p.message;
|
|
53
|
+
if (p.type === 'task_complete' || p.type === 'turn_complete') this.end = 'turn';
|
|
54
|
+
if (p.type === 'turn_aborted') this.end = 'canceled';
|
|
55
|
+
if (p.type === 'error' || p.type === 'stream_error') this.end = 'error';
|
|
56
|
+
if (p.type === 'token_count') {
|
|
57
|
+
const u = p.info && p.info.last_token_usage;
|
|
58
|
+
if (u) {
|
|
59
|
+
const cached = u.cached_input_tokens || 0, tin = Math.max(0, (u.input_tokens || 0) - cached), tout = u.output_tokens || 0;
|
|
60
|
+
const m = this.model || 'gpt';
|
|
61
|
+
const mm = this.models[m] || (this.models[m] = { in: 0, cache: 0, out: 0 });
|
|
62
|
+
mm.in += tin; mm.cache += cached; mm.out += tout;
|
|
63
|
+
this.tokens.in += tin; this.tokens.cache += cached; this.tokens.out += tout;
|
|
64
|
+
this.samples.add(ts, m, tin, cached, tout); this.steps++;
|
|
65
|
+
}
|
|
66
|
+
if (p.rate_limits) { this.limits = p.rate_limits; this.limitsTs = ts; }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class Codex {
|
|
73
|
+
constructor(cfg) {
|
|
74
|
+
this.id = 'codex'; this.label = 'Codex';
|
|
75
|
+
this.home = (cfg && cfg.home) || process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
|
|
76
|
+
this.root = path.join(this.home, 'sessions');
|
|
77
|
+
this.sessions = new Map(); this.acct = null; this.acctAt = 0;
|
|
78
|
+
}
|
|
79
|
+
available() { return !!statOrNull(this.root); }
|
|
80
|
+
account() {
|
|
81
|
+
if (Date.now() - this.acctAt < 5 * MIN) return this.acct;
|
|
82
|
+
this.acctAt = Date.now();
|
|
83
|
+
const a = readJSONFile(path.join(this.home, 'auth.json'));
|
|
84
|
+
const jwt = a && a.tokens && a.tokens.id_token;
|
|
85
|
+
let email = '';
|
|
86
|
+
if (typeof jwt === 'string' && jwt.split('.').length === 3) {
|
|
87
|
+
const claims = tryJSON(Buffer.from(jwt.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'));
|
|
88
|
+
email = (claims && claims.email) || '';
|
|
89
|
+
}
|
|
90
|
+
this.acct = email ? { name: email.split('@')[0], email } : (a ? { name: a.OPENAI_API_KEY ? 'API key' : '', email: '' } : null);
|
|
91
|
+
return this.acct;
|
|
92
|
+
}
|
|
93
|
+
scan(now, windowMs) {
|
|
94
|
+
const seen = new Set(), from = now - windowMs;
|
|
95
|
+
// walk only the day folders inside the window
|
|
96
|
+
for (let t = from - DAY; t <= now + DAY; t += DAY) {
|
|
97
|
+
const d = new Date(t);
|
|
98
|
+
const dir = path.join(this.root, String(d.getFullYear()), String(d.getMonth() + 1).padStart(2, '0'), String(d.getDate()).padStart(2, '0'));
|
|
99
|
+
for (const f of listDir(dir) || []) {
|
|
100
|
+
if (!f.name.endsWith('.jsonl')) continue;
|
|
101
|
+
const file = path.join(dir, f.name), st = statOrNull(file);
|
|
102
|
+
if (!st || st.mtimeMs < from) continue;
|
|
103
|
+
const m = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i.exec(f.name);
|
|
104
|
+
const id = 'cx:' + (m ? m[1] : f.name);
|
|
105
|
+
seen.add(id);
|
|
106
|
+
let s = this.sessions.get(id); if (!s) { s = new Session(id, file); this.sessions.set(id, s); }
|
|
107
|
+
s.update();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const id of [...this.sessions.keys()]) if (!seen.has(id)) this.sessions.delete(id);
|
|
111
|
+
const acct = this.account(), out = [];
|
|
112
|
+
for (const s of this.sessions.values()) {
|
|
113
|
+
s.samples.prune(now - 8 * DAY);
|
|
114
|
+
out.push({
|
|
115
|
+
id: s.id, provider: this.id, tool: this.label, kind: s.parent ? 'subagent' : 'session',
|
|
116
|
+
parent: s.parent ? 'cx:' + s.parent : null, name: s.parent ? (s.role || 'subagent') : 'Codex', role: s.role,
|
|
117
|
+
task: short(firstLine(s.prompt), 160), cwd: s.cwd, branch: s.branch, client: s.client || 'cli',
|
|
118
|
+
user: acct ? acct.name : '', account: acct ? acct.email : '',
|
|
119
|
+
started: s.first, last: s.last, steps: s.steps, model: s.model || null, models: s.models, tokens: s.tokens,
|
|
120
|
+
end: s.parent && s.end === 'turn' ? 'final' : s.end, interactive: !s.parent, last_action: s.lastAction,
|
|
121
|
+
partial: s.tail.partial, samples: s.samples,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
// Codex reports both windows with their exact reset time in every token_count event; use the newest one.
|
|
127
|
+
quotas(now) {
|
|
128
|
+
let best = null;
|
|
129
|
+
for (const s of this.sessions.values()) if (s.limits && (!best || s.limitsTs > best.limitsTs)) best = s;
|
|
130
|
+
if (!best) return [];
|
|
131
|
+
const windows = [];
|
|
132
|
+
for (const key of ['primary', 'secondary']) {
|
|
133
|
+
const l = best.limits[key]; if (!l) continue;
|
|
134
|
+
const mins = l.window_minutes || 0;
|
|
135
|
+
const reset = l.resets_at ? (l.resets_at > 1e12 ? l.resets_at : l.resets_at * 1000)
|
|
136
|
+
: l.resets_in_seconds != null ? best.limitsTs + l.resets_in_seconds * 1000 : null;
|
|
137
|
+
windows.push({
|
|
138
|
+
window: mins >= 9000 ? 'week' : mins >= 250 && mins <= 330 ? '5h' : 'other',
|
|
139
|
+
label: mins && !(mins >= 9000 || (mins >= 250 && mins <= 330)) ? Math.round(mins / 60) + '-hour window' : null,
|
|
140
|
+
left_pct: Math.max(0, Math.round(100 - (l.used_percent || 0))), resets_at: reset && reset > now ? reset : null,
|
|
141
|
+
note: reset && reset <= now ? 'reset since last update' : null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return [{ id: 'codex', tool: this.label, label: 'ChatGPT plan (Codex)', vendors: ['openai'], windows, checked: best.limitsTs }];
|
|
145
|
+
}
|
|
146
|
+
trace(id, limit) {
|
|
147
|
+
const s = this.sessions.get(id); if (!s) return null;
|
|
148
|
+
const txt = readText(s.file) || '';
|
|
149
|
+
const rows = [], calls = new Map(); let lastAnswer = null;
|
|
150
|
+
for (const line of txt.split('\n')) {
|
|
151
|
+
const o = tryJSON(line); if (!o || o.type !== 'response_item') continue;
|
|
152
|
+
const p = o.payload || {}, ts = Date.parse(o.timestamp) || 0;
|
|
153
|
+
if (p.type === 'message') {
|
|
154
|
+
const t = textOf(p.content).trim(); if (!t) continue;
|
|
155
|
+
if (p.role === 'assistant') { rows.push({ ts, kind: 'answer', tool: 'text', text: cut(t, 300) }); lastAnswer = t; }
|
|
156
|
+
else if (p.role === 'user' && !/^<(environment_context|user_instructions|permissions)/.test(t)) rows.push({ ts, kind: 'in', tool: 'prompt', text: cut(t, 300) });
|
|
157
|
+
} else if (/call$/.test(p.type)) {
|
|
158
|
+
const r = { ts, kind: 'tool', tool: p.name || 'shell', arg: callArg(p.name, p.arguments || p.action || p.input) };
|
|
159
|
+
rows.push(r); if (p.call_id) calls.set(p.call_id, r);
|
|
160
|
+
} else if (/call_output$/.test(p.type)) {
|
|
161
|
+
const r = calls.get(p.call_id); if (r) { r.res = cut(typeof p.output === 'string' ? p.output : JSON.stringify(p.output), 300); r.dur = ts - r.ts; }
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { rows: limit === 'all' ? rows : rows.slice(-(Number(limit) || 30)), total: rows.length, task_full: s.prompt, result: lastAnswer, files: [], commands: [], messages: [] };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = Codex;
|