@owlmeans/llm-common 0.1.18-rc.9 → 0.1.18
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/README.md +2 -2
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/llm-common/SKILL.md +64 -12
- package/build/consts.d.ts +107 -7
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +125 -5
- package/build/consts.js.map +1 -1
- package/build/delegate/consts.d.ts +25 -0
- package/build/delegate/consts.d.ts.map +1 -0
- package/build/delegate/consts.js +28 -0
- package/build/delegate/consts.js.map +1 -0
- package/build/delegate/index.d.ts +3 -0
- package/build/delegate/index.d.ts.map +1 -0
- package/build/delegate/index.js +3 -0
- package/build/delegate/index.js.map +1 -0
- package/build/delegate/types.d.ts +85 -0
- package/build/delegate/types.d.ts.map +1 -0
- package/build/delegate/types.js +13 -0
- package/build/delegate/types.js.map +1 -0
- package/build/files/types.d.ts +10 -0
- package/build/files/types.d.ts.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/inquiry/consts.d.ts +48 -0
- package/build/inquiry/consts.d.ts.map +1 -0
- package/build/inquiry/consts.js +50 -0
- package/build/inquiry/consts.js.map +1 -0
- package/build/inquiry/helper/types.d.ts +47 -0
- package/build/inquiry/helper/types.d.ts.map +1 -0
- package/build/inquiry/helper/types.js +2 -0
- package/build/inquiry/helper/types.js.map +1 -0
- package/build/inquiry/helper.d.ts +4 -0
- package/build/inquiry/helper.d.ts.map +1 -0
- package/build/inquiry/helper.js +39 -0
- package/build/inquiry/helper.js.map +1 -0
- package/build/inquiry/index.d.ts +6 -0
- package/build/inquiry/index.d.ts.map +1 -0
- package/build/inquiry/index.js +4 -0
- package/build/inquiry/index.js.map +1 -0
- package/build/inquiry/types.d.ts +72 -0
- package/build/inquiry/types.d.ts.map +1 -0
- package/build/inquiry/types.js +2 -0
- package/build/inquiry/types.js.map +1 -0
- package/build/inquiry/utils.d.ts +14 -0
- package/build/inquiry/utils.d.ts.map +1 -0
- package/build/inquiry/utils.js +14 -0
- package/build/inquiry/utils.js.map +1 -0
- package/build/results/consts.d.ts +19 -0
- package/build/results/consts.d.ts.map +1 -0
- package/build/results/consts.js +30 -0
- package/build/results/consts.js.map +1 -0
- package/build/results/consts.local.d.ts +3 -0
- package/build/results/consts.local.d.ts.map +1 -0
- package/build/results/consts.local.js +3 -0
- package/build/results/consts.local.js.map +1 -0
- package/build/results/index.d.ts +4 -0
- package/build/results/index.d.ts.map +1 -0
- package/build/results/index.js +3 -0
- package/build/results/index.js.map +1 -0
- package/build/results/types.d.ts +37 -0
- package/build/results/types.d.ts.map +1 -0
- package/build/results/types.js +2 -0
- package/build/results/types.js.map +1 -0
- package/build/results/utils.d.ts +11 -0
- package/build/results/utils.d.ts.map +1 -0
- package/build/results/utils.js +27 -0
- package/build/results/utils.js.map +1 -0
- package/build/spectator/types.d.ts +6 -0
- package/build/spectator/types.d.ts.map +1 -1
- package/build/types.d.ts +99 -7
- package/build/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/consts.ts +129 -5
- package/src/delegate/consts.ts +26 -0
- package/src/delegate/index.ts +2 -0
- package/src/delegate/types.ts +91 -0
- package/src/files/types.ts +11 -0
- package/src/index.ts +3 -0
- package/src/inquiry/consts.ts +52 -0
- package/src/inquiry/helper/types.ts +47 -0
- package/src/inquiry/helper.ts +53 -0
- package/src/inquiry/index.ts +5 -0
- package/src/inquiry/types.ts +77 -0
- package/src/inquiry/utils.ts +20 -0
- package/src/results/consts.local.ts +2 -0
- package/src/results/consts.ts +32 -0
- package/src/results/index.ts +3 -0
- package/src/results/types.ts +37 -0
- package/src/results/utils.ts +34 -0
- package/src/spectator/types.ts +6 -0
- package/src/types.ts +101 -7
- package/tests/inquiry.spec.ts +111 -0
- package/tests/results.spec.ts +81 -0
- package/tsconfig.json +3 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
CONFIRM_NO, CONFIRM_YES, DEFAULT_INQUIRY_ANSWER_CHARS, INQUIRY_STATE_TEXT_CHARS, InquiryKind, inquiryHelper,
|
|
4
|
+
} from '../src/index.js'
|
|
5
|
+
import type { Inquiry, InquiryAnswer } from '../src/index.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The pure half of the inquiry primitive. Every layer that carries an answer — the execution
|
|
9
|
+
* service, the pipeline runner, the `ask_user` tool, the connector — reads it through exactly
|
|
10
|
+
* these functions, so a second reading of "was this answered" is what these specs exist to stop.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const inquiry = (patch: Partial<Inquiry> = {}): Inquiry => ({
|
|
14
|
+
id: 'q1',
|
|
15
|
+
kind: InquiryKind.Choice,
|
|
16
|
+
question: 'Which database does the origin use?',
|
|
17
|
+
options: [
|
|
18
|
+
{ value: 'postgres', label: 'PostgreSQL' },
|
|
19
|
+
{ value: 'mongo', label: 'MongoDB' },
|
|
20
|
+
],
|
|
21
|
+
...patch,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('@owlmeans/llm-common — what an unanswered question assumes', () => {
|
|
25
|
+
test('a question with a default answers itself with it', () => {
|
|
26
|
+
expect(inquiryHelper.defaultAnswerFor(inquiry({ default: 'postgres' })))
|
|
27
|
+
.toEqual({ inquiryId: 'q1', value: 'postgres' })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('a question without one declines — a decision, never a failure', () => {
|
|
31
|
+
const answer = inquiryHelper.defaultAnswerFor(inquiry())
|
|
32
|
+
expect(inquiryHelper.isDeclined(answer)).toBe(true)
|
|
33
|
+
expect(inquiryHelper.answeredWith(answer)).toBeNull()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('a multiple-choice default travels whole', () => {
|
|
37
|
+
expect(inquiryHelper.defaultAnswerFor(inquiry({ multiple: true, default: ['postgres', 'mongo'] })).value)
|
|
38
|
+
.toEqual(['postgres', 'mongo'])
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('@owlmeans/llm-common — reading one answer', () => {
|
|
43
|
+
test('the chosen value wins over free text, and the first of a list is the answer', () => {
|
|
44
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1', value: 'mongo', text: 'or postgres' })).toBe('mongo')
|
|
45
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1', value: ['mongo', 'redis'] })).toBe('mongo')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('free text answers a question that offered no options', () => {
|
|
49
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1', text: 'the vendor one' })).toBe('the vendor one')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('an answer that says nothing reads as nothing, declined or not', () => {
|
|
53
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1' })).toBeNull()
|
|
54
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1', value: '', text: '' })).toBeNull()
|
|
55
|
+
expect(inquiryHelper.isDeclined({ inquiryId: 'q1' })).toBe(false)
|
|
56
|
+
expect(inquiryHelper.isDeclined({ inquiryId: 'q1', declined: true })).toBe(true)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('a confirmation is just its two values', () => {
|
|
60
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1', value: CONFIRM_YES })).toBe(CONFIRM_YES)
|
|
61
|
+
expect(inquiryHelper.answeredWith({ inquiryId: 'q1', value: CONFIRM_NO })).toBe(CONFIRM_NO)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('@owlmeans/llm-common — the one ceiling', () => {
|
|
66
|
+
test('an answer inside the ceiling is left exactly as it came', () => {
|
|
67
|
+
const answer: InquiryAnswer = { inquiryId: 'q1', value: 'mongo', text: 'because of the driver' }
|
|
68
|
+
expect(inquiryHelper.capAnswer(answer)).toEqual(answer)
|
|
69
|
+
expect(inquiryHelper.capAnswer(answer).truncated).toBeUndefined()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('a cut is never silent', () => {
|
|
73
|
+
const capped = inquiryHelper.capAnswer({ inquiryId: 'q1', text: 'x'.repeat(DEFAULT_INQUIRY_ANSWER_CHARS + 5) })
|
|
74
|
+
expect(capped.text).toHaveLength(DEFAULT_INQUIRY_ANSWER_CHARS)
|
|
75
|
+
expect(capped.truncated).toBe(true)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('an over-long value is reported, never shortened into an option nobody offered', () => {
|
|
79
|
+
const value = ['ok', 'y'.repeat(40)]
|
|
80
|
+
const capped = inquiryHelper.capAnswer({ inquiryId: 'q1', value }, 10)
|
|
81
|
+
// Cutting prose degrades an answer; cutting an identifier CHANGES it — `answeredWith` would
|
|
82
|
+
// then hand the caller a choice the question never carried.
|
|
83
|
+
expect(capped.value).toEqual(value)
|
|
84
|
+
expect(capped.truncated).toBe(true)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('the state copy keeps the decision whole and cuts only the prose', () => {
|
|
88
|
+
const answer: InquiryAnswer = {
|
|
89
|
+
inquiryId: 'q1', value: 'postgres', text: 'z'.repeat(INQUIRY_STATE_TEXT_CHARS + 100),
|
|
90
|
+
}
|
|
91
|
+
const stored = inquiryHelper.stateAnswerOf(answer)
|
|
92
|
+
expect(stored.value).toBe('postgres')
|
|
93
|
+
expect(stored.text).toHaveLength(INQUIRY_STATE_TEXT_CHARS)
|
|
94
|
+
expect(stored.truncated).toBe(true)
|
|
95
|
+
// The answer handed back to whoever asked is untouched — only the persisted copy is reduced.
|
|
96
|
+
expect(answer.text).toHaveLength(INQUIRY_STATE_TEXT_CHARS + 100)
|
|
97
|
+
expect(inquiryHelper.stateAnswerOf({ inquiryId: 'q1', value: 'postgres' }).truncated).toBeUndefined()
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
describe('@owlmeans/llm-common — one line for a trace', () => {
|
|
102
|
+
test('the label names the kind, the question and the choices, on one line', () => {
|
|
103
|
+
expect(inquiryHelper.renderInquiry(inquiry({ question: 'Which\n database?' })))
|
|
104
|
+
.toBe('[choice] Which database? (postgres | mongo)')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('a question with no options renders without an empty bracket', () => {
|
|
108
|
+
expect(inquiryHelper.renderInquiry({ id: 'q2', kind: InquiryKind.Confirm, question: 'Relocate the origin?' }))
|
|
109
|
+
.toBe('[confirm] Relocate the origin?')
|
|
110
|
+
})
|
|
111
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
CUMULATIVE_RESULTS_OMITTED_LEAD, CUMULATIVE_RESULTS_PREAMBLE, PACKAGE_PURPOSES, PackagePurpose,
|
|
4
|
+
PROMPT_BLOCK_ORDER, PROMPT_REGIONS, PromptBlock, PromptRegion, renderCumulativeResults,
|
|
5
|
+
} from '../src/index.js'
|
|
6
|
+
import type { CumulativeResults } from '../src/index.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The prompt-facing half of cumulative pipeline results: where the block sits and what it says.
|
|
10
|
+
* Both are cache facts as much as wording — a view must render to the same bytes every time, and
|
|
11
|
+
* an absent view must render to nothing at all.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const view = (patch: Partial<CumulativeResults> = {}): CumulativeResults => ({
|
|
15
|
+
step: 'resources',
|
|
16
|
+
sections: [
|
|
17
|
+
{ step: 'types', text: '### types\n- type `User`: { id: string } — import from `@app/common`' },
|
|
18
|
+
{ step: 'files', text: '### files (names only)\n- file: `a.ts`' },
|
|
19
|
+
],
|
|
20
|
+
omitted: [],
|
|
21
|
+
chars: 100,
|
|
22
|
+
digest: 'digest-that-must-never-be-rendered',
|
|
23
|
+
...patch,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('@owlmeans/llm-common — results block placement', () => {
|
|
27
|
+
test('sits after the packages block and before the context and the per-call tail', () => {
|
|
28
|
+
expect(PROMPT_BLOCK_ORDER).toEqual([
|
|
29
|
+
PromptBlock.Role, PromptBlock.Skills, PromptBlock.Packages, PromptBlock.Results,
|
|
30
|
+
PromptBlock.Context, PromptBlock.Tail,
|
|
31
|
+
])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// The regions partition the order: every block travels in exactly one place, in emission order.
|
|
35
|
+
test('the regions cover every block once, in emission order', () => {
|
|
36
|
+
const regions = [PromptRegion.System, PromptRegion.Project, PromptRegion.Tail]
|
|
37
|
+
expect(regions.flatMap(region => PROMPT_REGIONS[region])).toEqual([...PROMPT_BLOCK_ORDER])
|
|
38
|
+
expect(PROMPT_REGIONS[PromptRegion.Project]).toEqual([PromptBlock.Results, PromptBlock.Context])
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('@owlmeans/llm-common — package purposes', () => {
|
|
43
|
+
// A closed vocabulary that library-manager copies; the list must be the enum, once each.
|
|
44
|
+
test('the declared list holds every purpose exactly once', () => {
|
|
45
|
+
expect(PACKAGE_PURPOSES).toHaveLength(26)
|
|
46
|
+
expect(new Set(PACKAGE_PURPOSES).size).toBe(PACKAGE_PURPOSES.length)
|
|
47
|
+
expect([...PACKAGE_PURPOSES].sort()).toEqual([...Object.values(PackagePurpose)].sort())
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('@owlmeans/llm-common — rendering a results view', () => {
|
|
52
|
+
test('no view, or a view with nothing in it, renders nothing at all', () => {
|
|
53
|
+
expect(renderCumulativeResults(undefined)).toBe('')
|
|
54
|
+
expect(renderCumulativeResults(null)).toBe('')
|
|
55
|
+
expect(renderCumulativeResults(view({ sections: [] }))).toBe('')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('opens with the fixed rules, then the sections oldest first', () => {
|
|
59
|
+
const text = renderCumulativeResults(view())
|
|
60
|
+
|
|
61
|
+
expect(text.startsWith(CUMULATIVE_RESULTS_PREAMBLE)).toBe(true)
|
|
62
|
+
expect(text).toContain('No model wrote it.')
|
|
63
|
+
expect(text).toContain('Import a listed symbol only from the specifier listed for it.')
|
|
64
|
+
expect(text).toContain('is NEWER than this list')
|
|
65
|
+
expect(text.indexOf('### types')).toBeLessThan(text.indexOf('### files'))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('never renders the digest, and renders the same bytes every time', () => {
|
|
69
|
+
const text = renderCumulativeResults(view())
|
|
70
|
+
|
|
71
|
+
expect(text).not.toContain('digest-that-must-never-be-rendered')
|
|
72
|
+
expect(renderCumulativeResults(view())).toBe(text)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('names the steps left out for space, and says their results exist', () => {
|
|
76
|
+
const text = renderCumulativeResults(view({ omitted: ['scaffold', 'design/screens'] }))
|
|
77
|
+
|
|
78
|
+
expect(text).toContain(`${CUMULATIVE_RESULTS_OMITTED_LEAD} \`scaffold\`, \`design/screens\`.`)
|
|
79
|
+
expect(text.endsWith('Look there before creating anything they may already have made.')).toBe(true)
|
|
80
|
+
})
|
|
81
|
+
})
|