@vellumai/assistant 0.11.0-dev.202607302128.ff52e0f → 0.11.0-dev.202607302257.e87c491
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/package.json +1 -1
- package/src/__tests__/byok-default-profile-ensure.test.ts +292 -7
- package/src/__tests__/max-tokens-continue-hook.test.ts +120 -0
- package/src/__tests__/pricing.test.ts +2 -2
- package/src/config/__tests__/default-plugin-skill-discovery.test.ts +158 -0
- package/src/config/schemas/llm.ts +13 -2
- package/src/config/skills.ts +102 -14
- package/src/plugins/defaults/main.ts +31 -0
- package/src/plugins/defaults/max-tokens-continue/hooks/post-model-call.ts +50 -2
- package/src/providers/model-catalog.ts +52 -48
- package/src/watcher/__tests__/payload-bounds.test.ts +9 -4
- package/src/watcher/payload-bounds.ts +16 -14
- package/src/workspace/byok-default-profile-ensure.ts +94 -35
package/package.json
CHANGED
|
@@ -536,7 +536,9 @@ describe("ensureByokDefaultProfiles", () => {
|
|
|
536
536
|
expectSecondRunNoop();
|
|
537
537
|
});
|
|
538
538
|
|
|
539
|
-
test("a re-enabled hatch stub is
|
|
539
|
+
test("a re-enabled hatch stub is deleted", () => {
|
|
540
|
+
// The bare key resolves active post-conversion, so deleting the
|
|
541
|
+
// re-enabled stub preserves the enable.
|
|
540
542
|
writeConfig({
|
|
541
543
|
llm: {
|
|
542
544
|
defaultProvider: { provider: "anthropic" },
|
|
@@ -549,11 +551,11 @@ describe("ensureByokDefaultProfiles", () => {
|
|
|
549
551
|
},
|
|
550
552
|
},
|
|
551
553
|
});
|
|
552
|
-
const before = readFileSync(configPath(), "utf-8");
|
|
553
554
|
|
|
554
555
|
ensureByokDefaultProfiles(workspaceDir);
|
|
555
556
|
|
|
556
|
-
expect(
|
|
557
|
+
expect(profiles()["quality-optimized"]).toBeUndefined();
|
|
558
|
+
expectSecondRunNoop();
|
|
557
559
|
});
|
|
558
560
|
|
|
559
561
|
test("a label-only hatch stub with no status key is deleted", () => {
|
|
@@ -710,17 +712,62 @@ describe("ensureByokDefaultProfiles", () => {
|
|
|
710
712
|
expect(readFileSync(configPath(), "utf-8")).toBe(before);
|
|
711
713
|
});
|
|
712
714
|
|
|
713
|
-
test("
|
|
715
|
+
test("a vellum-default install (hatched BYOK, later platform-connected) converts fully", () => {
|
|
714
716
|
const config = uneditedByokConfig();
|
|
715
717
|
(config.llm as Record<string, unknown>).defaultProvider = {
|
|
716
718
|
provider: "vellum",
|
|
717
719
|
};
|
|
718
720
|
writeConfig(config);
|
|
719
|
-
const before = readFileSync(configPath(), "utf-8");
|
|
720
721
|
|
|
721
722
|
ensureByokDefaultProfiles(workspaceDir);
|
|
722
723
|
|
|
723
|
-
|
|
724
|
+
for (const name of [
|
|
725
|
+
"balanced",
|
|
726
|
+
"quality-optimized",
|
|
727
|
+
"cost-optimized",
|
|
728
|
+
"custom-balanced",
|
|
729
|
+
"custom-quality-optimized",
|
|
730
|
+
"custom-cost-optimized",
|
|
731
|
+
]) {
|
|
732
|
+
expect(profiles()[name]).toBeUndefined();
|
|
733
|
+
}
|
|
734
|
+
expect(llm().activeProfile).toBe("balanced");
|
|
735
|
+
expect(llm().advisorProfile).toBe("quality-optimized");
|
|
736
|
+
// With the stub gone, the default resolves active from the vellum column.
|
|
737
|
+
const resolved = resolveDefaultProfileForProvider(
|
|
738
|
+
profiles() as Record<string, ProfileEntry>,
|
|
739
|
+
"balanced",
|
|
740
|
+
{ provider: "vellum" },
|
|
741
|
+
);
|
|
742
|
+
expect(resolved?.source).toBe("managed");
|
|
743
|
+
expect(resolved?.status).toBeUndefined();
|
|
744
|
+
expectSecondRunNoop();
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
test("a vellum-default install keeps a user-edited copy untouched", () => {
|
|
748
|
+
const config = uneditedByokConfig();
|
|
749
|
+
const llmConfig = config.llm as Record<string, unknown>;
|
|
750
|
+
llmConfig.defaultProvider = { provider: "vellum" };
|
|
751
|
+
const profileMap = llmConfig.profiles as Record<
|
|
752
|
+
string,
|
|
753
|
+
Record<string, unknown>
|
|
754
|
+
>;
|
|
755
|
+
profileMap["custom-balanced"] = {
|
|
756
|
+
...profileMap["custom-balanced"],
|
|
757
|
+
model: "claude-opus-4-6",
|
|
758
|
+
};
|
|
759
|
+
writeConfig(config);
|
|
760
|
+
|
|
761
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
762
|
+
|
|
763
|
+
expect(profiles()["custom-balanced"]).toEqual({
|
|
764
|
+
...hatchBody("balanced", "anthropic"),
|
|
765
|
+
model: "claude-opus-4-6",
|
|
766
|
+
});
|
|
767
|
+
expect(llm().activeProfile).toBe("custom-balanced");
|
|
768
|
+
expect(profiles()["custom-quality-optimized"]).toBeUndefined();
|
|
769
|
+
expect(profiles()["custom-cost-optimized"]).toBeUndefined();
|
|
770
|
+
expectSecondRunNoop();
|
|
724
771
|
});
|
|
725
772
|
|
|
726
773
|
test("no-op when llm.defaultProvider is absent or invalid", () => {
|
|
@@ -771,6 +818,104 @@ describe("ensureByokDefaultProfiles", () => {
|
|
|
771
818
|
expect(readFileSync(configPath(), "utf-8")).toBe(before);
|
|
772
819
|
});
|
|
773
820
|
|
|
821
|
+
test("a real vellum-default workspace with re-enabled stubs and mixed connection stamps converts (specimen shape)", () => {
|
|
822
|
+
// Mirrors a live 2026-07 workspace: hatched BYOK anthropic, later
|
|
823
|
+
// platform-connected, stubs re-enabled through the UI, the
|
|
824
|
+
// onboarding-authored copy stamped with the bare "anthropic" connection,
|
|
825
|
+
// and call sites pinned at custom-balanced.
|
|
826
|
+
writeConfig({
|
|
827
|
+
llm: {
|
|
828
|
+
defaultProvider: { provider: "vellum", connectionName: "vellum" },
|
|
829
|
+
activeProfile: "balanced",
|
|
830
|
+
advisorProfile: "quality-optimized",
|
|
831
|
+
profileOrder: [
|
|
832
|
+
"balanced",
|
|
833
|
+
"os-beta",
|
|
834
|
+
"quality-optimized",
|
|
835
|
+
"cost-optimized",
|
|
836
|
+
"custom-balanced",
|
|
837
|
+
"custom-quality-optimized",
|
|
838
|
+
"custom-cost-optimized",
|
|
839
|
+
],
|
|
840
|
+
callSites: {
|
|
841
|
+
subagentSpawn: { profile: "custom-balanced" },
|
|
842
|
+
memoryRouter: {
|
|
843
|
+
profile: "custom-balanced",
|
|
844
|
+
contextWindow: { maxInputTokens: 1000000 },
|
|
845
|
+
},
|
|
846
|
+
},
|
|
847
|
+
profiles: {
|
|
848
|
+
balanced: {
|
|
849
|
+
source: "managed",
|
|
850
|
+
status: "active",
|
|
851
|
+
label: "Balanced (Managed)",
|
|
852
|
+
thinking: { enabled: true, streamThinking: true },
|
|
853
|
+
},
|
|
854
|
+
"quality-optimized": {
|
|
855
|
+
source: "managed",
|
|
856
|
+
status: "active",
|
|
857
|
+
label: "Quality (Managed)",
|
|
858
|
+
thinking: { enabled: true, streamThinking: true },
|
|
859
|
+
},
|
|
860
|
+
"cost-optimized": {
|
|
861
|
+
source: "managed",
|
|
862
|
+
status: "active",
|
|
863
|
+
label: "Speed (Managed)",
|
|
864
|
+
},
|
|
865
|
+
"custom-balanced": {
|
|
866
|
+
...hatchBody("balanced", "anthropic"),
|
|
867
|
+
provider_connection: "anthropic",
|
|
868
|
+
},
|
|
869
|
+
"custom-quality-optimized": hatchBody(
|
|
870
|
+
"quality-optimized",
|
|
871
|
+
"anthropic",
|
|
872
|
+
),
|
|
873
|
+
"custom-cost-optimized": hatchBody("cost-optimized", "anthropic"),
|
|
874
|
+
"os-beta": {
|
|
875
|
+
source: "managed",
|
|
876
|
+
status: "active",
|
|
877
|
+
label: "OS Beta (Managed)",
|
|
878
|
+
},
|
|
879
|
+
},
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
// The live workspace booted with completion baking the copies first.
|
|
883
|
+
ensureCompleteCustomProfiles(workspaceDir);
|
|
884
|
+
const osBetaBefore = { ...profiles()["os-beta"] };
|
|
885
|
+
|
|
886
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
887
|
+
|
|
888
|
+
for (const name of [
|
|
889
|
+
"balanced",
|
|
890
|
+
"quality-optimized",
|
|
891
|
+
"cost-optimized",
|
|
892
|
+
"custom-balanced",
|
|
893
|
+
"custom-quality-optimized",
|
|
894
|
+
"custom-cost-optimized",
|
|
895
|
+
]) {
|
|
896
|
+
expect(profiles()[name]).toBeUndefined();
|
|
897
|
+
}
|
|
898
|
+
expect(profiles()["os-beta"]).toEqual(osBetaBefore);
|
|
899
|
+
expect(llm().activeProfile).toBe("balanced");
|
|
900
|
+
expect(llm().advisorProfile).toBe("quality-optimized");
|
|
901
|
+
expect(llm().profileOrder).toEqual([
|
|
902
|
+
"balanced",
|
|
903
|
+
"os-beta",
|
|
904
|
+
"quality-optimized",
|
|
905
|
+
"cost-optimized",
|
|
906
|
+
]);
|
|
907
|
+
const callSites = llm().callSites as Record<
|
|
908
|
+
string,
|
|
909
|
+
Record<string, unknown>
|
|
910
|
+
>;
|
|
911
|
+
expect(callSites.subagentSpawn?.profile).toBe("balanced");
|
|
912
|
+
expect(callSites.memoryRouter?.profile).toBe("balanced");
|
|
913
|
+
expect(callSites.memoryRouter?.contextWindow).toEqual({
|
|
914
|
+
maxInputTokens: 1000000,
|
|
915
|
+
});
|
|
916
|
+
expectSecondRunNoop();
|
|
917
|
+
});
|
|
918
|
+
|
|
774
919
|
test("a managed-source default entry with body keys is left alone", () => {
|
|
775
920
|
writeConfig({
|
|
776
921
|
llm: {
|
|
@@ -792,7 +937,9 @@ describe("ensureByokDefaultProfiles", () => {
|
|
|
792
937
|
expect(readFileSync(configPath(), "utf-8")).toBe(before);
|
|
793
938
|
});
|
|
794
939
|
|
|
795
|
-
test("a custom copy for a different provider is kept", () => {
|
|
940
|
+
test("a custom copy for a different BYOK provider than the current default is kept", () => {
|
|
941
|
+
// A re-provisioned copy is indistinguishable from a hatch copy for that
|
|
942
|
+
// provider, so only copies matching the default provider convert.
|
|
796
943
|
writeConfig({
|
|
797
944
|
llm: {
|
|
798
945
|
defaultProvider: { provider: "openai" },
|
|
@@ -807,4 +954,142 @@ describe("ensureByokDefaultProfiles", () => {
|
|
|
807
954
|
|
|
808
955
|
expect(readFileSync(configPath(), "utf-8")).toBe(before);
|
|
809
956
|
});
|
|
957
|
+
|
|
958
|
+
test("a vellum default keeps a singleton copy (incomplete set is not hatch provenance)", () => {
|
|
959
|
+
// A lone surviving copy is trivially uniform; the complete-set
|
|
960
|
+
// requirement keeps it.
|
|
961
|
+
const config = uneditedByokConfig();
|
|
962
|
+
const llmConfig = config.llm as Record<string, unknown>;
|
|
963
|
+
llmConfig.defaultProvider = { provider: "vellum" };
|
|
964
|
+
const profileMap = llmConfig.profiles as Record<
|
|
965
|
+
string,
|
|
966
|
+
Record<string, unknown>
|
|
967
|
+
>;
|
|
968
|
+
delete profileMap["custom-quality-optimized"];
|
|
969
|
+
delete profileMap["custom-cost-optimized"];
|
|
970
|
+
writeConfig(config);
|
|
971
|
+
|
|
972
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
973
|
+
|
|
974
|
+
expect(profiles()["custom-balanced"]).toBeDefined();
|
|
975
|
+
expect(llm().activeProfile).toBe("custom-balanced");
|
|
976
|
+
// The stubs are hatch residue regardless and still delete.
|
|
977
|
+
expect(profiles().balanced).toBeUndefined();
|
|
978
|
+
expectSecondRunNoop();
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
test("a vellum default keeps all copies when one was re-provisioned to another provider", () => {
|
|
982
|
+
// A re-provisioned copy breaks provider uniformity and keeps the whole
|
|
983
|
+
// set; the stubs still delete.
|
|
984
|
+
const config = uneditedByokConfig();
|
|
985
|
+
const llmConfig = config.llm as Record<string, unknown>;
|
|
986
|
+
llmConfig.defaultProvider = { provider: "vellum" };
|
|
987
|
+
const profileMap = llmConfig.profiles as Record<
|
|
988
|
+
string,
|
|
989
|
+
Record<string, unknown>
|
|
990
|
+
>;
|
|
991
|
+
profileMap["custom-balanced"] = hatchBody("balanced", "openai");
|
|
992
|
+
writeConfig(config);
|
|
993
|
+
|
|
994
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
995
|
+
|
|
996
|
+
expect(profiles().balanced).toBeUndefined();
|
|
997
|
+
expect(profiles()["quality-optimized"]).toBeUndefined();
|
|
998
|
+
expect(profiles()["cost-optimized"]).toBeUndefined();
|
|
999
|
+
expect(profiles()["custom-balanced"]).toBeDefined();
|
|
1000
|
+
expect(profiles()["custom-quality-optimized"]).toBeDefined();
|
|
1001
|
+
expect(profiles()["custom-cost-optimized"]).toBeDefined();
|
|
1002
|
+
expect(llm().activeProfile).toBe("custom-balanced");
|
|
1003
|
+
expectSecondRunNoop();
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
test("the pre-#39516 onboarding bare-provider connection stamp converts", () => {
|
|
1007
|
+
// Pre-#39516 web onboarding stamped the bare connection name.
|
|
1008
|
+
writeConfig({
|
|
1009
|
+
llm: {
|
|
1010
|
+
defaultProvider: { provider: "anthropic" },
|
|
1011
|
+
activeProfile: "custom-balanced",
|
|
1012
|
+
profiles: {
|
|
1013
|
+
"custom-balanced": {
|
|
1014
|
+
...hatchBody("balanced", "anthropic"),
|
|
1015
|
+
provider_connection: "anthropic",
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
},
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
1022
|
+
|
|
1023
|
+
expect(profiles()["custom-balanced"]).toBeUndefined();
|
|
1024
|
+
expect(llm().activeProfile).toBe("balanced");
|
|
1025
|
+
expectSecondRunNoop();
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
test("a copy for an endpoint-supplied provider is kept even when body-identical to the template", () => {
|
|
1029
|
+
// Its connection can carry a base URL the bare key cannot recover.
|
|
1030
|
+
const body = hatchBody("balanced", "anthropic") as Record<string, unknown>;
|
|
1031
|
+
writeConfig({
|
|
1032
|
+
llm: {
|
|
1033
|
+
defaultProvider: { provider: "anthropic" },
|
|
1034
|
+
profiles: {
|
|
1035
|
+
"custom-balanced": {
|
|
1036
|
+
...body,
|
|
1037
|
+
provider: "openai-compatible",
|
|
1038
|
+
provider_connection: "openai-compatible-personal",
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
},
|
|
1042
|
+
});
|
|
1043
|
+
const before = readFileSync(configPath(), "utf-8");
|
|
1044
|
+
|
|
1045
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
1046
|
+
|
|
1047
|
+
expect(readFileSync(configPath(), "utf-8")).toBe(before);
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
test("a copy disable wins over a re-enabled hatch stub on the same key", () => {
|
|
1051
|
+
const config = uneditedByokConfig();
|
|
1052
|
+
const profileMap = (config.llm as Record<string, unknown>)
|
|
1053
|
+
.profiles as Record<string, Record<string, unknown>>;
|
|
1054
|
+
profileMap["quality-optimized"] = {
|
|
1055
|
+
source: "managed",
|
|
1056
|
+
status: "active",
|
|
1057
|
+
label: "Quality (Managed)",
|
|
1058
|
+
};
|
|
1059
|
+
profileMap["custom-quality-optimized"] = {
|
|
1060
|
+
...profileMap["custom-quality-optimized"],
|
|
1061
|
+
status: "disabled",
|
|
1062
|
+
};
|
|
1063
|
+
writeConfig(config);
|
|
1064
|
+
|
|
1065
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
1066
|
+
|
|
1067
|
+
expect(profiles()["custom-quality-optimized"]).toBeUndefined();
|
|
1068
|
+
expect(profiles()["quality-optimized"]).toEqual({
|
|
1069
|
+
source: "managed",
|
|
1070
|
+
status: "disabled",
|
|
1071
|
+
});
|
|
1072
|
+
expectSecondRunNoop();
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
test("a copy pointing at a non-conventional connection is kept", () => {
|
|
1076
|
+
// A non-conventional reference could be an explicit selection among
|
|
1077
|
+
// several keys; retiring it could switch which key gets billed.
|
|
1078
|
+
writeConfig({
|
|
1079
|
+
llm: {
|
|
1080
|
+
defaultProvider: { provider: "anthropic" },
|
|
1081
|
+
profiles: {
|
|
1082
|
+
"custom-balanced": {
|
|
1083
|
+
...hatchBody("balanced", "anthropic"),
|
|
1084
|
+
provider_connection: "anthropic-work",
|
|
1085
|
+
},
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
});
|
|
1089
|
+
const before = readFileSync(configPath(), "utf-8");
|
|
1090
|
+
|
|
1091
|
+
ensureByokDefaultProfiles(workspaceDir);
|
|
1092
|
+
|
|
1093
|
+
expect(readFileSync(configPath(), "utf-8")).toBe(before);
|
|
1094
|
+
});
|
|
810
1095
|
});
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* `messages`; any other stop reason → stop; non-main-agent call sites →
|
|
9
9
|
* stop; a provider rejection → stop; an entirely-stripped (empty) truncated
|
|
10
10
|
* turn → stop.
|
|
11
|
+
* - Which continuation nudge the hook picks: a truncated turn that emitted
|
|
12
|
+
* only thinking gets the thinking-only nudge; one that emitted partial
|
|
13
|
+
* output keeps the generic continuation.
|
|
11
14
|
* - The per-run budget is split across the two hooks: `post-model-call`
|
|
12
15
|
* consumes one unit per continue (up to `MAX_TOKENS_AUTO_CONTINUES`) and
|
|
13
16
|
* the `stop` hook clears the counter on the definitive terminal so the next
|
|
@@ -33,6 +36,7 @@ import {
|
|
|
33
36
|
} from "../plugins/defaults/max-tokens-continue/continue-state-store.js";
|
|
34
37
|
import postModelCall, {
|
|
35
38
|
MAX_TOKENS_CONTINUE_NUDGE_TEXT,
|
|
39
|
+
MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT,
|
|
36
40
|
} from "../plugins/defaults/max-tokens-continue/hooks/post-model-call.js";
|
|
37
41
|
import stop from "../plugins/defaults/max-tokens-continue/hooks/stop.js";
|
|
38
42
|
import type { ContentBlock } from "../providers/types.js";
|
|
@@ -51,6 +55,20 @@ const truncatedText: ContentBlock = {
|
|
|
51
55
|
text: "Here is the start of a very long answer that got cut o",
|
|
52
56
|
};
|
|
53
57
|
|
|
58
|
+
const thinkingBlock: ContentBlock = {
|
|
59
|
+
type: "thinking",
|
|
60
|
+
thinking: "Writing SVG code... Writing component markup...",
|
|
61
|
+
signature: "sig-abc",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** The nudge text the hook appended after the truncated turn. */
|
|
65
|
+
function appendedNudgeText(ctx: PostModelCallContext): unknown {
|
|
66
|
+
const nudge = ctx.messages[ctx.messages.length - 1];
|
|
67
|
+
return nudge?.content[0] && "text" in nudge.content[0]
|
|
68
|
+
? nudge.content[0].text
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
54
72
|
function makeCtx(
|
|
55
73
|
overrides: Partial<PostModelCallContext> = {},
|
|
56
74
|
): PostModelCallContext {
|
|
@@ -89,6 +107,24 @@ describe("max-tokens-continue NUDGE_TEXT — internal-notice suppression", () =>
|
|
|
89
107
|
"Continue exactly where you stopped",
|
|
90
108
|
);
|
|
91
109
|
});
|
|
110
|
+
|
|
111
|
+
test("the thinking-only nudge names the failure and demands output now", () => {
|
|
112
|
+
expect(MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT).toContain(
|
|
113
|
+
INTERNAL_NUDGE_OUTPUT_SUPPRESSION,
|
|
114
|
+
);
|
|
115
|
+
expect(
|
|
116
|
+
MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT.startsWith("<system_notice>"),
|
|
117
|
+
).toBe(true);
|
|
118
|
+
expect(
|
|
119
|
+
MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT.endsWith("</system_notice>"),
|
|
120
|
+
).toBe(true);
|
|
121
|
+
expect(MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT).toContain(
|
|
122
|
+
"spent its entire output budget inside thinking",
|
|
123
|
+
);
|
|
124
|
+
expect(MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT).toContain(
|
|
125
|
+
"Do not resume planning",
|
|
126
|
+
);
|
|
127
|
+
});
|
|
92
128
|
});
|
|
93
129
|
|
|
94
130
|
describe("max-tokens-continue post-model-call hook", () => {
|
|
@@ -117,6 +153,90 @@ describe("max-tokens-continue post-model-call hook", () => {
|
|
|
117
153
|
});
|
|
118
154
|
});
|
|
119
155
|
|
|
156
|
+
test("thinking-only truncated turn → continue with the thinking-only nudge", async () => {
|
|
157
|
+
/**
|
|
158
|
+
* Tests that a turn which burned its whole budget inside thinking is told
|
|
159
|
+
* so, rather than being invited to resume drafting in thought.
|
|
160
|
+
*/
|
|
161
|
+
// GIVEN a truncated turn carrying only a thinking block.
|
|
162
|
+
const ctx = makeCtx({ content: [thinkingBlock] });
|
|
163
|
+
|
|
164
|
+
// WHEN the hook runs.
|
|
165
|
+
await postModelCall(ctx);
|
|
166
|
+
|
|
167
|
+
// THEN it continues with the thinking-only nudge.
|
|
168
|
+
expect(ctx.decision).toBe("continue");
|
|
169
|
+
expect(appendedNudgeText(ctx)).toBe(MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("thinking plus whitespace-only text → thinking-only nudge", async () => {
|
|
173
|
+
/**
|
|
174
|
+
* Tests that a blank text block does not count as emitted output.
|
|
175
|
+
*/
|
|
176
|
+
// GIVEN a truncated turn whose only text block is whitespace.
|
|
177
|
+
const ctx = makeCtx({
|
|
178
|
+
content: [thinkingBlock, { type: "text", text: " \n" }],
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// WHEN the hook runs.
|
|
182
|
+
await postModelCall(ctx);
|
|
183
|
+
|
|
184
|
+
// THEN it still uses the thinking-only nudge.
|
|
185
|
+
expect(ctx.decision).toBe("continue");
|
|
186
|
+
expect(appendedNudgeText(ctx)).toBe(MAX_TOKENS_THINKING_ONLY_NUDGE_TEXT);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("thinking plus partial text → generic continuation nudge", async () => {
|
|
190
|
+
/**
|
|
191
|
+
* Tests that a turn which did emit output keeps the resume-where-you-left
|
|
192
|
+
* instruction.
|
|
193
|
+
*/
|
|
194
|
+
// GIVEN a truncated turn that emitted thinking and partial text.
|
|
195
|
+
const ctx = makeCtx({ content: [thinkingBlock, truncatedText] });
|
|
196
|
+
|
|
197
|
+
// WHEN the hook runs.
|
|
198
|
+
await postModelCall(ctx);
|
|
199
|
+
|
|
200
|
+
// THEN it continues with the generic nudge.
|
|
201
|
+
expect(ctx.decision).toBe("continue");
|
|
202
|
+
expect(appendedNudgeText(ctx)).toBe(MAX_TOKENS_CONTINUE_NUDGE_TEXT);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("thinking plus a tool call → generic continuation nudge", async () => {
|
|
206
|
+
/**
|
|
207
|
+
* Tests that a tool call counts as emitted output.
|
|
208
|
+
*/
|
|
209
|
+
// GIVEN a truncated turn carrying thinking and a tool call.
|
|
210
|
+
const ctx = makeCtx({
|
|
211
|
+
content: [
|
|
212
|
+
thinkingBlock,
|
|
213
|
+
{ type: "tool_use", id: "tool-1", name: "write_file", input: {} },
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// WHEN the hook runs.
|
|
218
|
+
await postModelCall(ctx);
|
|
219
|
+
|
|
220
|
+
// THEN it continues with the generic nudge.
|
|
221
|
+
expect(ctx.decision).toBe("continue");
|
|
222
|
+
expect(appendedNudgeText(ctx)).toBe(MAX_TOKENS_CONTINUE_NUDGE_TEXT);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("thinking-only turn on a non-max-tokens stop → untouched", async () => {
|
|
226
|
+
/**
|
|
227
|
+
* Tests that the nudge selection never fires outside a max_tokens stop.
|
|
228
|
+
*/
|
|
229
|
+
// GIVEN a thinking-only turn that ended normally.
|
|
230
|
+
const ctx = makeCtx({ content: [thinkingBlock], stopReason: "end_turn" });
|
|
231
|
+
|
|
232
|
+
// WHEN the hook runs.
|
|
233
|
+
await postModelCall(ctx);
|
|
234
|
+
|
|
235
|
+
// THEN nothing is appended.
|
|
236
|
+
expect(ctx.decision).toBe("stop");
|
|
237
|
+
expect(ctx.messages).toHaveLength(1);
|
|
238
|
+
});
|
|
239
|
+
|
|
120
240
|
test("non-max-tokens stop reason → stop", async () => {
|
|
121
241
|
/**
|
|
122
242
|
* Tests that ordinary stop reasons are left alone.
|
|
@@ -834,8 +834,8 @@ describe("Anthropic models on OpenRouter", () => {
|
|
|
834
834
|
});
|
|
835
835
|
|
|
836
836
|
expect(result.pricingStatus).toBe("priced");
|
|
837
|
-
// 0.05M x $1 direct + 0.05M x $
|
|
838
|
-
expect(result.estimatedCostUsd).toBeCloseTo(0.
|
|
837
|
+
// 0.05M x $0.1 direct + 0.05M x $0.125 write + 0.05M x $0.01 read
|
|
838
|
+
expect(result.estimatedCostUsd).toBeCloseTo(0.005 + 0.00625 + 0.0005, 10);
|
|
839
839
|
});
|
|
840
840
|
|
|
841
841
|
test("returns unpriced for unknown non-Anthropic OpenRouter model", () => {
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for default-plugin resident skill discovery.
|
|
3
|
+
*
|
|
4
|
+
* A default plugin ships inside the assistant's own source tree
|
|
5
|
+
* (`plugins/defaults/<dir>/`) rather than under `<workspaceDir>/plugins/`, so
|
|
6
|
+
* its `skills/` directory is enumerated from the compiled-in tree. The walk
|
|
7
|
+
* takes its roots as an argument so these tests can drive it against a temp
|
|
8
|
+
* tree instead of adding fixture plugins to `src/`.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
existsSync,
|
|
12
|
+
mkdirSync,
|
|
13
|
+
mkdtempSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
writeFileSync,
|
|
16
|
+
} from "node:fs";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
20
|
+
|
|
21
|
+
import { getDefaultPluginSkillRoots } from "../../plugins/defaults/main.js";
|
|
22
|
+
import { getWorkspacePluginsDir } from "../../util/platform.js";
|
|
23
|
+
import {
|
|
24
|
+
discoverDefaultPluginResidentSkills,
|
|
25
|
+
discoverPluginResidentSkills,
|
|
26
|
+
mergePluginResidentSkills,
|
|
27
|
+
} from "../skills.js";
|
|
28
|
+
|
|
29
|
+
let tempRoot: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create `<tempRoot>/<dirName>/skills/<id>/SKILL.md` for each skill and return
|
|
33
|
+
* the root descriptor the discovery walk consumes.
|
|
34
|
+
*/
|
|
35
|
+
function defaultPluginRoot(
|
|
36
|
+
dirName: string,
|
|
37
|
+
skills: Array<{ id: string; skillMd?: string }>,
|
|
38
|
+
): { pluginName: string; skillsDir: string } {
|
|
39
|
+
const skillsDir = join(tempRoot, dirName, "skills");
|
|
40
|
+
for (const skill of skills) {
|
|
41
|
+
const skillDir = join(skillsDir, skill.id);
|
|
42
|
+
mkdirSync(skillDir, { recursive: true });
|
|
43
|
+
writeFileSync(
|
|
44
|
+
join(skillDir, "SKILL.md"),
|
|
45
|
+
skill.skillMd ??
|
|
46
|
+
`---\nname: ${skill.id}\ndescription: Description for ${skill.id}.\n---\n\nBody for ${skill.id}.\n`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return { pluginName: `default-${dirName}`, skillsDir };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Install a workspace plugin shipping the given skills. */
|
|
53
|
+
function writeWorkspacePlugin(dirName: string, skillIds: string[]): void {
|
|
54
|
+
const pluginDir = join(getWorkspacePluginsDir(), dirName);
|
|
55
|
+
mkdirSync(pluginDir, { recursive: true });
|
|
56
|
+
writeFileSync(
|
|
57
|
+
join(pluginDir, "package.json"),
|
|
58
|
+
JSON.stringify({ name: dirName, version: "1.0.0" }),
|
|
59
|
+
);
|
|
60
|
+
for (const id of skillIds) {
|
|
61
|
+
const skillDir = join(pluginDir, "skills", id);
|
|
62
|
+
mkdirSync(skillDir, { recursive: true });
|
|
63
|
+
writeFileSync(
|
|
64
|
+
join(skillDir, "SKILL.md"),
|
|
65
|
+
`---\nname: ${id}\ndescription: Workspace plugin copy of ${id}.\n---\n\nBody.\n`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Write the `.disabled` sentinel the CLI writes for `pluginName`. */
|
|
71
|
+
function disablePlugin(pluginName: string): void {
|
|
72
|
+
const dir = join(getWorkspacePluginsDir(), pluginName);
|
|
73
|
+
mkdirSync(dir, { recursive: true });
|
|
74
|
+
writeFileSync(join(dir, ".disabled"), "");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
describe("default plugin resident skills", () => {
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
const pluginsDir = getWorkspacePluginsDir();
|
|
80
|
+
if (existsSync(pluginsDir)) {
|
|
81
|
+
rmSync(pluginsDir, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
tempRoot = mkdtempSync(join(tmpdir(), "default-plugin-skills-"));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
rmSync(tempRoot, { recursive: true, force: true });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("surfaces a default plugin's resident skill, owned by its default- name", () => {
|
|
91
|
+
const root = defaultPluginRoot("fixture", [{ id: "qa-fixture-skill" }]);
|
|
92
|
+
|
|
93
|
+
const skills = discoverDefaultPluginResidentSkills([root]);
|
|
94
|
+
|
|
95
|
+
expect(skills).toHaveLength(1);
|
|
96
|
+
expect(skills[0]!.id).toBe("qa-fixture-skill");
|
|
97
|
+
expect(skills[0]!.source).toBe("plugin");
|
|
98
|
+
expect(skills[0]!.owner).toEqual({
|
|
99
|
+
kind: "plugin",
|
|
100
|
+
id: "default-fixture",
|
|
101
|
+
});
|
|
102
|
+
expect(skills[0]!.description).toBe("Description for qa-fixture-skill.");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("hides a default plugin's skills when the plugin is disabled", () => {
|
|
106
|
+
const root = defaultPluginRoot("fixture", [{ id: "qa-fixture-skill" }]);
|
|
107
|
+
disablePlugin("default-fixture");
|
|
108
|
+
|
|
109
|
+
expect(discoverDefaultPluginResidentSkills([root])).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("an installed plugin's skill of the same id overrides the default one", () => {
|
|
113
|
+
const root = defaultPluginRoot("fixture", [
|
|
114
|
+
{ id: "qa-shared-skill" },
|
|
115
|
+
{ id: "qa-default-only" },
|
|
116
|
+
]);
|
|
117
|
+
writeWorkspacePlugin("installed-fixture", ["qa-shared-skill"]);
|
|
118
|
+
|
|
119
|
+
// The installed side comes from the real zero-arg discovery (the shipped
|
|
120
|
+
// defaults tree contributes nothing), the default side from the fixture.
|
|
121
|
+
const skills = mergePluginResidentSkills(
|
|
122
|
+
discoverDefaultPluginResidentSkills([root]),
|
|
123
|
+
discoverPluginResidentSkills(),
|
|
124
|
+
);
|
|
125
|
+
const shared = skills.filter((skill) => skill.id === "qa-shared-skill");
|
|
126
|
+
|
|
127
|
+
expect(shared).toHaveLength(1);
|
|
128
|
+
expect(shared[0]!.owner).toEqual({
|
|
129
|
+
kind: "plugin",
|
|
130
|
+
id: "installed-fixture",
|
|
131
|
+
});
|
|
132
|
+
// The default plugin's other skills are unaffected by the override.
|
|
133
|
+
expect(
|
|
134
|
+
skills.find((skill) => skill.id === "qa-default-only")?.owner,
|
|
135
|
+
).toEqual({ kind: "plugin", id: "default-fixture" });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("skips a malformed SKILL.md and still surfaces its valid siblings", () => {
|
|
139
|
+
const root = defaultPluginRoot("fixture", [
|
|
140
|
+
{ id: "qa-malformed-skill", skillMd: "No frontmatter here.\n" },
|
|
141
|
+
{ id: "qa-missing-description", skillMd: "---\nname: x\n---\n\nBody.\n" },
|
|
142
|
+
{ id: "qa-valid-skill" },
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
const skills = discoverDefaultPluginResidentSkills([root]);
|
|
146
|
+
|
|
147
|
+
expect(skills.map((skill) => skill.id)).toEqual(["qa-valid-skill"]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("getDefaultPluginSkillRoots reports no roots until a default plugin ships skills", () => {
|
|
151
|
+
// Every root it reports must be a `default-`-prefixed plugin name; today no
|
|
152
|
+
// default plugin ships a `skills/` directory, so the set is empty.
|
|
153
|
+
for (const root of getDefaultPluginSkillRoots()) {
|
|
154
|
+
expect(root.pluginName).toMatch(/^default-[a-z0-9-]+$/);
|
|
155
|
+
}
|
|
156
|
+
expect(getDefaultPluginSkillRoots()).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
});
|