worktrust 0.9.2 → 0.9.3
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 +1 -0
- package/package.json +1 -1
- package/preserve-lines.mjs +11 -1
- package/stretch-evidence.mjs +60 -4
- package/worktrust.mjs +1 -1
package/README.md
CHANGED
|
@@ -177,6 +177,7 @@ nothing it does not:
|
|
|
177
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
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) |
|
|
179
179
|
| `route` | the route the work took: branches made, pushes straight to the default branch, and of the stretch's own commits those over twenty files, a fix that followed another, those naming an issue, and the changed CI, script and docs files; counts only, never a subject, a branch name or a path (0.9.2) |
|
|
180
|
+
| `adaptation` | evidence and adaptation: what the stretch read by kind (docs, tests, logs, config, source, the web), a plan written again after a failure, a model changed right after a failure, two or more agents whose work a check met, and outages (overloaded, rate-limited, timed out) and how many the work went on past; counts only, never a path or a message (0.9.3) |
|
|
180
181
|
| `collector_version` | the CLI version that measured it |
|
|
181
182
|
| `seq`, `prev`, `hash` | the line's place, the hash of the line before it, and its own hash |
|
|
182
183
|
|
package/package.json
CHANGED
package/preserve-lines.mjs
CHANGED
|
@@ -127,6 +127,13 @@ export function archiveLine(entry, behaviour = null, { ids = {}, collector, salt
|
|
|
127
127
|
const route = Object.fromEntries(ROUTE_KEYS.filter((key) => whole(entry.route[key])).map((key) => [key, entry.route[key]]));
|
|
128
128
|
if (Object.keys(route).length > 0) line.route = route;
|
|
129
129
|
}
|
|
130
|
+
// 0.9.3: evidence read and adaptation; whole counts, and reads by kind.
|
|
131
|
+
if (entry.adaptation && typeof entry.adaptation === "object") {
|
|
132
|
+
const adaptation = Object.fromEntries(ADAPTATION_KEYS.filter((key) => whole(entry.adaptation[key])).map((key) => [key, entry.adaptation[key]]));
|
|
133
|
+
const sources = entry.adaptation.sources && typeof entry.adaptation.sources === "object" ? Object.fromEntries(READ_KINDS.filter((kind) => whole(entry.adaptation.sources[kind]) && entry.adaptation.sources[kind] > 0).map((kind) => [kind, entry.adaptation.sources[kind]])) : {};
|
|
134
|
+
if (Object.keys(sources).length > 0) adaptation.sources = sources;
|
|
135
|
+
if (Object.keys(adaptation).length > 0) line.adaptation = adaptation;
|
|
136
|
+
}
|
|
130
137
|
const risk = pick(entry.risk, ["proposed", "refused", "run"]);
|
|
131
138
|
if (risk && risk.proposed > 0 && risk.refused + risk.run <= risk.proposed) line.risk = risk;
|
|
132
139
|
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; };
|
|
@@ -186,12 +193,15 @@ export function archiveEntries(dir, ownKey) {
|
|
|
186
193
|
/** The furthest step a stretch reached on the computer (0.8.9). */
|
|
187
194
|
const STAGES = ["attempted", "verified", "committed", "pushed", "pr", "deployed"];
|
|
188
195
|
/** How fast a stretch moved (0.9.0). */
|
|
196
|
+
/** Evidence read and adaptation (0.9.3). */
|
|
197
|
+
const ADAPTATION_KEYS = ["replans", "escalations", "reconciled", "outages", "outages_continued"];
|
|
198
|
+
const READ_KINDS = ["docs", "tests", "logs", "config", "source", "web"];
|
|
189
199
|
/** The route the work took (0.9.2). */
|
|
190
200
|
const ROUTE_KEYS = ["branches", "pushes_to_main", "commits_large", "fix_followups", "issue_refs", "ci_files", "script_files", "doc_files"];
|
|
191
201
|
/** Risk and hygiene (0.9.1). */
|
|
192
202
|
const HYGIENE_KEYS = ["rollbacks", "privileged", "bypasses", "secrets", "destructive", "destructive_checked", "guard_retried", "guard_changed", "guard_stopped"];
|
|
193
203
|
const TIMING_KEYS = ["first_action_s", "first_check_s", "detect_actions", "detect_s", "recovery_calls", "resume_actions"];
|
|
194
|
-
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", "route", "interrupts", "steers", "utc_offset"];
|
|
204
|
+
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", "route", "adaptation", "interrupts", "steers", "utc_offset"];
|
|
195
205
|
export function supplementFor(line, earlier) {
|
|
196
206
|
const missing = DERIVED_KEYS.filter((key) => line[key] !== undefined && !earlier.some((old) => old[key] !== undefined));
|
|
197
207
|
if (missing.length === 0) return null;
|
package/stretch-evidence.mjs
CHANGED
|
@@ -62,6 +62,23 @@ export const marksOf = (block) => {
|
|
|
62
62
|
return marks;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* WHAT A READ WAS (0.9.3), by kind: docs, tests, logs, config, source, or the web. The path is read here and never kept.
|
|
67
|
+
*/
|
|
68
|
+
const READ_KINDS = [
|
|
69
|
+
["docs", /(^|[\\/])docs?[\\/]|(^|[\\/])README|\.(md|mdx|rst|txt)$/i],
|
|
70
|
+
["tests", /(^|[\\/])(__tests__|tests?|spec|e2e)[\\/]|\.(test|spec)\.[cm]?[jt]sx?$|_test\.(go|py|rb)$/],
|
|
71
|
+
["logs", /\.log$|(^|[\\/])logs?[\\/]/i],
|
|
72
|
+
["config", /\.(json|ya?ml|toml|ini|env\.example)$|(^|[\\/])\.[\w-]+rc$|config/i],
|
|
73
|
+
];
|
|
74
|
+
export const readKindOf = (block) => {
|
|
75
|
+
const name = String(block?.name ?? "");
|
|
76
|
+
if (/^(WebFetch|WebSearch|web_fetch|web_search)$/.test(name)) return "web";
|
|
77
|
+
const path = READ_TOOLS.has(name) ? block.input?.file_path ?? block.input?.path ?? null : null;
|
|
78
|
+
if (typeof path !== "string") return null;
|
|
79
|
+
return READ_KINDS.find(([, pattern]) => pattern.test(path))?.[0] ?? "source";
|
|
80
|
+
};
|
|
81
|
+
|
|
65
82
|
/**
|
|
66
83
|
* 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
|
|
67
84
|
* refused it when it was refused: the PERSON (Claude Code's fixed sentence when they decline a tool use or a plan) or a
|
|
@@ -69,18 +86,21 @@ export const marksOf = (block) => {
|
|
|
69
86
|
*/
|
|
70
87
|
const PERSON_REFUSED = /^\s*(The user doesn't want to (proceed|take this action)|User rejected|The user rejected|The user declined)/i;
|
|
71
88
|
const GUARD_REFUSED = /^\s*Permission for this (command|action) was denied by/i;
|
|
89
|
+
const OUTAGE = /\b(overloaded|rate[ -]?limit(ed)?|too many requests|429|503|service unavailable|timed? ?out|ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND)\b/i;
|
|
72
90
|
export const resultOf = (block) => {
|
|
73
91
|
const text = typeof block.content === "string" ? block.content : Array.isArray(block.content) ? block.content.map((part) => (part && typeof part.text === "string" ? part.text : "")).join("") : "";
|
|
74
92
|
const failed = block.is_error === true;
|
|
75
93
|
// 0.8.5: a reader that could not see the outcome (Codex's code mode, a background terminal) says so; unknown is never a pass.
|
|
76
94
|
if (!failed && block.outcome === "unknown") return { id: block.tool_use_id, failed: null, refusal: null };
|
|
77
|
-
|
|
95
|
+
// 0.9.3: an OUTAGE (the model or a tool overloaded, rate-limited, timed out, unreachable), read here and never kept.
|
|
96
|
+
const outage = failed && OUTAGE.test(text);
|
|
97
|
+
return { id: block.tool_use_id, failed, refusal: failed && PERSON_REFUSED.test(text) ? "person" : failed && GUARD_REFUSED.test(text) ? "guard" : null, ...(outage ? { outage: true } : {}) };
|
|
78
98
|
};
|
|
79
99
|
/** A to-do list the agent wrote (TodoWrite): how many items and how many done, never what they say. */
|
|
80
100
|
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);
|
|
81
101
|
|
|
82
102
|
/** 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). */
|
|
83
|
-
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 } : {}) }; };
|
|
103
|
+
export const callOf = (block) => { const kinds = callKindsOf(block), plan = planOf(block), marks = marksOf(block), read = readKindOf(block); return { id: block.id, kinds, ...(marks.length ? { marks } : {}), ...(read ? { read } : {}), family: `${String(block.name)}|${kinds.join("+")}`, digest: createHash("sha256").update(JSON.stringify(block.input ?? null)).digest("base64url").slice(0, 16), ...(plan ? { plan } : {}) }; };
|
|
84
104
|
|
|
85
105
|
/**
|
|
86
106
|
* VERIFICATION PER STRETCH (0.7.1; framework L7, L12): per kind of check, how many ran and how many failed; per step of
|
|
@@ -453,9 +473,45 @@ function routeOf(messages) {
|
|
|
453
473
|
return branches + pushesToMain > 0 ? { ...(branches ? { branches } : {}), ...(pushesToMain ? { pushes_to_main: pushesToMain } : {}) } : null;
|
|
454
474
|
}
|
|
455
475
|
|
|
476
|
+
/**
|
|
477
|
+
* EVIDENCE AND ADAPTATION (0.9.3): what the stretch read, by kind; a plan written again after a failure; a model change
|
|
478
|
+
* within three calls after a failure (escalation); two or more agents whose work a check met before the next delivery
|
|
479
|
+
* (reconciliation, a proxy); and outages (the model or a tool overloaded, rate-limited, timed out) and how many the work
|
|
480
|
+
* went on past (a later call succeeded). Counts only.
|
|
481
|
+
*/
|
|
482
|
+
function adaptationOf(messages) {
|
|
483
|
+
const results = new Map();
|
|
484
|
+
for (const message of messages) for (const result of message.results ?? []) results.set(result.id, result);
|
|
485
|
+
const sources = {}, out = { replans: 0, escalations: 0, reconciled: 0, outages: 0, outages_continued: 0 };
|
|
486
|
+
let failedSince = false, lastFailureCall = null, index = 0, model = null, agentsOpen = 0, outageOpen = false;
|
|
487
|
+
for (const message of messages) {
|
|
488
|
+
if (message.bridge) continue;
|
|
489
|
+
if (message.type === "assistant" && message.model) {
|
|
490
|
+
// Once per failure: the change that answered it, not every switch after it.
|
|
491
|
+
if (model && message.model !== model && lastFailureCall !== null && index - lastFailureCall <= 3) { out.escalations += 1; lastFailureCall = null; }
|
|
492
|
+
model = message.model;
|
|
493
|
+
}
|
|
494
|
+
for (const call of message.calls ?? []) {
|
|
495
|
+
index += 1;
|
|
496
|
+
const tool = call.family.split("|")[0], result = results.get(call.id);
|
|
497
|
+
if (call.read) sources[call.read] = (sources[call.read] ?? 0) + 1;
|
|
498
|
+
if (call.plan && failedSince) { out.replans += 1; failedSince = false; }
|
|
499
|
+
if (tool === "Agent" || tool === "Task") agentsOpen += 1;
|
|
500
|
+
if (call.kinds.some((kind) => CHECK_KINDS.includes(kind)) && agentsOpen >= 2) { out.reconciled += 1; agentsOpen = 0; }
|
|
501
|
+
if (call.kinds.some((kind) => DELIVERY_KINDS.includes(kind))) agentsOpen = 0;
|
|
502
|
+
if (result?.outage) { out.outages += 1; outageOpen = true; }
|
|
503
|
+
else if (outageOpen && result?.failed === false) { out.outages_continued += 1; outageOpen = false; }
|
|
504
|
+
if (result?.failed === true) { failedSince = true; lastFailureCall = index; }
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const kept = Object.fromEntries(Object.entries(out).filter(([, value]) => value > 0));
|
|
508
|
+
if (Object.keys(sources).length > 0) kept.sources = sources;
|
|
509
|
+
return Object.keys(kept).length > 0 ? kept : null;
|
|
510
|
+
}
|
|
511
|
+
|
|
456
512
|
/** The stretch's whole derived record; `helpers` are the hook's own readers of a human turn, so both read it the same way. */
|
|
457
513
|
export function deriveStretch(messages, helpers) {
|
|
458
514
|
const context = contextOf(messages, helpers), routing = routingOf(messages), steering = steeringOf(messages, helpers);
|
|
459
|
-
const timing = timingOf(messages, helpers), hygiene = hygieneOf(messages), route = routeOf(messages), tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages), practice = practiceOf(messages, helpers);
|
|
460
|
-
return { ...(practice ?? {}), ...(oversight ? { oversight } : {}), ...(planning ? { planning } : {}), ...(autonomy ? { autonomy } : {}), ...verificationOf(messages, helpers), ...(context ? { context } : {}), ...(routing ? { routing } : {}), ...(steering ? { steering } : {}), ...(tools ? { tools } : {}), ...(timing ? { timing } : {}), ...(hygiene ? { hygiene } : {}), ...(route ? { route } : {}) };
|
|
515
|
+
const timing = timingOf(messages, helpers), hygiene = hygieneOf(messages), route = routeOf(messages), adaptation = adaptationOf(messages), tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages), practice = practiceOf(messages, helpers);
|
|
516
|
+
return { ...(practice ?? {}), ...(oversight ? { oversight } : {}), ...(planning ? { planning } : {}), ...(autonomy ? { autonomy } : {}), ...verificationOf(messages, helpers), ...(context ? { context } : {}), ...(routing ? { routing } : {}), ...(steering ? { steering } : {}), ...(tools ? { tools } : {}), ...(timing ? { timing } : {}), ...(hygiene ? { hygiene } : {}), ...(route ? { route } : {}), ...(adaptation ? { adaptation } : {}) };
|
|
461
517
|
}
|
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.9.
|
|
76
|
+
const CLI_VERSION = "0.9.3";
|
|
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");
|