worktrust 0.9.9 → 0.10.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 +2 -0
- package/package.json +1 -1
- package/preserve-lines.mjs +15 -1
- package/stretch-evidence.mjs +78 -2
- package/worktrust.mjs +1 -1
package/README.md
CHANGED
|
@@ -186,6 +186,8 @@ nothing it does not:
|
|
|
186
186
|
| `hygiene.secrets` | counts a secret shown only when a reader (cat, head, tail, base64, cp) takes the file as its own argument; a command that uses a .env and reads its output, and a template (.env.example), are no secret shown (0.9.6) |
|
|
187
187
|
| `outcomes` | outcomes of the steps: per kind of check whether its first run passed, delivery attempts that failed, a model change and a new plan after a failure each followed by a passing check; and a check whose output goes through a pipe is read from its output's words (an error fails, a pass passes, a silent type check or lint passes, anything else is unconfirmed), never from the pipe's exit code (0.9.8) |
|
|
188
188
|
| `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) |
|
|
189
|
+
| `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) |
|
|
190
|
+
| `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) |
|
|
189
191
|
| `collector_version` | the CLI version that measured it |
|
|
190
192
|
| `seq`, `prev`, `hash` | the line's place, the hash of the line before it, and its own hash |
|
|
191
193
|
|
package/package.json
CHANGED
package/preserve-lines.mjs
CHANGED
|
@@ -152,6 +152,16 @@ export function archiveLine(entry, behaviour = null, { ids = {}, collector, salt
|
|
|
152
152
|
const retrieval = Object.fromEntries(RETRIEVAL_KEYS.filter((key) => whole(entry.retrieval[key])).map((key) => [key, entry.retrieval[key]]));
|
|
153
153
|
if (Object.keys(retrieval).length > 0) line.retrieval = retrieval;
|
|
154
154
|
}
|
|
155
|
+
// 0.10.0: the context window; whole counts only.
|
|
156
|
+
if (entry.window && typeof entry.window === "object") {
|
|
157
|
+
const span = Object.fromEntries(WINDOW_KEYS.filter((key) => Number.isInteger(entry.window[key]) && entry.window[key] >= 0).map((key) => [key, entry.window[key]]));
|
|
158
|
+
if (Object.keys(span).length > 0) line.window = span;
|
|
159
|
+
}
|
|
160
|
+
// 0.10.1: reviewing the agent; whole counts only.
|
|
161
|
+
if (entry.review && typeof entry.review === "object") {
|
|
162
|
+
const review = Object.fromEntries(REVIEW_KEYS.filter((key) => Number.isInteger(entry.review[key]) && entry.review[key] >= 0 && entry.review[key] <= 100_000).map((key) => [key, entry.review[key]]));
|
|
163
|
+
if (Object.keys(review).length > 0) line.review = review;
|
|
164
|
+
}
|
|
155
165
|
const risk = pick(entry.risk, ["proposed", "refused", "run"]);
|
|
156
166
|
if (risk && risk.proposed > 0 && risk.refused + risk.run <= risk.proposed) line.risk = risk;
|
|
157
167
|
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; };
|
|
@@ -211,6 +221,10 @@ export function archiveEntries(dir, ownKey) {
|
|
|
211
221
|
/** The furthest step a stretch reached on the computer (0.8.9). */
|
|
212
222
|
const STAGES = ["attempted", "verified", "committed", "pushed", "pr", "deployed"];
|
|
213
223
|
/** How fast a stretch moved (0.9.0). */
|
|
224
|
+
/** The context window (0.10.0); the peak may pass the whole-count bound of 100,000. */
|
|
225
|
+
const WINDOW_KEYS = ["peak", "over_100k", "over_200k", "over_500k", "growth", "compact_near_peak"];
|
|
226
|
+
/** Reviewing the agent (0.10.1): counts, and the middle interval between reviews in seconds. */
|
|
227
|
+
const REVIEW_KEYS = ["reviews", "agent_runs", "agent_runs_reviewed", "changed_course", "changed_code", "checked", "interval_median_s"];
|
|
214
228
|
/** Retrieval and grounding (0.9.9). */
|
|
215
229
|
const RETRIEVAL_KEYS = ["searches", "repeated", "found", "again", "before_change", "after_failure", "deliveries", "grounded"];
|
|
216
230
|
/** Outcomes of the steps (0.9.8). */
|
|
@@ -226,7 +240,7 @@ const ROUTE_KEYS = ["branches", "pushes_to_main", "commits_large", "fix_followup
|
|
|
226
240
|
/** Risk and hygiene (0.9.1). */
|
|
227
241
|
const HYGIENE_KEYS = ["rollbacks", "privileged", "bypasses", "secrets", "destructive", "destructive_checked", "guard_retried", "guard_changed", "guard_stopped"];
|
|
228
242
|
const TIMING_KEYS = ["first_action_s", "first_check_s", "detect_actions", "detect_s", "recovery_calls", "resume_actions"];
|
|
229
|
-
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", "reach", "outcomes", "retrieval", "interrupts", "steers", "utc_offset"];
|
|
243
|
+
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", "reach", "outcomes", "retrieval", "window", "review", "interrupts", "steers", "utc_offset"];
|
|
230
244
|
export function supplementFor(line, earlier) {
|
|
231
245
|
const missing = DERIVED_KEYS.filter((key) => line[key] !== undefined && !earlier.some((old) => old[key] !== undefined));
|
|
232
246
|
if (missing.length === 0) return null;
|
package/stretch-evidence.mjs
CHANGED
|
@@ -652,6 +652,82 @@ function retrievalOf(messages) {
|
|
|
652
652
|
return out.searches > 0 || out.deliveries > 0 ? Object.fromEntries(Object.entries(out).filter(([, value]) => value > 0)) : null;
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
+
/**
|
|
656
|
+
* THE CONTEXT WINDOW (0.10.0), from the token counts the AI app writes beside each answer (input plus cached, read
|
|
657
|
+
* once per message): the peak a turn carried, the turns over 100k, 200k and 500k, the growth from the stretch's first
|
|
658
|
+
* quarter of answers to its last (their middles, as a percentage), and compactions that came at 80% of the peak or more
|
|
659
|
+
* (the window managed before it ran out). Counts; nothing of what the context held.
|
|
660
|
+
*/
|
|
661
|
+
function windowOf(messages) {
|
|
662
|
+
const seen = new Set(), sizes = [];
|
|
663
|
+
let compactNearPeak = 0, last = 0;
|
|
664
|
+
const marks = [];
|
|
665
|
+
for (const message of messages) {
|
|
666
|
+
if (message.bridge) continue;
|
|
667
|
+
if (message.compacted) marks.push(last);
|
|
668
|
+
if (message.type !== "assistant" || !message.usage) continue;
|
|
669
|
+
if (message.messageId) { if (seen.has(message.messageId)) continue; seen.add(message.messageId); }
|
|
670
|
+
const u = message.usage, size = (u.input_tokens ?? 0) + (u.cache_read_input_tokens ?? 0) + (u.cache_creation_input_tokens ?? 0);
|
|
671
|
+
if (size > 0) { sizes.push(size); last = size; }
|
|
672
|
+
}
|
|
673
|
+
if (sizes.length === 0) return null;
|
|
674
|
+
const peak = Math.max(...sizes);
|
|
675
|
+
for (const before of marks) if (before >= 0.8 * peak) compactNearPeak += 1;
|
|
676
|
+
const middle = (values) => { const sorted = [...values].sort((a, b) => a - b); return sorted[Math.floor(sorted.length / 2)]; };
|
|
677
|
+
const quarter = Math.floor(sizes.length / 4);
|
|
678
|
+
const growth = quarter >= 2 ? Math.round((100 * middle(sizes.slice(-quarter))) / Math.max(1, middle(sizes.slice(0, quarter)))) : null;
|
|
679
|
+
const out = { peak, over_100k: sizes.filter((size) => size > 100_000).length, over_200k: sizes.filter((size) => size > 200_000).length, over_500k: sizes.filter((size) => size > 500_000).length, ...(growth !== null ? { growth } : {}), ...(compactNearPeak ? { compact_near_peak: compactNearPeak } : {}) };
|
|
680
|
+
return Object.fromEntries(Object.entries(out).filter(([key, value]) => key === "peak" || value > 0));
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* REVIEWING THE AGENT (0.10.1; Agent Oversight & Steering): a REVIEW is the person's turn while the agent was working (a
|
|
685
|
+
* tool call since their last turn). Counted: reviews, the middle of the time between them, subagent runs and how many the
|
|
686
|
+
* person reviewed before the next change or delivery, and what a review led to within three calls: the agent changing
|
|
687
|
+
* course (another model, a plan left, a to-do list that grew or shrank; another tool alone says nothing), a change (something found), a check. What was said is never read.
|
|
688
|
+
*/
|
|
689
|
+
function reviewOf(messages, { isHumanTurn }) {
|
|
690
|
+
const out = { reviews: 0, agent_runs: 0, agent_runs_reviewed: 0, changed_course: 0, changed_code: 0, checked: 0 };
|
|
691
|
+
const times = [];
|
|
692
|
+
let workedSinceTurn = false, lastModel = null, lastItems = null, after = null, agentPending = 0;
|
|
693
|
+
for (const message of messages) {
|
|
694
|
+
if (message.bridge) continue;
|
|
695
|
+
if (message.type === "user" && !message.meta && message.kind !== "tool_result" && isHumanTurn(message.content)) {
|
|
696
|
+
if (workedSinceTurn) {
|
|
697
|
+
out.reviews += 1;
|
|
698
|
+
if (Number.isFinite(message.at)) times.push(message.at);
|
|
699
|
+
out.agent_runs_reviewed += agentPending;
|
|
700
|
+
after = { left: 3, changed: false, coded: false, checked: false };
|
|
701
|
+
}
|
|
702
|
+
agentPending = 0; workedSinceTurn = false;
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (message.type === "assistant" && message.model && after && after.left > 0 && lastModel && message.model !== lastModel && !after.changed) { after.changed = true; out.changed_course += 1; }
|
|
706
|
+
if (message.type === "assistant" && message.model) lastModel = message.model;
|
|
707
|
+
for (const call of message.calls ?? []) {
|
|
708
|
+
const tool = call.family.split("|")[0];
|
|
709
|
+
workedSinceTurn = true;
|
|
710
|
+
if (tool === "Agent" || tool === "Task") { out.agent_runs += 1; agentPending += 1; }
|
|
711
|
+
if (EDIT_TOOLS.has(tool) || call.kinds.some((kind) => DELIVERY_KINDS.includes(kind))) agentPending = 0;
|
|
712
|
+
if (after && after.left > 0) {
|
|
713
|
+
// Another model, a plan left, or a to-do list that grew or shrank: not merely another tool (after almost every turn the
|
|
714
|
+
// next tool differs, 84% on the owner's history) and not a ticked item.
|
|
715
|
+
const replanned = tool === "ExitPlanMode" || (call.plan && lastItems !== null && call.plan.items !== lastItems);
|
|
716
|
+
if (!after.changed && replanned) { after.changed = true; out.changed_course += 1; }
|
|
717
|
+
if (!after.coded && EDIT_TOOLS.has(tool)) { after.coded = true; out.changed_code += 1; }
|
|
718
|
+
if (!after.checked && call.kinds.some((kind) => CHECK_KINDS.includes(kind))) { after.checked = true; out.checked += 1; }
|
|
719
|
+
after.left -= 1;
|
|
720
|
+
}
|
|
721
|
+
if (call.plan) lastItems = call.plan.items;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (out.reviews === 0 && out.agent_runs === 0) return null;
|
|
725
|
+
const gaps = times.slice(1).map((time, index) => Math.round((time - times[index]) / 1000)).filter((gap) => gap >= 0).sort((a, b) => a - b);
|
|
726
|
+
const kept = Object.fromEntries(Object.entries(out).filter(([, value]) => value > 0));
|
|
727
|
+
if (gaps.length >= 2) kept.interval_median_s = gaps[Math.floor(gaps.length / 2)];
|
|
728
|
+
return kept;
|
|
729
|
+
}
|
|
730
|
+
|
|
655
731
|
/** The stretch's whole derived record; `helpers` are the hook's own readers of a human turn, so both read it the same way. */
|
|
656
732
|
/** A piped check's outcome from its output's words: failed or passed when they say so, unknown (null) when they do not. */
|
|
657
733
|
function settlePiped(messages) {
|
|
@@ -667,6 +743,6 @@ function settlePiped(messages) {
|
|
|
667
743
|
export function deriveStretch(raw, helpers) {
|
|
668
744
|
const messages = settlePiped(raw);
|
|
669
745
|
const context = contextOf(messages, helpers), routing = routingOf(messages), steering = steeringOf(messages, helpers);
|
|
670
|
-
const timing = timingOf(messages, helpers), hygiene = hygieneOf(messages), route = routeOf(messages), adaptation = adaptationOf(messages), reach = reachOf(messages), outcomes = outcomesOf(messages), retrieval = retrievalOf(messages), tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages), practice = practiceOf(messages, helpers);
|
|
671
|
-
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 } : {}), ...(reach ? { reach } : {}), ...(outcomes ? { outcomes } : {}), ...(retrieval ? { retrieval } : {}) };
|
|
746
|
+
const timing = timingOf(messages, helpers), hygiene = hygieneOf(messages), route = routeOf(messages), adaptation = adaptationOf(messages), reach = reachOf(messages), outcomes = outcomesOf(messages), retrieval = retrievalOf(messages), window = windowOf(messages), review = reviewOf(messages, helpers), tools = toolsOf(messages), oversight = oversightOf(messages), planning = planningOf(messages), autonomy = autonomyOf(messages), practice = practiceOf(messages, helpers);
|
|
747
|
+
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 } : {}), ...(reach ? { reach } : {}), ...(outcomes ? { outcomes } : {}), ...(retrieval ? { retrieval } : {}), ...(window ? { window } : {}), ...(review ? { review } : {}) };
|
|
672
748
|
}
|
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.
|
|
76
|
+
const CLI_VERSION = "0.10.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");
|