@linxin666/dsh-client-ui-task-board-team 0.0.0-stage → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +1117 -0
- package/lib/index.js +2968 -0
- package/lib/types/client/index.d.ts +58 -0
- package/lib/types/client/locales.d.ts +83 -0
- package/lib/types/client/optional-service.d.ts +22 -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 +41 -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 +83 -3
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +139 -0
- package/src/client/locales.ts +154 -0
- package/src/client/optional-service.ts +30 -0
- package/src/client/team/extension.ts +185 -0
- package/src/client/team/sections.tsx +159 -0
- package/src/client/team/settings.tsx +242 -0
- package/src/client/team/summary.ts +156 -0
- package/src/client/team/team.module.css +122 -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,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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settlement one finished execution reports to the hub.
|
|
3
|
+
*
|
|
4
|
+
* The board owns the execution verdict and the hub owns the collaboration
|
|
5
|
+
* status, so this module is the whole mapping between them: a passed automated
|
|
6
|
+
* acceptance becomes `succeeded` (the hub moves the issue to `in_review`), and
|
|
7
|
+
* every other outcome — including a cancelled run — becomes `failed`, because a
|
|
8
|
+
* card the Host stopped never earned a human review. The summary is clipped to
|
|
9
|
+
* the character cap the protocol fixes (section 13), which mirrors the board's
|
|
10
|
+
* own execution-summary limit.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-task-board-team/core/settlement
|
|
13
|
+
*/
|
|
14
|
+
import { EXECUTION_SUMMARY_LIMIT } from './hub-protocol.ts'
|
|
15
|
+
import type { ExecutionOutcome, TaskRecord } from './task-record.ts'
|
|
16
|
+
|
|
17
|
+
/** The body one settlement write-back sends. */
|
|
18
|
+
export interface SettleRequestBody {
|
|
19
|
+
outcome: 'succeeded' | 'failed'
|
|
20
|
+
summary: string
|
|
21
|
+
error?: string
|
|
22
|
+
/**
|
|
23
|
+
* The attempt this settlement belongs to.
|
|
24
|
+
*
|
|
25
|
+
* The hub keeps it optional, but a lease that expired while the run was still
|
|
26
|
+
* going is only accepted when the attempt matches: presenting it is what lets a
|
|
27
|
+
* long execution report its own result instead of having it refused as stale.
|
|
28
|
+
*/
|
|
29
|
+
execution_attempt_id?: string
|
|
30
|
+
/**
|
|
31
|
+
* What the Host itself verified, in the shape the frozen settlement sample
|
|
32
|
+
* shows. It is the local evidence a reviewer reads next to the outcome.
|
|
33
|
+
*/
|
|
34
|
+
verification_evidence?: Record<string, unknown>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Map one execution outcome onto the hub's settlement vocabulary.
|
|
39
|
+
* @param outcome - the board's own verdict.
|
|
40
|
+
* @returns `succeeded` only for a passed run.
|
|
41
|
+
*/
|
|
42
|
+
export function settleOutcome(outcome: ExecutionOutcome): 'succeeded' | 'failed' {
|
|
43
|
+
return outcome === 'succeeded' ? 'succeeded' : 'failed'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Clip one summary to the protocol's character cap.
|
|
48
|
+
* @param text - the text to clip.
|
|
49
|
+
* @returns text of at most {@link EXECUTION_SUMMARY_LIMIT} characters.
|
|
50
|
+
*/
|
|
51
|
+
export function clipSummary(text: string): string {
|
|
52
|
+
if (text.length <= EXECUTION_SUMMARY_LIMIT) return text
|
|
53
|
+
return text.slice(0, EXECUTION_SUMMARY_LIMIT - 3) + '...'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Build the settlement body for one settled execution.
|
|
58
|
+
*
|
|
59
|
+
* The summary names the run and what it produced, so a reviewer reading the hub
|
|
60
|
+
* sees which attempt this was without opening the Host: the card title, the
|
|
61
|
+
* attempt id and, on a failure, the recorded reason.
|
|
62
|
+
* @param input - the settlement event and the card it belongs to.
|
|
63
|
+
* @returns the body to post.
|
|
64
|
+
*/
|
|
65
|
+
export function buildSettleRequest(input: {
|
|
66
|
+
task: TaskRecord
|
|
67
|
+
executionId: string
|
|
68
|
+
outcome: ExecutionOutcome
|
|
69
|
+
error?: string
|
|
70
|
+
/** Attempt the card was claimed under, when the payload still records one. */
|
|
71
|
+
attemptId?: string
|
|
72
|
+
}): SettleRequestBody {
|
|
73
|
+
const outcome = settleOutcome(input.outcome)
|
|
74
|
+
const lines = [
|
|
75
|
+
`${input.task.title} — ${outcome === 'succeeded' ? 'automated acceptance passed' : 'automated acceptance did not pass'}`,
|
|
76
|
+
`attempt: ${input.executionId}`,
|
|
77
|
+
]
|
|
78
|
+
if (input.error !== undefined && input.error.trim() !== '') lines.push(`reason: ${input.error.trim()}`)
|
|
79
|
+
const body: SettleRequestBody = { outcome, summary: clipSummary(lines.join('\n')) }
|
|
80
|
+
if (input.error !== undefined && input.error.trim() !== '') body.error = clipSummary(input.error.trim())
|
|
81
|
+
if (input.attemptId !== undefined) body.execution_attempt_id = input.attemptId
|
|
82
|
+
body.verification_evidence = { execution_id: input.executionId, outcome }
|
|
83
|
+
return body
|
|
84
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural view of the task-board vocabulary this extension reads.
|
|
3
|
+
*
|
|
4
|
+
* The extension is a separate bundle and may not import the board's internals,
|
|
5
|
+
* so it restates the record shape the provider contract hands it. These are
|
|
6
|
+
* read-only structural declarations: the board's own values satisfy them and
|
|
7
|
+
* nothing here is constructed by the board.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-task-board-team/core/task-record
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Column a card occupies. */
|
|
13
|
+
export type TaskStatus = 'backlog' | 'todo' | 'running' | 'done' | 'failed'
|
|
14
|
+
|
|
15
|
+
/** Settlement of one execution. */
|
|
16
|
+
export type ExecutionOutcome = 'succeeded' | 'failed' | 'cancelled'
|
|
17
|
+
|
|
18
|
+
/** One execution of a card, as a provider reads it. */
|
|
19
|
+
export interface ExecutionRecord {
|
|
20
|
+
/** Stable execution id. */
|
|
21
|
+
id: string
|
|
22
|
+
/** Session the execution runs in, once one was opened. */
|
|
23
|
+
sessionId?: string | undefined
|
|
24
|
+
/** Instant the execution started (ms epoch). */
|
|
25
|
+
startedAt: number
|
|
26
|
+
/** Instant the execution settled (ms epoch), absent while it runs. */
|
|
27
|
+
endedAt?: number | undefined
|
|
28
|
+
/** Settlement, absent while the execution is still running. */
|
|
29
|
+
result?: ExecutionOutcome | undefined
|
|
30
|
+
/** Human failure text when the run failed. */
|
|
31
|
+
error?: string | undefined
|
|
32
|
+
/** Rework instructions this execution carries, when a run was sent back. */
|
|
33
|
+
rework?: { instructions?: string } | undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One card, as a provider reads it through the capability face. */
|
|
37
|
+
export interface TaskRecord {
|
|
38
|
+
id: string
|
|
39
|
+
title: string
|
|
40
|
+
description: string
|
|
41
|
+
prompt: string
|
|
42
|
+
status: TaskStatus
|
|
43
|
+
createdAt: number
|
|
44
|
+
updatedAt: number
|
|
45
|
+
parentId?: string
|
|
46
|
+
workspaceId?: string
|
|
47
|
+
/** Agent preset the card's execution must be composed from. */
|
|
48
|
+
mode?: string
|
|
49
|
+
hidden?: boolean
|
|
50
|
+
archivedAt?: number
|
|
51
|
+
executions: ExecutionRecord[]
|
|
52
|
+
tags?: ReadonlyArray<{ name: string }>
|
|
53
|
+
/** Opaque provider payloads, keyed by extension id. */
|
|
54
|
+
integrations?: Record<string, unknown>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether one card still occupies a column the board calls unfinished. */
|
|
58
|
+
export function isOpenTask(task: TaskRecord): boolean {
|
|
59
|
+
return task.archivedAt === undefined && task.status !== 'done' && task.status !== 'failed'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Whether one card currently has an execution the board has not settled. */
|
|
63
|
+
export function hasOpenExecution(task: TaskRecord): boolean {
|
|
64
|
+
return task.executions.some(execution => execution.result === undefined)
|
|
65
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timer seat the team sync service schedules through.
|
|
3
|
+
*
|
|
4
|
+
* The extension never reaches for a global timer directly: the Host entry
|
|
5
|
+
* injects the timer face, so heartbeats, lease renewals and reconnect backoff
|
|
6
|
+
* are observable and cancellable under fake timers without patching globals.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-task-board-team/core/timers
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** The timer operations this provider needs, each returning its own canceller. */
|
|
12
|
+
export interface HostTimerFace {
|
|
13
|
+
/** Run `callback` once after `delay` ms. */
|
|
14
|
+
timeout(callback: () => void, delay: number): () => void
|
|
15
|
+
/** Run `callback` every `delay` ms. */
|
|
16
|
+
interval(callback: () => void, delay: number): () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The process timer face: what a real Host mount uses. */
|
|
20
|
+
export const processTimers: HostTimerFace = {
|
|
21
|
+
timeout(callback, delay) {
|
|
22
|
+
const handle = setTimeout(callback, delay)
|
|
23
|
+
handle.unref?.()
|
|
24
|
+
return () => { clearTimeout(handle) }
|
|
25
|
+
},
|
|
26
|
+
interval(callback, delay) {
|
|
27
|
+
const handle = setInterval(callback, delay)
|
|
28
|
+
handle.unref?.()
|
|
29
|
+
return () => { clearInterval(handle) }
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One clock the service reads; injectable so tests can pin time. */
|
|
34
|
+
export type Clock = () => number
|