Skip to content

Commit 3abac09

Browse files
authored
fix(cli): name SIM_CONFIG_DIR in help, and fix the similarity score width (#6795)
Two loose ends from the command-surface audit. `--help` stated where the profile files live and named only `~/.sim`, so it was wrong for anyone who had set `SIM_CONFIG_DIR` — which every CI job pointing the CLI at a scratch directory has. The variable is documented in the README and the guides; help was the one place that omitted it. `knowledge search` printed the raw similarity double, `0.2818957269585687`: a nineteen-character column whose last dozen digits cannot separate one result from another. A `score` format fixes it to four decimals, the width `cost` already uses, so the column stays put down the page. `json` and `yaml` still carry the full double, which is what a script compares.
1 parent aa367a4 commit 3abac09

7 files changed

Lines changed: 45 additions & 3 deletions

File tree

packages/sim-cli/src/contract/commands.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import type { Command } from 'commander'
55
import { describe, expect, it } from 'vitest'
66
import { V2_OPERATIONS, type V2OperationName } from '../generated/v2-api'
7+
import { HELP_EPILOGUE } from '../program'
78
import { buildGeneratedCommands } from '../runtime/build'
89
import { flagNameFor, flagSpecFor } from '../runtime/request'
910
import type { OperationSpec } from '../runtime/types'
@@ -193,4 +194,12 @@ describe('folder-path fields', () => {
193194
expect(paths).toContain('serviceId')
194195
expect(paths).toContain('providerId')
195196
})
197+
198+
it('mentions the variable that moves the profile files, since help names a path', () => {
199+
// The epilogue states where the files live, and SIM_CONFIG_DIR moves both.
200+
// Naming only ~/.sim made help wrong for anyone who had set it — including
201+
// every CI job that points the CLI at a scratch directory.
202+
expect(HELP_EPILOGUE).toContain('~/.sim/config')
203+
expect(HELP_EPILOGUE).toContain('SIM_CONFIG_DIR')
204+
})
196205
})

packages/sim-cli/src/contract/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export const CLI_CONTRACT: CliContract = {
259259
},
260260
itemsPath: 'results',
261261
columns: [
262-
{ header: 'score', path: 'similarity' },
262+
{ header: 'score', path: 'similarity', format: 'score' },
263263
{ header: 'document', path: 'documentName' },
264264
{ header: 'chunk', path: 'chunkIndex' },
265265
{ header: 'content' },

packages/sim-cli/src/contract/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ export interface ColumnSpec {
123123
* wire encoding for the human formats, so a folder no longer prints as
124124
* `/cli-test-a/nested%20one` in the same row as the `nested one` the server
125125
* put in the adjacent name column.
126+
*
127+
* `score` fixes a similarity to four decimals. The raw double arrives as
128+
* `0.2818957269585687`, a nineteen-character column whose last dozen digits
129+
* cannot separate one result from another.
126130
*/
127131
format?:
128132
| 'auto'
@@ -134,6 +138,7 @@ export interface ColumnSpec {
134138
| 'count'
135139
| 'trace-count'
136140
| 'folder-path'
141+
| 'score'
137142
}
138143

139144
export interface BodyVariantSpec {

packages/sim-cli/src/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const PROGRAM_DESCRIPTION = 'Talk to the Sim API from your terminal'
1313

1414
export const HELP_EPILOGUE = `
1515
Profiles work like the AWS CLI: settings live in ~/.sim/config, keys in
16-
~/.sim/credentials (0600). Select one with -P, --profile, or SIM_PROFILE.
16+
~/.sim/credentials (0600), or under SIM_CONFIG_DIR when it is set. Select one
17+
with -P, --profile, or SIM_PROFILE.
1718
1819
Examples:
1920
$ sim login Authorize the default profile

packages/sim-cli/src/runtime/build.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,9 @@ describe('contract-selected list rendering', () => {
881881
totalResults: 1,
882882
})
883883

884-
expect(printed).toEqual(['0.91\tpolicy.md\t2\tRefunds are available for 30 days.'])
884+
// Four decimals, fixed, like the `cost` column: a similarity is compared
885+
// against its neighbours, so the width has to stay put down the column.
886+
expect(printed).toEqual(['0.9100\tpolicy.md\t2\tRefunds are available for 30 days.'])
885887
})
886888

887889
it('renders row matches as rows', async () => {

packages/sim-cli/src/runtime/result.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,29 @@ describe('a declared field that the API stops returning', () => {
172172
})
173173
})
174174

175+
describe('a similarity score, at a width a person can read', () => {
176+
const results = {
177+
results: [
178+
{ similarity: 0.2818957269585687, documentName: 'a.md', chunkIndex: 0, content: 'x' },
179+
],
180+
}
181+
const spec = CLI_CONTRACT.searchKnowledge as CommandSpec
182+
183+
it('fixes the score to four decimals in the table', () => {
184+
// The raw double is nineteen characters wide and its last dozen digits
185+
// separate nothing: every row shares them to within a rounding error.
186+
renderResult('searchKnowledge', 'table', results, spec)
187+
const [, row] = tableLines()
188+
expect(row).toContain('0.2819')
189+
expect(row).not.toContain('0.2818957269585687')
190+
})
191+
192+
it('leaves the full double in json, which is what a script compares', () => {
193+
renderResult('searchKnowledge', 'json', results, spec)
194+
expect(JSON.parse(logged[0]).results[0].similarity).toBe(0.2818957269585687)
195+
})
196+
})
197+
175198
describe('folder paths are shown by name, but piped in wire form', () => {
176199
const folders = [
177200
{

packages/sim-cli/src/runtime/result.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ function renderCell(
8080
return bool(value as boolean | null)
8181
case 'cost':
8282
return typeof value === 'number' ? `$${value.toFixed(4)}` : text(null)
83+
case 'score':
84+
return typeof value === 'number' ? value.toFixed(4) : text(null)
8385
case 'count':
8486
return Array.isArray(value) ? String(value.length) : text(null)
8587
case 'folder-path':

0 commit comments

Comments
 (0)