Skip to content

Commit 2edb436

Browse files
authored
chore(mothership): take the remaining contracts from the worker and drop the Go contract generators (#10264)
* chore(mothership): take the remaining contracts from the worker and drop the Go contract generators The Go copilot is being removed from the mothership repo. The eight contracts Sim generated from its JSON (stream, billing protocol, vfs snapshot, trace and metric names) are now worker-owned TypeScript copied in by the worker's contracts:sync, so the eight json2ts sync scripts and the mship:generate umbrella go. The base tool catalog moves to the worker's packages/contracts, and mship-tools:generate reads it there. * chore(mothership): point the pi sandbox note at the moved mothership sandbox * chore(mothership): drop the unused json2ts dependency and keep the ship note's catalog path a placeholder * fix(mothership): type the auto-model router call from the worker's model-router contract The worker now serves POST /api/model-router again (mothership D116); only the Go service did, so every sim-auto block has fallen back to its default model since the cutover. The resolver takes its request and response types from the synced contract instead of a hand-kept copy.
1 parent 1734687 commit 2edb436

27 files changed

Lines changed: 2623 additions & 3929 deletions

‎.agents/skills/ship/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ When the user runs `/ship`:
5959
```
6060
Then `git status --short` to see what regenerated — those files must be staged in step 7 alongside your own changes.
6161
62-
**Do NOT blanket-run the domain generators here.** `mship:generate` (`generate-mship-contracts.ts`) is an **umbrella** that drives all nine mothership contract generators (`mship-contracts`, `billing-protocol-contract`, `mship-tools`, the four `trace-*`, `metrics-contract`, `vfs-snapshot-contract`) and biome-formats `apps/sim/lib/mothership/generated/` — never run it *and* its constituents (they write the same files and corrupt each other in parallel), and never run it on an ordinary ship: it reads an **external** copilot-contract source that isn't checked out in most worktrees, so it hard-fails with `ENOENT` and would abort ship for an unrelated reason. `generate:pi-model-catalog` (under `apps/sim`) likewise regenerates from the installed Pi package, not repo source. `scripts/generate-docs.ts` rewrites the integration docs and client-safe catalog; run it when this PR changes their block/icon/landing-content inputs or when `check:integration-catalog` reports drift, then review its broad generated diff. Only when **this PR's diff actually touches** a domain generator's input do you regenerate it deliberately and run its matching `:check` (`bun run mship:check` / the individual `*:check`) — with the external source present.
62+
**Do NOT blanket-run the domain generators here.** `mship-tools:generate` merges Sim's tool contracts into the base tool catalog in the **external** Mothership worker checkout (`<mothership>/worker/packages/contracts/tool-catalog-v1.json`), which most worktrees lack, so it hard-fails with `ENOENT` and would abort ship for an unrelated reason. The other mothership contracts in `apps/sim/lib/mothership/generated/` are copied in by the worker's `contracts:sync`, never generated here. `generate:pi-model-catalog` (under `apps/sim`) likewise regenerates from the installed Pi package, not repo source. `scripts/generate-docs.ts` rewrites the integration docs and client-safe catalog; run it when this PR changes their block/icon/landing-content inputs or when `check:integration-catalog` reports drift, then review its broad generated diff. Only when **this PR's diff actually touches** a domain generator's input do you regenerate it deliberately and run its matching `:check` (e.g. `bun run mship-tools:check`) — with the external source present.
6363
6464
**Phase B — run lint + every audit CI enforces, in parallel, and abort ship if any fails.** Before running the commands, compare this list with `.github/workflows/checks.yml`; when CI adds an audit, run it and update this skill instead of trusting a stale snapshot. The env-flag audit is currently an inline workflow block rather than a package script: when `apps/sim/lib/core/config/env-flags.ts` changed, run that current workflow block verbatim instead of copying a second version into this skill. Run `bun run lint` first (it autofixes formatting and mutates files, so don't parallelize it with the read-only audits), then run the base-sensitive block-registry check, then fan the independent audits out and collect exit codes:
6565
```bash

‎apps/sim/lib/model-router/resolve.ts‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { createLogger } from '@sim/logger'
33
import { getErrorMessage } from '@sim/utils/errors'
44
import { env } from '@/lib/core/config/env'
55
import { getCostMultiplier, isHosted } from '@/lib/core/config/env-flags'
6+
import type {
7+
ModelRouterRequest,
8+
ModelRouterResponse,
9+
ModelRouterUsage,
10+
} from '@/lib/mothership/generated/model-router'
611
import { fetchGo } from '@/lib/mothership/request/go/fetch'
712
import { getMothershipBaseURL } from '@/lib/mothership/server/agent-url'
813
import { validateModelProvider } from '@/ee/access-control/utils/permission-check'
@@ -100,22 +105,6 @@ export interface AutoRoutingSignals {
100105
approxInputTokens: number
101106
}
102107

103-
/** Mirrors mothership's model-router-v1 response usage block. */
104-
interface ModelRouterUsage {
105-
model: string
106-
inputTokens: number
107-
cachedInputTokens: number
108-
outputTokens: number
109-
cost: number
110-
}
111-
112-
interface ModelRouterResponse {
113-
choice?: string
114-
decidedBy?: string
115-
usage?: ModelRouterUsage
116-
billable?: boolean
117-
}
118-
119108
export interface AutoRoutingResult {
120109
model: string
121110
tier: AutoTierId | null
@@ -219,7 +208,7 @@ async function callModelRouter(
219208
signals: AutoRoutingSignals,
220209
ctx: ExecutionContext,
221210
blockId: string
222-
): Promise<ModelRouterResponse | null> {
211+
): Promise<Partial<ModelRouterResponse> | null> {
223212
const baseURL = await getMothershipBaseURL({ userId: ctx.userId ?? '' })
224213

225214
const res = await fetchGo(`${baseURL}/api/model-router`, {
@@ -244,7 +233,7 @@ async function callModelRouter(
244233
workflowId: ctx.workflowId,
245234
blockId,
246235
executionId: ctx.executionId,
247-
}),
236+
} satisfies ModelRouterRequest),
248237
signal: AbortSignal.timeout(MODEL_ROUTER_TIMEOUT_MS),
249238
spanName: 'sim → go /api/model-router',
250239
operation: 'model_router',
@@ -254,7 +243,7 @@ async function callModelRouter(
254243
logger.warn('Model router returned non-OK status', { status: res.status })
255244
return null
256245
}
257-
return (await res.json().catch(() => null)) as ModelRouterResponse | null
246+
return (await res.json().catch(() => null)) as Partial<ModelRouterResponse> | null
258247
}
259248

260249
/**
Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,75 @@
1-
/**
2-
* AUTO-GENERATED FILE. DO NOT EDIT.
3-
*
4-
* Source: copilot/copilot/contracts/billing-protocol-v1.schema.json
5-
* Regenerate with: bun run billing-protocol-contract:generate
6-
*/
1+
// GENERATED — do not edit. Source of truth: mothership worker packages/contracts/src/billing-protocol-v1.ts
2+
// Regenerate with `bun run contracts:sync` in the worker.
3+
4+
// The trusted Sim-to-worker billing protocol: header names, protocol modes, bounds, safe
5+
// API-key denials, and callback and analytics outcomes.
76

87
export const BILLING_PROTOCOL_HEADERS = {
9-
accountDecision: 'x-sim-billing-account-decision',
10-
attribution: 'x-sim-billing-attribution',
11-
protocol: 'x-sim-billing-protocol',
12-
requestId: 'x-sim-billing-request-id',
13-
} as const
8+
accountDecision: "x-sim-billing-account-decision",
9+
attribution: "x-sim-billing-attribution",
10+
protocol: "x-sim-billing-protocol",
11+
requestId: "x-sim-billing-request-id",
12+
} as const;
1413

