@fish-under-sea/dsh-agent-teams-fish 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +13 -7
- package/README.en.md +20 -12
- package/README.md +20 -12
- package/compatibility.json +82 -46
- package/icon.png +0 -0
- package/lib/artifacts.js +148 -25
- package/lib/client/ActivityPanel.js +26 -5
- package/lib/client/WorkspaceActivity.js +6 -4
- package/lib/client/activity-monitor.js +113 -41
- package/lib/client/locales.js +14 -0
- package/lib/client.js +433 -199
- package/lib/client.js.map +1 -1
- package/lib/command.js +7 -4
- package/lib/git-artifact-stamp.json +2 -2
- package/lib/harness-compat.js +120 -62
- package/lib/index.js +7 -10
- package/lib/mailbox.js +15 -5
- package/lib/members.js +221 -154
- package/lib/snapshot.js +15 -10
- package/lib/state.js +41 -8
- package/lib/tools.js +123 -64
- package/lib/types/artifacts.d.ts +6 -3
- package/lib/types/client/activity-monitor.d.ts +13 -4
- package/lib/types/client/locales.d.ts +14 -0
- package/lib/types/harness-compat.d.ts +63 -16
- package/lib/types/mailbox.d.ts +2 -0
- package/lib/types/members.d.ts +5 -17
- package/lib/types/snapshot.d.ts +12 -7
- package/lib/types/state.d.ts +10 -3
- package/lib/types/types.d.ts +5 -0
- package/lib/types/web-routes.d.ts +2 -0
- package/lib/types/workspace-audit-service.d.ts +35 -0
- package/lib/types/workspace-audit-worker.d.ts +1 -0
- package/lib/web-routes.js +31 -0
- package/lib/workspace-audit-service.js +165 -0
- package/lib/workspace-audit-worker.js +11 -0
- package/lib/workspace-audit.js +6 -5
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +69 -64
- package/pnpm-workspace.yaml +306 -273
- package/release-notes/v0.1.25.md +16 -0
- package/release-notes/v0.1.26.md +19 -0
- package/release-notes/v0.1.27.md +42 -0
- package/release-notes/v0.1.28.md +45 -0
- package/release-notes/v0.1.29.md +23 -0
- package/release-notes/v1.1.0.md +42 -0
- package/release-notes/v2.0.0.md +17 -0
- package/scripts/artwork-role-match.test.mjs +517 -0
- package/scripts/capabilities.test.mjs +301 -0
- package/scripts/check-install-channel.mjs +55 -0
- package/scripts/check-install-channel.test.mjs +39 -0
- package/scripts/clean-build.mjs +14 -0
- package/scripts/client-harness-migration.test.mjs +46 -0
- package/scripts/compatibility.mjs +20 -0
- package/scripts/compatibility.test.mjs +187 -0
- package/scripts/corrupt-teamjson.test.mjs +180 -0
- package/scripts/custom-artwork.test.mjs +273 -0
- package/scripts/fallback-tdd.mjs +61 -0
- package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
- package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
- package/scripts/fixtures/harness-complex-case.mjs +201 -0
- package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
- package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
- package/scripts/fixtures/harness-issue-case.mjs +51 -0
- package/scripts/fixtures/harness-issue159-case.mjs +28 -0
- package/scripts/fixtures/harness-model-case.mjs +127 -0
- package/scripts/fixtures/harness-model-case.test.mjs +37 -0
- package/scripts/fixtures/harness-model-driver.mjs +100 -0
- package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
- package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
- package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
- package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
- package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
- package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
- package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
- package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
- package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
- package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
- package/scripts/git-artifacts.mjs +64 -0
- package/scripts/git-artifacts.test.mjs +32 -0
- package/scripts/harness-compat-tdd.mjs +492 -0
- package/scripts/harness-issue-verify.mjs +26 -0
- package/scripts/harness-model-benchmark.mjs +163 -0
- package/scripts/harness-runtime-platform.test.mjs +31 -0
- package/scripts/harness-runtime-scenarios.mjs +297 -0
- package/scripts/harness-runtime-verify.mjs +169 -0
- package/scripts/harness-source-verify.mjs +211 -0
- package/scripts/harness-source-verify.test.mjs +97 -0
- package/scripts/harness-validation.mjs +68 -0
- package/scripts/harness-validation.test.mjs +95 -0
- package/scripts/http-body.test.mjs +72 -0
- package/scripts/import-vendor-artwork.mjs +78 -0
- package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
- package/scripts/issue-159.test.mjs +78 -0
- package/scripts/issue-188.test.mjs +148 -0
- package/scripts/issue-189.test.mjs +100 -0
- package/scripts/issue-203-card.test.mjs +181 -0
- package/scripts/issue-205.test.mjs +163 -0
- package/scripts/issue-234.test.mjs +424 -0
- package/scripts/issue-236-stale-module.test.mjs +63 -0
- package/scripts/issue-236.test.mjs +59 -0
- package/scripts/issue-262.test.mjs +98 -0
- package/scripts/issue-336.test.mjs +404 -0
- package/scripts/legacy-session-source-repair.test.mjs +201 -0
- package/scripts/lifecycle-verify.mjs +1573 -0
- package/scripts/lineage-identity.test.mjs +77 -0
- package/scripts/member-failure-tdd.mjs +451 -0
- package/scripts/member-spawn-recovery.test.mjs +92 -0
- package/scripts/quality-gates-amend.test.mjs +161 -0
- package/scripts/quality-gates-content-bound.test.mjs +572 -0
- package/scripts/quality-gates-cross-binding.test.mjs +184 -0
- package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
- package/scripts/quality-gates-repair-scope.test.mjs +143 -0
- package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
- package/scripts/quality-gates-tdd.mjs +1238 -0
- package/scripts/quality-gates-work-order.test.mjs +494 -0
- package/scripts/readme-version.mjs +89 -0
- package/scripts/readme-version.test.mjs +77 -0
- package/scripts/release-metadata.mjs +45 -0
- package/scripts/release-metadata.test.mjs +66 -0
- package/scripts/scoped-release.test.mjs +52 -0
- package/scripts/stability-tdd.mjs +144 -0
- package/scripts/stress-verify.mjs +548 -0
- package/scripts/symlink-support.mjs +46 -0
- package/scripts/sync-skill.mjs +103 -0
- package/scripts/tool-policies.test.mjs +280 -0
- package/scripts/update-skills.mjs +105 -0
- package/scripts/update-skills.test.mjs +79 -0
- package/scripts/upgrade-status.mjs +66 -0
- package/scripts/upgrade-status.test.mjs +83 -0
- package/scripts/verify-package.mjs +73 -0
- package/scripts/verify.mjs +2199 -0
- package/scripts/web-routes-verify.mjs +142 -0
- package/scripts/workspace-activity.test.mjs +346 -0
- package/scripts/workspace-summary.test.mjs +49 -0
- package/src/artifacts.ts +487 -0
- package/src/artwork-source.ts +262 -0
- package/src/capabilities.ts +113 -0
- package/src/client/ActivityPanel.module.css +2390 -0
- package/src/client/ActivityPanel.tsx +1507 -0
- package/src/client/AgentTeamsCard.module.css +148 -0
- package/src/client/AgentTeamsCard.tsx +155 -0
- package/src/client/StagingPlanEditor.tsx +829 -0
- package/src/client/TeamChatEntry.tsx +27 -0
- package/src/client/WorkspaceActivity.module.css +41 -0
- package/src/client/WorkspaceActivity.tsx +137 -0
- package/src/client/activity-model.ts +372 -0
- package/src/client/activity-monitor.ts +440 -0
- package/src/client/agent-teams-card-definition.ts +250 -0
- package/src/client/artwork.ts +374 -0
- package/src/client/icons.tsx +17 -0
- package/src/client/index.tsx +140 -0
- package/src/client/locales.ts +481 -0
- package/src/client/panel-geometry.ts +194 -0
- package/src/client/session-navigation.ts +73 -0
- package/src/client/workspace-state.ts +52 -0
- package/src/command.ts +145 -0
- package/src/css-modules.d.ts +4 -0
- package/src/event-types.ts +177 -0
- package/src/events.ts +78 -0
- package/src/harness-compat.ts +570 -0
- package/src/index.ts +599 -0
- package/src/lineage.ts +248 -0
- package/src/mailbox.ts +185 -0
- package/src/members.ts +1230 -0
- package/src/profiles.ts +765 -0
- package/src/quality-gates.ts +2124 -0
- package/src/scheduler.ts +554 -0
- package/src/snapshot.ts +333 -0
- package/src/state.ts +1317 -0
- package/src/tool-names.ts +14 -0
- package/src/tool-policies.ts +219 -0
- package/src/tools.ts +2939 -0
- package/src/types.ts +414 -0
- package/src/web-routes.ts +128 -0
- package/src/workspace-audit-service.ts +182 -0
- package/src/workspace-audit-worker.ts +12 -0
- package/src/workspace-audit.ts +57 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable AgentTeams state types.
|
|
3
|
+
*
|
|
4
|
+
* A team is one directory under the state root holding `team.json` plus an
|
|
5
|
+
* `inbox/` of per-agent JSONL mailboxes. Members are continuable subagents
|
|
6
|
+
* whose durable child session ids are recorded in the team file, so a team
|
|
7
|
+
* survives harness restarts.
|
|
8
|
+
* @module dsh-agent-teams/types
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { MemberToolFilter } from './tool-policies.ts'
|
|
12
|
+
|
|
13
|
+
/** Task lifecycle statuses in progression order. */
|
|
14
|
+
export type TaskStatus =
|
|
15
|
+
| 'pending'
|
|
16
|
+
| 'claimed'
|
|
17
|
+
| 'in_progress'
|
|
18
|
+
| 'completed'
|
|
19
|
+
| 'failed'
|
|
20
|
+
| 'cancelled'
|
|
21
|
+
|
|
22
|
+
/** Statuses after which a task can no longer be claimed or worked on. */
|
|
23
|
+
export const TERMINAL_TASK_STATUSES: readonly TaskStatus[] = ['completed', 'failed', 'cancelled']
|
|
24
|
+
|
|
25
|
+
/** Structured quality-gate kind. Absent / unknown values are treated as `work`. */
|
|
26
|
+
export type TaskKind =
|
|
27
|
+
| 'requirements'
|
|
28
|
+
| 'implementation'
|
|
29
|
+
| 'verification'
|
|
30
|
+
| 'review'
|
|
31
|
+
| 'repair'
|
|
32
|
+
| 'integration'
|
|
33
|
+
| 'work'
|
|
34
|
+
|
|
35
|
+
export const TASK_KINDS: readonly TaskKind[] = [
|
|
36
|
+
'requirements',
|
|
37
|
+
'implementation',
|
|
38
|
+
'verification',
|
|
39
|
+
'review',
|
|
40
|
+
'repair',
|
|
41
|
+
'integration',
|
|
42
|
+
'work',
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
/** Review / requirements conclusion. Only `pass` may complete those kinds. */
|
|
46
|
+
export type ReviewVerdict = 'pass' | 'needs_revision' | 'reject'
|
|
47
|
+
|
|
48
|
+
export const REVIEW_VERDICTS: readonly ReviewVerdict[] = ['pass', 'needs_revision', 'reject']
|
|
49
|
+
|
|
50
|
+
/** Finding severity used by review / requirements output. */
|
|
51
|
+
export type FindingSeverity = 'low' | 'medium' | 'high' | 'blocker'
|
|
52
|
+
|
|
53
|
+
export const FINDING_SEVERITIES: readonly FindingSeverity[] = ['low', 'medium', 'high', 'blocker']
|
|
54
|
+
|
|
55
|
+
/** One structured review finding. */
|
|
56
|
+
export interface ReviewFinding {
|
|
57
|
+
/** Stable id, for example `SEC-001`. */
|
|
58
|
+
id: string
|
|
59
|
+
severity: FindingSeverity
|
|
60
|
+
file?: string
|
|
61
|
+
line?: number
|
|
62
|
+
problem: string
|
|
63
|
+
requiredFix: string
|
|
64
|
+
resolved?: boolean
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One acceptance criterion result recorded at completion. */
|
|
68
|
+
export interface AcceptanceResult {
|
|
69
|
+
criterion: string
|
|
70
|
+
status: 'passed' | 'failed'
|
|
71
|
+
evidence?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** One verification command result recorded at completion. */
|
|
75
|
+
export interface CommandResult {
|
|
76
|
+
command: string
|
|
77
|
+
status: 'passed' | 'failed'
|
|
78
|
+
exitCode?: number
|
|
79
|
+
evidence?: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Identity of one workspace path at one instant. A verdict is evidence about a
|
|
84
|
+
* revision, so recording the bytes it judged (not only the task id) lets the
|
|
85
|
+
* delivery check refuse to advertise a revision no review ever saw.
|
|
86
|
+
*/
|
|
87
|
+
export interface ArtifactDigest {
|
|
88
|
+
/** Workspace-relative POSIX path. */
|
|
89
|
+
path: string
|
|
90
|
+
/** Whether a regular file existed when the digest was taken. */
|
|
91
|
+
present: boolean
|
|
92
|
+
/** Lowercase hex sha256 of the file bytes; absent unless the file was read. */
|
|
93
|
+
sha256?: string
|
|
94
|
+
/** File size in bytes; absent unless the file was read. */
|
|
95
|
+
size?: number
|
|
96
|
+
/** File mtime in epoch ms; lets a legacy record detect a later edit. */
|
|
97
|
+
mtimeMs?: number
|
|
98
|
+
/**
|
|
99
|
+
* The path exists but could not be read or safely resolved (permissions,
|
|
100
|
+
* symlink escaping the workspace, I/O error). Never conflated with "absent":
|
|
101
|
+
* unreadable bytes cannot be claimed as unchanged.
|
|
102
|
+
*/
|
|
103
|
+
unreadable?: boolean
|
|
104
|
+
/** Why the path could not be read, when `unreadable` is set. */
|
|
105
|
+
reason?: string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A declared scope that could not be fully enumerated (file cap reached,
|
|
110
|
+
* unreadable directory, path that is not workspace-relative). Recorded so a
|
|
111
|
+
* partial artifact list is never mistaken for complete coverage.
|
|
112
|
+
*/
|
|
113
|
+
export interface ArtifactScopeGap {
|
|
114
|
+
/** The pattern or path that could not be fully resolved. */
|
|
115
|
+
pattern: string
|
|
116
|
+
reason: string
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** One set of artifact digests captured at a single instant. */
|
|
120
|
+
export interface ArtifactSnapshot {
|
|
121
|
+
/** Epoch ms when these bytes were read. */
|
|
122
|
+
at: number
|
|
123
|
+
artifacts: ArtifactDigest[]
|
|
124
|
+
/** Present when the recorded coverage is known to be incomplete. */
|
|
125
|
+
gaps?: ArtifactScopeGap[]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Profile / team review-loop limits. */
|
|
129
|
+
export interface ReviewPolicy {
|
|
130
|
+
requirementsMinRounds?: number
|
|
131
|
+
requirementsMaxRounds?: number
|
|
132
|
+
codeMaxRounds?: number
|
|
133
|
+
maxRepairAttempts?: number
|
|
134
|
+
requiredReviewers?: string[]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** One captain-only contract amendment recorded on a quality task. */
|
|
138
|
+
export interface TaskRevision {
|
|
139
|
+
/** Epoch ms when the amendment was applied. */
|
|
140
|
+
at: number
|
|
141
|
+
/** Identity that applied it (`captain`). */
|
|
142
|
+
by: string
|
|
143
|
+
/** Why the previous contract was wrong; kept for the audit trail. */
|
|
144
|
+
reason: string
|
|
145
|
+
/** Amended contract field names (`objective`, `acceptance`, …). */
|
|
146
|
+
fields: string[]
|
|
147
|
+
/** Previous values of the amended fields; fields absent before are omitted. */
|
|
148
|
+
previous: Record<string, unknown>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Append-only observations; never replace the terminal verdict or unlock a gate. */
|
|
152
|
+
export interface TaskEvidence {
|
|
153
|
+
at: number
|
|
154
|
+
by: string
|
|
155
|
+
attempt: number
|
|
156
|
+
attemptId?: string
|
|
157
|
+
note?: string
|
|
158
|
+
acceptanceResults?: AcceptanceResult[]
|
|
159
|
+
commandsRun?: CommandResult[]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One task of a team's task list. */
|
|
163
|
+
export interface TeamTask {
|
|
164
|
+
/** Stable task id from the profile template; absent for ad-hoc tasks. */
|
|
165
|
+
profileSeedId?: string
|
|
166
|
+
/** Stable task id within the team (`t1`, `t2`, …). */
|
|
167
|
+
id: string
|
|
168
|
+
/** Brief title for the task. */
|
|
169
|
+
subject: string
|
|
170
|
+
/** What needs to be done. */
|
|
171
|
+
description?: string
|
|
172
|
+
status: TaskStatus
|
|
173
|
+
/** Member name (or `captain`) the task is assigned to; unassigned tasks await a claim. */
|
|
174
|
+
assignee?: string
|
|
175
|
+
/** Task ids that must reach `completed` before this task can be claimed. */
|
|
176
|
+
dependencies: string[]
|
|
177
|
+
/** The worker's written result, set when the task completes or fails. */
|
|
178
|
+
output?: string
|
|
179
|
+
/** Monotonic execution generation. Reassignment/retry invalidates every older attempt. */
|
|
180
|
+
attempt?: number
|
|
181
|
+
/** Capability for the current claimed/in-progress attempt. Members must present it when updating. */
|
|
182
|
+
attemptId?: string
|
|
183
|
+
/** Opaque generation for a revocation/handoff that has not started its next attempt yet. */
|
|
184
|
+
handoffId?: string
|
|
185
|
+
/** Previous activation retained until a handoff drain succeeds (retryable). */
|
|
186
|
+
handoffFromMemberId?: string
|
|
187
|
+
/** A handoff is quiescing the old owner; the scheduler must not dispatch it yet. */
|
|
188
|
+
reassigning?: boolean
|
|
189
|
+
/** Quality-gate kind. Missing values are treated as `work`. */
|
|
190
|
+
kind?: TaskKind
|
|
191
|
+
/** Review / requirements / repair loop index, 1-based when present. */
|
|
192
|
+
round?: number
|
|
193
|
+
verdict?: ReviewVerdict
|
|
194
|
+
findings?: ReviewFinding[]
|
|
195
|
+
objective?: string
|
|
196
|
+
inScope?: string[]
|
|
197
|
+
outOfScope?: string[]
|
|
198
|
+
acceptance?: string[]
|
|
199
|
+
verify?: string[]
|
|
200
|
+
deliverables?: string[]
|
|
201
|
+
nonGoals?: string[]
|
|
202
|
+
changedPaths?: string[]
|
|
203
|
+
acceptanceResults?: AcceptanceResult[]
|
|
204
|
+
commandsRun?: CommandResult[]
|
|
205
|
+
/** Supplemental observations, attributed to their original execution generation. */
|
|
206
|
+
supplementalEvidence?: TaskEvidence[]
|
|
207
|
+
reviewedTaskId?: string
|
|
208
|
+
/** Execution generation of the reviewed task at the moment of judgment. */
|
|
209
|
+
reviewedAttempt?: number
|
|
210
|
+
/**
|
|
211
|
+
* Bytes this verdict judged, read from the workspace when the gate closed.
|
|
212
|
+
* A later edit, deletion or re-attempt invalidates the verdict.
|
|
213
|
+
*/
|
|
214
|
+
reviewedArtifacts?: ArtifactDigest[]
|
|
215
|
+
/** Scope of that verdict that could not be fully enumerated, if any. */
|
|
216
|
+
reviewedGaps?: ArtifactScopeGap[]
|
|
217
|
+
/**
|
|
218
|
+
* Scope patterns the verdict bound (e.g. `lib/`). A file that appears under
|
|
219
|
+
* one of them later was never reviewed, so the verdict must not claim it.
|
|
220
|
+
*/
|
|
221
|
+
reviewedScope?: string[]
|
|
222
|
+
/**
|
|
223
|
+
* Drift observed while this verdict was being formed (the workspace changed
|
|
224
|
+
* between claim and close). The verdict cannot be read as binding a stable
|
|
225
|
+
* revision.
|
|
226
|
+
*/
|
|
227
|
+
reviewedDuringDrift?: string[]
|
|
228
|
+
/**
|
|
229
|
+
* Workspace snapshot taken when this verdict's attempt started, so a close
|
|
230
|
+
* can tell whether it judged a revision that was changing underneath it.
|
|
231
|
+
*/
|
|
232
|
+
verdictStartSnapshot?: ArtifactSnapshot
|
|
233
|
+
/**
|
|
234
|
+
* Workspace snapshot an auto-generated contract (acceptance / inScope /
|
|
235
|
+
* verify) was derived from. When a cited artifact changes underneath it the
|
|
236
|
+
* work order is marked stale instead of being read as authoritative.
|
|
237
|
+
*/
|
|
238
|
+
contractSnapshot?: ArtifactSnapshot
|
|
239
|
+
/** Repair source: the implementation / previous successful artifact. */
|
|
240
|
+
sourceTaskId?: string
|
|
241
|
+
/**
|
|
242
|
+
* The failed gate task(s) whose findings this repair fixes. Recorded as an
|
|
243
|
+
* explicit causal edge because `dependencies` cannot carry it: a failed task
|
|
244
|
+
* never reaches `completed`, so a dependency on it would make the repair
|
|
245
|
+
* permanently unclaimable. Delivery reads this to tell a closed loop from
|
|
246
|
+
* genuinely unresolved work (issue #175A).
|
|
247
|
+
*/
|
|
248
|
+
findingSourceTaskIds?: string[]
|
|
249
|
+
sourceFindingIds?: string[]
|
|
250
|
+
/** User-constraint / goal items this task claims to cover. */
|
|
251
|
+
coverageOf?: string[]
|
|
252
|
+
/** Captain-only contract amendments, oldest first (see amendTaskContract). */
|
|
253
|
+
revisions?: TaskRevision[]
|
|
254
|
+
createdAt: number
|
|
255
|
+
updatedAt: number
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Member lifecycle status. */
|
|
259
|
+
export type MemberStatus = 'idle' | 'working' | 'removed'
|
|
260
|
+
|
|
261
|
+
/** One team member: a continuable subagent plus its team-side record. */
|
|
262
|
+
export interface TeamMember {
|
|
263
|
+
/** Durable continuable subagent session id (empty until spawned). */
|
|
264
|
+
id: string
|
|
265
|
+
/** Unique display name inside the team. */
|
|
266
|
+
name: string
|
|
267
|
+
/** Role description, e.g. `researcher`, `engineer`, `reviewer`. */
|
|
268
|
+
role?: string
|
|
269
|
+
/** Resolved LLM provider route captured when this member was created. */
|
|
270
|
+
provider?: string
|
|
271
|
+
/** Resolved model captured when this member was created. */
|
|
272
|
+
model?: string
|
|
273
|
+
/** Resolved reasoning effort captured from the captain or target model default. */
|
|
274
|
+
reasoningEffort?: string
|
|
275
|
+
/** Prompt specific to this member's execution turns. */
|
|
276
|
+
executionPrompt?: string
|
|
277
|
+
/** Configured second-choice route. */
|
|
278
|
+
fallback?: TeamModelFallback
|
|
279
|
+
/** Active route after fallback, without changing the primary descriptor route. */
|
|
280
|
+
activeProvider?: string
|
|
281
|
+
activeModel?: string
|
|
282
|
+
/** Whether the fallback route is currently active. */
|
|
283
|
+
fallbackActive?: boolean
|
|
284
|
+
/**
|
|
285
|
+
* Owner-declared tool-policy id this member selected (`#59`), absent for a
|
|
286
|
+
* member without a policy (the unchanged default behavior). The Captain
|
|
287
|
+
* model may only select a configured id; it never submits raw tool lists.
|
|
288
|
+
*/
|
|
289
|
+
toolPolicy?: string
|
|
290
|
+
/**
|
|
291
|
+
* The immutable effective tool filter resolved when the member was created
|
|
292
|
+
* and installed on the child. Every member records it: on a preset-only host
|
|
293
|
+
* (no `persona`/`toolFilter` capability) the continuable descriptor carries
|
|
294
|
+
* neither, so `team.json` is the durable authority a cold resume reinstalls
|
|
295
|
+
* the persona and this filter from.
|
|
296
|
+
*/
|
|
297
|
+
toolFilter?: MemberToolFilter
|
|
298
|
+
/** Exact child-scoped setup restored on hosts with managed activations. */
|
|
299
|
+
runtimeSetup?: { persona: string; toolFilter: MemberToolFilter }
|
|
300
|
+
joinedAt: number
|
|
301
|
+
status: MemberStatus
|
|
302
|
+
/** Execution admission is closed while a failed/pending handoff is drained. */
|
|
303
|
+
stopping?: boolean
|
|
304
|
+
/**
|
|
305
|
+
* Last member-start failure, recorded so the captain can see why a member
|
|
306
|
+
* never acquired a session instead of observing an unexplained `unspawned`
|
|
307
|
+
* member. Cleared by the next successful start.
|
|
308
|
+
*/
|
|
309
|
+
spawnError?: string
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** One mailbox message. */
|
|
313
|
+
export interface TeamMessage {
|
|
314
|
+
id: string
|
|
315
|
+
/** `captain` or a member name. */
|
|
316
|
+
from: string
|
|
317
|
+
/** `captain` or a member name. */
|
|
318
|
+
to: string
|
|
319
|
+
content: string
|
|
320
|
+
ts: number
|
|
321
|
+
/** Process-local delivery lease; prevents fallback and direct delivery racing. */
|
|
322
|
+
deliveryClaimedAt?: number
|
|
323
|
+
/** Set after the durable message was accepted by the recipient's live Harness inbox. */
|
|
324
|
+
deliveredAt?: number
|
|
325
|
+
/** Set once the recipient has consumed or been shown the durable fallback. */
|
|
326
|
+
readAt?: number
|
|
327
|
+
/** Guidance is scoped to the recipient's execution generation, when present. */
|
|
328
|
+
taskId?: string
|
|
329
|
+
attemptId?: string
|
|
330
|
+
/** Source execution generation, independent of the recipient guidance generation. */
|
|
331
|
+
sourceTaskId?: string
|
|
332
|
+
sourceAttemptId?: string
|
|
333
|
+
sourceTaskStatus?: TaskStatus
|
|
334
|
+
/** Cancelled delivery is retained for audit but must not wake the recipient. */
|
|
335
|
+
discardedAt?: number
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Snapshot of the named profile used to seed a team. */
|
|
339
|
+
export interface TeamModelFallback {
|
|
340
|
+
provider: string
|
|
341
|
+
model: string
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface TeamProfileSnapshot {
|
|
345
|
+
name: string
|
|
346
|
+
description?: string
|
|
347
|
+
protocol?: string
|
|
348
|
+
executionPrompt?: string
|
|
349
|
+
fallback?: TeamModelFallback
|
|
350
|
+
/** Frozen planning mode: captain plans the graph; seed keeps template tasks. */
|
|
351
|
+
taskPlanning?: 'captain' | 'seed'
|
|
352
|
+
/** Frozen review-loop policy from the creating profile. */
|
|
353
|
+
reviewPolicy?: ReviewPolicy
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** The full durable team record. */
|
|
357
|
+
export interface TeamState {
|
|
358
|
+
/** Original team name. */
|
|
359
|
+
name: string
|
|
360
|
+
/** Sanitized directory id; the team's stable identity. */
|
|
361
|
+
id: string
|
|
362
|
+
/** Team purpose/goal. */
|
|
363
|
+
description?: string
|
|
364
|
+
/** Immutable named profile snapshot, when created from a profile. */
|
|
365
|
+
profile?: TeamProfileSnapshot
|
|
366
|
+
/** Session id of the captain agent that owns this team. */
|
|
367
|
+
captainSessionId: string
|
|
368
|
+
/**
|
|
369
|
+
* LLM provider route of the captain when this team was created.
|
|
370
|
+
*
|
|
371
|
+
* The captain is the owning session rather than a member, so its route has
|
|
372
|
+
* no other durable home. It is what lets the panel pick the captain's
|
|
373
|
+
* vendor artwork (`team-lead-<vendor>-v2.png`) the same way members pick
|
|
374
|
+
* theirs; without it the captain image is stuck on the packaged DeepSeek
|
|
375
|
+
* whale no matter which model actually leads the team.
|
|
376
|
+
*
|
|
377
|
+
* Optional for durable compatibility: teams created before this field
|
|
378
|
+
* existed simply keep the packaged fallback.
|
|
379
|
+
*/
|
|
380
|
+
captainProvider?: string
|
|
381
|
+
/** Model of the captain when this team was created; see {@link captainProvider}. */
|
|
382
|
+
captainModel?: string
|
|
383
|
+
createdAt: number
|
|
384
|
+
/** Teammates only; the captain is implicit (the owning session). */
|
|
385
|
+
members: TeamMember[]
|
|
386
|
+
tasks: TeamTask[]
|
|
387
|
+
/** Monotonic task id counter. */
|
|
388
|
+
taskSeq: number
|
|
389
|
+
/**
|
|
390
|
+
* Two-phase execution lifecycle. Missing means `running` for durable
|
|
391
|
+
* compatibility with teams created before staging existed.
|
|
392
|
+
*/
|
|
393
|
+
phase?: 'staged' | 'running'
|
|
394
|
+
/**
|
|
395
|
+
* Human-facing review sub-state while `phase` is `staged`. Missing staged
|
|
396
|
+
* records are treated as `awaiting_review` for backward compatibility.
|
|
397
|
+
* `awaiting_feedback` means the user returned to chat and the Captain must
|
|
398
|
+
* ask what should change before editing this same draft.
|
|
399
|
+
*/
|
|
400
|
+
planReviewState?: 'awaiting_review' | 'awaiting_feedback'
|
|
401
|
+
/** Timestamp written only after a staged plan is explicitly approved. */
|
|
402
|
+
approvedAt?: number
|
|
403
|
+
/**
|
|
404
|
+
* Human halt from the captain chat. The team remains on disk, members stay
|
|
405
|
+
* available, and unfinished work is cancelled until the captain resumes.
|
|
406
|
+
*/
|
|
407
|
+
halted?: boolean
|
|
408
|
+
/** Timestamp of the latest human halt, when present. */
|
|
409
|
+
haltedAt?: number
|
|
410
|
+
/** Review-loop policy snapshot copied from the creating profile, when present. */
|
|
411
|
+
reviewPolicy?: ReviewPolicy
|
|
412
|
+
/** Set when an automatic review/repair loop hits its configured ceiling. */
|
|
413
|
+
escalated?: boolean
|
|
414
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
3
|
+
import type { HostConnectionService } from '@deepseek-ai/dsh-client-connection'
|
|
4
|
+
|
|
5
|
+
/** Public WebServer route surface used by the plugin. */
|
|
6
|
+
export interface WebRouteHost {
|
|
7
|
+
register(route: {
|
|
8
|
+
kind: 'exact' | 'prefix'
|
|
9
|
+
path: string
|
|
10
|
+
handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>
|
|
11
|
+
}): () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type BrowserRequestGate = Pick<HostConnectionService, 'requestRejection'>
|
|
15
|
+
|
|
16
|
+
export class RequestBodyError extends Error {
|
|
17
|
+
constructor(message: string, readonly status: 400 | 413) {
|
|
18
|
+
super(message)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Bound memory while draining oversized requests so the route can return 413. */
|
|
23
|
+
export async function readJsonRequest(req: IncomingMessage, maxBytes = 1_000_000): Promise<Record<string, unknown>> {
|
|
24
|
+
const raw = await new Promise<string>((resolve, reject) => {
|
|
25
|
+
let size = 0
|
|
26
|
+
let settled = false
|
|
27
|
+
const chunks: Buffer[] = []
|
|
28
|
+
const finish = (error?: Error): void => {
|
|
29
|
+
if (settled) return
|
|
30
|
+
settled = true
|
|
31
|
+
req.off('data', onData)
|
|
32
|
+
req.off('end', onEnd)
|
|
33
|
+
req.off('aborted', onAborted)
|
|
34
|
+
req.off('error', onError)
|
|
35
|
+
if (error) {
|
|
36
|
+
chunks.length = 0
|
|
37
|
+
// IncomingMessage may still receive data; discard it without buffering.
|
|
38
|
+
req.once('error', () => {})
|
|
39
|
+
req.resume()
|
|
40
|
+
reject(error)
|
|
41
|
+
} else {
|
|
42
|
+
resolve(Buffer.concat(chunks).toString('utf8'))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const onData = (chunk: Buffer | string): void => {
|
|
46
|
+
const part = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
|
|
47
|
+
size += part.length
|
|
48
|
+
if (size > maxBytes) finish(new RequestBodyError('request body is too large', 413))
|
|
49
|
+
else chunks.push(part)
|
|
50
|
+
}
|
|
51
|
+
const onEnd = (): void => finish()
|
|
52
|
+
const onAborted = (): void => finish(new RequestBodyError('request body was aborted', 400))
|
|
53
|
+
const onError = (): void => finish(new RequestBodyError('invalid request body', 400))
|
|
54
|
+
req.on('data', onData)
|
|
55
|
+
req.once('end', onEnd)
|
|
56
|
+
req.once('aborted', onAborted)
|
|
57
|
+
req.once('error', onError)
|
|
58
|
+
})
|
|
59
|
+
let value: unknown
|
|
60
|
+
try {
|
|
61
|
+
value = raw.trim() === '' ? {} : JSON.parse(raw)
|
|
62
|
+
} catch {
|
|
63
|
+
throw new RequestBodyError('invalid JSON', 400)
|
|
64
|
+
}
|
|
65
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
66
|
+
throw new RequestBodyError('body must be an object', 400)
|
|
67
|
+
}
|
|
68
|
+
return value as Record<string, unknown>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function matchesEntityTagList(header: string | undefined, tag: string): boolean {
|
|
72
|
+
if (header === undefined) return false
|
|
73
|
+
if (header.trim() === '*') return true
|
|
74
|
+
// A comma can be part of the quoted opaque tag. Consume whole list entries
|
|
75
|
+
// and compare their quoted values, accepting either weak or strong spelling.
|
|
76
|
+
const entry = /[ \t]*(?:(?:W\/)?("[\x21\x23-\x7e\x80-\xff]*"))?[ \t]*(?:,|$)/y
|
|
77
|
+
let matched = false
|
|
78
|
+
while (entry.lastIndex < header.length) {
|
|
79
|
+
const parsed = entry.exec(header)
|
|
80
|
+
if (parsed === null) return false
|
|
81
|
+
matched ||= parsed[1] === tag
|
|
82
|
+
}
|
|
83
|
+
return matched
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Revalidate a current JSON representation across both identity and gzip delivery. */
|
|
87
|
+
export function writeJsonWithEtag(req: IncomingMessage, res: ServerResponse, body: string): void {
|
|
88
|
+
const tag = `"${createHash('sha256').update(body).digest('base64url')}"`
|
|
89
|
+
const headers = { 'cache-control': 'no-store', etag: `W/${tag}` }
|
|
90
|
+
if ((req.method === 'GET' || req.method === 'HEAD')
|
|
91
|
+
&& matchesEntityTagList(req.headers['if-none-match'], tag)) {
|
|
92
|
+
res.writeHead(304, headers)
|
|
93
|
+
res.end()
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
res.writeHead(200, { ...headers, 'content-type': 'application/json; charset=utf-8' })
|
|
97
|
+
res.end(body)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Raw WebServer routes do not inherit Connection's authentication fence. */
|
|
101
|
+
export function authenticatedWebRoutes(
|
|
102
|
+
server: WebRouteHost,
|
|
103
|
+
connection: () => BrowserRequestGate | undefined,
|
|
104
|
+
): WebRouteHost {
|
|
105
|
+
return {
|
|
106
|
+
register(route) {
|
|
107
|
+
return server.register({
|
|
108
|
+
...route,
|
|
109
|
+
async handler(req, res) {
|
|
110
|
+
const gate = connection()
|
|
111
|
+
// Missing/disposing Connection is an assembly failure, never an
|
|
112
|
+
// invitation to expose workspace state or accept plan mutations.
|
|
113
|
+
const rejection = gate === undefined ? 503 : gate.requestRejection(req)
|
|
114
|
+
if (rejection !== undefined) {
|
|
115
|
+
res.writeHead(rejection, {
|
|
116
|
+
'content-type': 'application/json; charset=utf-8',
|
|
117
|
+
'cache-control': 'no-store',
|
|
118
|
+
})
|
|
119
|
+
res.end(JSON.stringify({ error: rejection === 503 ? 'authentication unavailable'
|
|
120
|
+
: rejection === 401 ? 'unauthorized' : 'forbidden' }))
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
await route.handler(req, res)
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
}
|