@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 = 'ios-swift';
199
210
  const PLATFORM = 'mavis';
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,
@@ -2928,9 +2997,10 @@ function armResumedAttempt(step, stepIndex, agent) {
2928
2997
  0,
2929
2998
  ) + 1;
2930
2999
  attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
3000
+ const execution = executionForStep(step);
2931
3001
  status.activeAttempts = {
2932
3002
  ...(status.activeAttempts || {}),
2933
- [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
3003
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null, ...execution },
2934
3004
  };
2935
3005
  events.push({
2936
3006
  eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
@@ -2946,6 +3016,7 @@ function armResumedAttempt(step, stepIndex, agent) {
2946
3016
  waveId: null,
2947
3017
  source: 'hook',
2948
3018
  attributionConfidence: 'high',
3019
+ ...execution,
2949
3020
  });
2950
3021
  });
2951
3022
  return attemptId;
@@ -3121,12 +3192,17 @@ if (hookInput.action === 'out_of_band_start') {
3121
3192
  const agent = typeof hookInput.agent === 'string' ? hookInput.agent : 'unknown';
3122
3193
  const reason = typeof hookInput.reason === 'string' ? hookInput.reason : null;
3123
3194
  const outOfBandId = `${status.metricsRunId || slug}:oob:${Date.now()}:${Math.random().toString(16).slice(2, 8)}`;
3195
+ const observed = observedModel();
3124
3196
  appendMetric({
3125
3197
  type: 'out_of_band_started',
3126
3198
  outOfBandId,
3127
3199
  agent,
3128
3200
  reason,
3129
3201
  at: now,
3202
+ tool: PLATFORM,
3203
+ modelTier: null,
3204
+ model: observed ? observed.model : null,
3205
+ modelSource: observed ? observed.modelSource : null,
3130
3206
  source: 'orchestrator',
3131
3207
  attributionConfidence: 'high',
3132
3208
  });
@@ -3161,6 +3237,7 @@ if (hookInput.action === 'out_of_band_end') {
3161
3237
  }
3162
3238
  const durationMs = Math.max(0, Date.parse(now) - Date.parse(started.at));
3163
3239
  const outcome = typeof hookInput.outcome === 'string' ? hookInput.outcome : 'completed';
3240
+ const finishedModel = boundedModel(started.model);
3164
3241
  appendMetric({
3165
3242
  type: 'out_of_band_finished',
3166
3243
  outOfBandId: started.outOfBandId,
@@ -3169,6 +3246,10 @@ if (hookInput.action === 'out_of_band_end') {
3169
3246
  outcome,
3170
3247
  durationMs,
3171
3248
  at: now,
3249
+ tool: PLATFORM,
3250
+ modelTier: MODEL_TIERS.has(started.modelTier) ? started.modelTier : null,
3251
+ model: finishedModel,
3252
+ modelSource: finishedModel && MODEL_SOURCES.has(started.modelSource) ? started.modelSource : null,
3172
3253
  source: 'orchestrator',
3173
3254
  attributionConfidence: 'high',
3174
3255
  });
@@ -3,7 +3,7 @@
3
3
  "platform": "mavis",
4
4
  "stack": "java",
5
5
  "semanticSource": "cursor/java",
6
- "sourceRevision": "771c086d56bb8cf2f21df895f5577cbaf0b42da25bedd9aa334bed32b861ad0c",
6
+ "sourceRevision": "90e18d05b81ff995f9a07830c9d6ca88df1aab8f3fd9e804f44e41957a811d52",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -87,7 +87,20 @@ function writeSessionLease(id, value) {
87
87
  const temporary = `${file}.${process.pid}.tmp`;
88
88
  const now = new Date().toISOString();
89
89
  const firstSeenAt = firstSeenAtOf(file, value, now);
90
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
90
+ let model = null;
91
+ try {
92
+ if (Date.now() - fs.statSync(file).mtimeMs <= LEASE_TTL_MS) {
93
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
94
+ const previousTool = previous && typeof previous.tool === 'string' ? previous.tool : '';
95
+ const keepModel = previous && previous.slug === value && (previousTool === '' || previousTool === PLATFORM);
96
+ if (keepModel && typeof previous.model === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(previous.model)) {
97
+ model = previous.model;
98
+ }
99
+ }
100
+ } catch {}
101
+ const body = { slug: value, sessionId: id, firstSeenAt, updatedAt: now, tool: PLATFORM };
102
+ if (model) body.model = model;
103
+ fs.writeFileSync(temporary, `${JSON.stringify(body)}\n`);
91
104
  fs.renameSync(temporary, file);
92
105
  for (const name of fs.readdirSync(LEASE_ROOT)) {
93
106
  if (!name.endsWith('.json')) continue;
@@ -178,8 +191,6 @@ if (slugSource === 'active-task.json') {
178
191
  if (slugSource !== 'TEAM_TASK_SLUG') {
179
192
  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`);
180
193
  }
181
- if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
182
-
183
194
  const taskDir = path.join(TEAM_ROOT, 'tasks', slug);
184
195
  const statusPath = path.join(taskDir, 'status.json');
185
196
  const pipelinePath = path.join(taskDir, 'pipeline.json');
@@ -198,6 +209,7 @@ let status;
198
209
  const now = new Date().toISOString();
199
210
  const STACK = 'java';
200
211
  const PLATFORM = 'mavis';
212
+ if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
201
213
 
202
214
  let metricsLockToken = null;
203
215
  function readMetricsLockToken() {
@@ -494,6 +506,7 @@ function reclaimStaleAttempts(scope) {
494
506
  type: 'attempt_finished',
495
507
  at: now,
496
508
  attemptId,
509
+ ...closingExecution(entry, Array.isArray(steps) ? steps[entry.stepIndex] : null),
497
510
  stepIndex: entry.stepIndex,
498
511
  stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
499
512
  agent: entry.agent,
@@ -560,6 +573,59 @@ function saveWriteScopeBaseline(step) {
560
573
  .split('\n').map((line) => line.trim()).filter(Boolean)[0] || `exit ${result ? result.status : 'unknown'}`;
561
574
  process.stderr.write(`[chain-team-phases] ${slug}: write-scope baseline for step ${stepId} not saved (${reason}); the audit will skip that step.\n`);
562
575
  }
576
+ const MODEL_TIERS = new Set(['cheap', 'standard', 'strong']);
577
+ const MODEL_SOURCES = new Set(['host', 'lease', 'tier-map', 'session']);
578
+ function boundedModel(value) {
579
+ if (typeof value !== 'string') return null;
580
+ const text = value.trim();
581
+ return /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(text) ? text : null;
582
+ }
583
+ function readTierMapModel(tier) {
584
+ try {
585
+ const parsed = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'model-tiers.json'), 'utf8'));
586
+ const tiers = parsed && parsed.tiers;
587
+ if (!tiers || typeof tiers !== 'object') return null;
588
+ const approvedBy = typeof parsed.approvedBy === 'string' ? parsed.approvedBy.trim() : '';
589
+ const filled = ['cheap', 'standard', 'strong'].some((key) => typeof tiers[key] === 'string' && tiers[key].trim() !== '');
590
+ if (approvedBy === '' && !filled) return null;
591
+ return boundedModel(tiers[tier]);
592
+ } catch {
593
+ return null;
594
+ }
595
+ }
596
+ function observedModel() {
597
+ const execution = hookInput && hookInput.execution;
598
+ if (execution && typeof execution === 'object') {
599
+ const model = boundedModel(execution.model);
600
+ if (model) return { model, modelSource: MODEL_SOURCES.has(execution.modelSource) ? execution.modelSource : 'host' };
601
+ }
602
+ const direct = boundedModel(hookInput && hookInput.model);
603
+ return direct ? { model: direct, modelSource: 'host' } : null;
604
+ }
605
+ function leaseModel() {
606
+ if (!sessionId) return null;
607
+ const lease = readSessionLease(sessionId);
608
+ if (!lease || lease.tool !== PLATFORM) return null;
609
+ const model = boundedModel(lease.model);
610
+ return model ? { model, modelSource: 'lease' } : null;
611
+ }
612
+ function executionForStep(step) {
613
+ const modelTier = step && MODEL_TIERS.has(step.model) ? step.model : null;
614
+ const observed = observedModel() || leaseModel();
615
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
616
+ const mapped = modelTier ? readTierMapModel(modelTier) : null;
617
+ if (mapped) return { tool: PLATFORM, modelTier, model: mapped, modelSource: 'tier-map' };
618
+ return { tool: PLATFORM, modelTier, model: null, modelSource: null };
619
+ }
620
+ function closingExecution(entry, step) {
621
+ const model = boundedModel(entry && entry.model);
622
+ const armedTier = entry && MODEL_TIERS.has(entry.modelTier) ? entry.modelTier : null;
623
+ const armedSource = model && entry && MODEL_SOURCES.has(entry.modelSource) ? entry.modelSource : null;
624
+ const observed = observedModel();
625
+ const modelTier = (step && MODEL_TIERS.has(step.model) ? step.model : null) || armedTier;
626
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
627
+ return { tool: PLATFORM, modelTier, model, modelSource: model ? armedSource : null };
628
+ }
563
629
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
564
630
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
565
631
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
@@ -569,8 +635,9 @@ function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null)
569
635
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
570
636
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
571
637
  if (active[attemptId]) continue;
572
- active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null };
573
- 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' });
638
+ const execution = executionForStep(step);
639
+ active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null, ...execution };
640
+ 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 });
574
641
  }
575
642
  status.activeAttempts = active;
576
643
  saveWriteScopeBaseline(step);
@@ -1574,10 +1641,12 @@ function finishActiveAttempt(forced) {
1574
1641
  const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
1575
1642
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
1576
1643
  const usage = sanitizeUsage(hookInput.usage);
1644
+ const execution = closingExecution(resolved.entry, Array.isArray(steps) ? steps[resolved.entry.stepIndex] : null);
1577
1645
  appendMetric({
1578
1646
  type: 'attempt_finished',
1579
1647
  at: now,
1580
1648
  attemptId: resolved.attemptId,
1649
+ ...execution,
1581
1650
  stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
1582
1651
  agent: resolved.entry.agent || null,
1583
1652
  outcome,
@@ -2923,9 +2992,10 @@ function armResumedAttempt(step, stepIndex, agent) {
2923
2992
  0,
2924
2993
  ) + 1;
2925
2994
  attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2995
+ const execution = executionForStep(step);
2926
2996
  status.activeAttempts = {
2927
2997
  ...(status.activeAttempts || {}),
2928
- [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2998
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null, ...execution },
2929
2999
  };
2930
3000
  events.push({
2931
3001
  eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
@@ -2941,6 +3011,7 @@ function armResumedAttempt(step, stepIndex, agent) {
2941
3011
  waveId: null,
2942
3012
  source: 'hook',
2943
3013
  attributionConfidence: 'high',
3014
+ ...execution,
2944
3015
  });
2945
3016
  });
2946
3017
  return attemptId;
@@ -3116,12 +3187,17 @@ if (hookInput.action === 'out_of_band_start') {
3116
3187
  const agent = typeof hookInput.agent === 'string' ? hookInput.agent : 'unknown';
3117
3188
  const reason = typeof hookInput.reason === 'string' ? hookInput.reason : null;
3118
3189
  const outOfBandId = `${status.metricsRunId || slug}:oob:${Date.now()}:${Math.random().toString(16).slice(2, 8)}`;
3190
+ const observed = observedModel();
3119
3191
  appendMetric({
3120
3192
  type: 'out_of_band_started',
3121
3193
  outOfBandId,
3122
3194
  agent,
3123
3195
  reason,
3124
3196
  at: now,
3197
+ tool: PLATFORM,
3198
+ modelTier: null,
3199
+ model: observed ? observed.model : null,
3200
+ modelSource: observed ? observed.modelSource : null,
3125
3201
  source: 'orchestrator',
3126
3202
  attributionConfidence: 'high',
3127
3203
  });
@@ -3156,6 +3232,7 @@ if (hookInput.action === 'out_of_band_end') {
3156
3232
  }
3157
3233
  const durationMs = Math.max(0, Date.parse(now) - Date.parse(started.at));
3158
3234
  const outcome = typeof hookInput.outcome === 'string' ? hookInput.outcome : 'completed';
3235
+ const finishedModel = boundedModel(started.model);
3159
3236
  appendMetric({
3160
3237
  type: 'out_of_band_finished',
3161
3238
  outOfBandId: started.outOfBandId,
@@ -3164,6 +3241,10 @@ if (hookInput.action === 'out_of_band_end') {
3164
3241
  outcome,
3165
3242
  durationMs,
3166
3243
  at: now,
3244
+ tool: PLATFORM,
3245
+ modelTier: MODEL_TIERS.has(started.modelTier) ? started.modelTier : null,
3246
+ model: finishedModel,
3247
+ modelSource: finishedModel && MODEL_SOURCES.has(started.modelSource) ? started.modelSource : null,
3167
3248
  source: 'orchestrator',
3168
3249
  attributionConfidence: 'high',
3169
3250
  });
@@ -3,7 +3,7 @@
3
3
  "platform": "mavis",
4
4
  "stack": "mcp-ts",
5
5
  "semanticSource": "cursor/mcp-ts",
6
- "sourceRevision": "17ce7626ede115d23f1033a84dd383768389b730f8f57013b7f63d22da0dc3c7",
6
+ "sourceRevision": "6ba2b9eb03742ec269c70e86ec4458de90fdacff50b6c993c0a7f2ecf68f7eec",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -89,7 +89,20 @@ function writeSessionLease(id, value) {
89
89
  const temporary = `${file}.${process.pid}.tmp`;
90
90
  const now = new Date().toISOString();
91
91
  const firstSeenAt = firstSeenAtOf(file, value, now);
92
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
92
+ let model = null;
93
+ try {
94
+ if (Date.now() - fs.statSync(file).mtimeMs <= LEASE_TTL_MS) {
95
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
96
+ const previousTool = previous && typeof previous.tool === 'string' ? previous.tool : '';
97
+ const keepModel = previous && previous.slug === value && (previousTool === '' || previousTool === PLATFORM);
98
+ if (keepModel && typeof previous.model === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(previous.model)) {
99
+ model = previous.model;
100
+ }
101
+ }
102
+ } catch {}
103
+ const body = { slug: value, sessionId: id, firstSeenAt, updatedAt: now, tool: PLATFORM };
104
+ if (model) body.model = model;
105
+ fs.writeFileSync(temporary, `${JSON.stringify(body)}\n`);
93
106
  fs.renameSync(temporary, file);
94
107
  for (const name of fs.readdirSync(LEASE_ROOT)) {
95
108
  if (!name.endsWith('.json')) continue;
@@ -180,8 +193,6 @@ if (slugSource === 'active-task.json') {
180
193
  if (slugSource !== 'TEAM_TASK_SLUG') {
181
194
  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`);
182
195
  }
183
- if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
184
-
185
196
  const taskDir = path.join(TEAM_ROOT, 'tasks', slug);
186
197
  const statusPath = path.join(taskDir, 'status.json');
187
198
  const pipelinePath = path.join(taskDir, 'pipeline.json');
@@ -200,6 +211,7 @@ let status;
200
211
  const now = new Date().toISOString();
201
212
  const STACK = 'mcp-ts';
202
213
  const PLATFORM = 'mavis';
214
+ if (slugSource === 'TEAM_TASK_SLUG' && sessionId) writeSessionLease(sessionId, slug);
203
215
 
204
216
  let metricsLockToken = null;
205
217
  function readMetricsLockToken() {
@@ -482,6 +494,7 @@ function reclaimStaleAttempts(scope) {
482
494
  type: 'attempt_finished',
483
495
  at: now,
484
496
  attemptId,
497
+ ...closingExecution(entry, Array.isArray(steps) ? steps[entry.stepIndex] : null),
485
498
  stepIndex: entry.stepIndex,
486
499
  stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
487
500
  agent: entry.agent,
@@ -548,6 +561,59 @@ function saveWriteScopeBaseline(step) {
548
561
  .split('\n').map((line) => line.trim()).filter(Boolean)[0] || `exit ${result ? result.status : 'unknown'}`;
549
562
  process.stderr.write(`[chain-team-phases] ${slug}: write-scope baseline for step ${stepId} not saved (${reason}); the audit will skip that step.\n`);
550
563
  }
564
+ const MODEL_TIERS = new Set(['cheap', 'standard', 'strong']);
565
+ const MODEL_SOURCES = new Set(['host', 'lease', 'tier-map', 'session']);
566
+ function boundedModel(value) {
567
+ if (typeof value !== 'string') return null;
568
+ const text = value.trim();
569
+ return /^[A-Za-z0-9][A-Za-z0-9._:@/#-]{0,119}$/.test(text) ? text : null;
570
+ }
571
+ function readTierMapModel(tier) {
572
+ try {
573
+ const parsed = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'model-tiers.json'), 'utf8'));
574
+ const tiers = parsed && parsed.tiers;
575
+ if (!tiers || typeof tiers !== 'object') return null;
576
+ const approvedBy = typeof parsed.approvedBy === 'string' ? parsed.approvedBy.trim() : '';
577
+ const filled = ['cheap', 'standard', 'strong'].some((key) => typeof tiers[key] === 'string' && tiers[key].trim() !== '');
578
+ if (approvedBy === '' && !filled) return null;
579
+ return boundedModel(tiers[tier]);
580
+ } catch {
581
+ return null;
582
+ }
583
+ }
584
+ function observedModel() {
585
+ const execution = hookInput && hookInput.execution;
586
+ if (execution && typeof execution === 'object') {
587
+ const model = boundedModel(execution.model);
588
+ if (model) return { model, modelSource: MODEL_SOURCES.has(execution.modelSource) ? execution.modelSource : 'host' };
589
+ }
590
+ const direct = boundedModel(hookInput && hookInput.model);
591
+ return direct ? { model: direct, modelSource: 'host' } : null;
592
+ }
593
+ function leaseModel() {
594
+ if (!sessionId) return null;
595
+ const lease = readSessionLease(sessionId);
596
+ if (!lease || lease.tool !== PLATFORM) return null;
597
+ const model = boundedModel(lease.model);
598
+ return model ? { model, modelSource: 'lease' } : null;
599
+ }
600
+ function executionForStep(step) {
601
+ const modelTier = step && MODEL_TIERS.has(step.model) ? step.model : null;
602
+ const observed = observedModel() || leaseModel();
603
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
604
+ const mapped = modelTier ? readTierMapModel(modelTier) : null;
605
+ if (mapped) return { tool: PLATFORM, modelTier, model: mapped, modelSource: 'tier-map' };
606
+ return { tool: PLATFORM, modelTier, model: null, modelSource: null };
607
+ }
608
+ function closingExecution(entry, step) {
609
+ const model = boundedModel(entry && entry.model);
610
+ const armedTier = entry && MODEL_TIERS.has(entry.modelTier) ? entry.modelTier : null;
611
+ const armedSource = model && entry && MODEL_SOURCES.has(entry.modelSource) ? entry.modelSource : null;
612
+ const observed = observedModel();
613
+ const modelTier = (step && MODEL_TIERS.has(step.model) ? step.model : null) || armedTier;
614
+ if (observed) return { tool: PLATFORM, modelTier, model: observed.model, modelSource: observed.modelSource };
615
+ return { tool: PLATFORM, modelTier, model, modelSource: model ? armedSource : null };
616
+ }
551
617
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
552
618
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
553
619
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
@@ -557,8 +623,9 @@ function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null)
557
623
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
558
624
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
559
625
  if (active[attemptId]) continue;
560
- active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null };
561
- 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' });
626
+ const execution = executionForStep(step);
627
+ active[attemptId] = { agent, stepIndex, attempt, startedAt: now, parallelGroupId, waveId: waveId || null, ...execution };
628
+ 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 });
562
629
  }