15-
export const BILLING_ACCOUNT_DECISION_HEADER = BILLING_PROTOCOL_HEADERS.accountDecision
16-
export const BILLING_ATTRIBUTION_HEADER = BILLING_PROTOCOL_HEADERS.attribution
17-
export const COPILOT_BILLING_PROTOCOL_HEADER = BILLING_PROTOCOL_HEADERS.protocol
18-
export const BILLING_REQUEST_ID_HEADER = BILLING_PROTOCOL_HEADERS.requestId
14+
export const BILLING_ACCOUNT_DECISION_HEADER = BILLING_PROTOCOL_HEADERS.accountDecision;
15+
export const BILLING_ATTRIBUTION_HEADER = BILLING_PROTOCOL_HEADERS.attribution;
16+
export const COPILOT_BILLING_PROTOCOL_HEADER = BILLING_PROTOCOL_HEADERS.protocol;
17+
export const BILLING_REQUEST_ID_HEADER = BILLING_PROTOCOL_HEADERS.requestId;
1918

2019
export const COPILOT_BILLING_PROTOCOL = {
21-
attributed: 'attribution-v1',
22-
direct: 'direct-v1',
23-
legacy: 'legacy-v0',
24-
} as const
20+
attributed: "attribution-v1",
21+
direct: "direct-v1",
22+
legacy: "legacy-v0",
23+
} as const;
2524

