@jagreehal/shepherd 0.16.0 → 0.17.0
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/gate/.shepherd/gate.schema.json +11 -1
- package/gate/.shepherd/gate.yml +4 -3
- package/gate/src/cli.ts +20 -2
- package/gate/src/eval.ts +5 -1
- package/gate/src/llm.ts +48 -7
- package/gate/src/policy.ts +21 -5
- package/gate/src/prices.ts +62 -0
- package/gate/templates/policy-strict.yml +4 -3
- package/gate/templates/shepherd-gate.yml +1 -1
- package/package.json +4 -4
- package/src/cli.ts +9 -8
|
@@ -483,7 +483,7 @@
|
|
|
483
483
|
}
|
|
484
484
|
},
|
|
485
485
|
"pricing": {
|
|
486
|
-
"description": "Prices per million tokens for
|
|
486
|
+
"description": "Prices per million tokens for each model you use. Shepherd ships no prices: without one, the $ budget is inactive and costs show as unpriced.",
|
|
487
487
|
"type": "object",
|
|
488
488
|
"propertyNames": {
|
|
489
489
|
"type": "string"
|
|
@@ -499,6 +499,16 @@
|
|
|
499
499
|
},
|
|
500
500
|
"cachedInputPer1M": {
|
|
501
501
|
"type": "number"
|
|
502
|
+
},
|
|
503
|
+
"as_of": {
|
|
504
|
+
"description": "The date you read these prices (YYYY-MM-DD), so a stale price is visible.",
|
|
505
|
+
"type": "string",
|
|
506
|
+
"format": "date",
|
|
507
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
|
|
508
|
+
},
|
|
509
|
+
"source": {
|
|
510
|
+
"description": "Where the prices came from: a price page, a contract, a region.",
|
|
511
|
+
"type": "string"
|
|
502
512
|
}
|
|
503
513
|
},
|
|
504
514
|
"required": [
|
package/gate/.shepherd/gate.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# yaml-language-server: $schema=https://unpkg.com/@jagreehal/shepherd@0.
|
|
1
|
+
# yaml-language-server: $schema=https://unpkg.com/@jagreehal/shepherd@0.17.0/gate/.shepherd/gate.schema.json
|
|
2
2
|
# gate merge-gate policy.
|
|
3
3
|
#
|
|
4
4
|
# Read from the repository's DEFAULT BRANCH, never from the PR head, so a PR
|
|
@@ -8,11 +8,12 @@ version: 1
|
|
|
8
8
|
|
|
9
9
|
# Settings. Each is optional. SHEPHERD_MODEL overrides `model`; `shepherd gate config` shows every value in effect
|
|
10
10
|
# and where it came from.
|
|
11
|
-
# Secrets never go here. Without a price for the model, the $ budget cannot fire ("budget guard inactive")
|
|
11
|
+
# Secrets never go here. Without a price for the model, the $ budget cannot fire ("budget guard inactive"); gate init
|
|
12
|
+
# writes the model's list price from models.dev, dated, for you to check against your region or contract.
|
|
12
13
|
# model: bedrock/minimax.minimax-m2.5
|
|
13
14
|
# backends: [api, bedrock:openai.gpt-oss-120b-1:0] # primary, then a second opinion
|
|
14
15
|
# pricing:
|
|
15
|
-
#
|
|
16
|
+
# openai.gpt-oss-120b: { inputPer1M: 0.18, outputPer1M: 0.70, as_of: 2026-11-14, source: aws.amazon.com/bedrock/pricing eu-west-1 }
|
|
16
17
|
# provider: { region: eu-west-1 } # also base_url (openai-compatible/) and anthropic_base_url
|
|
17
18
|
# guard: { budget_usd: 2, tokens: 3m, loop: 4/12, max_tools: 80, timeout: 15m }
|
|
18
19
|
# max_output_tokens: 16000
|
package/gate/src/cli.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { appendFileSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readd
|
|
|
12
12
|
import { tmpdir } from "node:os";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
import { parseArgs, type ParseArgsConfig } from "node:util";
|
|
15
|
+
import { parse as parseYaml } from "yaml";
|
|
15
16
|
import { z } from "zod";
|
|
16
17
|
import { notify, notifyOn } from "./notify.ts";
|
|
17
18
|
import { computeFamiliarity, ensureFullHistory, familiarityEvidence, type AuthorFamiliarity } from "./familiarity.ts";
|
|
@@ -54,6 +55,7 @@ import { incrementalDiff } from "./delta.ts";
|
|
|
54
55
|
import { anchoredIssues } from "./inline.ts";
|
|
55
56
|
import { leadsAt } from "./leads.ts";
|
|
56
57
|
import { explainFailure, failureText } from "./provider-errors.ts";
|
|
58
|
+
import { catalogPrice } from "./prices.ts";
|
|
57
59
|
import { beginReviewSpan, endReviewSpan, inReviewSpan, keyEnvFor, keySource, parseModelId, reviewMeasurements, summarizeRun, type ReviewAttributes } from "./llm.ts";
|
|
58
60
|
import { configSummary, effectiveConfig, setting, useSettings, type Settings } from "./config.ts";
|
|
59
61
|
import { egressRefusals } from "./isolated-cli.ts";
|
|
@@ -138,6 +140,9 @@ if (process.argv[2] === "config") {
|
|
|
138
140
|
process.exit(process.exitCode ?? 0);
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
/** The one field setup reads from a gate policy already in the working tree. */
|
|
144
|
+
const PolicyModel = z.object({ model: z.string().optional() }).loose();
|
|
145
|
+
|
|
141
146
|
const { values: opts, positionals } = args({
|
|
142
147
|
allowPositionals: true,
|
|
143
148
|
options: {
|
|
@@ -161,6 +166,16 @@ const repoRoot = execFileSync("git", ["rev-parse", "--show-toplevel"], { encodin
|
|
|
161
166
|
const git = (...args: string[]) => execFileSync("git", ["-C", repoRoot, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: callTimeout() }).trim();
|
|
162
167
|
|
|
163
168
|
if (positionals[0] === "init") {
|
|
169
|
+
// Setup, not review: the working tree names the key, since the default branch has not seen it yet. Same order as a
|
|
170
|
+
// review, after --model: SHEPHERD_MODEL, then the gate policy's `model:`, then the loop's models.loop, then the default.
|
|
171
|
+
const local = (rel: string) => (existsSync(path.join(repoRoot, rel)) ? readFileSync(path.join(repoRoot, rel), "utf8") : null);
|
|
172
|
+
const policyModel = PolicyModel.safeParse(parseYaml(local(".shepherd/gate.yml") ?? "") ?? {}).data?.model;
|
|
173
|
+
// SAFETY: shepherdModel reads only `model` and `policyFiles` from the policy, and both are optional.
|
|
174
|
+
const model = opts.model ?? (process.env.SHEPHERD_MODEL?.trim() || undefined) ?? policyModel ?? shepherdModel({} as Policy, local).model ?? setting("model");
|
|
175
|
+
// A new policy gets today's list price for that model, dated, so the $ budget works from the first review.
|
|
176
|
+
const policyExists = existsSync(path.join(repoRoot, ".shepherd/gate.yml"));
|
|
177
|
+
const priced = policyExists ? null : await catalogPrice(model);
|
|
178
|
+
|
|
164
179
|
// Existing files are kept: the repo's policy is the repo's. --upgrade rewrites the workflows only, from this
|
|
165
180
|
// gate's templates, keeping the environment, OIDC and region each was written with unless a flag changes one.
|
|
166
181
|
for (const rel of [".shepherd/gate.yml", ".shepherd/review-guidance.md", ".github/workflows/shepherd-gate.yml", ".github/workflows/shepherd-gate-edited.yml", ".github/workflows/shepherd-gate-actions.yml"]) {
|
|
@@ -187,15 +202,18 @@ if (positionals[0] === "init") {
|
|
|
187
202
|
mkdirSync(path.dirname(dest), { recursive: true });
|
|
188
203
|
|
|
189
204
|
if (rel.startsWith(".github")) writeFileSync(dest, installWorkflow(readFileSync(src, "utf8"), { awsOidc: opts["aws-oidc"], environment: ownJob ? opts.environment : undefined, region: opts.region }));
|
|
190
|
-
else if (rel === ".shepherd/gate.yml") writeFileSync(dest, policyWithSettings(readFileSync(opts.strict ? path.join(DEFAULTS_DIR, "templates/policy-strict.yml") : src, "utf8"), { model: opts.model, region: opts.region }));
|
|
205
|
+
else if (rel === ".shepherd/gate.yml") writeFileSync(dest, policyWithSettings(readFileSync(opts.strict ? path.join(DEFAULTS_DIR, "templates/policy-strict.yml") : src, "utf8"), { model: opts.model, region: opts.region, pricing: priced ? { [priced.key]: priced.price } : undefined }));
|
|
191
206
|
else copyFileSync(src, dest);
|
|
192
207
|
console.log(`created ${rel}`);
|
|
193
208
|
}
|
|
194
209
|
|
|
195
|
-
const key = opts["aws-oidc"] ? "nothing: under OIDC set the AWS_ROLE_ARN variable instead, naming a role that can invoke Bedrock" : `your provider key as the ${keyEnvFor(
|
|
210
|
+
const key = opts["aws-oidc"] ? "nothing: under OIDC set the AWS_ROLE_ARN variable instead, naming a role that can invoke Bedrock" : `your provider key as the ${keyEnvFor(model)} secret`;
|
|
196
211
|
|
|
197
212
|
console.log(`\nNext: add ${key}, enable 'Allow GitHub Actions to create and approve pull requests', and merge. The model is SHEPHERD_MODEL, else \`model:\` in .shepherd/gate.yml, else the loop's models.loop; every other setting lives in .shepherd/gate.yml. Run \`shepherd gate config\` to see what is in effect.`);
|
|
198
213
|
|
|
214
|
+
if (priced) console.log(`Priced ${priced.key} at $${priced.price.inputPer1M} in / $${priced.price.outputPer1M} out per 1M tokens (${priced.price.source}, ${priced.price.as_of}) in .shepherd/gate.yml: edit it to your region's or contract's rate.`);
|
|
215
|
+
else if (!policyExists) console.log(`No list price found for ${model}: add one under pricing: in .shepherd/gate.yml (with as_of and source), or the $ budget stays inactive and only the token ceiling applies.`);
|
|
216
|
+
|
|
199
217
|
if (opts.environment) console.log(`The review job runs in the "${opts.environment}" environment: create it (no protection rules) and put the model key there as an environment secret, not repository secrets.`);
|
|
200
218
|
console.log(`\nThe gate reads its policy from the default branch, so whoever can merge there decides what it approves. Suggested .github/CODEOWNERS entries (replace @your-team):\n\n/.shepherd/ @your-team\n/.github/ @your-team\n\nThen turn on "Require review from Code Owners" for the default branch.\n`);
|
|
201
219
|
console.log("Optional alerts: add the SHEPHERD_NOTIFY_WEBHOOK secret (Slack or any JSON endpoint) for refused, escalated and failed reviews.");
|
package/gate/src/eval.ts
CHANGED
|
@@ -50,6 +50,10 @@ export const Run = z.object({
|
|
|
50
50
|
issues: z.array(z.string()),
|
|
51
51
|
costUsd: z.number().nullable(),
|
|
52
52
|
durationMs: z.number(),
|
|
53
|
+
/** Tokens and tool calls, so a model without a price in the policy can be priced from its published rates. */
|
|
54
|
+
inputTokens: z.number().optional(),
|
|
55
|
+
outputTokens: z.number().optional(),
|
|
56
|
+
toolCalls: z.number().optional(),
|
|
53
57
|
error: z.string().optional(),
|
|
54
58
|
});
|
|
55
59
|
|
|
@@ -174,7 +178,7 @@ export async function runCase(name: string, c: Case, backend: Backend, label: st
|
|
|
174
178
|
const llm = await review(backend, input, guidance, dir);
|
|
175
179
|
const outcome = readAll(assured({ verdict: llm.verdict, llm }), diffCut(diff), [llm]);
|
|
176
180
|
|
|
177
|
-
return { case: name, label, verdict: outcome.verdict, model_verdict: llm.verdict, issues: outcome.llm.issues, costUsd: llm.run?.costUsd ?? null, durationMs: Date.now() - started };
|
|
181
|
+
return { case: name, label, verdict: outcome.verdict, model_verdict: llm.verdict, issues: outcome.llm.issues, costUsd: llm.run?.costUsd ?? null, durationMs: Date.now() - started, inputTokens: llm.run?.inputTokens, outputTokens: llm.run?.outputTokens, toolCalls: llm.run?.toolCalls };
|
|
178
182
|
} catch (e) {
|
|
179
183
|
return { case: name, label, verdict: null, issues: [], costUsd: null, durationMs: Date.now() - started, error: String(e instanceof Error ? e.message : e).split("\n")[0] };
|
|
180
184
|
} finally {
|
package/gate/src/llm.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { createMistral } from "@ai-sdk/mistral";
|
|
|
11
11
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
12
12
|
import { createGateway, gateway, generateText, stepCountIs, tool, ToolChoiceViolationError, type LanguageModel, type ModelMessage, type StepResult, type ToolSet } from "ai";
|
|
13
13
|
import type { runWithSpan, Span, SpanStatusCode } from "autotel";
|
|
14
|
-
import { BEDROCK_PRICING } from "autotel-bedrock";
|
|
15
14
|
import { estimateLLMCost, registerModelPricing } from "autotel-genai/cost";
|
|
16
15
|
import { createGenAiGuard, parseGuardRules } from "autotel-genai/guard";
|
|
17
16
|
import { execFileSync } from "node:child_process";
|
|
@@ -25,10 +24,46 @@ import { Effort, Pricing } from "./policy.ts";
|
|
|
25
24
|
|
|
26
25
|
export { PROVIDER_ENV } from "./env.ts";
|
|
27
26
|
|
|
28
|
-
registerModelPricing(BEDROCK_PRICING);
|
|
29
|
-
|
|
30
27
|
let pricingLoadedFor: string | undefined;
|
|
31
28
|
|
|
29
|
+
/** The current policy's prices. A review is priced from these alone, even after an earlier policy registered others. */
|
|
30
|
+
let policyPricing: z.infer<typeof Pricing> = {};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A vendor or region prefix peeled off a model id, as the cost library peels it: everything up to the last `/`
|
|
34
|
+
* (`moonshotai/kimi-k3`), else up to the first `.` unless that segment holds a digit (`gpt-4.1-mini` is no prefix).
|
|
35
|
+
*/
|
|
36
|
+
function withoutPrefix(id: string): string | undefined {
|
|
37
|
+
const slash = id.lastIndexOf("/");
|
|
38
|
+
|
|
39
|
+
if (slash !== -1) return id.slice(slash + 1);
|
|
40
|
+
|
|
41
|
+
const dot = id.indexOf(".");
|
|
42
|
+
const head = id.slice(0, dot);
|
|
43
|
+
|
|
44
|
+
return dot <= 0 || /\d/.test(head) ? undefined : id.slice(dot + 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The policy's price for a model id, resolved the way the cost library resolves ids: exact, then the longest key
|
|
49
|
+
* the id starts with, tried again after each vendor or region prefix is peeled (`eu.openai.gpt-oss-120b-1:0`
|
|
50
|
+
* reaches `openai.gpt-oss-120b`, `moonshotai/kimi-k3` reaches `kimi-k3`). Undefined when the policy has none, so a
|
|
51
|
+
* model nobody priced stays unpriced.
|
|
52
|
+
*/
|
|
53
|
+
export function policyPrice(model: string): z.infer<typeof Pricing>[string] | undefined {
|
|
54
|
+
for (let id: string | undefined = model; id !== undefined; id = withoutPrefix(id)) {
|
|
55
|
+
if (policyPricing[id]) return policyPricing[id];
|
|
56
|
+
|
|
57
|
+
const key = Object.keys(policyPricing)
|
|
58
|
+
.filter((k) => id?.startsWith(k))
|
|
59
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
60
|
+
|
|
61
|
+
if (key) return policyPricing[key];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
32
67
|
/**
|
|
33
68
|
* Register the `pricing` setting (the policy's) at review time: a malformed value fails
|
|
34
69
|
* that review as ERROR, never the CLI's startup or its retraction of a stale approval.
|
|
@@ -38,6 +73,8 @@ function loadPricing(): void {
|
|
|
38
73
|
|
|
39
74
|
if (pricingLoadedFor === raw) return;
|
|
40
75
|
|
|
76
|
+
policyPricing = {};
|
|
77
|
+
|
|
41
78
|
if (raw) {
|
|
42
79
|
let json: unknown;
|
|
43
80
|
|
|
@@ -50,7 +87,9 @@ function loadPricing(): void {
|
|
|
50
87
|
const parsed = Pricing.safeParse(json);
|
|
51
88
|
|
|
52
89
|
if (!parsed.success) throw new Error(`pricing: ${parsed.error.issues.map((i) => `${i.path.join(".")} ${i.message}`).join("; ")}`);
|
|
53
|
-
|
|
90
|
+
policyPricing = parsed.data;
|
|
91
|
+
// Telemetry prices spans from these too, and records each price's date as gen_ai.usage.cost.price_as_of.
|
|
92
|
+
registerModelPricing(Object.fromEntries(Object.entries(parsed.data).map(([model, { as_of, ...price }]) => [model, { ...price, asOf: as_of }])));
|
|
54
93
|
}
|
|
55
94
|
|
|
56
95
|
pricingLoadedFor = raw;
|
|
@@ -410,7 +449,8 @@ export async function reviewWithTools<T>(o: Options<T>): Promise<ToolReview<T>>
|
|
|
410
449
|
const { model: pricedAs } = parseModelId(o.modelId);
|
|
411
450
|
const model = o.model ?? languageModel(o.modelId, o.session);
|
|
412
451
|
const rules = o.guard ?? setting("guard");
|
|
413
|
-
const
|
|
452
|
+
const price = policyPrice(pricedAs);
|
|
453
|
+
const priced = price !== undefined;
|
|
414
454
|
|
|
415
455
|
if (!priced && (rule(rules, "budget") || rule(rules, "cost"))) console.error(`budget guard inactive: no price for ${o.modelId}; set pricing in the policy (the token ceiling still holds)`);
|
|
416
456
|
const limits = guardRules(rules, priced);
|
|
@@ -451,7 +491,8 @@ export async function reviewWithTools<T>(o: Options<T>): Promise<ToolReview<T>>
|
|
|
451
491
|
|
|
452
492
|
const onStepFinish = (step: StepResult<typeof tools>) => {
|
|
453
493
|
const usage = { inputTokens: step.usage.inputTokens ?? 0, outputTokens: step.usage.outputTokens ?? 0, cacheReadInputTokens: step.usage.inputTokenDetails.cacheReadTokens ?? 0 };
|
|
454
|
-
|
|
494
|
+
// Under the exact id, so this policy's price applies rather than one an earlier policy registered.
|
|
495
|
+
const cost = price && estimateLLMCost(pricedAs, usage, { pricing: { [pricedAs]: price } });
|
|
455
496
|
run.steps += 1;
|
|
456
497
|
run.inputTokens += usage.inputTokens;
|
|
457
498
|
run.outputTokens += usage.outputTokens;
|
|
@@ -541,7 +582,7 @@ export async function startTelemetry(): Promise<void> {
|
|
|
541
582
|
telemetry ??= (async () => {
|
|
542
583
|
const [{ init, shutdown }, { registerTelemetry }, { autotelTelemetry }, { bedrockProviderAttributes }] = await Promise.all([import("autotel"), import("ai"), import("autotel-genai/observer"), import("autotel-bedrock")]);
|
|
543
584
|
init({ service: setting("telemetry_service") });
|
|
544
|
-
registerTelemetry(autotelTelemetry({
|
|
585
|
+
registerTelemetry(autotelTelemetry({ providerAttributes: bedrockProviderAttributes }));
|
|
545
586
|
|
|
546
587
|
return { shutdown };
|
|
547
588
|
})();
|
package/gate/src/policy.ts
CHANGED
|
@@ -73,8 +73,19 @@ export function brand(b: z.infer<typeof Branding> | undefined) {
|
|
|
73
73
|
return { ...glyphs, heading: (verdict: "APPROVED" | "REFUSED" | "ESCALATE" | "ERROR") => `## ${avatar}${glyphs[verdict]} ${escapeText(name)}: ${verdict}` };
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/** Prices per million tokens
|
|
77
|
-
export const Pricing = z.record(
|
|
76
|
+
/** Prices per million tokens by model, dated: `{"kimi-k3":{"inputPer1M":3,"outputPer1M":15,"as_of":"2026-11-15"}}`. */
|
|
77
|
+
export const Pricing = z.record(
|
|
78
|
+
z.string(),
|
|
79
|
+
z
|
|
80
|
+
.object({
|
|
81
|
+
inputPer1M: z.number(),
|
|
82
|
+
outputPer1M: z.number(),
|
|
83
|
+
cachedInputPer1M: z.number().optional(),
|
|
84
|
+
as_of: z.iso.date().optional().describe("The date you read these prices (YYYY-MM-DD), so a stale price is visible."),
|
|
85
|
+
source: z.string().optional().describe("Where the prices came from: a price page, a contract, a region."),
|
|
86
|
+
})
|
|
87
|
+
.strict(),
|
|
88
|
+
);
|
|
78
89
|
|
|
79
90
|
export const Effort = z.enum(["low", "medium", "high"]);
|
|
80
91
|
|
|
@@ -110,7 +121,7 @@ export const PolicySchema = z
|
|
|
110
121
|
// variable overrides each one (config.ts, `gate config`). Secrets are never here.
|
|
111
122
|
model: z.string().min(1).optional().describe("The reviewer model, provider/model. Overridden by SHEPHERD_MODEL."),
|
|
112
123
|
backends: z.array(z.string().min(1)).min(1).optional().describe("Primary backend, then a second opinion."),
|
|
113
|
-
pricing: Pricing.optional().describe("Prices per million tokens for
|
|
124
|
+
pricing: Pricing.optional().describe("Prices per million tokens for each model you use. Shepherd ships no prices: without one, the $ budget is inactive and costs show as unpriced."),
|
|
114
125
|
provider: z.object({ region: z.string().regex(/^[a-z]{2}(-[a-z]+)+-\d$/, "an AWS region such as eu-west-1").optional(), base_url: z.url({ protocol: /^https?$/ }).optional(), anthropic_base_url: z.url({ protocol: /^https?$/ }).optional() }).strict().optional(),
|
|
115
126
|
guard: z
|
|
116
127
|
.object({
|
|
@@ -1251,8 +1262,13 @@ export function runGates(policy: Policy, pr: PRMeta): GateRun {
|
|
|
1251
1262
|
export const enableAwsOidc = (template: string) => template.replace(/^(\s*)#aws-oidc /gm, "$1");
|
|
1252
1263
|
|
|
1253
1264
|
/** The bundled policy with the settings `gate init` was given written in, so a first run needs only the secret. */
|
|
1254
|
-
export function policyWithSettings(text: string, s: { model?: string; region?: string }): string {
|
|
1255
|
-
const lines = [
|
|
1265
|
+
export function policyWithSettings(text: string, s: { model?: string; region?: string; pricing?: z.infer<typeof Pricing> }): string {
|
|
1266
|
+
const lines = [
|
|
1267
|
+
s.model && `model: ${JSON.stringify(s.model)}`,
|
|
1268
|
+
s.region && `provider:\n region: ${JSON.stringify(s.region)}`,
|
|
1269
|
+
s.pricing && `pricing:\n${Object.entries(s.pricing).map(([model, price]) => ` ${JSON.stringify(model)}: ${JSON.stringify(price)}`).join("\n")}`,
|
|
1270
|
+
].filter(Boolean);
|
|
1271
|
+
|
|
1256
1272
|
const out = lines.length ? text.replace(/^version: 1\n/m, `$&\n# Written by gate init.\n${lines.join("\n")}\n`) : text;
|
|
1257
1273
|
|
|
1258
1274
|
PolicySchema.parse(parseYaml(out)); // a bad --model or --region fails here, not on the first review
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { parseModelId } from "./llm.ts";
|
|
3
|
+
|
|
4
|
+
/** One `pricing:` entry in `.shepherd/gate.yml`, as `gate init` writes it. */
|
|
5
|
+
export interface PriceEntry {
|
|
6
|
+
inputPer1M: number;
|
|
7
|
+
outputPer1M: number;
|
|
8
|
+
cachedInputPer1M?: number;
|
|
9
|
+
as_of: string;
|
|
10
|
+
source: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DEFAULT_URL = "https://models.dev/api.json";
|
|
14
|
+
|
|
15
|
+
/** Shepherd's provider names, as models.dev spells them. */
|
|
16
|
+
const MODELS_DEV_PROVIDER = new Map([
|
|
17
|
+
["bedrock", "amazon-bedrock"],
|
|
18
|
+
["gateway", "vercel"],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
/** A Bedrock cross-region inference profile prefix, which models.dev may list only on the foundation id. */
|
|
22
|
+
const PROFILE_PREFIX = /^(?:eu|us|us-gov|apac|au|jp|in|global)\./;
|
|
23
|
+
|
|
24
|
+
const Cost = z.object({ input: z.number(), output: z.number(), cache_read: z.number().optional() });
|
|
25
|
+
|
|
26
|
+
/** One provider's slice of models.dev's catalogue: model id → entry. Only this provider is validated, so an odd entry elsewhere cannot hide a price. */
|
|
27
|
+
const ProviderModels = z.object({ models: z.record(z.string(), z.object({ cost: z.unknown() }).loose()) }).loose();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Today's list price for a model from models.dev's public catalogue, dated and sourced, or null when the
|
|
31
|
+
* catalogue has none or cannot be read. Shepherd ships no prices: this one is written into the repo's
|
|
32
|
+
* reviewed policy, where the team can see its date and change it.
|
|
33
|
+
* `SHEPHERD_PRICES_URL=off` skips the lookup; any other value replaces the catalogue's URL.
|
|
34
|
+
*/
|
|
35
|
+
export async function catalogPrice(modelId: string, o: { fetch?: (url: string, init: RequestInit) => Promise<Response>; url?: string; today?: string } = {}): Promise<{ key: string; price: PriceEntry } | null> {
|
|
36
|
+
const url = o.url ?? process.env.SHEPHERD_PRICES_URL ?? DEFAULT_URL;
|
|
37
|
+
|
|
38
|
+
if (url === "off") return null;
|
|
39
|
+
|
|
40
|
+
const { provider, model } = parseModelId(modelId);
|
|
41
|
+
const catalogProvider = MODELS_DEV_PROVIDER.get(provider) ?? provider;
|
|
42
|
+
let models: z.infer<typeof ProviderModels>["models"];
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const res = await (o.fetch ?? fetch)(url, { signal: AbortSignal.timeout(10_000) });
|
|
46
|
+
|
|
47
|
+
if (!res.ok) return null;
|
|
48
|
+
models = ProviderModels.parse(z.record(z.string(), z.unknown()).parse(await res.json())[catalogProvider]).models;
|
|
49
|
+
} catch {
|
|
50
|
+
return null; // offline, slow or an unexpected shape: init still succeeds, and prints how to add a price
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const cost = [model, model.replace(PROFILE_PREFIX, "")].map((id) => Cost.safeParse(models[id]?.cost)).find((r) => r.success)?.data;
|
|
54
|
+
|
|
55
|
+
if (!cost) return null;
|
|
56
|
+
|
|
57
|
+
const price: PriceEntry = { inputPer1M: cost.input, outputPer1M: cost.output, as_of: o.today ?? new Date().toISOString().slice(0, 10), source: `models.dev ${catalogProvider} list price` };
|
|
58
|
+
|
|
59
|
+
if (cost.cache_read !== undefined) price.cachedInputPer1M = cost.cache_read;
|
|
60
|
+
|
|
61
|
+
return { key: model, price };
|
|
62
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# yaml-language-server: $schema=https://unpkg.com/@jagreehal/shepherd@0.
|
|
1
|
+
# yaml-language-server: $schema=https://unpkg.com/@jagreehal/shepherd@0.17.0/gate/.shepherd/gate.schema.json
|
|
2
2
|
# gate merge-gate policy, strict: `shepherd gate init --strict` writes this one.
|
|
3
3
|
# Auth, secrets, migrations, infrastructure, billing, public API and toolchain
|
|
4
4
|
# changes always go to a human.
|
|
@@ -10,11 +10,12 @@ version: 1
|
|
|
10
10
|
|
|
11
11
|
# Settings. Each is optional. SHEPHERD_MODEL overrides `model`; `shepherd gate config` shows every value in effect
|
|
12
12
|
# and where it came from.
|
|
13
|
-
# Secrets never go here. Without a price for the model, the $ budget cannot fire ("budget guard inactive")
|
|
13
|
+
# Secrets never go here. Without a price for the model, the $ budget cannot fire ("budget guard inactive"); gate init
|
|
14
|
+
# writes the model's list price from models.dev, dated, for you to check against your region or contract.
|
|
14
15
|
# model: bedrock/minimax.minimax-m2.5
|
|
15
16
|
# backends: [api, bedrock:openai.gpt-oss-120b-1:0] # primary, then a second opinion
|
|
16
17
|
# pricing:
|
|
17
|
-
#
|
|
18
|
+
# openai.gpt-oss-120b: { inputPer1M: 0.18, outputPer1M: 0.70, as_of: 2026-11-14, source: aws.amazon.com/bedrock/pricing eu-west-1 }
|
|
18
19
|
# provider: { region: eu-west-1 } # also base_url (openai-compatible/) and anthropic_base_url
|
|
19
20
|
# guard: { budget_usd: 2, tokens: 3m, loop: 4/12, max_tools: 80, timeout: 15m }
|
|
20
21
|
# max_output_tokens: 16000
|
|
@@ -60,7 +60,7 @@ jobs:
|
|
|
60
60
|
runs-on: ubuntu-latest
|
|
61
61
|
timeout-minutes: 20 # a hung model call must not burn a runner for six hours; a killed run is fail-closed (the approval is already retracted)
|
|
62
62
|
env:
|
|
63
|
-
SHEPHERD_VERSION: 0.
|
|
63
|
+
SHEPHERD_VERSION: 0.17.0 # pinned: the engine decides what gets auto-approved, so bumps are deliberate
|
|
64
64
|
steps:
|
|
65
65
|
- uses: actions/checkout@v4
|
|
66
66
|
with:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jagreehal/shepherd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Agent skills that drive a PR to merge-ready: a review swarm, thread triage, CI repair, and a loop that hands the result to the gate.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:jagreehal/shepherd",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"@ai-sdk/openai-compatible": "3.0.71",
|
|
66
66
|
"@aws-sdk/credential-provider-node": "^3.972.86",
|
|
67
67
|
"ai": "7.0.143",
|
|
68
|
-
"autotel": "
|
|
69
|
-
"autotel-bedrock": "
|
|
70
|
-
"autotel-genai": "0.
|
|
68
|
+
"autotel": "9.3.0",
|
|
69
|
+
"autotel-bedrock": "4.0.0",
|
|
70
|
+
"autotel-genai": "0.17.0",
|
|
71
71
|
"yaml": "^2.9.1",
|
|
72
72
|
"zod": "^4.6.7"
|
|
73
73
|
}
|
package/src/cli.ts
CHANGED
|
@@ -545,18 +545,19 @@ if (command === "install") {
|
|
|
545
545
|
console.log(`wrote .github/workflows/${name}`);
|
|
546
546
|
}
|
|
547
547
|
|
|
548
|
-
//
|
|
549
|
-
// gate
|
|
550
|
-
const gateArgs = ["init", ...(opts.upgrade ? ["--upgrade"] : []), ...(opts.environment ? ["--environment", opts.environment] : []), ...(opts["aws-region"] ? ["--region", opts["aws-region"]] : [])];
|
|
551
|
-
|
|
552
|
-
if (spawnSync(process.execPath, [path.join(BUNDLE_ROOT, "gate", "src", "cli.ts"), ...gateArgs], { cwd: repoRoot, stdio: "inherit" }).status !== 0) process.exitCode = 1;
|
|
553
|
-
|
|
554
|
-
// Settings go in the team policy, reviewed and versioned, rather than in repository variables.
|
|
548
|
+
// Settings go in the team policy, reviewed and versioned, rather than in repository variables. Pinned before the
|
|
549
|
+
// gate's init, which names the key for this model.
|
|
555
550
|
if (opts.model) {
|
|
556
551
|
orExit(() => pinModel(repoLensFile(repoRoot), "loop", opts.model!));
|
|
557
552
|
console.log(`pinned models.loop: ${opts.model} in ${path.relative(repoRoot, repoLensFile(repoRoot))}`);
|
|
558
553
|
}
|
|
559
554
|
|
|
555
|
+
// The approval gate's workflows and policy too, so one command sets up the loop and the gate. No --model: the
|
|
556
|
+
// gate reads models.loop, so a later --model moves both.
|
|
557
|
+
const gateArgs = ["init", ...(opts.upgrade ? ["--upgrade"] : []), ...(opts.environment ? ["--environment", opts.environment] : []), ...(opts["aws-region"] ? ["--region", opts["aws-region"]] : [])];
|
|
558
|
+
|
|
559
|
+
if (spawnSync(process.execPath, [path.join(BUNDLE_ROOT, "gate", "src", "cli.ts"), ...gateArgs], { cwd: repoRoot, stdio: "inherit" }).status !== 0) process.exitCode = 1;
|
|
560
|
+
|
|
560
561
|
const ci: Record<string, string> = {};
|
|
561
562
|
|
|
562
563
|
if (opts.label) ci.label = opts.label;
|
|
@@ -682,7 +683,7 @@ if (command === "install") {
|
|
|
682
683
|
// Only a new choice is written: a rerun keeps the model the policy names.
|
|
683
684
|
const wf = spawnSync(process.execPath, [path.join(BUNDLE_ROOT, "src", "bin.ts"), "workflows", ...(pick?.chosen ? ["--model", pick.model] : [])], { cwd: repoRoot, encoding: "utf8" });
|
|
684
685
|
|
|
685
|
-
for (const line of `${wf.stdout}${wf.stderr}`.split("\n")) if (/^(wrote|created|upgraded|pinned|scoped)\b/.test(line)) console.log(line); // a rerun's kept files are not news
|
|
686
|
+
for (const line of `${wf.stdout}${wf.stderr}`.split("\n")) if (/^(wrote|created|upgraded|pinned|scoped|Priced|No list price)\b/.test(line)) console.log(line); // a rerun's kept files are not news
|
|
686
687
|
|
|
687
688
|
if (wf.status !== 0) orExit(() => { throw new Error(`writing the workflows failed:\n${wf.stderr}`); });
|
|
688
689
|
console.log(pick ? `model ${pick.model} (${pick.why})` : `model none found: set ${KEY_MODELS.map(([k]) => k).join(", ")} or pass --model provider/model`);
|