dsh-plugin-opc 0.1.11 → 0.1.13

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/lib/client.js CHANGED
@@ -178,7 +178,7 @@ function registerMentions(ctx, api) {
178
178
  }
179
179
 
180
180
  // src/client/index.tsx
181
- var import_react11 = __toESM(require("react"), 1);
181
+ var import_react12 = __toESM(require("react"), 1);
182
182
 
183
183
  // node_modules/zod/v4/classic/external.js
184
184
  var external_exports = {};
@@ -19901,6 +19901,7 @@ function date4(params) {
19901
19901
  var contribution = { package: "dsh-plugin-opc", descriptors: [
19902
19902
  { id: "dsh-plugin-opc#opc/appList", service: "opc", namespace: "opc", method: "appList", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appList:expectedContextId", create: () => external_exports.string() } }], result: { mode: "strict", typeSymbol: "opc/appList:result", create: () => external_exports.string() } },
19903
19903
  { id: "dsh-plugin-opc#opc/appJob", service: "opc", namespace: "opc", method: "appJob", invocation: { kind: "direct" }, parameters: [{ name: "id", wire: "id", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJob:id", create: () => external_exports.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJob:expectedContextId", create: () => external_exports.string() } }], result: { mode: "strict", typeSymbol: "opc/appJob:result", create: () => external_exports.string() } },
19904
+ { id: "dsh-plugin-opc#opc/appJobByAnalysisSession", service: "opc", namespace: "opc", method: "appJobByAnalysisSession", invocation: { kind: "direct" }, parameters: [{ name: "sessionId", wire: "sessionId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:sessionId", create: () => external_exports.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:expectedContextId", create: () => external_exports.string() } }], result: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:result", create: () => external_exports.string() } },
19904
19905
  { id: "dsh-plugin-opc#opc/appCheckSlug", service: "opc", namespace: "opc", method: "appCheckSlug", invocation: { kind: "direct" }, parameters: [{ name: "slug", wire: "slug", source: "json", codec: { mode: "strict", typeSymbol: "opc/appCheckSlug:slug", create: () => external_exports.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appCheckSlug:expectedContextId", create: () => external_exports.string() } }], result: { mode: "strict", typeSymbol: "opc/appCheckSlug:result", create: () => external_exports.string() } },
19905
19906
  { id: "dsh-plugin-opc#opc/appOpcConfig", service: "opc", namespace: "opc", method: "appOpcConfig", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appOpcConfig:expectedContextId", create: () => external_exports.string() } }], result: { mode: "strict", typeSymbol: "opc/appOpcConfig:result", create: () => external_exports.string() } },
19906
19907
  { id: "dsh-plugin-opc#opc/appPickSourceFolder", service: "opc", namespace: "opc", method: "appPickSourceFolder", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appPickSourceFolder:expectedContextId", create: () => external_exports.string() } }], result: { mode: "strict", typeSymbol: "opc/appPickSourceFolder:result", create: () => external_exports.string() } },
@@ -30506,6 +30507,7 @@ function AppDeliveryReview({
30506
30507
  onReplaceSource,
30507
30508
  onNextStep,
30508
30509
  onInvalidate,
30510
+ beginAnalysisNavigation,
30509
30511
  initialFeedback = "",
30510
30512
  repairMode = false,
30511
30513
  onlineResources = [],
@@ -30593,15 +30595,16 @@ function AppDeliveryReview({
30593
30595
  const sendFeedback = async (customText, resume = false) => {
30594
30596
  const content3 = (customText ?? feedback).trim();
30595
30597
  if (!content3 && !resume || running || inFlight.current) return;
30598
+ const navigate = beginAnalysisNavigation?.();
30596
30599
  inFlight.current = true;
30597
30600
  setBusy(true);
30598
30601
  setError("");
30599
30602
  try {
30600
30603
  const mode = resume ? "resume" : repairMode || job?.analysis_mode === "repair" || job?.analysisMode === "repair" ? "repair" : "analysis";
30601
- if (api.appAnalyzeWithMode) {
30602
- await api.appAnalyzeWithMode(jobId, resume ? "" : content3, sessionId, mode, contextId);
30603
- } else {
30604
- await api.appAnalyze(jobId, content3, sessionId, contextId);
30604
+ const raw = api.appAnalyzeWithMode ? await api.appAnalyzeWithMode(jobId, resume ? "" : content3, sessionId, mode, contextId) : await api.appAnalyze(jobId, content3, sessionId, contextId);
30605
+ if (navigate) {
30606
+ const updated = JSON.parse(raw);
30607
+ if (updated?.id === jobId) navigate(updated);
30605
30608
  }
30606
30609
  onInvalidate?.();
30607
30610
  preparing.current = "";
@@ -56210,6 +56213,7 @@ function inferStepForJob(job) {
56210
56213
  case "ready":
56211
56214
  return 3;
56212
56215
  case "building":
56216
+ case "publishing":
56213
56217
  case "verifying":
56214
56218
  case "awaiting_page_verification":
56215
56219
  case "verified":
@@ -56217,6 +56221,7 @@ function inferStepForJob(job) {
56217
56221
  return 4;
56218
56222
  case "failed":
56219
56223
  if (job.failureStage === "import") return 1;
56224
+ if (job.failureStage === "deployment" || job.failureStage === "verification") return 4;
56220
56225
  if (job.failureStage === "analysis" || job.failureStage === "preparation" || job.analysis_failure && !job.published) return 2;
56221
56226
  if (job.published) return 4;
56222
56227
  if (job.proposal) return 2;
@@ -56303,9 +56308,21 @@ function AppsPanel({
56303
56308
  api,
56304
56309
  sessionId,
56305
56310
  contextId,
56306
- refreshSignal = 0
56311
+ refreshSignal = 0,
56312
+ prepareAnalysisNavigation
56307
56313
  }) {
56308
56314
  const [viewMode, setViewMode] = (0, import_react8.useState)("list");
56315
+ const [loadingLinkedJob, setLoadingLinkedJob] = (0, import_react8.useState)(Boolean(api.appJobByAnalysisSession));
56316
+ const [linkedJob, setLinkedJob] = (0, import_react8.useState)(null);
56317
+ const restoredLinkedJob = (0, import_react8.useRef)(false);
56318
+ const analysisViewActive = (0, import_react8.useRef)(false);
56319
+ (0, import_react8.useEffect)(() => {
56320
+ analysisViewActive.current = viewMode === "wizard";
56321
+ return () => {
56322
+ analysisViewActive.current = false;
56323
+ };
56324
+ }, [viewMode]);
56325
+ const beginAnalysisNavigation = () => prepareAnalysisNavigation?.(sessionId, contextId, () => analysisViewActive.current);
56309
56326
  const [loadingList, setLoadingList] = (0, import_react8.useState)(true);
56310
56327
  const [apps, setApps] = (0, import_react8.useState)([]);
56311
56328
  const [jobs, setJobs] = (0, import_react8.useState)([]);
@@ -56698,7 +56715,7 @@ function AppsPanel({
56698
56715
  [opcConfig.defaultPort]
56699
56716
  );
56700
56717
  const resumeWizardJob = (0, import_react8.useCallback)(
56701
- async (job, overrideStep) => {
56718
+ async (job, overrideStep, useSnapshot = false) => {
56702
56719
  setWizardError(null);
56703
56720
  setWizardNotice(null);
56704
56721
  setVerifyCredentials({});
@@ -56708,7 +56725,7 @@ function AppsPanel({
56708
56725
  setReviewInitialFeedback("");
56709
56726
  setConfigSubTab("configs");
56710
56727
  setViewMode("wizard");
56711
- const fresh = await refreshWizardJob(job.id) ?? job;
56728
+ const fresh = useSnapshot ? job : await refreshWizardJob(job.id) ?? job;
56712
56729
  setWizardJob(fresh);
56713
56730
  setUpgradeTarget(fresh.published || fresh.upgrade ? apps.find((a) => a.slug === fresh.slug && a.can_manage === true) ?? null : null);
56714
56731
  const targetStep = overrideStep ?? inferStepForJob(fresh);
@@ -56728,6 +56745,35 @@ function AppsPanel({
56728
56745
  },
56729
56746
  [apps, fetchWizardLogs, opcConfig.defaultPort, refreshWizardJob, syncStep3Drafts]
56730
56747
  );
56748
+ const openLinkedJob = (0, import_react8.useCallback)(async (job, refresh = true) => {
56749
+ const fresh = refresh ? await refreshWizardJob(job.id) ?? job : job;
56750
+ if (fresh.status === "verified") await openAppDetail(fresh.slug);
56751
+ else await resumeWizardJob(fresh, void 0, true);
56752
+ }, [openAppDetail, refreshWizardJob, resumeWizardJob]);
56753
+ (0, import_react8.useEffect)(() => {
56754
+ if (!api.appJobByAnalysisSession) return;
56755
+ let active = true;
56756
+ void api.appJobByAnalysisSession(sessionId, contextId).then((raw) => {
56757
+ if (active) setLinkedJob(parseJson(raw, null));
56758
+ }).catch((error62) => {
56759
+ if (active) setBannerError(readErrorMessage(error62, "\u65E0\u6CD5\u6062\u590D\u4E0E\u5F53\u524D\u4F1A\u8BDD\u5173\u8054\u7684\u4EFB\u52A1"));
56760
+ }).finally(() => {
56761
+ if (active) setLoadingLinkedJob(false);
56762
+ });
56763
+ return () => {
56764
+ active = false;
56765
+ };
56766
+ }, [api, contextId, sessionId]);
56767
+ (0, import_react8.useEffect)(() => {
56768
+ if (loadingLinkedJob || !linkedJob || restoredLinkedJob.current) return;
56769
+ restoredLinkedJob.current = true;
56770
+ void openLinkedJob(linkedJob, false);
56771
+ }, [linkedJob, loadingLinkedJob, openLinkedJob]);
56772
+ (0, import_react8.useEffect)(() => {
56773
+ if (viewMode !== "wizard" || wizardJob?.id !== linkedJob?.id || upgradeTarget || !(wizardJob?.upgrade || wizardJob?.published)) return;
56774
+ const target = apps.find((app) => app.slug === wizardJob.slug && app.can_manage === true);
56775
+ if (target) setUpgradeTarget(target);
56776
+ }, [apps, linkedJob?.id, upgradeTarget, viewMode, wizardJob]);
56731
56777
  const handleStep1Submit = async (e) => {
56732
56778
  e.preventDefault();
56733
56779
  setWizardError(null);
@@ -56762,6 +56808,7 @@ function AppsPanel({
56762
56808
  setWizardError("\u8BF7\u9009\u62E9\u6216\u586B\u5199\u672C\u673A\u6E90\u7801\u76EE\u5F55\u7684\u5B8C\u6574\u8DEF\u5F84");
56763
56809
  return;
56764
56810
  }
56811
+ const navigate = beginAnalysisNavigation();
56765
56812
  setWizardBusy(true);
56766
56813
  try {
56767
56814
  const payload = {
@@ -56794,7 +56841,10 @@ function AppsPanel({
56794
56841
  const analyzePromise = api.appAnalyzeWithMode ? api.appAnalyzeWithMode(created.id, "", sessionId, "analysis", contextId) : api.appAnalyze(created.id, "", sessionId, contextId);
56795
56842
  void analyzePromise.then((updatedRaw) => {
56796
56843
  const updated = parseJson(updatedRaw, null);
56797
- if (updated) setWizardJob(updated);
56844
+ if (updated) {
56845
+ setWizardJob(updated);
56846
+ navigate?.(updated);
56847
+ }
56798
56848
  void loadWorkspaceData(true);
56799
56849
  }).catch((err) => {
56800
56850
  setWizardError(readErrorMessage(err, "\u542F\u52A8\u6E90\u7801\u5206\u6790\u5931\u8D25"));
@@ -56995,6 +57045,7 @@ function AppsPanel({
56995
57045
  };
56996
57046
  const handleLaunchRepair = async () => {
56997
57047
  if (!wizardJob) return;
57048
+ const navigate = beginAnalysisNavigation();
56998
57049
  setWizardBusy(true);
56999
57050
  setWizardError(null);
57000
57051
  try {
@@ -57008,7 +57059,10 @@ function AppsPanel({
57008
57059
  setWizardStep(2);
57009
57060
  void analyzePromise.then((raw) => {
57010
57061
  const updated = parseJson(raw, null);
57011
- if (updated) setWizardJob(updated);
57062
+ if (updated) {
57063
+ setWizardJob(updated);
57064
+ navigate?.(updated);
57065
+ }
57012
57066
  }).catch((err) => {
57013
57067
  setWizardError(readErrorMessage(err, "\u542F\u52A8\u4FEE\u590D\u5206\u6790\u5931\u8D25"));
57014
57068
  void refreshWizardJob(wizardJob.id);
@@ -57225,7 +57279,7 @@ function AppsPanel({
57225
57279
  const currentVersion = (version2) => version2.is_active || detailApp?.status === "running" && detailApp.current_version === version2.version;
57226
57280
  const hasRunningVersion = detailApp?.status === "running" || versions.some((v) => v.status === "running" || v.is_active);
57227
57281
  const visibleVersions = versions.filter((version2, index3) => currentVersion(version2) || version2.status !== "failed" || !hasRunningVersion && index3 === 0);
57228
- const renderAppListView = () => /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 16 } }, /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-topbar" }, /* @__PURE__ */ import_react8.default.createElement("div", null, /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" } }, /* @__PURE__ */ import_react8.default.createElement("h2", { className: "oa-title" }, "\u4F01\u4E1A\u5E94\u7528"), /* @__PURE__ */ import_react8.default.createElement("span", { className: "oa-pill oa-pill-accent" }, apps.length, " \u4E2A\u5E94\u7528")), /* @__PURE__ */ import_react8.default.createElement("p", { className: "oa-subtitle", style: { marginTop: 4 } }, "\u5C06\u672C\u5730\u9879\u76EE\u63A5\u5165\u5E73\u53F0\u8FD0\u884C\u73AF\u5883\uFF0C\u81EA\u52A8\u5B8C\u6210\u5206\u6790\u6539\u9020\u3001\u914D\u7F6E\u6258\u7BA1\u4E0E\u4E0A\u7EBF\u53D1\u5E03\uFF0C\u540C\u65F6\u751F\u6210\u53EF\u8C03\u7528\u7684\u667A\u80FD\u4F53\u6280\u80FD\u3002")), /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 8 } }, /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn", disabled: loadingList, onClick: () => void loadWorkspaceData(false) }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "refresh", size: 14, className: loadingList ? "oa-spin" : "" }), /* @__PURE__ */ import_react8.default.createElement("span", null, "\u5237\u65B0")), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-primary", onClick: () => startWizardNew() }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "plus", size: 14 }), /* @__PURE__ */ import_react8.default.createElement("span", null, "\u65B0\u5EFA\u5E94\u7528")))), bannerError && /* @__PURE__ */ import_react8.default.createElement("div", { role: "alert", className: "oa-alert oa-alert-danger" }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "warning", size: 16 }), /* @__PURE__ */ import_react8.default.createElement("div", { style: { flex: 1 } }, bannerError), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-xs", onClick: () => setBannerError(null) }, "\u5173\u95ED")), bannerNotice && /* @__PURE__ */ import_react8.default.createElement("div", { role: "status", className: "oa-alert oa-alert-ok" }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "check", size: 16 }), /* @__PURE__ */ import_react8.default.createElement("div", { style: { flex: 1 } }, bannerNotice), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-xs", onClick: () => setBannerNotice(null) }, "\u5173\u95ED")), resumableJob && (() => {
57282
+ const renderAppListView = () => /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 16 } }, /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-topbar" }, /* @__PURE__ */ import_react8.default.createElement("div", null, /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" } }, /* @__PURE__ */ import_react8.default.createElement("h2", { className: "oa-title" }, "\u4F01\u4E1A\u5E94\u7528"), /* @__PURE__ */ import_react8.default.createElement("span", { className: "oa-pill oa-pill-accent" }, apps.length, " \u4E2A\u5E94\u7528")), /* @__PURE__ */ import_react8.default.createElement("p", { className: "oa-subtitle", style: { marginTop: 4 } }, "\u5C06\u672C\u5730\u9879\u76EE\u63A5\u5165\u5E73\u53F0\u8FD0\u884C\u73AF\u5883\uFF0C\u81EA\u52A8\u5B8C\u6210\u5206\u6790\u6539\u9020\u3001\u914D\u7F6E\u6258\u7BA1\u4E0E\u4E0A\u7EBF\u53D1\u5E03\uFF0C\u540C\u65F6\u751F\u6210\u53EF\u8C03\u7528\u7684\u667A\u80FD\u4F53\u6280\u80FD\u3002")), /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 8 } }, /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn", disabled: loadingList, onClick: () => void loadWorkspaceData(false) }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "refresh", size: 14, className: loadingList ? "oa-spin" : "" }), /* @__PURE__ */ import_react8.default.createElement("span", null, "\u5237\u65B0")), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-primary", onClick: () => startWizardNew() }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "plus", size: 14 }), /* @__PURE__ */ import_react8.default.createElement("span", null, "\u65B0\u5EFA\u5E94\u7528")))), bannerError && /* @__PURE__ */ import_react8.default.createElement("div", { role: "alert", className: "oa-alert oa-alert-danger" }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "warning", size: 16 }), /* @__PURE__ */ import_react8.default.createElement("div", { style: { flex: 1 } }, bannerError), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-xs", onClick: () => setBannerError(null) }, "\u5173\u95ED")), bannerNotice && /* @__PURE__ */ import_react8.default.createElement("div", { role: "status", className: "oa-alert oa-alert-ok" }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "check", size: 16 }), /* @__PURE__ */ import_react8.default.createElement("div", { style: { flex: 1 } }, bannerNotice), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-xs", onClick: () => setBannerNotice(null) }, "\u5173\u95ED")), linkedJob && /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-draft-banner" }, /* @__PURE__ */ import_react8.default.createElement("div", null, /* @__PURE__ */ import_react8.default.createElement("strong", null, linkedJob.name)), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-sm oa-btn-primary", onClick: () => void openLinkedJob(linkedJob) }, "\u56DE\u5230\u5F53\u524D\u4EFB\u52A1")), resumableJob && resumableJob.id !== linkedJob?.id && (() => {
57229
57283
  const tone = jobStatusTone(resumableJob.status, resumableJob.userDisabled);
57230
57284
  return /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-draft-banner" }, /* @__PURE__ */ import_react8.default.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" } }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "sparkle", size: 15 }), /* @__PURE__ */ import_react8.default.createElement("strong", { style: { fontSize: 13.5, color: "#0f172a" } }, "\u672A\u5B8C\u6210\u7684\u5E94\u7528\u4EA4\u4ED8\u4EFB\u52A1\uFF1A", resumableJob.name), /* @__PURE__ */ import_react8.default.createElement("span", { className: "oa-code" }, resumableJob.slug), /* @__PURE__ */ import_react8.default.createElement("span", { className: `oa-pill ${tone.pillClass}` }, tone.spinning && /* @__PURE__ */ import_react8.default.createElement("span", { className: "oa-dot oa-pulse" }), tone.text)), /* @__PURE__ */ import_react8.default.createElement("p", { className: "oa-hint", style: { marginTop: 4 } }, resumableJob.status === "awaiting_page_verification" ? "\u5BB9\u5668\u4E0E\u63A5\u53E3\u68C0\u67E5\u5DF2\u5C31\u7EEA\uFF0C\u8BF7\u6253\u5F00\u5E94\u7528\u9875\u9762\u786E\u8BA4\u540E\u542F\u7528\u667A\u80FD\u4F53\u6280\u80FD\u3002" : resumableJob.error || resumableJob.analysis_failure || "\u53EF\u4ECE\u4E0A\u6B21\u8FDB\u5EA6\u7EE7\u7EED\u529E\u7406\u6216\u8C03\u6574\u6E90\u7801\u65B9\u6848\u3002")), /* @__PURE__ */ import_react8.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 8, flexShrink: 0 } }, /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-sm oa-btn-primary", onClick: () => void resumeWizardJob(resumableJob) }, "\u7EE7\u7EED\u529E\u7406"), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-sm", onClick: () => dismissDraftBanner(resumableJob) }, "\u9690\u85CF\u63D0\u793A")));
