@chopin-ai/core 0.2.0 → 0.3.0
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/dist/evidence/classify.d.ts +31 -0
- package/dist/evidence/classify.js +87 -0
- package/dist/evidence/classify.js.map +1 -0
- package/dist/evidence/corrections.d.ts +14 -0
- package/dist/evidence/corrections.js +61 -0
- package/dist/evidence/corrections.js.map +1 -0
- package/dist/evidence/failures.d.ts +44 -0
- package/dist/evidence/failures.js +91 -0
- package/dist/evidence/failures.js.map +1 -0
- package/dist/evidence/messages-jsonl.d.ts +7 -0
- package/dist/evidence/messages-jsonl.js +97 -0
- package/dist/evidence/messages-jsonl.js.map +1 -0
- package/dist/evidence/points.d.ts +26 -0
- package/dist/evidence/points.js +72 -0
- package/dist/evidence/points.js.map +1 -0
- package/dist/evidence/sanitize.d.ts +16 -0
- package/dist/evidence/sanitize.js +70 -0
- package/dist/evidence/sanitize.js.map +1 -0
- package/dist/evidence/signals.d.ts +25 -0
- package/dist/evidence/signals.js +28 -0
- package/dist/evidence/signals.js.map +1 -0
- package/dist/evidence/usage.d.ts +12 -0
- package/dist/evidence/usage.js +24 -0
- package/dist/evidence/usage.js.map +1 -0
- package/dist/fault.d.ts +3 -0
- package/dist/fault.js +4 -0
- package/dist/fault.js.map +1 -0
- package/dist/gate/admission.d.ts +34 -0
- package/dist/gate/admission.js +2 -0
- package/dist/gate/admission.js.map +1 -0
- package/dist/gate/daily.d.ts +92 -0
- package/dist/gate/daily.js +136 -0
- package/dist/gate/daily.js.map +1 -0
- package/dist/gate/ledger.d.ts +29 -0
- package/dist/gate/ledger.js +88 -0
- package/dist/gate/ledger.js.map +1 -0
- package/dist/gate/sequential.d.ts +39 -0
- package/dist/gate/sequential.js +84 -0
- package/dist/gate/sequential.js.map +1 -0
- package/dist/index.d.ts +38 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/judge/audit.d.ts +45 -0
- package/dist/judge/audit.js +55 -0
- package/dist/judge/audit.js.map +1 -0
- package/dist/judge/calibration.d.ts +70 -0
- package/dist/judge/calibration.js +128 -0
- package/dist/judge/calibration.js.map +1 -0
- package/dist/judge/continuation.d.ts +16 -0
- package/dist/judge/continuation.js +48 -0
- package/dist/judge/continuation.js.map +1 -0
- package/dist/layer/versions.d.ts +71 -0
- package/dist/layer/versions.js +154 -0
- package/dist/layer/versions.js.map +1 -0
- package/dist/meta.d.ts +4 -0
- package/dist/meta.js.map +1 -1
- package/dist/propose/brief.d.ts +31 -0
- package/dist/propose/brief.js +52 -0
- package/dist/propose/brief.js.map +1 -0
- package/dist/propose/candidate.d.ts +15 -0
- package/dist/propose/candidate.js +30 -0
- package/dist/propose/candidate.js.map +1 -0
- package/dist/propose/rejections.d.ts +35 -0
- package/dist/propose/rejections.js +35 -0
- package/dist/propose/rejections.js.map +1 -0
- package/dist/propose/skill.d.ts +4 -0
- package/dist/propose/skill.js +34 -0
- package/dist/propose/skill.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TranscriptEntry } from "../transcript.js";
|
|
2
|
+
import type { Signal } from "./signals.js";
|
|
3
|
+
/** Asks a model for a reply to one prompt; the caller picks the model and pays for it. */
|
|
4
|
+
export type Complete = (prompt: string) => Promise<string>;
|
|
5
|
+
/** Why the failure happened. */
|
|
6
|
+
export declare const CAUSES: readonly ["tool_error", "wrong_command", "skipped_verification", "misread_request", "missing_context", "environment", "user_preference", "gave_up_early", "other"];
|
|
7
|
+
/** What the agent did that led to it. */
|
|
8
|
+
export declare const BEHAVIORS: readonly ["read", "edit", "run_command", "answer", "plan", "ask", "other"];
|
|
9
|
+
/** A failure written as three fields; two failures are the same kind only when all three are equal. */
|
|
10
|
+
export interface FailureSignature {
|
|
11
|
+
cause: (typeof CAUSES)[number];
|
|
12
|
+
behavior: (typeof BEHAVIORS)[number];
|
|
13
|
+
/** A short kebab-case name for the mechanism, such as `stops-at-truncated-output`. */
|
|
14
|
+
mechanism: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The rules failures are named by; a failure is counted only with failures named under the same rules, so changing
|
|
18
|
+
* them starts the count afresh instead of mixing two ways of naming.
|
|
19
|
+
*/
|
|
20
|
+
export declare const CLASSIFIER_VERSION = 3;
|
|
21
|
+
/** What a model makes of a signal: a named failure, or not a failure at all, such as a search that found nothing. */
|
|
22
|
+
export type Classified = FailureSignature | "not_a_failure";
|
|
23
|
+
/**
|
|
24
|
+
* The signature of the failure `signal` marks in `entries`. Signatures already seen, the most common first, are
|
|
25
|
+
* offered whole, so one kind of failure keeps one name; a reply that does not fit gives `undefined` rather than a
|
|
26
|
+
* guess. A session of another agent, `foreign`, may hold refusals by its host's own rules, which are not the agent's.
|
|
27
|
+
*/
|
|
28
|
+
export declare function classify(entries: readonly TranscriptEntry[], signal: Signal, known: readonly FailureSignature[], complete: Complete, foreign?: boolean): Promise<Classified | undefined>;
|
|
29
|
+
export declare function parseSignature(reply: string): Classified | undefined;
|
|
30
|
+
/** The key failures of one kind share. */
|
|
31
|
+
export declare function signatureKey(signature: FailureSignature): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isUserWritten } from "./points.js";
|
|
2
|
+
/** Why the failure happened. */
|
|
3
|
+
export const CAUSES = [
|
|
4
|
+
"tool_error", "wrong_command", "skipped_verification", "misread_request", "missing_context", "environment",
|
|
5
|
+
"user_preference", "gave_up_early", "other",
|
|
6
|
+
];
|
|
7
|
+
/** What the agent did that led to it. */
|
|
8
|
+
export const BEHAVIORS = ["read", "edit", "run_command", "answer", "plan", "ask", "other"];
|
|
9
|
+
const MECHANISM = /^[a-z0-9]+(-[a-z0-9]+){0,7}$/;
|
|
10
|
+
/**
|
|
11
|
+
* What the model is shown of a session: lines before the failure, and after it up to the user's next message, which
|
|
12
|
+
* tell a failure the agent had to recover from apart from a result it used; each line cut to a length.
|
|
13
|
+
*/
|
|
14
|
+
const BEFORE = 20;
|
|
15
|
+
const AFTER = 8;
|
|
16
|
+
const ENTRY_CHARS = 1500;
|
|
17
|
+
/** How many named failures are offered, the most common first, so the prompt does not grow with the catalog. */
|
|
18
|
+
const KNOWN_SHOWN = 30;
|
|
19
|
+
/**
|
|
20
|
+
* The rules failures are named by; a failure is counted only with failures named under the same rules, so changing
|
|
21
|
+
* them starts the count afresh instead of mixing two ways of naming.
|
|
22
|
+
*/
|
|
23
|
+
export const CLASSIFIER_VERSION = 3;
|
|
24
|
+
/**
|
|
25
|
+
* The signature of the failure `signal` marks in `entries`. Signatures already seen, the most common first, are
|
|
26
|
+
* offered whole, so one kind of failure keeps one name; a reply that does not fit gives `undefined` rather than a
|
|
27
|
+
* guess. A session of another agent, `foreign`, may hold refusals by its host's own rules, which are not the agent's.
|
|
28
|
+
*/
|
|
29
|
+
export async function classify(entries, signal, known, complete, foreign = false) {
|
|
30
|
+
const next = entries.findIndex((entry, line) => line > signal.line && isUserWritten(entry));
|
|
31
|
+
const end = Math.min(next === -1 ? entries.length : next + 1, signal.line + 1 + AFTER);
|
|
32
|
+
const window = entries.slice(Math.max(0, signal.line - BEFORE), end);
|
|
33
|
+
const reply = await complete(prompt(window, signal.line - Math.max(0, signal.line - BEFORE), signal, known.slice(0, KNOWN_SHOWN), foreign));
|
|
34
|
+
return parseSignature(reply);
|
|
35
|
+
}
|
|
36
|
+
export function parseSignature(reply) {
|
|
37
|
+
const json = reply.slice(reply.indexOf("{"), reply.lastIndexOf("}") + 1);
|
|
38
|
+
let value;
|
|
39
|
+
try {
|
|
40
|
+
value = JSON.parse(json);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
if (value.failure === false)
|
|
46
|
+
return "not_a_failure";
|
|
47
|
+
const { cause, behavior, mechanism } = value;
|
|
48
|
+
if (!CAUSES.includes(cause) || !BEHAVIORS.includes(behavior))
|
|
49
|
+
return undefined;
|
|
50
|
+
if (typeof mechanism !== "string" || !MECHANISM.test(mechanism))
|
|
51
|
+
return undefined;
|
|
52
|
+
return { cause, behavior, mechanism };
|
|
53
|
+
}
|
|
54
|
+
/** The key failures of one kind share. */
|
|
55
|
+
export function signatureKey(signature) {
|
|
56
|
+
return `${signature.cause}/${signature.behavior}/${signature.mechanism}`;
|
|
57
|
+
}
|
|
58
|
+
function prompt(window, at, signal, known, foreign) {
|
|
59
|
+
return [
|
|
60
|
+
"An agent's session may have gone wrong at the line marked >>> below. If it did, name the failure with three",
|
|
61
|
+
"fields, as one JSON object.",
|
|
62
|
+
`- cause: one of ${CAUSES.join(", ")}`,
|
|
63
|
+
`- behavior: what the agent did that led to it, one of ${BEHAVIORS.join(", ")}`,
|
|
64
|
+
"- mechanism: a kebab-case name for how it failed, of at most 8 words, general enough to recur in other sessions",
|
|
65
|
+
...(known.length === 0 ? [] : [
|
|
66
|
+
"When it is the same failure as one already named, reply with that one exactly, all three fields as they are;",
|
|
67
|
+
"name a new one when they only sound alike:",
|
|
68
|
+
...known.map((signature) => JSON.stringify(signature)),
|
|
69
|
+
]),
|
|
70
|
+
'Reply {"failure":false} when it is no failure of the agent\'s own making:',
|
|
71
|
+
"- the agent got what it needed and carried on, as the lines after it show, such as when a search rightly found",
|
|
72
|
+
" nothing or one part of a longer command exited non-zero",
|
|
73
|
+
"- the outside world failed, such as the network or a service, and no other step would have fared better",
|
|
74
|
+
...(foreign ? [
|
|
75
|
+
"- the agent's host refused it by a rule of its own, such as a blocked command, a permission check or a sandbox",
|
|
76
|
+
" limit; this session comes from another agent, and its host's rules are not this agent's",
|
|
77
|
+
] : []),
|
|
78
|
+
`The signal: ${JSON.stringify(signal)}`,
|
|
79
|
+
"The session around it, one ACP entry per line:",
|
|
80
|
+
...window.map((entry, line) => {
|
|
81
|
+
const text = JSON.stringify(entry);
|
|
82
|
+
return `${line === at ? ">>> " : ""}${text.length <= ENTRY_CHARS ? text : `${text.slice(0, ENTRY_CHARS)}…`}`;
|
|
83
|
+
}),
|
|
84
|
+
'Reply with only the JSON object, such as {"cause":"…","behavior":"…","mechanism":"…"} or {"failure":false}.',
|
|
85
|
+
].join("\n");
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=classify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../../src/evidence/classify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAM5C,gCAAgC;AAChC,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa;IAC1G,iBAAiB,EAAE,eAAe,EAAE,OAAO;CACnC,CAAC;AAEX,yCAAyC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAU,CAAC;AAUpG,MAAM,SAAS,GAAG,8BAA8B,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,gHAAgH;AAChH,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAKpC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAAmC,EACnC,MAAc,EACd,KAAkC,EAClC,QAAkB,EAClB,OAAO,GAAG,KAAK;IAEf,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5F,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAA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AAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC;QAC/G,CAAC,CAAC;QACF,6GAA6G;KAC9G,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TranscriptEntry } from "../transcript.js";
|
|
2
|
+
import type { Complete } from "./classify.js";
|
|
3
|
+
/** A user message that may correct the agent; it counts as a failure only once the user confirms it. */
|
|
4
|
+
export interface CorrectionCandidate {
|
|
5
|
+
/** The transcript line of the user's message. */
|
|
6
|
+
line: number;
|
|
7
|
+
/** What the user corrected, in a few words. */
|
|
8
|
+
summary: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Lines from `from` on where the user pushed back on what the agent did. A model proposes them, since no event marks
|
|
12
|
+
* a correction; a long session is asked about in batches, and lines the user did not write are dropped.
|
|
13
|
+
*/
|
|
14
|
+
export declare function proposeCorrections(entries: readonly TranscriptEntry[], complete: Complete, from?: number): Promise<CorrectionCandidate[]>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { correctedStep, isUserWritten } from "./points.js";
|
|
2
|
+
/** How much of each message the model is shown, and how much one request carries, so a long session stays cheap. */
|
|
3
|
+
const USER_CHARS = 1200;
|
|
4
|
+
const AGENT_CHARS = 600;
|
|
5
|
+
const BATCH_CHARS = 60_000;
|
|
6
|
+
/**
|
|
7
|
+
* Lines from `from` on where the user pushed back on what the agent did. A model proposes them, since no event marks
|
|
8
|
+
* a correction; a long session is asked about in batches, and lines the user did not write are dropped.
|
|
9
|
+
*/
|
|
10
|
+
export async function proposeCorrections(entries, complete, from = 0) {
|
|
11
|
+
const users = entries.flatMap((entry, line) => (line >= from && isUserWritten(entry) ? [line] : []));
|
|
12
|
+
const found = [];
|
|
13
|
+
for (const batch of batches(users.map((line) => excerpt(entries, line)))) {
|
|
14
|
+
const reply = await complete([
|
|
15
|
+
"Below are the user's messages from an agent session, each with the agent step just before it. Find the user",
|
|
16
|
+
"messages that correct the agent: rejecting what it did, pointing out a mistake, or restating a rule it broke.",
|
|
17
|
+
"Questions and new requests are not corrections, nor are praise, agreement, or frustration that names nothing to",
|
|
18
|
+
"do differently. Summarize each as what the agent should do instead, in a few words. Reply with only a JSON",
|
|
19
|
+
'array such as [{"line":12,"summary":"use pnpm, not npm"}], or [] for none.',
|
|
20
|
+
...batch,
|
|
21
|
+
].join("\n"));
|
|
22
|
+
found.push(...parseCandidates(reply, users));
|
|
23
|
+
}
|
|
24
|
+
return found;
|
|
25
|
+
}
|
|
26
|
+
function excerpt(entries, line) {
|
|
27
|
+
const before = correctedStep(entries, line);
|
|
28
|
+
const agent = before === undefined ? "" : `agent before ${line}: ${clip(JSON.stringify(entries[before]), AGENT_CHARS)}\n`;
|
|
29
|
+
return `${agent}user ${line}: ${clip(JSON.stringify(entries[line]), USER_CHARS)}`;
|
|
30
|
+
}
|
|
31
|
+
function batches(excerpts) {
|
|
32
|
+
const all = [];
|
|
33
|
+
let size = Infinity;
|
|
34
|
+
for (const text of excerpts) {
|
|
35
|
+
if (size + text.length > BATCH_CHARS) {
|
|
36
|
+
all.push([]);
|
|
37
|
+
size = 0;
|
|
38
|
+
}
|
|
39
|
+
all.at(-1).push(text);
|
|
40
|
+
size += text.length;
|
|
41
|
+
}
|
|
42
|
+
return all;
|
|
43
|
+
}
|
|
44
|
+
function parseCandidates(reply, users) {
|
|
45
|
+
let found;
|
|
46
|
+
try {
|
|
47
|
+
found = JSON.parse(reply.slice(reply.indexOf("["), reply.lastIndexOf("]") + 1));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(found))
|
|
53
|
+
return [];
|
|
54
|
+
return found.flatMap((item) => typeof item.line === "number" && users.includes(item.line) && typeof item.summary === "string" && item.summary !== ""
|
|
55
|
+
? [{ line: item.line, summary: item.summary }]
|
|
56
|
+
: []);
|
|
57
|
+
}
|
|
58
|
+
function clip(text, limit) {
|
|
59
|
+
return text.length <= limit ? text : `${text.slice(0, limit)}…`;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=corrections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corrections.js","sourceRoot":"","sources":["../../src/evidence/corrections.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D,oHAAoH;AACpH,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,WAAW,GAAG,MAAM,CAAC;AAU3B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAmC,EAAE,QAAkB,EAAE,IAAI,GAAG,CAAC;IACxG,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrG,MAAM,KAAK,GAA0B,EAAE,CAAC;IACxC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC;YAC3B,6GAA6G;YAC7G,+GAA+G;YAC/G,iHAAiH;YACjH,4GAA4G;YAC5G,4EAA4E;YAC5E,GAAG,KAAK;SACT,CAAC,IAAI,CAAC,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AAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAA2C,EAAE,EAAE,CACnE,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,EAAE;QACnH,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9C,CAAC,CAAC,EAAE,CAAC,CAAC;AACZ,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa;IACvC,OAAO,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Complete, type FailureSignature } from "./classify.js";
|
|
2
|
+
/** One failure in one session, with its signature. */
|
|
3
|
+
export interface Failure {
|
|
4
|
+
session: string;
|
|
5
|
+
/** The transcript line where it happened. */
|
|
6
|
+
line: number;
|
|
7
|
+
signature: FailureSignature;
|
|
8
|
+
/** The version of the rules it was named by. */
|
|
9
|
+
classifier?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Failures of one kind, and the distinct sessions they came from. */
|
|
12
|
+
export interface FailureClass {
|
|
13
|
+
key: string;
|
|
14
|
+
/** The signature most of its failures were named with. */
|
|
15
|
+
signature: FailureSignature;
|
|
16
|
+
failures: Failure[];
|
|
17
|
+
sessions: string[];
|
|
18
|
+
}
|
|
19
|
+
/** How many distinct sessions a kind of failure must appear in before it starts a round. */
|
|
20
|
+
export declare const TRIGGER_SESSIONS = 2;
|
|
21
|
+
/**
|
|
22
|
+
* The key failures of one kind share: what the agent did and how it failed. The cause is a judgement that differs
|
|
23
|
+
* between sessions for the same mechanism, so it describes a kind without splitting it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function kindKey(signature: FailureSignature): string;
|
|
26
|
+
/**
|
|
27
|
+
* Failures grouped by kind, the kinds seen in the most sessions first. `aliases` maps a kind's key to the key of the
|
|
28
|
+
* kind it is another name for, whose name the merged kind carries.
|
|
29
|
+
*/
|
|
30
|
+
export declare function groupFailures(failures: readonly Failure[], aliases?: ReadonlyMap<string, string>): FailureClass[];
|
|
31
|
+
/** The kinds looked at for other names before, and the aliases found among them. */
|
|
32
|
+
export interface KindNaming {
|
|
33
|
+
reviewed: readonly string[];
|
|
34
|
+
aliases: ReadonlyMap<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Which kinds are other names for one mechanism. Each behavior with a kind not looked at before is asked about once,
|
|
38
|
+
* with every name given within it; a new kind joins the kind of an earlier name it is grouped with, or else the first
|
|
39
|
+
* new name of its group, while kinds looked at before keep the names they were given, so grouping only ever settles.
|
|
40
|
+
* A reply naming a kind that is not there, or one kind twice, is not taken.
|
|
41
|
+
*/
|
|
42
|
+
export declare function kindAliases(kinds: readonly string[], complete: Complete, before?: KindNaming): Promise<Map<string, string>>;
|
|
43
|
+
/** The kinds of failure that have recurred often enough to start a round. */
|
|
44
|
+
export declare function triggered(classes: readonly FailureClass[], sessions?: number): FailureClass[];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { signatureKey } from "./classify.js";
|
|
2
|
+
/** How many distinct sessions a kind of failure must appear in before it starts a round. */
|
|
3
|
+
export const TRIGGER_SESSIONS = 2;
|
|
4
|
+
/**
|
|
5
|
+
* The key failures of one kind share: what the agent did and how it failed. The cause is a judgement that differs
|
|
6
|
+
* between sessions for the same mechanism, so it describes a kind without splitting it.
|
|
7
|
+
*/
|
|
8
|
+
export function kindKey(signature) {
|
|
9
|
+
return `${signature.behavior}/${signature.mechanism}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Failures grouped by kind, the kinds seen in the most sessions first. `aliases` maps a kind's key to the key of the
|
|
13
|
+
* kind it is another name for, whose name the merged kind carries.
|
|
14
|
+
*/
|
|
15
|
+
export function groupFailures(failures, aliases = new Map()) {
|
|
16
|
+
const classes = new Map();
|
|
17
|
+
for (const failure of failures) {
|
|
18
|
+
const own = kindKey(failure.signature);
|
|
19
|
+
const key = aliases.get(own) ?? own;
|
|
20
|
+
const found = classes.get(key) ?? { key, signature: failure.signature, failures: [], sessions: [] };
|
|
21
|
+
found.failures.push(failure);
|
|
22
|
+
if (!found.sessions.includes(failure.session))
|
|
23
|
+
found.sessions.push(failure.session);
|
|
24
|
+
classes.set(key, found);
|
|
25
|
+
}
|
|
26
|
+
for (const found of classes.values()) {
|
|
27
|
+
const signature = mostCommon(found.failures.map((failure) => failure.signature));
|
|
28
|
+
found.signature = { ...signature, mechanism: found.key.slice(found.key.indexOf("/") + 1) };
|
|
29
|
+
}
|
|
30
|
+
return [...classes.values()].sort((a, b) => b.sessions.length - a.sessions.length);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Which kinds are other names for one mechanism. Each behavior with a kind not looked at before is asked about once,
|
|
34
|
+
* with every name given within it; a new kind joins the kind of an earlier name it is grouped with, or else the first
|
|
35
|
+
* new name of its group, while kinds looked at before keep the names they were given, so grouping only ever settles.
|
|
36
|
+
* A reply naming a kind that is not there, or one kind twice, is not taken.
|
|
37
|
+
*/
|
|
38
|
+
export async function kindAliases(kinds, complete, before = { reviewed: [], aliases: new Map() }) {
|
|
39
|
+
const aliases = new Map(before.aliases);
|
|
40
|
+
const reviewed = new Set(before.reviewed);
|
|
41
|
+
for (const [behavior, keys] of Map.groupBy(kinds, (key) => key.slice(0, key.indexOf("/")))) {
|
|
42
|
+
if (keys.length < 2 || keys.every((key) => reviewed.has(key)))
|
|
43
|
+
continue;
|
|
44
|
+
const names = keys.map((key) => key.slice(behavior.length + 1));
|
|
45
|
+
const reply = await complete([
|
|
46
|
+
`Below are names an agent's failures were given, all from the behavior "${behavior}". Group the names that name`,
|
|
47
|
+
"the same mechanism in other words, so a fix for one is a fix for all; names that are only related stay apart.",
|
|
48
|
+
'Reply with only a JSON array of groups, each with the name to keep first, such as [["a-b","a-b-c"]], or [] for',
|
|
49
|
+
"none.",
|
|
50
|
+
...names,
|
|
51
|
+
].join("\n"));
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
for (const group of parseGroups(reply)) {
|
|
54
|
+
if (group.length < 2 || group.some((name) => !names.includes(name) || seen.has(name)))
|
|
55
|
+
continue;
|
|
56
|
+
for (const name of group)
|
|
57
|
+
seen.add(name);
|
|
58
|
+
const members = group.map((name) => `${behavior}/${name}`);
|
|
59
|
+
const anchor = members.find((key) => reviewed.has(key)) ?? members[0];
|
|
60
|
+
const target = aliases.get(anchor) ?? anchor;
|
|
61
|
+
for (const key of members)
|
|
62
|
+
if (!reviewed.has(key) && key !== target)
|
|
63
|
+
aliases.set(key, target);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return aliases;
|
|
67
|
+
}
|
|
68
|
+
function parseGroups(reply) {
|
|
69
|
+
try {
|
|
70
|
+
const value = JSON.parse(reply.slice(reply.indexOf("["), reply.lastIndexOf("]") + 1));
|
|
71
|
+
if (!Array.isArray(value))
|
|
72
|
+
return [];
|
|
73
|
+
return value.filter((group) => Array.isArray(group) && group.every((name) => typeof name === "string"));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function mostCommon(signatures) {
|
|
80
|
+
const counts = new Map();
|
|
81
|
+
for (const signature of signatures) {
|
|
82
|
+
const key = signatureKey(signature);
|
|
83
|
+
counts.set(key, { signature, count: (counts.get(key)?.count ?? 0) + 1 });
|
|
84
|
+
}
|
|
85
|
+
return [...counts.values()].reduce((best, next) => (next.count > best.count ? next : best)).signature;
|
|
86
|
+
}
|
|
87
|
+
/** The kinds of failure that have recurred often enough to start a round. */
|
|
88
|
+
export function triggered(classes, sessions = TRIGGER_SESSIONS) {
|
|
89
|
+
return classes.filter((found) => found.sessions.length >= sessions);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=failures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failures.js","sourceRoot":"","sources":["../../src/evidence/failures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwC,MAAM,eAAe,CAAC;AAqBnF,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,SAA2B;IACjD,OAAO,GAAG,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAA4B,EAAE,OAAO,GAAgC,IAAI,GAAG,EAAE;IAC1G,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAChD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;QACpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,QA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AAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACxG,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,SAAS,CAAC,OAAgC,EAAE,QAAQ,GAAG,gBAAgB;IACrF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TranscriptEntry } from "../transcript.js";
|
|
2
|
+
/**
|
|
3
|
+
* A transcript from session logs written one JSON object per line, each a user or assistant message whose content is
|
|
4
|
+
* text, thinking, tool-use and tool-result blocks. Side threads and bookkeeping lines are left out; user-role text the
|
|
5
|
+
* user did not write stays in, since the model saw it, marked as injected.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fromMessagesJsonl(text: string): TranscriptEntry[];
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { withChopinMeta } from "../meta.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tool names other agents use, as the tools chopin has. A call with no counterpart keeps its own name, and a
|
|
4
|
+
* continuation skips the steps it cannot offer.
|
|
5
|
+
*/
|
|
6
|
+
const TOOLS = { Read: "read", Write: "write", Edit: "edit", MultiEdit: "edit", Bash: "bash" };
|
|
7
|
+
const INTERRUPTED = "[Request interrupted by user";
|
|
8
|
+
/** How these logs record a tool call the user declined to let run. */
|
|
9
|
+
const REJECTED = "User rejected tool use";
|
|
10
|
+
/**
|
|
11
|
+
* A transcript from session logs written one JSON object per line, each a user or assistant message whose content is
|
|
12
|
+
* text, thinking, tool-use and tool-result blocks. Side threads and bookkeeping lines are left out; user-role text the
|
|
13
|
+
* user did not write stays in, since the model saw it, marked as injected.
|
|
14
|
+
*/
|
|
15
|
+
export function fromMessagesJsonl(text) {
|
|
16
|
+
const entries = [];
|
|
17
|
+
const kinds = new Map();
|
|
18
|
+
for (const raw of text.split("\n")) {
|
|
19
|
+
if (raw.trim() === "")
|
|
20
|
+
continue;
|
|
21
|
+
let line;
|
|
22
|
+
try {
|
|
23
|
+
line = JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const message = line.message;
|
|
29
|
+
if ((line.type !== "user" && line.type !== "assistant") || line.isSidechain === true || message === undefined)
|
|
30
|
+
continue;
|
|
31
|
+
const sessionId = line.sessionId ?? "";
|
|
32
|
+
const at = line.timestamp ?? "";
|
|
33
|
+
const blocks = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content ?? [];
|
|
34
|
+
if (message.role === "user") {
|
|
35
|
+
for (const block of blocks) {
|
|
36
|
+
if (block.type === "text" && "text" in block && block.text.startsWith(INTERRUPTED)) {
|
|
37
|
+
entries.push({ at, sessionId, turnEnd: { stopReason: "cancelled" } });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const update = userUpdate(block, kinds, line.toolUseResult === REJECTED);
|
|
41
|
+
const injected = update?.sessionUpdate === "user_message_chunk" && line.promptSource !== "typed";
|
|
42
|
+
if (update !== undefined) {
|
|
43
|
+
entries.push({ at, notification: { sessionId, update: injected ? withChopinMeta(update, { injected }) : update } });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (const block of blocks) {
|
|
50
|
+
const update = assistantUpdate(block, kinds);
|
|
51
|
+
if (update !== undefined)
|
|
52
|
+
entries.push({ at, notification: { sessionId, update } });
|
|
53
|
+
}
|
|
54
|
+
if (message.stop_reason === "end_turn") {
|
|
55
|
+
const model = message.model === undefined ? {} : { model: { provider: "", id: message.model } };
|
|
56
|
+
entries.push({ at, sessionId, turnEnd: withChopinMeta({ stopReason: "end_turn" }, model) });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return entries;
|
|
60
|
+
}
|
|
61
|
+
function userUpdate(block, kinds, rejected) {
|
|
62
|
+
if (block.type === "text" && "text" in block)
|
|
63
|
+
return { sessionUpdate: "user_message_chunk", content: { type: "text", text: block.text } };
|
|
64
|
+
if (block.type !== "tool_result" || !("tool_use_id" in block))
|
|
65
|
+
return undefined;
|
|
66
|
+
const text = typeof block.content === "string"
|
|
67
|
+
? block.content
|
|
68
|
+
: (block.content ?? []).flatMap((item) => (item.type === "text" && item.text !== undefined ? [item.text] : [])).join("\n");
|
|
69
|
+
const update = {
|
|
70
|
+
sessionUpdate: "tool_call_update", toolCallId: block.tool_use_id, status: block.is_error === true ? "failed" : "completed",
|
|
71
|
+
kind: kinds.get(block.tool_use_id) ?? "other", content: [{ type: "content", content: { type: "text", text } }],
|
|
72
|
+
};
|
|
73
|
+
return rejected ? withChopinMeta(update, { diagnostics: ["rejected"] }) : update;
|
|
74
|
+
}
|
|
75
|
+
function assistantUpdate(block, kinds) {
|
|
76
|
+
if (block.type === "text" && "text" in block)
|
|
77
|
+
return { sessionUpdate: "agent_message_chunk", content: { type: "text", text: block.text } };
|
|
78
|
+
if (block.type === "thinking" && "thinking" in block) {
|
|
79
|
+
return { sessionUpdate: "agent_thought_chunk", content: { type: "text", text: block.thinking } };
|
|
80
|
+
}
|
|
81
|
+
if (block.type !== "tool_use" || !("id" in block))
|
|
82
|
+
return undefined;
|
|
83
|
+
const title = TOOLS[block.name] ?? block.name;
|
|
84
|
+
const kind = toolKind(title);
|
|
85
|
+
kinds.set(block.id, kind);
|
|
86
|
+
return { sessionUpdate: "tool_call", toolCallId: block.id, title, kind, status: "pending", rawInput: block.input };
|
|
87
|
+
}
|
|
88
|
+
function toolKind(name) {
|
|
89
|
+
if (name === "read")
|
|
90
|
+
return "read";
|
|
91
|
+
if (name === "write" || name === "edit")
|
|
92
|
+
return "edit";
|
|
93
|
+
if (name === "bash")
|
|
94
|
+
return "execute";
|
|
95
|
+
return "other";
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=messages-jsonl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages-jsonl.js","sourceRoot":"","sources":["../../src/evidence/messages-jsonl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C;;;GAGG;AACH,MAAM,KAAK,GAAqC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAEhI,MAAM,WAAW,GAAG,8BAA8B,CAAC;AACnD,sEAAsE;AACtE,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAoB1C;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,SAAS;QAChC,IAAI,IAAU,CAAC;QACf,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,C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AAE,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;IAC3I,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;QACrD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACnG,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7B,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC1B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;AACrH,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACnC,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACvD,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IACtC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TranscriptEntry } from "../transcript.js";
|
|
2
|
+
import type { Signal } from "./signals.js";
|
|
3
|
+
/** Whether the entry is something the user wrote, not text the harness added in the user's role. */
|
|
4
|
+
export declare function isUserWritten(entry: TranscriptEntry): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* A place to continue a session from: the agent step at `line`, with every line before it as the context. Continuing
|
|
7
|
+
* there shows what another version of the agent would have done instead.
|
|
8
|
+
*/
|
|
9
|
+
export interface DecisionPoint {
|
|
10
|
+
session: string;
|
|
11
|
+
line: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The session before `line` to continue from: the last `size` lines or so, begun at a message in the user's role,
|
|
15
|
+
* as a conversation must be; one is looked for up to `size` lines further back, and without one there is none.
|
|
16
|
+
*/
|
|
17
|
+
export declare function continuationPrefix(entries: readonly TranscriptEntry[], line: number, size: number): TranscriptEntry[] | undefined;
|
|
18
|
+
/** The agent step a failure goes back to: the failed call itself, or the last step before the user stepped in. */
|
|
19
|
+
export declare function failureStep(entries: readonly TranscriptEntry[], signal: Signal): number | undefined;
|
|
20
|
+
/** The agent step a user's correction answers: the last one before the user spoke. */
|
|
21
|
+
export declare function correctedStep(entries: readonly TranscriptEntry[], line: number): number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Agent steps that went right: tool calls that completed, in turns where nothing went wrong afterwards before the user
|
|
24
|
+
* spoke again. `wrong` holds the lines of the session's signals and corrections.
|
|
25
|
+
*/
|
|
26
|
+
export declare function goodSteps(entries: readonly TranscriptEntry[], wrong: readonly number[]): number[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { chopinMeta } from "../meta.js";
|
|
2
|
+
/** Whether the entry is something the user wrote, not text the harness added in the user's role. */
|
|
3
|
+
export function isUserWritten(entry) {
|
|
4
|
+
if (!("notification" in entry))
|
|
5
|
+
return false;
|
|
6
|
+
const update = entry.notification.update;
|
|
7
|
+
return update.sessionUpdate === "user_message_chunk" && chopinMeta(update)?.injected !== true;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The session before `line` to continue from: the last `size` lines or so, begun at a message in the user's role,
|
|
11
|
+
* as a conversation must be; one is looked for up to `size` lines further back, and without one there is none.
|
|
12
|
+
*/
|
|
13
|
+
export function continuationPrefix(entries, line, size) {
|
|
14
|
+
const cut = Math.max(0, line - size);
|
|
15
|
+
const userTurn = (at) => {
|
|
16
|
+
const entry = entries[at];
|
|
17
|
+
return "notification" in entry && entry.notification.update.sessionUpdate === "user_message_chunk";
|
|
18
|
+
};
|
|
19
|
+
for (let start = cut; start < line; start += 1)
|
|
20
|
+
if (userTurn(start))
|
|
21
|
+
return entries.slice(start, line);
|
|
22
|
+
for (let start = cut - 1; start >= Math.max(0, cut - size); start -= 1)
|
|
23
|
+
if (userTurn(start))
|
|
24
|
+
return entries.slice(start, line);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The agent step a failure goes back to: the failed call itself, or the last step before the user stepped in. */
|
|
28
|
+
export function failureStep(entries, signal) {
|
|
29
|
+
if (signal.kind === "tool_failed") {
|
|
30
|
+
return entries.findIndex((entry) => "notification" in entry && entry.notification.update.sessionUpdate === "tool_call" &&
|
|
31
|
+
entry.notification.update.toolCallId === signal.toolCallId);
|
|
32
|
+
}
|
|
33
|
+
return lastAgentStep(entries, signal.line);
|
|
34
|
+
}
|
|
35
|
+
/** The agent step a user's correction answers: the last one before the user spoke. */
|
|
36
|
+
export function correctedStep(entries, line) {
|
|
37
|
+
return lastAgentStep(entries, line);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Agent steps that went right: tool calls that completed, in turns where nothing went wrong afterwards before the user
|
|
41
|
+
* spoke again. `wrong` holds the lines of the session's signals and corrections.
|
|
42
|
+
*/
|
|
43
|
+
export function goodSteps(entries, wrong) {
|
|
44
|
+
const completed = new Set(entries.flatMap((entry) => "notification" in entry && entry.notification.update.sessionUpdate === "tool_call_update" &&
|
|
45
|
+
entry.notification.update.status === "completed" ? [entry.notification.update.toolCallId] : []));
|
|
46
|
+
return entries.flatMap((entry, line) => {
|
|
47
|
+
if (!("notification" in entry))
|
|
48
|
+
return [];
|
|
49
|
+
const update = entry.notification.update;
|
|
50
|
+
if (update.sessionUpdate !== "tool_call" || !completed.has(update.toolCallId))
|
|
51
|
+
return [];
|
|
52
|
+
const end = nextUserLine(entries, line);
|
|
53
|
+
return wrong.some((bad) => bad > line && bad <= end) ? [] : [line];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function isAgentStep(entry) {
|
|
57
|
+
if (!("notification" in entry))
|
|
58
|
+
return false;
|
|
59
|
+
const kind = entry.notification.update.sessionUpdate;
|
|
60
|
+
return kind === "tool_call" || kind === "agent_message_chunk";
|
|
61
|
+
}
|
|
62
|
+
function lastAgentStep(entries, before) {
|
|
63
|
+
for (let line = before - 1; line >= 0; line -= 1)
|
|
64
|
+
if (isAgentStep(entries[line]))
|
|
65
|
+
return line;
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
function nextUserLine(entries, after) {
|
|
69
|
+
const next = entries.findIndex((entry, line) => line > after && isUserWritten(entry));
|
|
70
|
+
return next === -1 ? entries.length : next;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=points.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"points.js","sourceRoot":"","sources":["../../src/evidence/points.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIxC,oGAAoG;AACpG,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,IAAI,CAAC,CAAC,cAAc,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;IACzC,OAAO,MAAM,CAAC,aAAa,KAAK,oBAAoB,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;AAChG,CAAC;AAWD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAmC,EAAE,IAAY,EAAE,IAAY;IAChG,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CA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AC,aAAa,CAAC;IACrD,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,qBAAqB,CAAC;AAChE,CAAC;AAED,SAAS,aAAa,CAAC,OAAmC,EAAE,MAAc;IACxE,KAAK,IAAI,IAAI,GAAG,MAAM,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC;QAAE,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,CAAE,CAAC;YAAE,OAAO,IAAI,CAAC;IAC/F,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,YAAY,CAAC,OAAmC,EAAE,KAAa;IACtE,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACtF,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { McpServer } from "../layer/mcp.js";
|
|
2
|
+
import type { TranscriptEntry } from "../transcript.js";
|
|
3
|
+
/** The values of environment variables named like secrets. */
|
|
4
|
+
export declare function secretValues(env: Readonly<Record<string, string | undefined>>): string[];
|
|
5
|
+
/**
|
|
6
|
+
* The secrets MCP servers are configured with, from headers and environment named like secrets: each whole value and
|
|
7
|
+
* each long word of it, so a token is masked with or without the scheme before it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mcpSecrets(servers: Readonly<Record<string, McpServer>>): string[];
|
|
10
|
+
/** `text` with every known secret value and every common secret format masked. */
|
|
11
|
+
export declare function redactText(text: string, values: readonly string[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* A transcript fit to leave the session: secrets masked in every string, and the output of any tool call that touched
|
|
14
|
+
* a secret file replaced by the fact that it did.
|
|
15
|
+
*/
|
|
16
|
+
export declare function redactTranscript(entries: readonly TranscriptEntry[], values: readonly string[]): TranscriptEntry[];
|