worktrust 0.8.6 → 0.8.7

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 CHANGED
@@ -171,6 +171,7 @@ nothing it does not:
171
171
  | `supplements` | a supplement line: when a newer CLI measures more of a stretch already archived, the new fields go into a line of their own that names that stretch; nothing earlier is rewritten, and the chain and the day's root cover it (0.8.2) |
172
172
  | `evidence` (sent) | the same derived record now also travels with each stretch to WorkTrust, kinds and counts only, and `npx worktrust status` shows what this computer measured in the last thirty days (0.8.3) |
173
173
  | `unconfirmed` | checks the stretch ran whose outcome no reader could see (Codex's code mode prints no exit code; a background terminal), per kind: counted, never as a pass (0.8.5) |
174
+ | `autonomy`, `authorship` | the permission mode the AI app ran in, on one scale (ask, edits, plan, auto, full), how often it changed and the turns in plan mode; of the stretch's commits, how many name an AI as co-author (the trailer is read here, its names never leave) (0.8.7) |
174
175
  | `collector_version` | the CLI version that measured it |
175
176
  | `seq`, `prev`, `hash` | the line's place, the hash of the line before it, and its own hash |
176
177
 
package/log-session.mjs CHANGED
@@ -135,6 +135,8 @@ const DAY_SECONDS = 86400;
135
135
  const TOOL_CAP = 1800;
136
136
  /** Tools whose result waits for the person: the gap to it is the person's time. Names only; nothing of the call is read. */
137
137
  const WAITS_FOR_PERSON = new Set(["AskUserQuestion", "ExitPlanMode"]);
138
+ /** An AI named as a commit's co-author by the tools that sign their work that way (read locally; the name never leaves). */
139
+ const AI_COAUTHOR = /\b(claude|anthropic|codex|openai|chatgpt|copilot|cursor|devin|gemini|jules|aider|windsurf|cline)\b/i;
138
140
  /** A path that holds tests, by the conventions of the common test runners (read here; the path never leaves). */
139
141
  const TEST_PATH = /(^|[\\/])(__tests__|tests?|spec|e2e)[\\/]|\.(test|spec)\.[cm]?[jt]sx?$|_test\.(go|py|rb)$|(^|[\\/])test_[^\\/]+\.py$|Tests?\.(java|kt|cs|swift)$/;
140
142
  /** The derived record of a stretch, kept for the local archive only (see payloadFor). */
@@ -397,6 +399,8 @@ const messageOf = (line, at) => {
397
399
  // out, the hook counted it as a turn and the gap before it as the person's time. It is the loop's own, like a meta line.
398
400
  at, type: line.type, usage: line.message?.usage ?? null, model: line.message?.model ?? null, messageId: typeof line.message?.id === "string" ? line.message.id : null, meta: line.isMeta === true || line.isCompactSummary === true, content,
399
401
  compacted: line.isCompactSummary === true,
402
+ // 0.8.7: the permission mode the client recorded for this turn (Claude Code's own word; a reader's for Codex), never more.
403
+ permissionMode: typeof line.permissionMode === "string" ? line.permissionMode : null,
400
404
  // A tool's answer comes back on the user role; a line a reader marks `agentic` is an agent run (Copilot's asked → completed).
401
405
  kind: line.type === "assistant" ? "assistant" : blocks.some((block) => block && block.type === "tool_result") ? "tool_result" : "user",
402
406
  toolUse: line.type === "assistant" && blocks.some((block) => block && block.type === "tool_use"),
@@ -602,7 +606,9 @@ function payloadFor(stretch) {
602
606
  // 0.8.1: what the stretch changed, as counts of files (never their paths): how many, and how many of them tests.
603
607
  // 0.7.6: and the stretch's complexity class, read from what the hook knows here (layers, subagents, duration) and the record.
604
608
  const changed = [...new Set(touched.paths)], tests = changed.filter((path) => TEST_PATH.test(path)).length;
605
- const derived = stretch.derived ? { ...stretch.derived, ...(changed.length > 0 ? { changes: { files: changed.length, test_files: tests } } : {}), ...(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;
609
+ // 0.8.7: of the stretch's commits, how many name an AI as co-author (the Co-authored-by trailer, read here, never kept).
610
+ 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;
611
+ const derived = stretch.derived ? { ...stretch.derived, ...(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 } } : {}), ...(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;
606
612
  const payload = {
607
613
  title: layer ? `AI-assisted work · ${layer}` : "AI-assisted work",
608
614
  kind,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
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": {
@@ -98,6 +98,10 @@ export function archiveLine(entry, behaviour = null, { ids = {}, collector, salt
98
98
  if (planning && planning.lists > 0 && planning.done_last <= planning.items_last && planning.items_last <= planning.items_max) line.planning = planning;
99
99
  const changes = pick(entry.changes, ["files", "test_files"]);
100
100
  if (changes && changes.test_files <= changes.files) line.changes = changes;
101
+ // AUTONOMY AND AUTHORSHIP (0.8.7): the permission mode on one scale; commits and those naming an AI as co-author.
102
+ if (entry.autonomy && ["ask", "edits", "plan", "auto", "full"].includes(entry.autonomy.mode) && whole(entry.autonomy.switches) && whole(entry.autonomy.plan_turns)) line.autonomy = { mode: entry.autonomy.mode, switches: entry.autonomy.switches, plan_turns: entry.autonomy.plan_turns };
103
+ const authorship = pick(entry.authorship, ["commits", "ai_coauthored"]);
104
+ if (authorship && authorship.commits > 0 && authorship.ai_coauthored <= authorship.commits) line.authorship = authorship;
101
105
  // The behaviour signals of this stretch (0.7.0): keys of the counter's rubric and whole counts, never a word of a turn.
102
106
  if (behaviour && behaviour.signals && typeof behaviour.analyzer_version === "string" && /^counter@\d+\.\d+\.\d+$/.test(behaviour.analyzer_version)) {
103
107
  const kept = Object.entries(behaviour.signals).filter(([key, count]) => SIGNAL.test(key) && Number.isInteger(count) && count > 0).sort();
@@ -145,7 +149,7 @@ export function archiveEntries(dir, ownKey) {
145
149
  * a line of their own that names the stretch it adds to (`supplements`) and carries only what no earlier line of that
146
150
  * stretch carries, in the same chain, under the same day's root. Null when there is nothing new.
147
151
  */
148
- export const DERIVED_KEYS = ["signals", "analyzer_version", "verification", "unconfirmed", "delivery", "recovery", "delegation", "context", "routing", "steering", "tools", "complexity", "oversight", "planning", "changes", "interrupts", "steers", "utc_offset"];
152
+ export const DERIVED_KEYS = ["signals", "analyzer_version", "verification", "unconfirmed", "delivery", "recovery", "delegation", "context", "routing", "steering", "tools", "complexity", "oversight", "planning", "changes", "autonomy", "authorship", "interrupts", "steers", "utc_offset"];
149
153
  export function supplementFor(line, earlier) {
150
154
  const missing = DERIVED_KEYS.filter((key) => line[key] !== undefined && !earlier.some((old) => old[key] !== undefined));
151
155
  if (missing.length === 0) return null;
@@ -237,9 +237,28 @@ function planningOf(messages) {
237
237
  return { lists: lists.length, items_max: Math.max(...lists.map((list) => list.items)), items_last: last.items, done_last: last.done };
238
238
  }
239
239
 
240
+ /**
241
+ * THE AUTONOMY THE PERSON GAVE (0.8.7; framework L5, "autonomy calibration"): the permission mode the client ran in, on
242
+ * one common scale (ask, edits, plan, auto, full), as the mode most turns ran in, how often it changed, and how many
243
+ * turns ran in plan mode. Claude Code records its own word per turn; the Codex reader maps its approval policy and
244
+ * sandbox. Null where no client recorded one.
245
+ */
246
+ const MODE_SCALE = { default: "ask", ask: "ask", acceptEdits: "edits", edits: "edits", plan: "plan", auto: "auto", bypassPermissions: "full", dontAsk: "full", full: "full" };
247
+ function autonomyOf(messages) {
248
+ const modes = [];
249
+ for (const message of messages) if (!message.bridge && message.permissionMode && MODE_SCALE[message.permissionMode]) modes.push(MODE_SCALE[message.permissionMode]);
250
+ if (modes.length === 0) return null;
251
+ const tally = {};
252
+ for (const mode of modes) tally[mode] = (tally[mode] ?? 0) + 1;
253
+ const mode = Object.entries(tally).sort((a, b) => b[1] - a[1])[0][0];
254
+ let switches = 0;
255
+ for (let i = 1; i < modes.length; i += 1) if (modes[i] !== modes[i - 1]) switches += 1;
256
+ return { mode, switches, plan_turns: tally.plan ?? 0 };
257
+ }
258
+
240
259
  /** The stretch's whole derived record; `helpers` are the hook's own readers of a human turn, so both read it the same way. */
241
260
  export function deriveStretch(messages, helpers) {
242
261
  const context = contextOf(messages, helpers), routing = routingOf(messages), steering = steeringOf(messages, helpers);
243
- const tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages);
244
- return { ...(oversight ? { oversight } : {}), ...(planning ? { planning } : {}), ...verificationOf(messages, helpers), ...(context ? { context } : {}), ...(routing ? { routing } : {}), ...(steering ? { steering } : {}), ...(tools ? { tools } : {}) };
262
+ const tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages);
263
+ return { ...(oversight ? { oversight } : {}), ...(planning ? { planning } : {}), ...(autonomy ? { autonomy } : {}), ...verificationOf(messages, helpers), ...(context ? { context } : {}), ...(routing ? { routing } : {}), ...(steering ? { steering } : {}), ...(tools ? { tools } : {}) };
245
264
  }
@@ -56,7 +56,7 @@ export const codexToolInput = (name, raw) => {
56
56
  export const codexOutputText = (output) => (typeof output === "string" ? output : Array.isArray(output) ? output.map((part) => (typeof part === "string" ? part : part?.text ?? "")).join("\n") : "");
57
57
  /** The rollout's raw JSON lines → transcript-shaped line objects, in file order. */
58
58
  export function* codexLines(records) {
59
- let cwd = null, model = null;
59
+ let cwd = null, model = null, mode = null;
60
60
  const seenResponses = new Set();
61
61
  for (const raw of records) {
62
62
  if (!raw || !String(raw).trim()) continue;
@@ -64,7 +64,13 @@ export function* codexLines(records) {
64
64
  const timestamp = typeof record?.timestamp === "string" ? record.timestamp : null;
65
65
  const payload = record?.payload && typeof record.payload === "object" ? record.payload : {};
66
66
  if (record.type === "session_meta") { if (typeof payload.cwd === "string") cwd = payload.cwd; continue; }
67
- if (record.type === "turn_context") { if (typeof payload.cwd === "string") cwd = payload.cwd; if (typeof payload.model === "string") model = payload.model; continue; }
67
+ if (record.type === "turn_context") {
68
+ if (typeof payload.cwd === "string") cwd = payload.cwd; if (typeof payload.model === "string") model = payload.model;
69
+ // 0.8.7: Codex's approval policy and sandbox, as one word on the common scale (never asks and full access is "full").
70
+ const approval = String(payload.approval_policy ?? ""), sandbox = String(payload.sandbox_policy?.type ?? payload.sandbox_policy ?? payload.sandbox_mode ?? "");
71
+ mode = approval === "never" ? (sandbox === "danger-full-access" ? "full" : "auto") : approval === "on-failure" ? "edits" : approval ? "ask" : mode;
72
+ continue;
73
+ }
68
74
  if (record.type === "token_usage_record") {
69
75
  const id = String(payload.response_id ?? "");
70
76
  const usage = payload.usage;
@@ -80,7 +86,7 @@ export function* codexLines(records) {
80
86
  if (payload.role !== "user" && payload.role !== "assistant") continue;
81
87
  const text = Array.isArray(payload.content) ? payload.content.filter((part) => typeof part?.text === "string").map((part) => part.text).join("\n") : typeof payload.content === "string" ? payload.content : "";
82
88
  if (payload.role === "user" && CODEX_HARNESS_TURN.test(text)) continue;
83
- yield { type: payload.role, timestamp, cwd, uuid: payload.id ? `codex-${payload.id}` : undefined, message: { ...(payload.role === "assistant" && model ? { model } : {}), content: [{ type: "text", text }] } };
89
+ yield { type: payload.role, timestamp, cwd, ...(mode ? { permissionMode: mode } : {}), uuid: payload.id ? `codex-${payload.id}` : undefined, message: { ...(payload.role === "assistant" && model ? { model } : {}), content: [{ type: "text", text }] } };
84
90
  continue;
85
91
  }
86
92
  if (kind === "custom_tool_call" || kind === "function_call") {
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.8.6";
76
+ const CLI_VERSION = "0.8.7";
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");