typebulb 0.21.2 → 0.21.4
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/agents/pi/matchu-patchu.ts +41 -25
- package/dist/index.js +117 -117
- package/package.json +1 -1
|
@@ -2217,7 +2217,7 @@ var Patcher = class _Patcher {
|
|
|
2217
2217
|
|
|
2218
2218
|
// cli/agents/pi/server/piPatcherExtension.ts
|
|
2219
2219
|
var DESCRIPTION = true ? "Apply unified diffs to files \u2014 tolerant of form, strict about intent. Repairs sloppy AI-generated diffs (mangled headers, whitespace drift, missing prefixes; line numbers can be wrong or absent \u2014 hunks anchor by fuzzy-matched context lines) and applies all hunks atomically when the intent is unambiguous; fails with a precise, typed error when it isn't. Use for multi-hunk edits in one step, or when exact string-replacement editing fails on whitespace or invisible characters." : "Apply unified diffs to files.";
|
|
2220
|
-
var BUILD_TAG = true ? "matchu-patchu-pi 0.2.0, built 2026-07-
|
|
2220
|
+
var BUILD_TAG = true ? "matchu-patchu-pi 0.2.0, built 2026-07-08 16:28:04" : "matchu-patchu-pi dev";
|
|
2221
2221
|
var errorBlocks = (errors) => {
|
|
2222
2222
|
const parts = [`Patch failed with ${errors.length} error(s):`];
|
|
2223
2223
|
for (const e of errors) parts.push("", e.toString());
|
|
@@ -2289,36 +2289,51 @@ function logErr(...a) {
|
|
|
2289
2289
|
} catch {
|
|
2290
2290
|
}
|
|
2291
2291
|
}
|
|
2292
|
+
function patchOwnership(tools, registeredByUs) {
|
|
2293
|
+
const patch = tools.find((t) => t.name === "patch");
|
|
2294
|
+
if (!patch) return "absent";
|
|
2295
|
+
return registeredByUs || /matchu-patchu/i.test(patch.sourceInfo?.path ?? "") ? "ours" : "foreign";
|
|
2296
|
+
}
|
|
2297
|
+
var PATCH_TOOL = {
|
|
2298
|
+
name: "patch",
|
|
2299
|
+
label: "Patch",
|
|
2300
|
+
description: DESCRIPTION,
|
|
2301
|
+
promptSnippet: "Modify one or more existing files by applying a unified diff",
|
|
2302
|
+
promptGuidelines: [
|
|
2303
|
+
"Use patch for every edit to an existing file; write is only for creating new files or full rewrites.",
|
|
2304
|
+
"patch accepts lenient unified diffs: line numbers are optional and hunks anchor by context lines. One diff may target several files via ---/+++ headers; pass filePath instead for a headerless single-file diff."
|
|
2305
|
+
],
|
|
2306
|
+
parameters: Type.Object({
|
|
2307
|
+
diff: Type.String({ description: "Unified diff content to apply" }),
|
|
2308
|
+
filePath: Type.Optional(Type.String({
|
|
2309
|
+
description: "Path of the single file to patch (absolute or relative to the project root); the diff's headers are then ignored. Omit to target the file(s) named by the diff's ---/+++ headers."
|
|
2310
|
+
})),
|
|
2311
|
+
dryRun: Type.Optional(Type.Boolean({ description: "If true, return the patched content without writing to disk" }))
|
|
2312
|
+
}),
|
|
2313
|
+
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
2314
|
+
const { ok, message } = applyPatch(ctx.cwd, params);
|
|
2315
|
+
if (!ok) throw new Error(message);
|
|
2316
|
+
return { content: [{ type: "text", text: message }], details: {} };
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2292
2319
|
function piPatcherExtension_default(pi) {
|
|
2320
|
+
let registeredPatch = false;
|
|
2293
2321
|
try {
|
|
2294
|
-
pi.registerTool({
|
|
2295
|
-
name: "patch",
|
|
2296
|
-
label: "Patch",
|
|
2297
|
-
description: DESCRIPTION,
|
|
2298
|
-
promptSnippet: "Modify one or more existing files by applying a unified diff",
|
|
2299
|
-
promptGuidelines: [
|
|
2300
|
-
"Use patch for every edit to an existing file; write is only for creating new files or full rewrites.",
|
|
2301
|
-
"patch accepts lenient unified diffs: line numbers are optional and hunks anchor by context lines. One diff may target several files via ---/+++ headers; pass filePath instead for a headerless single-file diff."
|
|
2302
|
-
],
|
|
2303
|
-
parameters: Type.Object({
|
|
2304
|
-
diff: Type.String({ description: "Unified diff content to apply" }),
|
|
2305
|
-
filePath: Type.Optional(Type.String({
|
|
2306
|
-
description: "Path of the single file to patch (absolute or relative to the project root); the diff's headers are then ignored. Omit to target the file(s) named by the diff's ---/+++ headers."
|
|
2307
|
-
})),
|
|
2308
|
-
dryRun: Type.Optional(Type.Boolean({ description: "If true, return the patched content without writing to disk" }))
|
|
2309
|
-
}),
|
|
2310
|
-
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
2311
|
-
const { ok, message } = applyPatch(ctx.cwd, params);
|
|
2312
|
-
if (!ok) throw new Error(message);
|
|
2313
|
-
return { content: [{ type: "text", text: message }], details: {} };
|
|
2314
|
-
}
|
|
2315
|
-
});
|
|
2316
2322
|
pi.on("session_start", () => {
|
|
2317
2323
|
try {
|
|
2324
|
+
const owner = patchOwnership(pi.getAllTools(), registeredPatch);
|
|
2325
|
+
if (owner === "foreign") {
|
|
2326
|
+
logErr('another extension already provides "patch" \u2014 typebulb patcher standing down (built-in edit kept)');
|
|
2327
|
+
return;
|
|
2328
|
+
}
|
|
2329
|
+
if (owner === "absent") {
|
|
2330
|
+
pi.registerTool(PATCH_TOOL);
|
|
2331
|
+
registeredPatch = true;
|
|
2332
|
+
}
|
|
2318
2333
|
const active = pi.getActiveTools();
|
|
2319
2334
|
if (active.includes("edit")) pi.setActiveTools(active.filter((n) => n !== "edit"));
|
|
2320
2335
|
} catch (e) {
|
|
2321
|
-
logErr("
|
|
2336
|
+
logErr("session_start", e);
|
|
2322
2337
|
}
|
|
2323
2338
|
});
|
|
2324
2339
|
} catch (e) {
|
|
@@ -2328,5 +2343,6 @@ function piPatcherExtension_default(pi) {
|
|
|
2328
2343
|
export {
|
|
2329
2344
|
applyPatch,
|
|
2330
2345
|
piPatcherExtension_default as default,
|
|
2331
|
-
discoverDiffKeys
|
|
2346
|
+
discoverDiffKeys,
|
|
2347
|
+
patchOwnership
|
|
2332
2348
|
};
|