26-
export type CopilotBillingProtocol =
27-
(typeof COPILOT_BILLING_PROTOCOL)[keyof typeof COPILOT_BILLING_PROTOCOL]
25+
export type CopilotBillingProtocol = (typeof COPILOT_BILLING_PROTOCOL)[keyof typeof COPILOT_BILLING_PROTOCOL];
2826

2927
export const COPILOT_BILLING_PROTOCOL_VALUES = [
3028
COPILOT_BILLING_PROTOCOL.attributed,
3129
COPILOT_BILLING_PROTOCOL.direct,
3230
COPILOT_BILLING_PROTOCOL.legacy,
33-
] as const
31+
] as const;
3432

3533
export const COPILOT_VALIDATION_PURPOSE = {
36-
newTurn: 'new-turn',
37-
continuation: 'continuation',
38-
cancellation: 'cancellation',
39-
} as const
34+
newTurn: "new-turn",
35+
continuation: "continuation",
36+
cancellation: "cancellation",
37+
} as const;
4038

41-
export const COPILOT_VALIDATION_PURPOSE_VALUES = [
42-
'new-turn',
43-
'continuation',
44-
'cancellation',
45-
] as const
39+
export const COPILOT_VALIDATION_PURPOSE_VALUES = ["new-turn", "continuation", "cancellation"] as const;
4640

47-
export type CopilotValidationPurpose = (typeof COPILOT_VALIDATION_PURPOSE_VALUES)[number]
41+
export type CopilotValidationPurpose = (typeof COPILOT_VALIDATION_PURPOSE_VALUES)[number];
4842

49-
export const BILLING_ATTRIBUTION_HEADER_MAX_BYTES = 8192
50-
export const BILLING_ACCOUNT_DECISION_HEADER_MAX_BYTES = 2048
43+
export const BILLING_ATTRIBUTION_HEADER_MAX_BYTES = 8192;
44+
export const BILLING_ACCOUNT_DECISION_HEADER_MAX_BYTES = 2048;
5145

5246
export const BILLING_CALLBACK_OUTCOME = {
5347
billingContextMismatch: {
54-
code: 'BILLING_CONTEXT_MISMATCH',
55-
message: 'Idempotency key is already bound to a different billing context',
48+
code: "BILLING_CONTEXT_MISMATCH",
49+
message: "Idempotency key is already bound to a different billing context",
5650
},
5751
billingPeriodElapsed: {
58-
code: 'BILLING_PERIOD_ELAPSED',
59-
message: 'Billing period has elapsed; reconciliation required',
52+
code: "BILLING_PERIOD_ELAPSED",
53+
message: "Billing period has elapsed; reconciliation required",
6054
},
6155
billingUserNotFound: {
62-
code: 'BILLING_USER_NOT_FOUND',
63-
message: 'Billing user no longer exists; reconciliation required',
56+
code: "BILLING_USER_NOT_FOUND",
57+
message: "Billing user no longer exists; reconciliation required",
6458
},
6559
duplicateBillingEvent: {
66-
code: 'DUPLICATE_BILLING_EVENT',
67-
message: 'Duplicate request: cumulative cost already recorded',
60+
code: "DUPLICATE_BILLING_EVENT",
61+
message: "Duplicate request: cumulative cost already recorded",
6862
},
69-
} as const
63+
} as const;
7064

