@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.
Files changed (179) hide show
  1. package/NOTICE.md +13 -7
  2. package/README.en.md +20 -12
  3. package/README.md +20 -12
  4. package/compatibility.json +82 -46
  5. package/icon.png +0 -0
  6. package/lib/artifacts.js +148 -25
  7. package/lib/client/ActivityPanel.js +26 -5
  8. package/lib/client/WorkspaceActivity.js +6 -4
  9. package/lib/client/activity-monitor.js +113 -41
  10. package/lib/client/locales.js +14 -0
  11. package/lib/client.js +433 -199
  12. package/lib/client.js.map +1 -1
  13. package/lib/command.js +7 -4
  14. package/lib/git-artifact-stamp.json +2 -2
  15. package/lib/harness-compat.js +120 -62
  16. package/lib/index.js +7 -10
  17. package/lib/mailbox.js +15 -5
  18. package/lib/members.js +221 -154
  19. package/lib/snapshot.js +15 -10
  20. package/lib/state.js +41 -8
  21. package/lib/tools.js +123 -64
  22. package/lib/types/artifacts.d.ts +6 -3
  23. package/lib/types/client/activity-monitor.d.ts +13 -4
  24. package/lib/types/client/locales.d.ts +14 -0
  25. package/lib/types/harness-compat.d.ts +63 -16
  26. package/lib/types/mailbox.d.ts +2 -0
  27. package/lib/types/members.d.ts +5 -17
  28. package/lib/types/snapshot.d.ts +12 -7
  29. package/lib/types/state.d.ts +10 -3
  30. package/lib/types/types.d.ts +5 -0
  31. package/lib/types/web-routes.d.ts +2 -0
  32. package/lib/types/workspace-audit-service.d.ts +35 -0
  33. package/lib/types/workspace-audit-worker.d.ts +1 -0
  34. package/lib/web-routes.js +31 -0
  35. package/lib/workspace-audit-service.js +165 -0
  36. package/lib/workspace-audit-worker.js +11 -0
  37. package/lib/workspace-audit.js +6 -5
  38. package/locale/en.json +6 -0
  39. package/locale/zh.json +6 -0
  40. package/package.json +69 -64
  41. package/pnpm-workspace.yaml +306 -273
  42. package/release-notes/v0.1.25.md +16 -0
  43. package/release-notes/v0.1.26.md +19 -0
  44. package/release-notes/v0.1.27.md +42 -0
  45. package/release-notes/v0.1.28.md +45 -0
  46. package/release-notes/v0.1.29.md +23 -0
  47. package/release-notes/v1.1.0.md +42 -0
  48. package/release-notes/v2.0.0.md +17 -0
  49. package/scripts/artwork-role-match.test.mjs +517 -0
  50. package/scripts/capabilities.test.mjs +301 -0
  51. package/scripts/check-install-channel.mjs +55 -0
  52. package/scripts/check-install-channel.test.mjs +39 -0
  53. package/scripts/clean-build.mjs +14 -0
  54. package/scripts/client-harness-migration.test.mjs +46 -0
  55. package/scripts/compatibility.mjs +20 -0
  56. package/scripts/compatibility.test.mjs +187 -0
  57. package/scripts/corrupt-teamjson.test.mjs +180 -0
  58. package/scripts/custom-artwork.test.mjs +273 -0
  59. package/scripts/fallback-tdd.mjs +61 -0
  60. package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
  61. package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
  62. package/scripts/fixtures/harness-complex-case.mjs +201 -0
  63. package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
  64. package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
  65. package/scripts/fixtures/harness-issue-case.mjs +51 -0
  66. package/scripts/fixtures/harness-issue159-case.mjs +28 -0
  67. package/scripts/fixtures/harness-model-case.mjs +127 -0
  68. package/scripts/fixtures/harness-model-case.test.mjs +37 -0
  69. package/scripts/fixtures/harness-model-driver.mjs +100 -0
  70. package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
  71. package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
  72. package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
  73. package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
  74. package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
  75. package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
  76. package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
  77. package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
  78. package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
  79. package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
  80. package/scripts/git-artifacts.mjs +64 -0
  81. package/scripts/git-artifacts.test.mjs +32 -0
  82. package/scripts/harness-compat-tdd.mjs +492 -0
  83. package/scripts/harness-issue-verify.mjs +26 -0
  84. package/scripts/harness-model-benchmark.mjs +163 -0
  85. package/scripts/harness-runtime-platform.test.mjs +31 -0
  86. package/scripts/harness-runtime-scenarios.mjs +297 -0
  87. package/scripts/harness-runtime-verify.mjs +169 -0
  88. package/scripts/harness-source-verify.mjs +211 -0
  89. package/scripts/harness-source-verify.test.mjs +97 -0
  90. package/scripts/harness-validation.mjs +68 -0
  91. package/scripts/harness-validation.test.mjs +95 -0
  92. package/scripts/http-body.test.mjs +72 -0
  93. package/scripts/import-vendor-artwork.mjs +78 -0
  94. package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
  95. package/scripts/issue-159.test.mjs +78 -0
  96. package/scripts/issue-188.test.mjs +148 -0
  97. package/scripts/issue-189.test.mjs +100 -0
  98. package/scripts/issue-203-card.test.mjs +181 -0
  99. package/scripts/issue-205.test.mjs +163 -0
  100. package/scripts/issue-234.test.mjs +424 -0
  101. package/scripts/issue-236-stale-module.test.mjs +63 -0
  102. package/scripts/issue-236.test.mjs +59 -0
  103. package/scripts/issue-262.test.mjs +98 -0
  104. package/scripts/issue-336.test.mjs +404 -0
  105. package/scripts/legacy-session-source-repair.test.mjs +201 -0
  106. package/scripts/lifecycle-verify.mjs +1573 -0
  107. package/scripts/lineage-identity.test.mjs +77 -0
  108. package/scripts/member-failure-tdd.mjs +451 -0
  109. package/scripts/member-spawn-recovery.test.mjs +92 -0
  110. package/scripts/quality-gates-amend.test.mjs +161 -0
  111. package/scripts/quality-gates-content-bound.test.mjs +572 -0
  112. package/scripts/quality-gates-cross-binding.test.mjs +184 -0
  113. package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
  114. package/scripts/quality-gates-repair-scope.test.mjs +143 -0
  115. package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
  116. package/scripts/quality-gates-tdd.mjs +1238 -0
  117. package/scripts/quality-gates-work-order.test.mjs +494 -0
  118. package/scripts/readme-version.mjs +89 -0
  119. package/scripts/readme-version.test.mjs +77 -0
  120. package/scripts/release-metadata.mjs +45 -0
  121. package/scripts/release-metadata.test.mjs +66 -0
  122. package/scripts/scoped-release.test.mjs +52 -0
  123. package/scripts/stability-tdd.mjs +144 -0
  124. package/scripts/stress-verify.mjs +548 -0
  125. package/scripts/symlink-support.mjs +46 -0
  126. package/scripts/sync-skill.mjs +103 -0
  127. package/scripts/tool-policies.test.mjs +280 -0
  128. package/scripts/update-skills.mjs +105 -0
  129. package/scripts/update-skills.test.mjs +79 -0
  130. package/scripts/upgrade-status.mjs +66 -0
  131. package/scripts/upgrade-status.test.mjs +83 -0
  132. package/scripts/verify-package.mjs +73 -0
  133. package/scripts/verify.mjs +2199 -0
  134. package/scripts/web-routes-verify.mjs +142 -0
  135. package/scripts/workspace-activity.test.mjs +346 -0
  136. package/scripts/workspace-summary.test.mjs +49 -0
  137. package/src/artifacts.ts +487 -0
  138. package/src/artwork-source.ts +262 -0
  139. package/src/capabilities.ts +113 -0
  140. package/src/client/ActivityPanel.module.css +2390 -0
  141. package/src/client/ActivityPanel.tsx +1507 -0
  142. package/src/client/AgentTeamsCard.module.css +148 -0
  143. package/src/client/AgentTeamsCard.tsx +155 -0
  144. package/src/client/StagingPlanEditor.tsx +829 -0
  145. package/src/client/TeamChatEntry.tsx +27 -0
  146. package/src/client/WorkspaceActivity.module.css +41 -0
  147. package/src/client/WorkspaceActivity.tsx +137 -0
  148. package/src/client/activity-model.ts +372 -0
  149. package/src/client/activity-monitor.ts +440 -0
  150. package/src/client/agent-teams-card-definition.ts +250 -0
  151. package/src/client/artwork.ts +374 -0
  152. package/src/client/icons.tsx +17 -0
  153. package/src/client/index.tsx +140 -0
  154. package/src/client/locales.ts +481 -0
  155. package/src/client/panel-geometry.ts +194 -0
  156. package/src/client/session-navigation.ts +73 -0
  157. package/src/client/workspace-state.ts +52 -0
  158. package/src/command.ts +145 -0
  159. package/src/css-modules.d.ts +4 -0
  160. package/src/event-types.ts +177 -0
  161. package/src/events.ts +78 -0
  162. package/src/harness-compat.ts +570 -0
  163. package/src/index.ts +599 -0
  164. package/src/lineage.ts +248 -0
  165. package/src/mailbox.ts +185 -0
  166. package/src/members.ts +1230 -0
  167. package/src/profiles.ts +765 -0
  168. package/src/quality-gates.ts +2124 -0
  169. package/src/scheduler.ts +554 -0
  170. package/src/snapshot.ts +333 -0
  171. package/src/state.ts +1317 -0
  172. package/src/tool-names.ts +14 -0
  173. package/src/tool-policies.ts +219 -0
  174. package/src/tools.ts +2939 -0
  175. package/src/types.ts +414 -0
  176. package/src/web-routes.ts +128 -0
  177. package/src/workspace-audit-service.ts +182 -0
  178. package/src/workspace-audit-worker.ts +12 -0
  179. package/src/workspace-audit.ts +57 -0
