@1agents/acp-service 0.9.0 → 0.10.0
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/README.md +19 -13
- package/dist/bin/a2a.js +6 -2
- package/dist/bin/acp-service.js +25 -1
- package/dist/bin/process.d.ts +4 -0
- package/dist/bin/process.js +57 -0
- package/dist/bin/roles.js +21 -18
- package/dist/bin/rsi.d.ts +3 -0
- package/dist/bin/rsi.js +114 -0
- package/dist/bin/ticket.d.ts +13 -0
- package/dist/bin/ticket.js +97 -0
- package/dist/bin/trail.d.ts +4 -0
- package/dist/bin/trail.js +62 -0
- package/dist/src/a2a/artifact-content.d.ts +9 -0
- package/dist/src/a2a/artifact-content.js +45 -0
- package/dist/src/a2a/desktop-notify.d.ts +1 -0
- package/dist/src/a2a/desktop-notify.js +12 -0
- package/dist/src/a2a/execution-binding.d.ts +9 -0
- package/dist/src/a2a/execution-binding.js +19 -0
- package/dist/src/a2a/executor.d.ts +7 -2
- package/dist/src/a2a/executor.js +127 -60
- package/dist/src/a2a/gateway.d.ts +581 -10
- package/dist/src/a2a/gateway.js +1018 -95
- package/dist/src/a2a/index.d.ts +8 -1
- package/dist/src/a2a/index.js +4 -0
- package/dist/src/a2a/job-directory.d.ts +6 -0
- package/dist/src/a2a/job-directory.js +19 -0
- package/dist/src/a2a/preflight.js +16 -1
- package/dist/src/a2a/resubmit.d.ts +46 -0
- package/dist/src/a2a/resubmit.js +82 -0
- package/dist/src/a2a/result-metadata.d.ts +3 -0
- package/dist/src/a2a/result-metadata.js +27 -5
- package/dist/src/a2a/server.d.ts +10 -0
- package/dist/src/a2a/server.js +125 -1
- package/dist/src/a2a/session-lifecycle.d.ts +40 -0
- package/dist/src/a2a/session-lifecycle.js +54 -0
- package/dist/src/a2a/store.d.ts +4 -0
- package/dist/src/a2a/store.js +70 -1
- package/dist/src/a2a/types.d.ts +46 -6
- package/dist/src/a2a/types.js +4 -6
- package/dist/src/a2a/workbench-ui.d.ts +28 -0
- package/dist/src/a2a/workbench-ui.js +182 -0
- package/dist/src/acp-connection.js +27 -3
- package/dist/src/bridge.d.ts +1 -0
- package/dist/src/bridge.js +191 -39
- package/dist/src/capacity-queue.d.ts +35 -0
- package/dist/src/capacity-queue.js +139 -2
- package/dist/src/capacity.d.ts +25 -0
- package/dist/src/capacity.js +48 -9
- package/dist/src/dsh.js +1 -1
- package/dist/src/execution/agent-files.d.ts +25 -0
- package/dist/src/execution/agent-files.js +90 -0
- package/dist/src/execution/agent-registry.d.ts +164 -0
- package/dist/src/execution/agent-registry.js +275 -0
- package/dist/src/execution/human-review.d.ts +2 -0
- package/dist/src/execution/human-review.js +3 -1
- package/dist/src/execution/ledger.d.ts +52 -0
- package/dist/src/execution/ledger.js +83 -5
- package/dist/src/execution/ppt-delivery.d.ts +0 -5
- package/dist/src/execution/ppt-delivery.js +0 -26
- package/dist/src/execution/process-request.d.ts +151 -0
- package/dist/src/execution/process-request.js +177 -0
- package/dist/src/execution/targets.d.ts +64 -5
- package/dist/src/execution/targets.js +58 -7
- package/dist/src/execution/ticket-executor.d.ts +25 -0
- package/dist/src/execution/ticket-executor.js +27 -0
- package/dist/src/execution/ticket.d.ts +326 -0
- package/dist/src/execution/ticket.js +301 -0
- package/dist/src/execution/workbench-chat.d.ts +25 -0
- package/dist/src/execution/workbench-chat.js +54 -0
- package/dist/src/execution/workbench.d.ts +32 -1
- package/dist/src/execution/workbench.js +113 -22
- package/dist/src/roles/index.d.ts +1 -1
- package/dist/src/roles/index.js +1 -1
- package/dist/src/roles/skills.d.ts +27 -58
- package/dist/src/roles/skills.js +89 -404
- package/dist/src/rsi/gate.d.ts +25 -0
- package/dist/src/rsi/gate.js +59 -0
- package/dist/src/rsi/outline-run.d.ts +107 -0
- package/dist/src/rsi/outline-run.js +443 -0
- package/dist/workbench-ui/app.css +453 -0
- package/dist/workbench-ui/app.js +13 -0
- package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
- package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
- package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
- package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
- package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
- package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
- package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
- package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
- package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
- package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
- package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
- package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
- package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
- package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
- package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
- package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
- package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
- package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
- package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
- package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
- package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
- package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
- package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
- package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
- package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
- package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
- package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
- package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
- package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
- package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
- package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
- package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
- package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
- package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
- package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
- package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
- package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
- package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
- package/dist/workbench-ui/chunk-E253Y562.js +1 -0
- package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
- package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
- package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
- package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
- package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
- package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
- package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
- package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
- package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
- package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
- package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
- package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
- package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
- package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
- package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
- package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
- package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
- package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
- package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
- package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
- package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
- package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
- package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
- package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
- package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
- package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
- package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
- package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
- package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
- package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
- package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
- package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
- package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
- package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
- package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
- package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
- package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
- package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
- package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
- package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
- package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
- package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
- package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
- package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
- package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
- package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
- package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
- package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
- package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
- package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
- package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
- package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
- package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
- package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
- package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
- package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
- package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
- package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
- package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
- package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
- package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
- package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
- package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
- package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
- package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
- package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
- package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
- package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
- package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
- package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
- package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
- package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
- package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
- package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
- package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
- package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
- package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
- package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
- package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
- package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
- package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
- package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
- package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
- package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
- package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
- package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
- package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
- package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
- package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
- package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
- package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
- package/dist/workbench-ui/index.html +14 -0
- package/package.json +19 -8
- package/skills/acp-service/SKILL.md +4 -2
- package/skills/acp-service/references/a2a.md +18 -6
- package/skills/acp-service/references/dsh.md +2 -0
- package/skills/acp-service/references/roles-and-tasks.md +10 -10
- package/skills/rsi-coach/SKILL.md +134 -0
- package/vendor/dsh/README.md +10 -6
- package/vendor/dsh/a2a-executor.d.ts +56 -2
- package/vendor/dsh/a2a-executor.js +163 -17
- package/vendor/dsh/a2a.d.ts +12 -2
- package/vendor/dsh/a2a.js +9 -2
- package/vendor/dsh/adapter.d.ts +52 -3
- package/vendor/dsh/adapter.js +297 -30
- package/vendor/dsh/client.js +67 -11
- package/vendor/dsh/index.js +55 -3
- package/vendor/dsh/native-approvals.d.ts +4 -0
- package/vendor/dsh/native-approvals.js +44 -0
- package/vendor/dsh/preset-route.d.ts +49 -0
- package/vendor/dsh/preset-route.js +51 -0
- package/vendor/dsh/preset.js +10 -3
- package/vendor/dsh/process-admission.d.ts +25 -0
- package/vendor/dsh/process-admission.js +87 -0
- package/vendor/dsh/process-requests.d.ts +57 -0
- package/vendor/dsh/process-requests.js +49 -0
- package/vendor/dsh/review-mcp.d.ts +1 -0
- package/vendor/dsh/review-mcp.js +56 -0
- package/vendor/dsh/review.d.ts +30 -0
- package/vendor/dsh/review.js +149 -0
- package/vendor/dsh/session-settings.d.ts +34 -0
- package/vendor/dsh/session-settings.js +114 -0
- package/vendor/dsh/ticket-spec.d.ts +30 -0
- package/vendor/dsh/ticket-spec.js +10 -0
- package/vendor/dsh/ticket-tools.d.ts +21 -0
- package/vendor/dsh/ticket-tools.js +43 -0
- package/vendor/dsh/workbench.d.ts +18 -0
- package/vendor/dsh/workbench.js +91 -0
- package/vendor/runtime/README.md +6 -4
- package/vendor/runtime/dist/docs-site/CLI.html +2 -2
- package/vendor/runtime/dist/docs-site/VISION.html +2 -2
- package/vendor/runtime/dist/docs-site/agents.html +2 -2
- package/vendor/runtime/dist/docs-site/compare.html +2 -2
- package/vendor/runtime/dist/docs-site/config.html +2 -2
- package/vendor/runtime/dist/docs-site/custom-agents.html +2 -2
- package/vendor/runtime/dist/docs-site/exit-codes.html +2 -2
- package/vendor/runtime/dist/docs-site/flows.html +2 -2
- package/vendor/runtime/dist/docs-site/index.html +1 -1
- package/vendor/runtime/dist/docs-site/install.html +2 -2
- package/vendor/runtime/dist/docs-site/llms.txt +1 -1
- package/vendor/runtime/dist/docs-site/output-formats.html +2 -2
- package/vendor/runtime/dist/docs-site/permissions.html +2 -2
- package/vendor/runtime/dist/docs-site/prompting.html +2 -2
- package/vendor/runtime/dist/docs-site/quickstart.html +2 -2
- package/vendor/runtime/dist/docs-site/releasing.html +2 -2
- package/vendor/runtime/dist/docs-site/runtime-environment.html +2 -2
- package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +2 -2
- package/vendor/runtime/dist/docs-site/safe-errors.html +2 -2
- package/vendor/runtime/dist/docs-site/session-control.html +2 -2
- package/vendor/runtime/dist/docs-site/session-watch.html +2 -2
- package/vendor/runtime/dist/docs-site/sessions.html +2 -2
- package/vendor/runtime/dist/docs-site/shared-sessions.html +2 -2
- package/vendor/runtime/package.json +6 -4
- package/vendor/runtime/skills/acpx/SKILL.md +2 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type QualityReview, type CheckResult } from '../execution/ticket.js';
|
|
2
|
+
export type { CheckResult, QualityReview };
|
|
3
|
+
/** One QA pass over a frozen copy of the outline, in its own session. */
|
|
4
|
+
export interface ReviewRecord {
|
|
5
|
+
jobId?: string;
|
|
6
|
+
executionStatus: string;
|
|
7
|
+
outlineCopy: string;
|
|
8
|
+
review?: QualityReview;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface OutlineRound {
|
|
12
|
+
round: number;
|
|
13
|
+
jobId: string;
|
|
14
|
+
executionStatus: string;
|
|
15
|
+
passed: boolean;
|
|
16
|
+
results: CheckResult[];
|
|
17
|
+
outlineSha256?: string;
|
|
18
|
+
review?: ReviewRecord;
|
|
19
|
+
/** Why the round went back unchecked: the executor finished without submitting the ticket. */
|
|
20
|
+
ticketErrors?: string[];
|
|
21
|
+
}
|
|
22
|
+
export type Phase = 'dev' | 'test';
|
|
23
|
+
/** `host_error`: the host itself failed mid-run (the gateway went away, a call threw); the run is recorded and the error rethrown. */
|
|
24
|
+
export type StopReason = 'passed' | 'max_bounces' | 'max_revisions' | 'stalled' | 'needs_human' | 'not_completed' | 'review_failed' | 'host_error';
|
|
25
|
+
/** The role version is the last commit that touched the role directory; uncommitted changes make a run unattributable. */
|
|
26
|
+
export interface RoleVersion {
|
|
27
|
+
commit?: string;
|
|
28
|
+
dirty: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface OutlineRunReport {
|
|
31
|
+
roleId: string;
|
|
32
|
+
caseId: string;
|
|
33
|
+
phase: Phase;
|
|
34
|
+
role: RoleVersion;
|
|
35
|
+
repo: string;
|
|
36
|
+
commit: string;
|
|
37
|
+
workDirectory: string;
|
|
38
|
+
outlinePath: string;
|
|
39
|
+
ticketPath: string;
|
|
40
|
+
/** The executor's job, which carries the ticket. */
|
|
41
|
+
jobId?: string;
|
|
42
|
+
featuresConfirmed: boolean;
|
|
43
|
+
rounds: OutlineRound[];
|
|
44
|
+
passed: boolean;
|
|
45
|
+
stopReason: StopReason;
|
|
46
|
+
startedAt: string;
|
|
47
|
+
finishedAt: string;
|
|
48
|
+
/** The host error that stopped the run. */
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
/** One line of `<workspace>/<role>/ledger.jsonl`. */
|
|
52
|
+
export interface LedgerEntry {
|
|
53
|
+
startedAt: string;
|
|
54
|
+
phase: Phase;
|
|
55
|
+
caseId: string;
|
|
56
|
+
caseKind: 'original' | 'variant';
|
|
57
|
+
role: RoleVersion;
|
|
58
|
+
passed: boolean;
|
|
59
|
+
stopReason: StopReason;
|
|
60
|
+
/** The executor's first outline passed every program check without a bounce. */
|
|
61
|
+
firstDraftPassed: boolean;
|
|
62
|
+
bounces: number;
|
|
63
|
+
revisions: number;
|
|
64
|
+
scores: Record<string, number>[];
|
|
65
|
+
mustIssues: number;
|
|
66
|
+
proposals: NonNullable<QualityReview['proposals']>;
|
|
67
|
+
workDirectory: string;
|
|
68
|
+
ticketPath: string;
|
|
69
|
+
/** The executor's job, which carries the ticket; the gate reads the proposals' current state from it. */
|
|
70
|
+
jobId?: string;
|
|
71
|
+
originSessionId?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface OutlineRunOptions {
|
|
74
|
+
roleDirectory: string;
|
|
75
|
+
caseId: string;
|
|
76
|
+
projectPath: string;
|
|
77
|
+
workspace: string;
|
|
78
|
+
/** A test run needs a committed role directory and QA; development runs take whatever is on disk. */
|
|
79
|
+
phase?: Phase;
|
|
80
|
+
targetId: string;
|
|
81
|
+
agentPreset: string;
|
|
82
|
+
originSessionId: string;
|
|
83
|
+
/** Times a failed check goes back to the executor. The design default is one. */
|
|
84
|
+
maxBounces?: number;
|
|
85
|
+
pollMs?: number;
|
|
86
|
+
timeoutMs?: number;
|
|
87
|
+
python?: string;
|
|
88
|
+
/** How to run acp-service: the executor's ticket commands, and the coach's answer to a process request. */
|
|
89
|
+
cli?: {
|
|
90
|
+
command: string;
|
|
91
|
+
url: string;
|
|
92
|
+
};
|
|
93
|
+
/** A QA agent reviews each outline that passes the program checks and may send it back for revision, by default up to three times. */
|
|
94
|
+
qa?: {
|
|
95
|
+
agentPreset?: string;
|
|
96
|
+
targetId?: string;
|
|
97
|
+
maxRevisions?: number;
|
|
98
|
+
};
|
|
99
|
+
invoke: (method: string, params: Record<string, unknown>) => Promise<any>;
|
|
100
|
+
log?: (line: string) => void;
|
|
101
|
+
now?: () => Date;
|
|
102
|
+
/** A run directory: goes on with the run recorded there instead of starting one. */
|
|
103
|
+
resume?: string;
|
|
104
|
+
}
|
|
105
|
+
export declare function roleVersion(roleDirectory: string): Promise<RoleVersion>;
|
|
106
|
+
export declare const ledgerPath: (workspace: string, roleId: string) => string;
|
|
107
|
+
export declare function runOutlineCase(options: OutlineRunOptions): Promise<OutlineRunReport>;
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One product-intro outline run on a role's case: the executor writes outline.json in a prepared
|
|
3
|
+
* work directory, the role's program checks run on it, and a failed check goes back to the
|
|
4
|
+
* same session with its evidence. No model judges the result here; people accept it on the workbench.
|
|
5
|
+
* The checked bytes are recorded by sha256, and a delivered copy in the job's artifact folder must match them.
|
|
6
|
+
* Each run appends a line to the role's ledger, which the gate reads to decide when development is done.
|
|
7
|
+
* Everything sent back goes through the task ticket on the executor's job (execution/ticket.ts), kept by the gateway:
|
|
8
|
+
* the executor handles it with its ticket tools, every step is a ledger event, and ticket.json is a read-only export.
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { createHash } from 'node:crypto';
|
|
12
|
+
import { appendFile, cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import { checkResultSchema, pendingItems, qualityReviewSchema, unsettledMust } from '../execution/ticket.js';
|
|
16
|
+
const caseSchema = z.object({
|
|
17
|
+
schemaVersion: z.literal(1), id: z.string().min(1), kind: z.enum(['original', 'variant']), locked: z.boolean(),
|
|
18
|
+
input: z.object({ repo: z.string().min(1), commit: z.string().regex(/^[0-9a-f]{40}$/),
|
|
19
|
+
exclude: z.array(z.string().min(1)), audience: z.string().min(1) }).strict(),
|
|
20
|
+
features: z.string().min(1).nullable(), accepted: z.unknown(),
|
|
21
|
+
}).strict();
|
|
22
|
+
const featuresSchema = z.object({ repo: z.string(), commit: z.string(), confirmation: z.unknown(),
|
|
23
|
+
features: z.array(z.object({ id: z.string().min(1), name: z.string().min(1) }).passthrough()).min(1) }).passthrough();
|
|
24
|
+
const resultsSchema = z.array(checkResultSchema);
|
|
25
|
+
/**
|
|
26
|
+
* What training may change in the executor besides the first user message, which carries the role and is always
|
|
27
|
+
* trained; the agent's own system prompt and persona are never replaced. Tools and skills are only controlled on
|
|
28
|
+
* DSH's own presets, so a role that trains them cannot run on an ACP agent; `presets` narrows the executors further.
|
|
29
|
+
*/
|
|
30
|
+
const LAYERS = { prompt: '第一条消息', skills: '技能', tools: '工具和权限', model: '模型和模式' };
|
|
31
|
+
const profileSchema = z.object({ id: z.string().min(1), training: z.object({
|
|
32
|
+
layers: z.array(z.enum(Object.keys(LAYERS))).refine(layers => layers.includes('prompt'), 'layers must include prompt'),
|
|
33
|
+
presets: z.array(z.string().min(1)).min(1).optional()
|
|
34
|
+
}).strict().optional() }).passthrough();
|
|
35
|
+
const acpPreset = (preset) => preset.startsWith('oneagents-acp-');
|
|
36
|
+
/** Runs that stopped because something did not finish; the others stopped by the training's rules. */
|
|
37
|
+
const RESUMABLE = ['not_completed', 'review_failed', 'host_error'];
|
|
38
|
+
const terminal = new Set(['completed', 'failed', 'canceled', 'rejected']);
|
|
39
|
+
function run(command, args, options = {}) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const child = spawn(command, args, { cwd: options.cwd, stdio: [options.input ? 'pipe' : 'ignore', 'pipe', 'pipe'] });
|
|
42
|
+
let stdout = '', stderr = '';
|
|
43
|
+
child.stdout.on('data', chunk => { stdout += chunk; });
|
|
44
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
45
|
+
if (options.input)
|
|
46
|
+
options.input.pipe(child.stdin);
|
|
47
|
+
child.once('error', reject);
|
|
48
|
+
child.once('close', code => resolve({ code: code ?? 1, stdout, stderr }));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** The pinned commit as plain files, with the case's excluded paths removed. */
|
|
52
|
+
async function exportProject(repository, commit, destination, exclude) {
|
|
53
|
+
if ((await run('git', ['-C', repository, 'cat-file', '-e', `${commit}^{commit}`])).code !== 0)
|
|
54
|
+
throw new Error(`Commit ${commit} is not in ${repository}`);
|
|
55
|
+
await mkdir(destination, { recursive: true });
|
|
56
|
+
const archive = spawn('git', ['-C', repository, 'archive', '--format=tar', commit], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
57
|
+
const archived = new Promise((resolve, reject) => { archive.once('error', reject); archive.once('close', code => resolve(code ?? 1)); });
|
|
58
|
+
const extracted = await run('tar', ['-x', '-C', destination], { input: archive.stdout });
|
|
59
|
+
if (await archived !== 0 || extracted.code !== 0)
|
|
60
|
+
throw new Error(`Could not export ${commit}: ${extracted.stderr.trim()}`);
|
|
61
|
+
for (const entry of exclude) {
|
|
62
|
+
const target = path.resolve(destination, entry);
|
|
63
|
+
if (path.isAbsolute(entry) || !target.startsWith(destination + path.sep))
|
|
64
|
+
throw new Error(`Excluded path leaves the project: ${entry}`);
|
|
65
|
+
await rm(target, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function taskPrompt(role, kase, work, python) {
|
|
69
|
+
return `${role}\n\n## 本次任务\n\n- 工作目录:${work}\n- 仓库:${kase.input.repo}\n- 提交:${kase.input.commit}\n- 受众:${kase.input.audience}\n- 自查用的 Python:\`${python}\`(已装好 jsonschema)\n\n读 \`project/\`,按 \`features.json\` 和 \`checks/outline.schema.json\` 写出 \`${path.join(work, 'outline.json')}\`。自查:\`${python} -I checks/check_outline.py outline.json features.json project\`。通过后结束,最终答复给出文件路径。\n\n这次任务的任务单记在系统里,宿主维护。被打回时,意见都在任务单上,按打回消息里的步骤用 \`ticket_show\`、\`ticket_mark\`、\`ticket_submit\` 工具(或打回消息里给的命令)处理;工作目录里的 \`ticket.json\` 只是只读导出。`;
|
|
70
|
+
}
|
|
71
|
+
/** The checks need jsonschema, so the interpreter is resolved once and handed to the executor by absolute path. */
|
|
72
|
+
async function checkInterpreter(name) {
|
|
73
|
+
const found = await run(name, ['-I', '-c', 'import sys; from jsonschema import Draft202012Validator; print(sys.executable)']);
|
|
74
|
+
if (found.code !== 0)
|
|
75
|
+
throw new Error(`${name} cannot run the role checks (needs jsonschema with Draft 2020-12); pass another interpreter`);
|
|
76
|
+
return found.stdout.trim();
|
|
77
|
+
}
|
|
78
|
+
function ticketSteps(jobId, cli) {
|
|
79
|
+
const ticket = cli && `${cli.command} ticket`;
|
|
80
|
+
const commands = cli ? `\n\nACP 智能体里这三个工具由 \`oneagents-review\` MCP 服务提供。找不到这些工具时,在终端里用命令做同样的事:\n\n- 查看:\`${ticket} pending --job ${jobId} --url ${cli.url}\`\n- 标记:\`${ticket} mark --job ${jobId} --url ${cli.url} --id 编号 --state done --note '怎么改的'\`\n- 提交:\`${ticket} submit --job ${jobId} --url ${cli.url}\`` : '';
|
|
81
|
+
return ticket => {
|
|
82
|
+
const pending = pendingItems(ticket);
|
|
83
|
+
return `任务单上有 ${pending.length} 条待处理(${pending.filter(item => item.severity === 'must').length} 条必须改):\n\n1. 调用 \`ticket_show\` 工具查看待处理的意见和证据。\n2. 在同一个 outline.json 上逐条修改。改完一条就调用 \`ticket_mark\`:\`id\` 填编号,\`state\` 填 \`done\`,\`note\` 写怎么改的;不同意的 \`state\` 填 \`disputed\`,\`note\` 写理由。\n3. 全部处理完,调用 \`ticket_submit\`。\n4. 用任务里给的 Python 再运行自查,全部检查通过后结束,最终答复给出文件路径。${commands}\n\n任务单只能用这三个工具${cli ? '或这三条命令' : ''}处理;工作目录里的 ticket.json 是只读导出,改它没有用。`;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function bouncePrompt(steps, ticket, round) {
|
|
87
|
+
return `宿主程序检查没有通过(第 ${round} 轮),未通过的检查项和证据已写进任务单。${steps(ticket)}`;
|
|
88
|
+
}
|
|
89
|
+
function ticketBouncePrompt(steps, ticket, problems) {
|
|
90
|
+
return `任务单没有按规定处理:\n\n${problems.map(problem => `- ${problem}`).join('\n')}\n\n${steps(ticket)}`;
|
|
91
|
+
}
|
|
92
|
+
export async function roleVersion(roleDirectory) {
|
|
93
|
+
const last = await run('git', ['-C', roleDirectory, 'log', '-1', '--format=%H', '--', '.']);
|
|
94
|
+
const status = await run('git', ['-C', roleDirectory, 'status', '--porcelain', '--untracked-files=all', '--', '.']);
|
|
95
|
+
const commit = last.code === 0 && last.stdout.trim() ? last.stdout.trim() : undefined;
|
|
96
|
+
return { ...(commit ? { commit } : {}), dirty: !commit || status.code !== 0 || status.stdout.trim() !== '' };
|
|
97
|
+
}
|
|
98
|
+
export const ledgerPath = (workspace, roleId) => path.join(path.resolve(workspace), roleId, 'ledger.jsonl');
|
|
99
|
+
/** More revisions stop helping when the same issue survives two re-reviews in a row, or the total score has not risen twice running. */
|
|
100
|
+
function stalled(reviews) {
|
|
101
|
+
const open = (review) => new Set((review?.previous ?? []).filter(p => p.status === 'not_fixed' || p.status === 'partly').map(p => p.id));
|
|
102
|
+
const before = open(reviews.at(-2));
|
|
103
|
+
if ([...open(reviews.at(-1))].some(where => before.has(where)))
|
|
104
|
+
return true;
|
|
105
|
+
const totals = reviews.map(review => Object.values(review.scores).reduce((sum, score) => sum + score, 0));
|
|
106
|
+
return totals.length >= 3 && totals.at(-1) <= totals.at(-2) && totals.at(-2) <= totals.at(-3);
|
|
107
|
+
}
|
|
108
|
+
const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
109
|
+
function reviewPrompt(qaRole, kase, work, copy, output) {
|
|
110
|
+
return `${qaRole}\n\n## 本次质检\n\n- 工作目录:${work}\n- 要审的大纲:\`${copy}\`\n- 项目副本(只读):\`${path.join(work, 'project')}\`\n- 功能清单:\`${path.join(work, 'features.json')}\`\n- 任务单(系统里的任务单的只读导出):\`${path.join(work, 'ticket.json')}\`\n- 仓库:${kase.input.repo}\n- 受众:${kase.input.audience}\n\n把质检结果写到 \`${output}\`,写完立即结束。不要修改其他任何文件。`;
|
|
111
|
+
}
|
|
112
|
+
/** A re-review continues the same QA session, so it remembers its own issues and checks them first. */
|
|
113
|
+
function reReviewPrompt(copy, output, ticketPath, round) {
|
|
114
|
+
return `执行者按任务单改了大纲(第 ${round} 轮)。新版本:\`${copy}\`。任务单记在系统里,只读导出在 \`${ticketPath}\`;执行者在上面把你的每条意见标了 done(已改)或 disputed(不同意),并写了说明。\n\n按 QA.md 的复审要求:先在 previous 里用任务单编号逐条核对执行者处理过的质检意见,再用同样的标准打分,issues 只写新问题。把结果写到 \`${output}\`,写完立即结束。不要修改其他任何文件。`;
|
|
115
|
+
}
|
|
116
|
+
function revisePrompt(steps, ticket, review, round) {
|
|
117
|
+
return `质检审了你第 ${round} 轮的大纲,结论是需要修改:${review.summary}\n\n质检的意见已写进任务单,没改到位的旧意见已重新打开。${steps(ticket)}`;
|
|
118
|
+
}
|
|
119
|
+
async function check(work, python, jobId) {
|
|
120
|
+
const outline = path.join(work, 'outline.json');
|
|
121
|
+
const bytes = await readFile(outline).catch(() => undefined);
|
|
122
|
+
if (!bytes)
|
|
123
|
+
return { results: [{ itemId: 'P0', pass: false, evidence: [{ message: 'outline.json 不存在或不是普通文件' }] }] };
|
|
124
|
+
const outlineSha256 = sha256(bytes);
|
|
125
|
+
const result = await run(python, ['-I', path.join(work, 'checks', 'check_outline.py'), outline, path.join(work, 'features.json'), path.join(work, 'project')], { cwd: work });
|
|
126
|
+
let results;
|
|
127
|
+
try {
|
|
128
|
+
results = resultsSchema.parse(JSON.parse(result.stdout));
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
results = [{ itemId: 'P0', pass: false, evidence: [{ message: 'outline.json 不是可读的 JSON,或检查程序出错', stderr: result.stderr.slice(-2000) }] }];
|
|
132
|
+
}
|
|
133
|
+
// The host delivers the copy in the job's artifact folder, so it must be the very bytes that were checked.
|
|
134
|
+
const delivered = path.join(work, '.1agents', 'jobs', jobId, 'outline.json');
|
|
135
|
+
const copy = await readFile(delivered).catch(() => undefined);
|
|
136
|
+
if (copy) {
|
|
137
|
+
const copySha256 = sha256(copy);
|
|
138
|
+
results.push({ itemId: 'D1', pass: copySha256 === outlineSha256, evidence: copySha256 === outlineSha256 ? [] : [{ path: path.relative(work, delivered),
|
|
139
|
+
message: `产物目录里的 outline.json(sha256 ${copySha256})和工作目录的 outline.json(sha256 ${outlineSha256})字节不一致,请让两份完全相同` }] });
|
|
140
|
+
}
|
|
141
|
+
return { results, outlineSha256 };
|
|
142
|
+
}
|
|
143
|
+
export async function runOutlineCase(options) {
|
|
144
|
+
const log = options.log ?? (() => { }), now = options.now ?? (() => new Date());
|
|
145
|
+
const pollMs = options.pollMs ?? 10_000, timeoutMs = options.timeoutMs ?? 60 * 60_000, maxBounces = options.maxBounces ?? 1;
|
|
146
|
+
const prior = options.resume ? JSON.parse(await readFile(path.join(options.resume, 'run.json'), 'utf8')) : undefined;
|
|
147
|
+
const python = await checkInterpreter(options.python ?? 'python3'), startedAt = prior?.startedAt ?? now().toISOString();
|
|
148
|
+
const roleDirectory = path.resolve(options.roleDirectory);
|
|
149
|
+
const profile = profileSchema.parse(JSON.parse(await readFile(path.join(roleDirectory, 'profile.json'), 'utf8'))), roleId = profile.id;
|
|
150
|
+
const layers = profile.training?.layers ?? ['prompt'];
|
|
151
|
+
if (profile.training?.presets && !profile.training.presets.includes(options.agentPreset))
|
|
152
|
+
throw new Error(`This role runs only on ${profile.training.presets.join(', ')}, not ${options.agentPreset}`);
|
|
153
|
+
if (acpPreset(options.agentPreset) && (layers.includes('tools') || layers.includes('skills')))
|
|
154
|
+
throw new Error(`This role trains ${layers.filter(layer => layer === 'tools' || layer === 'skills').join(' and ')}, which only DSH's own presets control; ${options.agentPreset} is an ACP agent`);
|
|
155
|
+
const caseDirectory = path.join(roleDirectory, 'cases', options.caseId);
|
|
156
|
+
const kase = caseSchema.parse(JSON.parse(await readFile(path.join(caseDirectory, 'case.json'), 'utf8')));
|
|
157
|
+
if (!kase.features)
|
|
158
|
+
throw new Error(`Case ${kase.id} has no confirmed feature list yet`);
|
|
159
|
+
const features = featuresSchema.parse(JSON.parse(await readFile(path.join(caseDirectory, kase.features), 'utf8')));
|
|
160
|
+
if (features.repo !== kase.input.repo || features.commit !== kase.input.commit)
|
|
161
|
+
throw new Error('The feature list belongs to another repository or commit');
|
|
162
|
+
const phase = options.phase ?? 'dev', role = await roleVersion(roleDirectory);
|
|
163
|
+
if (phase === 'test' && role.dirty)
|
|
164
|
+
throw new Error('A test run needs the role directory committed with no local changes');
|
|
165
|
+
if (phase === 'test' && !options.qa)
|
|
166
|
+
throw new Error('A test run needs the QA review');
|
|
167
|
+
const stamp = startedAt.replace(/[-:]/g, '').replace(/\.\d+Z$/, 'Z');
|
|
168
|
+
const work = options.resume ? path.resolve(options.resume) : path.join(path.resolve(options.workspace), roleId, `${kase.id}-${stamp}`);
|
|
169
|
+
if (prior) {
|
|
170
|
+
if (prior.roleId !== roleId || prior.caseId !== kase.id || prior.phase !== phase)
|
|
171
|
+
throw new Error(`That run is ${prior.roleId} / ${prior.caseId} in phase ${prior.phase}`);
|
|
172
|
+
if (prior.passed)
|
|
173
|
+
throw new Error('That run already passed');
|
|
174
|
+
if (!RESUMABLE.includes(prior.stopReason))
|
|
175
|
+
throw new Error(`That run stopped by the training's rules (${prior.stopReason}); start a new one to try again`);
|
|
176
|
+
if (prior.role.commit !== role.commit || prior.role.dirty !== role.dirty)
|
|
177
|
+
throw new Error(`The role changed since that run (${prior.role.commit?.slice(0, 8)}); start a new one`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
await mkdir(work, { recursive: true });
|
|
181
|
+
await exportProject(path.resolve(options.projectPath), kase.input.commit, path.join(work, 'project'), kase.input.exclude);
|
|
182
|
+
await cp(path.join(roleDirectory, 'checklist.json'), path.join(work, 'checklist.json'));
|
|
183
|
+
await cp(path.join(roleDirectory, 'checks'), path.join(work, 'checks'), { recursive: true });
|
|
184
|
+
await cp(path.join(caseDirectory, kase.features), path.join(work, 'features.json'));
|
|
185
|
+
}
|
|
186
|
+
log(`${prior ? '接着跑,工作目录' : '工作目录'}:${work}`);
|
|
187
|
+
log(`阶段:${phase === 'dev' ? '开发' : '测试'},角色版本:${role.commit?.slice(0, 8) ?? '未提交'}${role.commit && role.dirty ? '(有未提交的改动)' : ''}`);
|
|
188
|
+
log(`执行者:${options.agentPreset},训练的层:${layers.map(layer => LAYERS[layer]).join('、')}`);
|
|
189
|
+
if (!features.confirmation)
|
|
190
|
+
log('注意:这份功能清单还没有经人确认。');
|
|
191
|
+
/** Process requests already reported, so each is said once. */
|
|
192
|
+
const reported = new Set();
|
|
193
|
+
/** Tells the gateway this run no longer waits on a job that may still run, so the workbench lists it for a later re-query. */
|
|
194
|
+
const unwatch = (jobId, reason) => options.invoke('execution_unwatch', { originSessionId: options.originSessionId, jobId, reason })
|
|
195
|
+
.catch(error => log(`任务 ${jobId}:没能记下停止等待(${error instanceof Error ? error.message : String(error)})`));
|
|
196
|
+
const wait = async (jobId) => {
|
|
197
|
+
const deadline = Date.now() + timeoutMs;
|
|
198
|
+
let last = '';
|
|
199
|
+
for (;;) {
|
|
200
|
+
// The query only reads; a slow or failed one is retried until the round's time is up.
|
|
201
|
+
const view = await options.invoke('execution_get', { originSessionId: options.originSessionId, jobId })
|
|
202
|
+
.catch(error => { log(`任务 ${jobId}:查询状态失败(${error instanceof Error ? error.message : String(error)}),继续等待`); return undefined; });
|
|
203
|
+
const status = view ? String(view.executionStatus ?? 'unknown') : last;
|
|
204
|
+
if (status !== last) {
|
|
205
|
+
log(`任务 ${jobId}:${status}${status === 'input_required' ? '(等待人在工作台处理)' : ''}`);
|
|
206
|
+
last = status;
|
|
207
|
+
}
|
|
208
|
+
if (terminal.has(status))
|
|
209
|
+
return status;
|
|
210
|
+
// A request beyond the executor's preset leaves the task working while it waits; the coach answers it by default.
|
|
211
|
+
const requests = (await options.invoke('execution_process_requests', { originSessionId: options.originSessionId, jobId }).catch(() => undefined))?.requests ?? [];
|
|
212
|
+
for (const request of requests.filter(item => item.status === 'pending' && !reported.has(item.requestId))) {
|
|
213
|
+
reported.add(request.requestId);
|
|
214
|
+
const asked = request.kind === 'permission' ? `工具「${request.toolTitle}」待批准` : request.kind === 'plan' ? '计划待批准' : '有提问待回答';
|
|
215
|
+
log(`任务 ${jobId} 的过程请求 ${request.requestId}:${asked}。${request.kind === 'question' ? '在工作台回答' : `教练处理:${options.cli ? `${options.cli.command} process` : 'acp-service process'} answer --job ${jobId} --id ${request.requestId} approve|reject --note 理由${options.cli ? ` --url ${options.cli.url}` : ''}`}`);
|
|
216
|
+
}
|
|
217
|
+
if (Date.now() > deadline) {
|
|
218
|
+
log(`任务 ${jobId}:${Math.round(timeoutMs / 60_000)} 分钟内没有结束,停止等待`);
|
|
219
|
+
await unwatch(jobId, `rsi run 等了 ${Math.round(timeoutMs / 60_000)} 分钟没有结束`);
|
|
220
|
+
return 'timed_out';
|
|
221
|
+
}
|
|
222
|
+
await new Promise(resolve => setTimeout(resolve, pollMs));
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const roleText = await readFile(path.join(roleDirectory, 'ROLE.md'), 'utf8');
|
|
226
|
+
const qaRole = options.qa ? await readFile(path.join(roleDirectory, 'QA.md'), 'utf8') : '';
|
|
227
|
+
const outlinePath = path.join(work, 'outline.json'), ticketPath = path.join(work, 'ticket.json');
|
|
228
|
+
/**
|
|
229
|
+
* One QA session per task: the first review opens it and each re-review continues it. The QA agent reads a
|
|
230
|
+
* frozen copy; if it touches the live outline anyway, the executor's version is restored.
|
|
231
|
+
*/
|
|
232
|
+
let qaJobId = prior?.rounds.flatMap(round => round.review?.jobId ?? []).at(-1);
|
|
233
|
+
const review = async (round, resuming = false) => {
|
|
234
|
+
await mkdir(path.join(work, 'reviews'), { recursive: true });
|
|
235
|
+
const copy = path.join(work, 'reviews', `outline-r${round}.json`), output = path.join(work, 'reviews', `review-r${round}.json`);
|
|
236
|
+
const bytes = await readFile(outlinePath);
|
|
237
|
+
await writeFile(copy, bytes);
|
|
238
|
+
const clientRequestId = `${roleId}:${kase.id}:${stamp}:review-${round}${resuming ? `-resume-${now().toISOString()}` : ''}`;
|
|
239
|
+
// Going on with a review: if QA is still at it, or has written its result, only the waiting was lost.
|
|
240
|
+
const qaStatus = resuming && qaJobId ? String((await options.invoke('execution_get', { originSessionId: options.originSessionId, jobId: qaJobId })).executionStatus) : undefined;
|
|
241
|
+
const lostOnlyTheWait = qaStatus !== undefined && (!terminal.has(qaStatus) || (qaStatus === 'completed' && await readFile(output).then(() => true, () => false)));
|
|
242
|
+
if (lostOnlyTheWait)
|
|
243
|
+
log(`第 ${round} 轮质检:接着等任务 ${qaJobId}`);
|
|
244
|
+
else if (qaJobId) {
|
|
245
|
+
await options.invoke('execution_continue', { originSessionId: options.originSessionId, jobId: qaJobId, clientRequestId,
|
|
246
|
+
input: { prompt: resuming && !reviews.length ? reviewPrompt(qaRole, kase, work, copy, output) : reReviewPrompt(copy, output, ticketPath, round) } });
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// A child of the executor's job, so the ledger shows the two as one run and cancelling the run reaches QA.
|
|
250
|
+
const executor = await options.invoke('execution_get', { originSessionId: options.originSessionId, jobId });
|
|
251
|
+
const submitted = await options.invoke('execution_submit', { originSessionId: options.originSessionId, targetId: options.qa.targetId ?? options.targetId,
|
|
252
|
+
title: `质检:产品介绍大纲 ${kase.input.repo}`, clientRequestId, purpose: 'qa_review',
|
|
253
|
+
parentJobRef: { sourceId: executor.sourceId, jobId }, parentAttemptId: executor.currentAttemptId,
|
|
254
|
+
input: { cwd: work, agentPreset: options.qa.agentPreset ?? options.agentPreset, prompt: reviewPrompt(qaRole, kase, work, copy, output) } });
|
|
255
|
+
qaJobId = String(submitted.jobId);
|
|
256
|
+
}
|
|
257
|
+
const record = { jobId: qaJobId, executionStatus: await wait(qaJobId), outlineCopy: copy };
|
|
258
|
+
const after = await readFile(outlinePath).catch(() => undefined);
|
|
259
|
+
if (!after || sha256(after) !== sha256(bytes)) {
|
|
260
|
+
await writeFile(outlinePath, bytes);
|
|
261
|
+
record.error = '质检智能体改动了 outline.json,已恢复执行者的版本';
|
|
262
|
+
}
|
|
263
|
+
if (record.executionStatus !== 'completed')
|
|
264
|
+
return { ...record, error: record.error ?? `质检任务没有完成(${record.executionStatus})` };
|
|
265
|
+
try {
|
|
266
|
+
record.review = qualityReviewSchema.parse(JSON.parse(await readFile(output, 'utf8')));
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
record.error = [record.error, `质检结果读不出来:${error instanceof Error ? error.message : String(error)}`].filter(Boolean).join(';');
|
|
270
|
+
}
|
|
271
|
+
return record;
|
|
272
|
+
};
|
|
273
|
+
const priorJob = prior?.jobId ?? prior?.rounds[0]?.jobId;
|
|
274
|
+
if (prior && !priorJob)
|
|
275
|
+
throw new Error('That run recorded no job to go on with');
|
|
276
|
+
const jobId = priorJob ?? String((await options.invoke('execution_submit', { originSessionId: options.originSessionId, targetId: options.targetId,
|
|
277
|
+
title: `产品介绍大纲:${kase.input.repo}`, clientRequestId: `${roleId}:${kase.id}:${stamp}:round-1`,
|
|
278
|
+
input: { cwd: work, agentPreset: options.agentPreset, prompt: taskPrompt(roleText, kase, work, python) } })).jobId);
|
|
279
|
+
/** Each change goes through the gateway, which records it on the job and rewrites the read-only copy in the work directory. */
|
|
280
|
+
const ticketCall = async (method, params = {}) => {
|
|
281
|
+
const scope = { originSessionId: options.originSessionId, jobId };
|
|
282
|
+
if (method !== 'ticket_get')
|
|
283
|
+
await options.invoke(method, { ...scope, ...params });
|
|
284
|
+
return await options.invoke('ticket_get', scope);
|
|
285
|
+
};
|
|
286
|
+
let ticket = prior ? await ticketCall('ticket_get') : await ticketCall('ticket_open', { roleId, caseId: kase.id, exportPath: ticketPath });
|
|
287
|
+
const steps = ticketSteps(jobId, options.cli);
|
|
288
|
+
const rounds = prior ? [...prior.rounds] : [];
|
|
289
|
+
// Where a resumed run picks up: the round its host never finished waiting on, or the review QA did not finish.
|
|
290
|
+
let startRound = 1, resumingReview = false;
|
|
291
|
+
if (prior) {
|
|
292
|
+
const last = rounds.at(-1);
|
|
293
|
+
if (!last || ticket.round > last.round)
|
|
294
|
+
startRound = ticket.round;
|
|
295
|
+
else if (last.executionStatus !== 'completed') {
|
|
296
|
+
rounds.pop();
|
|
297
|
+
startRound = last.round;
|
|
298
|
+
}
|
|
299
|
+
else if (options.qa && last.results.every(result => result.pass) && !last.review?.review) {
|
|
300
|
+
rounds.pop();
|
|
301
|
+
startRound = last.round;
|
|
302
|
+
resumingReview = true;
|
|
303
|
+
}
|
|
304
|
+
else
|
|
305
|
+
throw new Error(`That run stopped between steps of round ${last.round}; start a new one`);
|
|
306
|
+
}
|
|
307
|
+
const reviews = rounds.flatMap(round => round.review?.review && round.review.review.verdict !== 'pass' ? [round.review.review] : []);
|
|
308
|
+
let bounces = rounds.filter(round => round.ticketErrors || (round.executionStatus === 'completed' && round.results.some(result => !result.pass))).length;
|
|
309
|
+
let revisions = reviews.length, stopReason = 'passed';
|
|
310
|
+
// The stopped ticket refused whatever this round's executor tried to mark, so a missing submission is not its miss.
|
|
311
|
+
const excusedRound = prior && !resumingReview ? startRound : undefined;
|
|
312
|
+
const sendBack = async (round, feedback, note) => {
|
|
313
|
+
ticket = await ticketCall('ticket_revise', { note });
|
|
314
|
+
await options.invoke('execution_continue', { originSessionId: options.originSessionId, jobId,
|
|
315
|
+
clientRequestId: `${roleId}:${kase.id}:${stamp}:round-${round + 1}`, input: { prompt: feedback(ticket) } });
|
|
316
|
+
log(`已打回执行者(第 ${round + 1} 轮)`);
|
|
317
|
+
};
|
|
318
|
+
// Whatever stops the run, the ticket is closed and the run is recorded; a host error is rethrown afterwards.
|
|
319
|
+
let hostError;
|
|
320
|
+
try {
|
|
321
|
+
if (prior) {
|
|
322
|
+
if (ticket.status === 'stopped')
|
|
323
|
+
ticket = await ticketCall('ticket_reopen', { note: 'rsi run 接着跑' });
|
|
324
|
+
for (const id of [jobId, qaJobId])
|
|
325
|
+
if (id)
|
|
326
|
+
await options.invoke('execution_rewatch', { originSessionId: options.originSessionId, jobId: id });
|
|
327
|
+
const view = resumingReview ? undefined : await options.invoke('execution_get', { originSessionId: options.originSessionId, jobId });
|
|
328
|
+
if (view?.executionStatus === 'failed') {
|
|
329
|
+
await options.invoke('execution_continue', { originSessionId: options.originSessionId, jobId,
|
|
330
|
+
clientRequestId: `${roleId}:${kase.id}:${stamp}:round-${startRound}-resume-${now().toISOString()}`,
|
|
331
|
+
input: { prompt: `上一轮执行中断了,工作目录里的文件都还在,接着把这一轮做完。${ticket.status === 'in_revision' ? `\n\n${steps(ticket)}` : ''}` } });
|
|
332
|
+
log(`任务 ${jobId} 上一轮失败了,已让执行者接着做(第 ${startRound} 轮)`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (let round = startRound;; round++) {
|
|
336
|
+
const reviewOnly = resumingReview && round === startRound;
|
|
337
|
+
const executionStatus = reviewOnly ? 'completed' : await wait(jobId);
|
|
338
|
+
if (!reviewOnly && round > 1 && executionStatus === 'completed') {
|
|
339
|
+
ticket = await ticketCall('ticket_get');
|
|
340
|
+
if (ticket.status !== 'ready_for_review') {
|
|
341
|
+
const problems = [`还没有提交任务单(待处理 ${pendingItems(ticket).map(item => item.id).join('、') || '0 条'})`];
|
|
342
|
+
rounds.push({ round, jobId, executionStatus, passed: false, results: [], ticketErrors: problems });
|
|
343
|
+
log(`第 ${round} 轮:任务单没有按规定处理(${problems.join(';')})`);
|
|
344
|
+
if (round !== excusedRound) {
|
|
345
|
+
if (bounces >= maxBounces) {
|
|
346
|
+
stopReason = 'max_bounces';
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
bounces++;
|
|
350
|
+
}
|
|
351
|
+
await sendBack(round, current => ticketBouncePrompt(steps, current, problems), '执行者没有提交任务单');
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const checked = executionStatus === 'completed' ? await check(work, python, jobId) : { results: [] };
|
|
356
|
+
const results = checked.results, programPassed = executionStatus === 'completed' && results.every(result => result.pass);
|
|
357
|
+
const record = { round, jobId, executionStatus, passed: programPassed, results, ...(checked.outlineSha256 ? { outlineSha256: checked.outlineSha256 } : {}) };
|
|
358
|
+
rounds.push(record);
|
|
359
|
+
log(`第 ${round} 轮:${programPassed ? '程序检查通过' : executionStatus === 'completed' ? `未通过 ${results.filter(r => !r.pass).map(r => r.itemId).join('、')}` : `执行未完成(${executionStatus})`}`);
|
|
360
|
+
if (executionStatus !== 'completed') {
|
|
361
|
+
stopReason = 'not_completed';
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
if (!reviewOnly || ticket.status !== 'in_review')
|
|
365
|
+
ticket = await ticketCall('ticket_checks', { results });
|
|
366
|
+
let feedback, note;
|
|
367
|
+
if (!programPassed) {
|
|
368
|
+
if (bounces >= maxBounces) {
|
|
369
|
+
stopReason = 'max_bounces';
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
bounces++;
|
|
373
|
+
feedback = current => bouncePrompt(steps, current, round);
|
|
374
|
+
note = '程序检查没有通过';
|
|
375
|
+
}
|
|
376
|
+
else if (options.qa) {
|
|
377
|
+
record.review = await review(round, reviewOnly);
|
|
378
|
+
const verdict = record.review.review?.verdict;
|
|
379
|
+
record.passed = verdict === 'pass';
|
|
380
|
+
log(`第 ${round} 轮质检:${verdict ? `${verdict === 'pass' ? '通过' : '需要修改'},${JSON.stringify(record.review.review.scores)}` : record.review.error}`);
|
|
381
|
+
if (!verdict) {
|
|
382
|
+
stopReason = 'review_failed';
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
const accepted = record.review.review;
|
|
386
|
+
ticket = await ticketCall('ticket_review', { review: accepted, ...(record.review.jobId ? { qaJobId: record.review.jobId } : {}) });
|
|
387
|
+
if (verdict === 'pass')
|
|
388
|
+
break;
|
|
389
|
+
reviews.push(accepted);
|
|
390
|
+
if (stalled(reviews)) {
|
|
391
|
+
stopReason = 'stalled';
|
|
392
|
+
log('质检意见连续两轮没有改到位,或分数连续两轮没有提高,停止修改');
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
if (revisions >= (options.qa.maxRevisions ?? 3)) {
|
|
396
|
+
stopReason = 'max_revisions';
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
revisions++;
|
|
400
|
+
feedback = current => revisePrompt(steps, current, accepted, round);
|
|
401
|
+
note = '质检要求修改';
|
|
402
|
+
}
|
|
403
|
+
else
|
|
404
|
+
break;
|
|
405
|
+
await sendBack(round, feedback, note);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
hostError = error;
|
|
410
|
+
stopReason = 'host_error';
|
|
411
|
+
log(`宿主出错,停止运行:${error instanceof Error ? error.message : String(error)}`);
|
|
412
|
+
for (const id of [jobId, qaJobId])
|
|
413
|
+
if (id)
|
|
414
|
+
await unwatch(id, `rsi run 出错:${error instanceof Error ? error.message : String(error)}`);
|
|
415
|
+
}
|
|
416
|
+
const last = rounds.at(-1), passed = !hostError && Boolean(last?.passed);
|
|
417
|
+
// Revising further cannot help when QA says a locked item is in the way; only a person can change it.
|
|
418
|
+
if ((stopReason === 'stalled' || stopReason === 'max_revisions') && ticket.proposals.some(p => p.kind === 'locked'))
|
|
419
|
+
stopReason = 'needs_human';
|
|
420
|
+
try {
|
|
421
|
+
ticket = await ticketCall('ticket_close', { status: passed ? 'closed' : 'stopped', stopReason });
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
if (!hostError)
|
|
425
|
+
throw error;
|
|
426
|
+
} // The gateway may be what failed; the ledger line below still records the run.
|
|
427
|
+
const report = { roleId, caseId: kase.id, phase, role, repo: kase.input.repo, commit: kase.input.commit, workDirectory: work, jobId,
|
|
428
|
+
outlinePath, ticketPath, featuresConfirmed: Boolean(features.confirmation), rounds,
|
|
429
|
+
passed, stopReason, startedAt, finishedAt: now().toISOString(),
|
|
430
|
+
...(hostError ? { error: hostError instanceof Error ? hostError.message : String(hostError) } : {}) };
|
|
431
|
+
await writeFile(path.join(work, 'run.json'), JSON.stringify(report, null, 2) + '\n');
|
|
432
|
+
const first = rounds[0];
|
|
433
|
+
const entry = { startedAt, phase, caseId: kase.id, caseKind: kase.kind, role, passed, stopReason,
|
|
434
|
+
firstDraftPassed: first?.executionStatus === 'completed' && first.results.every(result => result.pass), bounces, revisions,
|
|
435
|
+
scores: rounds.flatMap(r => r.review?.review ? [r.review.review.scores] : []),
|
|
436
|
+
mustIssues: unsettledMust(ticket).length, proposals: ticket.proposals.map(({ kind, text }) => ({ kind, text })), workDirectory: work, ticketPath,
|
|
437
|
+
jobId, originSessionId: options.originSessionId };
|
|
438
|
+
await appendFile(ledgerPath(options.workspace, roleId), JSON.stringify(entry) + '\n');
|
|
439
|
+
log(`停止原因:${stopReason}`);
|
|
440
|
+
if (hostError)
|
|
441
|
+
throw hostError;
|
|
442
|
+
return report;
|
|
443
|
+
}
|