@introspection-ai/recipes 0.44.0 → 0.46.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/README.md +2 -0
- package/dist/artifact-review-tui.d.ts +5 -18
- package/dist/artifact-review-tui.d.ts.map +1 -1
- package/dist/artifact-review-tui.js +5 -18
- package/dist/artifact-review-tui.js.map +1 -1
- package/dist/artifact-review.d.ts +1 -52
- package/dist/artifact-review.d.ts.map +1 -1
- package/dist/artifact-review.js +2 -156
- package/dist/artifact-review.js.map +1 -1
- package/dist/ask-user-question.d.ts +3 -3
- package/dist/ask-user-question.d.ts.map +1 -1
- package/dist/ask-user-question.js +3 -3
- package/dist/ask-user-question.js.map +1 -1
- package/dist/interaction-text.d.ts +54 -0
- package/dist/interaction-text.d.ts.map +1 -0
- package/dist/interaction-text.js +93 -0
- package/dist/interaction-text.js.map +1 -0
- package/dist/interactions.d.ts +2 -44
- package/dist/interactions.d.ts.map +1 -1
- package/dist/interactions.js +2 -82
- package/dist/interactions.js.map +1 -1
- package/dist/mcp-daemon.js +1 -1
- package/dist/mcp-run-worker.js +1 -1
- package/dist/recipe/companions.d.ts +3 -2
- package/dist/recipe/companions.d.ts.map +1 -1
- package/dist/recipe/companions.js +15 -27
- package/dist/recipe/companions.js.map +1 -1
- package/dist/recipe/manifest.generated.d.ts +16 -0
- package/dist/recipe/manifest.generated.d.ts.map +1 -0
- package/dist/recipe/manifest.generated.js +17 -0
- package/dist/recipe/manifest.generated.js.map +1 -0
- package/dist/review.d.ts +92 -0
- package/dist/review.d.ts.map +1 -0
- package/dist/review.js +253 -0
- package/dist/review.js.map +1 -0
- package/docs/interactions.md +7 -1
- package/docs/pi-extension.md +3 -0
- package/docs/recipe-format.md +20 -2
- package/package.json +14 -9
- /package/dist/mcp-chunks/{chunk-GODH4VLN.js → chunk-3M4OCQR5.js} +0 -0
package/dist/review.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The review of the files an agent wrote, as every renderer shares it: the
|
|
3
|
+
* decisions, the answer text a run resumes with, the interrupt a pause/resume
|
|
4
|
+
* host renders, each tab's name and the diff since the last review, plus the
|
|
5
|
+
* interaction wording. Pi's terminal (`./artifact-review-tui.ts`) and a
|
|
6
|
+
* browser host both import it, so it imports nothing from Node, Pi or a
|
|
7
|
+
* renderer; `test/review-core.test.ts` fails if it does.
|
|
8
|
+
*/
|
|
9
|
+
export { DISMISSED_TEXT, formatInteractionOutcome, formatInteractionResume, type AskUserOutcome, type InteractionResumeResponse, } from "./interaction-text.js";
|
|
10
|
+
export declare const REVIEW_ARTIFACTS_TOOL_NAME = "review_artifacts";
|
|
11
|
+
/** At most this many files in one review, so the user can get through it. */
|
|
12
|
+
export declare const MAX_REVIEW_ITEMS = 20;
|
|
13
|
+
export type ReviewDecision = "approved" | "changes_requested" | "not_reviewed";
|
|
14
|
+
/** One file's outcome. `opened` says whether the user had it on screen. */
|
|
15
|
+
export interface ArtifactReview {
|
|
16
|
+
path: string;
|
|
17
|
+
decision: ReviewDecision;
|
|
18
|
+
comment?: string;
|
|
19
|
+
opened: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** One file as the review shows it. */
|
|
22
|
+
export interface ReviewDocument {
|
|
23
|
+
/** The file's path, relative to the workspace. */
|
|
24
|
+
path: string;
|
|
25
|
+
label: string;
|
|
26
|
+
/** What the box shows: the file's summary line and its section. */
|
|
27
|
+
content: string;
|
|
28
|
+
}
|
|
29
|
+
/** A file as the review shows it, with the hash of the whole file (null when it doesn't exist). */
|
|
30
|
+
export interface ShownDocument extends ReviewDocument {
|
|
31
|
+
sha256: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the review shows of a file: its front matter folded into one line (the
|
|
35
|
+
* case's check, inputs and approval, not the fields themselves), and with a
|
|
36
|
+
* `section`, only that heading's part.
|
|
37
|
+
*/
|
|
38
|
+
export declare function reviewSource(source: string, section?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* The answer text the model receives, one line per file after a tally. A
|
|
41
|
+
* pause/resume host resumes with this same text as `{ answer }`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatReviews(reviews: readonly ArtifactReview[]): string;
|
|
44
|
+
/** Read the reviews back from `formatReviews` text, as a host's resume carries it. */
|
|
45
|
+
export declare function parseReviews(text: string): ArtifactReview[];
|
|
46
|
+
/** One item of a pause/resume host's interrupt: what the reviewer is shown, so the host needs no file access. */
|
|
47
|
+
export interface ReviewInterruptItem {
|
|
48
|
+
path: string;
|
|
49
|
+
label: string;
|
|
50
|
+
section?: string;
|
|
51
|
+
/** The file as the review shows it (`reviewSource`). */
|
|
52
|
+
content: string;
|
|
53
|
+
/** sha256 of the whole file on disk when asked; null when it doesn't exist. */
|
|
54
|
+
sha256: string | null;
|
|
55
|
+
/** What this session's last answered review of the path showed, when it differs. */
|
|
56
|
+
previous_content?: string;
|
|
57
|
+
/** The content was cut to the interrupt's size cap; the item can be read but not approved. */
|
|
58
|
+
truncated?: true;
|
|
59
|
+
}
|
|
60
|
+
/** The history key for one review scope: a path, and the section of it shown. */
|
|
61
|
+
export declare function reviewScope(path: string, section: string | undefined): string;
|
|
62
|
+
/**
|
|
63
|
+
* The interrupt's items, holding at most `MAX_REVIEW_INTERRUPT_BYTES` of
|
|
64
|
+
* content: every file's current content first, in reading order, then the
|
|
65
|
+
* previous versions that fit whole in what's left. `previous` is keyed by
|
|
66
|
+
* `reviewScope`, so a different section of the same file is never its previous
|
|
67
|
+
* version.
|
|
68
|
+
*/
|
|
69
|
+
export declare function reviewInterruptItems(documents: readonly ShownDocument[], sections: readonly (string | undefined)[], previous: ReadonlyMap<string, string>, budget?: number): ReviewInterruptItem[];
|
|
70
|
+
/**
|
|
71
|
+
* A tab's name: an id at the start of the label ("C1" from "C1: four
|
|
72
|
+
* questions"), else at the start of the file's name ("C1-1" from
|
|
73
|
+
* `outputs/C1-1-transcript.md`), else the file's name when short (`DESIGN`),
|
|
74
|
+
* else the tab's number.
|
|
75
|
+
*/
|
|
76
|
+
export declare function tabName(label: string, path: string, index: number): string;
|
|
77
|
+
/** One line of a diff between what the reviewer saw last time and now. */
|
|
78
|
+
export interface DiffLine {
|
|
79
|
+
kind: "same" | "added" | "removed";
|
|
80
|
+
text: string;
|
|
81
|
+
}
|
|
82
|
+
/** The most cells the changed middle's table may hold before the diff falls back. */
|
|
83
|
+
export declare const LINE_DIFF_MAX_CELLS = 1000000;
|
|
84
|
+
/**
|
|
85
|
+
* A line diff of a file's previous review (`previous_content`) against now:
|
|
86
|
+
* the common prefix and suffix are kept as they are, and the changed middle
|
|
87
|
+
* is diffed by longest common subsequence. A middle whose table would exceed
|
|
88
|
+
* `LINE_DIFF_MAX_CELLS` reads as removed and then added, so memory stays
|
|
89
|
+
* bounded whatever the input.
|
|
90
|
+
*/
|
|
91
|
+
export declare function lineDiff(before: string, after: string): DiffLine[];
|
|
92
|
+
//# sourceMappingURL=review.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../src/review.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,cAAc,EACnB,KAAK,yBAAyB,GAC/B,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAE7D,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,KAAK,CAAC;AASnC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,mBAAmB,GAAG,cAAc,CAAC;AAE/E,2EAA2E;AAC3E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,IAA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AE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM1E;AAED,0EAA0E;AAC1E,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,UAAY,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CAwDlE"}
|
package/dist/review.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The review of the files an agent wrote, as every renderer shares it: the
|
|
3
|
+
* decisions, the answer text a run resumes with, the interrupt a pause/resume
|
|
4
|
+
* host renders, each tab's name and the diff since the last review, plus the
|
|
5
|
+
* interaction wording. Pi's terminal (`./artifact-review-tui.ts`) and a
|
|
6
|
+
* browser host both import it, so it imports nothing from Node, Pi or a
|
|
7
|
+
* renderer; `test/review-core.test.ts` fails if it does.
|
|
8
|
+
*/
|
|
9
|
+
export { DISMISSED_TEXT, formatInteractionOutcome, formatInteractionResume, } from "./interaction-text.js";
|
|
10
|
+
export const REVIEW_ARTIFACTS_TOOL_NAME = "review_artifacts";
|
|
11
|
+
/** At most this many files in one review, so the user can get through it. */
|
|
12
|
+
export const MAX_REVIEW_ITEMS = 20;
|
|
13
|
+
/**
|
|
14
|
+
* At most this many bytes of shown content across one review's interrupt, which
|
|
15
|
+
* a pause/resume host stores with the task. Past it, an item's content is cut
|
|
16
|
+
* and marked `truncated`, and the host must not let it be approved.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_REVIEW_INTERRUPT_BYTES = 256 * 1024;
|
|
19
|
+
/**
|
|
20
|
+
* What the review shows of a file: its front matter folded into one line (the
|
|
21
|
+
* case's check, inputs and approval, not the fields themselves), and with a
|
|
22
|
+
* `section`, only that heading's part.
|
|
23
|
+
*/
|
|
24
|
+
export function reviewSource(source, section) {
|
|
25
|
+
let text = source;
|
|
26
|
+
let summary;
|
|
27
|
+
const front = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
|
|
28
|
+
if (front) {
|
|
29
|
+
text = text.slice(front[0].length);
|
|
30
|
+
const field = (name) => new RegExp(`^${name}:[ \\t]*(.*)$`, "m").exec(front[1])?.[1]?.trim();
|
|
31
|
+
const inputs = [...front[1].matchAll(/^\s*-\s*name:\s*(.+)$/gm)].map((m) => m[1].trim());
|
|
32
|
+
const by = field("approved_by");
|
|
33
|
+
const parts = [
|
|
34
|
+
field("check") ? `check: ${field("check")}` : undefined,
|
|
35
|
+
inputs.length ? `inputs: ${inputs.join(", ")}` : undefined,
|
|
36
|
+
by
|
|
37
|
+
? `approved by ${by}${field("approved_at") ? ` on ${field("approved_at")}` : ""}`
|
|
38
|
+
: "not yet approved",
|
|
39
|
+
].filter(Boolean);
|
|
40
|
+
summary = `_${parts.join(" · ")}_`;
|
|
41
|
+
}
|
|
42
|
+
if (section?.trim()) {
|
|
43
|
+
const lines = text.split("\n");
|
|
44
|
+
const wanted = section.trim().toLowerCase();
|
|
45
|
+
// A `#` line inside a fenced code block isn't a heading.
|
|
46
|
+
let fenced = false;
|
|
47
|
+
const levels = lines.map((line) => {
|
|
48
|
+
if (/^\s*(```|~~~)/.test(line))
|
|
49
|
+
fenced = !fenced;
|
|
50
|
+
return !fenced && /^#{1,6}\s/.test(line)
|
|
51
|
+
? /^#+/.exec(line)[0].length
|
|
52
|
+
: 0;
|
|
53
|
+
});
|
|
54
|
+
const heading = (line) => line
|
|
55
|
+
.replace(/^#+\s*/, "")
|
|
56
|
+
.replace(/\s+#*\s*$/, "")
|
|
57
|
+
.trim()
|
|
58
|
+
.toLowerCase();
|
|
59
|
+
// An exact heading first, so "Part A" isn't taken from "Part A overview" above it.
|
|
60
|
+
const exact = lines.findIndex((line, i) => levels[i] > 0 && heading(line) === wanted);
|
|
61
|
+
const start = exact >= 0
|
|
62
|
+
? exact
|
|
63
|
+
: lines.findIndex((line, i) => levels[i] > 0 && heading(line).includes(wanted));
|
|
64
|
+
if (start >= 0) {
|
|
65
|
+
let end = lines.length;
|
|
66
|
+
for (let i = start + 1; i < lines.length; i += 1) {
|
|
67
|
+
if (levels[i] > 0 && levels[i] <= levels[start]) {
|
|
68
|
+
end = i;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
text = lines.slice(start, end).join("\n");
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
text = `_No heading "${section.trim()}" in this file, so all of it is shown._\n\n${text}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return summary ? `${summary}\n\n${text}` : text;
|
|
79
|
+
}
|
|
80
|
+
const DECISION_TEXT = {
|
|
81
|
+
approved: "approved",
|
|
82
|
+
changes_requested: "changes requested",
|
|
83
|
+
not_reviewed: "not reviewed",
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The answer text the model receives, one line per file after a tally. A
|
|
87
|
+
* pause/resume host resumes with this same text as `{ answer }`.
|
|
88
|
+
*/
|
|
89
|
+
export function formatReviews(reviews) {
|
|
90
|
+
const count = (decision) => reviews.filter((r) => r.decision === decision).length;
|
|
91
|
+
const lines = [
|
|
92
|
+
`Reviewed ${reviews.length} file${reviews.length === 1 ? "" : "s"}: ${count("approved")} approved, ${count("changes_requested")} with changes requested, ${count("not_reviewed")} not reviewed.`,
|
|
93
|
+
];
|
|
94
|
+
for (const review of reviews) {
|
|
95
|
+
// One line per file: the answer is parsed line by line, so a comment's own newlines are folded.
|
|
96
|
+
const text = review.comment?.replace(/\s+/g, " ").trim();
|
|
97
|
+
const comment = text ? ` — "${text}"` : "";
|
|
98
|
+
const unopened = review.opened ? "" : " (not opened)";
|
|
99
|
+
lines.push(`${review.path}: ${DECISION_TEXT[review.decision]}${unopened}${comment}`);
|
|
100
|
+
}
|
|
101
|
+
return lines.join("\n");
|
|
102
|
+
}
|
|
103
|
+
/** Read the reviews back from `formatReviews` text, as a host's resume carries it. */
|
|
104
|
+
export function parseReviews(text) {
|
|
105
|
+
const reviews = [];
|
|
106
|
+
for (const line of text.split("\n").slice(1)) {
|
|
107
|
+
const match = /^(.+?): (approved|changes requested|not reviewed)( \(not opened\))?(?: — "(.*)")?$/.exec(line);
|
|
108
|
+
if (!match)
|
|
109
|
+
continue;
|
|
110
|
+
const decision = Object.keys(DECISION_TEXT).find((d) => DECISION_TEXT[d] === match[2]);
|
|
111
|
+
reviews.push({
|
|
112
|
+
path: match[1],
|
|
113
|
+
decision,
|
|
114
|
+
opened: !match[3],
|
|
115
|
+
...(match[4] ? { comment: match[4] } : {}),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return reviews;
|
|
119
|
+
}
|
|
120
|
+
/** The history key for one review scope: a path, and the section of it shown. */
|
|
121
|
+
export function reviewScope(path, section) {
|
|
122
|
+
return `${path}\u0000${section ?? ""}`;
|
|
123
|
+
}
|
|
124
|
+
const encoder = new TextEncoder();
|
|
125
|
+
const decoder = new TextDecoder();
|
|
126
|
+
/**
|
|
127
|
+
* The interrupt's items, holding at most `MAX_REVIEW_INTERRUPT_BYTES` of
|
|
128
|
+
* content: every file's current content first, in reading order, then the
|
|
129
|
+
* previous versions that fit whole in what's left. `previous` is keyed by
|
|
130
|
+
* `reviewScope`, so a different section of the same file is never its previous
|
|
131
|
+
* version.
|
|
132
|
+
*/
|
|
133
|
+
export function reviewInterruptItems(documents, sections, previous, budget = MAX_REVIEW_INTERRUPT_BYTES) {
|
|
134
|
+
let left = budget;
|
|
135
|
+
const take = (text) => {
|
|
136
|
+
const bytes = encoder.encode(text);
|
|
137
|
+
if (bytes.length <= left) {
|
|
138
|
+
left -= bytes.length;
|
|
139
|
+
return { text, cut: false };
|
|
140
|
+
}
|
|
141
|
+
const kept = bytes.subarray(0, Math.max(left, 0));
|
|
142
|
+
left = 0;
|
|
143
|
+
// A cut can split a multi-byte character; drop the partial one.
|
|
144
|
+
return { text: decoder.decode(kept).replace(/�$/, ""), cut: true };
|
|
145
|
+
};
|
|
146
|
+
const shown = documents.map((doc) => take(doc.content));
|
|
147
|
+
return documents.map((doc, index) => {
|
|
148
|
+
const section = sections[index];
|
|
149
|
+
const before = previous.get(reviewScope(doc.path, section));
|
|
150
|
+
// A previous version is only worth sending whole, and only in the space the current files left.
|
|
151
|
+
const prior = before !== undefined &&
|
|
152
|
+
before !== doc.content &&
|
|
153
|
+
!shown[index].cut &&
|
|
154
|
+
encoder.encode(before).length <= left
|
|
155
|
+
? take(before)
|
|
156
|
+
: undefined;
|
|
157
|
+
return {
|
|
158
|
+
path: doc.path,
|
|
159
|
+
label: doc.label,
|
|
160
|
+
...(section ? { section } : {}),
|
|
161
|
+
content: shown[index].text,
|
|
162
|
+
sha256: doc.sha256,
|
|
163
|
+
...(prior && !prior.cut ? { previous_content: prior.text } : {}),
|
|
164
|
+
...(shown[index].cut ? { truncated: true } : {}),
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/** A case-like id at the start of a name: `C1`, `C1-1`, `C4/C5`. */
|
|
169
|
+
const TAB_ID = /^([A-Za-z]{1,3}\d+(?:[-/][A-Za-z]{0,3}\d+)*)(?![A-Za-z0-9])/;
|
|
170
|
+
/**
|
|
171
|
+
* A tab's name: an id at the start of the label ("C1" from "C1: four
|
|
172
|
+
* questions"), else at the start of the file's name ("C1-1" from
|
|
173
|
+
* `outputs/C1-1-transcript.md`), else the file's name when short (`DESIGN`),
|
|
174
|
+
* else the tab's number.
|
|
175
|
+
*/
|
|
176
|
+
export function tabName(label, path, index) {
|
|
177
|
+
const name = path.replace(/\/+$/, "").split("/").pop() ?? "";
|
|
178
|
+
const stem = name.replace(/\.[^.]*$/, "");
|
|
179
|
+
const id = TAB_ID.exec(label.trim())?.[1] ?? TAB_ID.exec(stem)?.[1];
|
|
180
|
+
if (id)
|
|
181
|
+
return id;
|
|
182
|
+
return stem.length > 0 && stem.length <= 12 ? stem : String(index + 1);
|
|
183
|
+
}
|
|
184
|
+
/** The most cells the changed middle's table may hold before the diff falls back. */
|
|
185
|
+
export const LINE_DIFF_MAX_CELLS = 1_000_000;
|
|
186
|
+
/**
|
|
187
|
+
* A line diff of a file's previous review (`previous_content`) against now:
|
|
188
|
+
* the common prefix and suffix are kept as they are, and the changed middle
|
|
189
|
+
* is diffed by longest common subsequence. A middle whose table would exceed
|
|
190
|
+
* `LINE_DIFF_MAX_CELLS` reads as removed and then added, so memory stays
|
|
191
|
+
* bounded whatever the input.
|
|
192
|
+
*/
|
|
193
|
+
export function lineDiff(before, after) {
|
|
194
|
+
const a = before.split("\n");
|
|
195
|
+
const b = after.split("\n");
|
|
196
|
+
let start = 0;
|
|
197
|
+
while (start < a.length && start < b.length && a[start] === b[start])
|
|
198
|
+
start += 1;
|
|
199
|
+
let endA = a.length;
|
|
200
|
+
let endB = b.length;
|
|
201
|
+
while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
|
|
202
|
+
endA -= 1;
|
|
203
|
+
endB -= 1;
|
|
204
|
+
}
|
|
205
|
+
const lines = a
|
|
206
|
+
.slice(0, start)
|
|
207
|
+
.map((text) => ({ kind: "same", text }));
|
|
208
|
+
const midA = a.slice(start, endA);
|
|
209
|
+
const midB = b.slice(start, endB);
|
|
210
|
+
const width = midB.length + 1;
|
|
211
|
+
if ((midA.length + 1) * width > LINE_DIFF_MAX_CELLS) {
|
|
212
|
+
for (const text of midA)
|
|
213
|
+
lines.push({ kind: "removed", text });
|
|
214
|
+
for (const text of midB)
|
|
215
|
+
lines.push({ kind: "added", text });
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const lengths = new Uint32Array((midA.length + 1) * width);
|
|
219
|
+
for (let i = midA.length - 1; i >= 0; i -= 1) {
|
|
220
|
+
for (let j = midB.length - 1; j >= 0; j -= 1) {
|
|
221
|
+
lengths[i * width + j] =
|
|
222
|
+
midA[i] === midB[j]
|
|
223
|
+
? lengths[(i + 1) * width + j + 1] + 1
|
|
224
|
+
: Math.max(lengths[(i + 1) * width + j], lengths[i * width + j + 1]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
let i = 0;
|
|
228
|
+
let j = 0;
|
|
229
|
+
while (i < midA.length && j < midB.length) {
|
|
230
|
+
if (midA[i] === midB[j]) {
|
|
231
|
+
lines.push({ kind: "same", text: midA[i] });
|
|
232
|
+
i += 1;
|
|
233
|
+
j += 1;
|
|
234
|
+
}
|
|
235
|
+
else if (lengths[(i + 1) * width + j] >= lengths[i * width + j + 1]) {
|
|
236
|
+
lines.push({ kind: "removed", text: midA[i] });
|
|
237
|
+
i += 1;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
lines.push({ kind: "added", text: midB[j] });
|
|
241
|
+
j += 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
for (; i < midA.length; i += 1)
|
|
245
|
+
lines.push({ kind: "removed", text: midA[i] });
|
|
246
|
+
for (; j < midB.length; j += 1)
|
|
247
|
+
lines.push({ kind: "added", text: midB[j] });
|
|
248
|
+
}
|
|
249
|
+
for (const text of a.slice(endA))
|
|
250
|
+
lines.push({ kind: "same", text });
|
|
251
|
+
return lines;
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.js","sourceRoot":"","sources":["../src/review.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,uBAAuB,GAGxB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAE7D,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;;;GAIG;AACH,MAAM,0BAA0B,GAAG,GAAG,GAAG,IAAI,CAAC;AA0B9C;;;;GAIG;AACH,MAAM,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AO,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAE,EAAE,CAAC;gBACxE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC;gBAChD,CAAC,IAAI,CAAC,CAAC;YACT,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC;gBAC9C,CAAC,IAAI,CAAC,CAAC;YACT,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/docs/interactions.md
CHANGED
|
@@ -171,7 +171,13 @@ something else.
|
|
|
171
171
|
Resume payloads are `{ answer }` for single-answer questions,
|
|
172
172
|
`{ answers: string[] }` for multi-select questions, and
|
|
173
173
|
`{ approved, feedback? }` for confirmations. A decline is a resume with
|
|
174
|
-
status `cancelled` and **no payload**.
|
|
174
|
+
status `cancelled` and **no payload**. A resume with status `cancelled` and
|
|
175
|
+
`{ dismissed: true }` means the user dismissed the question to reply in the
|
|
176
|
+
chat: the model is told to stop and wait for their message rather than
|
|
177
|
+
proceed. `formatInteractionResume` and `formatInteractionOutcome` are
|
|
178
|
+
importable without Node or Pi from `@introspection-ai/recipes/review`, with
|
|
179
|
+
the `review_artifacts` answer format (`formatReviews`, `parseReviews`), so a
|
|
180
|
+
browser host renders the same bytes as Pi's terminal. Any host-specific pause/resume state
|
|
175
181
|
should be generated by the host from this request, not authored inside a
|
|
176
182
|
Recipe.
|
|
177
183
|
|
package/docs/pi-extension.md
CHANGED
|
@@ -202,6 +202,9 @@ then a comment (required for changes); on a pause/resume host it pauses with
|
|
|
202
202
|
the host to render its own review, and resumes with `{ answer }` in the format
|
|
203
203
|
below; headless runs and child agents decline, so nothing is approved without a
|
|
204
204
|
person.
|
|
205
|
+
`@introspection-ai/recipes/review` exports what a host needs to render it the
|
|
206
|
+
way the terminal does (`formatReviews`, `parseReviews`, `tabName`, `lineDiff`
|
|
207
|
+
for the changes since `previous_content`), with no Node or Pi imports.
|
|
205
208
|
|
|
206
209
|
Each item carries what the reviewer is shown, so the host needs no access to
|
|
207
210
|
the files:
|
package/docs/recipe-format.md
CHANGED
|
@@ -726,6 +726,7 @@ A case file is YAML front matter, then a body. The front matter:
|
|
|
726
726
|
| `inputs` | A list of `{ name, sha256, location }`: each input by its hash and where it came from. The case file never holds an input; the implementation carries the copy it runs on, such as a Harbor task's `environment/`. |
|
|
727
727
|
| `sources` | What the agent must reach for this case, such as `[documents]`. |
|
|
728
728
|
| `approved_by`, `approved_at`, `approved_in` | Who approved the case, when, and in which message. All empty means a draft. |
|
|
729
|
+
| `approved_hash` | Optional: `sha256:<hex>` of the body when the case was approved, written by `introspection eval approve <id>`. An edited body no longer matches, so the case is unapproved until the owner approves it again. |
|
|
729
730
|
| `conversation` | Optional: `{ id, task_id, turn }` of the real conversation the case came from, `task_id` only when it ran as a platform task. Provenance only: a run never fetches it. |
|
|
730
731
|
| `issue` | Optional: the UUID of the issue recording the hypothesis the case tests. |
|
|
731
732
|
|
|
@@ -734,6 +735,23 @@ convention the body has the sections Situation, A good result and A bad
|
|
|
734
735
|
result, and optionally Verification. `evals/cases/inputs/` holds only
|
|
735
736
|
synthetic inputs; real inputs stay where `location` says.
|
|
736
737
|
|
|
738
|
+
`approved_hash` covers the body, not the front matter, so editing a
|
|
739
|
+
front-matter field (the approval fields included) keeps the approval. It is
|
|
740
|
+
`sha256:` followed by the lowercase hexadecimal SHA-256 of the UTF-8 body,
|
|
741
|
+
computed as follows:
|
|
742
|
+
|
|
743
|
+
1. The body is everything after the line that closes the front matter.
|
|
744
|
+
2. Each CRLF becomes LF.
|
|
745
|
+
3. Trailing whitespace is removed from every line.
|
|
746
|
+
4. Trailing whitespace at the end of the body is removed.
|
|
747
|
+
|
|
748
|
+
Line endings and stray trailing spaces therefore never unapprove a case. The
|
|
749
|
+
`introspection-recipe-check` crate exports this algorithm as
|
|
750
|
+
`spec::case_approval_hash(body: &str) -> String`, with `spec::eval_case_body`
|
|
751
|
+
to take the body out of a case file. A case with all three approval fields
|
|
752
|
+
and no `approved_hash` stays approved: cases approved before the hash existed
|
|
753
|
+
keep their approval.
|
|
754
|
+
|
|
737
755
|
```markdown
|
|
738
756
|
---
|
|
739
757
|
id: C3
|
|
@@ -805,9 +823,9 @@ eval paths, and the links between cases and implementations, all as warnings:
|
|
|
805
823
|
| --- | --- |
|
|
806
824
|
| `pi.evals_case_unknown` | A Vitest row or Harbor task names a case with no case file. |
|
|
807
825
|
| `pi.evals_case_duplicate` | A case has more than one implementation on one runner. |
|
|
808
|
-
| `pi.evals_case_unapproved` | A case with an implementation has an empty approval field. It stays a warning: a draft case is how one is proposed, and the owner approves it in review. |
|
|
826
|
+
| `pi.evals_case_unapproved` | A case with an implementation has an empty approval field, or a body that no longer matches its `approved_hash`; `introspection eval approve <id>` approves it again. It stays a warning: a draft case is how one is proposed, and the owner approves it in review. |
|
|
809
827
|
| `pi.evals_case_row_missing_id` | A `.eval.jsonl` row has no `case`. |
|
|
810
|
-
| `pi.evals_case_invalid` | A case file has no readable front matter, an `id` other than its file name,
|
|
828
|
+
| `pi.evals_case_invalid` | A case file has no readable front matter, an `id` other than its file name, an `issue` that is not a UUID, or an `approved_hash` that is not `sha256:` and 64 hexadecimal digits. |
|
|
811
829
|
|
|
812
830
|
## Conformance
|
|
813
831
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@introspection-ai/recipes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "The open format for vertical agents, built on Pi.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./dist/interactions.d.ts",
|
|
36
36
|
"import": "./dist/interactions.js"
|
|
37
37
|
},
|
|
38
|
+
"./review": {
|
|
39
|
+
"types": "./dist/review.d.ts",
|
|
40
|
+
"import": "./dist/review.js"
|
|
41
|
+
},
|
|
38
42
|
"./extensions": {
|
|
39
43
|
"types": "./dist/api/extensions.d.ts",
|
|
40
44
|
"import": "./dist/api/extensions.js"
|
|
@@ -106,10 +110,10 @@
|
|
|
106
110
|
"@introspection-ai/recipe-channel-slack": ">=0.6.0",
|
|
107
111
|
"@introspection-ai/recipe-documents-docx": ">=0.3.0",
|
|
108
112
|
"@introspection-ai/recipe-documents-pdf": ">=0.2.0",
|
|
109
|
-
"@introspection-ai/mcp-client-linux-x64": "0.
|
|
110
|
-
"@introspection-ai/mcp-client-linux-arm64": "0.
|
|
111
|
-
"@introspection-ai/mcp-client-darwin-arm64": "0.
|
|
112
|
-
"@introspection-ai/mcp-client-darwin-x64": "0.
|
|
113
|
+
"@introspection-ai/mcp-client-linux-x64": "0.46.0",
|
|
114
|
+
"@introspection-ai/mcp-client-linux-arm64": "0.46.0",
|
|
115
|
+
"@introspection-ai/mcp-client-darwin-arm64": "0.46.0",
|
|
116
|
+
"@introspection-ai/mcp-client-darwin-x64": "0.46.0"
|
|
113
117
|
},
|
|
114
118
|
"peerDependencies": {
|
|
115
119
|
"@earendil-works/pi-agent-core": ">=1.1.0 <2.0.0",
|
|
@@ -141,14 +145,15 @@
|
|
|
141
145
|
"scripts": {
|
|
142
146
|
"build": "pnpm build:ts && pnpm build:native",
|
|
143
147
|
"build:workspace-packages": "pnpm --filter './packages/**' build",
|
|
144
|
-
"build:ts": "rm -rf dist && tsc && node scripts/build-mcp-daemon.mjs && pnpm build:workspace-packages",
|
|
148
|
+
"build:ts": "rm -rf dist && pnpm manifest && tsc && node scripts/build-mcp-daemon.mjs && pnpm build:workspace-packages",
|
|
145
149
|
"build:native": "cargo build --release -p pi-mcp-client && node scripts/package-mcp-client.mjs",
|
|
146
150
|
"bench:mcp-client": "pnpm build:ts && cargo build --release -p pi-mcp-client && node scripts/benchmark-mcp-client.mjs",
|
|
147
|
-
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json && pnpm --filter './packages/**' --filter './examples/**' typecheck",
|
|
148
|
-
"lint": "eslint . --max-warnings 0",
|
|
151
|
+
"typecheck": "pnpm manifest && tsc --noEmit && tsc --noEmit -p tsconfig.test.json && pnpm --filter './packages/**' --filter './examples/**' typecheck",
|
|
152
|
+
"lint": "pnpm manifest && eslint . --max-warnings 0",
|
|
153
|
+
"manifest": "node scripts/write-manifest.mjs",
|
|
149
154
|
"format": "prettier --write \"{src,test,packages,examples}/**/*.{ts,mjs,md}\" \"*.{ts,mjs}\"",
|
|
150
155
|
"format:check": "prettier --check \"{src,test,packages,examples}/**/*.{ts,mjs,md}\" \"*.{ts,mjs}\"",
|
|
151
|
-
"knip": "knip",
|
|
156
|
+
"knip": "pnpm manifest && knip",
|
|
152
157
|
"test": "pnpm build:ts && cargo test -p pi-mcp-client -p introspection-recipe-check && cargo build -p pi-mcp-client && MCP_CLIENT_BIN=target/debug/mcp-client node scripts/package-mcp-client.mjs && vitest run && pnpm --filter './examples/**' test",
|
|
153
158
|
"pack:check": "pnpm pack --dry-run --json | node scripts/check-npm-pack.mjs && pnpm --filter './packages/**' pack:check",
|
|
154
159
|
"clean": "rm -rf dist .turbo node_modules target vendor/mcp-client"
|
|
File without changes
|