@aipanel/dsh-plugin 1.2.18 → 1.2.20

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.
Files changed (2) hide show
  1. package/dist/index.js +73 -12
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -552,6 +552,15 @@ async function runProjectDiagnostics(workspace) {
552
552
  };
553
553
  return { eslintOutput, tscOutput: mergedTsc };
554
554
  }
555
+ function formatDiagnosticsSections(title, eslintOutput, tscOutput) {
556
+ const parts = [];
557
+ parts.push("## ESLint\n\n" + (eslintOutput.text || "\u6CA1\u6709\u53D1\u73B0\u95EE\u9898"));
558
+ const tscLines = tscOutput.rawOutput.trim();
559
+ parts.push("## vue-tsc\n\n" + (tscLines || "\u6CA1\u6709\u53D1\u73B0\u7C7B\u578B\u9519\u8BEF"));
560
+ return `${title}
561
+
562
+ ` + parts.join("\n\n");
563
+ }
555
564
 
556
565
  // ../../core/es/common/utils.mjs
557
566
  var NODE_MENTION_RE = /@节点\[(n[0-9a-z]+)\]/g;
@@ -804,6 +813,47 @@ function buildNodeContext(e) {
804
813
  if (e.previewPageUrl) lines.push(`\u7528\u6237\u9009\u4E2D\u8282\u70B9\u65F6\u7684\u9875\u9762 URL\uFF1A${e.previewPageUrl}`);
805
814
  return lines.join("\n");
806
815
  }
816
+ function buildPluginMessage(text) {
817
+ return {
818
+ role: "user",
819
+ id: randomUUID(),
820
+ content: [{ type: "text", text }],
821
+ source: { kind: "plugin", plugin: name }
822
+ };
823
+ }
824
+ function registerPtcEdit(targets, rootKey, exec2, result, decision, cwd) {
825
+ if (!MUTATING_TOOLS.has(exec2.name)) return;
826
+ if (result.isError) return;
827
+ if (decision.kind !== "accept") return;
828
+ const rawArgs = exec2.arguments;
829
+ const filePath = typeof rawArgs?.file_path === "string" ? rawArgs.file_path : rawArgs?.filePath;
830
+ if (typeof filePath !== "string" || !filePath) return;
831
+ if (!isJsFile(filePath)) return;
832
+ let files = targets.get(rootKey);
833
+ if (!files) {
834
+ files = /* @__PURE__ */ new Set();
835
+ targets.set(rootKey, files);
836
+ }
837
+ files.add(path2.resolve(cwd, filePath));
838
+ }
839
+ async function collectPtcDiagnostics(files, cwd) {
840
+ const blocks = [];
841
+ for (const file of files) {
842
+ const { eslintOutput, tscOutput } = await runAllChecks(file, cwd).catch(
843
+ () => ({
844
+ eslintOutput: {},
845
+ tscOutput: { rawOutput: "", exitCode: 0 }
846
+ })
847
+ );
848
+ if (!eslintOutput.text && !tscOutput.rawOutput.trim()) continue;
849
+ blocks.push(
850
+ formatDiagnosticsSections(`### ${path2.relative(cwd, file)}`, eslintOutput, tscOutput)
851
+ );
852
+ }
853
+ return blocks.length > 0 ? `\u81EA\u52A8\u8BCA\u65AD\uFF08PTC \u6279\u91CF\u7F16\u8F91\u540E\uFF09\uFF1A
854
+
855
+ ${blocks.join("\n\n")}` : "";
856
+ }
807
857
  function toDiagnosticEntries(items) {
808
858
  return items.map((d) => ({
809
859
  file: d.file ?? "",
@@ -981,12 +1031,31 @@ function apply(ctx, config = {}) {
981
1031
  }
982
1032
  };
983
1033
  tools.register(diagnosticsTool);
1034
+ const pendingPtcEdits = /* @__PURE__ */ new Map();
984
1035
  ctx.on(
985
1036
  "tools/post-execute",
986
1037
  async (exec2, result, next) => {
987
1038
  const decision = await next();
988
1039
  if (!autoDiagnose) return decision;
989
- if (exec2.parent !== void 0) return decision;
1040
+ if (exec2.parent !== void 0) {
1041
+ registerPtcEdit(pendingPtcEdits, String(exec2.rootCallId), exec2, result, decision, cwd);
1042
+ return decision;
1043
+ }
1044
+ const rootKey = String(exec2.rootCallId);
1045
+ const ptcTargets = pendingPtcEdits.get(rootKey);
1046
+ if (ptcTargets !== void 0) {
1047
+ pendingPtcEdits.delete(rootKey);
1048
+ if (decision.kind !== "accept") return decision;
1049
+ const ptcDiagText = await collectPtcDiagnostics(ptcTargets, cwd);
1050
+ if (!ptcDiagText) return decision;
1051
+ return {
1052
+ ...decision,
1053
+ additionalContexts: [
1054
+ ...decision.additionalContexts ?? [],
1055
+ buildPluginMessage(ptcDiagText)
1056
+ ]
1057
+ };
1058
+ }
990
1059
  if (!MUTATING_TOOLS.has(exec2.name)) return decision;
991
1060
  if (result.isError) return decision;
992
1061
  if (decision.kind !== "accept") return decision;
@@ -1048,19 +1117,11 @@ ${diagText}` }]
1048
1117
  const injected = [...ids].map((id) => byId.get(id)).filter((el) => el !== void 0);
1049
1118
  if (injected.length === 0) return decision;
1050
1119
  const contextText = injected.map(buildNodeContext).join("\n\n---\n\n");
1051
- const contextMessage = {
1052
- role: "user",
1053
- id: randomUUID(),
1054
- content: [
1055
- {
1056
- type: "text",
1057
- text: `\u4EE5\u4E0B\u662F\u7528\u6237\u5F15\u7528\u8282\u70B9\u7684\u5B8C\u6574\u4E0A\u4E0B\u6587\uFF08\u8282\u70B9 ID \u4E0E\u6D88\u606F\u4E2D\u7684 @\u8282\u70B9[id] \u6807\u8BB0\u5BF9\u5E94\uFF09\uFF1A
1120
+ const contextMessage = buildPluginMessage(
1121
+ `\u4EE5\u4E0B\u662F\u7528\u6237\u5F15\u7528\u8282\u70B9\u7684\u5B8C\u6574\u4E0A\u4E0B\u6587\uFF08\u8282\u70B9 ID \u4E0E\u6D88\u606F\u4E2D\u7684 @\u8282\u70B9[id] \u6807\u8BB0\u5BF9\u5E94\uFF09\uFF1A
1058
1122
 
1059
1123
  ${contextText}`
1060
- }
1061
- ],
1062
- source: { kind: "plugin", plugin: name }
1063
- };
1124
+ );
1064
1125
  try {
1065
1126
  await fetch(contextBase, { method: "DELETE", signal });
1066
1127
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aipanel/dsh-plugin",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "type": "module",
5
5
  "description": "AIPanel for DeepSeek Harness (dsh):注入审查工具 run_diagnostics、编辑后自动诊断。",
6
6
  "main": "./dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "@deepseek-ai/dsh-user-questions": "^0.1.5-rc.1",
26
26
  "@deepseek-ai/dsh-util-values": "^0.1.5-rc.1",
27
27
  "esbuild": "^0.25.0",
28
- "@aipanel/core": "1.2.18"
28
+ "@aipanel/core": "1.2.20"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "esbuild src/index.ts --bundle --outfile=dist/index.js --platform=node --format=esm --target=node18 --external:@deepseek-ai/* --external:node:* --external:vue-tsc",