@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.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/agentGuidancePaths.d.ts +101 -0
  4. package/dist/agentGuidancePaths.d.ts.map +1 -0
  5. package/dist/agentGuidancePaths.js +185 -0
  6. package/dist/agentGuidancePaths.js.map +1 -0
  7. package/dist/agentGuidancePaths.test.d.ts +2 -0
  8. package/dist/agentGuidancePaths.test.d.ts.map +1 -0
  9. package/dist/agentGuidancePaths.test.js +91 -0
  10. package/dist/agentGuidancePaths.test.js.map +1 -0
  11. package/dist/aliasPaths.d.ts +100 -0
  12. package/dist/aliasPaths.d.ts.map +1 -0
  13. package/dist/aliasPaths.js +148 -0
  14. package/dist/aliasPaths.js.map +1 -0
  15. package/dist/aliasPaths.test.d.ts +2 -0
  16. package/dist/aliasPaths.test.d.ts.map +1 -0
  17. package/dist/aliasPaths.test.js +80 -0
  18. package/dist/aliasPaths.test.js.map +1 -0
  19. package/dist/artifact.test.d.ts +2 -0
  20. package/dist/artifact.test.d.ts.map +1 -0
  21. package/dist/artifact.test.js +374 -0
  22. package/dist/artifact.test.js.map +1 -0
  23. package/dist/bundleSlug.d.ts +177 -0
  24. package/dist/bundleSlug.d.ts.map +1 -0
  25. package/dist/bundleSlug.js +233 -0
  26. package/dist/bundleSlug.js.map +1 -0
  27. package/dist/bundleSlug.test.d.ts +2 -0
  28. package/dist/bundleSlug.test.d.ts.map +1 -0
  29. package/dist/bundleSlug.test.js +197 -0
  30. package/dist/bundleSlug.test.js.map +1 -0
  31. package/dist/commentAnchor.d.ts +34 -0
  32. package/dist/commentAnchor.d.ts.map +1 -0
  33. package/dist/commentAnchor.js +122 -0
  34. package/dist/commentAnchor.js.map +1 -0
  35. package/dist/commentAnchor.test.d.ts +2 -0
  36. package/dist/commentAnchor.test.d.ts.map +1 -0
  37. package/dist/commentAnchor.test.js +48 -0
  38. package/dist/commentAnchor.test.js.map +1 -0
  39. package/dist/contextKinds.d.ts +165 -0
  40. package/dist/contextKinds.d.ts.map +1 -0
  41. package/dist/contextKinds.js +148 -0
  42. package/dist/contextKinds.js.map +1 -0
  43. package/dist/contextKinds.test.d.ts +2 -0
  44. package/dist/contextKinds.test.d.ts.map +1 -0
  45. package/dist/contextKinds.test.js +137 -0
  46. package/dist/contextKinds.test.js.map +1 -0
  47. package/dist/frameDocument.d.ts +71 -0
  48. package/dist/frameDocument.d.ts.map +1 -0
  49. package/dist/frameDocument.js +140 -0
  50. package/dist/frameDocument.js.map +1 -0
  51. package/dist/frameDocument.test.d.ts +2 -0
  52. package/dist/frameDocument.test.d.ts.map +1 -0
  53. package/dist/frameDocument.test.js +84 -0
  54. package/dist/frameDocument.test.js.map +1 -0
  55. package/dist/frameProtocol.d.ts +11 -0
  56. package/dist/frameProtocol.d.ts.map +1 -0
  57. package/dist/frameProtocol.js +11 -0
  58. package/dist/frameProtocol.js.map +1 -0
  59. package/dist/index.d.ts +24 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +24 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/limits.d.ts +19 -0
  64. package/dist/limits.d.ts.map +1 -0
  65. package/dist/limits.js +19 -0
  66. package/dist/limits.js.map +1 -0
  67. package/dist/markdownSections.d.ts +58 -0
  68. package/dist/markdownSections.d.ts.map +1 -0
  69. package/dist/markdownSections.js +102 -0
  70. package/dist/markdownSections.js.map +1 -0
  71. package/dist/markdownSections.test.d.ts +2 -0
  72. package/dist/markdownSections.test.d.ts.map +1 -0
  73. package/dist/markdownSections.test.js +95 -0
  74. package/dist/markdownSections.test.js.map +1 -0
  75. package/dist/pairing.d.ts +183 -0
  76. package/dist/pairing.d.ts.map +1 -0
  77. package/dist/pairing.js +175 -0
  78. package/dist/pairing.js.map +1 -0
  79. package/dist/pairing.test.d.ts +2 -0
  80. package/dist/pairing.test.d.ts.map +1 -0
  81. package/dist/pairing.test.js +105 -0
  82. package/dist/pairing.test.js.map +1 -0
  83. package/dist/photos.d.ts +146 -0
  84. package/dist/photos.d.ts.map +1 -0
  85. package/dist/photos.js +127 -0
  86. package/dist/photos.js.map +1 -0
  87. package/dist/publicModelCatalog.d.ts +19 -0
  88. package/dist/publicModelCatalog.d.ts.map +1 -0
  89. package/dist/publicModelCatalog.generated.d.ts +2 -0
  90. package/dist/publicModelCatalog.generated.d.ts.map +1 -0
  91. package/dist/publicModelCatalog.generated.js +489 -0
  92. package/dist/publicModelCatalog.generated.js.map +1 -0
  93. package/dist/publicModelCatalog.js +68 -0
  94. package/dist/publicModelCatalog.js.map +1 -0
  95. package/dist/publicModelCatalog.test.d.ts +2 -0
  96. package/dist/publicModelCatalog.test.d.ts.map +1 -0
  97. package/dist/publicModelCatalog.test.js +88 -0
  98. package/dist/publicModelCatalog.test.js.map +1 -0
  99. package/dist/publicModelNativeAliases.d.ts +5 -0
  100. package/dist/publicModelNativeAliases.d.ts.map +1 -0
  101. package/dist/publicModelNativeAliases.js +8 -0
  102. package/dist/publicModelNativeAliases.js.map +1 -0
  103. package/dist/schemas.d.ts +10745 -0
  104. package/dist/schemas.d.ts.map +1 -0
  105. package/dist/schemas.js +4572 -0
  106. package/dist/schemas.js.map +1 -0
  107. package/dist/schemas.test.d.ts +2 -0
  108. package/dist/schemas.test.d.ts.map +1 -0
  109. package/dist/schemas.test.js +1617 -0
  110. package/dist/schemas.test.js.map +1 -0
  111. package/dist/steeringOverTime.d.ts +30 -0
  112. package/dist/steeringOverTime.d.ts.map +1 -0
  113. package/dist/steeringOverTime.js +19 -0
  114. package/dist/steeringOverTime.js.map +1 -0
  115. package/dist/types.d.ts +109 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +12 -0
  118. package/dist/types.js.map +1 -0
  119. package/dist/usageOnly.d.ts +190 -0
  120. package/dist/usageOnly.d.ts.map +1 -0
  121. package/dist/usageOnly.js +53 -0
  122. package/dist/usageOnly.js.map +1 -0
  123. package/dist/usageOnly.test.d.ts +2 -0
  124. package/dist/usageOnly.test.d.ts.map +1 -0
  125. package/dist/usageOnly.test.js +203 -0
  126. package/dist/usageOnly.test.js.map +1 -0
  127. package/dist/version.d.ts +47 -0
  128. package/dist/version.d.ts.map +1 -0
  129. package/dist/version.js +125 -0
  130. package/dist/version.js.map +1 -0
  131. package/dist/version.test.d.ts +2 -0
  132. package/dist/version.test.d.ts.map +1 -0
  133. package/dist/version.test.js +86 -0
  134. package/dist/version.test.js.map +1 -0
  135. package/dist/whatSyncs.d.ts +62 -0
  136. package/dist/whatSyncs.d.ts.map +1 -0
  137. package/dist/whatSyncs.js +228 -0
  138. package/dist/whatSyncs.js.map +1 -0
  139. package/dist/whatSyncs.test.d.ts +2 -0
  140. package/dist/whatSyncs.test.d.ts.map +1 -0
  141. package/dist/whatSyncs.test.js +113 -0
  142. package/dist/whatSyncs.test.js.map +1 -0
  143. package/package.json +52 -0