57231
57285
  })(), loadingList && apps.length === 0 ? /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-form-card", style: { textAlign: "center", padding: "44px 20px", color: "#64748b" } }, "\u6B63\u5728\u52A0\u8F7D\u4F01\u4E1A\u5E94\u7528\u76EE\u5F55\u2026") : apps.length === 0 ? /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-form-card", style: { textAlign: "center", padding: "48px 24px" } }, /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-app-icon-box", style: { margin: "0 auto 14px", width: 48, height: 48 } }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "sparkle", size: 22 })), /* @__PURE__ */ import_react8.default.createElement("div", { style: { fontSize: 16, fontWeight: 600, color: "#0f172a" } }, "\u6682\u65E0\u5DF2\u90E8\u7F72\u7684\u4F01\u4E1A\u5E94\u7528"), /* @__PURE__ */ import_react8.default.createElement("p", { className: "oa-subtitle", style: { maxWidth: 460, margin: "8px auto 18px" } }, "\u4E0A\u4F20\u9879\u76EE\u538B\u7F29\u5305\u6216\u9009\u62E9\u672C\u5730\u9879\u76EE\u6587\u4EF6\u5939\uFF0CAI \u5C06\u81EA\u52A8\u5206\u6790\u8FD0\u884C\u73AF\u5883\u3001\u6258\u7BA1\u914D\u7F6E\u5E76\u53D1\u5E03\u5230\u4F01\u4E1A\u8BBF\u95EE\u57DF\u540D\uFF0C\u540C\u65F6\u751F\u6210\u540C\u540D\u5E94\u7528\u6280\u80FD\u3002"), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", className: "oa-btn oa-btn-primary", onClick: () => startWizardNew() }, /* @__PURE__ */ import_react8.default.createElement(AppIcon, { name: "plus", size: 14 }), /* @__PURE__ */ import_react8.default.createElement("span", null, "\u65B0\u5EFA\u7B2C\u4E00\u4E2A\u5E94\u7528"))) : /* @__PURE__ */ import_react8.default.createElement("div", { className: "oa-apps-grid" }, apps.map((app) => {
@@ -57471,6 +57525,7 @@ function AppsPanel({
57471
57525
  sessionId,
57472
57526
  contextId,
57473
57527
  jobId: wizardJob.id,
57528
+ beginAnalysisNavigation,
57474
57529
  footerMode: "external",
57475
57530
  onlineResources: resources,
57476
57531
  repairMode: wizardJob.analysis_mode === "repair" || wizardJob.analysisMode === "repair",
@@ -57952,7 +58007,7 @@ function AppsPanel({
57952
58007
  "\u53D6\u6D88"
57953
58008
  ))))));
57954
58009
  };
57955
- return /* @__PURE__ */ import_react8.default.createElement("div", { className: "opc-apps-root" }, /* @__PURE__ */ import_react8.default.createElement("style", null, appsCss), viewMode === "list" && renderAppListView(), viewMode === "wizard" && renderWizardView(), viewMode === "detail" && renderDetailView());
58010
+ return /* @__PURE__ */ import_react8.default.createElement("div", { className: "opc-apps-root" }, /* @__PURE__ */ import_react8.default.createElement("style", null, appsCss), viewMode === "list" && (loadingLinkedJob || linkedJob && !restoredLinkedJob.current ? /* @__PURE__ */ import_react8.default.createElement("p", { role: "status" }, "\u6B63\u5728\u67E5\u627E\u5F53\u524D\u4F1A\u8BDD\u7684\u5E94\u7528\u4EFB\u52A1\u2026") : renderAppListView()), viewMode === "wizard" && renderWizardView(), viewMode === "detail" && renderDetailView());
57956
58011
  }
57957
58012
 
57958
58013
  // src/client/OpcSettingsPanel.tsx
@@ -58038,10 +58093,12 @@ var settingsCss = `
58038
58093
  align-items: center;
58039
58094
  gap: 8px;
58040
58095
  }
58041
- .opc-settings-input {
58096
+ .opc-panel .opc-settings-input {
58042
58097
  width: 100%;
58043
58098
  min-width: 0;
58044
58099
  height: 36px;
58100
+ min-height: 36px;
58101
+ flex: 0 0 auto;
58045
58102
  padding: 6px 12px;
58046
58103
  border: 1px solid #cbd5e1;
58047
58104
  border-radius: 8px;
@@ -58050,14 +58107,20 @@ var settingsCss = `
58050
58107
  font-size: 13px;
