worktrust 0.10.14 → 0.10.16
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/README.md +2 -1
- package/SECURITY.md +15 -0
- package/claude-mod.mjs +230 -0
- package/log-session.mjs +9 -6
- package/package.json +3 -2
- package/transcript-readers.mjs +32 -0
- package/worktrust.mjs +51 -4
package/README.md
CHANGED
|
@@ -226,6 +226,7 @@ nothing it does not:
|
|
|
226
226
|
| `retrieval` | retrieval and grounding: searches (grep, rg, find, Grep, Glob, a web search, an MCP search tool), the same search again, a search followed by a read or a change (found) or by another search (again), searches before the first change and right after a failure, and deliveries with docs, tests or a search since the last change (grounded); counts only, nothing searched is kept (0.9.9) |
|
|
227
227
|
| `window` | the context window, from the token counts the AI app writes beside each answer (input plus cached, once per message): the peak a turn carried, the turns over 100k, 200k and 500k, the growth from the first quarter of answers to the last, and compactions near the peak; counts only, nothing of what the context held (0.10.0) |
|
|
228
228
|
| `review` | reviewing the agent: reviews while it worked, the middle interval, subagent runs reviewed, and what a review led to (a change of course, a change, a check); counts only (0.10.1) |
|
|
229
|
+
| `live` | counted inside Claude Code by the WorkTrust mod, only when you turned it on (`worktrust mod install`, 0.10.15): permission questions put to you and how many you answered yes or no (not in auto mode, where a classifier answers), model requests per effort level, how many models answered and requests sent to another model, the highest context fill and plan-limit use as percentages, compactions you asked for or that ran by themselves, subagents started (built-in, your own, in the background, forks) and teammates, and how many other mods, MCP servers and own agent types were active; counts only, never a prompt, an answer, a command, a path or a name. From 0.10.16 a Codex session carries the same keys read from its own rollout, with nothing installed: each turn's effort level, the models, and the highest context fill and plan-limit use |
|
|
229
230
|
| `collector_version` | the CLI version that measured it |
|
|
230
231
|
| `seq`, `prev`, `hash` | the line's place, the hash of the line before it, and its own hash |
|
|
231
232
|
|
|
@@ -372,7 +373,7 @@ which would delete every password on the computer, and many people rightly keep
|
|
|
372
373
|
| **Reads** | Which AI apps are installed (the settings folders of Claude Code, Codex, Cursor, Gemini CLI, Antigravity, VS Code, Windsurf, Hermes Agent, Goose, OpenCode, OpenClaw), and the chats Cursor and Copilot keep (clocks, models and token counts only). Afterwards, the session hook reads Claude Code's, Codex's and Antigravity's session files, the session databases of Hermes, Goose, OpenCode and OpenClaw, and the chats Cursor and Copilot keep, on this computer to measure durations and token counts. |
|
|
373
374
|
| **Writes** | The key file (above). In each AI app's MCP settings (`~/.claude.json` through `claude mcp`, `~/.cursor/mcp.json`, `~/.codex/config.toml`, `~/.gemini/settings.json`, `~/.gemini/config/mcp_config.json` (Antigravity), VS Code's `mcp.json`, Windsurf's `mcp_config.json`, Hermes's and Goose's `config.yaml`, OpenCode's `opencode.json`, OpenClaw through `openclaw mcp set`) a WorkTrust entry that runs the local bridge, with no key in it; three hooks in `~/.claude/settings.json`; the bridge, the hook and the counter in `~/.worktrust/`. |
|
|
374
375
|
| **Sends, to pair** | This computer's system (macOS, Windows, Linux) and host name. WorkTrust also records the network address the request arrives from, as a security record kept 90 days and seen only by WorkTrust staff (to answer a theft or fraud report). |
|
|
375
|
-
| **Sends, afterwards** | Per measured stretch of work, and nothing else: its durations (`seconds`, `duration_basis`, `model_seconds`, `tool_seconds`, `human_seconds`, `idle_seconds`), token counts (`tokens_in`, `tokens_out`, `tokens_cache_read`, `tokens_cache_write`, `token_basis`), the model's name (`model`), the kind of work and one layer keyword such as frontend or backend (`title`, `kind`, `layer`, `layers`), closed technology keys (`stack`) and separate display-only tool keys (`tools_seen`), counts of how you work (`exchanges`, `turn_basis`, `agent_runs`, `agent_seconds`, `agent_peak`, `interrupts`, `steers`), when it began and ended and your computer's offset from UTC (`started_at`, `at`, `utc_offset`), what the CLI derived from the stretch as kinds and counts (`evidence`: checks run and failed, delivery steps and whether a check passed first, recoveries, delegation, context, routing, steering, refusals, planning, files and test files changed, the complexity class; never a word, a command or a path; since 0.8.3), a hash of the session and the day (`stretch_ref`), `steered_from` when it ran over SSH, and, so the work can be matched to GitHub, the repository as its remote's owner/name (`repo`, only for a repository on GitHub, GitLab or Bitbucket, the hosts WorkTrust can couple; never one on your own or a client's server) and the hashes of the commits made in the stretch (`commits`, never their messages). |
|
|
376
|
+
| **Sends, afterwards** | Per measured stretch of work, and nothing else: its durations (`seconds`, `duration_basis`, `model_seconds`, `tool_seconds`, `human_seconds`, `idle_seconds`), token counts (`tokens_in`, `tokens_out`, `tokens_cache_read`, `tokens_cache_write`, `token_basis`), the model's name (`model`), the kind of work and one layer keyword such as frontend or backend (`title`, `kind`, `layer`, `layers`), closed technology keys (`stack`) and separate display-only tool keys (`tools_seen`), counts of how you work (`exchanges`, `turn_basis`, `agent_runs`, `agent_seconds`, `agent_peak`, `interrupts`, `steers`), when it began and ended and your computer's offset from UTC (`started_at`, `at`, `utc_offset`), what the CLI derived from the stretch as kinds and counts (`evidence`: checks run and failed, delivery steps and whether a check passed first, recoveries, delegation, context, routing, steering, refusals, planning, files and test files changed, the complexity class; with the WorkTrust mod on, its `live` counts from inside Claude Code: permission answers, effort levels, context and plan-limit peaks, subagents and setup; never a word, a command or a path; since 0.8.3, `live` since 0.10.15), a hash of the session and the day (`stretch_ref`), `steered_from` when it ran over SSH, and, so the work can be matched to GitHub, the repository as its remote's owner/name (`repo`, only for a repository on GitHub, GitLab or Bitbucket, the hosts WorkTrust can couple; never one on your own or a client's server) and the hashes of the commits made in the stretch (`commits`, never their messages). |
|
|
376
377
|
| **Never sends** | Prompts, answers, code, file names or paths, commit messages, branch names, or the name of your local folder (a repository is named only as its remote's owner/name, above). The door has no field for them and refuses a submission that carries them. |
|
|
377
378
|
|
|
378
379
|
## Why you can check it
|
package/SECURITY.md
CHANGED
|
@@ -73,6 +73,21 @@ artifact was built from reviewed source. `npm audit signatures` can inspect an i
|
|
|
73
73
|
tree; verification coverage and failures must be reported for that actual installation.
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
## The WorkTrust mod for Claude Code (0.10.15, opt-in)
|
|
77
|
+
|
|
78
|
+
`worktrust mod install` asks, then writes a Claude Code plugin to `~/.worktrust/claude-mod` and names
|
|
79
|
+
that directory in `~/.claude/settings.json` (`env.CLAUDE_CODE_PLUGIN_DIRS`, the file backed up beside
|
|
80
|
+
itself first). Claude Code 2.1.287 or later loads it in every session. It runs inside Claude Code
|
|
81
|
+
with your permissions, as every mod does, and Claude Code's own validator lists what it may do:
|
|
82
|
+
twelve events it observes, and three calls: `fs.write` (its one counts file per session under
|
|
83
|
+
`~/.worktrust/claude-mod-counts`), `session.id` and `tool.list`. It makes no network request, starts
|
|
84
|
+
no process, calls no model, rewrites no prompt or tool call (each hook hands back exactly what Claude
|
|
85
|
+
Code gave it) and keeps no text: only integer counts in a closed list (`claude-mod.mjs`,
|
|
86
|
+
`MOD_FIELDS`). The session hook sends those counts with the session's stretch as `evidence.live`;
|
|
87
|
+
the platform keeps only the listed keys, from a CLI key alone, and shows them to you alone.
|
|
88
|
+
`worktrust mod remove` and `worktrust disconnect` take it out of the settings and delete the plugin
|
|
89
|
+
and its counts.
|
|
90
|
+
|
|
76
91
|
## Python distribution and explicit agent observations
|
|
77
92
|
|
|
78
93
|
The official [PyPI package](https://pypi.org/project/worktrust/) runs the same measurement
|
package/claude-mod.mjs
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE WORKTRUST MOD FOR CLAUDE CODE (owner, 2026-10-16: "implement mods so we can collect additional data relevant to
|
|
3
|
+
* human-AI capability"). Claude Code 2.1.287 runs mods: plugins whose functions run INSIDE Claude Code on its events
|
|
4
|
+
* (docs/CLAUDE-CODE-MOD.md). This file is the whole of ours, and how the CLI puts it in place and reads it back.
|
|
5
|
+
*
|
|
6
|
+
* WHAT IT ADDS, ONLY WHAT A TRANSCRIPT CANNOT SHOW (owner: "what fits and adds value, without noise"):
|
|
7
|
+
* oversight a permission question put to the PERSON, and whether they said yes or no (a transcript shows a refusal,
|
|
8
|
+
* never an approval after a question); not counted where a classifier or a mode answers instead
|
|
9
|
+
* effort each model request by its effort level, how many models answered, requests on another model than
|
|
10
|
+
* the main conversation's (routing)
|
|
11
|
+
* context the peak context fill and the peak plan-limit use, as percentages; compactions asked for or automatic
|
|
12
|
+
* delegation subagents started (built-in, the person's own, in the background, forks), teammates; and the setup in
|
|
13
|
+
* force: other mods, MCP servers and the person's own agent types, as counts
|
|
14
|
+
*
|
|
15
|
+
* WHAT IT NEVER DOES: it reads no text it keeps (a prompt, an answer, a command, a path, a name), it makes no network
|
|
16
|
+
* call, it changes no event (every hook returns what `next` gave it), and it writes one file per session of integer
|
|
17
|
+
* counts under ~/.worktrust/claude-mod-counts. The CLI reads that file when it reports the session's stretch and sends
|
|
18
|
+
* the counts, as the `live` evidence group, through the same signed door as everything else; the door keeps only the
|
|
19
|
+
* keys of `MOD_FIELDS` (packages/core/src/stretch-evidence.ts holds the same list, check-cli-package holds them equal).
|
|
20
|
+
* The figures reach the person's own mirror and nothing that scores: no dimension, no level, no passport, until they
|
|
21
|
+
* are validated (CLAUDE.md rules 6 and 11; the owner's choice, 2026-10-16).
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { homedir } from "node:os";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
|
|
27
|
+
export const MOD_NAME = "worktrust-measure";
|
|
28
|
+
export const MOD_VERSION = "1.0.0";
|
|
29
|
+
/** The first Claude Code whose terminal runs installed mods (the Desktop app from 2.1.286). */
|
|
30
|
+
export const MIN_CLAUDE_CODE = "2.1.287";
|
|
31
|
+
|
|
32
|
+
/** The closed list of what the mod counts: integers per UTC day; the two `_pct` fields are peaks from 0 to 100. */
|
|
33
|
+
export const MOD_FIELDS = [
|
|
34
|
+
"asked", "approved", "declined",
|
|
35
|
+
"effort_low", "effort_medium", "effort_high", "effort_xhigh", "effort_max", "models", "routed",
|
|
36
|
+
"context_peak_pct", "limit_peak_pct", "compact_manual", "compact_auto",
|
|
37
|
+
"spawned_builtin", "spawned_custom", "spawned_background", "forks", "teammates",
|
|
38
|
+
"mods", "mcp_servers", "custom_agents",
|
|
39
|
+
];
|
|
40
|
+
export const PEAK_FIELDS = ["context_peak_pct", "limit_peak_pct"];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The mod itself: a hooks module as Claude Code loads it (`register(on)`), written out by `installMod`. Plain
|
|
44
|
+
* JavaScript, no import, so the file Claude Code runs is the text below and nothing else; `claude plugin validate`
|
|
45
|
+
* lists what it uses: the events below, `fs.write`, `session.id` and `tool.list`.
|
|
46
|
+
*/
|
|
47
|
+
export const REGISTER_SOURCE = `// WorkTrust measure ${MOD_VERSION}: counts what a transcript cannot show, never a word of the session.
|
|
48
|
+
// Every hook returns what next() gave it: this mod observes and changes nothing. Written by the WorkTrust CLI.
|
|
49
|
+
const FIELDS = ${JSON.stringify(MOD_FIELDS)};
|
|
50
|
+
const PEAKS = new Set(${JSON.stringify(PEAK_FIELDS)});
|
|
51
|
+
const NOBODY_ASKED = new Set(["auto", "dontAsk", "bypassPermissions"]);
|
|
52
|
+
const EFFORTS = new Set(["low", "medium", "high", "xhigh", "max"]);
|
|
53
|
+
const days = {};
|
|
54
|
+
let file = null, session = null, mode = "default", main = null, dirty = false, written = 0;
|
|
55
|
+
const seen = { models: new Set(), servers: new Set(), agents: new Set(), mods: new Set() };
|
|
56
|
+
const asked = new Set();
|
|
57
|
+
const day = () => new Date().toISOString().slice(0, 10);
|
|
58
|
+
const row = () => (days[day()] ??= {});
|
|
59
|
+
const bump = (key) => { const r = row(); r[key] = Math.min(100000, (r[key] ?? 0) + 1); dirty = true; };
|
|
60
|
+
const set = (key, value) => { const r = row(); const v = Math.max(0, Math.min(PEAKS.has(key) ? 100 : 100000, Math.round(value))); if ((r[key] ?? -1) < v) { r[key] = v; dirty = true; } };
|
|
61
|
+
// The file's text when it is due (at most every five seconds, or now at the session's end); null when nothing changed.
|
|
62
|
+
function due(now) {
|
|
63
|
+
if (!file || !dirty || (!now && Date.now() - written < 5000)) return null;
|
|
64
|
+
dirty = false; written = Date.now();
|
|
65
|
+
const clean = {};
|
|
66
|
+
for (const [d, r] of Object.entries(days)) clean[d] = Object.fromEntries(FIELDS.filter((k) => Number.isInteger(r[k]) && r[k] > 0).map((k) => [k, r[k]]));
|
|
67
|
+
return JSON.stringify({ v: 1, mod: "${MOD_NAME}@${MOD_VERSION}", session, days: clean });
|
|
68
|
+
}
|
|
69
|
+
const MCP = /^mcp__(.+?)__/;
|
|
70
|
+
|
|
71
|
+
export function register(on) {
|
|
72
|
+
on("session.start", async ($, e, next) => {
|
|
73
|
+
try {
|
|
74
|
+
session = String(await $.session.id()).replace(/[^A-Za-z0-9_-]/g, "").slice(0, 80) || null;
|
|
75
|
+
const root = String($.plugin.root).replace(/[\\/]+$/, "");
|
|
76
|
+
if (session) file = root.replace(/[\\/][^\\/]+$/, "") + "/claude-mod-counts/" + session + ".json";
|
|
77
|
+
for (const tool of await $.tool.list()) { const m = MCP.exec(String(tool.name ?? "")); if (m) seen.servers.add(m[1]); }
|
|
78
|
+
set("mcp_servers", seen.servers.size);
|
|
79
|
+
set("mods", seen.mods.size);
|
|
80
|
+
set("custom_agents", seen.agents.size);
|
|
81
|
+
} catch {}
|
|
82
|
+
return next(e);
|
|
83
|
+
});
|
|
84
|
+
// The other mods the person runs, by count: a fact of their setup, never a name kept.
|
|
85
|
+
on("plugin.register", async ($, e, next) => {
|
|
86
|
+
try { if (e.tier === "user" && e.name !== "${MOD_NAME}") { seen.mods.add(e.name); set("mods", seen.mods.size); } } catch {}
|
|
87
|
+
return next(e);
|
|
88
|
+
});
|
|
89
|
+
// Their own agent types, offered beside the built-in ones.
|
|
90
|
+
on("agent.offer", async ($, e, next) => {
|
|
91
|
+
try { if (e.provider?.tier !== "core") { seen.agents.add(e.agent); set("custom_agents", seen.agents.size); } } catch {}
|
|
92
|
+
return next(e);
|
|
93
|
+
});
|
|
94
|
+
// Who answers a permission question: the person, unless a mode or a classifier does.
|
|
95
|
+
on("classic.UserPromptSubmit", async ($, e, next) => {
|
|
96
|
+
try { if (typeof e.permission_mode === "string") mode = e.permission_mode; } catch {}
|
|
97
|
+
return next(e);
|
|
98
|
+
});
|
|
99
|
+
on("tool.check", async ($, e, next) => {
|
|
100
|
+
const verdict = await next(e);
|
|
101
|
+
try { if (verdict?.decision === "ask" && !verdict.decider && !NOBODY_ASKED.has(mode) && e.tool_use_id) { asked.add(e.tool_use_id); bump("asked"); } } catch {}
|
|
102
|
+
return verdict;
|
|
103
|
+
});
|
|
104
|
+
on("tool.call", async ($, e, next) => {
|
|
105
|
+
const result = await next(e);
|
|
106
|
+
try { if (e.tool_use_id && asked.delete(e.tool_use_id)) bump(result && "deny" in result && typeof result.deny === "string" ? "declined" : "approved"); } catch {}
|
|
107
|
+
return result;
|
|
108
|
+
});
|
|
109
|
+
on("turn.step", async function* ($, e, next) {
|
|
110
|
+
try {
|
|
111
|
+
if (!e.agentId) main = e.model;
|
|
112
|
+
if (typeof e.effort === "string" && EFFORTS.has(e.effort)) bump("effort_" + e.effort);
|
|
113
|
+
if (e.model) { seen.models.add(e.model); set("models", seen.models.size); }
|
|
114
|
+
if (e.agentId && main && e.model && e.model !== main) bump("routed");
|
|
115
|
+
} catch {}
|
|
116
|
+
return yield* next(e);
|
|
117
|
+
});
|
|
118
|
+
on("agent.spawn", async ($, e, next) => {
|
|
119
|
+
try {
|
|
120
|
+
if (e.isTeammate) bump("teammates");
|
|
121
|
+
else if (e.fork) bump("forks");
|
|
122
|
+
else bump(e.provider?.tier === "core" ? "spawned_builtin" : "spawned_custom");
|
|
123
|
+
if (e.background) bump("spawned_background");
|
|
124
|
+
} catch {}
|
|
125
|
+
return next(e);
|
|
126
|
+
});
|
|
127
|
+
on("session.compact", async ($, e, next) => {
|
|
128
|
+
try { bump(e.trigger === "manual" ? "compact_manual" : "compact_auto"); } catch {}
|
|
129
|
+
return next(e);
|
|
130
|
+
});
|
|
131
|
+
on("session.measure", async ($, e, next) => {
|
|
132
|
+
try {
|
|
133
|
+
if (Number.isFinite(e.context?.percent)) set("context_peak_pct", e.context.percent);
|
|
134
|
+
for (const limit of e.rateLimits ?? []) if (Number.isFinite(limit?.percentUsed)) set("limit_peak_pct", limit.percentUsed);
|
|
135
|
+
} catch {}
|
|
136
|
+
return next(e);
|
|
137
|
+
});
|
|
138
|
+
on("turn.complete", async ($, e, next) => {
|
|
139
|
+
try { const text = due(false); if (text) await $.fs.write(file, text); } catch {}
|
|
140
|
+
return next(e);
|
|
141
|
+
});
|
|
142
|
+
on("session.end", async ($, e, next) => {
|
|
143
|
+
try { const text = due(true); if (text) await $.fs.write(file, text); } catch {}
|
|
144
|
+
return next(e);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
export const PLUGIN_JSON = { name: MOD_NAME, version: MOD_VERSION, description: "WorkTrust: counts how you work with Claude Code (permission answers, effort levels, context peaks, subagents), never a word of the session. Counts stay on this computer until the WorkTrust CLI reports a session.", author: { name: "WorkTrust", url: "https://worktrust.io" }, homepage: "https://worktrust.io", license: "MIT" };
|
|
150
|
+
export const HOOKS_JSON = { modules: ["./register.js"] };
|
|
151
|
+
|
|
152
|
+
const dirs = (home) => ({ plugin: join(home, ".worktrust", "claude-mod"), counts: join(home, ".worktrust", "claude-mod-counts"), settings: join(home, ".claude", "settings.json") });
|
|
153
|
+
const SEP = process.platform === "win32" ? ";" : ":";
|
|
154
|
+
const readSettings = (file) => (existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {});
|
|
155
|
+
function writeSettings(file, settings) {
|
|
156
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
157
|
+
if (existsSync(file)) writeFileSync(`${file}.worktrust-backup`, readFileSync(file));
|
|
158
|
+
writeFileSync(`${file}.worktrust-tmp`, JSON.stringify(settings, null, 2));
|
|
159
|
+
renameSync(`${file}.worktrust-tmp`, file);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Writes the mod to ~/.worktrust/claude-mod and names that directory in Claude Code's own settings
|
|
164
|
+
* (`env.CLAUDE_CODE_PLUGIN_DIRS`, the documented way to load a plugin directory in every session), keeping any
|
|
165
|
+
* directory already named there. The settings file is backed up beside itself first. Idempotent: a second run
|
|
166
|
+
* rewrites the files and changes no setting.
|
|
167
|
+
*/
|
|
168
|
+
export function installMod(home = homedir()) {
|
|
169
|
+
const at = dirs(home);
|
|
170
|
+
mkdirSync(join(at.plugin, ".claude-plugin"), { recursive: true });
|
|
171
|
+
mkdirSync(join(at.plugin, "hooks"), { recursive: true });
|
|
172
|
+
mkdirSync(at.counts, { recursive: true });
|
|
173
|
+
writeFileSync(join(at.plugin, ".claude-plugin", "plugin.json"), JSON.stringify(PLUGIN_JSON, null, 2) + "\n");
|
|
174
|
+
writeFileSync(join(at.plugin, "hooks", "hooks.json"), JSON.stringify(HOOKS_JSON, null, 2) + "\n");
|
|
175
|
+
writeFileSync(join(at.plugin, "hooks", "register.js"), REGISTER_SOURCE);
|
|
176
|
+
const settings = readSettings(at.settings);
|
|
177
|
+
const named = String(settings.env?.CLAUDE_CODE_PLUGIN_DIRS ?? "").split(SEP).filter(Boolean);
|
|
178
|
+
if (named.includes(at.plugin)) return { dir: at.plugin, settingsChanged: false };
|
|
179
|
+
settings.env = { ...(settings.env ?? {}), CLAUDE_CODE_PLUGIN_DIRS: [...named, at.plugin].join(SEP) };
|
|
180
|
+
writeSettings(at.settings, settings);
|
|
181
|
+
return { dir: at.plugin, settingsChanged: true };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Takes the mod out of Claude Code's settings and deletes it and the counts it kept. Other named directories stay. */
|
|
185
|
+
export function uninstallMod(home = homedir()) {
|
|
186
|
+
const at = dirs(home);
|
|
187
|
+
const settings = readSettings(at.settings);
|
|
188
|
+
const named = String(settings.env?.CLAUDE_CODE_PLUGIN_DIRS ?? "").split(SEP).filter(Boolean);
|
|
189
|
+
let settingsChanged = false;
|
|
190
|
+
if (named.includes(at.plugin)) {
|
|
191
|
+
const rest = named.filter((one) => one !== at.plugin);
|
|
192
|
+
const env = { ...settings.env };
|
|
193
|
+
if (rest.length) env.CLAUDE_CODE_PLUGIN_DIRS = rest.join(SEP); else delete env.CLAUDE_CODE_PLUGIN_DIRS;
|
|
194
|
+
if (Object.keys(env).length) settings.env = env; else delete settings.env;
|
|
195
|
+
writeSettings(at.settings, settings);
|
|
196
|
+
settingsChanged = true;
|
|
197
|
+
}
|
|
198
|
+
rmSync(at.plugin, { recursive: true, force: true });
|
|
199
|
+
rmSync(at.counts, { recursive: true, force: true });
|
|
200
|
+
return { settingsChanged };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Whether the mod is in place: its file written and its directory named in Claude Code's settings. */
|
|
204
|
+
export function modInstalled(home = homedir()) {
|
|
205
|
+
const at = dirs(home);
|
|
206
|
+
if (!existsSync(join(at.plugin, "hooks", "register.js"))) return false;
|
|
207
|
+
try { return String(readSettings(at.settings).env?.CLAUDE_CODE_PLUGIN_DIRS ?? "").split(SEP).includes(at.plugin); } catch { return false; }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The counts the mod kept for one Claude Code session on one UTC day, as the `live` evidence group: only the keys of
|
|
212
|
+
* `MOD_FIELDS`, only positive integers (the peaks at most 100, the rest at most 100,000). Null when the mod kept
|
|
213
|
+
* nothing for that session and day, so a stretch without the mod carries no group at all, never zeros.
|
|
214
|
+
*/
|
|
215
|
+
export function modCounts(sessionId, day, home = homedir()) {
|
|
216
|
+
if (!/^[A-Za-z0-9_-]{1,80}$/.test(String(sessionId ?? "")) || !/^\d{4}-\d{2}-\d{2}$/.test(String(day ?? ""))) return null;
|
|
217
|
+
const file = join(dirs(home).counts, `${sessionId}.json`);
|
|
218
|
+
if (!existsSync(file)) return null;
|
|
219
|
+
let kept;
|
|
220
|
+
try { kept = JSON.parse(readFileSync(file, "utf8")); } catch { return null; }
|
|
221
|
+
const row = kept?.days?.[day];
|
|
222
|
+
if (!row || typeof row !== "object") return null;
|
|
223
|
+
const out = {};
|
|
224
|
+
for (const key of MOD_FIELDS) {
|
|
225
|
+
const value = row[key];
|
|
226
|
+
if (!Number.isInteger(value) || value <= 0) continue;
|
|
227
|
+
out[key] = Math.min(PEAK_FIELDS.includes(key) ? 100 : 100000, value);
|
|
228
|
+
}
|
|
229
|
+
return Object.keys(out).length ? out : null;
|
|
230
|
+
}
|
package/log-session.mjs
CHANGED
|
@@ -263,7 +263,7 @@ const excluded = (path) => excludes.some((text) => text && path.includes(text));
|
|
|
263
263
|
* reader), the database clients in session-databases.mjs. The install copies both into ~/.worktrust with this hook.
|
|
264
264
|
* Without them this hook still reads Claude Code; the never-matching patterns keep every other client out.
|
|
265
265
|
*/
|
|
266
|
-
const { CODEX_ROLLOUT = /(?!)/, codexIdOf = (file) => String(file).split(/[\\/]/).at(-1).replace(/\.jsonl$/, ""), antigravityIdOf = (file) => String(file).split(/[\\/]/).at(-4), codexLines, codexRolloutFiles = function* () {}, codexCwd = () => null, ANTIGRAVITY_TRANSCRIPT = /(?!)/, antigravityLines, antigravityRoots = () => [], antigravityTranscripts = function* () {}, antigravityContext = () => ({}), rememberAntigravity = () => null } = (await import("./transcript-readers.mjs").catch(() => null)) ?? {};
|
|
266
|
+
const { CODEX_ROLLOUT = /(?!)/, codexIdOf = (file) => String(file).split(/[\\/]/).at(-1).replace(/\.jsonl$/, ""), antigravityIdOf = (file) => String(file).split(/[\\/]/).at(-4), codexLines, codexRolloutFiles = function* () {}, codexCwd = () => null, ANTIGRAVITY_TRANSCRIPT = /(?!)/, antigravityLines, antigravityRoots = () => [], antigravityTranscripts = function* () {}, antigravityContext = () => ({}), rememberAntigravity = () => null, codexLive = () => null } = (await import("./transcript-readers.mjs").catch(() => null)) ?? {};
|
|
267
267
|
// THE STRETCH'S DERIVED RECORD (0.7.4: split from this file): tool calls named by kind, verification, recovery, delegation,
|
|
268
268
|
// context and routing, for the local archive only. A copy without the module still measures and sends exactly as before.
|
|
269
269
|
const { callOf = (block) => ({ id: block.id, kinds: [], family: String(block.name), digest: "" }), deriveStretch = () => ({}), complexityOf = null, resultOf = (block) => ({ id: block.tool_use_id, failed: block.is_error === true, refusal: null }) } = (await import("./stretch-evidence.mjs").catch(() => null)) ?? {};
|
|
@@ -271,11 +271,13 @@ const { DATABASE_SESSION = /(?!)/, databaseLines = () => null, databaseSessions
|
|
|
271
271
|
// A WEB CHAT'S DATA EXPORT AS HISTORY (0.10.10, owner 2026-10-10): chat-exports.mjs reads a ChatGPT or Claude export (the counter
|
|
272
272
|
// imports the same reader); `--history --export <path>` sends its conversations as RECONSTRUCTED days, never measured, never tokens.
|
|
273
273
|
const { EXPORT_CLIENTS = [], EXPORT_TITLES = {}, exportSessions = null, exportRef = null, readExport = null, findExports = null } = (await import("./chat-exports.mjs").catch(() => null)) ?? {};
|
|
274
|
+
const { modCounts = () => null } = (await import("./claude-mod.mjs").catch(() => null)) ?? {}; // 0.10.15: the WorkTrust mod's live counts per Claude Code session and day; absent → no `live` group, never zeros
|
|
275
|
+
const liveOf = (file, day) => modCounts(String(file).split(/[\\/]/).pop().replace(/\.jsonl$/, ""), day) ?? codexLive(file, day); // 0.10.16: a Codex rollout's own
|
|
274
276
|
const { stackOfFiles = () => [], displayStackOfFiles = () => [] } = (await import("./stack-rules.mjs").catch(() => null)) ?? {}; // 0.10.11: core's stack rules and the display-only keys (tools_seen), generated (build-stack-rules --check); absent → nothing named, never a guess
|
|
275
277
|
const EXPORT_PATHS = []; for (let i = 0; i < args.length; i += 1) if (args[i] === "--export" && args[i + 1]) EXPORT_PATHS.push(args[i + 1]);
|
|
276
278
|
const DATABASE_CLIENTS = ["hermes", "goose", "opencode", "openclaw", "cursor", "copilot"]; // the registry's keys, the name each line carries
|
|
277
279
|
const LIVE_SOURCE = new RegExp(`^(codex|antigravity|${DATABASE_CLIENTS.join("|")}):`); // a sweep entry's id → the client it names (every database client, 0.6.16)
|
|
278
|
-
const READER_FILES = ["transcript-readers.mjs", "session-databases.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules
|
|
280
|
+
const READER_FILES = ["transcript-readers.mjs", "session-databases.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "claude-mod.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules; 0.10.15: the mod
|
|
279
281
|
/** The readers go where the hook and the counter run: copied from beside this file, else (or for a newer counter) from the deployment. */
|
|
280
282
|
async function installReaders(origin, fromNetwork = false) {
|
|
281
283
|
let installed = true;
|
|
@@ -415,7 +417,7 @@ function stretchesOf(file, since) {
|
|
|
415
417
|
messages.sort((a, b) => a.at - b.at);
|
|
416
418
|
const byDay = byDayOf(messages);
|
|
417
419
|
const agents = agentsByDay(file, since);
|
|
418
|
-
return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, ofDay]) => { const stretch = measure(cwd, ofDay); return stretch && { ...stretch, ref: stretchRef(file, day), steered, agents: agents.get(day) ?? null }; }).filter(Boolean);
|
|
420
|
+
return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, ofDay]) => { const stretch = measure(cwd, ofDay); return stretch && { ...stretch, ref: stretchRef(file, day), steered, agents: agents.get(day) ?? null, live: liveOf(file, day) }; }).filter(Boolean);
|
|
419
421
|
}
|
|
420
422
|
|
|
421
423
|
/**
|
|
@@ -666,6 +668,7 @@ function payloadFor(stretch) {
|
|
|
666
668
|
const coauthored = cwd && touched.shas.length > 0 ? git(cwd, "log", "--no-walk", "--format=%(trailers:key=Co-authored-by,valueonly,separator=%x01)%x00", ...touched.shas.slice(0, 50)).split("\0").filter((entry, index) => index < Math.min(50, touched.shas.length) && AI_COAUTHOR.test(entry)).length : 0;
|
|
667
669
|
const route = { ...(stretch.derived?.route ?? {}), ...(touched.committed ? gitRouteOf(cwd, touched.shas, changed) : {}) };
|
|
668
670
|
const derived = stretch.derived ? { ...stretch.derived, ...(Object.keys(route).length > 0 ? { route } : {}), ...(changed.length > 0 ? { changes: { files: changed.length, test_files: tests } } : {}), ...(touched.shas.length > 0 ? { authorship: { commits: Math.min(50, touched.shas.length), ai_coauthored: coauthored } } : {}), ...(contextFilesOf(changed) ? { context_files: contextFilesOf(changed) } : {}), ...(complexityOf ? { complexity: complexityOf(stretch.derived, { layers: Math.max(layers.length, layer ? 1 : 0), agentRuns: stretch.agents?.runs ?? 0, agentPeak: stretch.agents?.peak ?? 0, seconds: stretch.seconds }) } : {}) } : null;
|
|
671
|
+
const evidence = derived || stretch.live ? { ...(derived ?? {}), ...(stretch.live ? { live: stretch.live } : {}) } : null; // 0.10.15: the mod's counts ride as their own group
|
|
669
672
|
const payload = {
|
|
670
673
|
title: layer ? `AI-assisted work · ${layer}` : "AI-assisted work",
|
|
671
674
|
kind,
|
|
@@ -698,12 +701,12 @@ function payloadFor(stretch) {
|
|
|
698
701
|
...(stretch.steers > 0 ? { steers: Math.min(10000, stretch.steers) } : {}),
|
|
699
702
|
...(stretch.agents && stretch.agents.runs > 0 ? { agent_runs: Math.min(AGENT_RUNS_MAX, stretch.agents.runs), agent_seconds: Math.min(AGENT_SECONDS_MAX, stretch.agents.seconds), agent_peak: Math.min(AGENT_RUNS_MAX, stretch.agents.peak) } : {}),
|
|
700
703
|
// THE STRETCH'S EVIDENCE (0.8.3): what the CLI derived from it here, kinds and counts only (stretch-evidence.mjs); the door keeps it from a CLI key alone.
|
|
701
|
-
...(
|
|
704
|
+
...(evidence ? { evidence } : {}),
|
|
702
705
|
at: new Date(stretch.to).toISOString(),
|
|
703
706
|
};
|
|
704
707
|
// WHAT STAYS ON THIS COMPUTER (0.7.1): the stretch's derived record rides beside the payload for the local archive, never in it.
|
|
705
708
|
// The same record rides beside the payload for the local archive (preserve --archive).
|
|
706
|
-
if (
|
|
709
|
+
if (evidence) DERIVED.set(payload, evidence);
|
|
707
710
|
return payload;
|
|
708
711
|
}
|
|
709
712
|
|
|
@@ -845,7 +848,7 @@ function historyEntries(floor = null, all = false) {
|
|
|
845
848
|
// The live window belongs to the hook: a stretch that log_work may still report is not history.
|
|
846
849
|
if (!all && Date.now() - last < WINDOW_HOURS * 3600_000) continue;
|
|
847
850
|
// The same measure as a live day (seconds, layers, tokens, turns, model); history differs only in the door it goes through.
|
|
848
|
-
const entry = payloadFor({ ...measure(cwd, messages), ref: stretchRef(file, day), steered, agents: agents.get(day) ?? null });
|
|
851
|
+
const entry = payloadFor({ ...measure(cwd, messages), ref: stretchRef(file, day), steered, agents: agents.get(day) ?? null, live: liveOf(file, day) });
|
|
849
852
|
if (CODEX_ROLLOUT.test(file)) entrySource.set(entry, "codex");
|
|
850
853
|
if (ANTIGRAVITY_TRANSCRIPT.test(file)) entrySource.set(entry, "antigravity");
|
|
851
854
|
if (DATABASE_SESSION.test(file)) entrySource.set(entry, file.slice(0, file.indexOf(":")));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.16",
|
|
4
4
|
"description": "Couple this computer to WorkTrust: approve a code in your browser, and every AI app here reports what you built. Metadata only, no dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"CLAUDE.md",
|
|
29
29
|
"orchestration-contract.mjs",
|
|
30
30
|
"orchestration-evidence.mjs",
|
|
31
|
-
"orchestration-report.mjs"
|
|
31
|
+
"orchestration-report.mjs",
|
|
32
|
+
"claude-mod.mjs"
|
|
32
33
|
],
|
|
33
34
|
"engines": {
|
|
34
35
|
"node": ">=18"
|
package/transcript-readers.mjs
CHANGED
|
@@ -102,6 +102,38 @@ export function* codexLines(records) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
/** Every rollout under a Codex sessions root, in a stable order. */
|
|
105
|
+
/**
|
|
106
|
+
* WHAT A CODEX ROLLOUT SHOWS OF HOW THE PERSON STEERS (CLI 0.10.16, owner 2026-10-16): the same `live` keys the WorkTrust
|
|
107
|
+
* mod fills inside Claude Code, read from what Codex itself writes, so nothing is installed. Per UTC day of one rollout:
|
|
108
|
+
* each turn by its effort level (`turn_context.effort`; per TURN here, per request in Claude Code), the models that
|
|
109
|
+
* answered, the highest context fill (a request's input tokens over the model's window) and the highest plan-limit use
|
|
110
|
+
* (`rate_limits.primary`/`secondary.used_percent`), as whole percentages. Compactions and subagents stay out: the rollout
|
|
111
|
+
* does not say who started them, and a guess is noise. Null when the day shows none of it.
|
|
112
|
+
*/
|
|
113
|
+
const EFFORT_LEVELS = new Set(["low", "medium", "high", "xhigh", "max"]);
|
|
114
|
+
export function codexLive(file, day) {
|
|
115
|
+
if (!CODEX_ROLLOUT.test(String(file)) || !/^\d{4}-\d{2}-\d{2}$/.test(String(day))) return null;
|
|
116
|
+
let text; try { text = readFileSync(file, "utf8"); } catch { return null; }
|
|
117
|
+
const out = {}, models = new Set();
|
|
118
|
+
const peak = (key, value) => { if (Number.isFinite(value)) { const v = Math.max(0, Math.min(100, Math.round(value))); if (v > 0 && (out[key] ?? 0) < v) out[key] = v; } };
|
|
119
|
+
for (const raw of text.split("\n")) {
|
|
120
|
+
if (!raw.includes(day)) continue;
|
|
121
|
+
let record; try { record = JSON.parse(raw); } catch { continue; }
|
|
122
|
+
if (String(record?.timestamp ?? "").slice(0, 10) !== day) continue;
|
|
123
|
+
const p = record?.payload && typeof record.payload === "object" ? record.payload : {};
|
|
124
|
+
if (record.type === "turn_context") {
|
|
125
|
+
if (typeof p.effort === "string" && EFFORT_LEVELS.has(p.effort)) out[`effort_${p.effort}`] = Math.min(100000, (out[`effort_${p.effort}`] ?? 0) + 1);
|
|
126
|
+
if (typeof p.model === "string" && p.model) models.add(p.model);
|
|
127
|
+
} else if (record.type === "event_msg" && p.type === "token_count") {
|
|
128
|
+
const window = p.info?.model_context_window, input = p.info?.last_token_usage?.input_tokens;
|
|
129
|
+
if (Number.isFinite(window) && window > 0 && Number.isFinite(input)) peak("context_peak_pct", (input / window) * 100);
|
|
130
|
+
for (const limit of [p.rate_limits?.primary, p.rate_limits?.secondary]) peak("limit_peak_pct", limit?.used_percent);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (models.size > 0) out.models = models.size;
|
|
134
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
135
|
+
}
|
|
136
|
+
|
|
105
137
|
export function* codexRolloutFiles(root) {
|
|
106
138
|
let entries = []; try { entries = readdirSync(root, { withFileTypes: true }); } catch { return; }
|
|
107
139
|
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
package/worktrust.mjs
CHANGED
|
@@ -75,7 +75,7 @@ import { homedir, hostname, platform } from "node:os";
|
|
|
75
75
|
import { dirname, join } from "node:path";
|
|
76
76
|
import { createInterface } from "node:readline/promises";
|
|
77
77
|
import { createInterface as lines } from "node:readline";
|
|
78
|
-
import { fileURLToPath } from "node:url";
|
|
78
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
79
79
|
|
|
80
80
|
const args = process.argv.slice(2);
|
|
81
81
|
const VALUED = ["--name", "--origin", "--url", "--export", "--from-folder"];
|
|
@@ -83,12 +83,12 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
83
83
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
84
84
|
const has = (name) => args.includes(`--${name}`);
|
|
85
85
|
/** 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). */
|
|
86
|
-
const CLI_VERSION = "0.10.
|
|
86
|
+
const CLI_VERSION = "0.10.16";
|
|
87
87
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
88
88
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
89
89
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
90
90
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
91
|
-
const SCRIPTS = ["setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs"];
|
|
91
|
+
const SCRIPTS = ["setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs"];
|
|
92
92
|
/** The modules the scripts import by name from beside them; a download keeps that name. */
|
|
93
93
|
const IMPORTED = new Set(["transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs"]);
|
|
94
94
|
const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
|
|
@@ -1012,6 +1012,8 @@ async function disconnect() {
|
|
|
1012
1012
|
if (!(await ask("Continue?"))) { say(" Stopped. Nothing was changed."); return; }
|
|
1013
1013
|
await run(paths["setup-mcp.mjs"], ["--remove", "--write"], PLACEHOLDER);
|
|
1014
1014
|
await run(paths["log-session.mjs"], ["--uninstall", "--purge"], PLACEHOLDER);
|
|
1015
|
+
// 0.10.15: the WorkTrust mod goes with the coupling, and what it counted with it.
|
|
1016
|
+
try { const mod = await import(pathToFileURL(paths["claude-mod.mjs"]).href); if (mod.modInstalled()) { mod.uninstallMod(); say(" ✓ The WorkTrust mod is out of Claude Code, and what it counted is deleted."); } } catch { /* never installed */ }
|
|
1015
1017
|
if (removeCodexNotify()) say(" ✓ Codex no longer wakes the session hook.");
|
|
1016
1018
|
if (removeAntigravityHook()) say(" ✓ Antigravity no longer wakes the session hook.");
|
|
1017
1019
|
previousNote.save(keyStore.load());
|
|
@@ -1023,6 +1025,47 @@ async function disconnect() {
|
|
|
1023
1025
|
say(" Done. Revoke the key in WorkTrust to finish.");
|
|
1024
1026
|
}
|
|
1025
1027
|
|
|
1028
|
+
/**
|
|
1029
|
+
* THE WORKTRUST MOD FOR CLAUDE CODE (0.10.15, owner 2026-10-16; claude-mod.mjs, docs/CLAUDE-CODE-MOD.md). The person turns
|
|
1030
|
+
* it on and off here; nothing else installs it. On: Claude Code (2.1.287 or later) loads it in every session, and it
|
|
1031
|
+
* counts, per session and day, what a transcript cannot show. Its counts stay in ~/.worktrust/claude-mod-counts until
|
|
1032
|
+
* the session hook reports that session's stretch, beside the rest; they reach the person's own mirror, never a score.
|
|
1033
|
+
*/
|
|
1034
|
+
async function mod() {
|
|
1035
|
+
const paths = await scripts();
|
|
1036
|
+
const kit = await import(pathToFileURL(paths["claude-mod.mjs"]).href);
|
|
1037
|
+
const sub = args[1] ?? "status";
|
|
1038
|
+
const on = kit.modInstalled();
|
|
1039
|
+
say();
|
|
1040
|
+
say(` WorkTrust mod for Claude Code · ${on ? "on" : "off"}`);
|
|
1041
|
+
say();
|
|
1042
|
+
if (sub === "install") {
|
|
1043
|
+
say(" It runs inside Claude Code and counts, per session and day, what a transcript cannot show:");
|
|
1044
|
+
say(" · permission questions put to you, and how often you said yes or no");
|
|
1045
|
+
say(" · model requests per effort level, the models that answered, requests sent to another model");
|
|
1046
|
+
say(" · the peak context fill and plan-limit use, compactions you asked for or that ran by themselves");
|
|
1047
|
+
say(" · subagents and teammates started, and how many mods, MCP servers and own agent types are active");
|
|
1048
|
+
say(" Counts only: never a prompt, an answer, a command, a file or a name. It sends nothing itself: your session hook");
|
|
1049
|
+
say(" reports the counts with the session, and they show in your own mirror, not on your passport.");
|
|
1050
|
+
say(` It names ~/.worktrust/claude-mod in ~/.claude/settings.json (CLAUDE_CODE_PLUGIN_DIRS), backed up first. Claude Code ${kit.MIN_CLAUDE_CODE} or later.`);
|
|
1051
|
+
say();
|
|
1052
|
+
if (on && !has("yes")) { kit.installMod(); say(" Already on. Its file is refreshed; nothing else changed."); return; }
|
|
1053
|
+
if (!(await ask("Turn it on?"))) { say(" Stopped. Nothing was changed."); return; }
|
|
1054
|
+
const done = kit.installMod();
|
|
1055
|
+
say(` ✓ On: ${done.dir}${done.settingsChanged ? " (named in ~/.claude/settings.json)" : ""}. Start a new Claude Code session, or run /reload-plugins in an open one.`);
|
|
1056
|
+
say(" In Claude Code, /plugin then shows: 1 mod active · worktrust-measure.");
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
if (sub === "remove" || sub === "uninstall") {
|
|
1060
|
+
if (!on) { say(" It is not on. Nothing to remove."); return; }
|
|
1061
|
+
if (!(await ask("Turn it off and delete what it counted?"))) { say(" Stopped. Nothing was changed."); return; }
|
|
1062
|
+
kit.uninstallMod();
|
|
1063
|
+
say(" ✓ Off. It is out of ~/.claude/settings.json and its counts are deleted. Counts already reported stay in your mirror.");
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
say(on ? " On: Claude Code loads it in every new session. `worktrust mod remove` turns it off." : " Off. `worktrust mod install` shows what it counts and asks first.");
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1026
1069
|
async function status() {
|
|
1027
1070
|
const servers = {};
|
|
1028
1071
|
try {
|
|
@@ -1116,6 +1159,9 @@ function help() {
|
|
|
1116
1159
|
say(" worktrust disconnect take WorkTrust out of every AI app here (asks first)");
|
|
1117
1160
|
say(" worktrust status what is coupled here");
|
|
1118
1161
|
say(" worktrust orchestration report --file recording.jsonl inspect local agent metadata; sends nothing");
|
|
1162
|
+
say(" worktrust mod the WorkTrust mod for Claude Code: what it counts, and whether it is on");
|
|
1163
|
+
say(" install turn it on: counts permission answers, effort levels, context peaks and subagents (asks first)");
|
|
1164
|
+
say(" remove turn it off and delete what it counted");
|
|
1119
1165
|
say(" worktrust preserve keep your AI history: the report, then the settings and a local archive, each on your yes");
|
|
1120
1166
|
say(" --apply keep them: asks per change, backs the file up first (--yes: no question)");
|
|
1121
1167
|
say(" --archive [dir] a local, metadata-only, hash-chained record of the measured days (~/AI-Evidence)");
|
|
@@ -1131,7 +1177,7 @@ function help() {
|
|
|
1131
1177
|
// before anything is read or written, --yes included. The hook and the MCP bridge are started by the agent's client
|
|
1132
1178
|
// itself and stay as they are; `status` only reads.
|
|
1133
1179
|
const AGENT_ENV = ["CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CODEX_SANDBOX", "CODEX_CI", "GEMINI_CLI", "CURSOR_AGENT", "OPENCODE", "CLINE_ACTIVE", "AIDER_CHAT", "ANTIGRAVITY_AGENT", "WINDSURF_AGENT"];
|
|
1134
|
-
const PERSON_ONLY = new Set(["default", "connect", "update", "history", "disconnect", "preserve", "codex", "antigravity", "sources", "web", "import", "orchestration"]);
|
|
1180
|
+
const PERSON_ONLY = new Set(["default", "connect", "update", "history", "disconnect", "preserve", "codex", "antigravity", "sources", "web", "import", "orchestration", "mod"]);
|
|
1135
1181
|
const agentShell = AGENT_ENV.find((name) => process.env[name] && process.env[name] !== "0");
|
|
1136
1182
|
if (agentShell && PERSON_ONLY.has(command)) {
|
|
1137
1183
|
say();
|
|
@@ -1194,6 +1240,7 @@ else if (command === "antigravity") await offerAntigravity();
|
|
|
1194
1240
|
else if (command === "disconnect") await disconnect();
|
|
1195
1241
|
else if (command === "status") await status();
|
|
1196
1242
|
else if (command === "preserve") await preserve();
|
|
1243
|
+
else if (command === "mod") await mod();
|
|
1197
1244
|
else if (command === "orchestration") {
|
|
1198
1245
|
if (!["orchestration-report.mjs", "orchestration-evidence.mjs", "orchestration-contract.mjs"].every((name) => existsSync(join(HERE, name)))) fail("Local agent reports need the complete WorkTrust npm/Python package or preservation kit. No file was read or sent.");
|
|
1199
1246
|
const { reportFile } = await import("./orchestration-report.mjs"); reportFile(args.slice(1));
|