7165
export const BillingAnalyticsOutcome = {
72-
DeadLettered: 'dead_lettered',
73-
Duplicate: 'duplicate',
74-
NotBillable: 'not_billable',
75-
RetriesExhausted: 'retries_exhausted',
76-
Success: 'success',
77-
Unknown: 'unknown',
78-
} as const
66+
DeadLettered: "dead_lettered",
67+
Duplicate: "duplicate",
68+
NotBillable: "not_billable",
69+
RetriesExhausted: "retries_exhausted",
70+
Success: "success",
71+
Unknown: "unknown",
72+
} as const;
7973

8074
export type BillingAnalyticsOutcomeValue =
81-
(typeof BillingAnalyticsOutcome)[keyof typeof BillingAnalyticsOutcome]
75+
(typeof BillingAnalyticsOutcome)[keyof typeof BillingAnalyticsOutcome];
Lines changed: 61 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,67 @@
1-
// AUTO-GENERATED FILE. DO NOT EDIT.
2-
//
3-
// Source: copilot/copilot/contracts/metrics-v1.schema.json
4-
// Regenerate with: bun run metrics-contract:generate
5-
//
6-
// Canonical mothership OTel metric names. Call sites should reference
7-
// `Metric.<Identifier>` (e.g. `Metric.CopilotToolDuration`) rather than raw
8-
// string literals, so the Go-side contract is the single source of truth and
9-
// typos become compile errors.
10-
//
11-
// NAMES ONLY. Label keys and histogram bucket boundaries are NOT in this
12-
// contract — Go owns the label-cardinality allowlist and the shared bucket
13-
// constant, and the Sim emitter MUST mirror those by hand so the Go∪Sim metric
14-
// union is queryable as one series set.
1+
// GENERATED — do not edit. Source of truth: mothership worker packages/contracts/src/metrics-v1.ts
2+
// Regenerate with `bun run contracts:sync` in the worker.
3+
4+
// Canonical mothership OTel metric names Sim emits. Names only: label keys and histogram
5+
// buckets are the emitter's.
156

167
export const Metric = {
17-
CopilotBillingLongContextCount: 'copilot.billing.long_context.count',
18-
CopilotCacheAttempted: 'copilot.cache.attempted',
19-
CopilotCacheHit: 'copilot.cache.hit',
20-
CopilotCacheWrite: 'copilot.cache.write',
21-
CopilotChatBlobBytes: 'copilot.chat.blob.bytes',
22-
CopilotChatBlobCount: 'copilot.chat.blob.count',
23-
CopilotDegradedCount: 'copilot.degraded.count',
24-
CopilotFileReadDuration: 'copilot.file.read.duration',
25-
CopilotFileReadSize: 'copilot.file.read.size',
26-
CopilotMessagesSerializeDuration: 'copilot.messages.serialize.duration',
27-
CopilotOptionsEmittedCount: 'copilot.options.emitted.count',
28-
CopilotPromptComponentChars: 'copilot.prompt.component.chars',
29-
CopilotRequestCount: 'copilot.request.count',
30-
CopilotRequestDuration: 'copilot.request.duration',
31-
CopilotToolCalls: 'copilot.tool.calls',
32-
CopilotToolDuration: 'copilot.tool.duration',
33-
CopilotVfsDelta: 'copilot.vfs.delta',
34-
CopilotVfsMaterializeDuration: 'copilot.vfs.materialize.duration',
35-
GenAiClientCacheTokenUsage: 'gen_ai.client.cache.token.usage',
36-
GenAiClientTokenUsage: 'gen_ai.client.token.usage',
37-
LlmClientCompactions: 'llm.client.compactions',
38-
LlmClientContextTokens: 'llm.client.context_tokens',
39-
LlmClientErrors: 'llm.client.errors',
40-
LlmClientOutputCutoff: 'llm.client.output_cutoff',
41-
LlmClientStreamDuration: 'llm.client.stream.duration',
42-
LlmClientTimeToFirstToken: 'llm.client.time_to_first_token',
43-
} as const
8+
CopilotBillingLongContextCount: "copilot.billing.long_context.count",
9+
CopilotCacheAttempted: "copilot.cache.attempted",
10+
CopilotCacheHit: "copilot.cache.hit",
11+
CopilotCacheWrite: "copilot.cache.write",
12+
CopilotChatBlobBytes: "copilot.chat.blob.bytes",
13+
CopilotChatBlobCount: "copilot.chat.blob.count",
14+
CopilotDegradedCount: "copilot.degraded.count",
15+
CopilotFileReadDuration: "copilot.file.read.duration",
16+
CopilotFileReadSize: "copilot.file.read.size",
17+
CopilotMessagesSerializeDuration: "copilot.messages.serialize.duration",
18+
CopilotOptionsEmittedCount: "copilot.options.emitted.count",
19+
CopilotPromptComponentChars: "copilot.prompt.component.chars",
20+
CopilotRequestCount: "copilot.request.count",
21+
CopilotRequestDuration: "copilot.request.duration",
22+
CopilotToolCalls: "copilot.tool.calls",
23+
CopilotToolDuration: "copilot.tool.duration",
24+
CopilotVfsDelta: "copilot.vfs.delta",
25+
CopilotVfsMaterializeDuration: "copilot.vfs.materialize.duration",
26+
GenAiClientCacheTokenUsage: "gen_ai.client.cache.token.usage",
27+
GenAiClientTokenUsage: "gen_ai.client.token.usage",
28+
LlmClientCompactions: "llm.client.compactions",
29+
LlmClientContextTokens: "llm.client.context_tokens",
30+
LlmClientErrors: "llm.client.errors",
31+
LlmClientOutputCutoff: "llm.client.output_cutoff",
32+
LlmClientStreamDuration: "llm.client.stream.duration",
33+
LlmClientTimeToFirstToken: "llm.client.time_to_first_token",
34+
} as const;
4435