58051
58108
  transition: border-color 0.15s, background 0.15s;
58052
58109
  }
58053
- .opc-settings-input:focus {
58110
+ .opc-panel .opc-settings-input-row .opc-settings-input {
58111
+ flex: 1 1 0%;
58112
+ }
58113
+ .opc-panel .opc-settings-input:focus {
58054
58114
  outline: none;
58055
58115
  border-color: #245c9f;
58056
58116
  background: #ffffff;
58057
58117
  }
58058
- .opc-settings-port-input {
58059
- width: 120px !important;
58060
- flex: 0 0 120px !important;
58118
+ .opc-panel .opc-settings-port-input {
58119
+ width: 120px;
58120
+ max-width: 120px;
58121
+ height: 36px;
58122
+ min-height: 36px;
58123
+ flex: 0 0 auto;
58061
58124
  }
58062
58125
  .opc-settings-test-btn {
58063
58126
  height: 36px;
@@ -59114,7 +59177,7 @@ var css = `
59114
59177
  margin: 0 0 10px;
59115
59178
  }
59116
59179
  `;
59117
- function Panel({ api, sessionId, kind }) {
59180
+ function Panel({ api, sessionId, kind, prepareAnalysisNavigation }) {
59118
59181
  const [state, setState] = (0, import_react10.useState)({ signedIn: false, loginInProgress: false, context: null });
59119
59182
  const [error62, setError] = (0, import_react10.useState)(""), [busy, setBusy] = (0, import_react10.useState)(false), [q, setQ] = (0, import_react10.useState)("");
59120
59183
  const [items, setItems] = (0, import_react10.useState)([]), [hits, setHits] = (0, import_react10.useState)([]);
@@ -59245,6 +59308,7 @@ function Panel({ api, sessionId, kind }) {
59245
59308
  api,
59246
59309
  sessionId,
59247
59310
  contextId: context.applicationContextId,
59311
+ prepareAnalysisNavigation,
59248
59312
  refreshSignal: appsRefreshTrigger
59249
59313
  }
59250
59314
  ), kind === "knowledge" && /* @__PURE__ */ import_react10.default.createElement(import_react10.default.Fragment, null, /* @__PURE__ */ import_react10.default.createElement("div", { className: "s2-kb-tabs" }, /* @__PURE__ */ import_react10.default.createElement(
@@ -59628,6 +59692,75 @@ function McpDebug({ api, serviceId, toolName, contextId }) {
59628
59692
  } }, pending ? "\u6267\u884C\u4E2D\u2026" : "\u8C03\u7528"), result && /* @__PURE__ */ import_react10.default.createElement("pre", { style: { marginTop: 6, fontSize: 11, background: "#f1f5f9", padding: 8, borderRadius: 4, overflowX: "auto" } }, result));
59629
59693
  }
59630
59694
 
59695
+ // src/client/app-analysis-navigation.tsx
59696
+ var import_react11 = require("react");
59697
+ function OpenAnalysisSidebar({ open: open2 }) {
59698
+ (0, import_react11.useEffect)(() => {
59699
+ open2();
59700
+ }, [open2]);
59701
+ return null;
59702
+ }
59703
+ function registerAnalysisNavigation(ctx, api) {
59704
+ let attempt = 0;
59705
+ let pending;
59706
+ const sidebar = ctx.get("sidebarRight");
59707
+ const currentSession = () => sidebar?.mounted?.getSnapshot();
59708
+ if (sidebar?.mounted) {
59709
+ ctx.effect(() => sidebar.mounted.subscribe(() => {
59710
+ attempt++;
59711
+ if (pending && currentSession() !== pending) pending = void 0;
59712
+ }));
59713
+ }
59714
+ ctx.effect(() => () => {
59715
+ attempt++;
59716
+ pending = void 0;
59717
+ });
59718
+ ctx.effect(() => ctx.slots.inject("conversation.session.header.utilities", () => ctx.slots.register({
59719
+ name: "conversation.session.header.utilities",
59720
+ id: "opc-app-analysis-sidebar",
59721
+ inject: (sessionId) => ({
59722
+ open: () => {
59723
+ if (pending !== sessionId || currentSession() !== sessionId) return;
59724
+ pending = void 0;
59725
+ try {
59726
+ sidebar?.openTab("opc-apps");
59727
+ } catch {
59728
+ }
59729
+ }
59730
+ })
59731
+ }, OpenAnalysisSidebar)));
59732
+ return (origin, contextId, isActive) => {
59733
+ const started = ++attempt;
59734
+ const canNavigate = () => attempt === started && isActive() && currentSession() === origin;
59735
+ return (job) => {
59736
+ const workspace = ctx.get("uiWorkspace");
59737
+ if (!workspace || !sidebar || !canNavigate()) return;
59738
+ void (async () => {
59739
+ let current = job;
59740
+ while (canNavigate()) {
59741
+ const target = current.analysisSessionId;
59742
+ if (target) {
59743
+ if (target !== origin) {
59744
+ pending = target;
59745
+ try {
59746
+ workspace.openSession(target);
59747
+ } catch {
59748
+ pending = void 0;
59749
+ }
59750
+ }
59751
+ return;
59752
+ }
59753
+ if (current.status !== "analyzing" || !api.appJob) return;
59754
+ await new Promise((resolve) => setTimeout(resolve, 500));
59755
+ if (!canNavigate()) return;
59756
+ current = JSON.parse(await api.appJob(job.id, contextId));
59757
+ }
59758
+ })().catch(() => {
59759
+ });
59760
+ };
59761
+ };
59762
+ }
59763
+
59631
59764
  // src/client/index.tsx
59632
59765
  var inject = ["remote"];
59633
59766
  async function apply(ctx) {
@@ -59646,6 +59779,7 @@ function registerPanels(ctx) {
59646
59779
  appCatalog: (...args) => unwrap(wire.appCatalog(...args)),
59647
59780
  appList: (...args) => unwrap(wire.appList(...args)),
59648
59781
  appJob: (...args) => unwrap(wire.appJob(...args)),
59782
+ appJobByAnalysisSession: (...args) => unwrap(wire.appJobByAnalysisSession(...args)),
59649
59783
  appCheckSlug: (...args) => unwrap(wire.appCheckSlug(...args)),
59650
59784
  opcConfigGet: () => unwrap(wire.opcConfigGet()),
59651
59785
  opcConfigUpdate: (payloadJson) => unwrap(wire.opcConfigUpdate(payloadJson)),
@@ -59704,11 +59838,12 @@ function registerPanels(ctx) {
59704
59838
  decideDebugInvocation: (...args) => unwrap(wire.decideDebugInvocation(...args))
59705
59839
  };
59706
59840
  ctx.inject(["inputTriggers"], (child) => registerMentions(child, api));
59841
+ const prepareAnalysisNavigation = registerAnalysisNavigation(ctx, api);
59707
59842
  for (const [index3, kind] of ["knowledge", "skills", "mcp", "apps"].entries()) {
59708
59843
  const id = `dsh-plugin-opc/${kind}`;
59709
59844
  ctx.effect(() => ctx.sidebarRightTabs.register({ id, kind: `opc-${kind}`, priority: "extension", title: () => labels[kind], guide: [{ id: `opc-${kind}`, order: 10 + index3, icon: OpcIcon, title: () => labels[kind], description: () => "OPC \u5DE5\u4F5C\u7A7A\u95F4" }] }));
59710
- ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab.title", () => ctx.slots.register({ name: "sidebar.right.pane.tab.title", key: id }, () => /* @__PURE__ */ import_react11.default.createElement(import_react11.default.Fragment, null, /* @__PURE__ */ import_react11.default.createElement(OpcIcon, null), " ", labels[kind]))));
59711
- ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ name: "sidebar.right.pane.tab", key: id, inject: (sessionId) => ({ api, sessionId: String(sessionId), kind }) }, Panel)));
59845
+ ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab.title", () => ctx.slots.register({ name: "sidebar.right.pane.tab.title", key: id }, () => /* @__PURE__ */ import_react12.default.createElement(import_react12.default.Fragment, null, /* @__PURE__ */ import_react12.default.createElement(OpcIcon, null), " ", labels[kind]))));
59846
+ ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ name: "sidebar.right.pane.tab", key: id, inject: (sessionId) => ({ api, sessionId: String(sessionId), kind, prepareAnalysisNavigation }) }, Panel)));
59712
59847
  }
59713
59848
  }
59714
59849
 
