@mossbear/protocol 0.1.0-alpha.100
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/agentGuidancePaths.d.ts +101 -0
- package/dist/agentGuidancePaths.d.ts.map +1 -0
- package/dist/agentGuidancePaths.js +185 -0
- package/dist/agentGuidancePaths.js.map +1 -0
- package/dist/agentGuidancePaths.test.d.ts +2 -0
- package/dist/agentGuidancePaths.test.d.ts.map +1 -0
- package/dist/agentGuidancePaths.test.js +91 -0
- package/dist/agentGuidancePaths.test.js.map +1 -0
- package/dist/aliasPaths.d.ts +100 -0
- package/dist/aliasPaths.d.ts.map +1 -0
- package/dist/aliasPaths.js +148 -0
- package/dist/aliasPaths.js.map +1 -0
- package/dist/aliasPaths.test.d.ts +2 -0
- package/dist/aliasPaths.test.d.ts.map +1 -0
- package/dist/aliasPaths.test.js +80 -0
- package/dist/aliasPaths.test.js.map +1 -0
- package/dist/artifact.test.d.ts +2 -0
- package/dist/artifact.test.d.ts.map +1 -0
- package/dist/artifact.test.js +374 -0
- package/dist/artifact.test.js.map +1 -0
- package/dist/bundleSlug.d.ts +177 -0
- package/dist/bundleSlug.d.ts.map +1 -0
- package/dist/bundleSlug.js +233 -0
- package/dist/bundleSlug.js.map +1 -0
- package/dist/bundleSlug.test.d.ts +2 -0
- package/dist/bundleSlug.test.d.ts.map +1 -0
- package/dist/bundleSlug.test.js +197 -0
- package/dist/bundleSlug.test.js.map +1 -0
- package/dist/commentAnchor.d.ts +34 -0
- package/dist/commentAnchor.d.ts.map +1 -0
- package/dist/commentAnchor.js +122 -0
- package/dist/commentAnchor.js.map +1 -0
- package/dist/commentAnchor.test.d.ts +2 -0
- package/dist/commentAnchor.test.d.ts.map +1 -0
- package/dist/commentAnchor.test.js +48 -0
- package/dist/commentAnchor.test.js.map +1 -0
- package/dist/contextKinds.d.ts +165 -0
- package/dist/contextKinds.d.ts.map +1 -0
- package/dist/contextKinds.js +148 -0
- package/dist/contextKinds.js.map +1 -0
- package/dist/contextKinds.test.d.ts +2 -0
- package/dist/contextKinds.test.d.ts.map +1 -0
- package/dist/contextKinds.test.js +137 -0
- package/dist/contextKinds.test.js.map +1 -0
- package/dist/frameDocument.d.ts +71 -0
- package/dist/frameDocument.d.ts.map +1 -0
- package/dist/frameDocument.js +140 -0
- package/dist/frameDocument.js.map +1 -0
- package/dist/frameDocument.test.d.ts +2 -0
- package/dist/frameDocument.test.d.ts.map +1 -0
- package/dist/frameDocument.test.js +84 -0
- package/dist/frameDocument.test.js.map +1 -0
- package/dist/frameProtocol.d.ts +11 -0
- package/dist/frameProtocol.d.ts.map +1 -0
- package/dist/frameProtocol.js +11 -0
- package/dist/frameProtocol.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +19 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +19 -0
- package/dist/limits.js.map +1 -0
- package/dist/markdownSections.d.ts +58 -0
- package/dist/markdownSections.d.ts.map +1 -0
- package/dist/markdownSections.js +102 -0
- package/dist/markdownSections.js.map +1 -0
- package/dist/markdownSections.test.d.ts +2 -0
- package/dist/markdownSections.test.d.ts.map +1 -0
- package/dist/markdownSections.test.js +95 -0
- package/dist/markdownSections.test.js.map +1 -0
- package/dist/pairing.d.ts +183 -0
- package/dist/pairing.d.ts.map +1 -0
- package/dist/pairing.js +175 -0
- package/dist/pairing.js.map +1 -0
- package/dist/pairing.test.d.ts +2 -0
- package/dist/pairing.test.d.ts.map +1 -0
- package/dist/pairing.test.js +105 -0
- package/dist/pairing.test.js.map +1 -0
- package/dist/photos.d.ts +146 -0
- package/dist/photos.d.ts.map +1 -0
- package/dist/photos.js +127 -0
- package/dist/photos.js.map +1 -0
- package/dist/publicModelCatalog.d.ts +19 -0
- package/dist/publicModelCatalog.d.ts.map +1 -0
- package/dist/publicModelCatalog.generated.d.ts +2 -0
- package/dist/publicModelCatalog.generated.d.ts.map +1 -0
- package/dist/publicModelCatalog.generated.js +489 -0
- package/dist/publicModelCatalog.generated.js.map +1 -0
- package/dist/publicModelCatalog.js +68 -0
- package/dist/publicModelCatalog.js.map +1 -0
- package/dist/publicModelCatalog.test.d.ts +2 -0
- package/dist/publicModelCatalog.test.d.ts.map +1 -0
- package/dist/publicModelCatalog.test.js +88 -0
- package/dist/publicModelCatalog.test.js.map +1 -0
- package/dist/publicModelNativeAliases.d.ts +5 -0
- package/dist/publicModelNativeAliases.d.ts.map +1 -0
- package/dist/publicModelNativeAliases.js +8 -0
- package/dist/publicModelNativeAliases.js.map +1 -0
- package/dist/schemas.d.ts +10745 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +4572 -0
- package/dist/schemas.js.map +1 -0
- package/dist/schemas.test.d.ts +2 -0
- package/dist/schemas.test.d.ts.map +1 -0
- package/dist/schemas.test.js +1617 -0
- package/dist/schemas.test.js.map +1 -0
- package/dist/steeringOverTime.d.ts +30 -0
- package/dist/steeringOverTime.d.ts.map +1 -0
- package/dist/steeringOverTime.js +19 -0
- package/dist/steeringOverTime.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/usageOnly.d.ts +190 -0
- package/dist/usageOnly.d.ts.map +1 -0
- package/dist/usageOnly.js +53 -0
- package/dist/usageOnly.js.map +1 -0
- package/dist/usageOnly.test.d.ts +2 -0
- package/dist/usageOnly.test.d.ts.map +1 -0
- package/dist/usageOnly.test.js +203 -0
- package/dist/usageOnly.test.js.map +1 -0
- package/dist/version.d.ts +47 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +125 -0
- package/dist/version.js.map +1 -0
- package/dist/version.test.d.ts +2 -0
- package/dist/version.test.d.ts.map +1 -0
- package/dist/version.test.js +86 -0
- package/dist/version.test.js.map +1 -0
- package/dist/whatSyncs.d.ts +62 -0
- package/dist/whatSyncs.d.ts.map +1 -0
- package/dist/whatSyncs.js +228 -0
- package/dist/whatSyncs.js.map +1 -0
- package/dist/whatSyncs.test.d.ts +2 -0
- package/dist/whatSyncs.test.d.ts.map +1 -0
- package/dist/whatSyncs.test.js +113 -0
- package/dist/whatSyncs.test.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { DISPLAY_NAME_REFUSED_CHARACTERS, defaultGuidesBundleFor, deriveBundleSlug, displayable, printable, } from './bundleSlug.js';
|
|
3
|
+
const none = new Set();
|
|
4
|
+
describe('deriveBundleSlug', () => {
|
|
5
|
+
it('kebab-cases a plain name', () => {
|
|
6
|
+
expect(deriveBundleSlug('My Notes', none)).toBe('my-notes');
|
|
7
|
+
});
|
|
8
|
+
it('collapses punctuation and whitespace runs into single hyphens', () => {
|
|
9
|
+
expect(deriveBundleSlug(' Client — Q3 / Planning! ', none)).toBe('client-q3-planning');
|
|
10
|
+
});
|
|
11
|
+
it('strips diacritics', () => {
|
|
12
|
+
expect(deriveBundleSlug('Café Menü', none)).toBe('cafe-menu');
|
|
13
|
+
});
|
|
14
|
+
it('falls back to "bundle" when nothing survives normalization', () => {
|
|
15
|
+
expect(deriveBundleSlug('***', none)).toBe('bundle');
|
|
16
|
+
expect(deriveBundleSlug('', none)).toBe('bundle');
|
|
17
|
+
});
|
|
18
|
+
it('suffixes -2, -3… on collision with taken slugs', () => {
|
|
19
|
+
expect(deriveBundleSlug('Notes', new Set(['notes']))).toBe('notes-2');
|
|
20
|
+
expect(deriveBundleSlug('Notes', new Set(['notes', 'notes-2']))).toBe('notes-3');
|
|
21
|
+
});
|
|
22
|
+
// `inbox` was the last reserved slug, held open only while slice 3b's
|
|
23
|
+
// `unfiled` carve-out keyed on it. Slice 5 retired both, so it derives like
|
|
24
|
+
// any other name.
|
|
25
|
+
it('proposes `inbox` like any other name now that no slug is reserved', () => {
|
|
26
|
+
expect(deriveBundleSlug('Inbox', none)).toBe('inbox');
|
|
27
|
+
});
|
|
28
|
+
it('respects the 64-char cap, including when suffixing', () => {
|
|
29
|
+
const long = 'a'.repeat(80);
|
|
30
|
+
const base = deriveBundleSlug(long, none);
|
|
31
|
+
expect(base).toBe('a'.repeat(64));
|
|
32
|
+
const suffixed = deriveBundleSlug(long, new Set([base]));
|
|
33
|
+
expect(suffixed.length).toBeLessThanOrEqual(64);
|
|
34
|
+
expect(suffixed.endsWith('-2')).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it('does not end with a hyphen after truncation', () => {
|
|
37
|
+
const tricky = `${'a'.repeat(63)}bcd`;
|
|
38
|
+
const slug = deriveBundleSlug(tricky, none);
|
|
39
|
+
expect(slug.endsWith('-')).toBe(false);
|
|
40
|
+
expect(slug.length).toBeLessThanOrEqual(64);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('defaultGuidesBundleFor', () => {
|
|
44
|
+
it("keeps `my-guides` for the account's personal workspace", () => {
|
|
45
|
+
expect(defaultGuidesBundleFor({ slug: 'personal', name: 'Personal', isPersonal: true })).toEqual({ slug: 'my-guides', name: 'My guides' });
|
|
46
|
+
});
|
|
47
|
+
it("names another workspace's bundle after that workspace", () => {
|
|
48
|
+
expect(defaultGuidesBundleFor({ slug: 'acme-a1b2c3', name: 'Acme', isPersonal: false })).toEqual({ slug: 'acme-a1b2c3-guides', name: 'Acme guides' });
|
|
49
|
+
});
|
|
50
|
+
it('gives two workspaces of one account two distinct slugs', () => {
|
|
51
|
+
const personal = defaultGuidesBundleFor({
|
|
52
|
+
slug: 'personal',
|
|
53
|
+
name: 'Personal',
|
|
54
|
+
isPersonal: true,
|
|
55
|
+
});
|
|
56
|
+
const shared = defaultGuidesBundleFor({
|
|
57
|
+
slug: 'personal',
|
|
58
|
+
name: 'Personal',
|
|
59
|
+
isPersonal: false,
|
|
60
|
+
});
|
|
61
|
+
// Same workspace slug on both sides, so the personal flag is doing the
|
|
62
|
+
// whole job: a shared workspace that happens to be called "personal" still
|
|
63
|
+
// does not collide with the bundle `users.default_bundle_id` names.
|
|
64
|
+
expect(shared.slug).not.toBe(personal.slug);
|
|
65
|
+
});
|
|
66
|
+
it('stays within the 64-char cap `BundleSlugSchema` enforces', () => {
|
|
67
|
+
const { slug } = defaultGuidesBundleFor({
|
|
68
|
+
slug: 'w'.repeat(80),
|
|
69
|
+
name: 'Long',
|
|
70
|
+
isPersonal: false,
|
|
71
|
+
});
|
|
72
|
+
expect(slug.length).toBe(64);
|
|
73
|
+
expect(slug.endsWith('-guides')).toBe(true);
|
|
74
|
+
expect(slug).toMatch(/^[a-z0-9][a-z0-9-]*$/);
|
|
75
|
+
});
|
|
76
|
+
it('does not double the hyphen when truncation lands on one', () => {
|
|
77
|
+
const { slug } = defaultGuidesBundleFor({
|
|
78
|
+
// 57 characters ending in a hyphen — exactly where the cut falls.
|
|
79
|
+
slug: `${'w'.repeat(56)}-tail`,
|
|
80
|
+
name: 'Long',
|
|
81
|
+
isPersonal: false,
|
|
82
|
+
});
|
|
83
|
+
expect(slug).toBe(`${'w'.repeat(56)}-guides`);
|
|
84
|
+
expect(slug).toMatch(/^[a-z0-9][a-z0-9-]*$/);
|
|
85
|
+
});
|
|
86
|
+
it('falls back to a valid slug when a workspace slug is empty', () => {
|
|
87
|
+
expect(defaultGuidesBundleFor({ slug: '', name: 'Nameless', isPersonal: false })).toEqual({ slug: 'workspace-guides', name: 'Nameless guides' });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('defaultGuidesBundleFor — the name a teammate ends up reading', () => {
|
|
91
|
+
// A workspace name is typed by whoever created the workspace, and a member who
|
|
92
|
+
// imports from a repo declaring it gets a bundle of their own named after it.
|
|
93
|
+
// The CLI prints bundle names straight into a terminal line, so without this
|
|
94
|
+
// the workspace's author could rewrite what a teammate reads.
|
|
95
|
+
const ESC = String.fromCharCode(27);
|
|
96
|
+
const CR = String.fromCharCode(13);
|
|
97
|
+
it('strips the ESC that arms an ANSI sequence, leaving inert text', () => {
|
|
98
|
+
// Only the ESC is removed, and only the ESC needs to be: `[31m` on its own
|
|
99
|
+
// is ordinary printable text that colours nothing and moves no cursor. The
|
|
100
|
+
// assertion says so rather than pretending the whole sequence disappears.
|
|
101
|
+
const { name } = defaultGuidesBundleFor({
|
|
102
|
+
slug: 'acme',
|
|
103
|
+
name: `Acme${ESC}[31m`,
|
|
104
|
+
isPersonal: false,
|
|
105
|
+
});
|
|
106
|
+
expect(name).not.toContain(ESC);
|
|
107
|
+
expect(name).toBe('Acme[31m guides');
|
|
108
|
+
});
|
|
109
|
+
it('strips a carriage return, which is what rewrites the line', () => {
|
|
110
|
+
const { name } = defaultGuidesBundleFor({
|
|
111
|
+
slug: 'acme',
|
|
112
|
+
name: `Acme${CR}Still delivered by another bundle: nothing`,
|
|
113
|
+
isPersonal: false,
|
|
114
|
+
});
|
|
115
|
+
expect(name).not.toContain(CR);
|
|
116
|
+
expect(name).toBe('AcmeStill delivered by another bundle: nothing guides');
|
|
117
|
+
});
|
|
118
|
+
it('collapses whitespace runs and trims, so padding cannot push text off a line', () => {
|
|
119
|
+
expect(defaultGuidesBundleFor({ slug: 'acme', name: ' Acme Team ', isPersonal: false })
|
|
120
|
+
.name).toBe('Acme Team guides');
|
|
121
|
+
});
|
|
122
|
+
it('falls back when nothing survives, rather than naming a bundle " guides"', () => {
|
|
123
|
+
expect(defaultGuidesBundleFor({ slug: 'acme', name: `${ESC}${CR}`, isPersonal: false })
|
|
124
|
+
.name).toBe('Workspace guides');
|
|
125
|
+
});
|
|
126
|
+
it('leaves an ordinary name, including non-ASCII, alone', () => {
|
|
127
|
+
expect(defaultGuidesBundleFor({ slug: 'cafe', name: 'Café Ménü', isPersonal: false }).name).toBe('Café Ménü guides');
|
|
128
|
+
});
|
|
129
|
+
// A Persian workspace name spelled with a zero-width non-joiner reaches the
|
|
130
|
+
// teammate's bundle spelled the same way — the joiner is part of the word,
|
|
131
|
+
// not a way to redraw the line.
|
|
132
|
+
it('keeps the joiner a Persian workspace name is spelled with', () => {
|
|
133
|
+
const name = 'کتاب\u200cها';
|
|
134
|
+
expect(defaultGuidesBundleFor({ slug: 'ketab', name, isPersonal: false }).name).toBe(`${name} guides`);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
// `displayable` strips by the same class `displayNameSchema` refuses by, so a
|
|
138
|
+
// name the boundary would turn away is, once derived, the same name without
|
|
139
|
+
// the offending characters — and a name the boundary admits comes through as
|
|
140
|
+
// spelled.
|
|
141
|
+
describe('displayable', () => {
|
|
142
|
+
it('keeps a zero-width joiner, which is spelling rather than redrawing', () => {
|
|
143
|
+
expect(displayable('Team \u{1f468}\u200d\u{1f469}')).toBe('Team \u{1f468}\u200d\u{1f469}');
|
|
144
|
+
});
|
|
145
|
+
it('strips a right-to-left override, which reorders the line it lands on', () => {
|
|
146
|
+
expect(displayable('Acme\u202eEVIL')).toBe('AcmeEVIL');
|
|
147
|
+
});
|
|
148
|
+
it('strips a bidi isolate, the same power in its newer spelling', () => {
|
|
149
|
+
expect(displayable('Acme\u2066EVIL\u2069')).toBe('AcmeEVIL');
|
|
150
|
+
});
|
|
151
|
+
it('strips an ESC and a CR, the terminal cases the strip exists for', () => {
|
|
152
|
+
expect(displayable('Acme\u001b[31m\rEVIL')).toBe('Acme[31mEVIL');
|
|
153
|
+
});
|
|
154
|
+
it('returns an empty string for a name of nothing but refused characters', () => {
|
|
155
|
+
expect(displayable('\u001b\u202e\u2066')).toBe('');
|
|
156
|
+
});
|
|
157
|
+
// The class is one regex, and a global flag on it would make `.test` stateful
|
|
158
|
+
// across calls; the exported shape is the stateless one.
|
|
159
|
+
it('exports a stateless matcher, so two checks in a row agree', () => {
|
|
160
|
+
expect(DISPLAY_NAME_REFUSED_CHARACTERS.global).toBe(false);
|
|
161
|
+
expect(DISPLAY_NAME_REFUSED_CHARACTERS.test('\u202e')).toBe(true);
|
|
162
|
+
expect(DISPLAY_NAME_REFUSED_CHARACTERS.test('\u202e')).toBe(true);
|
|
163
|
+
expect(DISPLAY_NAME_REFUSED_CHARACTERS.test('\u200d')).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
// `printable` is the body half of the same defence: the same class of
|
|
167
|
+
// character, the opposite treatment of everything else. Each case below is a
|
|
168
|
+
// way the two halves could be confused for one another.
|
|
169
|
+
describe('printable', () => {
|
|
170
|
+
it('strips an ESC, a CR and a right-to-left override', () => {
|
|
171
|
+
expect(printable('before\u001b[31m\rafter\u202eEVIL')).toBe('before[31mafterEVIL');
|
|
172
|
+
});
|
|
173
|
+
it('keeps newlines and tabs, which a body is made of', () => {
|
|
174
|
+
expect(printable('one\ntwo\tthree\n')).toBe('one\ntwo\tthree\n');
|
|
175
|
+
});
|
|
176
|
+
it('keeps a line of leading spaces byte for byte, so a code block survives', () => {
|
|
177
|
+
// The case `displayable` gets right for a name and wrong for a body: it
|
|
178
|
+
// collapses these four spaces to one and trims the trailing newline.
|
|
179
|
+
const body = '# Title\n\n const x = 1\n';
|
|
180
|
+
expect(printable(body)).toBe(body);
|
|
181
|
+
expect(displayable(body)).toBe('# Title const x = 1');
|
|
182
|
+
});
|
|
183
|
+
it('keeps a zero-width non-joiner, which the class admits', () => {
|
|
184
|
+
expect(printable('with\u200cout')).toBe('with\u200cout');
|
|
185
|
+
});
|
|
186
|
+
it('returns a body with no refused character unchanged', () => {
|
|
187
|
+
const body = 'Prefer `Button` over `Pressable`.\n\n- one\n- two\n';
|
|
188
|
+
expect(printable(body)).toBe(body);
|
|
189
|
+
});
|
|
190
|
+
// The strip is a global regex; a stateful `lastIndex` would make the second
|
|
191
|
+
// call skip the first match.
|
|
192
|
+
it('strips the same body identically twice', () => {
|
|
193
|
+
expect(printable('a\u001bb')).toBe(printable('a\u001bb'));
|
|
194
|
+
expect(printable('a\u001bb')).toBe('ab');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=bundleSlug.test.js.map
|
|
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AI,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
/** A passage selected in a rendered artifact, with source text for relocation. */
|
|
3
|
+
export declare const CommentAnchorSchema: v.ObjectSchema<{
|
|
4
|
+
readonly quote: v.ObjectSchema<{
|
|
5
|
+
readonly exact: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
|
|
6
|
+
readonly prefix: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 64, undefined>]>;
|
|
7
|
+
readonly suffix: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 64, undefined>]>;
|
|
8
|
+
}, undefined>;
|
|
9
|
+
readonly block: v.OptionalSchema<v.ObjectSchema<{
|
|
10
|
+
readonly source: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 8000, undefined>]>;
|
|
11
|
+
readonly lines: v.ObjectSchema<{
|
|
12
|
+
readonly start: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
13
|
+
readonly end: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
14
|
+
}, undefined>;
|
|
15
|
+
}, undefined>, undefined>;
|
|
16
|
+
readonly element: v.OptionalSchema<v.ObjectSchema<{
|
|
17
|
+
readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
|
|
18
|
+
readonly tag: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 64, undefined>]>;
|
|
19
|
+
}, undefined>, undefined>;
|
|
20
|
+
}, undefined>;
|
|
21
|
+
export type CommentAnchor = v.InferOutput<typeof CommentAnchorSchema>;
|
|
22
|
+
export type BlockLocation = {
|
|
23
|
+
status: 'located' | 'changed';
|
|
24
|
+
lines: {
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
status: 'orphaned';
|
|
30
|
+
lines: null;
|
|
31
|
+
};
|
|
32
|
+
/** Relocate a Markdown source block without depending on a renderer or DOM. */
|
|
33
|
+
export declare function locateBlock(block: NonNullable<CommentAnchor['block']>, currentSource: string): BlockLocation;
|
|
34
|
+
//# sourceMappingURL=commentAnchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commentAnchor.d.ts","sourceRoot":"","sources":["../src/commentAnchor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,kFAAkF;AAClF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;aAqB9B,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAA;AACrE,MAAM,MAAM,aAAa,GACrB;IAAE,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;IAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACxE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAA;AAqCvC,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAC1C,aAAa,EAAE,MAAM,GACpB,aAAa,CA6Ef"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
/** A passage selected in a rendered artifact, with source text for relocation. */
|
|
3
|
+
export const CommentAnchorSchema = v.object({
|
|
4
|
+
quote: v.object({
|
|
5
|
+
exact: v.pipe(v.string(), v.minLength(1), v.maxLength(2000)),
|
|
6
|
+
prefix: v.pipe(v.string(), v.maxLength(64)),
|
|
7
|
+
suffix: v.pipe(v.string(), v.maxLength(64)),
|
|
8
|
+
}),
|
|
9
|
+
block: v.optional(v.object({
|
|
10
|
+
source: v.pipe(v.string(), v.minLength(1), v.maxLength(8000)),
|
|
11
|
+
lines: v.object({
|
|
12
|
+
start: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
13
|
+
end: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
14
|
+
}),
|
|
15
|
+
})),
|
|
16
|
+
element: v.optional(v.object({
|
|
17
|
+
selector: v.pipe(v.string(), v.maxLength(2000)),
|
|
18
|
+
tag: v.pipe(v.string(), v.maxLength(64)),
|
|
19
|
+
})),
|
|
20
|
+
});
|
|
21
|
+
function lineAt(source, offset) {
|
|
22
|
+
let line = 1;
|
|
23
|
+
for (let i = 0; i < offset; i += 1)
|
|
24
|
+
if (source[i] === '\n')
|
|
25
|
+
line += 1;
|
|
26
|
+
return line;
|
|
27
|
+
}
|
|
28
|
+
/** Distance with a fixed error budget. Rows outside the budget are skipped. */
|
|
29
|
+
function boundedDistance(a, b, budget) {
|
|
30
|
+
if (Math.abs(a.length - b.length) > budget)
|
|
31
|
+
return budget + 1;
|
|
32
|
+
let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
33
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
34
|
+
const current = new Array(b.length + 1).fill(budget + 1);
|
|
35
|
+
current[0] = i;
|
|
36
|
+
let rowMin = current[0];
|
|
37
|
+
for (let j = Math.max(1, i - budget); j <= Math.min(b.length, i + budget); j += 1) {
|
|
38
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
39
|
+
rowMin = Math.min(rowMin, current[j]);
|
|
40
|
+
}
|
|
41
|
+
if (rowMin > budget)
|
|
42
|
+
return budget + 1;
|
|
43
|
+
previous = current;
|
|
44
|
+
}
|
|
45
|
+
return previous[b.length];
|
|
46
|
+
}
|
|
47
|
+
/** Cheap ranking before the bounded edit-distance pass. */
|
|
48
|
+
function sampledOverlap(samples, candidate) {
|
|
49
|
+
let shared = 0;
|
|
50
|
+
for (const sample of samples)
|
|
51
|
+
if (candidate.includes(sample))
|
|
52
|
+
shared += 1;
|
|
53
|
+
return shared;
|
|
54
|
+
}
|
|
55
|
+
/** Relocate a Markdown source block without depending on a renderer or DOM. */
|
|
56
|
+
export function locateBlock(block, currentSource) {
|
|
57
|
+
const exactMatches = [];
|
|
58
|
+
let at = currentSource.indexOf(block.source);
|
|
59
|
+
while (at !== -1) {
|
|
60
|
+
const before = at === 0 || currentSource[at - 1] === '\n';
|
|
61
|
+
const end = at + block.source.length;
|
|
62
|
+
const after = end === currentSource.length || currentSource[end] === '\n';
|
|
63
|
+
if (before && after)
|
|
64
|
+
exactMatches.push(at);
|
|
65
|
+
at = currentSource.indexOf(block.source, at + 1);
|
|
66
|
+
}
|
|
67
|
+
if (exactMatches.length > 0) {
|
|
68
|
+
const closest = exactMatches.reduce((best, candidate) => Math.abs(lineAt(currentSource, candidate) - block.lines.start) <
|
|
69
|
+
Math.abs(lineAt(currentSource, best) - block.lines.start)
|
|
70
|
+
? candidate
|
|
71
|
+
: best);
|
|
72
|
+
const start = lineAt(currentSource, closest);
|
|
73
|
+
return {
|
|
74
|
+
status: 'located',
|
|
75
|
+
lines: { start, end: start + block.source.split('\n').length - 1 },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const lines = currentSource.split('\n');
|
|
79
|
+
const span = block.source.split('\n').length;
|
|
80
|
+
const budget = Math.min(256, Math.max(2, Math.floor(block.source.length * 0.2)));
|
|
81
|
+
const samples = [];
|
|
82
|
+
const sampleLength = Math.min(8, block.source.length);
|
|
83
|
+
for (let i = 0; i <= block.source.length - sampleLength; i += Math.max(1, Math.floor(block.source.length / 16)))
|
|
84
|
+
samples.push(block.source.slice(i, i + sampleLength));
|
|
85
|
+
const candidates = [];
|
|
86
|
+
const maxCandidates = 8;
|
|
87
|
+
let best = null;
|
|
88
|
+
// The source may be rewrapped across many lines. Grow each candidate only
|
|
89
|
+
// while its character length can still fit inside the edit budget.
|
|
90
|
+
for (let start = 0; start < lines.length; start += 1) {
|
|
91
|
+
for (let length = 1; length <= Math.min(lines.length - start, span + budget); length += 1) {
|
|
92
|
+
if (Math.abs(length - span) > budget)
|
|
93
|
+
continue;
|
|
94
|
+
const candidate = lines.slice(start, start + length).join('\n');
|
|
95
|
+
if (candidate.length > block.source.length + budget)
|
|
96
|
+
break;
|
|
97
|
+
if (Math.abs(block.source.length - candidate.length) > budget)
|
|
98
|
+
continue;
|
|
99
|
+
const score = sampledOverlap(samples, candidate);
|
|
100
|
+
candidates.push({ source: candidate, start: start + 1, end: start + length, score });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
candidates.sort((a, b) => b.score - a.score ||
|
|
104
|
+
Math.abs(a.start - block.lines.start) - Math.abs(b.start - block.lines.start));
|
|
105
|
+
// Fuzzy relocation is best effort. Bound the expensive edit-distance work
|
|
106
|
+
// per comment even when every line of a long document is similar in length.
|
|
107
|
+
for (const candidate of candidates.slice(0, maxCandidates)) {
|
|
108
|
+
const distance = boundedDistance(block.source, candidate.source, budget);
|
|
109
|
+
if (distance <= budget &&
|
|
110
|
+
(best === null ||
|
|
111
|
+
distance < best.distance ||
|
|
112
|
+
(distance === best.distance &&
|
|
113
|
+
Math.abs(candidate.start - block.lines.start) <
|
|
114
|
+
Math.abs(best.start - block.lines.start)))) {
|
|
115
|
+
best = { distance, start: candidate.start, end: candidate.end };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return best
|
|
119
|
+
? { status: 'changed', lines: { start: best.start, end: best.end } }
|
|
120
|
+
: { status: 'orphaned', lines: null };
|
|
121
|
+
}
|
|
122
|
+
//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MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxE,IACE,QAAQ,IAAI,MAAM;YAClB,CAAC,IAAI,KAAK,IAAI;gBACZ,QAAQ,GAAG,IAAI,CAAC,QAAQ;gBACxB,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ;oBACzB,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;wBAC3C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAChD,CAAC;YACD,IAAI,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,CAAA;QACjE,CAAC;IACH,CAAC;IACD,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;QACpE,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commentAnchor.test.d.ts","sourceRoot":"","sources":["../src/commentAnchor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { locateBlock } from './commentAnchor.js';
|
|
3
|
+
describe('comment passage relocation', () => {
|
|
4
|
+
it('points to the nearest copy after a duplicate passage moves', () => {
|
|
5
|
+
const block = { source: 'A repeated paragraph.', lines: { start: 4, end: 4 } };
|
|
6
|
+
expect(locateBlock(block, 'A repeated paragraph.\n\nMiddle\n\nA repeated paragraph.')).toEqual({
|
|
7
|
+
status: 'located',
|
|
8
|
+
lines: { start: 5, end: 5 },
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
it('flags changed words at their current lines', () => {
|
|
12
|
+
const block = { source: 'Review the old draft.', lines: { start: 8, end: 8 } };
|
|
13
|
+
expect(locateBlock(block, 'Heading\nReview the new draft.')).toEqual({
|
|
14
|
+
status: 'changed',
|
|
15
|
+
lines: { start: 2, end: 2 },
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it('leaves a deleted passage unlocated', () => {
|
|
19
|
+
const block = {
|
|
20
|
+
source: 'A unique paragraph about permissions.',
|
|
21
|
+
lines: { start: 2, end: 2 },
|
|
22
|
+
};
|
|
23
|
+
expect(locateBlock(block, 'Completely different content')).toEqual({
|
|
24
|
+
status: 'orphaned',
|
|
25
|
+
lines: null,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
it('does not locate a word embedded in a different line', () => {
|
|
29
|
+
const block = { source: 'cat', lines: { start: 1, end: 1 } };
|
|
30
|
+
expect(locateBlock(block, 'concatenate')).toEqual({ status: 'orphaned', lines: null });
|
|
31
|
+
});
|
|
32
|
+
it('finds a changed passage after it moves past similar length prose', () => {
|
|
33
|
+
const original = 'Review the old draft with examples for the setup guide.';
|
|
34
|
+
const changed = 'Review the new draft with examples for the setup guide.';
|
|
35
|
+
const filler = Array.from({ length: 300 }, (_, i) => `Paragraph ${i} has approximately the same length as the review passage.`);
|
|
36
|
+
const block = { source: original, lines: { start: 2, end: 2 } };
|
|
37
|
+
expect(locateBlock(block, [...filler, changed].join('\n'))).toEqual({
|
|
38
|
+
status: 'changed',
|
|
39
|
+
lines: { start: 301, end: 301 },
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it('follows a paragraph reflowed across several source lines', () => {
|
|
43
|
+
const original = 'Review the new draft with concrete examples for the setup guide.';
|
|
44
|
+
const block = { source: original, lines: { start: 1, end: 1 } };
|
|
45
|
+
expect(locateBlock(block, 'Heading\nReview the new draft\nwith concrete examples\nfor the setup guide.')).toEqual({ status: 'changed', lines: { start: 2, end: 4 } });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=commentAnchor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commentAnchor.test.js","sourceRoot":"","sources":["../src/commentAnchor.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACpE,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,uBAAuB,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAA;QAC9E,MAAM,CACJ,WAAW,CAAC,KAAK,EAAE,0DAA0D,CAAC,CAC/E,CAAC,OAAO,CAAC;YACR,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;SAC5B,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,uBAAuB,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAA;QAC9E,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,gCAAgC,CAAC,CAAC,CAAC,OAAO,CAAC;YACnE,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;SAC5B,CAAC,CAAA;IACJ,CAAC,CA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C,CAAC,CAAC,CAAC,OAAO,CAAC;YAClE,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;SAChC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,QAAQ,GAAG,kEAAkE,CAAA;QACnF,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAA;QAC/D,MAAM,CACJ,WAAW,CACT,KAAK,EACL,6EAA6E,CAC9E,CACF,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one table the context item-kind narrowings derive from.
|
|
3
|
+
*
|
|
4
|
+
* **Why this file exists.** What an agent may *read* back
|
|
5
|
+
* (`ContextItemTypeSchema`) and what it may *capture* into the inbox
|
|
6
|
+
* (`CaptureContentTypeSchema`) are two narrowings of the same question, plus a lossy
|
|
7
|
+
* kind → item-type mapping and a
|
|
8
|
+
* SQL inverse of it in the items route. Each narrowing had a reason and none of
|
|
9
|
+
* them derived from a shared source, so adding a fourth kind meant editing five
|
|
10
|
+
* places and nothing failed if you missed one.
|
|
11
|
+
*
|
|
12
|
+
* Now one row per kind answers all of it declaratively. A new kind is a new row
|
|
13
|
+
* that must state whether it is pushable and capturable; it cannot be added and
|
|
14
|
+
* silently omitted from a narrowing, because no narrowing has its own list any
|
|
15
|
+
* more.
|
|
16
|
+
*
|
|
17
|
+
* `contextKinds.test.ts` pins each derived picklist against a hand-written copy
|
|
18
|
+
* of today's values, so a row edit that would change the wire fails there rather
|
|
19
|
+
* than in a client. Which kinds are pushable and capturable are product
|
|
20
|
+
* decisions this table records; changing one is a separate, deliberate change to
|
|
21
|
+
* that row.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The stored kinds that are addressable as context items on the wire.
|
|
25
|
+
*
|
|
26
|
+
* **Keyed on the `(role, format)` pair, and that is the load-bearing part.**
|
|
27
|
+
* A table keyed on `role` alone would quietly hand a
|
|
28
|
+
* **script** — `content` + `code` — both `pushable` and `capturable`, because
|
|
29
|
+
* nothing would separate it from a markdown document. It must not, and the pair
|
|
30
|
+
* is what stops it. This is the one place the two columns have to be read
|
|
31
|
+
* together; splitting a column does not by itself make every consumer
|
|
32
|
+
* single-column.
|
|
33
|
+
*
|
|
34
|
+
* Pairs *not* listed — `guidance`, `criteria`, `content` + `code`, and a row
|
|
35
|
+
* with no role at all — are still stored. They collapse onto
|
|
36
|
+
* {@link DEFAULT_CONTEXT_ITEM_TYPE} when serialized, and
|
|
37
|
+
* {@link kindFilterForItemTypes} is what keeps SQL agreeing with that.
|
|
38
|
+
*
|
|
39
|
+
* Order is the wire order of the derived picklists and is load-bearing for the
|
|
40
|
+
* pin test; append rather than reorder.
|
|
41
|
+
*/
|
|
42
|
+
export declare const CONTEXT_CONTENT_KINDS: readonly [{
|
|
43
|
+
readonly itemType: "content";
|
|
44
|
+
readonly role: "content";
|
|
45
|
+
readonly format: "markdown";
|
|
46
|
+
readonly pushable: true;
|
|
47
|
+
readonly capturable: true;
|
|
48
|
+
}, {
|
|
49
|
+
readonly itemType: "asset";
|
|
50
|
+
readonly role: "content";
|
|
51
|
+
readonly format: "binary";
|
|
52
|
+
readonly pushable: true;
|
|
53
|
+
readonly capturable: true;
|
|
54
|
+
}];
|
|
55
|
+
/**
|
|
56
|
+
* The item type of a `guides` row.
|
|
57
|
+
*
|
|
58
|
+
* A guide is not a stored `(role, format)` pair at all — it is a different
|
|
59
|
+
* table — which is why it is named here rather than added to the table above. It
|
|
60
|
+
* is readable as an item and deliberately not capturable.
|
|
61
|
+
*/
|
|
62
|
+
export declare const GUIDE_ITEM_TYPE = "guide";
|
|
63
|
+
/**
|
|
64
|
+
* What an unlisted pair serializes as.
|
|
65
|
+
*
|
|
66
|
+
* The default arm exists so a stray row — one written before a kind was
|
|
67
|
+
* retired, or by a non-context surface — produces a schema-valid response
|
|
68
|
+
* instead of failing the read. It is what makes the mapping lossy, and so what
|
|
69
|
+
* forces {@link kindFilterForItemTypes} to exist.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DEFAULT_CONTEXT_ITEM_TYPE = "content";
|
|
72
|
+
/** A stored `(role, format)` pair, as the table and the filters pass it around. */
|
|
73
|
+
export type ContentKind = {
|
|
74
|
+
role: string | null;
|
|
75
|
+
format: string | null;
|
|
76
|
+
};
|
|
77
|
+
/** Item types a stored kind can serialize as, in wire order. */
|
|
78
|
+
export declare const CONTEXT_CONTENT_TYPES: ("content" | "asset")[];
|
|
79
|
+
/** Item types an agent may read back, in wire order. */
|
|
80
|
+
export declare const CONTEXT_ITEM_TYPES: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Everything `?types=` parses.
|
|
83
|
+
*
|
|
84
|
+
* The same list a read serializes, now that nothing is accepted under a
|
|
85
|
+
* retired name: `document` was mapped through for one release so a filter
|
|
86
|
+
* written against the old vocabulary returned a superset rather than an
|
|
87
|
+
* empty page, and that window closed with the release that moved the CLI's
|
|
88
|
+
* own vocabulary — the same shape `reference`'s retirement closed under (git
|
|
89
|
+
* history has that window's open and close).
|
|
90
|
+
*/
|
|
91
|
+
export declare const CONTEXT_ITEM_TYPE_FILTER_VALUES: string[];
|
|
92
|
+
/** Values the inbox may capture. */
|
|
93
|
+
export declare const CAPTURE_CONTENT_TYPES: ("content" | "asset")[];
|
|
94
|
+
/**
|
|
95
|
+
* The item type a stored kind serializes as.
|
|
96
|
+
*
|
|
97
|
+
* Anything unrecognized — a guidance row, a rubric, a script, an `html` page, a
|
|
98
|
+
* row carrying no role at all — is a {@link DEFAULT_CONTEXT_ITEM_TYPE}, so a
|
|
99
|
+
* stray row never produces a schema-invalid response. That default is what
|
|
100
|
+
* makes this mapping non-injective: the pair cannot be recovered from an item's
|
|
101
|
+
* `type`, which is why filtering by type in SQL needs
|
|
102
|
+
* {@link kindFilterForItemTypes} rather than an inverted lookup.
|
|
103
|
+
*/
|
|
104
|
+
export declare function itemTypeForKind(role: string | null, format: string | null): (typeof CONTEXT_ITEM_TYPES)[number];
|
|
105
|
+
/**
|
|
106
|
+
* The item type a bundle read's item is, whether or not the server sent `type`.
|
|
107
|
+
*
|
|
108
|
+
* `type` is leaving the wire, and everything it said is already on the item: a
|
|
109
|
+
* guide is a `guides` row, so it is the only live item with no `(role, format)`
|
|
110
|
+
* pair at all. A tombstone also reports both as null, and says `removed`; an
|
|
111
|
+
* alias never travels as an item of its own. Every other item's type is
|
|
112
|
+
* {@link itemTypeForKind} of its pair, which is how the server derives it.
|
|
113
|
+
*/
|
|
114
|
+
export declare function contextItemTypeOf(item: {
|
|
115
|
+
type?: string | undefined;
|
|
116
|
+
role: string | null;
|
|
117
|
+
format: string | null;
|
|
118
|
+
removed?: true | undefined;
|
|
119
|
+
}): string;
|
|
120
|
+
/**
|
|
121
|
+
* How to select the rows whose kind serializes as one of `wantedItemTypes` —
|
|
122
|
+
* the inverse of {@link itemTypeForKind}, as data.
|
|
123
|
+
*
|
|
124
|
+
* **Data rather than SQL because `packages/` never imports from the dashboard.**
|
|
125
|
+
* The caller builds the predicate with its own
|
|
126
|
+
* query builder; what it must not have to re-derive is *which* kinds belong in
|
|
127
|
+
* it, which is exactly the knowledge that drifted.
|
|
128
|
+
*
|
|
129
|
+
* The two variants are the whole contract, and the second one is why this
|
|
130
|
+
* returns a tagged shape instead of a bare array:
|
|
131
|
+
*
|
|
132
|
+
* - `{ kind: 'in' }` — match a row whose pair is one of `kinds`.
|
|
133
|
+
* - `{ kind: 'inOrUnlisted' }` — match a row whose pair is one of `kinds`, **or**
|
|
134
|
+
* whose pair is none of `excluding`.
|
|
135
|
+
*
|
|
136
|
+
* **"None of `excluding`" has to be NULL-safe, and that is part of what the
|
|
137
|
+
* variant means rather than an extra the caller adds.** `role` and `format` are
|
|
138
|
+
* NULL on exactly the rows that carry no content — a tombstone — and in SQL a
|
|
139
|
+
* comparison against NULL is NULL, so a predicate written as a plain `!=` pair
|
|
140
|
+
* drops precisely the rows the serializer still calls `content` — the default
|
|
141
|
+
* kind. The route would then contradict itself about the same row, which is the
|
|
142
|
+
* defect this shape was introduced to prevent (Codex, PR #562, when the columns
|
|
143
|
+
* were one).
|
|
144
|
+
*
|
|
145
|
+
* `wantedItemTypes` values that are not item types at all (`guide`, or junk)
|
|
146
|
+
* simply match no kind; guides are not `guide_files` rows and are selected
|
|
147
|
+
* separately by their caller.
|
|
148
|
+
*/
|
|
149
|
+
export type ContentKindFilter = {
|
|
150
|
+
kind: 'in';
|
|
151
|
+
kinds: ContentKind[];
|
|
152
|
+
} | {
|
|
153
|
+
kind: 'inOrUnlisted';
|
|
154
|
+
kinds: ContentKind[];
|
|
155
|
+
excluding: ContentKind[];
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* An item type addressable through the context layer.
|
|
159
|
+
*
|
|
160
|
+
* Derived from {@link CONTEXT_CONTENT_TYPES} rather than restated, so the table
|
|
161
|
+
* above stays the one definition.
|
|
162
|
+
*/
|
|
163
|
+
export type ContextContentType = (typeof CONTEXT_CONTENT_TYPES)[number];
|
|
164
|
+
export declare function kindFilterForItemTypes(wantedItemTypes: Iterable<string>): ContentKindFilter;
|
|
165
|
+
//# sourceMappingURL=contextKinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextKinds.d.ts","sourceRoot":"","sources":["../src/contextKinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,qBAAqB;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