worktrust 0.10.2 → 0.10.4
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/count-behaviour.mjs +51 -2
- package/package.json +1 -1
- package/setup-mcp.mjs +13 -4
- package/worktrust.mjs +4 -3
package/count-behaviour.mjs
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* node count-behaviour.mjs --url https://app.worktrust.io/api/mcp --token wt_...
|
|
18
18
|
* node count-behaviour.mjs --dry-run --exclude client-x --exclude secret
|
|
19
19
|
* node count-behaviour.mjs --dry-run --claude-export ~/Downloads/claude-export (a claude.ai data export beside the transcripts)
|
|
20
|
+
* node count-behaviour.mjs --dry-run --chatgpt-export ~/Downloads/chatgpt-export (a ChatGPT data export, the same way)
|
|
20
21
|
*
|
|
21
22
|
* CONFIDENTIAL PROJECTS stay out BEFORE anything is counted: `--exclude <text>` (repeatable)
|
|
22
23
|
* skips every project directory whose name contains that text, and `.worktrust-counter.json`
|
|
@@ -433,6 +434,15 @@ for (let i = 0; i < args.length; i += 1) if (args[i] === "--exclude" && args[i +
|
|
|
433
434
|
*/
|
|
434
435
|
const EXPORTS = [];
|
|
435
436
|
for (let i = 0; i < args.length; i += 1) if (args[i] === "--claude-export" && args[i + 1]) EXPORTS.push(args[i + 1]);
|
|
437
|
+
/**
|
|
438
|
+
* A CHATGPT DATA EXPORT (Settings → Data controls → Export data; docs/OPEN.md §0p step 2), the same way:
|
|
439
|
+
* `--chatgpt-export <folder or conversations.json>`, repeatable. A conversation is a tree (`mapping`, a node per
|
|
440
|
+
* message with its parent); only the branch that ends at `current_node` is read, so an answer regenerated or a message
|
|
441
|
+
* edited is counted once, as the person kept it. The person's own messages are the turns, `create_time` (epoch
|
|
442
|
+
* seconds) the clock, `model_slug` the model. No tokens: the export carries none, and none are estimated from text.
|
|
443
|
+
*/
|
|
444
|
+
const CHATGPT_EXPORTS = [];
|
|
445
|
+
for (let i = 0; i < args.length; i += 1) if (args[i] === "--chatgpt-export" && args[i + 1]) CHATGPT_EXPORTS.push(args[i + 1]);
|
|
436
446
|
try {
|
|
437
447
|
const config = JSON.parse(readFileSync(join(homedir(), ".worktrust-counter.json"), "utf8"));
|
|
438
448
|
for (const entry of Array.isArray(config.exclude) ? config.exclude : []) EXCLUDE.push(String(entry).toLowerCase());
|
|
@@ -628,6 +638,44 @@ function* claudeExportSessions() {
|
|
|
628
638
|
}
|
|
629
639
|
}
|
|
630
640
|
}
|
|
641
|
+
let chatgptConversations = 0;
|
|
642
|
+
/** The kept branch of one ChatGPT conversation, oldest first: from `current_node` up through the parents. */
|
|
643
|
+
function chatgptBranch(conversation) {
|
|
644
|
+
const mapping = conversation?.mapping && typeof conversation.mapping === "object" ? conversation.mapping : {};
|
|
645
|
+
const branch = [];
|
|
646
|
+
const seen = new Set();
|
|
647
|
+
for (let id = conversation?.current_node; id && mapping[id] && !seen.has(id); id = mapping[id].parent) { seen.add(id); branch.push(mapping[id]); }
|
|
648
|
+
return branch.reverse();
|
|
649
|
+
}
|
|
650
|
+
function* chatgptExportSessions() {
|
|
651
|
+
for (const given of CHATGPT_EXPORTS) {
|
|
652
|
+
let path = given.replace(/^~(?=\/|$)/, homedir());
|
|
653
|
+
try { if (statSync(path).isDirectory()) path = join(path, "conversations.json"); } catch { throw Error(`chatgpt export not found: ${given}`); }
|
|
654
|
+
let conversations; try { conversations = JSON.parse(readFileSync(path, "utf8")); } catch { throw Error(`chatgpt export unreadable: ${path}`); }
|
|
655
|
+
if (!Array.isArray(conversations)) throw Error("chatgpt export must contain an array of conversations");
|
|
656
|
+
for (const conversation of conversations) {
|
|
657
|
+
const title = String(conversation?.title ?? "");
|
|
658
|
+
if (excluded(title)) { skippedConversations.push(title.slice(0, 40)); continue; }
|
|
659
|
+
const lines = [];
|
|
660
|
+
for (const node of chatgptBranch(conversation)) {
|
|
661
|
+
const m = node?.message;
|
|
662
|
+
const role = m?.author?.role;
|
|
663
|
+
// The person and the model only: system prompts, tools and what the app hides are neither.
|
|
664
|
+
if ((role !== "user" && role !== "assistant") || m?.metadata?.is_visually_hidden_from_conversation) continue;
|
|
665
|
+
const parts = Array.isArray(m?.content?.parts) ? m.content.parts.filter((part) => typeof part === "string") : [];
|
|
666
|
+
const text = parts.join("\n");
|
|
667
|
+
if (text.length === 0) continue;
|
|
668
|
+
const seconds = Number(m?.create_time ?? conversation?.create_time);
|
|
669
|
+
const at = Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1000).toISOString() : null;
|
|
670
|
+
const model = typeof m?.metadata?.model_slug === "string" ? m.metadata.model_slug : undefined;
|
|
671
|
+
lines.push({ type: role === "user" ? "user" : "assistant", timestamp: at, message: { ...(role === "assistant" && model ? { model } : {}), content: [{ type: "text", text }] } });
|
|
672
|
+
}
|
|
673
|
+
if (lines.length === 0) continue;
|
|
674
|
+
chatgptConversations += 1;
|
|
675
|
+
yield { key: `chatgpt:${conversation?.conversation_id ?? conversation?.id ?? title}`, projectDir: "chatgpt", basename: "chatgpt", lines };
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
631
679
|
/**
|
|
632
680
|
* THE READERS FOR CODEX AND ANTIGRAVITY live in transcript-readers.mjs beside this file (2026-10-04;
|
|
633
681
|
* the session hook imports the same file). Run alone, without it, the counter reads Claude Code,
|
|
@@ -712,7 +760,7 @@ function* sessions() {
|
|
|
712
760
|
// A rollout is a transcript on this machine, so --only-transcripts keeps it.
|
|
713
761
|
yield* codexSessions();
|
|
714
762
|
yield* antigravitySessions();
|
|
715
|
-
if (!flag("only-transcripts")) { yield* claudeExportSessions(); yield* copilotSessions(); }
|
|
763
|
+
if (!flag("only-transcripts")) { yield* claudeExportSessions(); yield* chatgptExportSessions(); yield* copilotSessions(); }
|
|
716
764
|
}
|
|
717
765
|
|
|
718
766
|
/**
|
|
@@ -846,7 +894,7 @@ const seenLines = new Set(); // v0.10: line identities already counted (a uuid o
|
|
|
846
894
|
// scan; complete session boundaries preserve signals that depend on earlier turns.
|
|
847
895
|
const manifest = [];
|
|
848
896
|
for(const session of sessions())manifest.push(sessionDigest(session));
|
|
849
|
-
exportConversations = 0; copilotSessionCount = 0; codexRolloutCount = 0; antigravityCount = 0; skippedDirs.length = 0; countedDirs.length = 0; skippedConversations.length = 0;
|
|
897
|
+
exportConversations = 0; chatgptConversations = 0; copilotSessionCount = 0; codexRolloutCount = 0; antigravityCount = 0; skippedDirs.length = 0; countedDirs.length = 0; skippedConversations.length = 0;
|
|
850
898
|
const checkpoint = flag("no-checkpoint") || flag("stretch-signals") || LABEL_OUT ? null : checkpointStore(
|
|
851
899
|
value("checkpoint") ?? join(homedir(), ".worktrust", "counter-checkpoint.json"),
|
|
852
900
|
fingerprint({code:readFileSync(new URL(import.meta.url)),version:ANALYZER_VERSION,months:MONTHS_BACK,thisMonth,exclude:EXCLUDE,leaveOut:LEAVE_OUT,exports:EXPORTS}),manifest);
|
|
@@ -1229,6 +1277,7 @@ if (!codexLines) console.log(" codex and antigravity: not read (transcript-reade
|
|
|
1229
1277
|
if (antigravityCount > 0) console.log(` antigravity conversations read: ${antigravityCount} (~/.gemini/antigravity*, this machine; clocks and the person's turns, no tokens recorded)`);
|
|
1230
1278
|
if (codexRolloutCount > 0) console.log(` codex rollouts read: ${codexRolloutCount} (~/.codex/sessions, this machine; tokens once per response, the person's turns only)`);
|
|
1231
1279
|
if (EXPORTS.length > 0) console.log(` claude.ai export: ${exportConversations} conversation(s) counted${skippedConversations.length ? ` · excluded, never read: ${skippedConversations.length}` : ""}`);
|
|
1280
|
+
if (CHATGPT_EXPORTS.length > 0) console.log(` ChatGPT export: ${chatgptConversations} conversation(s) counted (the kept branch of each; no tokens, the export carries none)`);
|
|
1232
1281
|
if (skippedDirs.length > 0) console.log(` excluded, never read: ${skippedDirs.join(", ")}`);
|
|
1233
1282
|
for (const month of months) {
|
|
1234
1283
|
const bucket = byMonth.get(month);
|
package/package.json
CHANGED
package/setup-mcp.mjs
CHANGED
|
@@ -68,7 +68,16 @@ const masked = BRIDGE ? "kept in ~/.worktrust/key.json, not in these files" : `$
|
|
|
68
68
|
const stdio = { command: NODE, args: [BRIDGE ?? "", "mcp"] };
|
|
69
69
|
const home = homedir();
|
|
70
70
|
/** Whether Claude Code's own command is on this machine: asked of the shell, never guessed from a file. */
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* A COMMAND, RUN THE SAME WAY ON EVERY SYSTEM (0.10.4). On Windows `claude`, `openclaw` and `where` are .cmd shims that
|
|
73
|
+
* need a shell, and Node 24 warns (DEP0190) when arguments ride beside `shell: true` unescaped. So on Windows the line is
|
|
74
|
+
* built here, each argument quoted for cmd.exe, and handed over whole; elsewhere no shell is used at all.
|
|
75
|
+
*/
|
|
76
|
+
const quoteForCmd = (arg) => (/^[\w@%+=:,./\\-]+$/.test(arg) ? arg : `"${String(arg).replace(/"/g, '\\"')}"`);
|
|
77
|
+
const runCommand = (command, args, options = {}) => (platform() === "win32"
|
|
78
|
+
? spawnSync([command, ...args].map(quoteForCmd).join(" "), { encoding: "utf8", ...options, shell: true })
|
|
79
|
+
: spawnSync(command, args, { encoding: "utf8", ...options }));
|
|
80
|
+
const onPath = (command) => runCommand(platform() === "win32" ? "where" : "which", [command]).status === 0;
|
|
72
81
|
const claudeOnPath = () => onPath("claude");
|
|
73
82
|
const VIBE_DIR = process.env.VIBE_HOME?.trim() || join(home, ".vibe");
|
|
74
83
|
const GROK_DIR = process.env.GROK_HOME?.trim() || join(home, ".grok");
|
|
@@ -214,7 +223,7 @@ for (const client of CLIENTS) {
|
|
|
214
223
|
if (REMOVE ? !named : named && text.includes(JSON.stringify(BRIDGE ?? URL_).slice(1, -1)) && (BRIDGE === undefined || !text.includes(URL_))) { console.log(REMOVE ? ` – ${client.label}: does not name the door` : ` ✓ ${client.label}: already names the door (${client.file})`); if (!REMOVE) standing += 1; continue; }
|
|
215
224
|
if (!WRITE) { console.log(` ${REMOVE ? "−" : "+"} ${client.label}: would run ${shown}`); continue; }
|
|
216
225
|
if (!onPath("openclaw")) { console.log(` ! ${client.label}: the \`openclaw\` command is not on this machine's PATH; run ${shown}`); continue; }
|
|
217
|
-
const run =
|
|
226
|
+
const run = runCommand("openclaw", verb);
|
|
218
227
|
if (run.status === 0) { console.log(` ${REMOVE ? "−" : "+"} ${client.label}: ${REMOVE ? "removed" : "coupled"} through \`openclaw mcp ${REMOVE ? "unset" : "set"}\``); touched += 1; }
|
|
219
228
|
else console.log(` ! ${client.label}: \`openclaw mcp\` refused (${(run.stderr || run.stdout || "").trim().split("\n")[0] || "no output"}); run it yourself: ${shown}`);
|
|
220
229
|
continue;
|
|
@@ -232,11 +241,11 @@ for (const client of CLIENTS) {
|
|
|
232
241
|
if (BRIDGE || REMOVE) for (const entry of direct.entries.filter((one) => !(REMOVE && one.name === NAME && one.scope === "user"))) {
|
|
233
242
|
const verb = `claude mcp remove -s ${entry.scope} ${entry.name}`;
|
|
234
243
|
if (!WRITE) { console.log(` ↻ ${client.label}: the direct entry "${entry.name}" (${entry.scope}) is replaced`); continue; }
|
|
235
|
-
const out = claudeOnPath() ?
|
|
244
|
+
const out = claudeOnPath() ? runCommand("claude", ["mcp", "remove", "-s", entry.scope, entry.name], entry.dir ? { cwd: entry.dir } : {}) : null;
|
|
236
245
|
console.log(out?.status === 0 ? ` – ${client.label}: removed the direct entry "${entry.name}" (${entry.scope})` : ` ! ${client.label}: could not remove "${entry.name}"; run it yourself${entry.dir ? ` in ${entry.dir}` : ""}: ${verb}`);
|
|
237
246
|
}
|
|
238
247
|
if (WRITE && claudeOnPath()) {
|
|
239
|
-
const run =
|
|
248
|
+
const run = runCommand("claude", claudeArgs);
|
|
240
249
|
if (run.status === 0) { console.log(` + ${client.label}: ${REMOVE ? "removed" : "coupled"} through \`claude mcp ${REMOVE ? "remove" : "add"}\` (user scope)`); touched += 1; continue; }
|
|
241
250
|
console.log(` ! ${client.label}: \`claude mcp\` refused (${(run.stderr || run.stdout || "").trim().split("\n")[0] || "no output"}); run it yourself: ${shown}`);
|
|
242
251
|
continue;
|
package/worktrust.mjs
CHANGED
|
@@ -73,7 +73,7 @@ const command = args.find((arg, at) => !arg.startsWith("--") && !(at > 0 && VALU
|
|
|
73
73
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
74
74
|
const has = (name) => args.includes(`--${name}`);
|
|
75
75
|
/** This CLI's version, said to the door so the app can tell which computer runs an old one (check-cli-package holds it equal to package.json). */
|
|
76
|
-
const CLI_VERSION = "0.10.
|
|
76
|
+
const CLI_VERSION = "0.10.4";
|
|
77
77
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
78
78
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
79
79
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
@@ -593,7 +593,8 @@ async function connect() {
|
|
|
593
593
|
|
|
594
594
|
// The device key: made here, its private half kept with the key, its public half bound at WorkTrust.
|
|
595
595
|
const device = direct ? null : generateKeyPairSync("ed25519");
|
|
596
|
-
|
|
596
|
+
// Claude Code is coupled through its own command, so its plan line reads "! … couple with": it is coupled all the same (0.10.4).
|
|
597
|
+
const apps = foundApps.map((line) => /^\s*(?:[↻+✓] ([^:]+):|! ([^:]+): couple with)/.exec(line)).map((match) => match?.[1] ?? match?.[2]).filter(Boolean).slice(0, 12);
|
|
597
598
|
const extra = { apps, ...computerIds(), ...(device ? { device_key: device.publicKey.export({ format: "jwk" }).x } : {}) };
|
|
598
599
|
const pairing = useDevice() ? await pairByCode(host, extra) : await pairByBrowser(host, extra);
|
|
599
600
|
const { token } = pairing;
|
|
@@ -656,7 +657,7 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
|
|
|
656
657
|
if (!has("history") && !(rebuild ? await ask("Rebuild the history (replaces this computer's earlier lines for these days)?", false) : await ask("Send these as history (hours and tokens per day; never text)?", false))) { say(rebuild ? " Not sent. Rebuild later with: npx worktrust@latest history --rebuild" : " Not sent. Send them later with: npx worktrust@latest history"); return; }
|
|
657
658
|
const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : [])], token, true, env);
|
|
658
659
|
if (rebuild) say(sent.code === 0 ? " ✓ Rebuilt. This computer's earlier lines for those days were replaced; the record shows each replacement." : " Not all of it arrived. Run npx worktrust@latest history --rebuild again: a day already rebuilt is counted once.");
|
|
659
|
-
else say(sent.code === 0 ? " ✓ Sent as history.
|
|
660
|
+
else say(sent.code === 0 ? " ✓ Sent as history. Measured sessions count toward your verified hours; a day WorkTrust already holds is kept once." : " Not all of it arrived. Run npx worktrust@latest history again: a line already received is kept once.");
|
|
660
661
|
}
|
|
661
662
|
|
|
662
663
|
/** The version stamped in the stable copy in ~/.worktrust, the CLI this computer ran before an update; null without one. */
|