oh-my-opencode-cohub 1.5.0 → 1.5.2

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.
@@ -1,16 +1,22 @@
1
1
  import type { RelevantFile } from './types';
2
+ /** SDK v2 Part 格式(简化) */
3
+ interface SdkPart {
4
+ type?: string;
5
+ text?: string;
6
+ tool?: string;
7
+ state?: {
8
+ status?: string;
9
+ input?: Record<string, unknown>;
10
+ output?: string;
11
+ error?: string;
12
+ };
13
+ }
2
14
  /** SDK v2 消息格式(简化) */
3
15
  interface SdkMessage {
4
16
  info?: {
5
17
  role?: string;
6
18
  };
7
- parts?: Array<{
8
- type?: string;
9
- text?: string;
10
- tool?: string;
11
- args?: unknown;
12
- tool_result?: unknown;
13
- }>;
19
+ parts?: SdkPart[];
14
20
  }
15
21
  /**
16
22
  * 从消息列表中提取相关文件。
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../src/context/extractor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAuB5C,sBAAsB;AACtB,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACvG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,EAAE,EACtB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,YAAY,EAAE,CAuEhB;AAUD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,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M,EACjB,UAAU,EAAE,MAAM,GACjB,MAAM,EAAE,CAwBV"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=extractor.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractor.test.d.ts","sourceRoot":"","sources":["../../src/context/extractor.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAqIlD,QAAA,MAAM,WAAW,EAAE,MA8ZlB,CAAC;AAEF,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAqIlD,QAAA,MAAM,WAAW,EAAE,MAualB,CAAC;AAEF,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAe,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -770,13 +770,27 @@ function extractRelevantFiles(messages, maxFiles, windowSize) {
770
770
  const fileMap = new Map;
771
771
  for (const msg of recent) {
772
772
  for (const part of msg.parts ?? []) {
773
- if (part.type === "tool_call" && part.args) {
774
- const args = part.args;
775
- const path = extractPath(args);
776
- if (path && !fileMap.has(path)) {
777
- fileMap.set(path, { path, summary: "" });
773
+ if (part.type === "tool" && part.state) {
774
+ const state = part.state;
775
+ const input = state.input ?? {};
776
+ const path = extractPath(input);
777
+ if (path) {
778
+ if (!fileMap.has(path)) {
779
+ fileMap.set(path, { path, summary: "" });
780
+ }
781
+ const existing = fileMap.get(path);
782
+ if (typeof input.offset === "number") {
783
+ const limit = typeof input.limit === "number" ? input.limit : 50;
784
+ existing.lines = `${input.offset}-${input.offset + limit}`;
785
+ }
786
+ if (typeof input.oldString === "string") {
787
+ existing.summary = `编辑: ${input.oldString.slice(0, 80)}`;
788
+ }
789
+ if (state.status === "completed" && typeof state.output === "string" && !existing.summary) {
790
+ existing.summary = state.output.slice(0, 100).replace(/\n/g, " ");
791
+ }
778
792
  }
779
- for (const value of Object.values(args)) {
793
+ for (const value of Object.values(input)) {
780
794
  if (typeof value !== "string")
781
795
  continue;
782
796
  let match;
@@ -792,25 +806,19 @@ function extractRelevantFiles(messages, maxFiles, windowSize) {
792
806
  }
793
807
  }
794
808
  }
795
- }
796
- if (part.type === "tool_result" && part.tool_result) {
797
- const tr = part.tool_result;
798
- const path = extractPath(tr);
799
- if (path && fileMap.has(path)) {
800
- const existing = fileMap.get(path);
801
- const args = tr.args;
802
- if (args) {
803
- if (typeof args.offset === "number") {
804
- const limit = typeof args.limit === "number" ? args.limit : 50;
805
- existing.lines = `${args.offset}-${args.offset + limit}`;
806
- }
807
- if (typeof args.oldString === "string") {
808
- existing.summary = `编辑位置: ${args.oldString.slice(0, 80)}`;
809
+ if (state.status === "completed" && typeof state.output === "string") {
810
+ let match;
811
+ FILE_PATH_RE.lastIndex = 0;
812
+ while ((match = FILE_PATH_RE.exec(state.output)) !== null) {
813
+ const rawPath = match[1];
814
+ const ext = rawPath.split(".").pop()?.toLowerCase();
815
+ if (!ext || !KNOWN_EXTENSIONS.has(ext))
816
+ continue;
817
+ const cleanPath = rawPath.replace(/^`|`$/g, "");
818
+ if (!fileMap.has(cleanPath)) {
819
+ fileMap.set(cleanPath, { path: cleanPath, summary: "" });
809
820
  }
810
821
  }
811
- if (!existing.summary && typeof tr.output === "string") {
812
- existing.summary = tr.output.slice(0, 100).replace(/\n/g, " ");
813
- }
814
822
  }
815
823
  }
816
824
  if (typeof part.text === "string") {
@@ -871,10 +879,10 @@ function extractErrors(messages, maxErrors, windowSize) {
871
879
  const errorPatterns = /(error|Error|TypeError|ReferenceError|SyntaxError|RangeError|FAIL|failed|cannot find|cannot resolve|not found|unexpected token)/;
872
880
  for (const msg of recent) {
873
881
  for (const part of msg.parts ?? []) {
874
- if (part.type !== "tool_result" || !part.tool_result)
882
+ if (part.type !== "tool" || !part.state)
875
883
  continue;
876
- const tr = part.tool_result;
877
- const output = typeof tr.output === "string" ? tr.output : "";
884
+ const state = part.state;
885
+ const output = state.status === "error" ? typeof state.error === "string" ? state.error : "" : typeof state.output === "string" ? state.output : "";
878
886
  if (!output)
879
887
  continue;
880
888
  const lines = output.split(`
@@ -1756,8 +1764,19 @@ var CoHubPlugin = async (input, options) => {
1756
1764
  if (details) {
1757
1765
  output.args[targetField] += details;
1758
1766
  }
1767
+ const logPath = path2.join(os2.tmpdir(), "opencode", "ctx-diag.log");
1768
+ try {
1769
+ const stat = fs2.statSync(logPath);
1770
+ if (stat.size > 50 * 1024) {
1771
+ const lines = fs2.readFileSync(logPath, "utf-8").trim().split(`
1772
+ `);
1773
+ fs2.writeFileSync(logPath, lines.slice(-30).join(`
1774
+ `) + `
1775
+ `);
1776
+ }
1777
+ } catch {}
1759
1778
  const finalPrompt = typeof output.args?.prompt === "string" ? output.args.prompt : "";
1760
- fs2.appendFileSync("C:\\Users\\14023\\AppData\\Local\\Temp\\opencode\\ctx-diag.log", JSON.stringify({
1779
+ fs2.appendFileSync(logPath, JSON.stringify({
1761
1780
  time: new Date().toISOString(),
1762
1781
  session: input2.sessionID?.slice(0, 20) ?? "?",
1763
1782
  subagent: subagentType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-my-opencode-cohub",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Mr-cjf/oh-my-opencode-cohub.git"
@@ -27,6 +27,7 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "build": "bun run scripts/generate-prompts.ts && bun build src/index.ts src/tui.ts --outdir dist --target node --format esm --external @opencode-ai/plugin --external @opencode-ai/plugin/* --external @opencode-ai/sdk --external @opencode-ai/sdk/* --external @opentui/core --external @opentui/solid --external zod && bun build src/cli/index.ts --outdir dist/cli --target node --format esm && tsc --emitDeclarationOnly",
30
+ "test": "bun test",
30
31
  "prepublishOnly": "npm run build"
31
32
  },
32
33
  "keywords": [