@bonesofspring/ai-rules 0.2.90 → 0.2.92

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 (111) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/docs/OPENCODE-COMPATIBILITY.md +2 -1
  3. package/docs/OPENCODE.md +20 -2
  4. package/docs/TEAM-DB.md +2 -0
  5. package/package.json +1 -1
  6. package/presets/_shared/ai-local/scripts/team-db-api.mjs +33 -15
  7. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +15 -0
  8. package/presets/_shared/ai-local/scripts/team-db-project.mjs +41 -2
  9. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +23 -0
  10. package/presets/_shared/core/agent-team/agent-task-metrics.md +16 -1
  11. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +87 -6
  12. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +87 -6
  13. package/presets/claude/go/hooks/chain-team-phases.sh +87 -6
  14. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +87 -6
  15. package/presets/claude/java/hooks/chain-team-phases.sh +87 -6
  16. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +87 -6
  17. package/presets/claude/mol/hooks/chain-team-phases.sh +87 -6
  18. package/presets/claude/next/hooks/chain-team-phases.sh +87 -6
  19. package/presets/claude/nuxt/hooks/chain-team-phases.sh +87 -6
  20. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +87 -6
  21. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +87 -6
  22. package/presets/claude/svelte/hooks/chain-team-phases.sh +87 -6
  23. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +87 -6
  24. package/presets/cursor/go/hooks/chain-team-phases.sh +87 -6
  25. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +87 -6
  26. package/presets/cursor/java/hooks/chain-team-phases.sh +87 -6
  27. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +87 -6
  28. package/presets/cursor/mol/hooks/chain-team-phases.sh +87 -6
  29. package/presets/cursor/next/hooks/chain-team-phases.sh +87 -6
  30. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +87 -6
  31. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +87 -6
  32. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +87 -6
  33. package/presets/cursor/svelte/hooks/chain-team-phases.sh +87 -6
  34. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  35. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +87 -6
  36. package/presets/mavis/go/adapter-map.json +1 -1
  37. package/presets/mavis/go/hooks/chain-team-phases.sh +87 -6
  38. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  39. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +87 -6
  40. package/presets/mavis/java/adapter-map.json +1 -1
  41. package/presets/mavis/java/hooks/chain-team-phases.sh +87 -6
  42. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  43. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +87 -6
  44. package/presets/mavis/mol/adapter-map.json +1 -1
  45. package/presets/mavis/mol/hooks/chain-team-phases.sh +87 -6
  46. package/presets/mavis/next/adapter-map.json +1 -1
  47. package/presets/mavis/next/hooks/chain-team-phases.sh +87 -6
  48. package/presets/mavis/nuxt/adapter-map.json +1 -1
  49. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +87 -6
  50. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  51. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +87 -6
  52. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  53. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +87 -6
  54. package/presets/mavis/svelte/adapter-map.json +1 -1
  55. package/presets/mavis/svelte/hooks/chain-team-phases.sh +87 -6
  56. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  57. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +87 -6
  58. package/presets/opencode/go/adapter-map.json +1 -1
  59. package/presets/opencode/go/hooks/chain-team-phases.sh +87 -6
  60. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  61. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +87 -6
  62. package/presets/opencode/java/adapter-map.json +1 -1
  63. package/presets/opencode/java/hooks/chain-team-phases.sh +87 -6
  64. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  65. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +87 -6
  66. package/presets/opencode/mol/adapter-map.json +1 -1
  67. package/presets/opencode/mol/hooks/chain-team-phases.sh +87 -6
  68. package/presets/opencode/next/adapter-map.json +1 -1
  69. package/presets/opencode/next/hooks/chain-team-phases.sh +87 -6
  70. package/presets/opencode/nuxt/adapter-map.json +1 -1
  71. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +87 -6
  72. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  73. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +87 -6
  74. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  75. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +87 -6
  76. package/presets/opencode/plugins/output-guard/README.md +4 -3
  77. package/presets/opencode/plugins/output-guard/index.ts +4 -3
  78. package/presets/opencode/plugins/output-guard/rewrite.ts +1 -2
  79. package/presets/opencode/plugins/rule-attach/README.md +1 -1
  80. package/presets/opencode/plugins/rule-attach/index.ts +23 -4
  81. package/presets/opencode/plugins/settings-guard/README.md +3 -0
  82. package/presets/opencode/plugins/settings-guard/index.ts +1 -1
  83. package/presets/opencode/plugins/settings-guard/policy.mjs +1 -1
  84. package/presets/opencode/plugins/task-status/README.md +4 -4
  85. package/presets/opencode/plugins/task-status/deepseek.ts +27 -8
  86. package/presets/opencode/plugins/task-status/task-view.ts +8 -4
  87. package/presets/opencode/plugins/task-status/tui.tsx +12 -3
  88. package/presets/opencode/svelte/adapter-map.json +1 -1
  89. package/presets/opencode/svelte/hooks/chain-team-phases.sh +87 -6
  90. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  91. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +87 -6
  92. package/presets/zcode/go/adapter-map.json +1 -1
  93. package/presets/zcode/go/hooks/chain-team-phases.sh +87 -6
  94. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  95. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +87 -6
  96. package/presets/zcode/java/adapter-map.json +1 -1
  97. package/presets/zcode/java/hooks/chain-team-phases.sh +87 -6
  98. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  99. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +87 -6
  100. package/presets/zcode/mol/adapter-map.json +1 -1
  101. package/presets/zcode/mol/hooks/chain-team-phases.sh +87 -6
  102. package/presets/zcode/next/adapter-map.json +1 -1
  103. package/presets/zcode/next/hooks/chain-team-phases.sh +87 -6
  104. package/presets/zcode/nuxt/adapter-map.json +1 -1
  105. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +87 -6
  106. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  107. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +87 -6
  108. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  109. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +87 -6
  110. package/presets/zcode/svelte/adapter-map.json +1 -1
  111. package/presets/zcode/svelte/hooks/chain-team-phases.sh +87 -6
