@justsilver/opencode-team 0.2.2-beta.3 → 0.2.2-beta.4

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/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.2-beta.4] - 2026-11-18
11
+
12
+ ### Fixed
13
+
14
+ - 并发保存不同 Agent 的模型覆盖不再互相覆盖:策略保存与旧版迁移的读改写按进程内队列串行执行。
15
+
10
16
  ## [0.2.2-beta.3] - 2026-11-18
11
17
 
12
18
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justsilver/opencode-team",
3
- "version": "0.2.2-beta.3",
3
+ "version": "0.2.2-beta.4",
4
4
  "type": "module",
5
5
  "description": "Zero-config multi-agent team for OpenCode V2: Orchestrator, QA, Reviewer, and per-agent subagent model/variant policy",
6
6
  "license": "MIT",
@@ -35,6 +35,7 @@
35
35
  "build:prompts": "node scripts/build-prompts.mjs gen",
36
36
  "check:prompts": "node scripts/build-prompts.mjs check",
37
37
  "build:tui": "node scripts/build-tui.mjs",
38
+ "bundle:check": "esbuild plugin/opencode-team/index.ts --bundle --platform=node --format=esm --outfile=dist/team-server.js && esbuild plugin/opencode-team/tui.ts --bundle --platform=node --format=esm --jsx=automatic --jsx-import-source=@opentui/solid --external:@opencode/plugin/tui --external:@opentui/core --external:@opentui/solid --external:solid-js --outfile=dist/team-tui.js",
38
39
  "prepack": "node scripts/build-prompts.mjs check && node scripts/build-tui.mjs"
39
40
  },
40
41
  "peerDependencies": {
@@ -56,6 +57,7 @@
56
57
  "@opentui/core": "^0.8.4",
57
58
  "@opentui/solid": "^0.8.4",
58
59
  "babel-preset-solid": "^1.9.16",
60
+ "esbuild": "^0.28.2",
59
61
  "solid-js": "^1.9.17",
60
62
  "typescript": "^5.9.3"
61
63
  }
@@ -158,6 +158,18 @@ async function writePolicy(storage: TeamPolicyContext["storage"], agents: Record
158
158
  }
159
159
  }
160
160
 
161
+ // 宿主 storage 只有 get/set,没有 compare-and-swap;并发保存必须串行,否则后写覆盖先写。
162
+ let pendingPolicyMutation: Promise<unknown> = Promise.resolve()
163
+
164
+ function mutatePolicy<T>(operation: () => Promise<T>): Promise<T> {
165
+ const result = pendingPolicyMutation.then(operation, operation)
166
+ pendingPolicyMutation = result.then(
167
+ () => undefined,
168
+ () => undefined,
169
+ )
170
+ return result
171
+ }
172
+
161
173
  async function readMarker(storage: TeamPolicyContext["storage"]): Promise<MigrationMarker | undefined> {
162
174
  const raw = await storage.get(MIGRATION_KEY)
163
175
  if (raw === undefined) return undefined
@@ -356,32 +368,31 @@ async function runMigration(
356
368
  return { status: "failed", errors: [`The legacy model "${legacyModel}" is invalid.`] }
357
369
  }
358
370
 
359
- let agents: Record<string, string>
360
371
  try {
361
- agents = await readPolicy(ctx.storage)
362
- } catch (error) {
363
- return { status: "failed", errors: [message(error)] }
364
- }
365
-
366
- const imported =
367
- legacyModel === null ? [] : (await listSubagentIDs(ctx, fallbackAgents)).filter((agent) => agents[agent] === undefined)
368
- if (legacyModel !== null) {
369
- for (const agentID of imported) agents[agentID] = legacyModel
370
- }
372
+ return await mutatePolicy(async () => {
373
+ const agents = await readPolicy(ctx.storage)
374
+
375
+ const imported =
376
+ legacyModel === null
377
+ ? []
378
+ : (await listSubagentIDs(ctx, fallbackAgents)).filter((agent) => agents[agent] === undefined)
379
+ if (legacyModel !== null) {
380
+ for (const agentID of imported) agents[agentID] = legacyModel
381
+ }
371
382
 
372
- const marker: MigrationMarker = {
373
- from: "opencode-subagent-model",
374
- status: legacyModel === null ? "empty" : "applied",
375
- model: legacyModel,
376
- agents: imported,
377
- }
378
- try {
379
- if (imported.length > 0) await writePolicy(ctx.storage, agents)
380
- await writeMarker(ctx.storage, marker)
383
+ const marker: MigrationMarker = {
384
+ from: "opencode-subagent-model",
385
+ status: legacyModel === null ? "empty" : "applied",
386
+ model: legacyModel,
387
+ agents: imported,
388
+ }
389
+ if (imported.length > 0) await writePolicy(ctx.storage, agents)
390
+ await writeMarker(ctx.storage, marker)
391
+ return marker
392
+ })
381
393
  } catch (error) {
382
394
  return { status: "failed", errors: [message(error)] }
383
395
  }
384
- return marker
385
396
  }
386
397
 
387
398
  /**
@@ -521,19 +532,16 @@ async function setAgentModel(
521
532
 
522
533
  let agents: Record<string, string>
523
534
  try {
524
- agents = await readPolicy(ctx.storage)
525
- } catch (error) {
526
- return { ok: false, supported: true, agentsSupported, errors: [message(error)] }
527
- }
528
-
529
- if (model === null) {
530
- delete agents[agentID]
531
- } else {
532
- agents[agentID] = formatModelRef(ref!)
533
- }
534
-
535
- try {
536
- await writePolicy(ctx.storage, agents)
535
+ agents = await mutatePolicy(async () => {
536
+ const next = await readPolicy(ctx.storage)
537
+ if (model === null) {
538
+ delete next[agentID]
539
+ } else {
540
+ next[agentID] = formatModelRef(ref!)
541
+ }
542
+ await writePolicy(ctx.storage, next)
543
+ return next
544
+ })
537
545
  } catch (error) {
538
546
  return { ok: false, supported: true, agentsSupported, errors: [message(error)] }
539
547
  }