@mossbear/protocol 0.1.0-alpha.115 → 0.1.0-alpha.117

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 (57) hide show
  1. package/dist/bundles.d.ts +662 -0
  2. package/dist/bundles.d.ts.map +1 -0
  3. package/dist/bundles.js +454 -0
  4. package/dist/bundles.js.map +1 -0
  5. package/dist/bundles.test.d.ts +2 -0
  6. package/dist/bundles.test.d.ts.map +1 -0
  7. package/dist/bundles.test.js +61 -0
  8. package/dist/bundles.test.js.map +1 -0
  9. package/dist/guideHistory.d.ts +643 -0
  10. package/dist/guideHistory.d.ts.map +1 -0
  11. package/dist/guideHistory.js +343 -0
  12. package/dist/guideHistory.js.map +1 -0
  13. package/dist/guideHistory.test.d.ts +2 -0
  14. package/dist/guideHistory.test.d.ts.map +1 -0
  15. package/dist/guideHistory.test.js +35 -0
  16. package/dist/guideHistory.test.js.map +1 -0
  17. package/dist/guideImport.d.ts +398 -0
  18. package/dist/guideImport.d.ts.map +1 -0
  19. package/dist/guideImport.js +350 -0
  20. package/dist/guideImport.js.map +1 -0
  21. package/dist/guideImport.test.d.ts +2 -0
  22. package/dist/guideImport.test.d.ts.map +1 -0
  23. package/dist/guideImport.test.js +62 -0
  24. package/dist/guideImport.test.js.map +1 -0
  25. package/dist/guideSnapshot.d.ts +105 -0
  26. package/dist/guideSnapshot.d.ts.map +1 -0
  27. package/dist/guideSnapshot.js +101 -0
  28. package/dist/guideSnapshot.js.map +1 -0
  29. package/dist/guideSnapshot.test.d.ts +2 -0
  30. package/dist/guideSnapshot.test.d.ts.map +1 -0
  31. package/dist/guideSnapshot.test.js +49 -0
  32. package/dist/guideSnapshot.test.js.map +1 -0
  33. package/dist/pairing.d.ts +1 -1
  34. package/dist/schemas.d.ts +43 -2072
  35. package/dist/schemas.d.ts.map +1 -1
  36. package/dist/schemas.js +43 -1389
  37. package/dist/schemas.js.map +1 -1
  38. package/dist/search.d.ts +97 -0
  39. package/dist/search.d.ts.map +1 -1
  40. package/dist/search.js +14 -0
  41. package/dist/search.js.map +1 -1
  42. package/dist/search.test.js +22 -0
  43. package/dist/search.test.js.map +1 -1
  44. package/dist/sessionGrade.d.ts +12 -12
  45. package/dist/sessionGrade.d.ts.map +1 -1
  46. package/dist/sessionGrade.js +11 -11
  47. package/dist/sessionGrade.js.map +1 -1
  48. package/dist/types.d.ts +4 -27
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/types.js.map +1 -1
  51. package/dist/whatSyncs.js +4 -4
  52. package/dist/whatSyncs.js.map +1 -1
  53. package/dist/wirePrimitives.d.ts +90 -3
  54. package/dist/wirePrimitives.d.ts.map +1 -1
  55. package/dist/wirePrimitives.js +124 -3
  56. package/dist/wirePrimitives.js.map +1 -1
  57. package/package.json +1 -1
