@1agents/acp-service 0.9.0 → 0.9.1
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 +24 -0
- package/dist/bin/process.d.ts +4 -0
- package/dist/bin/process.js +57 -0
- 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 +6 -0
- package/dist/src/a2a/executor.js +112 -12
- package/dist/src/a2a/gateway.d.ts +537 -2
- package/dist/src/a2a/gateway.js +1014 -87
- 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 +23 -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 +45 -0
- 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/process-request.d.ts +151 -0
- package/dist/src/execution/process-request.js +177 -0
- package/dist/src/execution/targets.d.ts +15 -0
- package/dist/src/execution/targets.js +22 -3
- 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/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 +3 -1
- package/skills/acp-service/references/a2a.md +17 -5
- package/skills/acp-service/references/dsh.md +2 -0
- package/skills/acp-service/references/roles-and-tasks.md +1 -1
- 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,326 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { JobLedger } from './ledger.js';
|
|
3
|
+
export declare const checkResultSchema: z.ZodObject<{
|
|
4
|
+
itemId: z.ZodString;
|
|
5
|
+
pass: z.ZodBoolean;
|
|
6
|
+
evidence: z.ZodArray<z.ZodUnknown>;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export declare const qualityReviewSchema: z.ZodObject<{
|
|
9
|
+
verdict: z.ZodEnum<{
|
|
10
|
+
pass: "pass";
|
|
11
|
+
revise: "revise";
|
|
12
|
+
}>;
|
|
13
|
+
summary: z.ZodString;
|
|
14
|
+
scores: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
15
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
16
|
+
where: z.ZodString;
|
|
17
|
+
problem: z.ZodString;
|
|
18
|
+
suggestion: z.ZodString;
|
|
19
|
+
severity: z.ZodEnum<{
|
|
20
|
+
must: "must";
|
|
21
|
+
should: "should";
|
|
22
|
+
}>;
|
|
23
|
+
}, z.core.$strict>>;
|
|
24
|
+
previous: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
status: z.ZodEnum<{
|
|
27
|
+
fixed: "fixed";
|
|
28
|
+
partly: "partly";
|
|
29
|
+
not_fixed: "not_fixed";
|
|
30
|
+
withdrawn: "withdrawn";
|
|
31
|
+
}>;
|
|
32
|
+
note: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, z.core.$strict>>>;
|
|
34
|
+
proposals: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
35
|
+
kind: z.ZodEnum<{
|
|
36
|
+
check: "check";
|
|
37
|
+
role: "role";
|
|
38
|
+
qa: "qa";
|
|
39
|
+
locked: "locked";
|
|
40
|
+
}>;
|
|
41
|
+
text: z.ZodString;
|
|
42
|
+
}, z.core.$strict>>>;
|
|
43
|
+
}, z.core.$loose>;
|
|
44
|
+
export type CheckResult = z.infer<typeof checkResultSchema>;
|
|
45
|
+
export type QualityReview = z.infer<typeof qualityReviewSchema>;
|
|
46
|
+
export type TicketActor = 'executor' | 'qa' | 'host' | 'person' | 'coach';
|
|
47
|
+
/** Who settled a proposal: a person, or a coach agent identified by the harness session it runs in. */
|
|
48
|
+
export interface ProposalSettler {
|
|
49
|
+
kind: 'person' | 'coach';
|
|
50
|
+
agent?: string;
|
|
51
|
+
sessionId?: string;
|
|
52
|
+
}
|
|
53
|
+
export type ItemState = 'open' | 'done' | 'disputed' | 'verified' | 'reopened' | 'withdrawn';
|
|
54
|
+
export type TicketStatus = 'drafting' | 'in_revision' | 'ready_for_review' | 'in_review' | 'closed' | 'stopped';
|
|
55
|
+
export interface TicketLog {
|
|
56
|
+
round: number;
|
|
57
|
+
by: TicketActor;
|
|
58
|
+
action: string;
|
|
59
|
+
note?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface TicketItem {
|
|
62
|
+
id: string;
|
|
63
|
+
source: 'qa' | 'program';
|
|
64
|
+
raisedInRound: number;
|
|
65
|
+
severity: 'must' | 'should';
|
|
66
|
+
where: string;
|
|
67
|
+
problem: string;
|
|
68
|
+
suggestion?: string;
|
|
69
|
+
checkId?: string;
|
|
70
|
+
evidence?: unknown[];
|
|
71
|
+
state: ItemState;
|
|
72
|
+
log: TicketLog[];
|
|
73
|
+
}
|
|
74
|
+
export interface TicketProposal {
|
|
75
|
+
id: string;
|
|
76
|
+
kind: NonNullable<QualityReview['proposals']>[number]['kind'];
|
|
77
|
+
text: string;
|
|
78
|
+
raisedInRound: number;
|
|
79
|
+
state: 'open' | 'accepted' | 'rejected' | 'done';
|
|
80
|
+
note?: string;
|
|
81
|
+
by?: ProposalSettler;
|
|
82
|
+
}
|
|
83
|
+
export interface Ticket {
|
|
84
|
+
schemaVersion: 1;
|
|
85
|
+
roleId: string;
|
|
86
|
+
caseId: string;
|
|
87
|
+
outline: 'outline.json';
|
|
88
|
+
status: TicketStatus;
|
|
89
|
+
/** The executor round now under way; executor log entries carry it. */
|
|
90
|
+
round: number;
|
|
91
|
+
stopReason?: string;
|
|
92
|
+
/** Where a stopped ticket stood, so a run that goes on picks it up there. */
|
|
93
|
+
stoppedFrom?: TicketStatus;
|
|
94
|
+
/** The read-only copy rewritten on every change, usually <work>/ticket.json. */
|
|
95
|
+
exportPath?: string;
|
|
96
|
+
items: TicketItem[];
|
|
97
|
+
proposals: TicketProposal[];
|
|
98
|
+
history: {
|
|
99
|
+
round: number;
|
|
100
|
+
by: TicketActor;
|
|
101
|
+
action: string;
|
|
102
|
+
verdict?: string;
|
|
103
|
+
scores?: Record<string, number>;
|
|
104
|
+
summary?: string;
|
|
105
|
+
note?: string;
|
|
106
|
+
}[];
|
|
107
|
+
}
|
|
108
|
+
/** One change, appended to the ledger as an event of this type. */
|
|
109
|
+
export interface TicketChange {
|
|
110
|
+
type: `ticket.${string}`;
|
|
111
|
+
data: {
|
|
112
|
+
actor: TicketActor;
|
|
113
|
+
round: number;
|
|
114
|
+
itemId?: string;
|
|
115
|
+
note?: string;
|
|
116
|
+
[key: string]: unknown;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** An operation the ticket's rules do not allow; the message is for the agent or person who asked. */
|
|
120
|
+
export declare class TicketError extends Error {
|
|
121
|
+
}
|
|
122
|
+
export declare const pendingItems: (ticket: Ticket) => TicketItem[];
|
|
123
|
+
/** Must-fix items nobody has confirmed as settled. */
|
|
124
|
+
export declare const unsettledMust: (ticket: Ticket) => TicketItem[];
|
|
125
|
+
export declare function openTicket(roleId: string, caseId: string, exportPath?: string): {
|
|
126
|
+
ticket: Ticket;
|
|
127
|
+
changes: TicketChange[];
|
|
128
|
+
};
|
|
129
|
+
/** Host: failed checks become or reopen program items, items whose check now passes are verified; all passing moves the ticket to review. */
|
|
130
|
+
export declare function applyChecks(ticket: Ticket, results: CheckResult[]): TicketChange[];
|
|
131
|
+
/** Host, on QA's behalf: QA's verdicts on handled items, its new issues and its proposals, merged into the ticket. */
|
|
132
|
+
export declare function applyReview(ticket: Ticket, review: QualityReview, qaJobId?: string): TicketChange[];
|
|
133
|
+
/** Host: the ticket goes back to the executor for the next round. */
|
|
134
|
+
export declare function startRevision(ticket: Ticket, note?: string): TicketChange[];
|
|
135
|
+
/** Executor: a pending item is done or disputed, with a note, in the current round. */
|
|
136
|
+
export declare function markItem(ticket: Ticket, itemId: string, state: string, note: string): TicketChange[];
|
|
137
|
+
/** Executor: everything is handled; the ticket is ready for the host's checks. */
|
|
138
|
+
export declare function submitTicket(ticket: Ticket): TicketChange[];
|
|
139
|
+
/** Person or coach: what became of a proposal. Allowed after the run ends, which is when the coach reads them. */
|
|
140
|
+
export declare function setProposal(ticket: Ticket, proposalId: string, state: 'accepted' | 'rejected' | 'done', note?: string, by?: ProposalSettler): TicketChange[];
|
|
141
|
+
/** Host: the run is over, passed (closed) or not (stopped). */
|
|
142
|
+
export declare function closeTicket(ticket: Ticket, status: 'closed' | 'stopped', stopReason?: string): TicketChange[];
|
|
143
|
+
/** Host: a stopped run goes on, so the ticket returns to where it stood; work going back to the executor enters a revision if it had left the executor's hands. */
|
|
144
|
+
export declare function reopenTicket(ticket: Ticket, note?: string, forExecutor?: boolean): TicketChange[];
|
|
145
|
+
export declare const TICKET_METHODS: {
|
|
146
|
+
ticket_get: {
|
|
147
|
+
description: string;
|
|
148
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
149
|
+
originSessionId: z.ZodString;
|
|
150
|
+
jobId: z.ZodString;
|
|
151
|
+
}, z.core.$strict>>;
|
|
152
|
+
};
|
|
153
|
+
ticket_open: {
|
|
154
|
+
description: string;
|
|
155
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
156
|
+
originSessionId: z.ZodString;
|
|
157
|
+
jobId: z.ZodString;
|
|
158
|
+
roleId: z.ZodString;
|
|
159
|
+
caseId: z.ZodString;
|
|
160
|
+
exportPath: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$strict>>;
|
|
162
|
+
};
|
|
163
|
+
ticket_checks: {
|
|
164
|
+
description: string;
|
|
165
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
166
|
+
originSessionId: z.ZodString;
|
|
167
|
+
jobId: z.ZodString;
|
|
168
|
+
results: z.ZodArray<z.ZodObject<{
|
|
169
|
+
itemId: z.ZodString;
|
|
170
|
+
pass: z.ZodBoolean;
|
|
171
|
+
evidence: z.ZodArray<z.ZodUnknown>;
|
|
172
|
+
}, z.core.$strict>>;
|
|
173
|
+
}, z.core.$strict>>;
|
|
174
|
+
};
|
|
175
|
+
ticket_review: {
|
|
176
|
+
description: string;
|
|
177
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
178
|
+
originSessionId: z.ZodString;
|
|
179
|
+
jobId: z.ZodString;
|
|
180
|
+
review: z.ZodObject<{
|
|
181
|
+
verdict: z.ZodEnum<{
|
|
182
|
+
pass: "pass";
|
|
183
|
+
revise: "revise";
|
|
184
|
+
}>;
|
|
185
|
+
summary: z.ZodString;
|
|
186
|
+
scores: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
187
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
188
|
+
where: z.ZodString;
|
|
189
|
+
problem: z.ZodString;
|
|
190
|
+
suggestion: z.ZodString;
|
|
191
|
+
severity: z.ZodEnum<{
|
|
192
|
+
must: "must";
|
|
193
|
+
should: "should";
|
|
194
|
+
}>;
|
|
195
|
+
}, z.core.$strict>>;
|
|
196
|
+
previous: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
197
|
+
id: z.ZodString;
|
|
198
|
+
status: z.ZodEnum<{
|
|
199
|
+
fixed: "fixed";
|
|
200
|
+
partly: "partly";
|
|
201
|
+
not_fixed: "not_fixed";
|
|
202
|
+
withdrawn: "withdrawn";
|
|
203
|
+
}>;
|
|
204
|
+
note: z.ZodOptional<z.ZodString>;
|
|
205
|
+
}, z.core.$strict>>>;
|
|
206
|
+
proposals: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
207
|
+
kind: z.ZodEnum<{
|
|
208
|
+
check: "check";
|
|
209
|
+
role: "role";
|
|
210
|
+
qa: "qa";
|
|
211
|
+
locked: "locked";
|
|
212
|
+
}>;
|
|
213
|
+
text: z.ZodString;
|
|
214
|
+
}, z.core.$strict>>>;
|
|
215
|
+
}, z.core.$loose>;
|
|
216
|
+
qaJobId: z.ZodOptional<z.ZodString>;
|
|
217
|
+
}, z.core.$strict>>;
|
|
218
|
+
};
|
|
219
|
+
ticket_revise: {
|
|
220
|
+
description: string;
|
|
221
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
222
|
+
originSessionId: z.ZodString;
|
|
223
|
+
jobId: z.ZodString;
|
|
224
|
+
note: z.ZodOptional<z.ZodString>;
|
|
225
|
+
}, z.core.$strict>>;
|
|
226
|
+
};
|
|
227
|
+
ticket_show: {
|
|
228
|
+
description: string;
|
|
229
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
230
|
+
jobId: z.ZodString;
|
|
231
|
+
attemptId: z.ZodOptional<z.ZodString>;
|
|
232
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
233
|
+
via: z.ZodOptional<z.ZodEnum<{
|
|
234
|
+
cli: "cli";
|
|
235
|
+
dsh: "dsh";
|
|
236
|
+
mcp: "mcp";
|
|
237
|
+
}>>;
|
|
238
|
+
}, z.core.$strict>>;
|
|
239
|
+
};
|
|
240
|
+
ticket_mark: {
|
|
241
|
+
description: string;
|
|
242
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
243
|
+
jobId: z.ZodString;
|
|
244
|
+
attemptId: z.ZodOptional<z.ZodString>;
|
|
245
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
246
|
+
via: z.ZodOptional<z.ZodEnum<{
|
|
247
|
+
cli: "cli";
|
|
248
|
+
dsh: "dsh";
|
|
249
|
+
mcp: "mcp";
|
|
250
|
+
}>>;
|
|
251
|
+
itemId: z.ZodString;
|
|
252
|
+
state: z.ZodEnum<{
|
|
253
|
+
done: "done";
|
|
254
|
+
disputed: "disputed";
|
|
255
|
+
}>;
|
|
256
|
+
note: z.ZodString;
|
|
257
|
+
}, z.core.$strict>>;
|
|
258
|
+
};
|
|
259
|
+
ticket_submit: {
|
|
260
|
+
description: string;
|
|
261
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
262
|
+
jobId: z.ZodString;
|
|
263
|
+
attemptId: z.ZodOptional<z.ZodString>;
|
|
264
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
265
|
+
via: z.ZodOptional<z.ZodEnum<{
|
|
266
|
+
cli: "cli";
|
|
267
|
+
dsh: "dsh";
|
|
268
|
+
mcp: "mcp";
|
|
269
|
+
}>>;
|
|
270
|
+
}, z.core.$strict>>;
|
|
271
|
+
};
|
|
272
|
+
ticket_proposal: {
|
|
273
|
+
description: string;
|
|
274
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
275
|
+
originSessionId: z.ZodString;
|
|
276
|
+
jobId: z.ZodString;
|
|
277
|
+
proposalId: z.ZodString;
|
|
278
|
+
state: z.ZodEnum<{
|
|
279
|
+
done: "done";
|
|
280
|
+
accepted: "accepted";
|
|
281
|
+
rejected: "rejected";
|
|
282
|
+
}>;
|
|
283
|
+
note: z.ZodOptional<z.ZodString>;
|
|
284
|
+
by: z.ZodOptional<z.ZodObject<{
|
|
285
|
+
kind: z.ZodEnum<{
|
|
286
|
+
person: "person";
|
|
287
|
+
coach: "coach";
|
|
288
|
+
}>;
|
|
289
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
290
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
291
|
+
}, z.core.$strict>>;
|
|
292
|
+
}, z.core.$strict>>;
|
|
293
|
+
};
|
|
294
|
+
ticket_close: {
|
|
295
|
+
description: string;
|
|
296
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
297
|
+
originSessionId: z.ZodString;
|
|
298
|
+
jobId: z.ZodString;
|
|
299
|
+
status: z.ZodEnum<{
|
|
300
|
+
stopped: "stopped";
|
|
301
|
+
closed: "closed";
|
|
302
|
+
}>;
|
|
303
|
+
stopReason: z.ZodOptional<z.ZodString>;
|
|
304
|
+
}, z.core.$strict>>;
|
|
305
|
+
};
|
|
306
|
+
ticket_reopen: {
|
|
307
|
+
description: string;
|
|
308
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
309
|
+
originSessionId: z.ZodString;
|
|
310
|
+
jobId: z.ZodString;
|
|
311
|
+
note: z.ZodOptional<z.ZodString>;
|
|
312
|
+
}, z.core.$strict>>;
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
/** An explicit continue gives the executor another go, so a stopped ticket opens with it; a job without a ticket has nothing to do. */
|
|
316
|
+
export declare function reopenForContinue(ledger: JobLedger, originSessionId: string, jobId: string): void;
|
|
317
|
+
/**
|
|
318
|
+
* The gateway's ticket methods. The method decides the actor: the host opens, merges checks and reviews, sends back
|
|
319
|
+
* and closes; a person settles proposals; the executor shows, marks and submits. The executor's call names its
|
|
320
|
+
* running attempt and session, and the ledger checks that the attempt is the job's current, unfinished one and,
|
|
321
|
+
* once the host has reported which session runs it, that the session matches; a CLI call names only the job and acts
|
|
322
|
+
* for its current attempt. Nothing here proves the call came from that session's agent: the DSH tools and the MCP
|
|
323
|
+
* server resolve the session themselves, the CLI is trusted to run in the executor's shell, and this MVP does not
|
|
324
|
+
* defend against a local caller that bypasses them with the right IDs.
|
|
325
|
+
*/
|
|
326
|
+
export declare function invokeTicket(ledger: JobLedger, method: string, params: unknown): Ticket;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The task ticket on an executor's job: every issue sent back, how the executor handled it and who confirmed it.
|
|
3
|
+
* The ledger keeps it with the job; each operation here belongs to one actor and returns the changes it made,
|
|
4
|
+
* which the ledger appends as `ticket.*` events, so who did what is recorded by the system rather than declared.
|
|
5
|
+
* Failed program checks become items the host verifies by re-running them; the host merges QA's review.
|
|
6
|
+
* When the ticket names an export path, every change also rewrites that read-only copy for people to read.
|
|
7
|
+
*/
|
|
8
|
+
import { rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
export const checkResultSchema = z.object({ itemId: z.string(), pass: z.boolean(), evidence: z.array(z.unknown()) }).strict();
|
|
12
|
+
export const qualityReviewSchema = z.object({
|
|
13
|
+
verdict: z.enum(['pass', 'revise']),
|
|
14
|
+
summary: z.string().trim().min(1).max(4000),
|
|
15
|
+
scores: z.record(z.string(), z.number().int().min(1).max(5)),
|
|
16
|
+
issues: z.array(z.object({ where: z.string().trim().min(1).max(300), problem: z.string().trim().min(1).max(2000),
|
|
17
|
+
suggestion: z.string().trim().min(1).max(2000), severity: z.enum(['must', 'should']) }).strict()).max(30),
|
|
18
|
+
/** On a re-review: QA's verdict on each ticket item the executor handled, by item id. */
|
|
19
|
+
previous: z.array(z.object({ id: z.string().trim().min(1).max(40), status: z.enum(['fixed', 'partly', 'not_fixed', 'withdrawn']),
|
|
20
|
+
note: z.string().trim().max(2000).optional() }).strict()).max(30).optional(),
|
|
21
|
+
/** Changes to the role itself: a program check, the executor's or QA's instructions, or a locked item only a person can change. */
|
|
22
|
+
proposals: z.array(z.object({ kind: z.enum(['check', 'role', 'qa', 'locked']), text: z.string().trim().min(1).max(2000) }).strict()).max(10).optional(),
|
|
23
|
+
}).passthrough().refine(review => review.verdict === 'pass' || review.issues.length > 0, { message: 'A revise verdict needs at least one issue' });
|
|
24
|
+
/** An operation the ticket's rules do not allow; the message is for the agent or person who asked. */
|
|
25
|
+
export class TicketError extends Error {
|
|
26
|
+
}
|
|
27
|
+
const fail = (message) => { throw new TicketError(message); };
|
|
28
|
+
const PENDING = ['open', 'reopened'];
|
|
29
|
+
export const pendingItems = (ticket) => ticket.items.filter(item => PENDING.includes(item.state));
|
|
30
|
+
/** Must-fix items nobody has confirmed as settled. */
|
|
31
|
+
export const unsettledMust = (ticket) => ticket.items.filter(item => item.severity === 'must' && item.state !== 'verified' && item.state !== 'withdrawn');
|
|
32
|
+
const isFinal = (ticket) => ticket.status === 'closed' || ticket.status === 'stopped';
|
|
33
|
+
const expect = (ticket, allowed, what) => {
|
|
34
|
+
if (!allowed.includes(ticket.status))
|
|
35
|
+
fail(`任务单状态是 ${ticket.status},${what}`);
|
|
36
|
+
};
|
|
37
|
+
export function openTicket(roleId, caseId, exportPath) {
|
|
38
|
+
return { ticket: { schemaVersion: 1, roleId, caseId, outline: 'outline.json', status: 'drafting', round: 1, ...(exportPath ? { exportPath } : {}),
|
|
39
|
+
items: [], proposals: [], history: [] },
|
|
40
|
+
changes: [{ type: 'ticket.opened', data: { actor: 'host', round: 1, roleId, caseId } }] };
|
|
41
|
+
}
|
|
42
|
+
/** Host: failed checks become or reopen program items, items whose check now passes are verified; all passing moves the ticket to review. */
|
|
43
|
+
export function applyChecks(ticket, results) {
|
|
44
|
+
expect(ticket, ['drafting', 'ready_for_review'], '只有执行者交稿后才能合并程序检查');
|
|
45
|
+
const round = ticket.round, changes = [];
|
|
46
|
+
const settle = (item, state, note) => {
|
|
47
|
+
item.state = state;
|
|
48
|
+
item.log.push({ round, by: 'host', action: state, note });
|
|
49
|
+
changes.push({ type: 'ticket.item_settled', data: { actor: 'host', round, itemId: item.id, state, note } });
|
|
50
|
+
};
|
|
51
|
+
for (const result of results) {
|
|
52
|
+
const item = ticket.items.find(entry => entry.source === 'program' && entry.checkId === result.itemId && entry.state !== 'verified');
|
|
53
|
+
if (result.pass) {
|
|
54
|
+
if (item)
|
|
55
|
+
settle(item, 'verified', `${result.itemId} 通过`);
|
|
56
|
+
}
|
|
57
|
+
else if (item) {
|
|
58
|
+
item.evidence = result.evidence;
|
|
59
|
+
if (item.state !== 'open')
|
|
60
|
+
settle(item, 'reopened', `${result.itemId} 仍未通过`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const where = result.evidence[0]?.path;
|
|
64
|
+
const raised = { id: `P${round}-${result.itemId}`, source: 'program', raisedInRound: round, severity: 'must',
|
|
65
|
+
where: typeof where === 'string' ? where : result.itemId, problem: `程序检查 ${result.itemId} 未通过`, checkId: result.itemId,
|
|
66
|
+
evidence: result.evidence, state: 'open', log: [{ round, by: 'host', action: 'raised' }] };
|
|
67
|
+
ticket.items.push(raised);
|
|
68
|
+
changes.push({ type: 'ticket.item_raised', data: { actor: 'host', round, itemId: raised.id, source: 'program', severity: 'must', where: raised.where, problem: raised.problem } });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const failed = results.filter(result => !result.pass).map(result => result.itemId);
|
|
72
|
+
if (!failed.length)
|
|
73
|
+
ticket.status = 'in_review';
|
|
74
|
+
changes.push({ type: 'ticket.checked', data: { actor: 'host', round, passed: !failed.length, failed, status: ticket.status } });
|
|
75
|
+
return changes;
|
|
76
|
+
}
|
|
77
|
+
const verdicts = { fixed: 'verified', partly: 'reopened', not_fixed: 'reopened', withdrawn: 'withdrawn' };
|
|
78
|
+
/** Host, on QA's behalf: QA's verdicts on handled items, its new issues and its proposals, merged into the ticket. */
|
|
79
|
+
export function applyReview(ticket, review, qaJobId) {
|
|
80
|
+
expect(ticket, ['in_review'], '只有程序检查通过后才能合并质检意见');
|
|
81
|
+
const round = ticket.round, changes = [], qa = qaJobId ? { qaJobId } : {};
|
|
82
|
+
for (const entry of review.previous ?? []) {
|
|
83
|
+
const item = ticket.items.find(candidate => candidate.id === entry.id && candidate.source === 'qa');
|
|
84
|
+
if (!item || item.state === 'verified' || item.state === 'withdrawn')
|
|
85
|
+
continue;
|
|
86
|
+
item.state = verdicts[entry.status];
|
|
87
|
+
item.log.push({ round, by: 'qa', action: entry.status, ...(entry.note ? { note: entry.note } : {}) });
|
|
88
|
+
changes.push({ type: 'ticket.item_settled', data: { actor: 'qa', round, itemId: item.id, state: item.state, verdict: entry.status, ...(entry.note ? { note: entry.note } : {}), ...qa } });
|
|
89
|
+
}
|
|
90
|
+
review.issues.forEach((issue, index) => {
|
|
91
|
+
const id = `Q${round}-${index + 1}`;
|
|
92
|
+
ticket.items.push({ id, source: 'qa', raisedInRound: round, severity: issue.severity, where: issue.where, problem: issue.problem,
|
|
93
|
+
suggestion: issue.suggestion, state: 'open', log: [{ round, by: 'qa', action: 'raised' }] });
|
|
94
|
+
changes.push({ type: 'ticket.item_raised', data: { actor: 'qa', round, itemId: id, source: 'qa', severity: issue.severity, where: issue.where, problem: issue.problem, ...qa } });
|
|
95
|
+
});
|
|
96
|
+
// A proposal QA repeats word for word is already on the ticket.
|
|
97
|
+
(review.proposals ?? []).forEach((proposal, index) => {
|
|
98
|
+
if (ticket.proposals.some(known => known.kind === proposal.kind && known.text === proposal.text))
|
|
99
|
+
return;
|
|
100
|
+
const id = `R${round}-${index + 1}`;
|
|
101
|
+
ticket.proposals.push({ id, kind: proposal.kind, text: proposal.text, raisedInRound: round, state: 'open' });
|
|
102
|
+
changes.push({ type: 'ticket.proposal_raised', data: { actor: 'qa', round, proposalId: id, kind: proposal.kind, text: proposal.text, ...qa } });
|
|
103
|
+
});
|
|
104
|
+
ticket.history.push({ round, by: 'qa', action: 'reviewed', verdict: review.verdict, scores: review.scores, summary: review.summary });
|
|
105
|
+
changes.push({ type: 'ticket.reviewed', data: { actor: 'qa', round, verdict: review.verdict, scores: review.scores, summary: review.summary, ...qa } });
|
|
106
|
+
return changes;
|
|
107
|
+
}
|
|
108
|
+
/** Host: the ticket goes back to the executor for the next round. */
|
|
109
|
+
export function startRevision(ticket, note) {
|
|
110
|
+
if (isFinal(ticket))
|
|
111
|
+
fail(`任务单已经 ${ticket.status}`);
|
|
112
|
+
ticket.round++;
|
|
113
|
+
ticket.status = 'in_revision';
|
|
114
|
+
return [{ type: 'ticket.revision_started', data: { actor: 'host', round: ticket.round, ...(note ? { note } : {}) } }];
|
|
115
|
+
}
|
|
116
|
+
/** Executor: a pending item is done or disputed, with a note, in the current round. */
|
|
117
|
+
export function markItem(ticket, itemId, state, note) {
|
|
118
|
+
expect(ticket, ['in_revision'], '现在不能修改');
|
|
119
|
+
const item = ticket.items.find(entry => entry.id === itemId) ?? fail(`任务单上没有 ${itemId}`);
|
|
120
|
+
if (!PENDING.includes(item.state))
|
|
121
|
+
fail(`${itemId} 已经是 ${item.state},只能处理 open 或 reopened 的意见`);
|
|
122
|
+
if (state !== 'done' && state !== 'disputed')
|
|
123
|
+
fail('只能标为 done(已改)或 disputed(不同意)');
|
|
124
|
+
const text = note.trim();
|
|
125
|
+
if (!text)
|
|
126
|
+
fail('说明不能为空:写清怎么改的,或者不同意的理由');
|
|
127
|
+
item.state = state;
|
|
128
|
+
item.log.push({ round: ticket.round, by: 'executor', action: state, note: text });
|
|
129
|
+
return [{ type: 'ticket.item_marked', data: { actor: 'executor', round: ticket.round, itemId, state, note: text } }];
|
|
130
|
+
}
|
|
131
|
+
/** Executor: everything is handled; the ticket is ready for the host's checks. */
|
|
132
|
+
export function submitTicket(ticket) {
|
|
133
|
+
expect(ticket, ['in_revision'], '现在不能提交');
|
|
134
|
+
const left = pendingItems(ticket);
|
|
135
|
+
if (left.length)
|
|
136
|
+
fail(`还有 ${left.length} 条没处理:${left.map(item => item.id).join('、')}`);
|
|
137
|
+
ticket.status = 'ready_for_review';
|
|
138
|
+
ticket.history.push({ round: ticket.round, by: 'executor', action: 'submitted' });
|
|
139
|
+
return [{ type: 'ticket.submitted', data: { actor: 'executor', round: ticket.round } }];
|
|
140
|
+
}
|
|
141
|
+
/** Person or coach: what became of a proposal. Allowed after the run ends, which is when the coach reads them. */
|
|
142
|
+
export function setProposal(ticket, proposalId, state, note, by = { kind: 'person' }) {
|
|
143
|
+
const proposal = ticket.proposals.find(entry => entry.id === proposalId) ?? fail(`任务单上没有提议 ${proposalId}`);
|
|
144
|
+
proposal.state = state;
|
|
145
|
+
proposal.by = by;
|
|
146
|
+
if (note)
|
|
147
|
+
proposal.note = note;
|
|
148
|
+
const { kind, ...who } = by;
|
|
149
|
+
return [{ type: 'ticket.proposal_marked', data: { actor: kind, round: ticket.round, proposalId, state, ...(note ? { note } : {}), ...who } }];
|
|
150
|
+
}
|
|
151
|
+
/** The read-only copy; the ledger stays the record, so a copy that cannot be written does not undo the change. */
|
|
152
|
+
function writeExport(ticket) {
|
|
153
|
+
if (!ticket.exportPath)
|
|
154
|
+
return;
|
|
155
|
+
try {
|
|
156
|
+
rmSync(ticket.exportPath, { force: true });
|
|
157
|
+
writeFileSync(ticket.exportPath, JSON.stringify(ticket, null, 2) + '\n', { mode: 0o444 });
|
|
158
|
+
}
|
|
159
|
+
catch { /* The next change, or ticket_get, has the current ticket. */ }
|
|
160
|
+
}
|
|
161
|
+
/** Host: the run is over, passed (closed) or not (stopped). */
|
|
162
|
+
export function closeTicket(ticket, status, stopReason) {
|
|
163
|
+
if (isFinal(ticket))
|
|
164
|
+
fail(`任务单已经 ${ticket.status}`);
|
|
165
|
+
if (status === 'stopped')
|
|
166
|
+
ticket.stoppedFrom = ticket.status;
|
|
167
|
+
ticket.status = status;
|
|
168
|
+
if (status === 'stopped' && stopReason)
|
|
169
|
+
ticket.stopReason = stopReason;
|
|
170
|
+
ticket.history.push({ round: ticket.round, by: 'host', action: status, ...(stopReason ? { note: stopReason } : {}) });
|
|
171
|
+
return [{ type: `ticket.${status}`, data: { actor: 'host', round: ticket.round, ...(stopReason ? { note: stopReason } : {}) } }];
|
|
172
|
+
}
|
|
173
|
+
/** Host: a stopped run goes on, so the ticket returns to where it stood; work going back to the executor enters a revision if it had left the executor's hands. */
|
|
174
|
+
export function reopenTicket(ticket, note, forExecutor = false) {
|
|
175
|
+
expect(ticket, ['stopped'], '只有 stopped 的任务单能重新打开');
|
|
176
|
+
const from = ticket.stoppedFrom ?? (ticket.round === 1 ? 'drafting' : 'in_revision');
|
|
177
|
+
ticket.status = from;
|
|
178
|
+
delete ticket.stoppedFrom;
|
|
179
|
+
delete ticket.stopReason;
|
|
180
|
+
ticket.history.push({ round: ticket.round, by: 'host', action: 'reopened', ...(note ? { note } : {}) });
|
|
181
|
+
const changes = [{ type: 'ticket.reopened', data: { actor: 'host', round: ticket.round, status: from, ...(note ? { note } : {}) } }];
|
|
182
|
+
return forExecutor && from !== 'drafting' && from !== 'in_revision' ? [...changes, ...startRevision(ticket, note)] : changes;
|
|
183
|
+
}
|
|
184
|
+
const id = z.string().trim().min(1).max(512);
|
|
185
|
+
const jobSchema = z.object({ originSessionId: id, jobId: id }).strict();
|
|
186
|
+
const openSchema = jobSchema.extend({ roleId: id, caseId: id,
|
|
187
|
+
exportPath: z.string().min(1).max(4096).refine(value => path.isAbsolute(value) && value.endsWith('.json'), 'exportPath must be an absolute .json path').optional() }).strict();
|
|
188
|
+
const settlerSchema = z.object({ kind: z.enum(['person', 'coach']), agent: id.optional(), sessionId: id.optional() }).strict()
|
|
189
|
+
.refine(by => by.kind === 'coach' || (!by.agent && !by.sessionId), 'Only a coach names an agent session');
|
|
190
|
+
const checksSchema = jobSchema.extend({ results: z.array(checkResultSchema).max(200) }).strict();
|
|
191
|
+
const reviewSchema = jobSchema.extend({ review: qualityReviewSchema, qaJobId: id.optional() }).strict();
|
|
192
|
+
const reviseSchema = jobSchema.extend({ note: z.string().trim().max(2000).optional() }).strict();
|
|
193
|
+
const reopenSchema = reviseSchema;
|
|
194
|
+
const proposalSchema = jobSchema.extend({ proposalId: id, state: z.enum(['accepted', 'rejected', 'done']), note: z.string().trim().max(2000).optional(),
|
|
195
|
+
by: settlerSchema.optional() }).strict();
|
|
196
|
+
const closeSchema = jobSchema.extend({ status: z.enum(['closed', 'stopped']), stopReason: id.optional() }).strict();
|
|
197
|
+
/**
|
|
198
|
+
* The executor names the attempt it is running and its session, never an origin or a role. The DSH tools and the ACP
|
|
199
|
+
* agents' MCP server resolve both from the calling session; the CLI runs in the executor's shell, knows only the job,
|
|
200
|
+
* and acts for the job's current attempt. `via` records which of the three the call came through. Nothing attests who
|
|
201
|
+
* ran the CLI, so its events carry no session and say the caller is unverified rather than borrowing the executor's.
|
|
202
|
+
*/
|
|
203
|
+
const executorBase = z.object({ jobId: id, attemptId: id.optional(), sessionId: id.optional(), via: z.enum(['dsh', 'mcp', 'cli']).optional() }).strict();
|
|
204
|
+
const attested = (input) => input.via === 'cli' ? !input.attemptId && !input.sessionId : Boolean(input.attemptId && input.sessionId);
|
|
205
|
+
const attestation = 'attemptId and sessionId are required, except from the CLI, which names only the job';
|
|
206
|
+
const executorSchema = executorBase.refine(attested, attestation);
|
|
207
|
+
const markSchema = executorBase.extend({ itemId: id, state: z.enum(['done', 'disputed']), note: z.string().max(4000) }).strict().refine(attested, attestation);
|
|
208
|
+
export const TICKET_METHODS = {
|
|
209
|
+
ticket_get: { description: '读取执行者任务上的任务单(意见、状态、轮次、提议、历史)。每次改动都在 execution_events 里留有 ticket.* 事件。', parameters: z.toJSONSchema(jobSchema) },
|
|
210
|
+
ticket_open: { description: '宿主:在执行者任务上开任务单,一个任务一张。exportPath 为只读导出的绝对路径,之后每次改动都会重写。', parameters: z.toJSONSchema(openSchema) },
|
|
211
|
+
ticket_checks: { description: '宿主:执行者交稿后合并本轮程序检查结果。未通过的项成为或重开意见,通过的核实;全部通过则进入审阅。', parameters: z.toJSONSchema(checksSchema) },
|
|
212
|
+
ticket_review: { description: '宿主:审阅中合并质检结果(previous 按意见编号 fixed/partly/not_fixed/withdrawn、新意见、去重后的提议),记录质检任务 qaJobId。质检自己不能改任务单。', parameters: z.toJSONSchema(reviewSchema) },
|
|
213
|
+
ticket_revise: { description: '宿主:把任务单打回执行者,进入下一轮修改。', parameters: z.toJSONSchema(reviseSchema) },
|
|
214
|
+
ticket_show: { description: '执行者:用正在执行的 jobId、attemptId 和 sessionId 读取自己的任务单;命令行只给 jobId,via 为 cli,按该任务当前这一轮执行。', parameters: z.toJSONSchema(executorSchema) },
|
|
215
|
+
ticket_mark: { description: '执行者:修改中把本轮 open 或 reopened 的意见标为 done 或 disputed,必须写说明;只能由正在执行当前轮次的会话调用。', parameters: z.toJSONSchema(markSchema) },
|
|
216
|
+
ticket_submit: { description: '执行者:没有待处理意见时提交任务单,等待宿主检查。', parameters: z.toJSONSchema(executorSchema) },
|
|
217
|
+
ticket_proposal: { description: '人或教练:把一条提议标为 accepted、rejected 或 done,可写说明;运行结束后也可以。by 说明是人还是教练(教练写明所在的智能体会话),缺省为人。', parameters: z.toJSONSchema(proposalSchema) },
|
|
218
|
+
ticket_close: { description: '宿主:运行结束时关单,通过为 closed,否则为 stopped 并写停止原因。', parameters: z.toJSONSchema(closeSchema) },
|
|
219
|
+
ticket_reopen: { description: '宿主:停下的运行接着跑时,把 stopped 的任务单放回停止前的状态。', parameters: z.toJSONSchema(reopenSchema) },
|
|
220
|
+
};
|
|
221
|
+
/** An explicit continue gives the executor another go, so a stopped ticket opens with it; a job without a ticket has nothing to do. */
|
|
222
|
+
export function reopenForContinue(ledger, originSessionId, jobId) {
|
|
223
|
+
let status;
|
|
224
|
+
try {
|
|
225
|
+
status = ledger.ticket(originSessionId, jobId).status;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (error instanceof TicketError)
|
|
229
|
+
return;
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
if (status !== 'stopped')
|
|
233
|
+
return;
|
|
234
|
+
writeExport(ledger.changeTicket(originSessionId, jobId, current => ({ ticket: current, changes: reopenTicket(current, '任务被继续', true) })));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The gateway's ticket methods. The method decides the actor: the host opens, merges checks and reviews, sends back
|
|
238
|
+
* and closes; a person settles proposals; the executor shows, marks and submits. The executor's call names its
|
|
239
|
+
* running attempt and session, and the ledger checks that the attempt is the job's current, unfinished one and,
|
|
240
|
+
* once the host has reported which session runs it, that the session matches; a CLI call names only the job and acts
|
|
241
|
+
* for its current attempt. Nothing here proves the call came from that session's agent: the DSH tools and the MCP
|
|
242
|
+
* server resolve the session themselves, the CLI is trusted to run in the executor's shell, and this MVP does not
|
|
243
|
+
* defend against a local caller that bypasses them with the right IDs.
|
|
244
|
+
*/
|
|
245
|
+
export function invokeTicket(ledger, method, params) {
|
|
246
|
+
const change = (origin, jobId, operation, caller = {}) => {
|
|
247
|
+
const ticket = ledger.changeTicket(origin, jobId, current => ({ ticket: current ?? fail('这个任务还没有任务单'), changes: operation(current) }), caller);
|
|
248
|
+
writeExport(ticket);
|
|
249
|
+
return ticket;
|
|
250
|
+
};
|
|
251
|
+
switch (method) {
|
|
252
|
+
case 'ticket_get': {
|
|
253
|
+
const input = jobSchema.parse(params);
|
|
254
|
+
return ledger.ticket(input.originSessionId, input.jobId);
|
|
255
|
+
}
|
|
256
|
+
case 'ticket_open': {
|
|
257
|
+
const input = openSchema.parse(params);
|
|
258
|
+
const ticket = ledger.changeTicket(input.originSessionId, input.jobId, current => current ? fail('这个任务已经有任务单') : openTicket(input.roleId, input.caseId, input.exportPath));
|
|
259
|
+
writeExport(ticket);
|
|
260
|
+
return ticket;
|
|
261
|
+
}
|
|
262
|
+
case 'ticket_checks': {
|
|
263
|
+
const input = checksSchema.parse(params);
|
|
264
|
+
return change(input.originSessionId, input.jobId, ticket => applyChecks(ticket, input.results));
|
|
265
|
+
}
|
|
266
|
+
case 'ticket_review': {
|
|
267
|
+
const input = reviewSchema.parse(params);
|
|
268
|
+
return change(input.originSessionId, input.jobId, ticket => applyReview(ticket, input.review, input.qaJobId));
|
|
269
|
+
}
|
|
270
|
+
case 'ticket_revise': {
|
|
271
|
+
const input = reviseSchema.parse(params);
|
|
272
|
+
return change(input.originSessionId, input.jobId, ticket => startRevision(ticket, input.note));
|
|
273
|
+
}
|
|
274
|
+
case 'ticket_proposal': {
|
|
275
|
+
const input = proposalSchema.parse(params);
|
|
276
|
+
return change(input.originSessionId, input.jobId, ticket => setProposal(ticket, input.proposalId, input.state, input.note, input.by));
|
|
277
|
+
}
|
|
278
|
+
case 'ticket_close': {
|
|
279
|
+
const input = closeSchema.parse(params);
|
|
280
|
+
return change(input.originSessionId, input.jobId, ticket => closeTicket(ticket, input.status, input.stopReason));
|
|
281
|
+
}
|
|
282
|
+
case 'ticket_reopen': {
|
|
283
|
+
const input = reopenSchema.parse(params);
|
|
284
|
+
return change(input.originSessionId, input.jobId, ticket => reopenTicket(ticket, input.note));
|
|
285
|
+
}
|
|
286
|
+
case 'ticket_show':
|
|
287
|
+
case 'ticket_mark':
|
|
288
|
+
case 'ticket_submit': {
|
|
289
|
+
const mark = method === 'ticket_mark' ? markSchema.parse(params) : undefined, input = mark ?? executorSchema.parse(params);
|
|
290
|
+
const current = input.via === 'cli' ? ledger.currentAttempt(input.jobId) : undefined;
|
|
291
|
+
const attemptId = current?.attemptId ?? input.attemptId, sessionId = current ? current.sessionId : input.sessionId;
|
|
292
|
+
const origin = ledger.executorOrigin(input.jobId, attemptId, sessionId ?? '');
|
|
293
|
+
if (method === 'ticket_show')
|
|
294
|
+
return ledger.ticket(origin, input.jobId);
|
|
295
|
+
const caller = current ? { attemptId, via: 'cli', callerUnverified: true }
|
|
296
|
+
: { attemptId, ...(sessionId !== undefined ? { sessionId } : {}), ...(input.via ? { via: input.via } : {}) };
|
|
297
|
+
return change(origin, input.jobId, ticket => mark ? markItem(ticket, mark.itemId, mark.state, mark.note) : submitTicket(ticket), caller);
|
|
298
|
+
}
|
|
299
|
+
default: throw new Error(`Unknown ticket method: ${method}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface WorkbenchChatItem {
|
|
2
|
+
id: string;
|
|
3
|
+
createdAt: number;
|
|
4
|
+
kind: 'user' | 'assistant_text';
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkbenchChatPage {
|
|
8
|
+
items: WorkbenchChatItem[];
|
|
9
|
+
hasMore: boolean;
|
|
10
|
+
nextCursor?: string;
|
|
11
|
+
total: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One item per message: text parts joined, structured data fenced, file parts as links. Status notices are
|
|
15
|
+
* dropped and repeats collapse; the agent's final answer lives in the task's text artifacts, not its history.
|
|
16
|
+
*/
|
|
17
|
+
export declare function chatItems(tasks: {
|
|
18
|
+
attemptId?: string;
|
|
19
|
+
task: unknown;
|
|
20
|
+
}[]): WorkbenchChatItem[];
|
|
21
|
+
/** `before` is the index the previous page started at; pages walk from the newest toward the oldest. */
|
|
22
|
+
export declare function pageChat(items: WorkbenchChatItem[], query?: {
|
|
23
|
+
limit?: number;
|
|
24
|
+
before?: number;
|
|
25
|
+
}): WorkbenchChatPage;
|