@@ -0,0 +1,182 @@
1
+ /** Bounded, lifecycle-owned execution of current-byte audits off the host thread. */
2
+ import type { Context } from '@deepseek-ai/cordis'
3
+ import { createHash } from 'node:crypto'
4
+ import { join, resolve } from 'node:path'
5
+ import { Worker } from 'node:worker_threads'
6
+ import { deliveryArtifactPaths, deliveryScopePatterns, type DeliveryAudit } from './quality-gates.ts'
7
+ import { readTeam } from './state.ts'
8
+ import type { TeamState } from './types.ts'
9
+
10
+ interface AuditJob {
11
+ id: number
12
+ key: string
13
+ workspace: string
14
+ stateRoot: string
15
+ team: TeamState
16
+ source: string
17
+ promise: Promise<DeliveryAudit>
18
+ complete: (audit: DeliveryAudit) => void
19
+ }
20
+
21
+ /** Execution limits; callers cannot turn these into a successful partial audit. */
22
+ export interface WorkspaceAuditOptions {
23
+ workerUrl?: URL
24
+ timeoutMs?: number
25
+ maxPending?: number
26
+ }
27
+
28
+ function incomplete(reason: string): DeliveryAudit {
29
+ return { artifacts: [], expandedScope: [], gaps: [{ pattern: '(workspace audit)', reason }] }
30
+ }
31
+
32
+ function isAudit(value: unknown): value is DeliveryAudit {
33
+ if (typeof value !== 'object' || value === null) return false
34
+ const audit = value as DeliveryAudit
35
+ return Array.isArray(audit.artifacts)
36
+ && audit.artifacts.every(item => typeof item?.path === 'string' && typeof item.present === 'boolean'
37
+ && (item.present !== true || (typeof item.sha256 === 'string' && /^[a-f0-9]{64}$/.test(item.sha256))))
38
+ && Array.isArray(audit.expandedScope)
39
+ && audit.expandedScope.every(item => typeof item?.path === 'string' && typeof item.present === 'boolean')
40
+ && (audit.gaps === undefined || (Array.isArray(audit.gaps)
41
+ && audit.gaps.every(gap => typeof gap?.pattern === 'string' && typeof gap.reason === 'string')))
42
+ }
43
+
44
+ /**
45
+ * One lazy, reusable worker per plugin owner. Identical requests may share a
46
+ * queued audit until it is dispatched. Every later request needs a read that
47
+ * starts after it arrives.
48
+ */
49
+ export class WorkspaceAuditService {
50
+ private worker: Worker | undefined
51
+ private active: AuditJob | undefined
52
+ private timer: ReturnType<typeof setTimeout> | undefined
53
+ private idleTimer: ReturnType<typeof setTimeout> | undefined
54
+ private readonly jobs = new Set<AuditJob>()
55
+ private readonly queue: AuditJob[] = []
56
+ private sequence = 0
57
+ private closed = false
58
+
59
+ constructor(private readonly options: WorkspaceAuditOptions = {}) {}
60
+
61
+ audit(workspace: string, team: TeamState, stateRoot = join(workspace, '.agent-teams')): Promise<DeliveryAudit> {
62
+ if (this.closed) return Promise.resolve(incomplete('workspace audit service was disposed; retry after reload'))
63
+ if (deliveryArtifactPaths(team).length === 0 && deliveryScopePatterns(team).length === 0) {
64
+ return Promise.resolve({ artifacts: [], expandedScope: [] })
65
+ }
66
+ const source = JSON.stringify(team)
67
+ const key = `${resolve(workspace)}\0${resolve(stateRoot)}\0${team.id}\0${createHash('sha256').update(source).digest('hex')}`
68
+ const existing = this.queue.find(job => job.key === key)
69
+ if (existing !== undefined) return existing.promise
70
+ if (this.jobs.size >= (this.options.maxPending ?? 16)) {
71
+ return Promise.resolve(incomplete('workspace audit queue is full; retry instead of treating unaudited bytes as verified'))
72
+ }
73
+ let complete!: AuditJob['complete']
74
+ const promise = new Promise<DeliveryAudit>(done => { complete = done })
75
+ const job: AuditJob = { id: ++this.sequence, key, workspace, stateRoot, source, team: JSON.parse(source) as TeamState, promise, complete }
76
+ this.jobs.add(job)
77
+ this.queue.push(job)
78
+ this.pump()
79
+ return promise
80
+ }
81
+
82
+ private pump(): void {
83
+ if (this.closed || this.active !== undefined || this.queue.length === 0) return
84
+ clearTimeout(this.idleTimer)
85
+ this.idleTimer = undefined
86
+ const job = this.queue.shift() as AuditJob
87
+ this.active = job
88
+ try {
89
+ if (this.worker === undefined) {
90
+ const worker = new Worker(this.options.workerUrl ?? new URL('./workspace-audit-worker.js', import.meta.url))
91
+ this.worker = worker
92
+ worker.on('message', (message: unknown) => {
93
+ if (this.worker !== worker) return
94
+ const reply = message as { id?: number; audit?: unknown; error?: unknown } | undefined
95
+ if (reply === null || typeof reply !== 'object' || reply.id !== this.active?.id) {
96
+ this.failWorker('workspace audit worker returned an invalid response')
97
+ return
98
+ }
99
+ const current = this.active as AuditJob
100
+ this.active = undefined
101
+ clearTimeout(this.timer)
102
+ this.timer = undefined
103
+ worker.unref()
104
+ const audit = isAudit(reply.audit)
105
+ ? reply.audit
106
+ : incomplete(typeof reply.error === 'string' ? `workspace audit failed: ${reply.error}` : 'workspace audit worker returned incomplete evidence')
107
+ void this.finish(current, audit)
108
+ this.pump()
109
+ if (this.active === undefined) {
110
+ this.idleTimer = setTimeout(() => {
111
+ if (this.worker === worker && this.active === undefined) {
112
+ this.worker = undefined
113
+ void worker.terminate()
114
+ }
115
+ }, 10_000)
116
+ this.idleTimer.unref()
117
+ }
118
+ })
119
+ worker.on('error', error => { if (this.worker === worker) this.failWorker(`workspace audit worker failed: ${error.message}`) })
120
+ worker.on('exit', code => { if (this.worker === worker) this.failWorker(`workspace audit worker exited (${code}) before completing its evidence`) })
121
+ }
122
+ this.worker.ref()
123
+ this.timer = setTimeout(() => this.failWorker('workspace audit timed out; current bytes could not be verified'), this.options.timeoutMs ?? 120_000)
124
+ this.worker.postMessage({ id: job.id, workspace: job.workspace, team: job.team })
125
+ } catch (error) {
126
+ this.failWorker(`workspace audit could not start: ${String(error)}`)
127
+ }
128
+ }
129
+
130
+ private async finish(job: AuditJob, audit: DeliveryAudit): Promise<void> {
131
+ try {
132
+ // Hashing yields the host thread, so a newer task attempt, edit, archive
133
+ // or replacement team can win while the worker is running. Never apply
134
+ // the old answer to that new record, even when its artifact paths match.
135
+ const current = await readTeam(job.stateRoot, job.team.id)
136
+ if (current === undefined || JSON.stringify(current) !== job.source) {
137
+ audit = { ...audit, gaps: [...audit.gaps ?? [], { pattern: '(team revision)', reason: 'team state changed during the workspace audit; retry the current revision' }] }
138
+ }
139
+ } catch (error) {
140
+ audit = { ...audit, gaps: [...audit.gaps ?? [], { pattern: '(team revision)', reason: `team state could not be revalidated after the workspace audit: ${String(error)}` }] }
141
+ }
142
+ if (!this.jobs.delete(job)) return
143
+ job.complete(this.closed ? incomplete('workspace audit service was disposed before its result could be applied') : audit)
144
+ }
145
+
146
+ private failWorker(reason: string): Promise<number> | undefined {
147
+ const worker = this.worker
148
+ this.worker = undefined
149
+ this.active = undefined
150
+ clearTimeout(this.timer)
151
+ clearTimeout(this.idleTimer)
152
+ this.timer = undefined
153
+ this.idleTimer = undefined
154
+ this.queue.length = 0
155
+ for (const job of this.jobs) job.complete(incomplete(reason))
156
+ this.jobs.clear()
157
+ return worker?.terminate()
158
+ }
159
+
160
+ /** Unload cancels active/queued work; late replies can never restore a pass. */
161
+ async dispose(): Promise<void> {
162
+ this.closed = true
163
+ await this.failWorker('workspace audit was cancelled when its owner unloaded')
164
+ }
165
+ }
166
+
167
+ const owners = new WeakMap<Context, WorkspaceAuditService>()
168
+
169
+ /** Share tools/panel work and release the worker with its Cordis owner. */
170
+ export function workspaceAuditor(ctx: Context): WorkspaceAuditService {
171
+ let service = owners.get(ctx)
172
+ if (service !== undefined) return service
173
+ service = new WorkspaceAuditService()
174
+ owners.set(ctx, service)
175
+ const owned = service
176
+ ctx.effect(() => () => {
177
+ // A reloaded Cordis fiber gets a new Context. Keep this disposed owner's
178
+ // service so a late callback cannot start new work after unload.
179
+ return owned.dispose()
180
+ }, 'agent-teams: workspace audit worker')
181
+ return service
182
+ }
@@ -0,0 +1,12 @@
1
+ /** Built worker entry: no Harness service instances cross the thread boundary. */
2
+ import { parentPort } from 'node:worker_threads'
3
+ import { auditTeamWorkspace } from './workspace-audit.ts'
4
+ import type { TeamState } from './types.ts'
5
+
6
+ parentPort?.on('message', (job: { id: number; workspace: string; team: TeamState }) => {
7
+ try {
8
+ parentPort?.postMessage({ id: job.id, audit: auditTeamWorkspace(job.workspace, job.team) })
9
+ } catch (error) {
10
+ parentPort?.postMessage({ id: job.id, error: String(error) })
11
+ }
12
+ })
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The single workspace audit shared by every surface that reports a delivery
3
+ * or quality-loop conclusion.
4
+ *
5
+ * `agent_teams_status`, the activity-panel route and any Web API consumer must
6
+ * read the same current bytes: if only one of them compared recorded verdicts
7
+ * against the workspace, the other would keep advertising a passing gate over
8
+ * a revision no review ever saw (issue #161).
9
+ *
10
+ * The audit consumes the artifact reader's *complete* result — digests, the
11
+ * enumeration gaps and unreadable paths — because a partial read must never
12
+ * look like a clean one: a scope that outgrew its cap after the review would
13
+ * otherwise be reported as fully verified.
14
+ * @module dsh-agent-teams/workspace-audit
15
+ */
16
+
17
+ import { readArtifactScopes } from './artifacts.ts'
18
+ import { deliveryArtifactPaths, deliveryScopePatterns } from './quality-gates.ts'
19
+ import type { DeliveryAudit } from './quality-gates.ts'
20
+ import type { ArtifactDigest, ArtifactScopeGap, TeamState } from './types.ts'
21
+
22
+ /**
23
+ * Read the current workspace bytes a team's recorded verdicts and generated
24
+ * work orders depend on.
25
+ * @param workspace - absolute path of the owning workspace.
26
+ * @param team - the durable team record.
27
+ * @returns digests of every recorded path, the current contents of the scopes
28
+ * the verdicts bound (so a new file cannot slip into a broad scope), and every
29
+ * gap that makes this audit incomplete.
30
+ */
31
+ export function auditTeamWorkspace(workspace: string, team: TeamState): DeliveryAudit {
32
+ const paths = deliveryArtifactPaths(team)
33
+ const scopePatterns = deliveryScopePatterns(team)
34
+ const [pathRead, scopeRead] = readArtifactScopes(workspace, [paths, scopePatterns]) as [
35
+ { artifacts: ArtifactDigest[]; gaps: ArtifactScopeGap[] },
36
+ { artifacts: ArtifactDigest[]; gaps: ArtifactScopeGap[] },
37
+ ]
38
+ const gaps: ArtifactScopeGap[] = []
39
+ const seen = new Set<string>()
40
+ const recordGap = (pattern: string, reason: string): void => {
41
+ const key = `${pattern}\u0000${reason}`
42
+ if (seen.has(key)) return
43
+ seen.add(key)
44
+ gaps.push({ pattern, reason })
45
+ }
46
+ for (const gap of [...pathRead.gaps, ...scopeRead.gaps]) recordGap(gap.pattern, gap.reason)
47
+ for (const artifact of [...pathRead.artifacts, ...scopeRead.artifacts]) {
48
+ // An unreadable path is not a gap in enumeration but a gap in evidence:
49
+ // report it the same way so no surface treats it as a clean read.
50
+ if (artifact.unreadable === true) recordGap(artifact.path, artifact.reason ?? 'path could not be read')
51
+ }
52
+ return {
53
+ artifacts: pathRead.artifacts,
54
+ expandedScope: scopeRead.artifacts.map((artifact) => ({ path: artifact.path, present: artifact.present })),
55
+ ...gaps.length === 0 ? {} : { gaps },
56
+ }
57
+ }