@bonesofspring/ai-rules 0.2.91 → 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.
- package/CHANGELOG.md +31 -0
- package/docs/TEAM-DB.md +2 -0
- package/package.json +1 -1
- package/presets/_shared/ai-local/scripts/team-db-api.mjs +33 -15
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +15 -0
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +41 -2
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +23 -0
- package/presets/_shared/core/agent-team/agent-task-metrics.md +16 -1
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +87 -6
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/go/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/java/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/mol/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/next/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +87 -6
- package/presets/claude/svelte/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/go/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/java/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/mol/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/next/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +87 -6
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +87 -6
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +87 -6
- package/presets/opencode/plugins/task-status/README.md +2 -2
- package/presets/opencode/plugins/task-status/deepseek.ts +8 -4
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +87 -6
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +87 -6
|
@@ -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
|
-
|
|
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-laravel';
|
|
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
|
-
|
|
574
|
-
|
|
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
|
});
|
|
@@ -13,7 +13,7 @@ Modelled on the built-in MCP sidebar plugin (`packages/tui/src/feature-plugins/s
|
|
|
13
13
|
- the `eta` row reads `~52m · p90 3h 32m`: estimated time to finish the remaining plan steps. It hides while the run waits on a human gate, is paused, blocked, waiting for a receipt, or is done. A stale run keeps it — the estimate is historical, not live — and with fewer than 3 ledgers the row reads `—` instead of disappearing
|
|
14
14
|
- clicking any row opens a details dialog with 3-cell side padding: `goal.md`, pipeline steps with the current one marked, artifacts from `artifact-manifest.json`, the last manifest entries, the prompt, the last update age and the ETA with its ledger count. The body scrolls with ↑/↓, PgUp/PgDn, Home/End or the mouse wheel; `esc` closes it.
|
|
15
15
|
- a live task shows `■ stop` in the header; click → confirm → writes the task-scoped `.ai.local/team/tasks/<slug>/STOP`. If that directory cannot be written, a second confirm asks before the repo-wide `.ai.local/STOP` is written. The in-flight attempt finishes, no next step starts. A task with a stop sentinel shows `▶ resume` instead: confirm clears it. Saying `/task-continue <slug>` (or `продолжай` / `continue`) in a matched session is the keyboard path. <!-- i18n-keep: E4 -->
|
|
16
|
-
- one `[peak]` / `[off-peak]` row
|
|
16
|
+
- one `[peak]` / `[off-peak]` row for DeepSeek and Z.AI in the nearest `.ai.local/models` store (the same `providers` / `links` / `windows` records the team-tasks UI reads). Those two are the only providers with a published peak schedule, so every other provider is omitted. No store, no rows. A weekly window covers `[startHour, endHour)` — the end hour is exclusive — and `startHour > endHour` wraps across midnight. A missing or non-finite hour drops that window. Chinese public holidays are off-peak all day but are not tracked, so a holiday weekday still reads `peak` inside a window
|
|
17
17
|
- a `Z.AI` row reads the same `[peak]`/`[off-peak]` for the GLM Coding Plan: the peak `windows` linked to the `Z.AI` provider in the same store (Monday–Friday 14:00–18:00 Asia/Singapore; weekends deduct at off-peak rates all day). Without a store it falls back to that published schedule. Quota consumption percentages and reset times are intentionally not shown: the plan quota is server-side and no usage API is documented
|
|
18
18
|
- a stale task reads `◌ stale · 8d 17h ago` with a muted tone instead of pretending to run
|
|
19
19
|
- the open flag lives in `context.storage.store("panel", { initial: { open: true } })`, so it survives restarts; the live view stays in `context.storage.memory`
|
|
@@ -21,7 +21,7 @@ Modelled on the built-in MCP sidebar plugin (`packages/tui/src/feature-plugins/s
|
|
|
21
21
|
|
|
22
22
|
## Data
|
|
23
23
|
|
|
24
|
-
Reads the nearest `.ai.local/team/` above the session directory, and the provider peak windows from the nearest `.ai.local/models/` — the same `providers`/`links`/`windows` records `apps/team-tasks-ui` reads (`MODELS_ROOT` points at the models directory; the deprecated `CATALOG_ROOT` still works for one release). The sidebar lists only
|
|
24
|
+
Reads the nearest `.ai.local/team/` above the session directory, and the provider peak windows from the nearest `.ai.local/models/` — the same `providers`/`links`/`windows` records `apps/team-tasks-ui` reads (`MODELS_ROOT` points at the models directory; the deprecated `CATALOG_ROOT` still works for one release). The sidebar lists only DeepSeek and Z.AI when the store names them:
|
|
25
25
|
|
|
26
26
|
- `tasks/<slug>/prompt.md` — the original prompt, the session-matching anchor
|
|
27
27
|
- `tasks/<slug>/prompt-log.md` — the follow-up log, shown in the details dialog only
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* covers `[startHour, endHour)` — the end hour is exclusive, so the published
|
|
9
9
|
* "14:00-18:00" schedule ends at 18:00 — and `startHour > endHour` spans
|
|
10
10
|
* midnight; absolute windows match `[startAt, endAt]`. When no store is
|
|
11
|
-
* reachable, `billingRates` returns no rows
|
|
12
|
-
*
|
|
11
|
+
* reachable, `billingRates` returns no rows, and only DeepSeek and Z.AI get a
|
|
12
|
+
* row because no other provider publishes a peak schedule. `deepseekRate` and
|
|
13
|
+
* `zaiRate` still fall back to the published schedule below for a direct caller.
|
|
13
14
|
*
|
|
14
15
|
* Chinese public holidays are off-peak all day, but a holiday calendar is not
|
|
15
16
|
* shipped here, so a holiday weekday still reads `peak` inside a window.
|
|
@@ -227,7 +228,10 @@ export const deepseekRate = (now: Date, directory?: string): DeepseekRate =>
|
|
|
227
228
|
export const zaiRate = (now: Date, directory?: string): DeepseekRate =>
|
|
228
229
|
providerRate("Z.AI", now, directory)
|
|
229
230
|
|
|
230
|
-
/** Providers
|
|
231
|
+
/** Providers with a published peak schedule; anyone else would always read `off-peak`. */
|
|
232
|
+
const BILLING_PROVIDERS = new Set(["DeepSeek", "Z.AI"])
|
|
233
|
+
|
|
234
|
+
/** DeepSeek and Z.AI rows present in the models store, in name order. No store, no rows. */
|
|
231
235
|
export const billingRates = (at: Date, directory?: string): Array<{ label: string; rate: ProviderRate }> => {
|
|
232
236
|
const root = resolveModelsRoot(directory)
|
|
233
237
|
if (root === undefined) return []
|
|
@@ -235,7 +239,7 @@ export const billingRates = (at: Date, directory?: string): Array<{ label: strin
|
|
|
235
239
|
...new Set(
|
|
236
240
|
readRecords<CatalogProvider>(path.join(root, "providers"))
|
|
237
241
|
.map((provider) => provider?.name)
|
|
238
|
-
.filter((name): name is string => typeof name === "string" && name
|
|
242
|
+
.filter((name): name is string => typeof name === "string" && BILLING_PROVIDERS.has(name)),
|
|
239
243
|
),
|
|
240
244
|
].sort((left, right) => left.localeCompare(right))
|
|
241
245
|
return names.map((label) => ({ label, rate: providerRate(label, at, directory) }))
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "opencode",
|
|
4
4
|
"stack": "svelte",
|
|
5
5
|
"semanticSource": "cursor/svelte",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "645efc03569bae44b124b827b7a52c981820f26082bd5f6b011b135cdc5c42ef",
|
|
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
|
-
|
|
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 = 'svelte';
|
|
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
|
-
|
|
574
|
-
|
|
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": "zcode",
|
|
4
4
|
"stack": "android-kotlin",
|
|
5
5
|
"semanticSource": "cursor/android-kotlin",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "1613dbeb64ed50559fa5da1402ad01e6dbd876947e6f2bde0780dcf0873af636",
|
|
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
|
-
|
|
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 = 'android-kotlin';
|
|
199
210
|
const PLATFORM = 'zcode';
|
|
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
|
-
|
|
574
|
-
|
|
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": "zcode",
|
|
4
4
|
"stack": "go",
|
|
5
5
|
"semanticSource": "cursor/go",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "7d31d2ab9508e6de003a7f8b11c968e8ce1f04e3ffa37d8eb44d1c1f574365ac",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|