@gmickel/gno 1.22.0 → 1.23.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.
Files changed (42) hide show
  1. package/README.md +16 -1
  2. package/assets/skill/SKILL.md +15 -0
  3. package/package.json +1 -1
  4. package/spec/cli.md +36 -20
  5. package/spec/evals-agentic.md +35 -0
  6. package/spec/evals.md +6 -0
  7. package/spec/mcp.md +18 -0
  8. package/spec/output-schemas/query-diagnose-v1.schema.json +123 -0
  9. package/spec/output-schemas/query-diagnose.schema.json +89 -2
  10. package/src/app/context-runtime-types.ts +3 -0
  11. package/src/app/context-runtime.ts +1 -0
  12. package/src/app/context-surface.ts +4 -2
  13. package/src/cli/commands/ask.ts +31 -20
  14. package/src/cli/commands/context-build.ts +17 -7
  15. package/src/cli/commands/query.ts +58 -37
  16. package/src/cli/commands/search.ts +29 -19
  17. package/src/cli/commands/vsearch.ts +31 -22
  18. package/src/cli/options.ts +39 -0
  19. package/src/cli/program.ts +48 -0
  20. package/src/config/defaults.ts +10 -1
  21. package/src/config/types.ts +71 -0
  22. package/src/core/project-affinity-surface.ts +114 -0
  23. package/src/core/project-affinity.ts +330 -0
  24. package/src/core/validation.ts +20 -1
  25. package/src/mcp/tools/ask.ts +10 -1
  26. package/src/mcp/tools/context.ts +18 -0
  27. package/src/mcp/tools/index.ts +13 -2
  28. package/src/mcp/tools/query.ts +12 -0
  29. package/src/mcp/tools/search.ts +7 -0
  30. package/src/mcp/tools/vsearch.ts +7 -0
  31. package/src/pipeline/diagnose.ts +48 -3
  32. package/src/pipeline/explain.ts +54 -13
  33. package/src/pipeline/hybrid.ts +100 -59
  34. package/src/pipeline/project-affinity.ts +162 -0
  35. package/src/pipeline/search.ts +76 -10
  36. package/src/pipeline/types.ts +9 -0
  37. package/src/pipeline/vsearch.ts +117 -91
  38. package/src/sdk/client.ts +80 -20
  39. package/src/sdk/index.ts +2 -0
  40. package/src/sdk/types.ts +20 -7
  41. package/src/serve/context-capsule.ts +18 -1
  42. package/src/serve/routes/api.ts +69 -0
@@ -32,7 +32,9 @@ import { CliError } from "./errors";
32
32
  import {
33
33
  assertFormatSupported,
34
34
  CMD,
35
+ collectRepeatableValue,
35
36
  getDefaultLimit,
37
+ parseCliProjectAffinityOptions,
36
38
  parseOptionalFloat,
37
39
  parsePositiveInt,
38
40
  } from "./options";
@@ -594,6 +596,13 @@ function wireSearchCommands(program: Command): void {
594
596
  )
595
597
  .option("--tags-all <tags>", "require ALL tags (comma-separated)")
596
598
  .option("--tags-any <tags>", "require ANY tag (comma-separated)")
599
+ .option(
600
+ "--project-root <path>",
601
+ "trusted project root (repeatable; replaces cwd affinity)",
602
+ collectRepeatableValue,
603
+ []
604
+ )
605
+ .option("--no-project-affinity", "disable project-aware ranking")
597
606
  .option("--full", "include full content")
598
607
  .option("--line-numbers", "include line numbers in output")
599
608
  .option("--json", "JSON output")