45-
export type MetricKey = keyof typeof Metric
46-
export type MetricValue = (typeof Metric)[MetricKey]
36+
export type MetricKey = keyof typeof Metric;
37+
export type MetricValue = (typeof Metric)[MetricKey];
4738

4839
/** Readonly sorted list of every canonical mothership metric name. */
4940
export const MetricValues: readonly MetricValue[] = [
50-
'copilot.billing.long_context.count',
51-
'copilot.cache.attempted',
52-
'copilot.cache.hit',
53-
'copilot.cache.write',
54-
'copilot.chat.blob.bytes',
55-
'copilot.chat.blob.count',
56-
'copilot.degraded.count',
57-
'copilot.file.read.duration',
58-
'copilot.file.read.size',
59-
'copilot.messages.serialize.duration',
60-
'copilot.options.emitted.count',
61-
'copilot.prompt.component.chars',
62-
'copilot.request.count',
63-
'copilot.request.duration',
64-
'copilot.tool.calls',
65-
'copilot.tool.duration',
66-
'copilot.vfs.delta',
67-
'copilot.vfs.materialize.duration',
68-
'gen_ai.client.cache.token.usage',
69-
'gen_ai.client.token.usage',
70-
'llm.client.compactions',
71-
'llm.client.context_tokens',
72-
'llm.client.errors',
73-
'llm.client.output_cutoff',
74-
'llm.client.stream.duration',
75-
'llm.client.time_to_first_token',
76-
] as const
41+
"copilot.billing.long_context.count",
42+
"copilot.cache.attempted",
43+
"copilot.cache.hit",
44+
"copilot.cache.write",
45+
"copilot.chat.blob.bytes",
46+
"copilot.chat.blob.count",
47+
"copilot.degraded.count",
48+
"copilot.file.read.duration",
49+
"copilot.file.read.size",
50+
"copilot.messages.serialize.duration",
51+
"copilot.options.emitted.count",
52+
"copilot.prompt.component.chars",
53+
"copilot.request.count",
54+
"copilot.request.duration",
55+
"copilot.tool.calls",
56+
"copilot.tool.duration",
57+
"copilot.vfs.delta",
58+
"copilot.vfs.materialize.duration",
59+
"gen_ai.client.cache.token.usage",
60+
"gen_ai.client.token.usage",
61+
"llm.client.compactions",
62+
"llm.client.context_tokens",
63+
"llm.client.errors",
64+
"llm.client.output_cutoff",
65+
"llm.client.stream.duration",
66+
"llm.client.time_to_first_token",
67+
] as const;

0 commit comments

Comments
 (0)