package/lib/index.js CHANGED
@@ -1431,8 +1431,8 @@ var OpcConfigStore = class {
1431
1431
 
1432
1432
  // src/host/remote-service.ts
1433
1433
  var execFileAsync = promisify(execFile);
1434
- var _decideDebugInvocation_dec, _unmountMcpService_dec, _mountMcpService_dec, _invokeMcpTool_dec, _listMcpServices_dec, _readKnowledgeDocument_dec, _searchKnowledge_dec, _setPinnedKnowledgeScope_dec, _uninstallSkill_dec, _setSkillEnabled_dec, _installSkill_dec, _listSkillsCatalog_dec, _listKnowledgeBases_dec, _switchTenant_dec, _logout_dec, _cancelLogin_dec, _startLogin_dec, _watchState_dec, _state_dec, _opcConfigTest_dec, _opcConfigReset_dec, _opcConfigUpdate_dec, _opcConfigGet_dec, _appRollback_dec, _appDelete_dec, _appUpdateConfig_dec, _appRecheck_dec, _appSaveDownload_dec, _appDownload_dec, _appStorage_dec, _appLogs_dec, _appVersions_dec, _appDetails_dec, _appResources_dec, _appSetSkillEnabled_dec, _appVerifyWithOptions_dec, _appVerify_dec, _appPublish_dec, _appConfirmDeployment_dec, _appSkillPreview_dec, _appHandoff_dec, _appSaveLocalArtifact_dec, _appLocalArtifact_dec, _appSaveConfigDraft_dec, _appConfigDraft_dec, _appCancelAnalysis_dec, _appReopenDeployment_dec, _appReopenReview_dec, _appPrepare_dec, _appAnalyzeWithMode_dec, _appAnalyze_dec, _appCreate_dec, _appCatalog_dec, _appModels_dec, _appPickSourceFolder_dec, _appOpcConfig_dec, _appCheckSlug_dec, _appJob_dec, _appList_dec, _a, _init;
1435
- var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [Remote], _appJob_dec = [Remote], _appCheckSlug_dec = [Remote], _appOpcConfig_dec = [Remote], _appPickSourceFolder_dec = [Remote], _appModels_dec = [Remote], _appCatalog_dec = [Remote], _appCreate_dec = [Remote], _appAnalyze_dec = [Remote], _appAnalyzeWithMode_dec = [Remote], _appPrepare_dec = [Remote], _appReopenReview_dec = [Remote], _appReopenDeployment_dec = [Remote], _appCancelAnalysis_dec = [Remote], _appConfigDraft_dec = [Remote], _appSaveConfigDraft_dec = [Remote], _appLocalArtifact_dec = [Remote], _appSaveLocalArtifact_dec = [Remote], _appHandoff_dec = [Remote], _appSkillPreview_dec = [Remote], _appConfirmDeployment_dec = [Remote], _appPublish_dec = [Remote], _appVerify_dec = [Remote], _appVerifyWithOptions_dec = [Remote], _appSetSkillEnabled_dec = [Remote], _appResources_dec = [Remote], _appDetails_dec = [Remote], _appVersions_dec = [Remote], _appLogs_dec = [Remote], _appStorage_dec = [Remote], _appDownload_dec = [Remote], _appSaveDownload_dec = [Remote], _appRecheck_dec = [Remote], _appUpdateConfig_dec = [Remote], _appDelete_dec = [Remote], _appRollback_dec = [Remote], _opcConfigGet_dec = [Remote], _opcConfigUpdate_dec = [Remote], _opcConfigReset_dec = [Remote], _opcConfigTest_dec = [Remote], _state_dec = [Remote], _watchState_dec = [Remote({ mode: "stream" })], _startLogin_dec = [Remote], _cancelLogin_dec = [Remote], _logout_dec = [Remote], _switchTenant_dec = [Remote], _listKnowledgeBases_dec = [Remote], _listSkillsCatalog_dec = [Remote], _installSkill_dec = [Remote], _setSkillEnabled_dec = [Remote], _uninstallSkill_dec = [Remote], _setPinnedKnowledgeScope_dec = [Remote], _searchKnowledge_dec = [Remote], _readKnowledgeDocument_dec = [Remote], _listMcpServices_dec = [Remote], _invokeMcpTool_dec = [Remote], _mountMcpService_dec = [Remote], _unmountMcpService_dec = [Remote], _decideDebugInvocation_dec = [Remote], _a) {
1434
+ var _decideDebugInvocation_dec, _unmountMcpService_dec, _mountMcpService_dec, _invokeMcpTool_dec, _listMcpServices_dec, _readKnowledgeDocument_dec, _searchKnowledge_dec, _setPinnedKnowledgeScope_dec, _uninstallSkill_dec, _setSkillEnabled_dec, _installSkill_dec, _listSkillsCatalog_dec, _listKnowledgeBases_dec, _switchTenant_dec, _logout_dec, _cancelLogin_dec, _startLogin_dec, _watchState_dec, _state_dec, _opcConfigTest_dec, _opcConfigReset_dec, _opcConfigUpdate_dec, _opcConfigGet_dec, _appRollback_dec, _appDelete_dec, _appUpdateConfig_dec, _appRecheck_dec, _appSaveDownload_dec, _appDownload_dec, _appStorage_dec, _appLogs_dec, _appVersions_dec, _appDetails_dec, _appResources_dec, _appSetSkillEnabled_dec, _appVerifyWithOptions_dec, _appVerify_dec, _appPublish_dec, _appConfirmDeployment_dec, _appSkillPreview_dec, _appHandoff_dec, _appSaveLocalArtifact_dec, _appLocalArtifact_dec, _appSaveConfigDraft_dec, _appConfigDraft_dec, _appCancelAnalysis_dec, _appReopenDeployment_dec, _appReopenReview_dec, _appPrepare_dec, _appAnalyzeWithMode_dec, _appAnalyze_dec, _appCreate_dec, _appCatalog_dec, _appModels_dec, _appPickSourceFolder_dec, _appOpcConfig_dec, _appCheckSlug_dec, _appJobByAnalysisSession_dec, _appJob_dec, _appList_dec, _a, _init;
1435
+ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [Remote], _appJob_dec = [Remote], _appJobByAnalysisSession_dec = [Remote], _appCheckSlug_dec = [Remote], _appOpcConfig_dec = [Remote], _appPickSourceFolder_dec = [Remote], _appModels_dec = [Remote], _appCatalog_dec = [Remote], _appCreate_dec = [Remote], _appAnalyze_dec = [Remote], _appAnalyzeWithMode_dec = [Remote], _appPrepare_dec = [Remote], _appReopenReview_dec = [Remote], _appReopenDeployment_dec = [Remote], _appCancelAnalysis_dec = [Remote], _appConfigDraft_dec = [Remote], _appSaveConfigDraft_dec = [Remote], _appLocalArtifact_dec = [Remote], _appSaveLocalArtifact_dec = [Remote], _appHandoff_dec = [Remote], _appSkillPreview_dec = [Remote], _appConfirmDeployment_dec = [Remote], _appPublish_dec = [Remote], _appVerify_dec = [Remote], _appVerifyWithOptions_dec = [Remote], _appSetSkillEnabled_dec = [Remote], _appResources_dec = [Remote], _appDetails_dec = [Remote], _appVersions_dec = [Remote], _appLogs_dec = [Remote], _appStorage_dec = [Remote], _appDownload_dec = [Remote], _appSaveDownload_dec = [Remote], _appRecheck_dec = [Remote], _appUpdateConfig_dec = [Remote], _appDelete_dec = [Remote], _appRollback_dec = [Remote], _opcConfigGet_dec = [Remote], _opcConfigUpdate_dec = [Remote], _opcConfigReset_dec = [Remote], _opcConfigTest_dec = [Remote], _state_dec = [Remote], _watchState_dec = [Remote({ mode: "stream" })], _startLogin_dec = [Remote], _cancelLogin_dec = [Remote], _logout_dec = [Remote], _switchTenant_dec = [Remote], _listKnowledgeBases_dec = [Remote], _listSkillsCatalog_dec = [Remote], _installSkill_dec = [Remote], _setSkillEnabled_dec = [Remote], _uninstallSkill_dec = [Remote], _setPinnedKnowledgeScope_dec = [Remote], _searchKnowledge_dec = [Remote], _readKnowledgeDocument_dec = [Remote], _listMcpServices_dec = [Remote], _invokeMcpTool_dec = [Remote], _mountMcpService_dec = [Remote], _unmountMcpService_dec = [Remote], _decideDebugInvocation_dec = [Remote], _a) {
1436
1436
  constructor(ctx, options) {
1437
1437
  super(ctx, "opc");
1438
1438
  __runInitializers(_init, 5, this);
@@ -1477,6 +1477,9 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
1477
1477
  async appJob(id, expectedContextId) {
1478
1478
  return JSON.stringify(await this.delivery.getJob(id, expectedContextId));
1479
1479
  }
1480
+ async appJobByAnalysisSession(sessionId, expectedContextId) {
1481
+ return JSON.stringify(await this.delivery.getJobByAnalysisSession(sessionId, expectedContextId));
1482
+ }
1480
1483
  async appCheckSlug(slug, expectedContextId) {
1481
1484
  return JSON.stringify(await this.delivery.checkSlug(slug, expectedContextId));
1482
1485
  }
@@ -1772,6 +1775,7 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
1772
1775
  _init = __decoratorStart(_a);
1773
1776
  __decorateElement(_init, 1, "appList", _appList_dec, OpcRemoteService);
1774
1777
  __decorateElement(_init, 1, "appJob", _appJob_dec, OpcRemoteService);
1778
+ __decorateElement(_init, 1, "appJobByAnalysisSession", _appJobByAnalysisSession_dec, OpcRemoteService);
1775
1779
  __decorateElement(_init, 1, "appCheckSlug", _appCheckSlug_dec, OpcRemoteService);
1776
1780
  __decorateElement(_init, 1, "appOpcConfig", _appOpcConfig_dec, OpcRemoteService);
1777
1781
  __decorateElement(_init, 1, "appPickSourceFolder", _appPickSourceFolder_dec, OpcRemoteService);
@@ -1972,7 +1976,7 @@ function worker(input, signal) {
1972
1976
  if (!result.ok) throw new Error(result.error);
1973
1977
  resolve(result.value);
1974
1978
  } catch (error) {
1975
- reject(new Error(stdout ? String(error) : `\u5E94\u7528\u51C6\u5907\u5DE5\u5177\u672A\u80FD\u542F\u52A8\uFF1A${stderr.slice(0, 500)}`));
1979
+ reject(new Error(stdout ? error instanceof Error ? error.message : String(error) : `\u5E94\u7528\u51C6\u5907\u5DE5\u5177\u672A\u80FD\u542F\u52A8\uFF1A${stderr.slice(0, 500)}`));
1976
1980
  }
1977
1981
  });
1978
1982
  child.stdin.on("error", () => {
@@ -2117,14 +2121,17 @@ ${combinedLog}` : combinedLog).slice(-24e3);
2117
2121
  }
2118
2122
  }
2119
2123
  }
2120
- async list(expected) {
2121
- const scope = this.scope(expected);
2122
- const directories = await this.directories(scope.directory);
2123
- const entries = (await Promise.all(directories.map((directory) => readdir2(directory).catch((error) => {
2124
+ async localJobIds(directory) {
2125
+ const directories = await this.directories(directory);
2126
+ const entries = (await Promise.all(directories.map((directory2) => readdir2(directory2).catch((error) => {
2124
2127
  if (error.code === "ENOENT") return [];
2125
2128
  throw error;
2126
2129
  })))).flat();
2127
- const jobs = await Promise.all([...new Set(entries.filter((id) => /^[a-f0-9-]{36}$/.test(id)))].map(async (id) => {
2130
+ return [...new Set(entries.filter((id) => /^[a-f0-9-]{36}$/.test(id)))];
2131
+ }
2132
+ async list(expected) {
2133
+ const scope = this.scope(expected);
2134
+ const jobs = await Promise.all((await this.localJobIds(scope.directory)).map(async (id) => {
2128
2135
  const result = await this.open(scope.directory, id).catch((error) => {
2129
2136
  if (error.code !== "ENOENT") throw error;
2130
2137
  return void 0;
@@ -2201,6 +2208,17 @@ ${combinedLog}` : combinedLog).slice(-24e3);
2201
2208
  if (job.status === "verified") view.userDisabled = await this.isSkillDisabled(scope.directory, job.slug);
2202
2209
  return view;
2203
2210
  }
2211
+ async getJobByAnalysisSession(sessionId, expected) {
2212
+ const scope = this.scope(expected);
2213
+ if (!/^[a-f0-9-]{36}$/.test(sessionId)) return null;
2214
+ const jobs = await Promise.all((await this.localJobIds(scope.directory)).map((id) => this.open(scope.directory, id).catch((error) => {
2215
+ if (error.code !== "ENOENT") throw error;
2216
+ return void 0;
2217
+ })));
2218
+ scope.assertCurrent();
2219
+ const match = jobs.find((entry) => entry?.job.analysisSessions?.includes(sessionId));
2220
+ return match ? this.getJob(match.job.id, expected) : null;
2221
+ }
2204
2222
  async checkSlug(slug, expected) {
2205
2223
  const trimmed = slug.trim();
2206
2224
  if (!/^[a-z][a-z0-9-]{2,39}$/.test(trimmed)) throw new Error("\u5E94\u7528\u552F\u4E00\u6807\u8BC6\u9700\u4E3A 3\u201340 \u4F4D\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u6216\u8FDE\u5B57\u7B26\uFF0C\u4E14\u4EE5\u5B57\u6BCD\u5F00\u5934");
@@ -2235,7 +2253,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
2235
2253
  };
2236
2254
  }