@@ -0,0 +1,101 @@
1
+ /** Guide snapshot reads and observed rule-file delivery manifests. */
2
+ import * as v from 'valibot';
3
+ import { GuideFileFormatSchema } from './guideImport.js';
4
+ import { Sha256HexSchema, RepoIdSchema, GuideDiscoveryRootSchema, SafeRelativePosixPathSchema, } from './wirePrimitives.js';
5
+ // ---------------------------------------------------------------------------
6
+ // Guide snapshot schemas
7
+ // ---------------------------------------------------------------------------
8
+ export const GuideSnapshotSchema = v.object({
9
+ id: v.string(),
10
+ title: v.string(),
11
+ content: v.string(),
12
+ enabled: v.boolean(),
13
+ updatedAt: v.string(),
14
+ // origin is `file:{format}:{path}` for imported guides, null/absent
15
+ // otherwise. contentHash is the SHA-256 of the canonical bytes; the CLI uses
16
+ // the pair to round-trip imported files back to disk without re-encoding.
17
+ //
18
+ // **`origin` is not superseded by `(root, path)`.** Nothing on the write side
19
+ // reconciles on it after this slice, but `resolveRuleFileDelivery` still
20
+ // matches delivery evidence on `(origin, contentHash)`, so dropping it
21
+ // would make every guide read as undelivered — silently, since runs still
22
+ // grade and verdicts still appear. It stays as provenance.
23
+ origin: v.optional(v.nullable(v.string())),
24
+ contentHash: v.optional(v.nullable(Sha256HexSchema)),
25
+ // Which scope root `path` is relative to, and the path itself — the write
26
+ // side's half of the identity the read side already stores on
27
+ // `guide_files.root` / `guide_files.path`
28
+ // (`guide-write-side-identity-plan.md` → "Carry `root` on every write path").
29
+ //
30
+ // Without them the bundle could not express "global": `origin` is
31
+ // `file:{format}:{path}` with no root component, so every writer resolved it
32
+ // against the repo and a guide imported from `~/.claude/CLAUDE.md` came back
33
+ // down as `<repo>/.claude/CLAUDE.md`.
34
+ //
35
+ // **Both optional and nullable, and their absence is not an error.** A guide
36
+ // authored in the dashboard has no path; a row imported before the columns
37
+ // existed has neither. Such a guide keeps resolving from `origin` alone —
38
+ // today's behaviour — rather than becoming undeliverable. A missing `root` is
39
+ // read as `project`, which is what every pre-existing row meant.
40
+ root: v.optional(v.nullable(GuideDiscoveryRootSchema)),
41
+ path: v.optional(v.nullable(SafeRelativePosixPathSchema)),
42
+ });
43
+ export const GuideBundleResponseSchema = v.object({
44
+ guides: v.array(GuideSnapshotSchema),
45
+ pulledAt: v.string(),
46
+ });
47
+ /**
48
+ * Max rule files one delivery manifest enumerates. Well above what a real repo
49
+ * carries (this one: ~20), and bounded because the manifest rides every
50
+ * action-carrying batch: an unbounded list would multiply across a chunked
51
+ * sync. Overflow sets `truncated` rather than being dropped silently.
52
+ */
53
+ export const MAX_RULE_MANIFEST_FILES = 500;
54
+ /**
55
+ * A rule file observed on disk in the repo `mossbear report` ran from.
56
+ *
57
+ * `path` is relative to that repo root, in exactly the form `payloadPath`
58
+ * takes at import time (`packages/cli/src/guides/discover.ts`), so
59
+ * `file:{format}:{path}` reconstructs the `origin` the dashboard stored for
60
+ * the guide this file produced. That reconstruction is the whole join; nothing
61
+ * else about the file is needed and nothing else is sent.
62
+ *
63
+ * **Never any content.** `contentHash` is the same sha256 the import payload
64
+ * carries, present so a later slice can tell "delivered" from "delivered but
65
+ * edited since import" without shipping the bytes again.
66
+ */
67
+ export const RuleManifestFileSchema = v.object({
68
+ path: v.pipe(v.string(), v.minLength(1), v.maxLength(512)),
69
+ format: GuideFileFormatSchema,
70
+ contentHash: Sha256HexSchema,
71
+ });
72
+ /**
73
+ * Which rule files were actually on disk in the repo this sync ran from —
74
+ * observed delivery, replacing the assumption that every non-skill active
75
+ * guide reached the agent. Without it, an account with several repos, or a
76
+ * dashboard-authored guide never exported anywhere, is graded against
77
+ * instructions the agent never received.
78
+ *
79
+ * `repoId` is an opaque, machine-local digest — deliberately not a path, a
80
+ * remote URL, or a repo name. Its only job is to keep two checkouts on the
81
+ * same account distinguishable, which is the half of review finding 5 that
82
+ * repo-root-relative origins cannot express: two repos each holding
83
+ * `.claude/skills/review` produce byte-identical origins by construction. See
84
+ * `repoIdFromRoot` (`packages/cli/src/guides/manifest.ts`) for how it is
85
+ * derived and why that derivation is privacy-safe.
86
+ */
87
+ export const RuleFileManifestSchema = v.object({
88
+ repoId: RepoIdSchema,
89
+ files: v.pipe(v.array(RuleManifestFileSchema), v.maxLength(MAX_RULE_MANIFEST_FILES)),
90
+ /**
91
+ * The repo held more rule files than the cap, so `files` is a prefix. Set
92
+ * rather than silently trimmed: a manifest read as complete would mark the
93
+ * omitted files' guides undelivered, which is the exact wrong-verdict
94
+ * failure this field exists to prevent.
95
+ */
96
+ truncated: v.optional(v.boolean()),
97
+ });
98
+ export function parseGuideBundleResponse(data) {
99
+ return v.parse(GuideBundleResponseSchema, data);
100
+ }
101
+ //# sourceMappingURL=guideSnapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guideSnapshot.js","sourceRoot":"","sources":["../src/guideSnapshot.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAA;AAE5B,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E,MAAM,C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GAAG,GAAG,CAAA;AAE1C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC1D,MAAM,EAAE,qBAAqB;IAC7B,WAAW,EAAE,eAAe;CAC7B,CAAC,CAAA;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;IACpF;;;;;OAKG;IACH,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;CACnC,CAAC,CAAA;AAOF,MAAM,UAAU,wBAAwB,CAAC,IAAa;IACpD,OAAO,CAAC,CAAC,KAAK,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=guideSnapshot.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guideSnapshot.test.d.ts","sourceRoot":"","sources":["../src/guideSnapshot.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ import * as v from 'valibot';
2
+ import { describe, expect, expectTypeOf, it } from 'vitest';
3
+ import * as snapshots from './guideSnapshot.js';
4
+ import * as protocol from './index.js';
5
+ import * as schemas from './schemas.js';
6
+ describe('guide snapshot and rule manifest extraction', () => {
7
+ it('preserves every aggregate export and sync schema identity', () => {
8
+ for (const [name, value] of Object.entries(snapshots)) {
9
+ expect(Reflect.get(schemas, name), name).toBe(value);
10
+ expect(Reflect.get(protocol, name), name).toBe(value);
11
+ }
12
+ expect(schemas.DashboardSyncRequestSchema.entries.ruleManifest.wrapped).toBe(snapshots.RuleFileManifestSchema);
13
+ });
14
+ it('preserves inferred consumer types and parser output', () => {
15
+ expectTypeOf().toEqualTypeOf();
16
+ expectTypeOf().toEqualTypeOf();
17
+ expectTypeOf().toEqualTypeOf();
18
+ expectTypeOf().toEqualTypeOf();
19
+ expectTypeOf(snapshots.parseGuideBundleResponse).returns.toEqualTypeOf();
20
+ });
21
+ it('retains the manifest path contract independently of safe snapshot paths', () => {
22
+ // Manifest paths historically have length bounds only; do not tighten them
23
+ // to the snapshot's safe relative path contract during extraction.
24
+ const file = {
25
+ path: '../AGENTS.md',
26
+ format: 'agents-md',
27
+ contentHash: 'a'.repeat(64),
28
+ };
29
+ const manifest = { repoId: `repo_${'b'.repeat(32)}`, files: [file] };
30
+ expect(v.parse(snapshots.RuleFileManifestSchema, manifest)).toEqual(manifest);
31
+ expect(v.safeParse(snapshots.RuleManifestFileSchema, { ...file, path: '' }).success).toBe(false);
32
+ expect(v.safeParse(snapshots.RuleManifestFileSchema, { ...file, path: 'x'.repeat(513) })
33
+ .success).toBe(false);
34
+ expect(v.safeParse(snapshots.RuleFileManifestSchema, { ...manifest, repoId: 'bad' })
35
+ .success).toBe(false);
36
+ expect(v.safeParse(snapshots.RuleFileManifestSchema, {
37
+ ...manifest,
38
+ files: Array(snapshots.MAX_RULE_MANIFEST_FILES).fill(file),
39
+ truncated: true,
40
+ }).success).toBe(true);
41
+ expect(v.safeParse(snapshots.RuleFileManifestSchema, {
42
+ ...manifest,
43
+ files: Array(snapshots.MAX_RULE_MANIFEST_FILES + 1).fill(file),
44
+ }).success).toBe(false);
45
+ expect(v.safeParse(snapshots.RuleFileManifestSchema, { ...manifest, truncated: null })
46
+ .success).toBe(false);
47
+ });
48
+ });
49
+ //# sourceMappingURL=guideSnapshot.test.js.map
@@ -0,0 +1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AAC,IAAI,CAAC,IAAI,CAAC;YAC1D,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC,OAAO,CACX,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACZ,MAAM,CACJ,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,sBAAsB,EAAE;YAC5C,GAAG,QAAQ;YACX,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,uBAAuB,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;SAC/D,CAAC,CAAC,OAAO,CACX,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACb,MAAM,CACJ,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,sBAAsB,EAAE,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;aAC5E,OAAO,CACX,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/dist/pairing.d.ts CHANGED
@@ -191,6 +191,6 @@ export declare function parsePairDecisionRequest(data: unknown): {
191
191
  decision: "approve" | "deny";
192
192
  };
193
193
  export declare function parsePairDecisionResponse(data: unknown): {
194
- status: "approved" | "denied";
194
+ status: "denied" | "approved";
195
195
  };
196
196
  //# sourceMappingURL=pairing.d.ts.map