dsh-plugin-opc 0.1.12 → 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/index.js +152 -35
- package/package.json +1 -1
- package/runtime/app_delivery_auth.py +17 -10
- package/runtime/worker.py +33 -12
package/lib/index.js
CHANGED
|
@@ -1976,7 +1976,7 @@ function worker(input, signal) {
|
|
|
1976
1976
|
if (!result.ok) throw new Error(result.error);
|
|
1977
1977
|
resolve(result.value);
|
|
1978
1978
|
} catch (error) {
|
|
1979
|
-
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)}`));
|
|
1980
1980
|
}
|
|
1981
1981
|
});
|
|
1982
1982
|
child.stdin.on("error", () => {
|
|
@@ -2519,12 +2519,10 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2519
2519
|
const controller = new AbortController();
|
|
2520
2520
|
const analysisSignal = AbortSignal.any([scope.signal, controller.signal]);
|
|
2521
2521
|
this.analyses.set(id, controller);
|
|
2522
|
-
if (!resume) {
|
|
2522
|
+
if (!resume && job.status !== "failed") {
|
|
2523
2523
|
job.analysisFailure = void 0;
|
|
2524
|
-
if (!job.proposal) {
|
|
2525
|
-
|
|
2526
|
-
});
|
|
2527
|
-
}
|
|
2524
|
+
if (!job.proposal) await rm2(join3(root, "draft_files.json"), { force: true }).catch(() => {
|
|
2525
|
+
});
|
|
2528
2526
|
}
|
|
2529
2527
|
if (!resume && (options?.mode === "repair" || job.revision && (job.published || job.status === "failed"))) {
|
|
2530
2528
|
job.analysisMode = "repair";
|
|
@@ -2717,7 +2715,14 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2717
2715
|
throw new Error("unresolved \u5FC5\u987B\u4E3A\u6570\u7EC4");
|
|
2718
2716
|
}
|
|
2719
2717
|
const hasQuestions = Boolean(proposal.unresolved.length || proposal.contract.unresolved?.length);
|
|
2720
|
-
if (!hasQuestions
|
|
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
|
+
}
|
|
2721
2726
|
const validated = await worker({
|
|
2722
2727
|
action: "validate",
|
|
2723
2728
|
root,
|
|
@@ -3490,6 +3495,110 @@ import { join as join4 } from "node:path";
|
|
|
3490
3495
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3491
3496
|
import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
|
|
3492
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
|
|
3493
3602
|
function loadBundledSkillText(relativePath) {
|
|
3494
3603
|
const fromSrc = fileURLToPath2(new URL(`../../runtime/app_delivery/${relativePath}`, import.meta.url));
|
|
3495
3604
|
const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
|
|
@@ -3567,7 +3676,7 @@ function compactPreviousPlan(proposal) {
|
|
|
3567
3676
|
function buildInstructions(isRepair) {
|
|
3568
3677
|
const skillDoc = loadBundledSkillText("SKILL.md");
|
|
3569
3678
|
const contractDoc = loadBundledSkillText("references/contract.md");
|
|
3570
|
-
let
|
|
3679
|
+
let text3 = `${skillDoc}
|
|
3571
3680
|
${contractDoc}
|
|
3572
3681
|
|
|
3573
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
|
|
@@ -3582,10 +3691,10 @@ ${contractDoc}
|
|
|
3582
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
|
|
3583
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`;
|
|
3584
3693
|
if (isRepair) {
|
|
3585
|
-
|
|
3694
|
+
text3 += `
|
|
3586
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`;
|
|
3587
3696
|
}
|
|
3588
|
-
return
|
|
3697
|
+
return text3;
|
|
3589
3698
|
}
|
|
3590
3699
|
function attachAppAgent(ctx, delivery) {
|
|
3591
3700
|
delivery.analyze = async (job, root, feedback, signal, onSessionReady) => {
|
|
@@ -3598,7 +3707,9 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3598
3707
|
} : parent?.model.current() ?? parent?.session.requestHeader()?.config;
|
|
3599
3708
|
const appCtxId = delivery.core.auth.contexts.applicationContextId;
|
|
3600
3709
|
const isRepair = Boolean(job.failedRevision || job.failedSnapshot || job.failureContext || job.analysisMode === "repair");
|
|
3601
|
-
const
|
|
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`;
|
|
3602
3713
|
const prevPlan = compactPreviousPlan(job.proposal);
|
|
3603
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";
|
|
3604
3715
|
const abort = AbortSignal.any([signal, AbortSignal.timeout(15 * 6e4)]);
|
|
@@ -3681,16 +3792,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3681
3792
|
child.tools.register(defineTool2({
|
|
3682
3793
|
name: "opc_delivery_submit",
|
|
3683
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",
|
|
3684
|
-
parameters:
|
|
3685
|
-
summary: { type: "string" },
|
|
3686
|
-
issues: { type: "array", items: { type: "object", additionalProperties: true } },
|
|
3687
|
-
unresolved: { type: "array", items: { type: "string" } },
|
|
3688
|
-
changes: { type: "array", items: { type: "object", additionalProperties: true } },
|
|
3689
|
-
contract: { type: "object", additionalProperties: true },
|
|
3690
|
-
decisions: { type: "array", items: { type: "object", additionalProperties: true } },
|
|
3691
|
-
four_step_report: { type: "object", additionalProperties: true },
|
|
3692
|
-
proposal: { type: "string" }
|
|
3693
|
-
},
|
|
3795
|
+
parameters: proposalParameters(port),
|
|
3694
3796
|
output,
|
|
3695
3797
|
async execute(args) {
|
|
3696
3798
|
if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
|
|
@@ -3701,17 +3803,20 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3701
3803
|
try {
|
|
3702
3804
|
const { proposal, ...fields } = args;
|
|
3703
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");
|
|
3704
3807
|
if (candidate && typeof candidate.contract === "object" && candidate.contract !== null) {
|
|
3705
3808
|
candidate.contract = { ...candidate.contract, slug: job.slug, base_url: job.url };
|
|
3706
3809
|
}
|
|
3707
3810
|
await delivery.submit(job, root, candidate, abort);
|
|
3708
3811
|
} catch (error) {
|
|
3709
|
-
const
|
|
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);
|
|
3710
3814
|
validationErrors.push(detail);
|
|
3711
3815
|
job.analysisFailure = detail;
|
|
3712
3816
|
if (candidate) {
|
|
3713
3817
|
const rej = fingerprint({
|
|
3714
3818
|
contract: candidate.contract,
|
|
3819
|
+
issues: candidate.issues,
|
|
3715
3820
|
changes: candidate.changes,
|
|
3716
3821
|
unresolved: candidate.unresolved,
|
|
3717
3822
|
decisions: candidate.decisions,
|
|
@@ -3747,18 +3852,26 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3747
3852
|
sessionId: randomUUID5(),
|
|
3748
3853
|
meta: { cwd: root }
|
|
3749
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";
|
|
3862
|
+
});
|
|
3750
3863
|
const cancel = () => {
|
|
3751
3864
|
analysis.agent.cancel({ kind: "user" });
|
|
3752
3865
|
};
|
|
3753
3866
|
abort.addEventListener("abort", cancel, { once: true });
|
|
3754
|
-
const send = (
|
|
3867
|
+
const send = (text3) => {
|
|
3755
3868
|
analysis.agent.followup({
|
|
3756
3869
|
id: randomUUID5(),
|
|
3757
3870
|
role: "user",
|
|
3758
3871
|
source: { kind: "user" },
|
|
3759
3872
|
content: [{
|
|
3760
3873
|
type: "text",
|
|
3761
|
-
text:
|
|
3874
|
+
text: text3
|
|
3762
3875
|
}]
|
|
3763
3876
|
});
|
|
3764
3877
|
};
|
|
@@ -3793,7 +3906,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3793
3906
|
description: job.description ?? "",
|
|
3794
3907
|
slug: job.slug,
|
|
3795
3908
|
base_url: job.url,
|
|
3796
|
-
container_port:
|
|
3909
|
+
container_port: port,
|
|
3797
3910
|
available_resource_metadata: filteredRes?.resources ?? [],
|
|
3798
3911
|
user_answers: job.feedbackHistory || feedback,
|
|
3799
3912
|
feedback,
|
|
@@ -3806,26 +3919,29 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3806
3919
|
task: taskInstruction
|
|
3807
3920
|
});
|
|
3808
3921
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
3809
|
-
|
|
3922
|
+
turnOutcome.failure = void 0;
|
|
3923
|
+
turnOutcome.truncated = false;
|
|
3924
|
+
let errorMessage = "";
|
|
3810
3925
|
try {
|
|
3811
3926
|
send(prompt);
|
|
3812
3927
|
await analysis.agent.whenIdle();
|
|
3813
3928
|
} catch (err) {
|
|
3814
3929
|
if (signal.aborted || abort.aborted && !repeatedProposal) throw err;
|
|
3815
|
-
|
|
3816
|
-
if (/(?:timed?\s*out|timeout|connection\s*reset|ECONNRESET|ETIMEDOUT|fetch failed|network|terminated)/i.test(msg)) {
|
|
3817
|
-
transientError = msg.slice(0, 1e3);
|
|
3818
|
-
} else if (!repeatedProposal) {
|
|
3819
|
-
throw err;
|
|
3820
|
-
}
|
|
3930
|
+
errorMessage = err instanceof Error ? err.message : String(err);
|
|
3821
3931
|
}
|
|
3822
3932
|
if (job.status === "review") return;
|
|
3823
3933
|
if (repeatedProposal || validationErrors.length >= 6) {
|
|
3824
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");
|
|
3825
3935
|
}
|
|
3826
3936
|
abort.throwIfAborted();
|
|
3827
|
-
const
|
|
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";
|
|
3828
3943
|
job.analysisFailure = reason;
|
|
3944
|
+
if (providerMessage && !invalidOutput && !networkError) throw new Error(reason);
|
|
3829
3945
|
if (attempt === 2) {
|
|
3830
3946
|
if (/(?:timed?\s*out|timeout|AI.*超时)/i.test(reason)) {
|
|
3831
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");
|
|
@@ -3835,11 +3951,12 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3835
3951
|
}
|
|
3836
3952
|
throw new Error(reason);
|
|
3837
3953
|
}
|
|
3838
|
-
job.events.push(
|
|
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`);
|
|
3839
3955
|
delivery.core.emit("change");
|
|
3840
|
-
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\
|
|
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`;
|
|
3841
3957
|
}
|
|
3842
3958
|
} finally {
|
|
3959
|
+
stopObserving();
|
|
3843
3960
|
abort.removeEventListener("abort", cancel);
|
|
3844
3961
|
await analysis.dispose();
|
|
3845
3962
|
}
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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('
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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('
|
|
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)
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|