@@ -0,0 +1,148 @@
1
+ /**
2
+ * **Which paths are the same rules under two names** — the alias sets
3
+ * (`alias-instruction-file-identity-plan.md` → Decision 5, *same
4
+ * root, different path*).
5
+ *
6
+ * A repo that uses Cursor alongside anything else can hold `.cursorrules` and
7
+ * `AGENTS.md` with the same rules in both, and without this each imports as its
8
+ * own guide with nothing keeping them together. This module is the one definition
9
+ * of "these two paths are one rule", so the server can collapse an identical
10
+ * pair into a single guide and the CLI can derive the mirror in the checkout
11
+ * from the same list.
12
+ *
13
+ * **Why the protocol package.** Both sides need the identical answer and they
14
+ * sit on opposite sides of the wire — the import route decides which payloads
15
+ * collapse, and the CLI's docs phase decides which files to derive. Same
16
+ * argument as {@link ./agentGuidancePaths.ts}, and the same failure mode from
17
+ * keeping a copy on each side: a path added to one and missed on the other is
18
+ * silent in exactly one direction, since the server would merge a pair the CLI
19
+ * then never mirrors.
20
+ *
21
+ * **Not a discovery list.** Discovery decides what to scan
22
+ * (`packages/cli/src/rules/discover.ts:93-105`); this decides which of the
23
+ * scanned paths are interchangeable. The two overlap without either being a
24
+ * subset of the other: `.claude/rules/*.md` is discovered and has no alias, and
25
+ * a future `~/.agents/skills` root is an alias of `.claude/skills` before any
26
+ * scan reaches it.
27
+ */
28
+ import { AGENT_GUIDANCE_FILES } from './agentGuidancePaths.js';
29
+ /** Group key for the root instruction files — `AGENTS.md` and its twins. */
30
+ export const ROOT_INSTRUCTIONS_ALIAS_GROUP = 'root-instructions';
31
+ /**
32
+ * The root instruction files that are one set, in preference order.
33
+ *
34
+ * **`CLAUDE.md` is deliberately not one of them.** Claude Code reads a
35
+ * `CLAUDE.md` *instead of* `AGENTS.md` when both exist, and the documented way
36
+ * to make it read both is a `CLAUDE.md` that imports `AGENTS.md`
37
+ * (`@AGENTS.md`). So `CLAUDE.md` belongs to whoever keeps it — a one-line
38
+ * redirect, Claude-specific notes, or both — and Mossbear's only business with
39
+ * it is that the import is there. Treating it as a byte twin of `AGENTS.md`
40
+ * merged the two on the server and had the CLI copy edits between them, which
41
+ * carried a Claude-only line into the file every other agent reads. Leaving it
42
+ * out here is what stops both halves at once: the import route no longer merges
43
+ * it, and no alias row exists for the CLI to mirror.
44
+ */
45
+ const ROOT_INSTRUCTION_ALIAS_FILES = AGENT_GUIDANCE_FILES.filter((file) => file !== 'CLAUDE.md');
46
+ /** Group-key prefix for one skill's `SKILL.md` under either skills directory. */
47
+ export const SKILL_ALIAS_GROUP_PREFIX = 'skill:';
48
+ /**
49
+ * The skills directories that hold the same skill under two names
50
+ * (`packages/projections/src/detect-format.ts:7-14` classifies both as
51
+ * `skill-md`). Order is the preference order below.
52
+ */
53
+ const SKILL_DIRS = ['.agents/skills/', '.claude/skills/'];
54
+ /**
55
+ * The comparison key for a path: separators folded, repeats collapsed,
56
+ * lowercased — the way `detectFormat` normalizes
57
+ * (`packages/projections/src/detect-format.ts:3-5`). `AGENTS.md` and `agents.md`
58
+ * are two strings and one file on macOS and Windows, and an exact-match rule
59
+ * would put the same file in two alias sets.
60
+ *
61
+ * **Exported because a stored path has to be compared the same way.** A guide
62
+ * is stored at the spelling its file had, so `.claude/skills/Review/SKILL.md`
63
+ * and `.agents/skills/review/SKILL.md` are one set under
64
+ * {@link aliasPathIdentity} and two strings to anything that compares the
65
+ * paths themselves. The import route looks a set's other half up on the server
66
+ * and must ask it with this function, or it finds nothing and forks a second
67
+ * guide; this is the one place that decides when two spellings are one path.
68
+ */
69
+ export function aliasPathKey(path) {
70
+ return collapseSeparators(path).toLowerCase();
71
+ }
72
+ /**
73
+ * The separator half of {@link normalize}, without the lowercasing. Split out
74
+ * because {@link aliasPathSiblings} builds strings that are looked *up* rather
75
+ * than compared, so it needs the path's own spelling back.
76
+ */
77
+ function collapseSeparators(path) {
78
+ return path.replaceAll('\\', '/').replace(/\/+/g, '/');
79
+ }
80
+ /**
81
+ * The alias set a discovery-root-relative path belongs to, or `null` when the
82
+ * path has no alias — which is most paths, and is not an error.
83
+ *
84
+ * Takes the path alone because a set never spans roots: the caller compares
85
+ * `root` itself (Decision 5 keys on *same root, different path*, which is what
86
+ * leaves a project skill and its `~/.claude/skills` twin as two guides). Doing
87
+ * it here instead would need the root passed to every call and would still not
88
+ * be able to enforce it, since one path's identity says nothing about another's.
89
+ */
90
+ export function aliasPathIdentity(path) {
91
+ const normalized = aliasPathKey(path);
92
+ const rootFileRank = ROOT_INSTRUCTION_ALIAS_FILES.findIndex((candidate) => candidate.toLowerCase() === normalized);
93
+ if (rootFileRank !== -1) {
94
+ return { group: ROOT_INSTRUCTIONS_ALIAS_GROUP, rank: rootFileRank };
95
+ }
96
+ for (const [rank, dir] of SKILL_DIRS.entries()) {
97
+ if (!normalized.startsWith(dir))
98
+ continue;
99
+ if (!normalized.endsWith('/skill.md'))
100
+ return null;
101
+ const name = normalized.slice(dir.length, normalized.length - '/skill.md'.length);
102
+ // A `SKILL.md` directly under `skills/` has no skill name and is not a
103
+ // skill discovery would import as one; a nested `a/b/SKILL.md` is one skill
104
+ // named `a/b` in both directories alike, so the whole remainder is the key.
105
+ if (name.length === 0)
106
+ return null;
107
+ return { group: `${SKILL_ALIAS_GROUP_PREFIX}${name}`, rank };
108
+ }
109
+ return null;
110
+ }
111
+ /**
112
+ * The **other** paths in one path's alias set — the file's twins, whether or
113
+ * not they exist on disk or on the server.
114
+ *
115
+ * {@link aliasPathIdentity} answers "which set is this path in"; this answers
116
+ * "what else is in it". The import route needs the second question because a
117
+ * set's other half is routinely absent from the request that carries this half:
118
+ * a file already managed as a guide is excluded from the payload, so the only
119
+ * way to find it is to name the path it would sit at and look it up. Returns
120
+ * `[]` for a path with no alias, which is most paths and is not an error.
121
+ *
122
+ * Case is carried over from the caller's path rather than normalized away:
123
+ * `aliasPathIdentity` lowercases to compare, but these strings are used to
124
+ * *look rows up*, and a stored path is stored as it was written. So the skill
125
+ * name and the `SKILL.md` segment keep the spelling they arrived with, and only
126
+ * the directory prefix comes from the list — which is the half that is fixed.
127
+ * Comparing what comes back is
128
+ * the caller's job, and it does so through {@link aliasPathKey}: the stored twin
129
+ * may be spelled some other way than the string built here.
130
+ */
131
+ export function aliasPathSiblings(path) {
132
+ const identity = aliasPathIdentity(path);
133
+ if (identity === null)
134
+ return [];
135
+ const collapsed = collapseSeparators(path);
136
+ const lowered = collapsed.toLowerCase();
137
+ if (identity.group === ROOT_INSTRUCTIONS_ALIAS_GROUP) {
138
+ return ROOT_INSTRUCTION_ALIAS_FILES.filter((candidate) => candidate.toLowerCase() !== lowered);
139
+ }
140
+ const dir = SKILL_DIRS.find((candidate) => lowered.startsWith(candidate));
141
+ if (dir === undefined)
142
+ return [];
143
+ // `/SKILL.md` as the caller spelled it, and the skill name between the two.
144
+ const suffix = collapsed.slice(collapsed.length - '/SKILL.md'.length);
145
+ const name = collapsed.slice(dir.length, collapsed.length - suffix.length);
146
+ return SKILL_DIRS.filter((candidate) => candidate !== dir).map((candidate) => `${candidate}${name}${suffix}`);
147
+ }
148
+ //# sourceMappingURL=aliasPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliasPaths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4EAA4E;IAC5E,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IACrE,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1E,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,GAAG,CAC5D,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,EAAE,CAC9C,CAAA;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=aliasPaths.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliasPaths.test.d.ts","sourceRoot":"","sources":["../src/aliasPaths.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,80 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ROOT_INSTRUCTIONS_ALIAS_GROUP, aliasPathIdentity, aliasPathKey, aliasPathSiblings, } from './aliasPaths.js';
3
+ describe('aliasPathIdentity', () => {
4
+ it('puts AGENTS.md and .cursorrules in one set, AGENTS.md preferred', () => {
5
+ const agents = aliasPathIdentity('AGENTS.md');
6
+ const cursor = aliasPathIdentity('.cursorrules');
7
+ expect(agents?.group).toBe(ROOT_INSTRUCTIONS_ALIAS_GROUP);
8
+ expect(cursor?.group).toBe(ROOT_INSTRUCTIONS_ALIAS_GROUP);
9
+ expect(agents?.rank).toBeLessThan(cursor?.rank ?? Infinity);
10
+ });
11
+ it('leaves CLAUDE.md out of the set: it imports AGENTS.md rather than mirroring it', () => {
12
+ expect(aliasPathIdentity('CLAUDE.md')).toBeNull();
13
+ expect(aliasPathIdentity('claude.md')).toBeNull();
14
+ });
15
+ it('reads a differently-cased file name as the same file', () => {
16
+ expect(aliasPathIdentity('agents.md')?.group).toBe(ROOT_INSTRUCTIONS_ALIAS_GROUP);
17
+ });
18
+ it('pairs one skill across the two skills directories, .agents preferred', () => {
19
+ const agents = aliasPathIdentity('.agents/skills/review/SKILL.md');
20
+ const claude = aliasPathIdentity('.claude/skills/review/SKILL.md');
21
+ expect(agents?.group).toBe('skill:review');
22
+ expect(claude?.group).toBe('skill:review');
23
+ expect(agents?.rank).toBeLessThan(claude?.rank ?? Infinity);
24
+ });
25
+ it('gives two differently-named skills different sets', () => {
26
+ expect(aliasPathIdentity('.agents/skills/review/SKILL.md')?.group).not.toBe(aliasPathIdentity('.claude/skills/deploy/SKILL.md')?.group);
27
+ });
28
+ it('reads two spellings of one path as one file, not a set of two', () => {
29
+ // Same group *and* same file: a caller grouping by group key must still see
30
+ // one path here, or the collapse would write an alias row for the path that
31
+ // already holds the body.
32
+ expect(aliasPathIdentity('AGENTS.md')).toEqual(aliasPathIdentity('agents.md'));
33
+ expect(aliasPathIdentity('.claude//skills/review/SKILL.md')).toEqual(aliasPathIdentity('.claude/skills/review/SKILL.md'));
34
+ });
35
+ it('leaves a skill member file, a nested rules file and an ordinary doc unaliased', () => {
36
+ expect(aliasPathIdentity('.claude/skills/review/scripts/run.sh')).toBeNull();
37
+ expect(aliasPathIdentity('.claude/rules/style.md')).toBeNull();
38
+ expect(aliasPathIdentity('docs/architecture.md')).toBeNull();
39
+ expect(aliasPathIdentity('.agents/skills/SKILL.md')).toBeNull();
40
+ });
41
+ });
42
+ describe('aliasPathKey', () => {
43
+ it('reads spellings of one path as one key, and keeps different paths apart', () => {
44
+ expect(aliasPathKey('.claude/skills/Review/SKILL.md')).toBe(aliasPathKey('.claude//skills\\review/skill.md'));
45
+ expect(aliasPathKey('.claude/skills/review/SKILL.md')).not.toBe(aliasPathKey('.agents/skills/review/SKILL.md'));
46
+ });
47
+ it('agrees with aliasPathIdentity about which spellings are one skill', () => {
48
+ const stored = '.agents/skills/Review/SKILL.md';
49
+ const [twin] = aliasPathSiblings('.claude/skills/review/SKILL.md');
50
+ expect(aliasPathIdentity(stored)?.group).toBe(aliasPathIdentity(twin ?? '')?.group);
51
+ expect(aliasPathKey(stored)).toBe(aliasPathKey(twin ?? ''));
52
+ });
53
+ });
54
+ describe('aliasPathSiblings', () => {
55
+ it('names the other root instruction files, and never the path itself', () => {
56
+ expect(aliasPathSiblings('AGENTS.md')).toEqual(['.cursorrules']);
57
+ expect(aliasPathSiblings('.cursorrules')).toEqual(['AGENTS.md']);
58
+ expect(aliasPathSiblings('CLAUDE.md')).toEqual([]);
59
+ });
60
+ it('names the twin skills directory, keeping the skill name as written', () => {
61
+ expect(aliasPathSiblings('.claude/skills/Design-Review/SKILL.md')).toEqual([
62
+ '.agents/skills/Design-Review/SKILL.md',
63
+ ]);
64
+ expect(aliasPathSiblings('.agents/skills/a/b/SKILL.md')).toEqual([
65
+ '.claude/skills/a/b/SKILL.md',
66
+ ]);
67
+ });
68
+ it('reads a differently-cased path as the same file, and hands back its spelling', () => {
69
+ expect(aliasPathSiblings('agents.md')).toEqual(['.cursorrules']);
70
+ expect(aliasPathSiblings('.claude//skills/review/SKILL.md')).toEqual([
71
+ '.agents/skills/review/SKILL.md',
72
+ ]);
73
+ });
74
+ it('has nothing to say about a path with no alias', () => {
75
+ expect(aliasPathSiblings('docs/architecture.md')).toEqual([]);
76
+ expect(aliasPathSiblings('.claude/skills/review/scripts/run.sh')).toEqual([]);
77
+ expect(aliasPathSiblings('.agents/skills/SKILL.md')).toEqual([]);
78
+ });
79
+ });
80
+ //# sourceMappingURL=aliasPaths.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliasPaths.test.js","sourceRoot":"","sources":["../src/aliasPaths.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EACL,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,GAClB,MAAM,iBAAiB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,CAAC,CAAC,CAAC,OAAO,CAAC;YAC/D,6BAA6B;SAC9B,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,8EAA8E,EAAE,GAAG,EAAE;QACtF,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAA;QAChE,MAAM,CAAC,iBAAiB,CAAC,iCAAiC,CAAC,CAAC,CAAC,OAAO,CAAC;YACnE,gCAAgC;SACjC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC7D,MAAM,CAAC,iBAAiB,CAAC,sCAAsC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC7E,MAAM,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAClE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=artifact.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact.test.d.ts","sourceRoot":"","sources":["../src/artifact.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,374 @@
1
+ import * as v from 'valibot';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { DeleteArtifactRequestSchema, ArtifactHistoryQuerySchema, ArtifactHistoryResponseSchema, ArtifactRecordedSourceRefSchema, ArtifactSchema, ArtifactSourceRefSchema, ArtifactVersionConflictSchema, artifactKindOf, CreatableArtifactFormatSchema, CreateArtifactRequestSchema, ListArtifactsQuerySchema, ListArtifactsResponseSchema, ReadArtifactQuerySchema, ReadArtifactResponseSchema, WithdrawArtifactRequestSchema, WithdrawArtifactResponseSchema, UpdateArtifactRequestSchema, UpsertArtifactDraftRequestSchema, } from './schemas.js';
4
+ const artifact = {
5
+ id: 'file_1',
6
+ name: 'Plan',
7
+ role: 'content',
8
+ format: 'markdown',
9
+ version: 3,
10
+ state: 'live',
11
+ workspaceId: 'ws_1',
12
+ kind: 'markdown',
13
+ capture: false,
14
+ content: '# Plan',
15
+ createdAt: '2026-10-01T00:00:00.000Z',
16
+ updatedAt: '2026-10-07T00:00:00.000Z',
17
+ };
18
+ const ok = (schema, value) => v.safeParse(schema, value).success;
19
+ describe('ArtifactSchema', () => {
20
+ it('accepts a document and a guide with real role and format', () => {
21
+ expect(ok(ArtifactSchema, artifact)).toBe(true);
22
+ expect(ok(ArtifactSchema, { ...artifact, role: 'guidance', format: 'markdown' })).toBe(true);
23
+ });
24
+ it('rejects null or unknown role and format', () => {
25
+ expect(ok(ArtifactSchema, { ...artifact, role: null })).toBe(false);
26
+ expect(ok(ArtifactSchema, { ...artifact, format: null })).toBe(false);
27
+ expect(ok(ArtifactSchema, { ...artifact, role: 'rubric' })).toBe(false);
28
+ expect(ok(ArtifactSchema, { ...artifact, format: 'pdf' })).toBe(false);
29
+ });
30
+ it('requires version, state, workspace and capture', () => {
31
+ for (const key of ['version', 'state', 'workspaceId', 'capture']) {
32
+ const { [key]: _omitted, ...rest } = artifact;
33
+ expect(ok(ArtifactSchema, rest)).toBe(false);
34
+ }
35
+ expect(ok(ArtifactSchema, { ...artifact, state: 'alias' })).toBe(false);
36
+ });
37
+ });
38
+ describe('CreateArtifactRequestSchema', () => {
39
+ it('accepts name and content with no bundle', () => {
40
+ expect(ok(CreateArtifactRequestSchema, { name: 'n', content: 'c' })).toBe(true);
41
+ });
42
+ it('accepts a bundle slug and creatable format', () => {
43
+ expect(ok(CreateArtifactRequestSchema, {
44
+ name: 'n',
45
+ content: 'c',
46
+ bundle: 'my-bundle',
47
+ format: 'markdown',
48
+ })).toBe(true);
49
+ });
50
+ it('accepts an html page, the format the dashboard renders in a frame', () => {
51
+ expect(ok(CreateArtifactRequestSchema, { name: 'n', content: '<p>hi</p>', format: 'html' })).toBe(true);
52
+ });
53
+ it('refuses binary, which stores text but reads back with no content', () => {
54
+ expect(ok(CreateArtifactRequestSchema, { name: 'n', content: 'c', format: 'binary' })).toBe(false);
55
+ expect(CreatableArtifactFormatSchema.options).not.toContain('binary');
56
+ });
57
+ it('bounds a read version to the 32-bit column', () => {
58
+ expect(ok(ReadArtifactQuerySchema, { version: 2147483647 })).toBe(true);
59
+ expect(ok(ReadArtifactQuerySchema, { version: 2147483648 })).toBe(false);
60
+ expect(ok(ReadArtifactQuerySchema, { version: 1e16 })).toBe(false);
61
+ });
62
+ it('rejects non-creatable format, bad slug, empty name', () => {
63
+ const base = { name: 'n', content: 'c' };
64
+ expect(ok(CreateArtifactRequestSchema, { ...base, format: 'code' })).toBe(false);
65
+ expect(ok(CreateArtifactRequestSchema, { ...base, bundle: 'Bad Slug' })).toBe(false);
66
+ expect(ok(CreateArtifactRequestSchema, { ...base, name: '' })).toBe(false);
67
+ });
68
+ it('is not an update: an id or expectedVersion is refused', () => {
69
+ expect(ok(CreateArtifactRequestSchema, { name: 'n', content: 'c', itemId: 'x' })).toBe(false);
70
+ expect(ok(CreateArtifactRequestSchema, { name: 'n', content: 'c', expectedVersion: 1 })).toBe(false);
71
+ });
72
+ });
73
+ describe('CreateArtifactRequestSchema publication claims', () => {
74
+ const gitSource = { projectId: 'proj_1', commitSha: 'a'.repeat(40), branch: 'main' };
75
+ it('accepts a path, project and git source beside the bundle', () => {
76
+ expect(ok(CreateArtifactRequestSchema, {
77
+ name: 'review.md',
78
+ content: 'c',
79
+ bundle: 'standards',
80
+ path: 'skills/review.md',
81
+ projectId: 'proj_1',
82
+ gitSource,
83
+ })).toBe(true);
84
+ });
85
+ it('refuses an unsafe path, a malformed git source, a blank project', () => {
86
+ const base = { name: 'n', content: 'c', bundle: 'b' };
87
+ for (const path of ['/abs.md', '../up.md', 'a//b.md', 'a\\b.md']) {
88
+ expect(ok(CreateArtifactRequestSchema, { ...base, path })).toBe(false);
89
+ }
90
+ expect(ok(CreateArtifactRequestSchema, {
91
+ ...base,
92
+ gitSource: { projectId: 'p', commitSha: 'short' },
93
+ })).toBe(false);
94
+ expect(ok(CreateArtifactRequestSchema, { ...base, projectId: ' ' })).toBe(false);
95
+ });
96
+ it('has no root: a declared scope is not a create claim', () => {
97
+ expect(ok(CreateArtifactRequestSchema, { name: 'n', content: 'c', root: 'project' })).toBe(false);
98
+ });
99
+ });
100
+ describe('WithdrawArtifactRequestSchema', () => {
101
+ const gitSource = { projectId: 'proj_1', commitSha: 'b'.repeat(40) };
102
+ it('needs the commit that removed the file and the checkout it comes from', () => {
103
+ expect(ok(WithdrawArtifactRequestSchema, { gitSource, projectId: 'proj_1' })).toBe(true);
104
+ expect(ok(WithdrawArtifactRequestSchema, { projectId: 'proj_1' })).toBe(false);
105
+ expect(ok(WithdrawArtifactRequestSchema, { gitSource })).toBe(false);
106
+ expect(ok(WithdrawArtifactRequestSchema, {})).toBe(false);
107
+ });
108
+ it('takes an optional positive integer version', () => {
109
+ const base = { gitSource, projectId: 'p' };
110
+ expect(ok(WithdrawArtifactRequestSchema, { ...base, expectedVersion: 4 })).toBe(true);
111
+ for (const expectedVersion of [0, -1, 1.5]) {
112
+ expect(ok(WithdrawArtifactRequestSchema, { ...base, expectedVersion })).toBe(false);
113
+ }
114
+ });
115
+ it('may name the one bundle a withdrawal is for', () => {
116
+ const base = { gitSource, projectId: 'p' };
117
+ expect(ok(WithdrawArtifactRequestSchema, { ...base, onlyMemberOf: 'bun_1' })).toBe(true);
118
+ expect(ok(WithdrawArtifactRequestSchema, { ...base, onlyMemberOf: '' })).toBe(false);
119
+ });
120
+ it('carries no content or path, and is not an update', () => {
121
+ const base = { gitSource, projectId: 'p' };
122
+ expect(ok(WithdrawArtifactRequestSchema, { ...base, content: 'c' })).toBe(false);
123
+ expect(ok(WithdrawArtifactRequestSchema, { ...base, path: 'a.md' })).toBe(false);
124
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c', expectedVersion: 1, removed: true })).toBe(false);
125
+ });
126
+ it('answers with the artifact, which may be state removed', () => {
127
+ expect(ok(WithdrawArtifactResponseSchema, { artifact: { ...artifact, state: 'removed' } })).toBe(true);
128
+ });
129
+ });
130
+ describe('UpdateArtifactRequestSchema', () => {
131
+ it('accepts an explicit preserve-ownership intent without changing publication requests', () => {
132
+ const publication = {
133
+ content: 'c',
134
+ expectedVersion: 1,
135
+ projectId: 'project-home',
136
+ gitSource: { projectId: 'project-home', commitSha: 'a'.repeat(40) },
137
+ };
138
+ expect(v.parse(UpdateArtifactRequestSchema, publication)).toEqual(publication);
139
+ expect(v.parse(UpdateArtifactRequestSchema, { ...publication, preserveOwnership: true })).toEqual({ ...publication, preserveOwnership: true });
140
+ expect(ok(UpdateArtifactRequestSchema, { ...publication, preserveOwnership: false })).toBe(false);
141
+ });
142
+ it('accepts content with expectedVersion', () => {
143
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c', expectedVersion: 2 })).toBe(true);
144
+ });
145
+ it('rejects a missing, zero or fractional expectedVersion', () => {
146
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c' })).toBe(false);
147
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c', expectedVersion: 0 })).toBe(false);
148
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c', expectedVersion: 1.5 })).toBe(false);
149
+ });
150
+ it('refuses create-only fields', () => {
151
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c', expectedVersion: 1, bundle: 'b' })).toBe(false);
152
+ });
153
+ it('accepts a name or a description alone, and null to clear a description', () => {
154
+ expect(ok(UpdateArtifactRequestSchema, { name: 'Whiteboard', expectedVersion: 1 })).toBe(true);
155
+ expect(ok(UpdateArtifactRequestSchema, {
156
+ description: 'After standup',
157
+ expectedVersion: 1,
158
+ })).toBe(true);
159
+ expect(ok(UpdateArtifactRequestSchema, { description: null, expectedVersion: 1 })).toBe(true);
160
+ });
161
+ it('refuses a request that changes nothing', () => {
162
+ expect(ok(UpdateArtifactRequestSchema, { expectedVersion: 1 })).toBe(false);
163
+ });
164
+ it('refuses a description that is blank, too long, or more than one line', () => {
165
+ for (const description of [
166
+ '',
167
+ ' ',
168
+ 'x'.repeat(1001),
169
+ 'a\nb',
170
+ 'a\u2028b',
171
+ 'a\u001b[31m',
172
+ 'a\u202eb',
173
+ '\u200b\u200d',
174
+ ]) {
175
+ expect(ok(UpdateArtifactRequestSchema, { description, expectedVersion: 1 })).toBe(false);
176
+ }
177
+ expect(ok(UpdateArtifactRequestSchema, {
178
+ description: 'x'.repeat(1000),
179
+ expectedVersion: 1,
180
+ })).toBe(true);
181
+ // The zero-width joiner some scripts need is not a control.
182
+ expect(ok(UpdateArtifactRequestSchema, { description: 'क्\u200dष', expectedVersion: 1 })).toBe(true);
183
+ });
184
+ });
185
+ describe('source references', () => {
186
+ const commit = 'a'.repeat(40);
187
+ it('accepts a full pin and a minimal id-only reference', () => {
188
+ expect(ok(ArtifactSourceRefSchema, {
189
+ artifactId: 'a',
190
+ version: 2,
191
+ contentHash: 'b'.repeat(64),
192
+ passage: { start: 0, end: 10 },
193
+ gitCommit: commit,
194
+ })).toBe(true);
195
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a' })).toBe(true);
196
+ });
197
+ it('rejects bad hash, commit and passage', () => {
198
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', contentHash: 'xyz' })).toBe(false);
199
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', gitCommit: 'abc' })).toBe(false);
200
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', passage: { start: 5, end: 5 } })).toBe(false);
201
+ });
202
+ it('bounds the list on writes', () => {
203
+ const sources = Array.from({ length: 51 }, () => ({ artifactId: 'a' }));
204
+ expect(ok(UpdateArtifactRequestSchema, { content: 'c', expectedVersion: 1, sources })).toBe(false);
205
+ });
206
+ });
207
+ describe('responses and conflict', () => {
208
+ it('parses a read with its selected revision', () => {
209
+ expect(ok(ReadArtifactResponseSchema, {
210
+ artifact,
211
+ revision: { version: 2, current: false, contentHash: 'c'.repeat(64) },
212
+ })).toBe(true);
213
+ });
214
+ it('parses history with sources', () => {
215
+ expect(ok(ArtifactHistoryResponseSchema, {
216
+ versions: [
217
+ {
218
+ id: 'v1',
219
+ version: 1,
220
+ contentHash: 'h',
221
+ authorType: 'cli',
222
+ createdAt: 'now',
223
+ sources: [{ artifactId: 'a', version: 1, basis: 'asserted' }],
224
+ },
225
+ ],
226
+ nextCursor: null,
227
+ })).toBe(true);
228
+ });
229
+ it('requires the version-conflict code and both versions', () => {
230
+ const conflict = {
231
+ error: 'Version conflict',
232
+ code: 'version-conflict',
233
+ currentVersion: 4,
234
+ expectedVersion: 3,
235
+ };
236
+ expect(ok(ArtifactVersionConflictSchema, conflict)).toBe(true);
237
+ expect(ok(ArtifactVersionConflictSchema, { ...conflict, code: 'other' })).toBe(false);
238
+ expect(ok(ArtifactVersionConflictSchema, { ...conflict, currentVersion: undefined })).toBe(false);
239
+ });
240
+ });
241
+ describe('recorded source references', () => {
242
+ it('carry the server-set basis, which requests drop', () => {
243
+ const ref = { artifactId: 'file_1', version: 2 };
244
+ expect(ok(ArtifactRecordedSourceRefSchema, { ...ref, basis: 'verified' })).toBe(true);
245
+ expect(ok(ArtifactRecordedSourceRefSchema, { ...ref, basis: 'asserted' })).toBe(true);
246
+ expect(ok(ArtifactRecordedSourceRefSchema, ref)).toBe(false);
247
+ expect(ok(ArtifactRecordedSourceRefSchema, { ...ref, basis: 'trusted' })).toBe(false);
248
+ // Requests strip `basis` rather than carry it, so a client cannot set it.
249
+ const parsed = v.parse(UpdateArtifactRequestSchema, {
250
+ content: 'x',
251
+ expectedVersion: 1,
252
+ sources: [{ ...ref, basis: 'verified' }],
253
+ });
254
+ expect(parsed.sources).toEqual([ref]);
255
+ expect(v.parse(ArtifactSourceRefSchema, { ...ref, basis: 'verified' })).toEqual(ref);
256
+ });
257
+ });
258
+ describe('passage selectors, history query and project claim', () => {
259
+ it('requires a version beside a passage', () => {
260
+ const passage = { start: 0, end: 4 };
261
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', passage })).toBe(false);
262
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', version: 1, passage })).toBe(true);
263
+ expect(ok(ArtifactRecordedSourceRefSchema, { artifactId: 'a', passage, basis: 'asserted' })).toBe(false);
264
+ });
265
+ it('takes integer strings only for limit and before', () => {
266
+ expect(v.parse(ArtifactHistoryQuerySchema, { limit: '2', before: '9' })).toEqual({
267
+ limit: 2,
268
+ before: 9,
269
+ });
270
+ for (const bad of [
271
+ { limit: '2abc' },
272
+ { limit: '0' },
273
+ { limit: '201' },
274
+ { before: 'x' },
275
+ { before: '99999999999999999999' },
276
+ ]) {
277
+ expect(ok(ArtifactHistoryQuerySchema, bad)).toBe(false);
278
+ }
279
+ });
280
+ it('bounds a source version and the history cursor to the stored integer', () => {
281
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', version: 2147483647 })).toBe(true);
282
+ expect(ok(ArtifactSourceRefSchema, { artifactId: 'a', version: 2147483648 })).toBe(false);
283
+ expect(ok(ArtifactHistoryQuerySchema, { before: '2147483647' })).toBe(true);
284
+ expect(ok(ArtifactHistoryQuerySchema, { before: '2147483648' })).toBe(false);
285
+ });
286
+ it('accepts a gitSource on update and rejects a malformed one', () => {
287
+ const base = { content: 'c', expectedVersion: 1 };
288
+ expect(ok(UpdateArtifactRequestSchema, {
289
+ ...base,
290
+ gitSource: { projectId: 'p', commitSha: 'a'.repeat(40), branch: 'main' },
291
+ })).toBe(true);
292
+ expect(ok(UpdateArtifactRequestSchema, {
293
+ ...base,
294
+ gitSource: { projectId: 'p', commitSha: 'nope' },
295
+ })).toBe(false);
296
+ });
297
+ it('accepts an optional projectId on update and archive', () => {
298
+ expect(ok(UpdateArtifactRequestSchema, {
299
+ content: 'c',
300
+ expectedVersion: 1,
301
+ projectId: 'p',
302
+ })).toBe(true);
303
+ expect(ok(DeleteArtifactRequestSchema, {})).toBe(true);
304
+ expect(ok(DeleteArtifactRequestSchema, { projectId: 'p' })).toBe(true);
305
+ expect(ok(DeleteArtifactRequestSchema, { projectId: '' })).toBe(false);
306
+ });
307
+ });
308
+ describe('UpsertArtifactDraftRequestSchema', () => {
309
+ const base = { branch: 'feat/x', content: 'c', baseVersion: 3 };
310
+ it('accepts a branch draft, with or without the commit it came from', () => {
311
+ expect(ok(UpsertArtifactDraftRequestSchema, base)).toBe(true);
312
+ expect(ok(UpsertArtifactDraftRequestSchema, { ...base, gitCommit: 'a'.repeat(40) })).toBe(true);
313
+ });
314
+ it('refuses a draft with no base version or branch, or an abbreviated commit', () => {
315
+ expect(ok(UpsertArtifactDraftRequestSchema, { branch: 'b', content: 'c' })).toBe(false);
316
+ expect(ok(UpsertArtifactDraftRequestSchema, { ...base, branch: '' })).toBe(false);
317
+ expect(ok(UpsertArtifactDraftRequestSchema, { ...base, gitCommit: 'abc1234' })).toBe(false);
318
+ });
319
+ it('does not let a caller name the source key itself', () => {
320
+ expect(ok(UpsertArtifactDraftRequestSchema, { ...base, source: 'editor' })).toBe(false);
321
+ });
322
+ });
323
+ describe('artifactKindOf', () => {
324
+ it('names a guide by its role and content by its format', () => {
325
+ expect(artifactKindOf({ role: 'guidance', format: 'markdown', hasPhotoAsset: false })).toBe('guide');
326
+ expect(artifactKindOf({ role: 'criteria', format: 'markdown', hasPhotoAsset: false })).toBe('guide');
327
+ expect(artifactKindOf({ role: 'content', format: 'markdown', hasPhotoAsset: false })).toBe('markdown');
328
+ expect(artifactKindOf({ role: 'content', format: 'html', hasPhotoAsset: false })).toBe('html');
329
+ expect(artifactKindOf({ role: 'content', format: 'code', hasPhotoAsset: false })).toBe('code');
330
+ });
331
+ it('calls binary content a photo only when it carries photo parts', () => {
332
+ expect(artifactKindOf({ role: 'content', format: 'binary', hasPhotoAsset: true })).toBe('photo');
333
+ expect(artifactKindOf({ role: 'content', format: 'binary', hasPhotoAsset: false })).toBe('file');
334
+ });
335
+ });
336
+ describe('ListArtifactsQuerySchema', () => {
337
+ const parse = (query) => v.safeParse(ListArtifactsQuerySchema, query);
338
+ it('lists the newest 100 with no filter', () => {
339
+ const parsed = parse({});
340
+ expect(parsed.success && parsed.output).toEqual({ inbox: false, limit: 100 });
341
+ });
342
+ it('reads the inbox, kinds, since and limit from query values', () => {
343
+ const parsed = parse({
344
+ inbox: 'true',
345
+ kind: 'markdown, photo',
346
+ since: '2026-10-01T00:00:00.000Z',
347
+ limit: '25',
348
+ });
349
+ expect(parsed.success && parsed.output).toEqual({
350
+ inbox: true,
351
+ kind: ['markdown', 'photo'],
352
+ since: '2026-10-01T00:00:00.000Z',
353
+ limit: 25,
354
+ });
355
+ });
356
+ it('refuses the inbox combined with a bundle, since the inbox is unfiled', () => {
357
+ expect(parse({ inbox: 'true', bundle: 'b_1' }).success).toBe(false);
358
+ expect(parse({ inbox: 'false', bundle: 'b_1' }).success).toBe(true);
359
+ });
360
+ it('refuses an unknown kind, a bad timestamp and an out-of-range limit', () => {
361
+ expect(parse({ kind: 'note' }).success).toBe(false);
362
+ expect(parse({ since: 'yesterday' }).success).toBe(false);
363
+ expect(parse({ limit: '0' }).success).toBe(false);
364
+ expect(parse({ limit: '501' }).success).toBe(false);
365
+ expect(parse({ limit: '2.5' }).success).toBe(false);
366
+ });
367
+ });
368
+ describe('ListArtifactsResponseSchema', () => {
369
+ it('carries a page of artifacts and the cursor for the next one', () => {
370
+ expect(ok(ListArtifactsResponseSchema, { artifacts: [artifact], nextCursor: 'abc' })).toBe(true);
371
+ expect(ok(ListArtifactsResponseSchema, { artifacts: [], nextCursor: null })).toBe(true);
372
+ });
373
+ });
374
+ //# sourceMappingURL=artifact.test.js.map