@mossbear/protocol 0.1.0-alpha.26

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mossbear
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @mossbear/protocol
2
+
3
+ Shared types and Valibot wire schemas for [Mossbear](https://app.mossbear.io) — the contract between the [`mossbear` CLI](https://www.npmjs.com/package/mossbear) and the Mossbear dashboard (action-sync payloads, raw guide-file payloads, context-bundle payloads).
4
+
5
+ You normally don't install this directly; it ships as a dependency of `mossbear`.
6
+
7
+ Source: https://github.com/auden-to/auden (`packages/protocol`)
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Bundle slug derivation — shared because every client that can create a bundle
3
+ * must produce a slug the server's `BundleSlugSchema` accepts, and there is one
4
+ * such rule. The dashboard's create row and the MCP `create_bundle` tool both
5
+ * call this; the server's unique index stays the authority on collisions.
6
+ */
7
+ /**
8
+ * The per-user bundle every imported guide is enrolled in
9
+ * (`unified-item-sync-plan.md` → Slice 0). Delivery is about to become
10
+ * bundle-members-only, and an imported guide starts with zero memberships, so
11
+ * without a default every existing guide would stop reaching every repo.
12
+ *
13
+ * **Well-known, and as of `inbox-as-view` slice 5 there is no other kind.** No
14
+ * slug is reserved any more: `inbox` was the last one, held open only while
15
+ * slice 3b's `unfiled` carve-out keyed on it, and both are gone. This bundle
16
+ * needs no lifecycle of its own either — it is an ordinary user bundle that
17
+ * happens to be pre-populated, and a user who renames it, prunes it or
18
+ * unsubscribes from it is expressing a real preference rather than corrupting
19
+ * an invariant.
20
+ *
21
+ * The consequence of not reserving it: a user who already owns a bundle at this
22
+ * slug has it adopted as their default rather than getting a second one at
23
+ * `my-guides-2`. That is the better outcome — a bundle the user already calls
24
+ * "my guides" is the bundle their guides belong in.
25
+ *
26
+ * Shared because both sides need it: the server materializes it, and the CLI
27
+ * discovers it by slug in the bundle listing to learn its **id**, which is what
28
+ * a committed subscription stores (plan → "A subscription names a bundle id,
29
+ * not a slug").
30
+ */
31
+ export declare const DEFAULT_GUIDES_SLUG = "my-guides";
32
+ /** Display name minted alongside {@link DEFAULT_GUIDES_SLUG}. */
33
+ export declare const DEFAULT_GUIDES_NAME = "My guides";
34
+ /**
35
+ * Derive a URL-safe bundle slug from a user-typed name, suffixing `-2`, `-3`…
36
+ * until it stops colliding with `taken`. No slug is reserved — `inbox-as-view`
37
+ * slice 5 retired the last one along with the carve-out that needed it — so
38
+ * `taken` is the whole rule. The server's unique index is still the authority;
39
+ * this only picks a candidate the common case won't bounce.
40
+ */
41
+ export declare function deriveBundleSlug(name: string, taken: ReadonlySet<string>): string;
42
+ //# sourceMappingURL=bundleSlug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundleSlug.d.ts","sourceRoot":"","sources":["../src/bundleSlug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,mBAAmB,cAAc,CAAA;AAE9C,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,cAAc,CAAA;AAmB9C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAUjF"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Bundle slug derivation — shared because every client that can create a bundle
3
+ * must produce a slug the server's `BundleSlugSchema` accepts, and there is one
4
+ * such rule. The dashboard's create row and the MCP `create_bundle` tool both
5
+ * call this; the server's unique index stays the authority on collisions.
6
+ */
7
+ /**
8
+ * The per-user bundle every imported guide is enrolled in
9
+ * (`unified-item-sync-plan.md` → Slice 0). Delivery is about to become
10
+ * bundle-members-only, and an imported guide starts with zero memberships, so
11
+ * without a default every existing guide would stop reaching every repo.
12
+ *
13
+ * **Well-known, and as of `inbox-as-view` slice 5 there is no other kind.** No
14
+ * slug is reserved any more: `inbox` was the last one, held open only while
15
+ * slice 3b's `unfiled` carve-out keyed on it, and both are gone. This bundle
16
+ * needs no lifecycle of its own either — it is an ordinary user bundle that
17
+ * happens to be pre-populated, and a user who renames it, prunes it or
18
+ * unsubscribes from it is expressing a real preference rather than corrupting
19
+ * an invariant.
20
+ *
21
+ * The consequence of not reserving it: a user who already owns a bundle at this
22
+ * slug has it adopted as their default rather than getting a second one at
23
+ * `my-guides-2`. That is the better outcome — a bundle the user already calls
24
+ * "my guides" is the bundle their guides belong in.
25
+ *
26
+ * Shared because both sides need it: the server materializes it, and the CLI
27
+ * discovers it by slug in the bundle listing to learn its **id**, which is what
28
+ * a committed subscription stores (plan → "A subscription names a bundle id,
29
+ * not a slug").
30
+ */
31
+ export const DEFAULT_GUIDES_SLUG = 'my-guides';
32
+ /** Display name minted alongside {@link DEFAULT_GUIDES_SLUG}. */
33
+ export const DEFAULT_GUIDES_NAME = 'My guides';
34
+ /**
35
+ * Matches `BundleSlugSchema`: lowercase alphanumerics + hyphens, starting
36
+ * alphanumeric, max 64 chars (`schemas.ts`).
37
+ */
38
+ const MAX_SLUG_LENGTH = 64;
39
+ function normalize(name) {
40
+ return name
41
+ .normalize('NFKD')
42
+ .replace(/[̀-ͯ]/g, '')
43
+ .toLowerCase()
44
+ .replace(/[^a-z0-9]+/g, '-')
45
+ .replace(/^-+|-+$/g, '')
46
+ .slice(0, MAX_SLUG_LENGTH)
47
+ .replace(/-+$/g, '');
48
+ }
49
+ /**
50
+ * Derive a URL-safe bundle slug from a user-typed name, suffixing `-2`, `-3`…
51
+ * until it stops colliding with `taken`. No slug is reserved — `inbox-as-view`
52
+ * slice 5 retired the last one along with the carve-out that needed it — so
53
+ * `taken` is the whole rule. The server's unique index is still the authority;
54
+ * this only picks a candidate the common case won't bounce.
55
+ */
56
+ export function deriveBundleSlug(name, taken) {
57
+ const base = normalize(name) || 'bundle';
58
+ const isFree = (slug) => !taken.has(slug);
59
+ if (isFree(base))
60
+ return base;
61
+ for (let n = 2;; n++) {
62
+ const suffix = `-${n}`;
63
+ const candidate = base.slice(0, MAX_SLUG_LENGTH - suffix.length) + suffix;
64
+ if (isFree(candidate))
65
+ return candidate;
66
+ }
67
+ }
68
+ //# sourceMappingURL=bundleSlug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundleSlug.js","sourceRoot":"","sources":["../src/bundleSlug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAA;AAE9C,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAA;AAE9C;;;GAGG;AACH,MAAM,eAAe,GAAG,EAAE,CAAA;AAE1B,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAI;SACR,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC;SACzB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,KAA0B;IACvE,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAA;IACxC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAEjD,IAAI,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC,EAAE,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;QACtB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;QACzE,IAAI,MAAM,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;IACzC,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bundleSlug.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundleSlug.test.d.ts","sourceRoot":"","sources":["../src/bundleSlug.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { deriveBundleSlug } 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
+ //# sourceMappingURL=bundleSlug.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundleSlug.test.js","sourceRoot":"","sources":["../src/bundleSlug.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO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AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @mossbear/protocol
3
+ *
4
+ * Runtime-validated shared schemas and transport contracts.
5
+ * This package must remain importable outside the CLI package.
6
+ */
7
+ export * from './bundleSlug.js';
8
+ export * from './schemas.js';
9
+ export * from './types.js';
10
+ export * from './version.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @mossbear/protocol
3
+ *
4
+ * Runtime-validated shared schemas and transport contracts.
5
+ * This package must remain importable outside the CLI package.
6
+ */
7
+ export * from './bundleSlug.js';
8
+ export * from './schemas.js';
9
+ export * from './types.js';
10
+ export * from './version.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}