dsh-github-copilot 0.4.2-alpha.12 → 0.4.2-alpha.14

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.
@@ -1,4 +1,4 @@
1
- import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-DEo3UrOO.js";
1
+ import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-D5T4fto9.js";
2
2
  import { z } from "zod";
3
3
  //#region lib/types/diagnostics-analysis.js
4
4
  const RETENTION_MS = 12096e5;
@@ -51,15 +51,49 @@ function excludedModelSet(value) {
51
51
  const AUTO_ALLOCATION_POLICIES = [
52
52
  "high-cost-v1",
53
53
  "high-cost-v2",
54
- "high-cost-v3"
54
+ "high-cost-v3",
55
+ "high-cost-v4"
55
56
  ];
56
- const AUTO_ALLOCATION_POLICY = "high-cost-v3";
57
+ const AUTO_ALLOCATION_POLICY = "high-cost-v4";
58
+ const categories = [
59
+ "powerful",
60
+ "versatile",
61
+ "lightweight",
62
+ "unknown"
63
+ ];
64
+ function autoCategoryWeight(category, target) {
65
+ if (category === "unknown") return .02;
66
+ return [
67
+ 1,
68
+ .25,
69
+ .05
70
+ ][(target === "powerful" ? [
71
+ "powerful",
72
+ "versatile",
73
+ "lightweight"
74
+ ] : target === "lightweight" ? [
75
+ "lightweight",
76
+ "versatile",
77
+ "powerful"
78
+ ] : [
79
+ "versatile",
80
+ "powerful",
81
+ "lightweight"
82
+ ]).indexOf(category)];
83
+ }
57
84
  const AutoAllocationSchema = z.object({
58
85
  policyVersion: z.enum(AUTO_ALLOCATION_POLICIES),
86
+ targetCategory: z.enum([
87
+ "powerful",
88
+ "versatile",
89
+ "lightweight"
90
+ ]).optional(),
59
91
  deferredHighCostCount: z.number().int().min(0).max(511).optional(),
60
92
  selectedModelId: z.string().min(1).max(512),
61
93
  candidates: z.array(z.object({
62
94
  modelId: z.string().min(1).max(512),
95
+ category: z.enum(categories).optional(),
96
+ categoryWeight: z.number().positive().max(1).optional(),
63
97
  highCost: z.boolean(),
64
98
  previous: z.boolean(),
65
99
  weight: z.number().positive().max(1.5),
@@ -68,8 +102,11 @@ const AutoAllocationSchema = z.object({
68
102
  }).strict().refine((value) => {
69
103
  const total = value.candidates.reduce((sum, row) => sum + row.weight, 0);
70
104
  const legacy = value.policyVersion === "high-cost-v1";
71
- const decay = value.policyVersion === "high-cost-v3";
72
- return (legacy || decay ? value.deferredHighCostCount === void 0 : value.deferredHighCostCount !== void 0 && value.candidates.length + value.deferredHighCostCount <= 512 && value.candidates.every((row) => row.highCost === value.candidates[0].highCost) && (!value.candidates[0].highCost || value.deferredHighCostCount === 0)) && new Set(value.candidates.map((row) => row.modelId)).size === value.candidates.length && value.candidates.some((row) => row.modelId === value.selectedModelId) && value.candidates.filter((row) => row.previous).length <= 1 && value.candidates.every((row) => row.weight === (decay && row.highCost && row.previous ? 2 : (row.highCost ? 20 : 100) * (row.previous && (legacy || !row.highCost) ? 1.5 : 1)) / 100 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
105
+ const soft = value.policyVersion === "high-cost-v4";
106
+ const decay = value.policyVersion === "high-cost-v3" || soft;
107
+ const categoryValid = soft ? value.targetCategory !== void 0 && value.candidates.every((row) => row.category !== void 0 && row.categoryWeight === autoCategoryWeight(row.category, value.targetCategory)) : value.targetCategory === void 0 && value.candidates.every((row) => row.category === void 0 && row.categoryWeight === void 0);
108
+ const tierValid = legacy || decay ? value.deferredHighCostCount === void 0 : value.deferredHighCostCount !== void 0 && value.candidates.length + value.deferredHighCostCount <= 512 && value.candidates.every((row) => row.highCost === value.candidates[0].highCost) && (!value.candidates[0].highCost || value.deferredHighCostCount === 0);
109
+ return categoryValid && tierValid && new Set(value.candidates.map((row) => row.modelId)).size === value.candidates.length && value.candidates.some((row) => row.modelId === value.selectedModelId) && value.candidates.filter((row) => row.previous).length <= 1 && value.candidates.every((row) => row.weight === (decay && row.highCost && row.previous ? 2 : (row.highCost ? 20 : 100) * (row.previous && (legacy || !row.highCost) ? 1.5 : 1)) * (soft ? Math.round(row.categoryWeight * 100) : 100) / 1e4 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
73
110
  }, { message: "Invalid allocation policy evidence" });
74
111
  function normalizeHighCostModelIds(value) {
75
112
  try {
@@ -80,15 +117,19 @@ function normalizeHighCostModelIds(value) {
80
117
  }
81
118
  }
82
119
  /** Integer policy units avoid cumulative decimal drift; avalanche sequential turn seeds. */
83
- function allocateAutoModel(pool, highCostModelIds, previousModelId, seed) {
120
+ function allocateAutoModel(pool, highCostModelIds, previousModelId, seed, targetCategory = "powerful") {
84
121
  if (!Number.isSafeInteger(seed) || pool.length === 0 || pool.length > 512 || normalizeExcludedModelIds(pool.map((model) => model.id)).length !== pool.length) throw new Error("COPILOT_AUTO_ALLOCATION_INVALID");
85
122
  const marked = new Set(normalizeHighCostModelIds(highCostModelIds));
86
123
  const rows = pool.map((model) => {
87
124
  const highCost = marked.has(model.id);
88
125
  const previous = model.id === previousModelId;
89
- const units = highCost ? previous ? 2 : 20 : previous ? 150 : 100;
126
+ const category = model.category ?? "unknown";
127
+ const categoryWeight = autoCategoryWeight(category, targetCategory);
128
+ const units = (highCost ? previous ? 2 : 20 : previous ? 150 : 100) * Math.round(categoryWeight * 100);
90
129
  return {
91
130
  modelId: model.id,
131
+ category,
132
+ categoryWeight,
92
133
  highCost,
93
134
  previous,
94
135
  units
@@ -106,10 +147,11 @@ function allocateAutoModel(pool, highCostModelIds, previousModelId, seed) {
106
147
  });
107
148
  return Object.freeze({
108
149
  policyVersion: AUTO_ALLOCATION_POLICY,
150
+ targetCategory,
109
151
  selectedModelId: selected.modelId,
110
152
  candidates: Object.freeze(rows.map(({ units, ...row }) => Object.freeze({
111
153
  ...row,
112
- weight: units / 100,
154
+ weight: units / 1e4,
113
155
  expectedShare: units / total
114
156
  })))
115
157
  });
@@ -256,7 +298,7 @@ var AutoAllocationDiagnosticsCollector = class {
256
298
  this.data.observationStart = this.data.observationStart === null ? day : Math.min(this.data.observationStart, day);
257
299
  this.data.observationEnd = this.data.observationEnd === null ? day : Math.max(this.data.observationEnd, day);
258
300
  if (explanation.method === "no-fit") {
259
- const row = this.data.noFitRows.find((item) => item.day === day && item.version === this.version && item.policyVersion === "high-cost-v3" && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome);
301
+ const row = this.data.noFitRows.find((item) => item.day === day && item.version === this.version && item.policyVersion === "high-cost-v4" && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome);
260
302
  if (row) row.decisions = this.add(row.decisions, 1);
261
303
  else if (this.data.rows.length + this.data.noFitRows.length < 1024) this.data.noFitRows.push({
262
304
  day,
@@ -279,14 +321,15 @@ var AutoAllocationDiagnosticsCollector = class {
279
321
  }
280
322
  if (explanation.method !== "weighted-distribution" && explanation.method !== "only-candidate") return;
281
323
  const parsed = AutoAllocationSchema.safeParse(explanation.allocation);
282
- if (!parsed.success || parsed.data.policyVersion !== "high-cost-v3") {
324
+ if (!parsed.success || parsed.data.policyVersion !== "high-cost-v4") {
283
325
  this.data.dropped = this.add(this.data.dropped, 1);
284
326
  this.changed();
285
327
  return;
286
328
  }
287
329
  const allocation = parsed.data;
288
330
  for (const candidate of allocation.candidates) {
289
- const row = this.data.rows.find((item) => item.day === day && item.version === this.version && item.policyVersion === allocation.policyVersion && item.modelId === candidate.modelId && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome && item.method === explanation.method && item.fallback === explanation.fallback && item.highCost === candidate.highCost && item.previous === candidate.previous && item.weight === candidate.weight);
331
+ const category = candidate.category ?? explanation.selectedCategory;
332
+ const row = this.data.rows.find((item) => item.day === day && item.version === this.version && item.policyVersion === allocation.policyVersion && item.modelId === candidate.modelId && item.targetCategory === explanation.targetCategory && item.category === category && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome && item.method === explanation.method && item.fallback === explanation.fallback && item.highCost === candidate.highCost && item.previous === candidate.previous && item.weight === candidate.weight);
290
333
  if (row) {
291
334
  row.opportunities = this.add(row.opportunities, 1);
292
335
  row.expectedSelections = Math.min(Number.MAX_SAFE_INTEGER, row.expectedSelections + candidate.expectedShare);
@@ -297,7 +340,7 @@ var AutoAllocationDiagnosticsCollector = class {
297
340
  policyVersion: allocation.policyVersion,
298
341
  modelId: candidate.modelId,
299
342
  targetCategory: explanation.targetCategory,
300
- category: explanation.selectedCategory,
343
+ category,
301
344
  demand: explanation.assessment.demand,
302
345
  assessmentSource: explanation.assessment.source,
303
346
  method: explanation.method,
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as GITHUB_COPILOT_PREVIEW_PROVIDER_ID, i as GITHUB_COPILOT_CREDENTIAL_KEY, n as GITHUB_COPILOT_AUTO_INTELLIGENCE_MODEL_ID, o as GITHUB_COPILOT_PROVIDER_ID, r as GITHUB_COPILOT_AUTO_MODEL_ID, s as autoModelPreference, t as GITHUB_COPILOT_AUTO_EFFICIENCY_MODEL_ID } from "./copilot-identity-DRZY_d2X.js";
2
- import { C as excludedModelSet, S as ModelExclusionTurns, _ as AUTO_ALLOCATION_POLICIES, b as allocateAutoModel, c as DiagnosticsViewSchema, d as diagnosticsReason, f as CredentialChangeSchema, g as emptyAutoAllocationDiagnostics, h as AutoAllocationDiagnosticsCollector, i as DIAGNOSTICS_RETENTION_MS, l as diagnosticsBucket, m as RequestDiagnosticSchema, o as DiagnosticsRowSchema, p as REQUEST_DIAGNOSTICS_RETENTION_MS, s as DiagnosticsSnapshotSchema, u as diagnosticsOutcome, v as AUTO_ALLOCATION_POLICY, w as normalizeExcludedModelIds, x as normalizeHighCostModelIds, y as AutoAllocationSchema } from "./diagnostics-types-DEo3UrOO.js";
2
+ import { C as excludedModelSet, S as ModelExclusionTurns, _ as AUTO_ALLOCATION_POLICIES, b as allocateAutoModel, c as DiagnosticsViewSchema, d as diagnosticsReason, f as CredentialChangeSchema, g as emptyAutoAllocationDiagnostics, h as AutoAllocationDiagnosticsCollector, i as DIAGNOSTICS_RETENTION_MS, l as diagnosticsBucket, m as RequestDiagnosticSchema, o as DiagnosticsRowSchema, p as REQUEST_DIAGNOSTICS_RETENTION_MS, s as DiagnosticsSnapshotSchema, u as diagnosticsOutcome, v as AUTO_ALLOCATION_POLICY, w as normalizeExcludedModelIds, x as normalizeHighCostModelIds, y as AutoAllocationSchema } from "./diagnostics-types-D5T4fto9.js";
3
3
  import { C as providerErrorMessage, D as onSettingsNamespaceUpdated, E as readCopilotCatalog, O as readConfigValue, S as isAbortError, T as isPluginPreviewProvider, _ as sameCandidates, a as COPILOT_HOSTED_SEARCH_PROVIDER_ID, b as currentSearchSelection, c as applyRequestAuth, d as ANTHROPIC_WEB_SEARCH_TOOL_TYPE, f as GITHUB_COPILOT_CREDENTIAL_KEY$1, g as candidatesForRoute, h as WEB_SEARCH_TOOL_TYPE, i as describeSearchBackend, k as readSettingsNamespace, l as normalizeRequestAuth, m as SearchPlan, n as routeSessionSearch, o as GITHUB_COPILOT_HOSTED_SEARCH_PROVIDER_ID, p as RESPONSES_WEB_SEARCH_TOOL_TYPE, r as DescribedSearchFallbackError, s as createTraditionalSearchProvider, t as isCopilotSearchSelection, u as providerRequestHeaders, v as currentChatRoute, w as readBounded, x as abortable$1, y as currentSearchInitiator } from "./search-routing-CV2hs8as.js";
4
4
  import { a as selectCompactionReasoning, i as resolveRequestBudgetPolicy, n as assessRequestBudget, r as calculateRequestBudget, t as DEFAULT_REQUEST_BUDGET_POLICY } from "./request-budget-DLY_aRq0.js";
5
5
  import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
@@ -12,6 +12,7 @@ import { getCACertificates } from "node:tls";
12
12
  import { Agent } from "undici";
13
13
  import { createModels, getSupportedThinkingLevels, hasApi, lazyStream } from "@earendil-works/pi-ai";
14
14
  import { githubCopilotProvider } from "@earendil-works/pi-ai/providers/github-copilot";
15
+ import { symbols } from "@deepseek-ai/cordis";
15
16
  import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
16
17
  import { credentialKey, credentialRef } from "@deepseek-ai/dsh-credentials";
17
18
  import { WebError } from "@deepseek-ai/dsh-web";
@@ -581,7 +582,7 @@ const result$1 = strictRemoteCodec("dsh-github-copilot#DiagnosticsView", Diagnos
581
582
  var package_default = {
582
583
  name: "dsh-github-copilot",
583
584
  description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
584
- version: "0.4.2-alpha.12",
585
+ version: "0.4.2-alpha.14",
585
586
  releaseNotes: "CHANGELOG.md",
586
587
  publishConfig: {
587
588
  "access": "public",
@@ -2072,6 +2073,10 @@ function normalizeGitHubCopilotOAuthCredential(credential) {
2072
2073
  const nativeRefreshResults = /* @__PURE__ */ new WeakSet();
2073
2074
  const nativeRefreshRejections = /* @__PURE__ */ new WeakMap();
2074
2075
  const refreshWrites = /* @__PURE__ */ new WeakMap();
2076
+ function credentialServiceIdentity(service) {
2077
+ const original = Reflect.get(service, symbols.original);
2078
+ return typeof original === "object" && original !== null ? original : service;
2079
+ }
2075
2080
  /** Only a validated native OAuth refresh may certify its exact returned object. */
2076
2081
  async function certifyCopilotNativeRefresh(previous, result, derive, signal) {
2077
2082
  const ids = (grant) => grant.availableModelIds === void 0 ? void 0 : JSON.stringify([...grant.availableModelIds].sort());
@@ -2091,7 +2096,7 @@ async function certifyCopilotNativeRefresh(previous, result, derive, signal) {
2091
2096
  /** Consume exactly one notification from the serialized, certified write. */
2092
2097
  function observeCopilotNativeRefresh(ctx, key, diagnostic) {
2093
2098
  const service = ctx.get("credentials");
2094
- const write = service === void 0 ? void 0 : refreshWrites.get(service)?.get(key);
2099
+ const write = service === void 0 ? void 0 : refreshWrites.get(credentialServiceIdentity(service))?.get(key);
2095
2100
  if (!write) {
2096
2101
  diagnostic?.("notification", "unknown-source");
2097
2102
  return;
@@ -2172,12 +2177,13 @@ function createGitHubCopilotCredentialStore(ctx, logicalProviderId = GITHUB_COPI
2172
2177
  assertProvider(providerId);
2173
2178
  binding?.assertCurrent();
2174
2179
  const service = credentialService(ctx);
2180
+ const identity = credentialServiceIdentity(service);
2175
2181
  let pending;
2176
2182
  let expected;
2177
- let writes = refreshWrites.get(service);
2183
+ let writes = refreshWrites.get(identity);
2178
2184
  if (!writes) {
2179
2185
  writes = /* @__PURE__ */ new Map();
2180
- refreshWrites.set(service, writes);
2186
+ refreshWrites.set(identity, writes);
2181
2187
  }
2182
2188
  try {
2183
2189
  const stored = await service.modifyRecord(key, async (current) => {
@@ -12343,7 +12349,7 @@ function targetCategory(assessment, preference) {
12343
12349
  }
12344
12350
  /**
12345
12351
  * Filter input headroom before task-aware supplier categories.
12346
- * Apply positive cost weights and marked recency decay inside the fitting category.
12352
+ * Apply soft category, cost and recency weights across every fitting candidate.
12347
12353
  * Preserves Core compaction ownership if no candidate currently fits.
12348
12354
  */
12349
12355
  function selectAutoModel(models, messages, preference = "balance", context) {
@@ -12362,38 +12368,21 @@ function selectAutoModel(models, messages, preference = "balance", context) {
12362
12368
  const seed = resolveSeed(messages, context);
12363
12369
  const assessment = context?.assessment ?? assessTaskLocally(messages);
12364
12370
  const target = targetCategory(assessment, preference);
12365
- const order = target === "powerful" ? [
12366
- "powerful",
12367
- "versatile",
12368
- "lightweight",
12369
- "unknown"
12370
- ] : target === "lightweight" ? [
12371
- "lightweight",
12372
- "versatile",
12373
- "powerful",
12374
- "unknown"
12375
- ] : [
12376
- "versatile",
12377
- "powerful",
12378
- "lightweight",
12379
- "unknown"
12380
- ];
12381
12371
  let selectedModel;
12382
12372
  let inputFitDiagnostic;
12383
12373
  let selectedInputBudget;
12384
12374
  let explanation;
12385
12375
  if (fitting.length > 0) {
12386
- const selectedCategory = order.find((category) => fitting.some((model) => (model.category ?? "unknown") === category));
12387
- const pool = fitting.filter((model) => (model.category ?? "unknown") === selectedCategory);
12388
- const allocation = allocateAutoModel(pool, context?.highCostModelIds, context?.previousModelId, seed);
12389
- selectedModel = pool.find((model) => model.id === allocation.selectedModelId);
12376
+ const allocation = allocateAutoModel(fitting, context?.highCostModelIds, context?.previousModelId, seed, target);
12377
+ selectedModel = fitting.find((model) => model.id === allocation.selectedModelId);
12390
12378
  explanation = {
12379
+ allocationPolicy: "high-cost-v4",
12391
12380
  assessment,
12392
12381
  targetCategory: target,
12393
- selectedCategory,
12382
+ selectedCategory: selectedModel.category ?? "unknown",
12394
12383
  categoryCandidateCount: allocation.candidates.length,
12395
12384
  method: allocation.candidates.length === 1 ? "only-candidate" : "weighted-distribution",
12396
- fallback: selectedCategory !== target,
12385
+ fallback: !fitting.some((model) => model.category === target),
12397
12386
  ...context?.collectAllocationEvidence === false ? {} : { allocation }
12398
12387
  };
12399
12388
  selectedInputBudget = candidateInputLimit(selectedModel, requestedMaxTokens, policy);
@@ -12481,7 +12470,7 @@ function summarizeAutoAllocations(explanations, window) {
12481
12470
  let noFitDecisions = 0;
12482
12471
  let retainedDecisions = 0;
12483
12472
  let rowsTruncated = false;
12484
- const policyVersion = explanations.some((row) => row.allocation?.policyVersion === "high-cost-v3") ? AUTO_ALLOCATION_POLICY : explanations.find((row) => row.allocation !== void 0)?.allocation?.policyVersion ?? "high-cost-v3";
12473
+ const policyVersion = explanations.some((row) => row.allocation?.policyVersion === "high-cost-v4") ? AUTO_ALLOCATION_POLICY : explanations.find((row) => row.allocation !== void 0)?.allocation?.policyVersion ?? "high-cost-v4";
12485
12474
  let omittedPolicyDecisions = 0;
12486
12475
  for (const explanation of explanations) {
12487
12476
  if (explanation.method === "no-fit") {
@@ -12496,9 +12485,10 @@ function summarizeAutoAllocations(explanations, window) {
12496
12485
  }
12497
12486
  retainedDecisions++;
12498
12487
  for (const row of allocation.candidates) {
12488
+ const category = row.category ?? explanation.selectedCategory;
12499
12489
  const key = JSON.stringify([
12500
12490
  row.modelId,
12501
- explanation.selectedCategory,
12491
+ category,
12502
12492
  row.highCost,
12503
12493
  row.previous,
12504
12494
  row.weight
@@ -12511,7 +12501,7 @@ function summarizeAutoAllocations(explanations, window) {
12511
12501
  }
12512
12502
  aggregate = {
12513
12503
  modelId: row.modelId,
12514
- category: explanation.selectedCategory,
12504
+ category,
12515
12505
  highCost: row.highCost,
12516
12506
  previous: row.previous,
12517
12507
  weight: row.weight,
@@ -12543,6 +12533,7 @@ function summarizeAutoAllocations(explanations, window) {
12543
12533
  //#endregion
12544
12534
  //#region lib/types/turn-selection.js
12545
12535
  const ExplanationSchema = z.object({
12536
+ allocationPolicy: z.literal("high-cost-v4").optional(),
12546
12537
  assessment: TaskAssessmentSchema.extend({
12547
12538
  source: z.enum(["local", "semantic"]),
12548
12539
  diagnostic: z.enum([
@@ -1,5 +1,5 @@
1
1
  import "./copilot-identity-DRZY_d2X.js";
2
- import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-DEo3UrOO.js";
2
+ import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-D5T4fto9.js";
3
3
  import { i as resolveRequestBudgetPolicy, r as calculateRequestBudget } from "./request-budget-DLY_aRq0.js";
4
4
  import z from "@deepseek-ai/schemastery";
5
5
  import { LlmError, createUserMessage } from "@deepseek-ai/dsh-llm";
package/lib/remote.js CHANGED
@@ -323,14 +323,48 @@ const TaskAssessmentSchema = z.object({
323
323
  const AUTO_ALLOCATION_POLICIES = [
324
324
  "high-cost-v1",
325
325
  "high-cost-v2",
326
- "high-cost-v3"
326
+ "high-cost-v3",
327
+ "high-cost-v4"
327
328
  ];
329
+ const categories = [
330
+ "powerful",
331
+ "versatile",
332
+ "lightweight",
333
+ "unknown"
334
+ ];
335
+ function autoCategoryWeight(category, target) {
336
+ if (category === "unknown") return .02;
337
+ return [
338
+ 1,
339
+ .25,
340
+ .05
341
+ ][(target === "powerful" ? [
342
+ "powerful",
343
+ "versatile",
344
+ "lightweight"
345
+ ] : target === "lightweight" ? [
346
+ "lightweight",
347
+ "versatile",
348
+ "powerful"
349
+ ] : [
350
+ "versatile",
351
+ "powerful",
352
+ "lightweight"
353
+ ]).indexOf(category)];
354
+ }
328
355
  const AutoAllocationSchema = z.object({
329
356
  policyVersion: z.enum(AUTO_ALLOCATION_POLICIES),
357
+ targetCategory: z.enum([
358
+ "powerful",
359
+ "versatile",
360
+ "lightweight"
361
+ ]).optional(),
330
362
  deferredHighCostCount: z.number().int().min(0).max(511).optional(),
331
363
  selectedModelId: z.string().min(1).max(512),
332
364
  candidates: z.array(z.object({
333
365
  modelId: z.string().min(1).max(512),
366
+ category: z.enum(categories).optional(),
367
+ categoryWeight: z.number().positive().max(1).optional(),
334
368
  highCost: z.boolean(),
335
369
  previous: z.boolean(),
336
370
  weight: z.number().positive().max(1.5),
@@ -339,8 +373,11 @@ const AutoAllocationSchema = z.object({
339
373
  }).strict().refine((value) => {
340
374
  const total = value.candidates.reduce((sum, row) => sum + row.weight, 0);
341
375
  const legacy = value.policyVersion === "high-cost-v1";
342
- const decay = value.policyVersion === "high-cost-v3";
343
- return (legacy || decay ? value.deferredHighCostCount === void 0 : value.deferredHighCostCount !== void 0 && value.candidates.length + value.deferredHighCostCount <= 512 && value.candidates.every((row) => row.highCost === value.candidates[0].highCost) && (!value.candidates[0].highCost || value.deferredHighCostCount === 0)) && new Set(value.candidates.map((row) => row.modelId)).size === value.candidates.length && value.candidates.some((row) => row.modelId === value.selectedModelId) && value.candidates.filter((row) => row.previous).length <= 1 && value.candidates.every((row) => row.weight === (decay && row.highCost && row.previous ? 2 : (row.highCost ? 20 : 100) * (row.previous && (legacy || !row.highCost) ? 1.5 : 1)) / 100 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
376
+ const soft = value.policyVersion === "high-cost-v4";
377
+ const decay = value.policyVersion === "high-cost-v3" || soft;
378
+ const categoryValid = soft ? value.targetCategory !== void 0 && value.candidates.every((row) => row.category !== void 0 && row.categoryWeight === autoCategoryWeight(row.category, value.targetCategory)) : value.targetCategory === void 0 && value.candidates.every((row) => row.category === void 0 && row.categoryWeight === void 0);
379
+ const tierValid = legacy || decay ? value.deferredHighCostCount === void 0 : value.deferredHighCostCount !== void 0 && value.candidates.length + value.deferredHighCostCount <= 512 && value.candidates.every((row) => row.highCost === value.candidates[0].highCost) && (!value.candidates[0].highCost || value.deferredHighCostCount === 0);
380
+ return categoryValid && tierValid && new Set(value.candidates.map((row) => row.modelId)).size === value.candidates.length && value.candidates.some((row) => row.modelId === value.selectedModelId) && value.candidates.filter((row) => row.previous).length <= 1 && value.candidates.every((row) => row.weight === (decay && row.highCost && row.previous ? 2 : (row.highCost ? 20 : 100) * (row.previous && (legacy || !row.highCost) ? 1.5 : 1)) * (soft ? Math.round(row.categoryWeight * 100) : 100) / 1e4 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
344
381
  }, { message: "Invalid allocation policy evidence" });
345
382
  //#endregion
346
383
  //#region lib/types/auto-allocation-evidence.js
@@ -374,6 +411,7 @@ const AutoAllocationSummarySchema = z.object({
374
411
  //#endregion
375
412
  //#region lib/types/turn-selection.js
376
413
  const ExplanationSchema = z.object({
414
+ allocationPolicy: z.literal("high-cost-v4").optional(),
377
415
  assessment: TaskAssessmentSchema.extend({
378
416
  source: z.enum(["local", "semantic"]),
379
417
  diagnostic: z.enum([
@@ -5,6 +5,7 @@ export declare const AutoAllocationSummarySchema: z.ZodObject<{
5
5
  "high-cost-v1": "high-cost-v1";
6
6
  "high-cost-v2": "high-cost-v2";
7
7
  "high-cost-v3": "high-cost-v3";
8
+ "high-cost-v4": "high-cost-v4";
8
9
  }>;
9
10
  scope: z.ZodLiteral<"viewed-session-host-lifetime">;
10
11
  status: z.ZodEnum<{
@@ -1,16 +1,32 @@
1
1
  import { z } from 'zod';
2
- export declare const AUTO_ALLOCATION_POLICIES: readonly ["high-cost-v1", "high-cost-v2", "high-cost-v3"];
3
- export declare const AUTO_ALLOCATION_POLICY = "high-cost-v3";
2
+ export declare const AUTO_ALLOCATION_POLICIES: readonly ["high-cost-v1", "high-cost-v2", "high-cost-v3", "high-cost-v4"];
3
+ export declare const AUTO_ALLOCATION_POLICY = "high-cost-v4";
4
+ declare const categories: readonly ["powerful", "versatile", "lightweight", "unknown"];
5
+ type Category = typeof categories[number];
6
+ export declare function autoCategoryWeight(category: Category, target: Exclude<Category, 'unknown'>): number;
4
7
  export declare const AutoAllocationSchema: z.ZodObject<{
5
8
  policyVersion: z.ZodEnum<{
6
9
  "high-cost-v1": "high-cost-v1";
7
10
  "high-cost-v2": "high-cost-v2";
8
11
  "high-cost-v3": "high-cost-v3";
12
+ "high-cost-v4": "high-cost-v4";
9
13
  }>;
14
+ targetCategory: z.ZodOptional<z.ZodEnum<{
15
+ powerful: "powerful";
16
+ versatile: "versatile";
17
+ lightweight: "lightweight";
18
+ }>>;
10
19
  deferredHighCostCount: z.ZodOptional<z.ZodNumber>;
11
20
  selectedModelId: z.ZodString;
12
21
  candidates: z.ZodArray<z.ZodObject<{
13
22
  modelId: z.ZodString;
23
+ category: z.ZodOptional<z.ZodEnum<{
24
+ unknown: "unknown";
25
+ powerful: "powerful";
26
+ versatile: "versatile";
27
+ lightweight: "lightweight";
28
+ }>>;
29
+ categoryWeight: z.ZodOptional<z.ZodNumber>;
14
30
  highCost: z.ZodBoolean;
15
31
  previous: z.ZodBoolean;
16
32
  weight: z.ZodNumber;
@@ -25,6 +41,7 @@ export declare function normalizeHighCostModelIds(value: unknown): readonly stri
25
41
  /** Integer policy units avoid cumulative decimal drift; avalanche sequential turn seeds. */
26
42
  export declare function allocateAutoModel(pool: readonly {
27
43
  readonly id: string;
28
- }[], highCostModelIds: unknown, previousModelId: string | undefined, seed: number): AutoAllocation;
44
+ readonly category?: Exclude<Category, 'unknown'>;
45
+ }[], highCostModelIds: unknown, previousModelId: string | undefined, seed: number, targetCategory?: Exclude<Category, 'unknown'>): AutoAllocation;
29
46
  export {};
30
47
  //# sourceMappingURL=auto-allocation.d.ts.map
@@ -24,6 +24,7 @@ export interface AutoModelDecision {
24
24
  readonly explanation: AutoSelectionExplanation;
25
25
  }
26
26
  export interface AutoSelectionExplanation {
27
+ readonly allocationPolicy?: 'high-cost-v4';
27
28
  readonly assessment: TaskAssessment;
28
29
  readonly targetCategory: AccountModelCategory;
29
30
  readonly selectedCategory: AccountModelCategory | 'unknown';
@@ -55,7 +56,7 @@ export declare function classifyAutoModelTurn(messages: readonly unknown[]): Aut
55
56
  export declare function estimateTurnInputTokens(messages: readonly unknown[], estimateMessage?: (message: unknown) => number): number;
56
57
  /**
57
58
  * Filter input headroom before task-aware supplier categories.
58
- * Apply positive cost weights and marked recency decay inside the fitting category.
59
+ * Apply soft category, cost and recency weights across every fitting candidate.
59
60
  * Preserves Core compaction ownership if no candidate currently fits.
60
61
  */
61
62
  export declare function selectAutoModel(models: readonly AccountModelDescriptor[], messages: readonly unknown[], preference?: AutoModelPreference, context?: AutoModelRoutingContext): AutoModelDecision;
@@ -2,7 +2,7 @@
2
2
  * Provider-side GitHub Copilot auth resolution over the same credential record
3
3
  * that DSH's built-in llm-pi-ai adapter owns.
4
4
  */
5
- import type { Context } from '@deepseek-ai/cordis';
5
+ import { type Context } from '@deepseek-ai/cordis';
6
6
  import { type CredentialStore, type OAuthAuth } from '@earendil-works/pi-ai';
7
7
  import { GITHUB_COPILOT_PROVIDER_ID, GITHUB_COPILOT_PREVIEW_PROVIDER_ID } from './copilot-identity.ts';
8
8
  import type { GitHubCopilotOAuthCredential } from './copilot-grant.ts';
@@ -9,7 +9,7 @@ export declare class TurnSelectionController extends TypertRemoteService {
9
9
  constructor(ctx: Context, selections: TurnSelectionStore);
10
10
  get(agent: Agent, turn: number): TurnSelection;
11
11
  allocationSummary(agent: Agent): {
12
- policyVersion: "high-cost-v1" | "high-cost-v2" | "high-cost-v3";
12
+ policyVersion: "high-cost-v1" | "high-cost-v2" | "high-cost-v3" | "high-cost-v4";
13
13
  scope: "viewed-session-host-lifetime";
14
14
  status: "observed" | "not-collected";
15
15
  retainedDecisions: number;
@@ -22,6 +22,7 @@ export declare const TurnSelectionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
22
22
  candidateCount: z.ZodNumber;
23
23
  fittingCandidateCount: z.ZodOptional<z.ZodNumber>;
24
24
  explanation: z.ZodOptional<z.ZodObject<{
25
+ allocationPolicy: z.ZodOptional<z.ZodLiteral<"high-cost-v4">>;
25
26
  assessment: z.ZodObject<{
26
27
  demand: z.ZodEnum<{
27
28
  unknown: "unknown";
@@ -132,11 +133,24 @@ export declare const TurnSelectionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
132
133
  "high-cost-v1": "high-cost-v1";
133
134
  "high-cost-v2": "high-cost-v2";
134
135
  "high-cost-v3": "high-cost-v3";
136
+ "high-cost-v4": "high-cost-v4";
135
137
  }>;
138
+ targetCategory: z.ZodOptional<z.ZodEnum<{
139
+ powerful: "powerful";
140
+ versatile: "versatile";
141
+ lightweight: "lightweight";
142
+ }>>;
136
143
  deferredHighCostCount: z.ZodOptional<z.ZodNumber>;
137
144
  selectedModelId: z.ZodString;
138
145
  candidates: z.ZodArray<z.ZodObject<{
139
146
  modelId: z.ZodString;
147
+ category: z.ZodOptional<z.ZodEnum<{
148
+ unknown: "unknown";
149
+ powerful: "powerful";
150
+ versatile: "versatile";
151
+ lightweight: "lightweight";
152
+ }>>;
153
+ categoryWeight: z.ZodOptional<z.ZodNumber>;
140
154
  highCost: z.ZodBoolean;
141
155
  previous: z.ZodBoolean;
142
156
  weight: z.ZodNumber;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-github-copilot",
3
3
  "description": "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
4
- "version": "0.4.2-alpha.12",
4
+ "version": "0.4.2-alpha.14",
5
5
  "releaseNotes": "CHANGELOG.md",
6
6
  "publishConfig": {
7
7
  "access": "public",