@@ -86,7 +86,20 @@ function writeSessionLease(id, value) {
86
86
  const temporary = `${file}.${process.pid}.tmp`;
87
87
  const now = new Date().toISOString();
88
88
  const firstSeenAt = firstSeenAtOf(file, value, now);
89
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
89
+ let model = null;
90
+ try {
91
+ if (Date.now() - fs.statSync(file).mtimeMs <= LEASE_TTL_MS) {
92
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
93
+ const previousTool = previous && typeof previous.tool === 'string' ? previous.tool : '';
94
+ const keepModel = previous && previous.slug === value && (previousTool === '' || previousTool === PLATFORM);
95
+ if (keepModel && typeof previous.model === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(previous.model)) {
96
+ model = previous.model;
97
+ }
98
+ }
99
+ } catch {}
100
+ const body = { slug: value, sessionId: id, firstSeenAt, updatedAt: now, tool: PLATFORM };
101
+ if (model) body.model = model;
102
+ fs.writeFileSync(temporary, `${JSON.stringify(body)}\n`);
90
103
  fs.renameSync(temporary, file);
91
104
  for (const name of fs.readdirSync(LEASE_ROOT)) {
92
105
  if (!name.endsWith('.json')) continue;
@@ -177,8 +190,6 @@ if (slugSource === 'active-task.json') {
177
190
  if (slugSource !== 'TEAM_TASK_SLUG') {
178
191
  process.stderr.write(`WARNING: ${slug}: chain hook resolved the slug from ${slugSource}; pass TEAM_TASK_SLUG=<slug> on every hook call so parallel sessions cannot no-op each other.\n`);
179
192
  }
180
- if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
181
-
182
193
  const taskDir = path.join(TEAM_ROOT, 'tasks', slug);
183
194
  const statusPath = path.join(taskDir, 'status.json');
184
195
  const pipelinePath = path.join(taskDir, 'pipeline.json');
@@ -197,6 +208,7 @@ let status;
197
208
  const now = new Date().toISOString();
198
209
  const STACK = 'next';
199
210
  const PLATFORM = 'opencode';
211
+ if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
200
212
 
201
213
  let metricsLockToken = null;
202
214
  function readMetricsLockToken() {
@@ -495,6 +507,7 @@ function reclaimStaleAttempts(scope) {
495
507
  type: 'attempt_finished',
496
508
  at: now,
497
509
  attemptId,
510
+ ...closingExecution(entry, Array.isArray(steps) ? steps[entry.stepIndex] : null),
498
511
  stepIndex: entry.stepIndex,
499
512
  stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
500
513
  agent: entry.agent,
@@ -561,6 +574,59 @@ function saveWriteScopeBaseline(step) {
561
574
  .split('\n').map((line) => line.trim()).filter(Boolean)[0] || `exit ${result ? result.status : 'unknown'}`;
562
575
  process.stderr.write(`[chain-team-phases] ${slug}: write-scope baseline for step ${stepId} not saved (${reason}); the audit will skip that step.\n`);
563
576
  }
577
+ const MODEL_TIERS = new Set(['cheap', 'standard', 'strong']);
578
+ const MODEL_SOURCES = new Set(['host', 'lease', 'tier-map', 'session']);
579
+ function boundedModel(value) {
580
+ if (typeof value !== 'string') return null;
581
+ const text = value.trim();
582
+ return /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(text) ? text : null;
583
+ }
584
+ function readTierMapModel(tier) {
585
+ try {
586
+ const parsed = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'model-tiers.json'), 'utf8'));
587
+ const tiers = parsed && parsed.tiers;
588
+ if (!tiers || typeof tiers !== 'object') return null;
589
+ const approvedBy = typeof parsed.approvedBy === 'string' ? parsed.approvedBy.trim() : '';
590
+ const filled = ['cheap', 'standard', 'strong'].some((key) => typeof tiers[key] === 'string' && tiers[key].trim() !== '');
591
+ if (approvedBy === '' && !filled) return null;
592
+ return boundedModel(tiers[tier]);
593
+ } catch {
594
+ return null;
595
+ }
596
+ }
597
+ function observedModel() {
598
+ const execution = hookInput && hookInput.execution;
599
+ if (execution && typeof execution === 'object') {
600
+ const model = boundedModel(execution.model);
601
+ if (model) return { model, modelSource: MODEL_SOURCES.has(execution.modelSource) ? execution.modelSource : 'host' };
602
+ }
603
+ const direct = boundedModel(hookInput && hookInput.model);
604
+ return direct ? { model: direct, modelSource: 'host' } : null;
605
+ }
606
+ function leaseModel() {
607
+ if (!sessionId) return null;
608
+ const lease = readSessionLease(sessionId);
609
+ if (!lease || lease.tool !== PLATFORM) return null;
610
+ const model = boundedModel(lease.model);
611
+ return model ? { model, modelSource: 'lease' } : null;
612
+ }
613
+ function executionForStep(step) {
614
+ const modelTier = step && MODEL_TIERS.has(step.model) ? step.model : null;
615
+ const observed = observedModel() || leaseModel();
616
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
617
+ const mapped = modelTier ? readTierMapModel(modelTier) : null;
618
+ if (mapped) return { tool: PLATFORM, modelTier, model: mapped, modelSource: 'tier-map' };
619
+ return { tool: PLATFORM, modelTier, model: null, modelSource: null };
620
+ }
621
+ function closingExecution(entry, step) {
622
+ const model = boundedModel(entry && entry.model);
623
+ const armedTier = entry && MODEL_TIERS.has(entry.modelTier) ? entry.modelTier : null;
624
+ const armedSource = model && entry && MODEL_SOURCES.has(entry.modelSource) ? entry.modelSource : null;
625
+ const observed = observedModel();
626
+ const modelTier = (step && MODEL_TIERS.has(step.model) ? step.model : null) || armedTier;
627
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
628
+ return { tool: PLATFORM, modelTier, model, modelSource: model ? armedSource : null };
629
+ }
564
630
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
565
631
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
566
632
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
@@ -570,8 +636,9 @@ function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null)
570
636
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
571
637
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
572
638
  if (active[attemptId]) continue;
573
- active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null };
574
- appendMetric({ type: 'attempt_started', at: now, attemptId, stepIndex, stepLabel: step.label || null, agent, role: roleFor(agent), attempt, parallelGroupId, waveId: waveId || null, source: 'hook', attributionConfidence: 'high' });
639
+ const execution = executionForStep(step);
640
+ active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null, ...execution };
641
+ appendMetric({ type: 'attempt_started', at: now, attemptId, stepIndex, stepLabel: step.label || null, agent, role: roleFor(agent), attempt, parallelGroupId, waveId: waveId || null, source: 'hook', attributionConfidence: 'high', ...execution });
575
642
  }