563
630
  status.activeAttempts = active;
564
631
  saveWriteScopeBaseline(step);
@@ -1562,10 +1629,12 @@ function finishActiveAttempt(forced) {
1562
1629
  const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
1563
1630
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
1564
1631
  const usage = sanitizeUsage(hookInput.usage);
1632
+ const execution = closingExecution(resolved.entry, Array.isArray(steps) ? steps[resolved.entry.stepIndex] : null);
1565
1633
  appendMetric({
1566
1634
  type: 'attempt_finished',
1567
1635
  at: now,
1568
1636
  attemptId: resolved.attemptId,
1637
+ ...execution,
1569
1638
  stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
1570
1639
  agent: resolved.entry.agent || null,
1571
1640
  outcome,
@@ -2870,9 +2939,10 @@ function armResumedAttempt(step, stepIndex, agent) {
2870
2939
  0,
2871
2940
  ) + 1;
2872
2941
  attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
2942
+ const execution = executionForStep(step);
2873
2943
  status.activeAttempts = {
2874
2944
  ...(status.activeAttempts || {}),
2875
- [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null },
2945
+ [attemptId]: { agent, stepIndex, attempt, startedAt: now, parallelGroupId: null, waveId: null, ...execution },
2876
2946
  };
2877
2947
  events.push({
2878
2948
  eventId: `${runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
@@ -2888,6 +2958,7 @@ function armResumedAttempt(step, stepIndex, agent) {
2888
2958
  waveId: null,
2889
2959
  source: 'hook',
2890
2960
  attributionConfidence: 'high',
2961
+ ...execution,
2891
2962
  });
2892
2963
  });
2893
2964
  return attemptId;
@@ -3063,12 +3134,17 @@ if (hookInput.action === 'out_of_band_start') {
3063
3134
  const agent = typeof hookInput.agent === 'string' ? hookInput.agent : 'unknown';
3064
3135
  const reason = typeof hookInput.reason === 'string' ? hookInput.reason : null;
3065
3136
  const outOfBandId = `${status.metricsRunId || slug}:oob:${Date.now()}:${Math.random().toString(16).slice(2, 8)}`;
3137
+ const observed = observedModel();
3066
3138
  appendMetric({
3067
3139
  type: 'out_of_band_started',
3068
3140
  outOfBandId,
3069
3141
  agent,
3070
3142
  reason,
3071
3143
  at: now,
3144
+ tool: PLATFORM,
3145
+ modelTier: null,
3146
+ model: observed ? observed.model : null,
3147
+ modelSource: observed ? observed.modelSource : null,
3072
3148
  source: 'orchestrator',
3073
3149
  attributionConfidence: 'high',
3074
3150
  });
@@ -3103,6 +3179,7 @@ if (hookInput.action === 'out_of_band_end') {
3103
3179
  }
3104
3180
  const durationMs = Math.max(0, Date.parse(now) - Date.parse(started.at));
3105
3181
  const outcome = typeof hookInput.outcome === 'string' ? hookInput.outcome : 'completed';
3182
+ const finishedModel = boundedModel(started.model);
3106
3183
  appendMetric({
3107
3184
  type: 'out_of_band_finished',
3108
3185
  outOfBandId: started.outOfBandId,
@@ -3111,6 +3188,10 @@ if (hookInput.action === 'out_of_band_end') {
3111
3188
  outcome,
3112
3189
  durationMs,
3113
3190
  at: now,
3191
+ tool: PLATFORM,
3192
+ modelTier: MODEL_TIERS.has(started.modelTier) ? started.modelTier : null,
3193
+ model: finishedModel,
3194
+ modelSource: finishedModel && MODEL_SOURCES.has(started.modelSource) ? started.modelSource : null,
3114
3195
  source: 'orchestrator',
3115
3196
  attributionConfidence: 'high',
3116
3197
  });
@@ -3,7 +3,7 @@
3
3
  "platform": "mavis",
4
4
  "stack": "mol",
5
5
  "semanticSource": "cursor/mol",
6
- "sourceRevision": "d538968cd662b7c6a5765db9ac9fd0175090bb1a41f71520277b5e130d8078bc",
6
+ "sourceRevision": "bb338787e38a8372032e93b46d9a917e476ce8e83da5b857347b6284719d40cf",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",