@cortexkit/aft-opencode 0.15.4 → 0.15.5

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/index.js CHANGED
@@ -24048,44 +24048,156 @@ function buildUnifiedDiff(fp, before, after) {
24048
24048
  `);
24049
24049
  const afterLines = after.split(`
24050
24050
  `);
24051
- let diff = `Index: ${fp}
24051
+ const ops = diffLines(beforeLines, afterLines);
24052
+ if (ops.every((op) => op.tag === "eq")) {
24053
+ return `Index: ${fp}
24052
24054
  ===================================================================
24053
24055
  --- ${fp}
24054
24056
  +++ ${fp}
24055
24057
  `;
24056
- let firstChange = -1;
24057
- let lastChange = -1;
24058
- const maxLen = Math.max(beforeLines.length, afterLines.length);
24059
- for (let i = 0;i < maxLen; i++) {
24060
- if ((beforeLines[i] ?? "") !== (afterLines[i] ?? "")) {
24061
- if (firstChange === -1)
24062
- firstChange = i;
24063
- lastChange = i;
24064
- }
24065
- }
24066
- if (firstChange === -1)
24067
- return diff;
24068
- const ctxStart = Math.max(0, firstChange - 2);
24069
- const ctxEnd = Math.min(maxLen - 1, lastChange + 2);
24070
- diff += `@@ -${ctxStart + 1},${Math.min(beforeLines.length, ctxEnd + 1) - ctxStart} +${ctxStart + 1},${Math.min(afterLines.length, ctxEnd + 1) - ctxStart} @@
24071
- `;
24072
- for (let i = ctxStart;i <= ctxEnd; i++) {
24073
- const bl = i < beforeLines.length ? beforeLines[i] : undefined;
24074
- const al = i < afterLines.length ? afterLines[i] : undefined;
24075
- if (bl === al) {
24076
- diff += ` ${bl}
24058
+ }
24059
+ const CONTEXT = 3;
24060
+ const HUNK_GAP = CONTEXT * 2;
24061
+ const hunks = groupIntoHunks(ops, CONTEXT, HUNK_GAP, beforeLines.length, afterLines.length);
24062
+ let diff = `Index: ${fp}
24063
+ ===================================================================
24064
+ --- ${fp}
24065
+ +++ ${fp}
24077
24066
  `;
24078
- } else {
24079
- if (bl !== undefined)
24080
- diff += `-${bl}
24067
+ for (const hunk of hunks) {
24068
+ diff += `@@ -${hunk.beforeStart},${hunk.beforeCount} +${hunk.afterStart},${hunk.afterCount} @@
24081
24069
  `;
24082
- if (al !== undefined)
24083
- diff += `+${al}
24070
+ for (const line of hunk.lines) {
24071
+ diff += `${line}
24084
24072
  `;
24085
24073
  }
24086
24074
  }
24087
24075
  return diff;
24088
24076
  }
24077
+ function diffLines(a, b) {
24078
+ const n = a.length;
24079
+ const m = b.length;
24080
+ const dp = new Uint32Array((n + 1) * (m + 1));
24081
+ const w = m + 1;
24082
+ for (let i2 = 1;i2 <= n; i2++) {
24083
+ for (let j2 = 1;j2 <= m; j2++) {
24084
+ if (a[i2 - 1] === b[j2 - 1]) {
24085
+ dp[i2 * w + j2] = dp[(i2 - 1) * w + (j2 - 1)] + 1;
24086
+ } else {
24087
+ const up = dp[(i2 - 1) * w + j2];
24088
+ const left = dp[i2 * w + (j2 - 1)];
24089
+ dp[i2 * w + j2] = up >= left ? up : left;
24090
+ }
24091
+ }
24092
+ }
24093
+ const ops = [];
24094
+ let i = n;
24095
+ let j = m;
24096
+ while (i > 0 && j > 0) {
24097
+ if (a[i - 1] === b[j - 1]) {
24098
+ ops.push({ tag: "eq", beforeIdx: i - 1, afterIdx: j - 1, line: a[i - 1] });
24099
+ i--;
24100
+ j--;
24101
+ } else if (dp[(i - 1) * w + j] >= dp[i * w + (j - 1)]) {
24102
+ ops.push({ tag: "del", beforeIdx: i - 1, line: a[i - 1] });
24103
+ i--;
24104
+ } else {
24105
+ ops.push({ tag: "ins", afterIdx: j - 1, line: b[j - 1] });
24106
+ j--;
24107
+ }
24108
+ }
24109
+ while (i > 0) {
24110
+ ops.push({ tag: "del", beforeIdx: i - 1, line: a[i - 1] });
24111
+ i--;
24112
+ }
24113
+ while (j > 0) {
24114
+ ops.push({ tag: "ins", afterIdx: j - 1, line: b[j - 1] });
24115
+ j--;
24116
+ }
24117
+ ops.reverse();
24118
+ return ops;
24119
+ }
24120
+ function groupIntoHunks(ops, context, gap, beforeLen, afterLen) {
24121
+ const changeIdx = [];
24122
+ for (let k = 0;k < ops.length; k++) {
24123
+ if (ops[k].tag !== "eq")
24124
+ changeIdx.push(k);
24125
+ }
24126
+ if (changeIdx.length === 0)
24127
+ return [];
24128
+ const ranges = [];
24129
+ for (const idx of changeIdx) {
24130
+ const start = Math.max(0, idx - context);
24131
+ const end = Math.min(ops.length - 1, idx + context);
24132
+ if (ranges.length > 0 && start <= ranges[ranges.length - 1][1] + gap) {
24133
+ ranges[ranges.length - 1][1] = Math.max(ranges[ranges.length - 1][1], end);
24134
+ } else {
24135
+ ranges.push([start, end]);
24136
+ }
24137
+ }
24138
+ const hunks = [];
24139
+ for (const [start, end] of ranges) {
24140
+ let beforeStart = -1;
24141
+ let afterStart = -1;
24142
+ let beforeCount = 0;
24143
+ let afterCount = 0;
24144
+ const lines = [];
24145
+ for (let k = start;k <= end; k++) {
24146
+ const op = ops[k];
24147
+ if (op.tag === "eq") {
24148
+ if (beforeStart === -1)
24149
+ beforeStart = op.beforeIdx + 1;
24150
+ if (afterStart === -1)
24151
+ afterStart = op.afterIdx + 1;
24152
+ beforeCount++;
24153
+ afterCount++;
24154
+ lines.push(` ${op.line}`);
24155
+ } else if (op.tag === "del") {
24156
+ if (beforeStart === -1)
24157
+ beforeStart = op.beforeIdx + 1;
24158
+ if (afterStart === -1) {
24159
+ afterStart = inferAfterStart(ops, k, afterLen);
24160
+ }
24161
+ beforeCount++;
24162
+ lines.push(`-${op.line}`);
24163
+ } else {
24164
+ if (afterStart === -1)
24165
+ afterStart = op.afterIdx + 1;
24166
+ if (beforeStart === -1) {
24167
+ beforeStart = inferBeforeStart(ops, k, beforeLen);
24168
+ }
24169
+ afterCount++;
24170
+ lines.push(`+${op.line}`);
24171
+ }
24172
+ }
24173
+ if (beforeCount === 0)
24174
+ beforeStart = 0;
24175
+ if (afterCount === 0)
24176
+ afterStart = 0;
24177
+ hunks.push({ beforeStart, beforeCount, afterStart, afterCount, lines });
24178
+ }
24179
+ return hunks;
24180
+ }
24181
+ function inferAfterStart(ops, from, afterLen) {
24182
+ for (let k = from;k < ops.length; k++) {
24183
+ const op = ops[k];
24184
+ if (op.tag === "eq")
24185
+ return op.afterIdx + 1;
24186
+ if (op.tag === "ins")
24187
+ return op.afterIdx + 1;
24188
+ }
24189
+ return afterLen;
24190
+ }
24191
+ function inferBeforeStart(ops, from, beforeLen) {
24192
+ for (let k = from;k < ops.length; k++) {
24193
+ const op = ops[k];
24194
+ if (op.tag === "eq")
24195
+ return op.beforeIdx + 1;
24196
+ if (op.tag === "del")
24197
+ return op.beforeIdx + 1;
24198
+ }
24199
+ return beforeLen;
24200
+ }
24089
24201
  var z3 = tool3.schema;
24090
24202
  var READ_DESCRIPTION = `Read file contents or list directory entries.
24091
24203
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Test-only re-exports of internal helpers from hoisted.ts.
3
+ *
4
+ * Kept in a separate file so the production import surface of hoisted.ts
5
+ * stays focused. Bun's test runner imports this directly; the bundled
6
+ * plugin output never references this module.
7
+ */
8
+ export { _buildUnifiedDiffForTest } from "./hoisted.js";
9
+ //# sourceMappingURL=hoisted-internals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hoisted-internals.d.ts","sourceRoot":"","sources":["../../src/tools/hoisted-internals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC"}
@@ -10,6 +10,8 @@
10
10
  */
11
11
  import type { ToolDefinition } from "@opencode-ai/plugin";
12
12
  import type { PluginContext } from "../types.js";
13
+ /** Test-only export. Production code uses buildUnifiedDiff directly. */
14
+ export declare const _buildUnifiedDiffForTest: (fp: string, before: string, after: string) => string;
13
15
  /**
14
16
  * Creates the simple read tool. Registers as "read" when hoisted, "aft_read" when not.
15
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"hoisted.d.ts","sourceRoot":"","sources":["../../src/tools/hoisted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA6EjD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CA4IjE;AAkxBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAS/E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAuBnF"}
1
+ {"version":3,"file":"hoisted.d.ts","sourceRoot":"","sources":["../../src/tools/hoisted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAcjD,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,GAAI,IAAI,MAAM,EAAE,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MAChD,CAAC;AA2OtC;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CA4IjE;AAkxBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAS/E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAuBnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/aft-opencode",
3
- "version": "0.15.4",
3
+ "version": "0.15.5",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Agent File Tools (AFT) — tree-sitter and lsp powered code analysis",
6
6
  "main": "dist/index.js",
@@ -32,11 +32,11 @@
32
32
  "zod": "^4.1.8"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@cortexkit/aft-darwin-arm64": "0.15.4",
36
- "@cortexkit/aft-darwin-x64": "0.15.4",
37
- "@cortexkit/aft-linux-arm64": "0.15.4",
38
- "@cortexkit/aft-linux-x64": "0.15.4",
39
- "@cortexkit/aft-win32-x64": "0.15.4"
35
+ "@cortexkit/aft-darwin-arm64": "0.15.5",
36
+ "@cortexkit/aft-darwin-x64": "0.15.5",
37
+ "@cortexkit/aft-linux-arm64": "0.15.5",
38
+ "@cortexkit/aft-linux-x64": "0.15.5",
39
+ "@cortexkit/aft-win32-x64": "0.15.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "^22.0.0",