worktrust 0.8.9 → 0.9.1

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
@@ -174,6 +174,8 @@ nothing it does not:
174
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) |
175
175
  | `framing`, `quality`, `risk`, `tool_mix`, `reads`, `context_files` | how the work was framed (your turns before the agent's first action, a plan first or not), checked (a check passing after the last change, the failures before a check passed, the change looked at before delivery; security scans count as checks), risked (destructive commands proposed, refused, run), which kinds of tools were used, files read again unchanged, and which of the AI app's own context files (instructions, skills, agents, commands, settings, MCP) the commits changed; kinds and counts only (0.8.8) |
176
176
  | `quality.change_blocks`, `checked_blocks`, `rework_cycles`, `stage` | how many change blocks (edits with no check between them) a check followed, how often a failed check was followed by another change before it ran again (rework), and the furthest step the stretch reached here: attempted, verified, committed, pushed, pr, deployed; counts and one word only (0.8.9) |
177
+ | `timing` | how fast the stretch moved: seconds from your first turn to the first action and from the first change to the first check, the actions and seconds from a failure to the change that answered it, the calls from a failed check to it passing, and the calls back to work after a compaction; medians from the order and the clocks, never what was said (0.9.0) |
178
+ | `hygiene` | risk and hygiene: rollbacks, privileged commands (sudo, a forced push), hooks skipped (--no-verify), secrets touched (a .env printed, a private key read), destructive commands and how many a look or a check came before, the answer to a guard (retried, changed, stopped), and whether a check followed delivery; counts only, never the command or the path (0.9.1) |
177
179
  | `collector_version` | the CLI version that measured it |
178
180
  | `seq`, `prev`, `hash` | the line's place, the hash of the line before it, and its own hash |
179
181
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.8.9",
3
+ "version": "0.9.1",
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": {
@@ -111,6 +111,17 @@ export function archiveLine(entry, behaviour = null, { ids = {}, collector, salt
111
111
  if (whole(entry.quality.change_blocks) && whole(entry.quality.checked_blocks) && whole(entry.quality.rework_cycles) && entry.quality.checked_blocks <= entry.quality.change_blocks) Object.assign(line.quality, { change_blocks: entry.quality.change_blocks, checked_blocks: entry.quality.checked_blocks, rework_cycles: entry.quality.rework_cycles });
112
112
  }
113
113
  if (STAGES.includes(entry.stage)) line.stage = entry.stage;
114
+ // 0.9.0: how fast the stretch moved; whole seconds and counts, each key optional.
115
+ if (entry.timing && typeof entry.timing === "object") {
116
+ const timing = Object.fromEntries(TIMING_KEYS.filter((key) => whole(entry.timing[key])).map((key) => [key, entry.timing[key]]));
117
+ if (Object.keys(timing).length > 0) line.timing = timing;
118
+ }
119
+ // 0.9.1: risk and hygiene; whole counts, and whether a check followed delivery.
120
+ if (entry.hygiene && typeof entry.hygiene === "object") {
121
+ const hygiene = Object.fromEntries(HYGIENE_KEYS.filter((key) => whole(entry.hygiene[key])).map((key) => [key, entry.hygiene[key]]));
122
+ if (typeof entry.hygiene.checked_after_delivery === "boolean") hygiene.checked_after_delivery = entry.hygiene.checked_after_delivery;
123
+ if (Object.keys(hygiene).length > 0) line.hygiene = hygiene;
124
+ }
114
125
  const risk = pick(entry.risk, ["proposed", "refused", "run"]);
115
126
  if (risk && risk.proposed > 0 && risk.refused + risk.run <= risk.proposed) line.risk = risk;
116
127
  const keyed = (record, keys) => { const kept = Object.entries(record && typeof record === "object" ? record : {}).filter(([key, n]) => keys.includes(key) && whole(n) && n > 0).sort(); return kept.length ? Object.fromEntries(kept) : null; };
@@ -169,7 +180,11 @@ export function archiveEntries(dir, ownKey) {
169
180
  */
170
181
  /** The furthest step a stretch reached on the computer (0.8.9). */
171
182
  const STAGES = ["attempted", "verified", "committed", "pushed", "pr", "deployed"];
172
- export const DERIVED_KEYS = ["signals", "analyzer_version", "verification", "unconfirmed", "delivery", "recovery", "delegation", "context", "routing", "steering", "tools", "complexity", "oversight", "planning", "changes", "autonomy", "authorship", "framing", "quality", "risk", "tool_mix", "reads", "context_files", "stage", "interrupts", "steers", "utc_offset"];
183
+ /** How fast a stretch moved (0.9.0). */
184
+ /** Risk and hygiene (0.9.1). */
185
+ const HYGIENE_KEYS = ["rollbacks", "privileged", "bypasses", "secrets", "destructive", "destructive_checked", "guard_retried", "guard_changed", "guard_stopped"];
186
+ const TIMING_KEYS = ["first_action_s", "first_check_s", "detect_actions", "detect_s", "recovery_calls", "resume_actions"];
187
+ export const DERIVED_KEYS = ["signals", "analyzer_version", "verification", "unconfirmed", "delivery", "recovery", "delegation", "context", "routing", "steering", "tools", "complexity", "oversight", "planning", "changes", "autonomy", "authorship", "framing", "quality", "risk", "tool_mix", "reads", "context_files", "stage", "timing", "hygiene", "interrupts", "steers", "utc_offset"];
173
188
  export function supplementFor(line, earlier) {
174
189
  const missing = DERIVED_KEYS.filter((key) => line[key] !== undefined && !earlier.some((old) => old[key] !== undefined));
175
190
  if (missing.length === 0) return null;
@@ -36,6 +36,29 @@ export const callKindsOf = (block) => {
36
36
  const command = block && SHELL_TOOLS.has(String(block.name)) ? block.input?.command ?? block.input?.CommandLine ?? block.input?.cmd : null;
37
37
  return typeof command === "string" ? CALL_KINDS.filter(([, pattern]) => pattern.test(command)).map(([kind]) => kind) : [];
38
38
  };
39
+ /**
40
+ * RISK AND HYGIENE MARKS (0.9.1), beside the kinds and outside a call's family so no earlier measure moves: a ROLLBACK
41
+ * (git revert or restore, a hard reset, a deploy rolled back), a PRIVILEGED command (sudo, a forced push, a world-
42
+ * writable chmod), a BYPASS (hooks skipped with --no-verify), and a SECRET touched (a .env, a private key, a credentials
43
+ * or token file read or printed). The path and the command are read here and never kept; only the mark travels.
44
+ */
45
+ const MARKS = [
46
+ ["rollback", /\bgit\s+(revert|restore)\b|\bgit\s+reset\s+--hard\b|\b(vercel|fly|netlify)\s+rollback\b|\bkubectl\s+rollout\s+undo\b/],
47
+ ["privilege", /(^|[\s;&|])sudo\s|\bgit\s+push\b[^\n]*\s(-f|--force(-with-lease)?)\b|\bchmod\s+(-R\s+)?777\b/],
48
+ ["bypass", /\s--no-verify\b/],
49
+ ];
50
+ const SECRET_FILE = /(^|[\/\s'"])(\.env(\.[\w-]+)?|id_(rsa|ed25519|ecdsa)|[\w.-]+\.(pem|p12|pfx|key)|credentials(\.json)?|\.npmrc|\.netrc|\.pgpass)(['"\s]|$)/;
51
+ const PRINTS = /\b(cat|less|more|head|tail|bat|type|Get-Content|grep|sed|awk|cp|scp|base64)\b/;
52
+ const READ_TOOLS = new Set(["Read", "read_file", "view", "open_file"]);
53
+ export const marksOf = (block) => {
54
+ const name = String(block?.name ?? "");
55
+ const command = SHELL_TOOLS.has(name) ? block.input?.command ?? block.input?.CommandLine ?? block.input?.cmd : null;
56
+ const path = READ_TOOLS.has(name) ? block.input?.file_path ?? block.input?.path ?? null : null;
57
+ const marks = typeof command === "string" ? MARKS.filter(([, pattern]) => pattern.test(command)).map(([mark]) => mark) : [];
58
+ if ((typeof path === "string" && SECRET_FILE.test(path)) || (typeof command === "string" && PRINTS.test(command) && SECRET_FILE.test(command))) marks.push("secret");
59
+ return marks;
60
+ };
61
+
39
62
  /**
40
63
  * A TOOL RESULT AS THE STRETCH READS IT (0.8.1): its call's id, whether it failed, and, read here and never kept, WHO
41
64
  * refused it when it was refused: the PERSON (Claude Code's fixed sentence when they decline a tool use or a plan) or a
@@ -54,7 +77,7 @@ export const resultOf = (block) => {
54
77
  const planOf = (block) => (block.name === "TodoWrite" && Array.isArray(block.input?.todos) ? { items: block.input.todos.length, done: block.input.todos.filter((todo) => todo && todo.status === "completed").length } : null);
55
78
 
56
79
  /** One tool call as the stretch reads it: its id, its kinds, its FAMILY (the tool and its check kinds) and a digest of its input (compared, never kept). */
57
- export const callOf = (block) => { const kinds = callKindsOf(block), plan = planOf(block); return { id: block.id, kinds, family: `${String(block.name)}|${kinds.join("+")}`, digest: createHash("sha256").update(JSON.stringify(block.input ?? null)).digest("base64url").slice(0, 16), ...(plan ? { plan } : {}) }; };
80
+ export const callOf = (block) => { const kinds = callKindsOf(block), plan = planOf(block), marks = marksOf(block); return { id: block.id, kinds, ...(marks.length ? { marks } : {}), family: `${String(block.name)}|${kinds.join("+")}`, digest: createHash("sha256").update(JSON.stringify(block.input ?? null)).digest("base64url").slice(0, 16), ...(plan ? { plan } : {}) }; };
58
81
 
59
82
  /**
60
83
  * VERIFICATION PER STRETCH (0.7.1; framework L7, L12): per kind of check, how many ran and how many failed; per step of
@@ -334,9 +357,89 @@ function practiceOf(messages, { isHumanTurn }) {
334
357
  };
335
358
  }
336
359
 
360
+ /**
361
+ * HOW FAST A STRETCH MOVED (0.9.0): seconds from the person's first turn to the agent's first action (an edit, a write or
362
+ * a shell command) and from the first change to the first check; per failure, the actions and seconds until the next
363
+ * change that answered it (detection), and the calls from a failed check to that check passing (recovery depth); after
364
+ * a resume, a clear or a compaction, the calls until the next change or check (back to work). Medians, from the order
365
+ * and the clocks alone; nothing of what was said or run.
366
+ */
367
+ const median = (values) => { if (values.length === 0) return null; const sorted = [...values].sort((a, b) => a - b); const middle = Math.floor(sorted.length / 2); return Math.round(sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2); };
368
+ function timingOf(messages, { isHumanTurn, textOf }) {
369
+ let firstTurn = null, firstAction = null, firstChange = null, firstCheck = null, index = 0, resumedAt = null;
370
+ const kindsById = new Map(), open = [], openChecks = new Map(), detect = [], detectSeconds = [], depth = [], resume = [];
371
+ for (const message of messages) {
372
+ if (message.bridge || !Number.isFinite(message.at)) continue;
373
+ const text = message.type === "user" ? textOf(message.content) : "";
374
+ if (message.compacted || ["compact", "clear", "resume"].includes(COMMAND.exec(text)?.[1] ?? "")) resumedAt = index;
375
+ if (message.type === "user" && !message.meta && message.kind !== "tool_result" && isHumanTurn(message.content) && firstTurn === null) firstTurn = message.at;
376
+ for (const result of message.results ?? []) {
377
+ const kinds = kindsById.get(result.id) ?? [];
378
+ if (result.failed !== true) {
379
+ for (const kind of kinds.filter((item) => CHECK_KINDS.includes(item) && result.failed === false)) { const at = openChecks.get(kind); if (at !== undefined) { depth.push(index - at); openChecks.delete(kind); } }
380
+ continue;
381
+ }
382
+ open.push({ index, at: message.at });
383
+ for (const kind of kinds.filter((item) => CHECK_KINDS.includes(item))) if (!openChecks.has(kind)) openChecks.set(kind, index);
384
+ }
385
+ for (const call of message.calls ?? []) {
386
+ index += 1;
387
+ kindsById.set(call.id, call.kinds);
388
+ const tool = call.family.split("|")[0];
389
+ if (firstAction === null && ACTION_TOOLS.has(tool)) firstAction = message.at;
390
+ if (EDIT_TOOLS.has(tool)) {
391
+ if (firstChange === null) firstChange = message.at;
392
+ for (const failure of open.splice(0)) { detect.push(index - failure.index); detectSeconds.push(Math.max(0, (message.at - failure.at) / 1000)); }
393
+ }
394
+ if (firstChange !== null && firstCheck === null && call.kinds.some((kind) => CHECK_KINDS.includes(kind))) firstCheck = message.at;
395
+ if (resumedAt !== null && (EDIT_TOOLS.has(tool) || call.kinds.some((kind) => CHECK_KINDS.includes(kind)))) { resume.push(index - resumedAt); resumedAt = null; }
396
+ }
397
+ }
398
+ const out = {
399
+ first_action_s: firstTurn !== null && firstAction !== null && firstAction >= firstTurn ? Math.round((firstAction - firstTurn) / 1000) : null,
400
+ first_check_s: firstChange !== null && firstCheck !== null ? Math.round((firstCheck - firstChange) / 1000) : null,
401
+ detect_actions: median(detect), detect_s: median(detectSeconds), recovery_calls: median(depth), resume_actions: median(resume),
402
+ };
403
+ const kept = Object.fromEntries(Object.entries(out).filter(([, value]) => value !== null));
404
+ return Object.keys(kept).length > 0 ? kept : null;
405
+ }
406
+
407
+ /**
408
+ * RISK AND HYGIENE PER STRETCH (0.9.1): rollbacks, privileged commands, hooks skipped, secrets touched; destructive
409
+ * commands and how many a look (git diff, show, status) or a check came before since the last change; after a guard
410
+ * refused a call, whether the next call was the same one again (retried), another (changed), or none (stopped); and
411
+ * whether a check ran after the stretch's first delivery step (a push, a deploy). Counts only.
412
+ */
413
+ function hygieneOf(messages) {
414
+ const results = new Map();
415
+ for (const message of messages) for (const result of message.results ?? []) results.set(result.id, result);
416
+ const out = { rollbacks: 0, privileged: 0, bypasses: 0, secrets: 0, destructive: 0, destructive_checked: 0, guard_retried: 0, guard_changed: 0, guard_stopped: 0 };
417
+ let lookedSinceChange = false, delivered = false, checkedAfterDelivery = false, refusedDigest = null;
418
+ for (const message of messages) {
419
+ if (message.bridge) continue;
420
+ for (const call of message.calls ?? []) {
421
+ const tool = call.family.split("|")[0], result = results.get(call.id), marks = call.marks ?? [];
422
+ if (refusedDigest !== null) { if (call.digest === refusedDigest) out.guard_retried += 1; else out.guard_changed += 1; refusedDigest = null; }
423
+ if (marks.includes("rollback")) out.rollbacks += 1;
424
+ if (marks.includes("privilege")) out.privileged += 1;
425
+ if (marks.includes("bypass")) out.bypasses += 1;
426
+ if (marks.includes("secret")) out.secrets += 1;
427
+ if (call.kinds.includes("destructive")) { out.destructive += 1; if (lookedSinceChange) out.destructive_checked += 1; }
428
+ if (EDIT_TOOLS.has(tool)) lookedSinceChange = false;
429
+ if (call.kinds.includes("inspect") || call.kinds.some((kind) => CHECK_KINDS.includes(kind))) { lookedSinceChange = true; if (delivered) checkedAfterDelivery = true; }
430
+ if ((call.kinds.includes("push") || call.kinds.includes("deploy")) && result?.failed === false) delivered = true;
431
+ if (result?.refusal === "guard") refusedDigest = call.digest;
432
+ }
433
+ }
434
+ if (refusedDigest !== null) out.guard_stopped += 1;
435
+ const kept = Object.fromEntries(Object.entries(out).filter(([, value]) => value > 0));
436
+ if (delivered) kept.checked_after_delivery = checkedAfterDelivery;
437
+ return Object.keys(kept).length > 0 ? kept : null;
438
+ }
439
+
337
440
  /** The stretch's whole derived record; `helpers` are the hook's own readers of a human turn, so both read it the same way. */
338
441
  export function deriveStretch(messages, helpers) {
339
442
  const context = contextOf(messages, helpers), routing = routingOf(messages), steering = steeringOf(messages, helpers);
340
- const tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages), practice = practiceOf(messages, helpers);
341
- return { ...(practice ?? {}), ...(oversight ? { oversight } : {}), ...(planning ? { planning } : {}), ...(autonomy ? { autonomy } : {}), ...verificationOf(messages, helpers), ...(context ? { context } : {}), ...(routing ? { routing } : {}), ...(steering ? { steering } : {}), ...(tools ? { tools } : {}) };
443
+ const timing = timingOf(messages, helpers), hygiene = hygieneOf(messages), tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages), practice = practiceOf(messages, helpers);
444
+ return { ...(practice ?? {}), ...(oversight ? { oversight } : {}), ...(planning ? { planning } : {}), ...(autonomy ? { autonomy } : {}), ...verificationOf(messages, helpers), ...(context ? { context } : {}), ...(routing ? { routing } : {}), ...(steering ? { steering } : {}), ...(tools ? { tools } : {}), ...(timing ? { timing } : {}), ...(hygiene ? { hygiene } : {}) };
342
445
  }
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.9";
76
+ const CLI_VERSION = "0.9.1";
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");