@linxin666/dsh-client-ui-task-board-team 0.0.0-stage → 0.4.14
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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +66 -2
- package/README.zh.md +67 -0
- package/cordis.patch.yml +14 -0
- package/icon.svg +3 -0
- package/lib/client.js +1490 -0
- package/lib/index.js +2968 -0
- package/lib/types/client/PluginSettingsCard.d.ts +255 -0
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/index.d.ts +58 -0
- package/lib/types/client/locales.d.ts +90 -0
- package/lib/types/client/optional-service.d.ts +22 -0
- package/lib/types/client/settings-form.d.ts +235 -0
- package/lib/types/client/team/extension.d.ts +29 -0
- package/lib/types/client/team/sections.d.ts +38 -0
- package/lib/types/client/team/settings.d.ts +67 -0
- package/lib/types/client/team/summary.d.ts +34 -0
- package/lib/types/core/contract.d.ts +269 -0
- package/lib/types/core/hub-protocol.d.ts +175 -0
- package/lib/types/core/identity.d.ts +96 -0
- package/lib/types/core/mirror.d.ts +51 -0
- package/lib/types/core/question-report.d.ts +84 -0
- package/lib/types/core/settlement.d.ts +49 -0
- package/lib/types/core/task-record.d.ts +59 -0
- package/lib/types/core/timers.d.ts +20 -0
- package/lib/types/host/bindings.d.ts +92 -0
- package/lib/types/host/channel.d.ts +44 -0
- package/lib/types/host/credentials.d.ts +63 -0
- package/lib/types/host/extension.d.ts +57 -0
- package/lib/types/host/hub-client.d.ts +157 -0
- package/lib/types/host/questions.d.ts +105 -0
- package/lib/types/host/service.d.ts +209 -0
- package/lib/types/host/setup.d.ts +152 -0
- package/lib/types/host/tools.d.ts +19 -0
- package/lib/types/host/waterfall.d.ts +39 -0
- package/lib/types/index.d.ts +152 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +84 -3
- package/src/client/PluginSettingsCard.tsx +838 -0
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +139 -0
- package/src/client/locales.ts +168 -0
- package/src/client/optional-service.ts +30 -0
- package/src/client/settings-card.module.css +821 -0
- package/src/client/settings-form.ts +510 -0
- package/src/client/team/extension.ts +185 -0
- package/src/client/team/sections.tsx +159 -0
- package/src/client/team/settings.tsx +348 -0
- package/src/client/team/summary.ts +156 -0
- package/src/client/team/team.module.css +193 -0
- package/src/core/contract.ts +326 -0
- package/src/core/hub-protocol.ts +217 -0
- package/src/core/identity.ts +193 -0
- package/src/core/mirror.ts +88 -0
- package/src/core/question-report.ts +144 -0
- package/src/core/settlement.ts +84 -0
- package/src/core/task-record.ts +65 -0
- package/src/core/timers.ts +34 -0
- package/src/host/bindings.ts +211 -0
- package/src/host/channel.ts +97 -0
- package/src/host/credentials.ts +147 -0
- package/src/host/extension.ts +197 -0
- package/src/host/hub-client.ts +287 -0
- package/src/host/questions.ts +275 -0
- package/src/host/service.ts +1421 -0
- package/src/host/setup.ts +259 -0
- package/src/host/tools.ts +70 -0
- package/src/host/waterfall.ts +51 -0
- package/src/index.ts +452 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire vocabulary of the team-hub protocol v1, as the Host half reads it.
|
|
3
|
+
*
|
|
4
|
+
* The protocol specification (`team-hub/PROTOCOL.md`) is the single source of
|
|
5
|
+
* truth; this module restates only what a Host uses and the operational
|
|
6
|
+
* constants section 13 fixes, so a drift in either direction is visible in one
|
|
7
|
+
* place. Nothing here interprets collaboration semantics: the hub is
|
|
8
|
+
* authoritative over issues, comments, questions and activity, and the Host is
|
|
9
|
+
* authoritative over execution.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-task-board-team/core/hub-protocol
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Protocol version sent on every REST call and on the WebSocket handshake. */
|
|
15
|
+
export const HUB_PROTOCOL_VERSION = '1.0.0'
|
|
16
|
+
|
|
17
|
+
/** Header carrying {@link HUB_PROTOCOL_VERSION}. */
|
|
18
|
+
export const HUB_PROTOCOL_HEADER = 'X-Team-Hub-Protocol-Version'
|
|
19
|
+
|
|
20
|
+
/** Prefix of every REST path this Host speaks. */
|
|
21
|
+
export const HUB_API_PREFIX = '/api/v1'
|
|
22
|
+
|
|
23
|
+
/** Heartbeat cadence the hub expects from an online Host (section 13). */
|
|
24
|
+
export const HEARTBEAT_INTERVAL_MS = 15_000
|
|
25
|
+
|
|
26
|
+
/** Lease lifetime the hub grants on a claim (section 13). */
|
|
27
|
+
export const LEASE_DURATION_MS = 60_000
|
|
28
|
+
|
|
29
|
+
/** Lease renewal cadence while an execution is active (section 13). */
|
|
30
|
+
export const LEASE_RENEW_INTERVAL_MS = 20_000
|
|
31
|
+
|
|
32
|
+
/** Question lifetime before the hub expires it (section 13). */
|
|
33
|
+
export const QUESTION_TTL_MS = 86_400_000
|
|
34
|
+
|
|
35
|
+
/** Execution summary character cap, aligned with the board's own limit. */
|
|
36
|
+
export const EXECUTION_SUMMARY_LIMIT = 4_000
|
|
37
|
+
|
|
38
|
+
/** Comment text byte cap (section 11). */
|
|
39
|
+
export const COMMENT_LIMIT_BYTES = 32_768
|
|
40
|
+
|
|
41
|
+
/** Cadence the claim sweep is coalesced to (protocol amendment A4 point 6). */
|
|
42
|
+
export const SWEEP_INTERVAL_MS = 5_000
|
|
43
|
+
|
|
44
|
+
/** Backoff the reconnect loop starts at after a dropped WebSocket. */
|
|
45
|
+
export const RECONNECT_BASE_MS = 1_000
|
|
46
|
+
|
|
47
|
+
/** Upper bound of the reconnect backoff; a longer outage never waits longer. */
|
|
48
|
+
export const RECONNECT_MAX_MS = 30_000
|
|
49
|
+
|
|
50
|
+
/** Client version this Host reports at registration. */
|
|
51
|
+
export const HOST_CLIENT_VERSION = '0.4.12'
|
|
52
|
+
|
|
53
|
+
/** Collaboration status of one issue, owned by the hub. */
|
|
54
|
+
export type HubIssueStatus =
|
|
55
|
+
| 'todo'
|
|
56
|
+
| 'assigned'
|
|
57
|
+
| 'waiting_host'
|
|
58
|
+
| 'running'
|
|
59
|
+
| 'in_review'
|
|
60
|
+
| 'done'
|
|
61
|
+
| 'canceled'
|
|
62
|
+
| 'failed'
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* One Agent definition this Host registers with the hub.
|
|
66
|
+
*
|
|
67
|
+
* Protocol amendment A4 fixes the registration body as snake_case and requires a
|
|
68
|
+
* non-empty `preset_id`: a member whose definition pins no preset is not
|
|
69
|
+
* reported at all, because the hub would otherwise store an agent this Host can
|
|
70
|
+
* only run under the deployment's default preset.
|
|
71
|
+
*/
|
|
72
|
+
export interface HubAgentDefinition {
|
|
73
|
+
/** Name the hub resolves `@` mentions by. */
|
|
74
|
+
name: string
|
|
75
|
+
/** Agent preset id the member definition pins; never empty. */
|
|
76
|
+
preset_id: string
|
|
77
|
+
/** Pinned model of that member, when it pins one. */
|
|
78
|
+
model?: string
|
|
79
|
+
/** Reasoning effort bound to that model, when the member pins one. */
|
|
80
|
+
reasoning_effort?: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** One Agent record the hub answered registration with. */
|
|
84
|
+
export interface HubAgentRecord {
|
|
85
|
+
id: string
|
|
86
|
+
name: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** One issue, as the hub serves it. */
|
|
90
|
+
export interface HubIssue {
|
|
91
|
+
id: string
|
|
92
|
+
issue_number: number
|
|
93
|
+
title: string
|
|
94
|
+
description: string
|
|
95
|
+
status: HubIssueStatus
|
|
96
|
+
assignee_type?: 'member' | 'agent'
|
|
97
|
+
assignee_member_id?: string
|
|
98
|
+
assignee_agent_id?: string
|
|
99
|
+
reviewer_member_id?: string
|
|
100
|
+
executing_host_id?: string
|
|
101
|
+
lease_expires_at?: number
|
|
102
|
+
/** Attempt the hub currently holds for this issue; null when it holds none. */
|
|
103
|
+
execution_attempt_id?: string | null
|
|
104
|
+
execution_summary?: string
|
|
105
|
+
/**
|
|
106
|
+
* Rework instructions waiting to be applied (protocol amendment A4 point 5).
|
|
107
|
+
*
|
|
108
|
+
* Non-empty instructions on the issue mean "a review sent this back": whichever
|
|
109
|
+
* path claims the card next must apply them to the existing mirror card.
|
|
110
|
+
*/
|
|
111
|
+
rework_instructions?: string | null
|
|
112
|
+
failure_error?: string | null
|
|
113
|
+
updated_at?: number
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** What a successful claim hands back. */
|
|
117
|
+
export interface HubClaim {
|
|
118
|
+
lease_token: string
|
|
119
|
+
lease_expires_at: number
|
|
120
|
+
execution_attempt_id: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** One selectable answer, as the hub exposes it on the wire. */
|
|
124
|
+
export interface HubQuestionOption {
|
|
125
|
+
label: string
|
|
126
|
+
description?: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* One decision question, in the wire shape (protocol amendment A2).
|
|
131
|
+
*
|
|
132
|
+
* The D1 columns `options_json` and `answer_json` are storage forms only: over
|
|
133
|
+
* the wire both are parsed values, so this client never sees a serialized string
|
|
134
|
+
* and never produces one.
|
|
135
|
+
*/
|
|
136
|
+
export interface HubQuestion {
|
|
137
|
+
id: string
|
|
138
|
+
issue_id: string
|
|
139
|
+
/** Question prompt text. */
|
|
140
|
+
text: string
|
|
141
|
+
options: readonly HubQuestionOption[] | null
|
|
142
|
+
multi_select: boolean
|
|
143
|
+
status: 'pending' | 'answered' | 'dismissed' | 'expired'
|
|
144
|
+
answer: HubQuestionAnswer | null
|
|
145
|
+
answered_at: number | null
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** One comment on an issue. */
|
|
149
|
+
export interface HubComment {
|
|
150
|
+
id: string
|
|
151
|
+
issue_id: string
|
|
152
|
+
author_type: 'human' | 'agent'
|
|
153
|
+
author_member_id?: string
|
|
154
|
+
author_agent_id?: string
|
|
155
|
+
content: string
|
|
156
|
+
created_at: number
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* One entry of the hub's append-only activity stream, in the wire shape: the
|
|
161
|
+
* payload is a JSON object here, and `payload_json` exists only inside D1.
|
|
162
|
+
*/
|
|
163
|
+
export interface HubActivity {
|
|
164
|
+
id: string
|
|
165
|
+
issue_id: string
|
|
166
|
+
actor_type: 'member' | 'agent' | 'host' | 'system'
|
|
167
|
+
actor_id: string | null
|
|
168
|
+
activity_type: string
|
|
169
|
+
payload: Record<string, unknown>
|
|
170
|
+
created_at: number
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The answer one human gives to one question (protocol amendment A2). */
|
|
174
|
+
export interface HubQuestionAnswer {
|
|
175
|
+
selected: readonly string[]
|
|
176
|
+
custom?: string
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** One client frame the Host sends on the team channel. */
|
|
180
|
+
export type HubClientFrame =
|
|
181
|
+
| { t: 'ping'; ts: number }
|
|
182
|
+
| { t: 'resume'; since_seq: number }
|
|
183
|
+
|
|
184
|
+
/** One server frame the Host reads from the team channel. */
|
|
185
|
+
export type HubServerFrame =
|
|
186
|
+
| { t: 'pong'; ts: number }
|
|
187
|
+
| { t: 'event'; seq: number; event: string; payload: Record<string, unknown>; ts: number }
|
|
188
|
+
| { t: 'resync_required'; reason: string; latest_seq: number }
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Read one server frame, tolerating anything the hub may add.
|
|
192
|
+
* @param raw - one decoded frame.
|
|
193
|
+
* @returns the frame, or undefined when it carries no recognizable shape.
|
|
194
|
+
*/
|
|
195
|
+
export function readServerFrame(raw: unknown): HubServerFrame | undefined {
|
|
196
|
+
if (typeof raw !== 'object' || raw === null) return undefined
|
|
197
|
+
const frame = raw as Record<string, unknown>
|
|
198
|
+
switch (frame.t) {
|
|
199
|
+
case 'pong':
|
|
200
|
+
return { t: 'pong', ts: typeof frame.ts === 'number' ? frame.ts : 0 }
|
|
201
|
+
case 'event': {
|
|
202
|
+
if (typeof frame.seq !== 'number' || typeof frame.event !== 'string') return undefined
|
|
203
|
+
const payload = typeof frame.payload === 'object' && frame.payload !== null
|
|
204
|
+
? frame.payload as Record<string, unknown>
|
|
205
|
+
: {}
|
|
206
|
+
return { t: 'event', seq: frame.seq, event: frame.event, payload, ts: typeof frame.ts === 'number' ? frame.ts : 0 }
|
|
207
|
+
}
|
|
208
|
+
case 'resync_required':
|
|
209
|
+
return {
|
|
210
|
+
t: 'resync_required',
|
|
211
|
+
reason: typeof frame.reason === 'string' ? frame.reason : '',
|
|
212
|
+
latest_seq: typeof frame.latest_seq === 'number' ? frame.latest_seq : 0,
|
|
213
|
+
}
|
|
214
|
+
default:
|
|
215
|
+
return undefined
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This extension's own payload on a mirror card.
|
|
3
|
+
*
|
|
4
|
+
* The board stores the payload opaquely and never interprets it, so the shape is
|
|
5
|
+
* this provider's private contract with itself: it is what makes claiming,
|
|
6
|
+
* lease renewal, settlement and rework idempotent across a reconnect, because
|
|
7
|
+
* the attempt credentials the hub wants back are exactly what the card already
|
|
8
|
+
* carries. Everything is optional on read: a payload written by an older
|
|
9
|
+
* revision of this extension must degrade instead of throwing.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-task-board-team/core/identity
|
|
12
|
+
*/
|
|
13
|
+
import type { HubIssueStatus } from './hub-protocol.ts'
|
|
14
|
+
import type { TaskBoardExtensionPayload } from './contract.ts'
|
|
15
|
+
import type { SettleRequestBody } from './settlement.ts'
|
|
16
|
+
import type { TaskRecord } from './task-record.ts'
|
|
17
|
+
|
|
18
|
+
/** Extension id: also the key of this provider's integration payload. */
|
|
19
|
+
export const TEAM_EXTENSION_ID = 'task-board-team'
|
|
20
|
+
|
|
21
|
+
/** One mirror card's linkage back to its hub issue. */
|
|
22
|
+
export interface TeamIssueLink {
|
|
23
|
+
/** Hub issue id the card mirrors. */
|
|
24
|
+
issueId: string
|
|
25
|
+
/** Human-facing issue number, when the hub reported one. */
|
|
26
|
+
issueNumber?: number
|
|
27
|
+
/** Execution attempt the hub granted on the last successful claim. */
|
|
28
|
+
attemptId?: string
|
|
29
|
+
/** Lease token that attempt holds; the credential a renew or a re-claim needs. */
|
|
30
|
+
leaseToken?: string
|
|
31
|
+
/** Lease expiry the hub last reported (ms epoch). */
|
|
32
|
+
leaseExpiresAt?: number
|
|
33
|
+
/** Hub agent record this member is bound as. */
|
|
34
|
+
agentId?: string
|
|
35
|
+
/** dsh-agents member id the binding came from. */
|
|
36
|
+
agentMemberId?: string
|
|
37
|
+
/** Agent preset the member definition pins, recorded for the operator. */
|
|
38
|
+
preset?: string
|
|
39
|
+
/** Last collaboration status the hub reported for this issue. */
|
|
40
|
+
hubStatus?: HubIssueStatus
|
|
41
|
+
/** Human assignee display name, when the hub named one. */
|
|
42
|
+
assignee?: string
|
|
43
|
+
/** Human reviewer display name, when the hub named one. */
|
|
44
|
+
reviewer?: string
|
|
45
|
+
/** Last provider-side failure worth keeping on the card. */
|
|
46
|
+
lastError?: string
|
|
47
|
+
/**
|
|
48
|
+
* A settlement the hub has not accepted yet.
|
|
49
|
+
*
|
|
50
|
+
* Recorded before the write-back is sent: a hub that refuses it (a lapsed
|
|
51
|
+
* attempt answers 412) must not lose what the run produced, so the next sweep
|
|
52
|
+
* or reconnect retries this same body and the hub's own gates still decide.
|
|
53
|
+
*/
|
|
54
|
+
pendingSettle?: SettleRequestBody
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function text(value: unknown): string | undefined {
|
|
58
|
+
return typeof value === 'string' && value.trim() !== '' ? value : undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function count(value: unknown): number | undefined {
|
|
62
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Read one linkage out of an opaque payload.
|
|
67
|
+
* @param payload - the stored payload, or undefined.
|
|
68
|
+
* @returns the linkage, or undefined when the payload carries no issue id.
|
|
69
|
+
*/
|
|
70
|
+
export function readTeamIssueLink(payload: TaskBoardExtensionPayload | undefined): TeamIssueLink | undefined {
|
|
71
|
+
if (payload === undefined) return undefined
|
|
72
|
+
const issueId = text(payload.issueId)
|
|
73
|
+
if (issueId === undefined) return undefined
|
|
74
|
+
const link: TeamIssueLink = { issueId }
|
|
75
|
+
const issueNumber = count(payload.issueNumber)
|
|
76
|
+
if (issueNumber !== undefined) link.issueNumber = issueNumber
|
|
77
|
+
const attemptId = text(payload.attemptId)
|
|
78
|
+
if (attemptId !== undefined) link.attemptId = attemptId
|
|
79
|
+
const leaseToken = text(payload.leaseToken)
|
|
80
|
+
if (leaseToken !== undefined) link.leaseToken = leaseToken
|
|
81
|
+
const leaseExpiresAt = count(payload.leaseExpiresAt)
|
|
82
|
+
if (leaseExpiresAt !== undefined) link.leaseExpiresAt = leaseExpiresAt
|
|
83
|
+
const agentId = text(payload.agentId)
|
|
84
|
+
if (agentId !== undefined) link.agentId = agentId
|
|
85
|
+
const agentMemberId = text(payload.agentMemberId)
|
|
86
|
+
if (agentMemberId !== undefined) link.agentMemberId = agentMemberId
|
|
87
|
+
const preset = text(payload.preset)
|
|
88
|
+
if (preset !== undefined) link.preset = preset
|
|
89
|
+
const hubStatus = text(payload.hubStatus) as HubIssueStatus | undefined
|
|
90
|
+
if (hubStatus !== undefined) link.hubStatus = hubStatus
|
|
91
|
+
const assignee = text(payload.assignee)
|
|
92
|
+
if (assignee !== undefined) link.assignee = assignee
|
|
93
|
+
const reviewer = text(payload.reviewer)
|
|
94
|
+
if (reviewer !== undefined) link.reviewer = reviewer
|
|
95
|
+
const lastError = text(payload.lastError)
|
|
96
|
+
if (lastError !== undefined) link.lastError = lastError
|
|
97
|
+
const pendingSettle = readPendingSettle(payload.pendingSettle)
|
|
98
|
+
if (pendingSettle !== undefined) link.pendingSettle = pendingSettle
|
|
99
|
+
return link
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Read one recorded settlement out of an opaque payload.
|
|
104
|
+
* @param value - the stored member, or undefined.
|
|
105
|
+
* @returns the body to retry, or undefined when it carries no usable outcome.
|
|
106
|
+
*/
|
|
107
|
+
function readPendingSettle(value: unknown): SettleRequestBody | undefined {
|
|
108
|
+
if (typeof value !== 'object' || value === null) return undefined
|
|
109
|
+
const row = value as Record<string, unknown>
|
|
110
|
+
const outcome = row.outcome === 'succeeded' || row.outcome === 'failed' ? row.outcome : undefined
|
|
111
|
+
const summary = text(row.summary)
|
|
112
|
+
if (outcome === undefined || summary === undefined) return undefined
|
|
113
|
+
const pending: SettleRequestBody = { outcome, summary }
|
|
114
|
+
const error = text(row.error)
|
|
115
|
+
if (error !== undefined) pending.error = error
|
|
116
|
+
const attemptId = text(row.execution_attempt_id)
|
|
117
|
+
if (attemptId !== undefined) pending.execution_attempt_id = attemptId
|
|
118
|
+
const evidence = row.verification_evidence
|
|
119
|
+
if (typeof evidence === 'object' && evidence !== null && !Array.isArray(evidence)) {
|
|
120
|
+
pending.verification_evidence = evidence as Record<string, unknown>
|
|
121
|
+
}
|
|
122
|
+
return pending
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Read the linkage off one card.
|
|
127
|
+
* @param task - the card to read.
|
|
128
|
+
* @returns its linkage, or undefined when it does not mirror an issue.
|
|
129
|
+
*/
|
|
130
|
+
export function readTaskIssueLink(task: TaskRecord): TeamIssueLink | undefined {
|
|
131
|
+
return readTeamIssueLink(task.integrations?.[TEAM_EXTENSION_ID] as TaskBoardExtensionPayload | undefined)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Project a linkage back onto a payload, dropping undefined members so a merge
|
|
136
|
+
* never stores a key whose value is absent.
|
|
137
|
+
* @param link - the linkage to store.
|
|
138
|
+
* @returns the payload the board keeps under this extension's id.
|
|
139
|
+
*/
|
|
140
|
+
export function toPayload(link: TeamIssueLink): TaskBoardExtensionPayload {
|
|
141
|
+
const payload: TaskBoardExtensionPayload = { issueId: link.issueId }
|
|
142
|
+
if (link.issueNumber !== undefined) payload.issueNumber = link.issueNumber
|
|
143
|
+
if (link.attemptId !== undefined) payload.attemptId = link.attemptId
|
|
144
|
+
if (link.leaseToken !== undefined) payload.leaseToken = link.leaseToken
|
|
145
|
+
if (link.leaseExpiresAt !== undefined) payload.leaseExpiresAt = link.leaseExpiresAt
|
|
146
|
+
if (link.agentId !== undefined) payload.agentId = link.agentId
|
|
147
|
+
if (link.agentMemberId !== undefined) payload.agentMemberId = link.agentMemberId
|
|
148
|
+
if (link.preset !== undefined) payload.preset = link.preset
|
|
149
|
+
if (link.hubStatus !== undefined) payload.hubStatus = link.hubStatus
|
|
150
|
+
if (link.assignee !== undefined) payload.assignee = link.assignee
|
|
151
|
+
if (link.reviewer !== undefined) payload.reviewer = link.reviewer
|
|
152
|
+
if (link.lastError !== undefined) payload.lastError = link.lastError
|
|
153
|
+
if (link.pendingSettle !== undefined) payload.pendingSettle = { ...link.pendingSettle }
|
|
154
|
+
return payload
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Find the card that already mirrors one issue.
|
|
159
|
+
* @param linked - every card this extension linked.
|
|
160
|
+
* @param issueId - the issue to look for.
|
|
161
|
+
* @returns the linked task, or undefined when the issue has no card yet.
|
|
162
|
+
*/
|
|
163
|
+
export function findLinkedTask(
|
|
164
|
+
linked: readonly { task: TaskRecord; payload: TaskBoardExtensionPayload }[],
|
|
165
|
+
issueId: string,
|
|
166
|
+
): TaskRecord | undefined {
|
|
167
|
+
for (const entry of linked) {
|
|
168
|
+
const link = readTeamIssueLink(entry.payload)
|
|
169
|
+
if (link?.issueId === issueId) return entry.task
|
|
170
|
+
}
|
|
171
|
+
return undefined
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Find the card whose execution owns one session.
|
|
176
|
+
*
|
|
177
|
+
* Questions and mentions arrive addressed by SESSION, and the only session a
|
|
178
|
+
* team question may be routed for is one a mirror card opened — that is what
|
|
179
|
+
* keeps this provider out of every other conversation on the machine.
|
|
180
|
+
* @param linked - every card this extension linked.
|
|
181
|
+
* @param sessionId - the session that asked, or that will receive the message.
|
|
182
|
+
* @returns the linked task, or undefined when this session is not a team card's.
|
|
183
|
+
*/
|
|
184
|
+
export function findTaskBySession(
|
|
185
|
+
linked: readonly { task: TaskRecord; payload: TaskBoardExtensionPayload }[],
|
|
186
|
+
sessionId: string,
|
|
187
|
+
): TaskRecord | undefined {
|
|
188
|
+
for (const entry of linked) {
|
|
189
|
+
if (readTeamIssueLink(entry.payload) === undefined) continue
|
|
190
|
+
if (entry.task.executions.some(execution => execution.sessionId === sessionId)) return entry.task
|
|
191
|
+
}
|
|
192
|
+
return undefined
|
|
193
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The card one hub issue becomes on this Host.
|
|
3
|
+
*
|
|
4
|
+
* Mirroring is deliberately one-way in shape: the card carries the issue's
|
|
5
|
+
* title and body so an operator can read and run it locally, while every
|
|
6
|
+
* collaboration field (assignee, reviewer, status, comments, activity) stays on
|
|
7
|
+
* the hub and reaches the browser through the published summary. Nothing the
|
|
8
|
+
* hub serves is ever interpreted as an execution target — remote text never
|
|
9
|
+
* becomes a permission, a workspace or a preset.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-task-board-team/core/mirror
|
|
12
|
+
*/
|
|
13
|
+
import type { HubIssue } from './hub-protocol.ts'
|
|
14
|
+
|
|
15
|
+
/** Longest title a mirrored card carries, matching the hub's own issue cap. */
|
|
16
|
+
export const MIRROR_TITLE_LIMIT = 256
|
|
17
|
+
|
|
18
|
+
/** Longest issue body carried into a card description. */
|
|
19
|
+
export const MIRROR_DESCRIPTION_LIMIT = 32_000
|
|
20
|
+
|
|
21
|
+
/** The member one issue was claimed for, as the mirror needs it. */
|
|
22
|
+
export interface MirrorAgent {
|
|
23
|
+
/** Hub agent record id. */
|
|
24
|
+
agentId: string
|
|
25
|
+
/** dsh-agents member id. */
|
|
26
|
+
memberId: string
|
|
27
|
+
/** Member name the hub resolves mentions by. */
|
|
28
|
+
name: string
|
|
29
|
+
/** Agent preset the member definition pins. */
|
|
30
|
+
preset?: string
|
|
31
|
+
/** Model the member definition pins, when it pins one. */
|
|
32
|
+
model?: string
|
|
33
|
+
/** Reasoning effort the member definition pins for that model. */
|
|
34
|
+
reasoningEffort?: string
|
|
35
|
+
/** Workspace the card runs in, as the caller resolved it for this member. */
|
|
36
|
+
workspaceId?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The draft a mirror card is created from. */
|
|
40
|
+
export interface MirrorDraft {
|
|
41
|
+
title: string
|
|
42
|
+
description: string
|
|
43
|
+
prompt: string
|
|
44
|
+
workspaceId?: string
|
|
45
|
+
mode?: string
|
|
46
|
+
model?: string
|
|
47
|
+
reasoningEffort?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function clip(text: string, limit: number): string {
|
|
51
|
+
const trimmed = text.trim()
|
|
52
|
+
return trimmed.length <= limit ? trimmed : trimmed.slice(0, limit)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build the card a claimed issue becomes.
|
|
57
|
+
* @param issue - the claimed issue.
|
|
58
|
+
* @param agent - the member it was claimed for.
|
|
59
|
+
* @returns the draft the board creates the card from.
|
|
60
|
+
*/
|
|
61
|
+
export function buildMirrorDraft(issue: HubIssue, agent: MirrorAgent): MirrorDraft {
|
|
62
|
+
const title = clip(`#${String(issue.issue_number)} ${issue.title}`, MIRROR_TITLE_LIMIT)
|
|
63
|
+
const body = clip(issue.description, MIRROR_DESCRIPTION_LIMIT)
|
|
64
|
+
const lines = [
|
|
65
|
+
`Team issue ${issue.id} (issue #${String(issue.issue_number)}) claimed for agent ${agent.name}.`,
|
|
66
|
+
'',
|
|
67
|
+
issue.title.trim(),
|
|
68
|
+
]
|
|
69
|
+
if (body !== '') lines.push('', body)
|
|
70
|
+
lines.push(
|
|
71
|
+
'',
|
|
72
|
+
'Work on this task in this workspace. Report progress and ask for decisions with the team_comment tool;',
|
|
73
|
+
'a question asked through ask_user_question is routed to the team and answered by its reviewer.',
|
|
74
|
+
'Answering a rework request in the same session keeps the review thread on the hub intact.',
|
|
75
|
+
)
|
|
76
|
+
return {
|
|
77
|
+
title,
|
|
78
|
+
description: body === '' ? `Team issue #${String(issue.issue_number)} mirror card.` : body,
|
|
79
|
+
prompt: lines.join('\n'),
|
|
80
|
+
// The member's own execution targets travel with the draft: the run has to be
|
|
81
|
+
// the member's preset, model and effort, never the deployment's defaults, and
|
|
82
|
+
// in the workspace the caller resolved rather than one the board picks.
|
|
83
|
+
...(agent.workspaceId === undefined ? {} : { workspaceId: agent.workspaceId }),
|
|
84
|
+
...(agent.preset === undefined ? {} : { mode: agent.preset }),
|
|
85
|
+
...(agent.model === undefined ? {} : { model: agent.model }),
|
|
86
|
+
...(agent.reasoningEffort === undefined ? {} : { reasoningEffort: agent.reasoningEffort }),
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one hub question an `ask_user_question` request becomes.
|
|
3
|
+
*
|
|
4
|
+
* The Host's question event carries a batch, and the hub's schema stores a
|
|
5
|
+
* single question with options and a multi-select flag. The bridge between them
|
|
6
|
+
* is explicit: the FIRST question is the one the team is asked, the rest stay on
|
|
7
|
+
* the machine, and an answer that names the reported question is mapped back
|
|
8
|
+
* onto it. That keeps the mapping total in both directions instead of guessing
|
|
9
|
+
* which of several questions a free-text team answer meant.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-task-board-team/core/question-report
|
|
12
|
+
*/
|
|
13
|
+
import { QUESTION_TTL_MS } from './hub-protocol.ts'
|
|
14
|
+
|
|
15
|
+
/** One selectable answer offered by the asker. */
|
|
16
|
+
export interface QuestionOption {
|
|
17
|
+
readonly label: string
|
|
18
|
+
readonly description?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** One question, in the shape the Host's question event publishes. */
|
|
22
|
+
export interface QuestionItem {
|
|
23
|
+
readonly id: string
|
|
24
|
+
readonly question: string
|
|
25
|
+
readonly header?: string
|
|
26
|
+
readonly detail?: string
|
|
27
|
+
readonly options?: readonly QuestionOption[]
|
|
28
|
+
readonly multiSelect?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The fields of a Host question request this provider reads. */
|
|
32
|
+
export interface QuestionRequestShape {
|
|
33
|
+
readonly questions: readonly QuestionItem[]
|
|
34
|
+
/** The agent asking; its id IS the session id (the event carries no session field). */
|
|
35
|
+
readonly agent?: { readonly id: string }
|
|
36
|
+
readonly signal?: AbortSignal
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One item of the answer batch the Host settles its ask with. */
|
|
40
|
+
export interface QuestionAnswerItem {
|
|
41
|
+
readonly id: string
|
|
42
|
+
readonly selected: readonly string[]
|
|
43
|
+
readonly custom?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The whole answer batch the Host's ask is settled with. */
|
|
47
|
+
export interface QuestionAnswer {
|
|
48
|
+
readonly answers: readonly QuestionAnswerItem[]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The body one question report sends to the hub. */
|
|
52
|
+
export interface QuestionReportBody {
|
|
53
|
+
question_text: string
|
|
54
|
+
/** Selectable answers, in the wire shape the hub stores and serves. */
|
|
55
|
+
options?: readonly QuestionOption[]
|
|
56
|
+
multi_select?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Build the hub question one Host question request reports.
|
|
61
|
+
* @param item - the first question of the batch.
|
|
62
|
+
* @returns the report body.
|
|
63
|
+
*/
|
|
64
|
+
export function buildQuestionReport(item: QuestionItem): QuestionReportBody {
|
|
65
|
+
const text = item.header === undefined || item.header.trim() === ''
|
|
66
|
+
? item.question
|
|
67
|
+
: `${item.header.trim()}: ${item.question}`
|
|
68
|
+
// The asker's own options travel as objects, label and description included:
|
|
69
|
+
// a description is what tells a reviewer which choice is which.
|
|
70
|
+
const options = (item.options ?? [])
|
|
71
|
+
.filter(option => option.label.trim() !== '')
|
|
72
|
+
.map(option => ({
|
|
73
|
+
label: option.label,
|
|
74
|
+
...(option.description === undefined || option.description.trim() === '' ? {} : { description: option.description }),
|
|
75
|
+
}))
|
|
76
|
+
return {
|
|
77
|
+
question_text: text,
|
|
78
|
+
...(options.length === 0 ? {} : { options }),
|
|
79
|
+
...(item.multiSelect === true ? { multi_select: true } : {}),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Map one team answer back onto the question the Host asked.
|
|
85
|
+
* @param item - the reported question item (whose id the answer addresses).
|
|
86
|
+
* @param answer - the hub's answer payload: the selected labels and optional custom text.
|
|
87
|
+
* @returns the answer batch the Host settles its ask with.
|
|
88
|
+
*/
|
|
89
|
+
export function answerToHost(
|
|
90
|
+
item: QuestionItem,
|
|
91
|
+
answer: { selected: readonly string[]; custom?: string },
|
|
92
|
+
): QuestionAnswer {
|
|
93
|
+
const selected = [...answer.selected]
|
|
94
|
+
const custom = answer.custom !== undefined && answer.custom.trim() !== '' ? answer.custom : undefined
|
|
95
|
+
return {
|
|
96
|
+
answers: [{
|
|
97
|
+
id: item.id,
|
|
98
|
+
selected,
|
|
99
|
+
...(custom === undefined ? {} : { custom }),
|
|
100
|
+
}],
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The answer batch that ends a question nobody answered.
|
|
106
|
+
*
|
|
107
|
+
* The protocol resolves an expired question as unanswered so the agent can
|
|
108
|
+
* proceed on its own assumptions or pause; the Host's answer vocabulary has no
|
|
109
|
+
* "expired" outcome, so the ask settles with an empty batch — a defined answer
|
|
110
|
+
* that selected nothing — instead of a fabricated choice a human never made.
|
|
111
|
+
* @returns the empty answer batch.
|
|
112
|
+
*/
|
|
113
|
+
export function unansweredAnswer(): QuestionAnswer {
|
|
114
|
+
return { answers: [] }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Longest question text one report may carry, derived from the hub's own TTL budget. */
|
|
118
|
+
export const QUESTION_REPORT_MAX_LENGTH = 4_000
|
|
119
|
+
|
|
120
|
+
/** Whether a question request still fits the hub's question schema. */
|
|
121
|
+
export function isReportable(item: QuestionItem): boolean {
|
|
122
|
+
return item.question.trim() !== '' && item.question.length <= QUESTION_REPORT_MAX_LENGTH
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Deadline one pending question expires at, measured from the moment it was asked. */
|
|
126
|
+
export function questionExpiry(askedAt: number): number {
|
|
127
|
+
return askedAt + QUESTION_TTL_MS
|
|
128
|
+
}
|
|
129
|
+
declare module '@deepseek-ai/cordis' {
|
|
130
|
+
interface Events {
|
|
131
|
+
/**
|
|
132
|
+
* Ask composed answerers one decision question. Returning an answer claims the
|
|
133
|
+
* request; calling \`next()\` delegates to the rest of the chain.
|
|
134
|
+
* @param request - the pending question batch.
|
|
135
|
+
* @param next - the rest of the answerer chain.
|
|
136
|
+
* @mode waterfall
|
|
137
|
+
*/
|
|
138
|
+
'user-questions/request'(
|
|
139
|
+
this: unknown,
|
|
140
|
+
request: QuestionRequestShape,
|
|
141
|
+
next: () => Promise<QuestionAnswer>,
|
|
142
|
+
): Promise<QuestionAnswer>
|
|
143
|
+
}
|
|
144
|
+
}
|