@@ -641,6 +650,7 @@ function wireSearchCommands(program: Command): void {
641
650
  : getDefaultLimit(format);
642
651
  const categories = parseCsvValues(cmdOpts.category);
643
652
  const exclude = parseCsvValues(cmdOpts.exclude);
653
+ const projectAffinity = parseCliProjectAffinityOptions(cmdOpts);
644
654
 
645
655
  const { search, formatSearch } = await import("./commands/search");
646
656
  const result = await search(queryText, {
@@ -658,6 +668,7 @@ function wireSearchCommands(program: Command): void {
658
668
  exclude,
659
669
  tagsAll,
660
670
  tagsAny,
671
+ ...projectAffinity,
661
672
  full: Boolean(cmdOpts.full),
662
673
  lineNumbers: Boolean(cmdOpts.lineNumbers),
663
674
  json: format === "json",
@@ -714,6 +725,13 @@ function wireSearchCommands(program: Command): void {
714
725
  )
715
726
  .option("--tags-all <tags>", "require ALL tags (comma-separated)")
716
727
  .option("--tags-any <tags>", "require ANY tag (comma-separated)")
728
+ .option(
729
+ "--project-root <path>",
730
+ "trusted project root (repeatable; replaces cwd affinity)",
731
+ collectRepeatableValue,
732
+ []
733
+ )
734
+ .option("--no-project-affinity", "disable project-aware ranking")
717
735
  .option("--full", "include full content")
718
736
  .option("--line-numbers", "include line numbers in output")
719
737
  .option("--json", "JSON output")
@@ -759,6 +777,7 @@ function wireSearchCommands(program: Command): void {
759
777
  : getDefaultLimit(format);
760
778
  const categories = parseCsvValues(cmdOpts.category);
761
779
  const exclude = parseCsvValues(cmdOpts.exclude);
780
+ const projectAffinity = parseCliProjectAffinityOptions(cmdOpts);
762
781
 
763
782
  const { vsearch, formatVsearch } = await import("./commands/vsearch");
764
783
  const result = await vsearch(queryText, {
@@ -776,6 +795,7 @@ function wireSearchCommands(program: Command): void {
776
795
  exclude,
777
796
  tagsAll,
778
797
  tagsAny,
798
+ ...projectAffinity,
779
799
  full: Boolean(cmdOpts.full),
780
800
  lineNumbers: Boolean(cmdOpts.lineNumbers),
781
801
  json: format === "json",
@@ -827,6 +847,13 @@ function wireSearchCommands(program: Command): void {
827
847
  )
828
848
  .option("--tags-all <tags>", "require ALL tags (comma-separated)")
829
849
  .option("--tags-any <tags>", "require ANY tag (comma-separated)")
850
+ .option(
851
+ "--project-root <path>",
852
+ "trusted project root (repeatable; replaces cwd affinity)",
853
+ collectRepeatableValue,
854
+ []
855
+ )
856
+ .option("--no-project-affinity", "disable project-aware ranking")
830
857
  .option("--full", "include full content")
831
858
  .option("--line-numbers", "include line numbers in output")
832
859
  .option("--fast", "skip expansion and reranking (fastest, ~0.7s)")
@@ -931,6 +958,7 @@ function wireSearchCommands(program: Command): void {
931
958
  : undefined;
932
959
  const categories = parseCsvValues(cmdOpts.category);
933
960
  const exclude = parseCsvValues(cmdOpts.exclude);
961
+ const projectAffinity = parseCliProjectAffinityOptions(cmdOpts);
934
962
 
935
963
  const depthPolicy = resolveDepthPolicy({
936
964
  presetId: activePresetId,
@@ -960,6 +988,7 @@ function wireSearchCommands(program: Command): void {
960
988
  exclude,
961
989
  tagsAll,
962
990
  tagsAny,
991
+ ...projectAffinity,
963
992
  noExpand: depthPolicy.noExpand,
964
993
  noRerank: depthPolicy.noRerank,
965
994
  graph: Boolean(cmdOpts.graph),
@@ -995,6 +1024,7 @@ function wireSearchCommands(program: Command): void {
995
1024
  exclude,
996
1025
  tagsAll,
997
1026
  tagsAny,
1027
+ ...projectAffinity,
998
1028
  full: Boolean(cmdOpts.full),
999
1029
  lineNumbers: Boolean(cmdOpts.lineNumbers),
1000
1030
  noExpand: depthPolicy.noExpand,
@@ -1121,6 +1151,13 @@ function wireSearchCommands(program: Command): void {
1121
1151
  .option("--context-budget-bytes <num>", "verified Context byte budget")
1122
1152
  .option("--min-score <score>", "minimum retrieval score (0-1)")
1123
1153
  .option("--graph", "include bounded graph expansion")
1154
+ .option(
1155
+ "--project-root <path>",
1156
+ "trusted project root (repeatable; replaces cwd affinity)",
1157
+ collectRepeatableValue,
1158
+ []
1159
+ )
1160
+ .option("--no-project-affinity", "disable project-aware ranking")
1124
1161
  .option("--show-sources", "show all retrieved sources (not just cited)")
1125
1162
  .option("--json", "JSON output")
1126
1163
  .option("--md", "Markdown output")
@@ -1169,6 +1206,7 @@ function wireSearchCommands(program: Command): void {
1169
1206
  }
1170
1207
  const categories = parseCsvValues(cmdOpts.category);
1171
1208
  const exclude = parseCsvValues(cmdOpts.exclude);
1209
+ const projectAffinity = parseCliProjectAffinityOptions(cmdOpts);
1172
1210
 
1173
1211
  let queryModes: import("../pipeline/types").QueryModeInput[] | undefined;
1174
1212
  if (Array.isArray(cmdOpts.queryMode) && cmdOpts.queryMode.length > 0) {
@@ -1229,6 +1267,7 @@ function wireSearchCommands(program: Command): void {
1229
1267
  maxAnswerTokens,
1230
1268
  contextBudgetTokens,
1231
1269
  contextBudgetBytes,
1270
+ ...projectAffinity,
1232
1271
  showSources,
1233
1272
  json: format === "json",
1234
1273
  md: format === "md",
@@ -1974,6 +2013,13 @@ function wireManagementCommands(program: Command): void {
1974
2013
  .option("--since <date>", "modified-at lower bound")
1975
2014
  .option("--until <date>", "modified-at upper bound")
1976
2015
  .option("--graph", "enable graph neighbor expansion")
2016
+ .option(
2017
+ "--project-root <path>",
2018
+ "trusted project root (repeatable; replaces cwd affinity)",
2019
+ collectRepeatableValue,
2020
+ []
2021
+ )
2022
+ .option("--no-project-affinity", "disable project-aware ranking")
1977
2023
  .option("--fast", "use lexical-first fast retrieval")
1978
2024
  .option("--thorough", "use a wider retrieval pool")
1979
2025
  .option("-n, --limit <num>", "maximum retrieved results")
@@ -1991,6 +2037,7 @@ function wireManagementCommands(program: Command): void {
1991
2037
  throw new CliError("VALIDATION", "Choose either --fast or --thorough");
1992
2038
  }
1993
2039
  const globals = getGlobals();
2040
+ const projectAffinity = parseCliProjectAffinityOptions(cmdOpts);
1994
2041
  const { contextBuild } = await import("./commands/context-build");
1995
2042
  let queryModes: import("../pipeline/types").QueryModeInput[] | undefined;
1996
2043
  if (Array.isArray(cmdOpts.queryMode) && cmdOpts.queryMode.length > 0) {
@@ -2022,6 +2069,7 @@ function wireManagementCommands(program: Command): void {
2022
2069
  true
2023
2070
  ),
2024
2071
  query: cmdOpts.query as string | undefined,
2072
+ ...projectAffinity,
2025
2073
  queryModes,
2026
2074
  collections: cmdOpts.collection as string[],
2027
2075
  uriPrefix: cmdOpts.uriPrefix as string | undefined,
@@ -4,7 +4,12 @@
4
4
  * @module src/config/defaults
5
5
  */
6
6
 
7
- import { CONFIG_VERSION, type Config, DEFAULT_FTS_TOKENIZER } from "./types";
7
+ import {
8
+ CONFIG_VERSION,
9
+ type Config,
10
+ DEFAULT_FTS_TOKENIZER,
11
+ PROJECT_AFFINITY_MAX_CONTRIBUTION,
12
+ } from "./types";
8
13
 
9
14
  /**
10
15
  * Create a default config object.
@@ -17,5 +22,9 @@ export function createDefaultConfig(): Config {
17
22
  collections: [],
18
23
  contexts: [],
19
24
  contentTypes: [],
25
+ projectAffinity: {
26
+ enabled: true,
27
+ contribution: PROJECT_AFFINITY_MAX_CONTRIBUTION,
28
+ },
20
29
  };
21
30
  }
@@ -115,6 +115,74 @@ export const CollectionSchema = z.object({
115
115
  export type Collection = z.infer<typeof CollectionSchema>;
116
116
  export type CollectionModelOverrides = NonNullable<Collection["models"]>;
117
117
 
118
+ // ─────────────────────────────────────────────────────────────────────────────
119
+ // Project Affinity Input
120
+ // ─────────────────────────────────────────────────────────────────────────────
121
+
122
+ export const TrustedProjectRootSourceSchema = z.enum([
123
+ "cli_cwd",
124
+ "cli_explicit",
125
+ "cli_worktree",
126
+ ]);
127
+ export type TrustedProjectRootSource = z.infer<
128
+ typeof TrustedProjectRootSourceSchema
129
+ >;
130
+
131
+ export const LocalProjectAffinityRootSchema = z.object({
132
+ source: TrustedProjectRootSourceSchema,
133
+ path: z.string().min(1),
134
+ });
135
+ export type LocalProjectAffinityRoot = z.infer<
136
+ typeof LocalProjectAffinityRootSchema
137
+ >;
138
+
139
+ export const RemoteProjectAffinityRootSchema = z.object({
140
+ source: z.literal("remote_hint"),
141
+ hint: z.string().min(1),
142
+ });
143
+ export type RemoteProjectAffinityRoot = z.infer<
144
+ typeof RemoteProjectAffinityRootSchema
145
+ >;
146
+
147
+ export const ProjectAffinityRootSchema = z.discriminatedUnion("source", [
148
+ LocalProjectAffinityRootSchema,
149
+ RemoteProjectAffinityRootSchema,
150
+ ]);
151
+ export type ProjectAffinityRoot = z.infer<typeof ProjectAffinityRootSchema>;
152
+
153
+ export const LocalProjectAffinityInputSchema = z.object({
154
+ roots: z.array(LocalProjectAffinityRootSchema).max(16).default([]),
155
+ });
156
+ export type LocalProjectAffinityInput = z.infer<
157
+ typeof LocalProjectAffinityInputSchema
158
+ >;
159
+
160
+ export const RemoteProjectAffinityInputSchema = z.object({
161
+ roots: z.array(RemoteProjectAffinityRootSchema).max(16).default([]),
162
+ });
163
+ export type RemoteProjectAffinityInput = z.infer<
164
+ typeof RemoteProjectAffinityInputSchema
165
+ >;
166
+
167
+ export const ProjectAffinityInputSchema = z.object({
168
+ roots: z.array(ProjectAffinityRootSchema).max(16).default([]),
169
+ });
170
+ export type ProjectAffinityInput = z.infer<typeof ProjectAffinityInputSchema>;
171
+
172
+ export const PROJECT_AFFINITY_MAX_CONTRIBUTION = 0.03;
173
+ export const AUXILIARY_RANKING_MAX_CONTRIBUTION = 0.08;
174
+
175
+ export const ProjectAffinityConfigSchema = z.object({
176
+ enabled: z.boolean().default(true),
177
+ contribution: z
178
+ .number()
179
+ .finite()
180
+ .min(0)
181
+ .max(PROJECT_AFFINITY_MAX_CONTRIBUTION)
182
+ .default(PROJECT_AFFINITY_MAX_CONTRIBUTION),
183
+ });
184
+ export type ProjectAffinityConfig = z.infer<typeof ProjectAffinityConfigSchema>;
185
+
118
186
  // ─────────────────────────────────────────────────────────────────────────────
119
187
  // Context Schema
120
188
  // ─────────────────────────────────────────────────────────────────────────────
@@ -342,6 +410,9 @@ export const ConfigSchema = z.object({
342
410
 
343
411
  /** Private local retrieval trace recording. Absent means recording off. */
344
412
  retrievalTraces: RetrievalTraceConfigSchema.optional(),
413
+
414
+ /** Bounded project-aware retrieval affinity. */
415
+ projectAffinity: ProjectAffinityConfigSchema.optional(),
345
416
  });
346
417
 
347
418
  export type Config = Omit<z.infer<typeof ConfigSchema>, "contentTypes"> & {
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Shared trust boundary for caller-supplied project affinity.
3
+ *
4
+ * Raw roots and hints stop here. Retrieval pipelines receive only the resolved,
5
+ * redaction-safe scoring input.
6
+ *
7
+ * @module src/core/project-affinity-surface
8
+ */
9
+
10
+ import type { Config, ProjectAffinityInput } from "../config/types";
11
+ import type { ProjectAffinityScoringInput } from "../pipeline/project-affinity";
12
+
13
+ import { resolveProjectAffinity } from "./project-affinity";
14
+
15
+ export const MAX_PROJECT_AFFINITY_INPUTS = 16;
16
+
17
+ export interface CliProjectAffinityRequest {
18
+ projectAffinityDisabled?: boolean;
19
+ projectRoots?: string[];
20
+ }
21
+
22
+ export class ProjectAffinityInputError extends Error {
23
+ constructor(message: string) {
24
+ super(message);
25
+ this.name = "ProjectAffinityInputError";
26
+ }
27
+ }
28
+
29
+ const compareCodeUnits = (left: string, right: string): number =>
30
+ left < right ? -1 : left > right ? 1 : 0;
31
+
32
+ export const normalizeProjectAffinityValues = (
33
+ values: readonly string[] | undefined,
34
+ label: "project hints" | "project roots"
35
+ ): string[] => {
36
+ if (values === undefined) return [];
37
+ if (
38
+ !Array.isArray(values) ||
39
+ values.length > MAX_PROJECT_AFFINITY_INPUTS ||
40
+ values.some((value) => typeof value !== "string")
41
+ ) {
42
+ throw new ProjectAffinityInputError(
43
+ `${label} must contain at most ${MAX_PROJECT_AFFINITY_INPUTS} strings`
44
+ );
45
+ }
46
+ const normalized = [
47
+ ...new Set(values.map((value) => value.normalize("NFC").trim())),
48
+ ].sort(compareCodeUnits);
49
+ if (normalized.some((value) => value.length === 0)) {
50
+ throw new ProjectAffinityInputError(
51
+ `${label} must not contain empty values`
52
+ );
53
+ }
54
+ return normalized;
55
+ };
56
+
57
+ const scoringInput = async (
58
+ input: ProjectAffinityInput,
59
+ config: Config,
60
+ channel: "local" | "remote"
61
+ ): Promise<ProjectAffinityScoringInput> => ({
62
+ enabled: config.projectAffinity?.enabled,
63
+ contribution: config.projectAffinity?.contribution,
64
+ resolution: await resolveProjectAffinity(input, config.collections, {
65
+ channel,
66
+ }),
67
+ });
68
+
69
+ export const resolveCliProjectAffinity = async (
70
+ config: Config,
71
+ options: {
72
+ cwd: string;
73
+ disabled?: boolean;
74
+ projectRoots?: readonly string[];
75
+ }
76
+ ): Promise<ProjectAffinityScoringInput | undefined> => {
77
+ const projectRoots = normalizeProjectAffinityValues(
78
+ options.projectRoots,
79
+ "project roots"
80
+ );
81
+ if (options.disabled && projectRoots.length > 0) {
82
+ throw new ProjectAffinityInputError(
83
+ "--no-project-affinity cannot be combined with --project-root"
84
+ );
85
+ }
86
+ if (options.disabled || config.projectAffinity?.enabled === false) return;
87
+
88
+ const roots =
89
+ projectRoots.length > 0
90
+ ? projectRoots.map((path) => ({
91
+ path,
92
+ source: "cli_explicit" as const,
93
+ }))
94
+ : [{ path: options.cwd, source: "cli_cwd" as const }];
95
+ return scoringInput({ roots }, config, "local");
96
+ };
97
+
98
+ export const resolveRemoteProjectAffinity = async (
99
+ config: Config,
100
+ projectHints: readonly string[] | undefined
101
+ ): Promise<ProjectAffinityScoringInput | undefined> => {
102
+ const hints = normalizeProjectAffinityValues(projectHints, "project hints");
103
+ if (hints.length === 0 || config.projectAffinity?.enabled === false) return;
104
+ return scoringInput(
105
+ {
106
+ roots: hints.map((hint) => ({
107
+ hint,
108
+ source: "remote_hint" as const,
109
+ })),
110
+ },
111
+ config,
112
+ "remote"
113
+ );
114
+ };