2237
2255
  public(job, root) {
2238
- const { proposal, skillMarkdown: _sm, dockerfileContent: _df, configDraft: _draft, confirmationToken: _token, ...rest } = job;
2256
+ const { proposal, skillMarkdown: _sm, dockerfileContent: _df, configDraft: _draft, confirmationToken: _token, analysisSessions: _analysisSessions, ...rest } = job;
2239
2257
  const hasOrigSet = new Set(job.hasOriginalKeys ?? []);
2240
2258
  const runtimeConfigs = (proposal?.contract?.configs ?? []).map((c) => {
2241
2259
  const hasOrig = hasOrigSet.has(c.key) || Boolean(c.has_original_value);
@@ -2490,7 +2508,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
2490
2508
  const resume = options?.mode === "resume";
2491
2509
  if (resume && (job.status !== "failed" || feedback.trim())) throw new Error("\u53EA\u80FD\u7EE7\u7EED\u5DF2\u6682\u505C\u7684\u5E94\u7528\u51C6\u5907");
2492
2510
  this.busy.add(id);
2493
- job.session = session || job.session;
2511
+ if (session && !job.analysisSessions?.includes(session)) job.session = session;
2494
2512
  let trimmedFeedback;
2495
2513
  try {
2496
2514
  trimmedFeedback = await worker({ action: "redact_feedback", root, text: feedback.slice(0, 2e4) }, scope.signal);
@@ -2501,12 +2519,10 @@ ${combinedLog}` : combinedLog).slice(-24e3);
2501
2519
  const controller = new AbortController();
2502
2520
  const analysisSignal = AbortSignal.any([scope.signal, controller.signal]);
2503
2521
  this.analyses.set(id, controller);
2504
- if (!resume) {
2522
+ if (!resume && job.status !== "failed") {
2505
2523
  job.analysisFailure = void 0;
2506
- if (!job.proposal) {
2507
- await rm2(join3(root, "draft_files.json"), { force: true }).catch(() => {
2508
- });
2509
- }
2524
+ if (!job.proposal) await rm2(join3(root, "draft_files.json"), { force: true }).catch(() => {
2525
+ });
2510
2526
  }
2511
2527
  if (!resume && (options?.mode === "repair" || job.revision && (job.published || job.status === "failed"))) {
2512
2528
  job.analysisMode = "repair";
@@ -2538,6 +2554,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
2538
2554
  }
2539
2555
  }
2540
2556
  job.status = "analyzing";
2557
+ delete job.analysisSessionId;
2541
2558
  job.failureStage = void 0;
2542
2559
  job.error = void 0;
2543
2560
  job.checks = void 0;
@@ -2555,7 +2572,14 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
2555
2572
  this.core.emit("skills-changed");
2556
2573
  void (async () => {
2557
2574
  try {
2558
- await this.analyze(job, root, trimmedFeedback, analysisSignal);
2575
+ await this.analyze(job, root, trimmedFeedback, analysisSignal, async (sessionId) => {
2576
+ analysisSignal.throwIfAborted();
2577
+ scope.assertCurrent();
2578
+ const analysisSessions = [...(job.analysisSessions ?? []).filter((id2) => id2 !== sessionId), sessionId];
2579
+ await this.save(root, { ...job, analysisSessions, analysisSessionId: sessionId });
2580
+ job.analysisSessions = analysisSessions;
2581
+ job.analysisSessionId = sessionId;
2582
+ });
2559
2583
  analysisSignal.throwIfAborted();
2560
2584
  scope.assertCurrent();
2561
2585
  if (!job.proposal || job.status === "analyzing") throw new Error("AI \u672A\u63D0\u4EA4\u6709\u6548\u6539\u9020\u65B9\u6848\uFF0C\u8BF7\u8865\u5145\u8BF4\u660E\u540E\u91CD\u8BD5");
@@ -2691,7 +2715,14 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
2691
2715
  throw new Error("unresolved \u5FC5\u987B\u4E3A\u6570\u7EC4");
2692
2716
  }
2693
2717
  const hasQuestions = Boolean(proposal.unresolved.length || proposal.contract.unresolved?.length);
2694
- if (!hasQuestions && proposal.contract.runtime?.port !== (job.port ?? 8080)) throw new Error("\u6A21\u578B\u4E0D\u80FD\u9759\u9ED8\u6539\u53D8\u7528\u6237\u9009\u62E9\u7684\u5BB9\u5668\u7AEF\u53E3");
2718
+ if (!hasQuestions) {
2719
+ const expectedPort = job.port ?? 8080;
2720
+ const actualPort = proposal.contract.runtime?.port;
2721
+ const field = "\u4EA4\u4ED8\u5951\u7EA6 runtime.port";
2722
+ if (actualPort == null) throw new Error(`${field} \u7F3A\u5931\u3002\u8BF7\u8865\u5168 runtime \u5E76\u586B\u5199\u5DF2\u9501\u5B9A\u7684\u6570\u5B57 ${expectedPort}`);
2723
+ if (!Number.isInteger(actualPort)) throw new Error(`${field} \u5FC5\u987B\u662F\u5DF2\u9501\u5B9A\u7684\u6574\u6570 ${expectedPort}\uFF0C\u4E0D\u80FD\u63D0\u4EA4\u5B57\u7B26\u4E32\u6216\u5176\u4ED6\u7C7B\u578B`);
2724
+ if (actualPort !== expectedPort) throw new Error(`${field} \u586B\u4E86 ${actualPort}\uFF0C\u4E0E\u5DF2\u9501\u5B9A\u7684\u5BB9\u5668\u7AEF\u53E3 ${expectedPort} \u4E0D\u4E00\u81F4\u3002\u6A21\u578B\u4E0D\u80FD\u9759\u9ED8\u6539\u53D8\u7528\u6237\u9009\u62E9\u7684\u5BB9\u5668\u7AEF\u53E3`);
2725
+ }
2695
2726
  const validated = await worker({
2696
2727
  action: "validate",
2697
2728
  root,
@@ -3464,6 +3495,110 @@ import { join as join4 } from "node:path";
3464
3495
  import { fileURLToPath as fileURLToPath2 } from "node:url";
3465
3496
  import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
3466
3497
  import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
3498
+
3499
+ // src/host/app-proposal-schema.ts
3500
+ var str = { type: "string" };
3501
+ var text2 = { ...str, required: true };
3502
+ var bool = { type: "boolean" };
3503
+ var strings = { type: "array", items: str };
3504
+ var object2 = { type: "object", additionalProperties: true };
3505
+ var objects = { type: "array", items: object2 };
3506
+ function proposalParameters(port) {
3507
+ return {
3508
+ summary: { ...str, description: "\u4E2D\u6587\u6539\u9020\u6458\u8981\uFF1B\u4F7F\u7528\u7ED3\u6784\u5316\u53C2\u6570\u65F6\u5FC5\u586B" },
3509
+ issues: { ...objects, items: { ...object2, properties: {
3510
+ id: text2,
3511
+ evidence: text2,
3512
+ impact: text2,
3513
+ recommendation: text2
3514
+ } } },
3515
+ unresolved: strings,
3516
+ changes: { ...objects, items: { ...object2, properties: {
3517
+ id: text2,
3518
+ path: text2,
3519
+ reason: text2,
3520
+ group: str,
3521
+ content: { ...str, description: "\u5B8C\u6574\u6587\u4EF6\u5185\u5BB9\uFF1B\u5DF2\u901A\u8FC7 opc_delivery_propose_file \u6682\u5B58\u7684\u6587\u4EF6\u7701\u7565\u8BE5\u5B57\u6BB5" },
3522
+ executable: bool
3523
+ } } },
3524
+ contract: { ...object2, description: "\u63D0\u4EA4\u5B8C\u6574\u5951\u7EA6\uFF1B\u4FEE\u6B63\u5176\u4ED6\u5B57\u6BB5\u65F6\u4E5F\u4FDD\u7559\u5DF2\u786E\u5B9A\u7684\u8FD0\u884C\u914D\u7F6E", properties: {
3525
+ schema_version: { type: "integer", required: true, description: "\u5F53\u524D\u4EA4\u4ED8\u5951\u7EA6\u7248\u672C\u4E3A 1" },
3526
+ slug: str,
3527
+ name: text2,
3528
+ description: text2,
3529
+ base_url: str,
3530
+ runtime: { ...object2, required: true, properties: {
3531
+ language: text2,
3532
+ version: text2,
3533
+ port: { type: "integer", required: true, description: `\u5FC5\u987B\u662F\u5411\u5BFC\u5DF2\u9501\u5B9A\u7684\u6570\u5B57 ${port}\uFF0C\u4E0D\u662F\u5B57\u7B26\u4E32\u6216\u5BBF\u4E3B\u673A\u7AEF\u53E3` }
3534
+ } },
3535
+ build_context: { ...strings, required: true },
3536
+ health: { ...object2, required: true, properties: { path: text2, status: { type: "integer", required: true }, json_contains: { ...object2, required: true } } },
3537
+ configs: { ...objects, items: { ...object2, properties: {
3538
+ key: text2,
3539
+ default: text2,
3540
+ secret: { ...bool, required: true },
3541
+ required: { ...bool, required: true },
3542
+ description: str,
3543
+ source: { ...object2, description: "\u4F7F\u7528 path \u548C keys \u5F15\u7528\u6E90\u914D\u7F6E\uFF0C\u7981\u6B62\u5199\u5165\u771F\u5B9E\u79D8\u5BC6\u503C" }
3544
+ } } },
3545
+ resources: objects,
3546
+ storage_mounts: objects,
3547
+ auth_profile: { ...object2, description: "\u4FDD\u7559\u539F\u8BA4\u8BC1\uFF1B\u51ED\u636E\u53EA\u5199\u8FD0\u884C\u65F6\u73AF\u5883\u53D8\u91CF\u540D", properties: {
3548
+ page_auth_required: bool,
3549
+ api_auth_required: bool,
3550
+ username_env: str,
3551
+ password_env: str,
3552
+ token_env: str,
3553
+ login_url: str,
3554
+ login_method: str,
3555
+ token_json_path: str
3556
+ } },
3557
+ auth_profiles: { ...object2, description: "\u6309 ID \u4FDD\u5B58\u767B\u5F55\u65B9\u5F0F\uFF0C\u63A5\u53E3\u901A\u8FC7 auth.profile \u5F15\u7528" },
3558
+ auth_rules: { ...objects, description: "\u6BCF\u6761\u89C4\u5219\u987B\u4E8C\u9009\u4E00\u586B\u5199 path \u6216 prefix\uFF1B\u7CBE\u786E\u89C4\u5219\u4F18\u5148", items: { ...object2, properties: {
3559
+ target: { ...text2, enum: ["api", "page"] },
3560
+ path: str,
3561
+ prefix: str,
3562
+ method: str,
3563
+ auth: { ...object2, required: true, properties: { type: { ...text2, enum: ["none", "header", "bearer"] } } },
3564
+ evidence: { ...strings, required: true, description: '\u8BFB\u53D6\u5DE5\u5177\u8FD4\u56DE\u7684\u6E90\u7801\u4F4D\u7F6E\u6570\u7EC4\uFF0C\u4F8B\u5982 ["server.mjs:42"]' }
3565
+ } } },
3566
+ auth_blockers: { ...objects, description: "\u53EA\u586B\u786E\u5B9E\u963B\u585E\u6539\u9020\u7684\u5916\u90E8\u6388\u6743\u6216\u89D2\u8272\u51B3\u5B9A\uFF1B\u666E\u901A\u9A8C\u8BC1\u51ED\u636E\u5728\u90E8\u7F72\u540E\u586B\u5199", items: { ...object2, properties: {
3567
+ question: text2,
3568
+ evidence: { ...strings, required: true },
3569
+ affected: { ...strings, required: true },
3570
+ action: text2,
3571
+ reason: { ...text2, enum: ["external_authorization", "missing_credential", "role_change"] }
3572
+ } } },
3573
+ apis: { ...objects, description: "\u626B\u63CF\u7ED3\u679C\u7531\u63D2\u4EF6\u5408\u5E76\uFF0C\u53EF\u4EE5\u4F20 [] \u6216\u53EA\u8865\u5145\u9700\u8981\u5B9A\u5236\u7684\u63A5\u53E3", items: { ...object2, properties: {
3574
+ id: text2,
3575
+ method: text2,
3576
+ path: text2,
3577
+ purpose: text2,
3578
+ evidence: { ...strings, required: true },
3579
+ parameters: { ...objects, required: true },
3580
+ request_body: { oneOf: [{ type: "null" }, object2], required: true },
3581
+ responses: { ...object2, required: true },
3582
+ auth: { ...object2, required: true },
3583
+ effect: { ...text2, enum: ["read", "write", "destructive", "external"] },
3584
+ confirmation_required: { ...bool, required: true }
3585
+ } } },
3586
+ pages: { ...objects, description: "\u626B\u63CF\u7ED3\u679C\u7531\u63D2\u4EF6\u5408\u5E76\uFF0C\u53EF\u4EE5\u4F20 [] \u6216\u53EA\u8865\u5145\u9700\u8981\u5B9A\u5236\u7684\u9875\u9762" },
3587
+ verification: object2,
3588
+ unresolved: strings
3589
+ } },
3590
+ decisions: { ...objects, items: { ...object2, properties: {
3591
+ id: text2,
3592
+ question: text2,
3593
+ impact: text2,
3594
+ options: { ...strings, required: true }
3595
+ } } },
3596
+ four_step_report: object2,
3597
+ proposal: { ...str, description: "\u65E7\u7248\u5B8C\u6574\u63D0\u6848 JSON \u5B57\u7B26\u4E32\uFF0C\u4EC5\u5728\u6CA1\u6709\u7ED3\u6784\u5316\u53C2\u6570\u65F6\u4F7F\u7528" }
3598
+ };
3599
+ }
3600
+
3601
+ // src/host/app-agent.ts
3467
3602
  function loadBundledSkillText(relativePath) {
3468
3603
  const fromSrc = fileURLToPath2(new URL(`../../runtime/app_delivery/${relativePath}`, import.meta.url));
3469
3604
  const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
@@ -3541,7 +3676,7 @@ function compactPreviousPlan(proposal) {
3541
3676
  function buildInstructions(isRepair) {
3542
3677
  const skillDoc = loadBundledSkillText("SKILL.md");
3543
3678
  const contractDoc = loadBundledSkillText("references/contract.md");
3544
- let text2 = `${skillDoc}
3679
+ let text3 = `${skillDoc}
3545
3680
  ${contractDoc}
3546
3681
 
3547
3682
  \u4F60\u662F OPC \u5E94\u7528\u6539\u9020\u52A9\u624B\uFF08DSH \u96C6\u6210\u7248\uFF0C\u4E0E Work-OPC \u4FDD\u6301\u540C\u4E00\u5957\u6539\u9020\u89C4\u8303\u4E0E\u4EA4\u4ED8\u5951\u7EA6\uFF09\u3002\u4F7F\u7528\u4E2D\u6587\u3002\u672C\u8F6E\u662F\u53EA\u8BFB\u5206\u6790\u4E0E\u65B9\u6848\u751F\u6210\uFF0C\u53EA\u5206\u6790\u9694\u79BB\u526F\u672C\uFF0C\u4E0D\u8FD0\u884C\u5E94\u7528\u6216\u4F9D\u8D56\uFF0C\u4E0D\u76F4\u63A5\u89E6\u53D1\u90E8\u7F72\u3002
@@ -3556,45 +3691,25 @@ ${contractDoc}
3556
3691
  9. verification.cases \u4E3A\u771F\u5B9E\u53EA\u8BFB\u4E1A\u52A1\u63A2\u9488\uFF08\u6BCF\u79CD\u53D7\u4FDD\u62A4\u8BA4\u8BC1\u8EAB\u4EFD\u5747\u9700\u8986\u76D6\uFF09\uFF0C\u4E0D\u80FD\u7F16\u9020\u4E1A\u52A1\u8BB0\u5F55\u6216\u4EE5\u5065\u5EB7\u63A2\u9488\u4EE3\u66FF\u3002
3557
3692
  10. \u6709\u9700\u8981\u7528\u6237\u51B3\u5B9A\u7684\u771F\u5B9E\u963B\u585E\uFF08\u5982\u5916\u90E8\u8FDE\u63A5\u66FF\u6362\u3001\u7F3A\u5931\u5916\u90E8\u6388\u6743\uFF09\u65F6\u63D0\u4EA4 unresolved\uFF0C\u5E76\u53EF\u5728 decisions \u4E2D\u63D0\u4F9B [{id, question, impact, options}]\uFF08\u6700\u591A 4 \u4E2A\u7B80\u77ED\u9009\u9879\uFF09\uFF1B\u6CA1\u6709\u963B\u585E\u65F6 unresolved \u8BBE\u4E3A\u7A7A\u6570\u7EC4 [] \u5E76\u63D0\u4EA4\u5B8C\u6574\u53EF\u6821\u9A8C\u63D0\u6848\u3002summary \u8BF7\u6309\u591A\u6BB5\u3010\u5E94\u7528\u5B9A\u4F4D\u3011\u3001\u3010\u8FD0\u884C\u73AF\u5883\u3011\u3001\u3010\u63A5\u53E3\u4E0E\u9875\u9762\u3011\u3001\u3010\u767B\u5F55\u4E0E\u9274\u6743\u3011\u3001\u3010\u6570\u636E\u4E0E\u5B58\u50A8\u3011\u3001\u3010\u6539\u9020\u4E0E\u6280\u80FD\u3011\u6E05\u6670\u6362\u884C\u6392\u7248\u3002\u5DE5\u5177\u6821\u9A8C\u5931\u8D25\u5E94\u4FEE\u6B63\u540E\u91CD\u63D0\uFF0C\u63D0\u4EA4\u6210\u529F\u540E\u7ED3\u675F\u672C\u8F6E\u3002`;
3558
3693
  if (isRepair) {
3559
- text2 += `
3694
+ text3 += `
3560
3695
  DEPLOYMENT REPAIR\uFF08\u90E8\u7F72/\u9A8C\u8BC1\u5931\u8D25\u4E13\u9879\u4FEE\u590D\uFF09\uFF1A\u5FC5\u987B\u5148\u8C03\u7528 opc_delivery_inspect \u7684 read_failed \u8BFB\u53D6\u4E0A\u6B21\u5B9E\u9645\u90E8\u7F72\u5305\u4E2D\u7684\u51FA\u9519\u6587\u4EF6\uFF0C\u5E76\u4E0E read \u539F\u6E90\u7801\u5BF9\u6BD4\u3002\u65E7\u4FEE\u6539\u53EF\u80FD\u662F\u9519\u8BEF\u7684\uFF0C\u4E0D\u80FD\u65E0\u4F9D\u636E\u590D\u7528\u65E7\u63D0\u6848\uFF1B\u9488\u5BF9\u8BED\u6CD5\u9519\u8BEF\u3001\u7F3A\u6A21\u5757\u6216\u542F\u52A8\u5931\u8D25\u5FC5\u987B\u4FEE\u6539\u5BF9\u5E94\u6587\u4EF6\u5E76\u63D0\u4EA4\u5B8C\u6574\u66FF\u6362\u5185\u5BB9\u3002`;
3561
3696
  }
3562
- return text2;
3697
+ return text3;
3563
3698
  }
3564
3699
  function attachAppAgent(ctx, delivery) {
3565
- delivery.analyze = async (job, root, feedback, signal) => {
3700
+ delivery.analyze = async (job, root, feedback, signal, onSessionReady) => {
3566
3701
  const parent = ctx.agents.get(job.session);
3567
- if (!parent) throw new Error("\u8BF7\u5148\u5728\u5F53\u524D\u5DE5\u4F5C\u533A\u521B\u5EFA\u5BF9\u8BDD\uFF0C\u518D\u6253\u5F00 OPC \u5E94\u7528\u8FDB\u884C\u5206\u6790");
3568
3702
  const configured = job.modelSelection;
3569
3703
  const selection = configured ? {
3570
3704
  provider: configured.provider,
3571
3705
  model: configured.model,
3572
3706
  reasoningEffort: configured.reasoningEffort ? ReasoningEffortId(configured.reasoningEffort) : void 0
3573
- } : parent.model.current() ?? parent.session.requestHeader()?.config;
3707
+ } : parent?.model.current() ?? parent?.session.requestHeader()?.config;
3574
3708
  const appCtxId = delivery.core.auth.contexts.applicationContextId;
3575
- const previous = job.published ? await delivery.platform("/" + job.slug, appCtxId).catch(() => void 0) : void 0;
3576
- const runtimeLogs = job.published ? await delivery.platform("/" + job.slug + "/logs", appCtxId).catch(() => void 0) : void 0;
3577
- const rawResources = await delivery.platform("/resources", appCtxId).catch(() => ({ resources: [] }));
3578
- const filteredRes = await worker({
3579
- action: "filter_resources",
3580
- root,
3581
- resources: rawResources?.resources ?? [],
3582
- slug: job.slug,
3583
- default_only: true
3584
- }, signal).catch(() => ({ resources: [] }));
3585
3709
  const isRepair = Boolean(job.failedRevision || job.failedSnapshot || job.failureContext || job.analysisMode === "repair");
3586
- if (isRepair || previous?.error_message || previous?.build_log || runtimeLogs?.runtime_logs) {
3587
- const mergedFailure = [
3588
- job.failureContext,
3589
- previous?.error_message,
3590
- previous?.build_log?.slice(-8e3),
3591
- runtimeLogs?.runtime_logs?.slice(-4e3)
3592
- ].filter(Boolean).join("\n");
3593
- if (mergedFailure) {
3594
- job.failureContext = await worker({ action: "redact_feedback", root, text: mergedFailure.slice(-24e3) }, signal);
3595
- }
3596
- }
3597
- const instructions = buildInstructions(isRepair);
3710
+ const port = job.port ?? 8080;
3711
+ const instructions = buildInstructions(isRepair) + `
3712
+ \u672C\u4EFB\u52A1\u5BB9\u5668\u7AEF\u53E3\u5DF2\u9501\u5B9A\u4E3A ${port}\u3002\u6BCF\u6B21\u8C03\u7528 opc_delivery_submit \u90FD\u8981\u63D0\u4EA4\u5B8C\u6574\u5951\u7EA6\uFF0C\u5305\u62EC contract.runtime \u7684 language\u3001version \u548C\u6570\u5B57 port=${port}\u3002\u4FEE\u6B63\u5355\u4E2A\u5B57\u6BB5\u65F6\uFF0C\u5408\u5E76\u5230\u5B8C\u6574\u63D0\u6848\u540E\u518D\u63D0\u4EA4\u3002issues \u6BCF\u9879\u8981\u6709 id\u3001evidence\u3001impact\u3001recommendation\uFF1Bauth_rules \u6BCF\u9879\u8981\u6709 target=api/page\u3001path \u6216 prefix\u3001auth \u548C\u6E90\u7801\u4F4D\u7F6E\u6570\u7EC4 evidence\u3002\u63A5\u53E3\u548C\u9875\u9762\u53EF\u4EE5\u7528\u7A7A\u6570\u7EC4\u4EA4\u7ED9\u540E\u7AEF\u5408\u5E76\u3002\u5927\u6587\u4EF6\u5355\u72EC\u6682\u5B58\uFF0C\u6C47\u603B\u53EA\u5F15\u7528\u53D8\u66F4 ID\u3002`;
3598
3713
  const prevPlan = compactPreviousPlan(job.proposal);
3599
3714
  const taskInstruction = isRepair ? "\u90E8\u7F72\u5931\u8D25\u4E13\u9879\u4FEE\u590D\uFF1A\u8BFB\u53D6\u5B9E\u9645\u5931\u8D25\u5236\u54C1\u4E0E\u539F\u59CB\u6E90\u7801\uFF0C\u5BF9\u6BD4\u65E7\u4FEE\u6539\uFF0C\u4FEE\u590D\u6839\u56E0\u3002\u4E0D\u80FD\u628A\u672C\u8F6E\u5F53\u6210\u914D\u7F6E\u786E\u8BA4\uFF0C\u4E0D\u80FD\u65E0\u4F9D\u636E\u590D\u7528\u9519\u8BEF\u4EE3\u7801\u3002" : prevPlan && feedback.trim() ? "\u8FD9\u662F\u57FA\u4E8E\u4E0A\u4E00\u8F6E\u5206\u6790\u7ED3\u679C\uFF08previous_plan\uFF09\u7684\u7528\u6237\u786E\u8BA4/\u8865\u5145\u8F6E\u6B21\u3002\u4E0A\u4E00\u8F6E\u6682\u5B58\u7684\u6587\u4EF6\u4FEE\u6539\uFF08changes\uFF09\u5DF2\u9884\u8F7D\u5165\u6682\u5B58\u533A\uFF08\u672A\u6539\u52A8\u7684\u6587\u4EF6\u53EF\u76F4\u63A5\u6309\u539F id \u5F15\u7528\uFF0C\u65E0\u9700\u91CD\u590D\u8BFB\u53D6\u6E90\u7801\u6216\u91CD\u65B0\u8C03\u7528 propose_file\uFF09\uFF0C\u626B\u63CF\u7684\u5168\u90E8\u63A5\u53E3\u4E0E\u9875\u9762\u4E5F\u5DF2\u7531\u540E\u7AEF\u7F13\u5B58\u5E76\u81EA\u52A8\u5408\u5E76\u3002\u8BF7\u4EC5\u9488\u5BF9 user_answers \u8FDB\u884C\u5FC5\u8981\u7684\u589E\u91CF\u8C03\u6574\u5E76\u76F4\u63A5\u8C03\u7528 opc_delivery_submit\uFF08unresolved \u4EC5\u4FDD\u7559\u771F\u6B63\u963B\u585E\u6539\u9020\u7684\u4E8B\u9879\uFF09\u3002\u672C\u8F6E summary \u53EA\u9700\u7B80\u660E\u8BF4\u660E\u5DF2\u6309\u7528\u6237\u786E\u8BA4\u5B8C\u6210\u4E86\u54EA\u4E9B\u8C03\u6574\uFF0C\u4E25\u7981\u91CD\u590D\u8F93\u51FA\u5168\u91CF\u6478\u5E95\u5185\u5BB9\uFF01" : "\u5206\u6790\u5E94\u7528\u5E76\u63D0\u4EA4\u5B8C\u6574\u4FEE\u6539\u63D0\u6848\u548C\u4E1A\u52A1\u5951\u7EA6\u3002\u5148\u8C03\u7528 scan_routes_and_pages \u4E0E\u8BFB\u53D6\u6E90\u7801\u5DE5\u5177\u5168\u9762\u6478\u6E05\u5E94\u7528\uFF0C\u5B8C\u6574\u6536\u5F55\u6240\u6709\u9875\u9762\u4E0E\u6240\u6709\u63A5\u53E3\uFF0C\u6309\u56DB\u6B65\u89C4\u8303\u5206\u6BB5\u6E05\u6670\u8F93\u51FA\u5206\u6790\u4E0E\u6539\u9020\u65B9\u6848\u3002";
3600
3715
  const abort = AbortSignal.any([signal, AbortSignal.timeout(15 * 6e4)]);
@@ -3609,10 +3724,9 @@ function attachAppAgent(ctx, delivery) {
3609
3724
  }
3610
3725
  } catch {
3611
3726
  }
3612
- const handle = await ctx.agents.create({
3613
- sessionId: randomUUID5(),
3614
- meta: { cwd: root },
3615
- agentOptions: selection ? { provider: selection.provider, model: selection.model, reasoningEffort: selection.reasoningEffort } : { ...parent.options },
3727
+ const agentOptions = selection ? { provider: selection.provider, model: selection.model, reasoningEffort: selection.reasoningEffort } : { ...parent?.options };
3728
+ const options = {
3729
+ agentOptions,
3616
3730
  signal: abort,
3617
3731
  setup(child) {
3618
3732
  child.tools.restrict({ allow: [] });
@@ -3678,16 +3792,7 @@ function attachAppAgent(ctx, delivery) {
3678
3792
  child.tools.register(defineTool2({
3679
3793
  name: "opc_delivery_submit",
3680
3794
  description: "\u4EE5\u7ED3\u6784\u5316\u5B57\u6BB5\u63D0\u4EA4\u5B8C\u6574\u6539\u9020\u63D0\u6848\u3002\u82E5\u5DF2\u6682\u5B58\u6587\u4EF6\uFF0Cchanges \u53EF\u4EC5\u4F20 {id, path, reason, group}\u3002\u65E7\u7248\u53EF\u7528 proposal JSON \u5B57\u7B26\u4E32\u3002",
3681
- parameters: {
3682
- summary: { type: "string" },
3683
- issues: { type: "array", items: { type: "object", additionalProperties: true } },
3684
- unresolved: { type: "array", items: { type: "string" } },
3685
- changes: { type: "array", items: { type: "object", additionalProperties: true } },
3686
- contract: { type: "object", additionalProperties: true },
3687
- decisions: { type: "array", items: { type: "object", additionalProperties: true } },
3688
- four_step_report: { type: "object", additionalProperties: true },
3689
- proposal: { type: "string" }
3690
- },
3795
+ parameters: proposalParameters(port),
3691
3796
  output,
3692
3797
  async execute(args) {
3693
3798
  if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
@@ -3698,17 +3803,20 @@ function attachAppAgent(ctx, delivery) {
3698
3803
  try {
3699
3804
  const { proposal, ...fields } = args;
3700
3805
  candidate = proposal ? JSON.parse(proposal) : { issues: [], unresolved: [], changes: [], decisions: [], ...fields };
3806
+ if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) throw new Error("\u63D0\u6848\u5FC5\u987B\u662F\u5B8C\u6574\u7684 JSON \u5BF9\u8C61");
3701
3807
  if (candidate && typeof candidate.contract === "object" && candidate.contract !== null) {
3702
3808
  candidate.contract = { ...candidate.contract, slug: job.slug, base_url: job.url };
3703
3809
  }
3704
3810
  await delivery.submit(job, root, candidate, abort);
3705
3811
  } catch (error) {
3706
- const detail = await worker({ action: "redact_feedback", root, text: String(error).slice(0, 1e3) }, abort);
3812
+ const message = error instanceof Error ? error.message : String(error);
3813
+ const detail = await worker({ action: "redact_feedback", root, text: message.slice(0, 1e3) }, abort);
3707
3814
  validationErrors.push(detail);
3708
3815
  job.analysisFailure = detail;
3709
3816
  if (candidate) {
3710
3817
  const rej = fingerprint({
3711
3818
  contract: candidate.contract,
3819
+ issues: candidate.issues,
3712
3820
  changes: candidate.changes,
3713
3821
  unresolved: candidate.unresolved,
3714
3822
  decisions: candidate.decisions,
@@ -3729,30 +3837,76 @@ function attachAppAgent(ctx, delivery) {
3729
3837
  }
3730
3838
  }));
3731
3839
  }
3840
+ };
3841
+ const previousSessionId = job.analysisSessions?.at(-1);
3842
+ let handle;
3843
+ if (previousSessionId && !ctx.agents.get(previousSessionId)) {
3844
+ try {
3845
+ handle = await ctx.agents.resume({ ...options, resumeSessionId: previousSessionId });
3846
+ } catch {
3847
+ abort.throwIfAborted();
3848
+ }
3849
+ }
3850
+ const analysis = handle ?? await ctx.agents.create({
3851
+ ...options,
3852
+ sessionId: randomUUID5(),
3853
+ meta: { cwd: root }
3854
+ });
3855
+ const turnOutcome = {};
3856
+ const getTurnOutcome = () => ({ ...turnOutcome });
3857
+ const stopObserving = ctx.on("session/event", (session, event) => {
3858
+ if (session !== analysis.agent.session || event.type !== "turn/end") return;
3859
+ const reason = event.data.reason;
3860
+ turnOutcome.failure = reason.kind === "error" ? reason.error : void 0;
3861
+ turnOutcome.truncated = reason.kind === "max-tokens";
3732
3862
  });
3733
3863
  const cancel = () => {
3734
- handle.agent.cancel({ kind: "user" });
3864
+ analysis.agent.cancel({ kind: "user" });
3735
3865
  };
3736
3866
  abort.addEventListener("abort", cancel, { once: true });
3737
- const send = (text2) => {
3738
- handle.agent.followup({
3867
+ const send = (text3) => {
3868
+ analysis.agent.followup({
3739
3869
  id: randomUUID5(),
3740
3870
  role: "user",
3741
3871
  source: { kind: "user" },
3742
3872
  content: [{
3743
3873
  type: "text",
3744
- text: text2
3874
+ text: text3
3745
3875
  }]
3746
3876
  });
3747
3877
  };
3748
3878
  try {
3879
+ abort.throwIfAborted();
3880
+ await onSessionReady(String(analysis.agent.session.id));
3881
+ abort.throwIfAborted();
3882
+ const previous = job.published ? await delivery.platform("/" + job.slug, appCtxId).catch(() => void 0) : void 0;
3883
+ const runtimeLogs = job.published ? await delivery.platform("/" + job.slug + "/logs", appCtxId).catch(() => void 0) : void 0;
3884
+ const rawResources = await delivery.platform("/resources", appCtxId).catch(() => ({ resources: [] }));
3885
+ const filteredRes = await worker({
3886
+ action: "filter_resources",
3887
+ root,
3888
+ resources: rawResources?.resources ?? [],
3889
+ slug: job.slug,
3890
+ default_only: true
3891
+ }, signal).catch(() => ({ resources: [] }));
3892
+ if (isRepair || previous?.error_message || previous?.build_log || runtimeLogs?.runtime_logs) {
3893
+ const mergedFailure = [
3894
+ job.failureContext,
3895
+ previous?.error_message,
3896
+ previous?.build_log?.slice(-8e3),
3897
+ runtimeLogs?.runtime_logs?.slice(-4e3)
3898
+ ].filter(Boolean).join("\n");
3899
+ if (mergedFailure) {
3900
+ job.failureContext = await worker({ action: "redact_feedback", root, text: mergedFailure.slice(-24e3) }, signal);
3901
+ }
3902
+ }
3749
3903
  abort.throwIfAborted();
3750
3904
  let prompt = JSON.stringify({
3751
3905
  name: job.name,
3752
3906
  description: job.description ?? "",
3753
3907
  slug: job.slug,
3754
3908
  base_url: job.url,
3755
- container_port: job.port ?? 8080,
3909
+ container_port: port,
3756
3910
  available_resource_metadata: filteredRes?.resources ?? [],
3757
3911
  user_answers: job.feedbackHistory || feedback,
3758
3912
  feedback,
@@ -3765,26 +3919,29 @@ function attachAppAgent(ctx, delivery) {
3765
3919
  task: taskInstruction
3766
3920
  });
3767
3921
  for (let attempt = 0; attempt < 3; attempt++) {
3768
- let transientError = "";
3922
+ turnOutcome.failure = void 0;
3923
+ turnOutcome.truncated = false;
3924
+ let errorMessage = "";
3769
3925
  try {
3770
3926
  send(prompt);
3771
- await handle.agent.whenIdle();
3927
+ await analysis.agent.whenIdle();
3772
3928
  } catch (err) {
3773
3929
  if (signal.aborted || abort.aborted && !repeatedProposal) throw err;
3774
- const msg = err instanceof Error ? err.message : String(err);
3775
- if (/(?:timed?\s*out|timeout|connection\s*reset|ECONNRESET|ETIMEDOUT|fetch failed|network|terminated)/i.test(msg)) {
3776
- transientError = msg.slice(0, 1e3);
3777
- } else if (!repeatedProposal) {
3778
- throw err;
3779
- }
3930
+ errorMessage = err instanceof Error ? err.message : String(err);
3780
3931
  }
3781
3932
  if (job.status === "review") return;
3782
3933
  if (repeatedProposal || validationErrors.length >= 6) {
3783
3934
  throw new Error(validationErrors.at(-1) ?? "\u6280\u672F\u65B9\u6848\u8FDE\u7EED\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u5DF2\u505C\u6B62\u81EA\u52A8\u91CD\u8BD5");
3784
3935
  }
3785
3936
  abort.throwIfAborted();
3786
- const reason = transientError || validationErrors.at(-1) || "AI \u5C1A\u672A\u63D0\u4EA4\u5B8C\u6574\u63D0\u6848";
3937
+ const { failure, truncated } = getTurnOutcome();
3938
+ const providerMessage = failure?.message ?? errorMessage;
3939
+ const badToolJson = /tool input is invalid JSON/i.test(providerMessage);
3940
+ const invalidOutput = badToolJson || truncated;
3941
+ const networkError = /(?:timed?\s*out|timeout|connection\s*reset|ECONNRESET|ETIMEDOUT|fetch failed|network|terminated)/i.test(providerMessage);
3942
+ const reason = invalidOutput ? badToolJson ? "\u6A21\u578B\u8FD4\u56DE\u7684\u5DE5\u5177\u53C2\u6570\u4E0D\u662F\u5408\u6CD5 JSON" : "\u6A21\u578B\u8F93\u51FA\u8FBE\u5230\u957F\u5EA6\u4E0A\u9650" : providerMessage ? await worker({ action: "redact_feedback", root, text: providerMessage.slice(0, 1e3) }, abort) : validationErrors.at(-1) || "AI \u5C1A\u672A\u63D0\u4EA4\u5B8C\u6574\u63D0\u6848";
3787
3943
  job.analysisFailure = reason;
3944
+ if (providerMessage && !invalidOutput && !networkError) throw new Error(reason);
3788
3945
  if (attempt === 2) {
3789
3946
  if (/(?:timed?\s*out|timeout|AI.*超时)/i.test(reason)) {
3790
3947
  throw new Error("AI \u5206\u6790\u8D85\u65F6\uFF0C\u539F\u6E90\u7801\u548C\u5DF2\u6709\u56DE\u7B54\u5DF2\u4FDD\u7559\u3002\u8BF7\u91CD\u8BD5\u5206\u6790\u3002");
@@ -3794,13 +3951,14 @@ function attachAppAgent(ctx, delivery) {
3794
3951
  }
3795
3952
  throw new Error(reason);
3796
3953
  }
3797
- job.events.push(transientError ? `\u{1F504} AI \u670D\u52A1\u6682\u65F6\u4E2D\u65AD\uFF0C\u6B63\u5728\u7EE7\u7EED\u51C6\u5907\uFF08${attempt + 1}/2\uFF09` : `\u{1F504} \u6B63\u5728\u4FEE\u6B63\u5E94\u7528\u51C6\u5907\u68C0\u67E5\uFF08${attempt + 1}/2\uFF09`);
3954
+ job.events.push(invalidOutput ? `\u{1F504} ${reason}\uFF0C\u6B63\u5728\u7F29\u77ED\u63D0\u4EA4\u5185\u5BB9\u540E\u91CD\u8BD5\uFF08${attempt + 1}/2\uFF09` : networkError ? `\u{1F504} AI \u670D\u52A1\u6682\u65F6\u4E2D\u65AD\uFF0C\u6B63\u5728\u7EE7\u7EED\u51C6\u5907\uFF08${attempt + 1}/2\uFF09` : `\u{1F504} \u6B63\u5728\u4FEE\u6B63\u5E94\u7528\u51C6\u5907\u68C0\u67E5\uFF08${attempt + 1}/2\uFF09`);
3798
3955
  delivery.core.emit("change");
3799
- prompt = `\u7EE7\u7EED\u5F53\u524D\u4EFB\u52A1\uFF0C\u4FDD\u7559\u539F\u4E1A\u52A1\u548C\u7528\u6237\u9009\u62E9\u3002\u5F85\u5904\u7406\u7684\u6280\u672F\u53CD\u9988\uFF1A${reason}\u3002\u590D\u7528\u5DF2\u6682\u5B58\u7684\u6587\u4EF6\u4FEE\u6539\uFF0C\u53EA\u4FEE\u6B63\u672A\u901A\u8FC7\u7684\u90E8\u5206\uFF0C\u518D\u7528 opc_delivery_submit \u63D0\u4EA4\u5B8C\u6574\u7ED3\u6784\u5316\u7ED3\u679C\u3002`;
3956
+ prompt = `\u7EE7\u7EED\u5F53\u524D\u4EFB\u52A1\uFF0C\u4FDD\u7559\u539F\u4E1A\u52A1\u548C\u7528\u6237\u9009\u62E9\u3002\u5F85\u5904\u7406\u7684\u6280\u672F\u53CD\u9988\uFF1A${reason}\u3002\u53EA\u4FEE\u6B63\u672A\u901A\u8FC7\u7684\u5B57\u6BB5\uFF0C\u518D\u63D0\u4EA4\u5B8C\u6574\u5951\u7EA6\uFF0C\u5FC5\u987B\u4FDD\u7559 runtime \u5E76\u586B\u5199\u6570\u5B57 port=${port}\u3002\u5927\u6587\u4EF6\u5148\u5355\u72EC\u6682\u5B58\uFF0Cchanges \u53EA\u4F20 ID\u3001\u8DEF\u5F84\u548C\u7406\u7531\uFF1Bapis/pages \u53EA\u4F20\u5B9A\u5236\u9879\uFF0C\u5176\u4F59\u8BA9\u540E\u7AEF\u5408\u5E76\u3002\u7528\u7ED3\u6784\u5316\u53C2\u6570\u8C03\u7528 opc_delivery_submit\uFF0C\u4E0D\u8981\u5728\u4E00\u4E2A\u5B57\u7B26\u4E32\u4E2D\u5D4C\u5957\u6574\u4EFD JSON\u3002`;
3800
3957
  }
3801
3958
  } finally {
3959
+ stopObserving();
3802
3960
  abort.removeEventListener("abort", cancel);
3803
- await handle.dispose();
3961
+ await analysis.dispose();
3804
3962
  }
3805
3963
  };
3806
3964
  ctx.effect(() => () => {
@@ -3897,6 +4055,7 @@ import { z } from "zod";
3897
4055
  var contribution = { package: "dsh-plugin-opc", descriptors: [
3898
4056
  { id: "dsh-plugin-opc#opc/appList", service: "opc", namespace: "opc", method: "appList", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appList:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appList:result", create: () => z.string() } },
3899
4057
  { id: "dsh-plugin-opc#opc/appJob", service: "opc", namespace: "opc", method: "appJob", invocation: { kind: "direct" }, parameters: [{ name: "id", wire: "id", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJob:id", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJob:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appJob:result", create: () => z.string() } },
4058
+ { id: "dsh-plugin-opc#opc/appJobByAnalysisSession", service: "opc", namespace: "opc", method: "appJobByAnalysisSession", invocation: { kind: "direct" }, parameters: [{ name: "sessionId", wire: "sessionId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:sessionId", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:result", create: () => z.string() } },
3900
4059
  { id: "dsh-plugin-opc#opc/appCheckSlug", service: "opc", namespace: "opc", method: "appCheckSlug", invocation: { kind: "direct" }, parameters: [{ name: "slug", wire: "slug", source: "json", codec: { mode: "strict", typeSymbol: "opc/appCheckSlug:slug", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appCheckSlug:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appCheckSlug:result", create: () => z.string() } },
3901
4060
  { id: "dsh-plugin-opc#opc/appOpcConfig", service: "opc", namespace: "opc", method: "appOpcConfig", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appOpcConfig:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appOpcConfig:result", create: () => z.string() } },
3902
4061
  { id: "dsh-plugin-opc#opc/appPickSourceFolder", service: "opc", namespace: "opc", method: "appPickSourceFolder", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appPickSourceFolder:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appPickSourceFolder:result", create: () => z.string() } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-opc",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "OPC Enterprise Plugin for DeepSeek Harness (DSH)",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -9,18 +9,25 @@ def resolve_authentication(contract):
9
9
  rules = contract.get('auth_rules', [])
10
10
  if not isinstance(rules, list):
11
11
  raise ValueError('auth_rules 必须是数组')
12
- for rule in rules:
13
- if not isinstance(rule, dict) or rule.get('target') not in {'api', 'page'} or not rule.get('evidence'):
14
- raise ValueError('认证规则必须声明 api/page 范围与源码证据')
15
- if not isinstance(rule.get('auth'), dict) or rule['auth'].get('type') not in {'none', 'header', 'bearer'}:
16
- raise ValueError('认证规则必须使用已确认的 none/header/bearer 方式')
12
+ for index, rule in enumerate(rules):
13
+ field = f'auth_rules[{index}]'
14
+ if not isinstance(rule, dict):
15
+ raise ValueError(f'{field} 必须是对象')
16
+ if rule.get('target') not in ('api', 'page'):
17
+ raise ValueError(f'{field}.target 必须填写 api 或 page')
18
+ if not rule.get('evidence'):
19
+ raise ValueError(f'{field}.evidence 缺少源码证据,请引用读取工具返回的 文件:行号')
20
+ if not isinstance(rule.get('auth'), dict) or rule['auth'].get('type') not in ('none', 'header', 'bearer'):
21
+ raise ValueError(f'{field}.auth.type 必须使用已确认的 none/header/bearer 方式')
17
22
  if not isinstance(rule.get('evidence'), list) or not all(isinstance(e, str) and e for e in rule['evidence']):
18
- raise ValueError('认证规则 evidence 必须是源码位置数组')
19
- location = rule.get('path') or rule.get('prefix')
20
- if not isinstance(location, str) or not location.startswith('/'):
21
- raise ValueError('认证规则路径必须以 / 开头')
23
+ raise ValueError(f'{field}.evidence 必须是源码位置数组')
24
+ for key in ('path', 'prefix'):
25
+ if key in rule and (not isinstance(rule[key], str) or not rule[key].startswith('/')):
26
+ raise ValueError(f'{field}.{key} 必须是以 / 开头的路径')
22
27
  if bool(rule.get('path')) == bool(rule.get('prefix')):
23
- raise ValueError('认证规则必须选择精确 path 或路径 prefix')
28
+ raise ValueError(f'{field} 必须选择精确 path 或路径 prefix')
29
+ if 'method' in rule and not isinstance(rule['method'], str):
30
+ raise ValueError(f'{field}.method 必须是字符串')
24
31
  for target, key in [('api', 'apis'), ('page', 'pages')]:
25
32
  for item in contract.get(key, []):
26
33
  matches = [r for r in rules if r['target'] == target
package/runtime/worker.py CHANGED
@@ -100,6 +100,28 @@ def compute_change_diffs(source: Path, changes: list[dict]) -> dict[str, str]:
100
100
  return diffs
101
101
 
102
102
 
103
+ def save_draft_files(path: Path, drafts: dict) -> None:
104
+ # A cancelled worker must leave the previous complete checkpoint readable.
105
+ with tempfile.NamedTemporaryFile(dir=path.parent, prefix="draft-files-", mode="w", encoding="utf-8", delete=False) as tmp:
106
+ tmp_path = Path(tmp.name)
107
+ try:
108
+ json.dump(drafts, tmp, ensure_ascii=False, indent=2)
109
+ tmp.write("\n")
110
+ tmp.close()
111
+ tmp_path.replace(path)
112
+ finally:
113
+ tmp_path.unlink(missing_ok=True)
114
+
115
+
116
+ def retain_proposal_changes(root: Path, proposal: dict) -> None:
117
+ draft_path = root / "draft_files.json"
118
+ drafts = load_json_if_exists(draft_path, {})
119
+ for change in proposal.get("changes", []):
120
+ if change.get("id") and change.get("path") and isinstance(change.get("content"), str):
121
+ drafts[change["id"]] = dict(change)
122
+ save_draft_files(draft_path, drafts)
123
+
124
+
103
125
  def resolve_and_enrich_proposal(
104
126
  root: Path,
105
127
  proposal: dict,
@@ -114,9 +136,11 @@ def resolve_and_enrich_proposal(
114
136
  d.require(isinstance(proposal, dict) and isinstance(proposal.get("summary"), str) and proposal["summary"].strip(), "提案缺少摘要")
115
137
  for field in ("issues", "changes", "unresolved"):
116
138
  d.require(isinstance(proposal.get(field, []), list), "提案列表字段无效:" + field)
117
- for issue in proposal.get("issues", []):
118
- d.require(isinstance(issue, dict) and all(issue.get(key) for key in ("id", "evidence", "impact", "recommendation")),
119
- "每项问题都需要 ID、证据、影响和建议")
139
+ for index, issue in enumerate(proposal.get("issues", [])):
140
+ d.require(isinstance(issue, dict), f"issues[{index}] 必须是对象")
141
+ missing = [key for key in ("id", "evidence", "impact", "recommendation")
142
+ if not isinstance(issue.get(key), str) or not issue[key].strip()]
143
+ d.require(not missing, f"issues[{index}] 缺少有效字段:{', '.join(missing)}")
120
144
  d.require(isinstance(proposal.get("contract"), dict), "业务契约必须是对象")
121
145
  source = root / "review/source"
122
146
  draft_files = load_json_if_exists(root / "draft_files.json", {})
@@ -129,10 +153,12 @@ def resolve_and_enrich_proposal(
129
153
  if change.get("path") and staged.get("path") and change["path"] != staged["path"]:
130
154
  raise ValueError("汇总提案的文件路径与分项提案不一致")
131
155
  change = {**staged, **change}
132
- elif change.get("path"):
156
+ elif not change.get("id") and change.get("path"):
133
157
  by_path = next((v for v in draft_files.values() if isinstance(v, dict) and v.get("path") == change["path"]), None)
134
158
  if by_path:
135
159
  change = {**by_path, **change}
160
+ if "content" not in change:
161
+ raise ValueError(f"changes[{idx}] 没有文件内容。请使用已暂存的修改 ID,或先单独暂存该文件")
136
162
  if isinstance(change, dict) and not change.get("id"):
137
163
  change = {**change, "id": change.get("path") or f"change-{idx + 1}"}
138
164
  if isinstance(change, dict) and not change.get("reason"):
@@ -435,7 +461,7 @@ def main(body):
435
461
  if cid in drafts and drafts[cid].get("path") != change["path"]:
436
462
  raise ValueError("同一修改 ID 不能对应不同文件")
437
463
  drafts[cid] = change
438
- d.save(draft_path, drafts)
464
+ save_draft_files(draft_path, drafts)
439
465
  return {"staged": cid, "path": change["path"], "message": f"File proposal recorded: {cid}. Source is unchanged."}
440
466
  if action == "validate":
441
467
  proposal = body["proposal"]
@@ -458,6 +484,7 @@ def main(body):
458
484
  )
459
485
  diffs = compute_change_diffs(source_dir, proposal.get("changes", []))
460
486
  _, has_orig = extract_original_config_values(source_dir, (proposal.get("contract") or {}).get("configs", []))
487
+ retain_proposal_changes(root, proposal)
461
488
  return {
462
489
  "valid": True,
463
490
  "proposal": proposal,
@@ -481,13 +508,7 @@ def main(body):
481
508
  )
482
509
  d.bundle_work(temp_path / "approved", temp_path / "bundle")
483
510
  syntax_check = check_archive_syntax(temp_path / "bundle/app.tar")
484
- # Persist staged files for future rounds
485
- draft_path = root / "draft_files.json"
486
- drafts = load_json_if_exists(draft_path, {})
487
- for ch in proposal.get("changes", []):
488
- if isinstance(ch, dict) and ch.get("id") and ch.get("path") and isinstance(ch.get("content"), str):
489
- drafts[ch["id"]] = dict(ch)
490
- d.save(draft_path, drafts)
511
+ retain_proposal_changes(root, proposal)
491
512
  diffs = compute_change_diffs(source_dir, proposal.get("changes", []))
492
513
  _, has_orig = extract_original_config_values(source_dir, (proposal.get("contract") or {}).get("configs", []))
493
514
  return {