576
643
  status.activeAttempts = active;
577
644
  saveWriteScopeBaseline(step);
@@ -1575,10 +1642,12 @@ function finishActiveAttempt(forced) {
1575
1642
  const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
1576
1643
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
1577
1644
  const usage = sanitizeUsage(hookInput.usage);
1645
+ const execution = closingExecution(resolved.entry, Array.isArray(steps) ? steps[resolved.entry.stepIndex] : null);
1578
1646
  appendMetric({
1579
1647
  type: 'attempt_finished',
1580
1648
  at: now,
1581
1649
  attemptId: resolved.attemptId,
1650
+ ...execution,
1582
1651
  stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
1583
1652
  agent: resolved.entry.agent || null,
1584
1653
  outcome,
@@ -2926,9 +2995,10 @@ function armResumedAttempt(step, stepIndex, agent) {
2926
2995
  0,
2927
2996
  ) + 1;
2928
2997
  attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2998
+ const execution = executionForStep(step);
2929
2999
  status.activeAttempts = {
2930
3000
  ...(status.activeAttempts || {}),
2931
- [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
3001
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null, ...execution },
2932
3002
  };
2933
3003
  events.push({
2934
3004
  eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
@@ -2944,6 +3014,7 @@ function armResumedAttempt(step, stepIndex, agent) {
2944
3014
  waveId: null,
2945
3015
  source: 'hook',
2946
3016
  attributionConfidence: 'high',
3017
+ ...execution,
2947
3018
  });
2948
3019
  });
2949
3020
  return attemptId;
@@ -3119,12 +3190,17 @@ if (hookInput.action === 'out_of_band_start') {
3119
3190
  const agent = typeof hookInput.agent === 'string' ? hookInput.agent : 'unknown';
3120
3191
  const reason = typeof hookInput.reason === 'string' ? hookInput.reason : null;
3121
3192
  const outOfBandId = `${status.metricsRunId || slug}:oob:${Date.now()}:${Math.random().toString(16).slice(2, 8)}`;
3193
+ const observed = observedModel();
3122
3194
  appendMetric({
3123
3195
  type: 'out_of_band_started',
3124
3196
  outOfBandId,
3125
3197
  agent,
3126
3198
  reason,
3127
3199
  at: now,
3200
+ tool: PLATFORM,
3201
+ modelTier: null,
3202
+ model: observed ? observed.model : null,
3203
+ modelSource: observed ? observed.modelSource : null,
3128
3204
  source: 'orchestrator',
3129
3205
  attributionConfidence: 'high',
3130
3206
  });
@@ -3159,6 +3235,7 @@ if (hookInput.action === 'out_of_band_end') {
3159
3235
  }
3160
3236
  const durationMs = Math.max(0, Date.parse(now) - Date.parse(started.at));
3161
3237
  const outcome = typeof hookInput.outcome === 'string' ? hookInput.outcome : 'completed';
3238
+ const finishedModel = boundedModel(started.model);
3162
3239
  appendMetric({
3163
3240
  type: 'out_of_band_finished',
3164
3241
  outOfBandId: started.outOfBandId,
@@ -3167,6 +3244,10 @@ if (hookInput.action === 'out_of_band_end') {
3167
3244
  outcome,
3168
3245
  durationMs,
3169
3246
  at: now,
3247
+ tool: PLATFORM,
3248
+ modelTier: MODEL_TIERS.has(started.modelTier) ? started.modelTier : null,
3249
+ model: finishedModel,
3250
+ modelSource: finishedModel && MODEL_SOURCES.has(started.modelSource) ? started.modelSource : null,
3170
3251
  source: 'orchestrator',
3171
3252
  attributionConfidence: 'high',
3172
3253
  });
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "nuxt",
5
5
  "semanticSource": "cursor/nuxt",
6
- "sourceRevision": "93f62ea15b3ad29fd68a1e3562a51a612ff16ee4ebdd3a08ad3c068cb9872bec",
6
+ "sourceRevision": "421006ed9e609bf2cb5a3c35072df1662d72c3090cd489f1f06d8f6f14475a2f",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -86,7 +86,20 @@ function writeSessionLease(id, value) {
86
86
  const temporary = `${file}.${process.pid}.tmp`;
87
87
  const now = new Date().toISOString();
88
88
  const firstSeenAt = firstSeenAtOf(file, value, now);
89
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
89
+ let model = null;
90
+ try {
91
+ if (Date.now() - fs.statSync(file).mtimeMs <= LEASE_TTL_MS) {
92
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
93
+ const previousTool = previous && typeof previous.tool === 'string' ? previous.tool : '';
94
+ const keepModel = previous && previous.slug === value && (previousTool === '' || previousTool === PLATFORM);
95
+ if (keepModel && typeof previous.model === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(previous.model)) {
96
+ model = previous.model;
97
+ }
98
+ }
99
+ } catch {}
100
+ const body = { slug: value, sessionId: id, firstSeenAt, updatedAt: now, tool: PLATFORM };
101
+ if (model) body.model = model;
102
+ fs.writeFileSync(temporary, `${JSON.stringify(body)}\n`);
90
103
  fs.renameSync(temporary, file);
91
104
  for (const name of fs.readdirSync(LEASE_ROOT)) {
92
105
  if (!name.endsWith('.json')) continue;
@@ -177,8 +190,6 @@ if (slugSource === 'active-task.json') {
177
190
  if (slugSource !== 'TEAM_TASK_SLUG') {
178
191
  process.stderr.write(`WARNING: ${slug}: chain hook resolved the slug from ${slugSource}; pass TEAM_TASK_SLUG=<slug> on every hook call so parallel sessions cannot no-op each other.\n`);
179
192
  }
180
- if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
181
-
182
193
  const taskDir = path.join(TEAM_ROOT, 'tasks', slug);
183
194
  const statusPath = path.join(taskDir, 'status.json');
184
195
  const pipelinePath = path.join(taskDir, 'pipeline.json');
@@ -197,6 +208,7 @@ let status;
197
208
  const now = new Date().toISOString();
198
209
  const STACK = 'nuxt';
199
210
  const PLATFORM = 'opencode';
211
+ if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
200
212
 
201
213
  let metricsLockToken = null;
202
214
  function readMetricsLockToken() {
@@ -495,6 +507,7 @@ function reclaimStaleAttempts(scope) {
495
507
  type: 'attempt_finished',
496
508
  at: now,
497
509
  attemptId,
510
+ ...closingExecution(entry, Array.isArray(steps) ? steps[entry.stepIndex] : null),
498
511
  stepIndex: entry.stepIndex,
499
512
  stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
500
513
  agent: entry.agent,
@@ -561,6 +574,59 @@ function saveWriteScopeBaseline(step) {
561
574
  .split('\n').map((line) => line.trim()).filter(Boolean)[0] || `exit ${result ? result.status : 'unknown'}`;
562
575
  process.stderr.write(`[chain-team-phases] ${slug}: write-scope baseline for step ${stepId} not saved (${reason}); the audit will skip that step.\n`);
563
576
  }
577
+ const MODEL_TIERS = new Set(['cheap', 'standard', 'strong']);
578
+ const MODEL_SOURCES = new Set(['host', 'lease', 'tier-map', 'session']);
579
+ function boundedModel(value) {
580
+ if (typeof value !== 'string') return null;
581
+ const text = value.trim();
582
+ return /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(text) ? text : null;
583
+ }
584
+ function readTierMapModel(tier) {
585
+ try {
586
+ const parsed = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'model-tiers.json'), 'utf8'));
587
+ const tiers = parsed && parsed.tiers;
588
+ if (!tiers || typeof tiers !== 'object') return null;
589
+ const approvedBy = typeof parsed.approvedBy === 'string' ? parsed.approvedBy.trim() : '';
590
+ const filled = ['cheap', 'standard', 'strong'].some((key) => typeof tiers[key] === 'string' && tiers[key].trim() !== '');
591
+ if (approvedBy === '' && !filled) return null;
592
+ return boundedModel(tiers[tier]);
593
+ } catch {
594
+ return null;
595
+ }
596
+ }
597
+ function observedModel() {
598
+ const execution = hookInput && hookInput.execution;
599
+ if (execution && typeof execution === 'object') {
600
+ const model = boundedModel(execution.model);
601
+ if (model) return { model, modelSource: MODEL_SOURCES.has(execution.modelSource) ? execution.modelSource : 'host' };
602
+ }
603
+ const direct = boundedModel(hookInput && hookInput.model);
604
+ return direct ? { model: direct, modelSource: 'host' } : null;
605
+ }
606
+ function leaseModel() {
607
+ if (!sessionId) return null;
608
+ const lease = readSessionLease(sessionId);
609
+ if (!lease || lease.tool !== PLATFORM) return null;
610
+ const model = boundedModel(lease.model);
611
+ return model ? { model, modelSource: 'lease' } : null;
612
+ }
613
+ function executionForStep(step) {
614
+ const modelTier = step && MODEL_TIERS.has(step.model) ? step.model : null;
615
+ const observed = observedModel() || leaseModel();
616
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
617
+ const mapped = modelTier ? readTierMapModel(modelTier) : null;
618
+ if (mapped) return { tool: PLATFORM, modelTier, model: mapped, modelSource: 'tier-map' };
619
+ return { tool: PLATFORM, modelTier, model: null, modelSource: null };
620
+ }
621
+ function closingExecution(entry, step) {
622
+ const model = boundedModel(entry && entry.model);
623
+ const armedTier = entry && MODEL_TIERS.has(entry.modelTier) ? entry.modelTier : null;
624
+ const armedSource = model && entry && MODEL_SOURCES.has(entry.modelSource) ? entry.modelSource : null;
625
+ const observed = observedModel();
626
+ const modelTier = (step && MODEL_TIERS.has(step.model) ? step.model : null) || armedTier;
627
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
628
+ return { tool: PLATFORM, modelTier, model, modelSource: model ? armedSource : null };
629
+ }
564
630
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
565
631
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
566
632
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
@@ -570,8 +636,9 @@ function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null)
570
636
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
571
637
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
572
638
  if (active[attemptId]) continue;
573
- active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null };
574
- appendMetric({ type: 'attempt_started', at: now, attemptId, stepIndex, stepLabel: step.label || null, agent, role: roleFor(agent), attempt, parallelGroupId, waveId: waveId || null, source: 'hook', attributionConfidence: 'high' });
639
+ const execution = executionForStep(step);
640
+ active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null, ...execution };
641
+ appendMetric({ type: 'attempt_started', at: now, attemptId, stepIndex, stepLabel: step.label || null, agent, role: roleFor(agent), attempt, parallelGroupId, waveId: waveId || null, source: 'hook', attributionConfidence: 'high', ...execution });
575
642
  }
576
643
  status.activeAttempts = active;
577
644
  saveWriteScopeBaseline(step);
@@ -1575,10 +1642,12 @@ function finishActiveAttempt(forced) {
1575
1642
  const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
1576
1643
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
1577
1644
  const usage = sanitizeUsage(hookInput.usage);
1645
+ const execution = closingExecution(resolved.entry, Array.isArray(steps) ? steps[resolved.entry.stepIndex] : null);
1578
1646
  appendMetric({
1579
1647
  type: 'attempt_finished',
1580
1648
  at: now,
1581
1649
  attemptId: resolved.attemptId,
1650
+ ...execution,
1582
1651
  stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
1583
1652
  agent: resolved.entry.agent || null,
1584
1653
  outcome,
@@ -2926,9 +2995,10 @@ function armResumedAttempt(step, stepIndex, agent) {
2926
2995
  0,
2927
2996
  ) + 1;
2928
2997
  attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2998
+ const execution = executionForStep(step);
2929
2999
  status.activeAttempts = {
2930
3000
  ...(status.activeAttempts || {}),
2931
- [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
3001
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null, ...execution },
2932
3002
  };
2933
3003
  events.push({
2934
3004
  eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
@@ -2944,6 +3014,7 @@ function armResumedAttempt(step, stepIndex, agent) {
2944
3014
  waveId: null,
2945
3015
  source: 'hook',
2946
3016
  attributionConfidence: 'high',
3017
+ ...execution,
2947
3018
  });
2948
3019
  });
2949
3020
  return attemptId;
@@ -3119,12 +3190,17 @@ if (hookInput.action === 'out_of_band_start') {
3119
3190
  const agent = typeof hookInput.agent === 'string' ? hookInput.agent : 'unknown';
3120
3191
  const reason = typeof hookInput.reason === 'string' ? hookInput.reason : null;
3121
3192
  const outOfBandId = `${status.metricsRunId || slug}:oob:${Date.now()}:${Math.random().toString(16).slice(2, 8)}`;
3193
+ const observed = observedModel();
3122
3194
  appendMetric({
3123
3195
  type: 'out_of_band_started',
3124
3196
  outOfBandId,
3125
3197
  agent,
3126
3198
  reason,
3127
3199
  at: now,
3200
+ tool: PLATFORM,
3201
+ modelTier: null,
3202
+ model: observed ? observed.model : null,
3203
+ modelSource: observed ? observed.modelSource : null,
3128
3204
  source: 'orchestrator',
3129
3205
  attributionConfidence: 'high',
3130
3206
  });
@@ -3159,6 +3235,7 @@ if (hookInput.action === 'out_of_band_end') {
3159
3235
  }
3160
3236
  const durationMs = Math.max(0, Date.parse(now) - Date.parse(started.at));
3161
3237
  const outcome = typeof hookInput.outcome === 'string' ? hookInput.outcome : 'completed';
3238
+ const finishedModel = boundedModel(started.model);
3162
3239
  appendMetric({
3163
3240
  type: 'out_of_band_finished',
3164
3241
  outOfBandId: started.outOfBandId,
@@ -3167,6 +3244,10 @@ if (hookInput.action === 'out_of_band_end') {
3167
3244
  outcome,
3168
3245
  durationMs,
3169
3246
  at: now,
3247
+ tool: PLATFORM,
3248
+ modelTier: MODEL_TIERS.has(started.modelTier) ? started.modelTier : null,
3249
+ model: finishedModel,
3250
+ modelSource: finishedModel && MODEL_SOURCES.has(started.modelSource) ? started.modelSource : null,
3170
3251
  source: 'orchestrator',
3171
3252
  attributionConfidence: 'high',
3172
3253
  });
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "php-hexagonal",
5
5
  "semanticSource": "cursor/php-hexagonal",
6
- "sourceRevision": "33eaeac017394e0cb0158e62fdb5e39bf775b84d7c4a98c7ae8b4b7d46d8ba3a",
6
+ "sourceRevision": "506dc53774a78a447b202fcac6ac9de86206225f4b6d8a0a03424b6036ef3352",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -88,7 +88,20 @@ function writeSessionLease(id, value) {
88
88
  const temporary = `${file}.${process.pid}.tmp`;
89
89
  const now = new Date().toISOString();
90
90
  const firstSeenAt = firstSeenAtOf(file, value, now);
91
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
91
+ let model = null;
92
+ try {
93
+ if (Date.now() - fs.statSync(file).mtimeMs <= LEASE_TTL_MS) {
94
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
95
+ const previousTool = previous && typeof previous.tool === 'string' ? previous.tool : '';
96
+ const keepModel = previous && previous.slug === value && (previousTool === '' || previousTool === PLATFORM);
97
+ if (keepModel && typeof previous.model === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(previous.model)) {
98
+ model = previous.model;
99
+ }
100
+ }
101
+ } catch {}
102
+ const body = { slug: value, sessionId: id, firstSeenAt, updatedAt: now, tool: PLATFORM };
103
+ if (model) body.model = model;
104
+ fs.writeFileSync(temporary, `${JSON.stringify(body)}\n`);
92
105
  fs.renameSync(temporary, file);
93
106
  for (const name of fs.readdirSync(LEASE_ROOT)) {
94
107
  if (!name.endsWith('.json')) continue;
@@ -179,8 +192,6 @@ if (slugSource === 'active-task.json') {
179
192
  if (slugSource !== 'TEAM_TASK_SLUG') {
180
193
  process.stderr.write(`WARNING: ${slug}: chain hook resolved the slug from ${slugSource}; pass TEAM_TASK_SLUG=<slug> on every hook call so parallel sessions cannot no-op each other.\n`);
181
194
  }
182
- if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
183
-
184
195
  const taskDir = path.join(TEAM_ROOT, 'tasks', slug);
185
196
  const statusPath = path.join(taskDir, 'status.json');
186
197
  const pipelinePath = path.join(taskDir, 'pipeline.json');
@@ -199,6 +210,7 @@ let status;
199
210
  const now = new Date().toISOString();
200
211
  const STACK = 'php-hexagonal';
201
212
  const PLATFORM = 'opencode';
213
+ if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
202
214
 
203
215
  let metricsLockToken = null;
204
216
  function readMetricsLockToken() {
@@ -495,6 +507,7 @@ function reclaimStaleAttempts(scope) {
495
507
  type: 'attempt_finished',
496
508
  at: now,
497
509
  attemptId,
510
+ ...closingExecution(entry, Array.isArray(steps) ? steps[entry.stepIndex] : null),
498
511
  stepIndex: entry.stepIndex,
499
512
  stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
500
513
  agent: entry.agent,
@@ -561,6 +574,59 @@ function saveWriteScopeBaseline(step) {
561
574
  .split('\n').map((line) => line.trim()).filter(Boolean)[0] || `exit ${result ? result.status : 'unknown'}`;
562
575
  process.stderr.write(`[chain-team-phases] ${slug}: write-scope baseline for step ${stepId} not saved (${reason}); the audit will skip that step.\n`);
563
576
  }
577
+ const MODEL_TIERS = new Set(['cheap', 'standard', 'strong']);
578
+ const MODEL_SOURCES = new Set(['host', 'lease', 'tier-map', 'session']);
579
+ function boundedModel(value) {
580
+ if (typeof value !== 'string') return null;
581
+ const text = value.trim();
582
+ return /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(text) ? text : null;
583
+ }
584
+ function readTierMapModel(tier) {
585
+ try {
586
+ const parsed = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'model-tiers.json'), 'utf8'));
587
+ const tiers = parsed && parsed.tiers;
588
+ if (!tiers || typeof tiers !== 'object') return null;
589
+ const approvedBy = typeof parsed.approvedBy === 'string' ? parsed.approvedBy.trim() : '';
590
+ const filled = ['cheap', 'standard', 'strong'].some((key) => typeof tiers[key] === 'string' && tiers[key].trim() !== '');
591
+ if (approvedBy === '' && !filled) return null;
592
+ return boundedModel(tiers[tier]);
593
+ } catch {
594
+ return null;
595
+ }
596
+ }
597
+ function observedModel() {
598
+ const execution = hookInput && hookInput.execution;
599
+ if (execution && typeof execution === 'object') {
600
+ const model = boundedModel(execution.model);
601
+ if (model) return { model, modelSource: MODEL_SOURCES.has(execution.modelSource) ? execution.modelSource : 'host' };
602
+ }
603
+ const direct = boundedModel(hookInput && hookInput.model);
604
+ return direct ? { model: direct, modelSource: 'host' } : null;
605
+ }
606
+ function leaseModel() {
607
+ if (!sessionId) return null;
608
+ const lease = readSessionLease(sessionId);
609
+ if (!lease || lease.tool !== PLATFORM) return null;
610
+ const model = boundedModel(lease.model);
611
+ return model ? { model, modelSource: 'lease' } : null;
612
+ }
613
+ function executionForStep(step) {
614
+ const modelTier = step && MODEL_TIERS.has(step.model) ? step.model : null;
615
+ const observed = observedModel() || leaseModel();
616
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
617
+ const mapped = modelTier ? readTierMapModel(modelTier) : null;
618
+ if (mapped) return { tool: PLATFORM, modelTier, model: mapped, modelSource: 'tier-map' };
619
+ return { tool: PLATFORM, modelTier, model: null, modelSource: null };
620
+ }
621
+ function closingExecution(entry, step) {
622
+ const model = boundedModel(entry && entry.model);
623
+ const armedTier = entry && MODEL_TIERS.has(entry.modelTier) ? entry.modelTier : null;
624
+ const armedSource = model && entry && MODEL_SOURCES.has(entry.modelSource) ? entry.modelSource : null;
625
+ const observed = observedModel();
626
+ const modelTier = (step && MODEL_TIERS.has(step.model) ? step.model : null) || armedTier;
627
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
628
+ return { tool: PLATFORM, modelTier, model, modelSource: model ? armedSource : null };
629
+ }
564
630
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
565
631
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
566
632
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
@@ -570,8 +636,9 @@ function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null)
570
636
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
571
637
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
572
638
  if (active[attemptId]) continue;
573
- active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null };
574
- appendMetric({ type: 'attempt_started', at: now, attemptId, stepIndex, stepLabel: step.label || null, agent, role: roleFor(agent), attempt, parallelGroupId, waveId: waveId || null, source: 'hook', attributionConfidence: 'high' });
639
+ const execution = executionForStep(step);
640
+ active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null, ...execution };
641
+ appendMetric({ type: 'attempt_started', at: now, attemptId, stepIndex, stepLabel: step.label || null, agent, role: roleFor(agent), attempt, parallelGroupId, waveId: waveId || null, source: 'hook', attributionConfidence: 'high', ...execution });
575
642
  }
576
643
  status.activeAttempts = active;
577
644
  saveWriteScopeBaseline(step);
@@ -1575,10 +1642,12 @@ function finishActiveAttempt(forced) {
1575
1642
  const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
1576
1643
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
1577
1644
  const usage = sanitizeUsage(hookInput.usage);
1645
+ const execution = closingExecution(resolved.entry, Array.isArray(steps) ? steps[resolved.entry.stepIndex] : null);
1578
1646
  appendMetric({
1579
1647
  type: 'attempt_finished',
1580
1648
  at: now,
1581
1649
  attemptId: resolved.attemptId,
1650
+ ...execution,
1582
1651
  stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
1583
1652
  agent: resolved.entry.agent || null,
1584
1653
  outcome,
@@ -2924,9 +2993,10 @@ function armResumedAttempt(step, stepIndex, agent) {
2924
2993
  0,
2925
2994
  ) + 1;
2926
2995
  attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2996
+ const execution = executionForStep(step);
2927
2997
  status.activeAttempts = {
2928
2998
  ...(status.activeAttempts || {}),
2929
- [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2999
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null, ...execution },
2930
3000
  };
2931
3001
  events.push({
2932
3002
  eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
@@ -2942,6 +3012,7 @@ function armResumedAttempt(step, stepIndex, agent) {
2942
3012
  waveId: null,
2943
3013
  source: 'hook',
2944
3014
  attributionConfidence: 'high',
3015
+ ...execution,
2945
3016
  });
2946
3017
  });
2947
3018
  return attemptId;
@@ -3117,12 +3188,17 @@ if (hookInput.action === 'out_of_band_start') {
3117
3188
  const agent = typeof hookInput.agent === 'string' ? hookInput.agent : 'unknown';
3118
3189
  const reason = typeof hookInput.reason === 'string' ? hookInput.reason : null;
3119
3190
  const outOfBandId = `${status.metricsRunId || slug}:oob:${Date.now()}:${Math.random().toString(16).slice(2, 8)}`;
3191
+ const observed = observedModel();
3120
3192
  appendMetric({
3121
3193
  type: 'out_of_band_started',
3122
3194
  outOfBandId,
3123
3195
  agent,
3124
3196
  reason,
3125
3197
  at: now,
3198
+ tool: PLATFORM,
3199
+ modelTier: null,
3200
+ model: observed ? observed.model : null,
3201
+ modelSource: observed ? observed.modelSource : null,
3126
3202
  source: 'orchestrator',
3127
3203
  attributionConfidence: 'high',
3128
3204
  });
@@ -3157,6 +3233,7 @@ if (hookInput.action === 'out_of_band_end') {
3157
3233
  }
3158
3234
  const durationMs = Math.max(0, Date.parse(now) - Date.parse(started.at));
3159
3235
  const outcome = typeof hookInput.outcome === 'string' ? hookInput.outcome : 'completed';
3236
+ const finishedModel = boundedModel(started.model);
3160
3237
  appendMetric({
3161
3238
  type: 'out_of_band_finished',
3162
3239
  outOfBandId: started.outOfBandId,
@@ -3165,6 +3242,10 @@ if (hookInput.action === 'out_of_band_end') {
3165
3242
  outcome,
3166
3243
  durationMs,
3167
3244
  at: now,
3245
+ tool: PLATFORM,
3246
+ modelTier: MODEL_TIERS.has(started.modelTier) ? started.modelTier : null,
3247
+ model: finishedModel,
3248
+ modelSource: finishedModel && MODEL_SOURCES.has(started.modelSource) ? started.modelSource : null,
3168
3249
  source: 'orchestrator',
3169
3250
  attributionConfidence: 'high',
3170
3251
  });
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "php-laravel",
5
5
  "semanticSource": "cursor/php-laravel",
6
- "sourceRevision": "18bfdc52993d5d62a7b02dc69ce4b62e4d1f2b18e371005c42ca28f68c2fca3c",
6
+ "sourceRevision": "2debd835121bfdcb3b6e149403ec107019d9006bcc3f3fbc7cc4d99b2c5472bf",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",