agentel 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 +452 -0
- package/agentlog-spec.md +551 -0
- package/bin/agentlog-recall.js +8 -0
- package/bin/agentlog.js +14 -0
- package/docs/code-reference.md +1108 -0
- package/docs/history-source-handling.md +837 -0
- package/docs/release.md +69 -0
- package/package.json +57 -0
- package/src/archive.js +1130 -0
- package/src/autostart.js +182 -0
- package/src/canonical-events.js +575 -0
- package/src/cli.js +7928 -0
- package/src/collector.js +113 -0
- package/src/commands/logs.js +51 -0
- package/src/commands/server.js +11 -0
- package/src/config.js +240 -0
- package/src/doctor.js +102 -0
- package/src/importers/aider.js +553 -0
- package/src/importers/claude.js +349 -0
- package/src/importers/cline.js +471 -0
- package/src/importers/gemini.js +795 -0
- package/src/importers/providers.js +149 -0
- package/src/importers/shared.js +15 -0
- package/src/importers.js +7063 -0
- package/src/mcp.js +148 -0
- package/src/parser-versions.js +62 -0
- package/src/paths.js +61 -0
- package/src/redaction.js +228 -0
- package/src/repo.js +106 -0
- package/src/search.js +619 -0
- package/src/sources.js +86 -0
- package/src/supervisor.js +217 -0
- package/src/sync.js +677 -0
- package/src/version.js +7 -0
- package/src/web-accounts.js +122 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const { paths, readJson, writeJson } = require("./paths");
|
|
5
|
+
|
|
6
|
+
function loadWebAccounts(env = process.env) {
|
|
7
|
+
const state = readJson(paths(env).webAccounts, { version: 1, accounts: {} });
|
|
8
|
+
return {
|
|
9
|
+
version: state.version || 1,
|
|
10
|
+
accounts: state.accounts && typeof state.accounts === "object" ? state.accounts : {}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function saveWebAccounts(state, env = process.env) {
|
|
15
|
+
writeJson(paths(env).webAccounts, {
|
|
16
|
+
version: state.version || 1,
|
|
17
|
+
accounts: state.accounts || {}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function canonicalWebProvider(provider) {
|
|
22
|
+
const value = String(provider || "").trim().toLowerCase().replace(/[-\s]+/g, "_");
|
|
23
|
+
if (value === "claude" || value === "claude_ai" || value === "claude_web") return "claude_web";
|
|
24
|
+
if (value === "chatgpt" || value === "openai") return "chatgpt";
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function webAccountKey(provider, accountId) {
|
|
29
|
+
return `${canonicalWebProvider(provider)}:${String(accountId || "").trim()}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function derivedAccountId(provider, username) {
|
|
33
|
+
const hash = crypto
|
|
34
|
+
.createHash("sha256")
|
|
35
|
+
.update(canonicalWebProvider(provider))
|
|
36
|
+
.update("\0")
|
|
37
|
+
.update(String(username || "").trim().toLowerCase())
|
|
38
|
+
.digest("hex")
|
|
39
|
+
.slice(0, 16);
|
|
40
|
+
return `u-${hash}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getWebAccount(provider, accountId, env = process.env) {
|
|
44
|
+
const id = String(accountId || "").trim();
|
|
45
|
+
if (!id) return null;
|
|
46
|
+
return loadWebAccounts(env).accounts[webAccountKey(provider, id)] || null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function findWebAccount(provider, value, env = process.env) {
|
|
50
|
+
const normalizedProvider = canonicalWebProvider(provider);
|
|
51
|
+
const wanted = String(value || "").trim().toLowerCase();
|
|
52
|
+
if (!wanted) return null;
|
|
53
|
+
for (const account of Object.values(loadWebAccounts(env).accounts)) {
|
|
54
|
+
if (canonicalWebProvider(account.provider) !== normalizedProvider) continue;
|
|
55
|
+
const candidates = [account.accountId, account.username, account.displayName, account.sourceAccountId]
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.map((item) => String(item).toLowerCase());
|
|
58
|
+
if (candidates.includes(wanted)) return account;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function upsertWebAccount(provider, input = {}, env = process.env) {
|
|
64
|
+
const state = loadWebAccounts(env);
|
|
65
|
+
const normalizedProvider = canonicalWebProvider(provider);
|
|
66
|
+
const username = String(input.username || "").trim();
|
|
67
|
+
const sourceAccountId = String(input.sourceAccountId || "").trim();
|
|
68
|
+
const accountId = String(input.accountId || sourceAccountId || derivedAccountId(normalizedProvider, username)).trim();
|
|
69
|
+
if (!accountId) throw new Error("web account id is required");
|
|
70
|
+
if (!username && !state.accounts[webAccountKey(normalizedProvider, accountId)]) {
|
|
71
|
+
throw new Error("username is required for a new web chat account");
|
|
72
|
+
}
|
|
73
|
+
const key = webAccountKey(normalizedProvider, accountId);
|
|
74
|
+
const now = new Date().toISOString();
|
|
75
|
+
const previous = state.accounts[key] || {};
|
|
76
|
+
const account = {
|
|
77
|
+
provider: normalizedProvider,
|
|
78
|
+
accountId,
|
|
79
|
+
username: username || previous.username || accountId,
|
|
80
|
+
displayName: String(input.displayName || "").trim() || previous.displayName || username || previous.username || accountId,
|
|
81
|
+
sourceAccountId: sourceAccountId || previous.sourceAccountId || "",
|
|
82
|
+
createdAt: previous.createdAt || now,
|
|
83
|
+
updatedAt: now
|
|
84
|
+
};
|
|
85
|
+
state.accounts[key] = account;
|
|
86
|
+
saveWebAccounts(state, env);
|
|
87
|
+
return account;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function listWebAccounts(env = process.env) {
|
|
91
|
+
return Object.values(loadWebAccounts(env).accounts).sort((a, b) =>
|
|
92
|
+
String(a.provider).localeCompare(String(b.provider)) ||
|
|
93
|
+
String(a.displayName || a.username).localeCompare(String(b.displayName || b.username))
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function renameWebAccount(provider, accountIdOrUsername, displayName, env = process.env) {
|
|
98
|
+
const account = findWebAccount(provider, accountIdOrUsername, env);
|
|
99
|
+
if (!account) throw new Error(`no ${canonicalWebProvider(provider)} account found for ${accountIdOrUsername}`);
|
|
100
|
+
const state = loadWebAccounts(env);
|
|
101
|
+
const key = webAccountKey(account.provider, account.accountId);
|
|
102
|
+
state.accounts[key] = {
|
|
103
|
+
...account,
|
|
104
|
+
displayName: String(displayName || "").trim(),
|
|
105
|
+
updatedAt: new Date().toISOString()
|
|
106
|
+
};
|
|
107
|
+
if (!state.accounts[key].displayName) throw new Error("--display-name is required");
|
|
108
|
+
saveWebAccounts(state, env);
|
|
109
|
+
return state.accounts[key];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = {
|
|
113
|
+
canonicalWebProvider,
|
|
114
|
+
derivedAccountId,
|
|
115
|
+
findWebAccount,
|
|
116
|
+
getWebAccount,
|
|
117
|
+
listWebAccounts,
|
|
118
|
+
loadWebAccounts,
|
|
119
|
+
renameWebAccount,
|
|
120
|
+
upsertWebAccount,
|
|
121
|
+
webAccountKey
|
|
122
|
+
};
|