@mossbear/protocol 0.1.0-alpha.114 → 0.1.0-alpha.116
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/dist/bundles.d.ts +662 -0
- package/dist/bundles.d.ts.map +1 -0
- package/dist/bundles.js +454 -0
- package/dist/bundles.js.map +1 -0
- package/dist/bundles.test.d.ts +2 -0
- package/dist/bundles.test.d.ts.map +1 -0
- package/dist/bundles.test.js +61 -0
- package/dist/bundles.test.js.map +1 -0
- package/dist/comments.d.ts +1405 -0
- package/dist/comments.d.ts.map +1 -0
- package/dist/comments.js +683 -0
- package/dist/comments.js.map +1 -0
- package/dist/comments.test.d.ts +2 -0
- package/dist/comments.test.d.ts.map +1 -0
- package/dist/comments.test.js +64 -0
- package/dist/comments.test.js.map +1 -0
- package/dist/guideHistory.d.ts +643 -0
- package/dist/guideHistory.d.ts.map +1 -0
- package/dist/guideHistory.js +343 -0
- package/dist/guideHistory.js.map +1 -0
- package/dist/guideHistory.test.d.ts +2 -0
- package/dist/guideHistory.test.d.ts.map +1 -0
- package/dist/guideHistory.test.js +35 -0
- package/dist/guideHistory.test.js.map +1 -0
- package/dist/guideImport.d.ts +398 -0
- package/dist/guideImport.d.ts.map +1 -0
- package/dist/guideImport.js +350 -0
- package/dist/guideImport.js.map +1 -0
- package/dist/guideImport.test.d.ts +2 -0
- package/dist/guideImport.test.d.ts.map +1 -0
- package/dist/guideImport.test.js +62 -0
- package/dist/guideImport.test.js.map +1 -0
- package/dist/guideSnapshot.d.ts +105 -0
- package/dist/guideSnapshot.d.ts.map +1 -0
- package/dist/guideSnapshot.js +101 -0
- package/dist/guideSnapshot.js.map +1 -0
- package/dist/guideSnapshot.test.d.ts +2 -0
- package/dist/guideSnapshot.test.d.ts.map +1 -0
- package/dist/guideSnapshot.test.js +49 -0
- package/dist/guideSnapshot.test.js.map +1 -0
- package/dist/schemas.d.ts +5122 -11710
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +61 -2816
- package/dist/schemas.js.map +1 -1
- package/dist/search.d.ts +1222 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +474 -0
- package/dist/search.js.map +1 -0
- package/dist/search.test.d.ts +2 -0
- package/dist/search.test.d.ts.map +1 -0
- package/dist/search.test.js +64 -0
- package/dist/search.test.js.map +1 -0
- package/dist/sessionContracts.test.d.ts +2 -0
- package/dist/sessionContracts.test.d.ts.map +1 -0
- package/dist/sessionContracts.test.js +75 -0
- package/dist/sessionContracts.test.js.map +1 -0
- package/dist/sessionDigest.d.ts +149 -0
- package/dist/sessionDigest.d.ts.map +1 -0
- package/dist/sessionDigest.js +57 -0
- package/dist/sessionDigest.js.map +1 -0
- package/dist/sessionGrade.d.ts +184 -0
- package/dist/sessionGrade.d.ts.map +1 -0
- package/dist/sessionGrade.js +130 -0
- package/dist/sessionGrade.js.map +1 -0
- package/dist/types.d.ts +4 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/usageOnly.d.ts +5 -5
- package/dist/wirePrimitives.d.ts +173 -0
- package/dist/wirePrimitives.d.ts.map +1 -0
- package/dist/wirePrimitives.js +210 -0
- package/dist/wirePrimitives.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/** Raw guide import and unlink wire contracts. */
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
import { BoundedRawContentSchema, SkippedMemberPathSchema, GuideDiscoveryRootSchema, SafeRelativePosixPathSchema, PATH_ISSUE_MESSAGES, NonEmptyStringSchema, Sha256HexSchema, RepoIdSchema, ProjectIdSchema, WorkspaceIdSchema, } from './wirePrimitives.js';
|
|
4
|
+
export const GuideFileFormatSchema = v.picklist([
|
|
5
|
+
'agents-md',
|
|
6
|
+
'agents-dir',
|
|
7
|
+
'claude-md',
|
|
8
|
+
'claude-rules',
|
|
9
|
+
'cursorrules',
|
|
10
|
+
'cursor-rules',
|
|
11
|
+
'skill-md',
|
|
12
|
+
]);
|
|
13
|
+
/** Max member files a single skill-md payload may carry. */
|
|
14
|
+
export const MAX_SKILL_MEMBER_FILES = 64;
|
|
15
|
+
// Member paths are relative to the skill directory, and additionally may never
|
|
16
|
+
// name the skill's own SKILL.md (the payload itself).
|
|
17
|
+
export const SkillMemberPathSchema = v.pipe(SafeRelativePosixPathSchema, v.check((path) => path.toLowerCase() !== 'skill.md', PATH_ISSUE_MESSAGES.skillMd));
|
|
18
|
+
// A sibling file of a skill's SKILL.md (scripts/, references/, assets/,
|
|
19
|
+
// supporting docs), imported alongside it as a guide_file row.
|
|
20
|
+
export const RawSkillMemberFileSchema = v.object({
|
|
21
|
+
path: SkillMemberPathSchema,
|
|
22
|
+
rawContent: BoundedRawContentSchema,
|
|
23
|
+
lastModified: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
24
|
+
content_hash: Sha256HexSchema,
|
|
25
|
+
/**
|
|
26
|
+
* Whether the file is executable (`100755` in git), so delivery writes it
|
|
27
|
+
* `0o755` or `0o644`. A boolean rather than a mode because git records only
|
|
28
|
+
* those two for a blob, and a numeric mode would be a channel for bits
|
|
29
|
+
* nothing here should set. **Absent is not `false`**: a CLI that predates the
|
|
30
|
+
* field sends none, and the server then keeps whatever it already holds.
|
|
31
|
+
*/
|
|
32
|
+
executable: v.optional(v.boolean()),
|
|
33
|
+
});
|
|
34
|
+
/** Max skipped-member paths a skill-md payload may report alongside `members`. */
|
|
35
|
+
export const MAX_SKILL_SKIPPED_MEMBER_PATHS = 256;
|
|
36
|
+
export const RawGuideFilePayloadSchema = v.pipe(v.object({
|
|
37
|
+
// Relative to the discovery root the CLI walked (`payloadPath`,
|
|
38
|
+
// `packages/cli/src/guides/discover.ts`). Two things depend on it
|
|
39
|
+
// being a safe relative path, which is why it is parsed here rather than
|
|
40
|
+
// guarded downstream:
|
|
41
|
+
//
|
|
42
|
+
// - it is embedded verbatim in the guide's `origin` (`file:{format}:{path}`)
|
|
43
|
+
// and parsed back out to place the file on disk. The writer that does so
|
|
44
|
+
// is now the docs phase's projection resolver
|
|
45
|
+
// (`packages/cli/src/artifacts/guide-projection.ts`), which rejects anything
|
|
46
|
+
// absolute, traversing or uncontained — so an unsafe path stores a guide
|
|
47
|
+
// that can never round-trip. (`mossbear guides export` was the original
|
|
48
|
+
// writer and skipped such a path *silently*; it was deleted by
|
|
49
|
+
// `unified-item-sync` Slice 5.);
|
|
50
|
+
// - it is stored as `guide_files.path`, the column import reconciles on
|
|
51
|
+
// (`guide-versioned-identity-plan.md` → Decision 4), and identity must
|
|
52
|
+
// not be keyable on a value the exporter refuses to honour.
|
|
53
|
+
path: SafeRelativePosixPathSchema,
|
|
54
|
+
// Which discovery root `path` is relative to — `guide-versioned-identity-plan.md`
|
|
55
|
+
// → Decision 6. Without it, `(repoId, path)` collapses a project skill onto
|
|
56
|
+
// its `~/.claude/skills` twin: `.claude/skills` is in both of the CLI's root
|
|
57
|
+
// lists and both scans emit the same relative string, while `repoId` is
|
|
58
|
+
// envelope-level so both files carry the same one.
|
|
59
|
+
//
|
|
60
|
+
// **Optional, and its absence is not an error** — a CLI predating this field
|
|
61
|
+
// sends none, exactly as it may send no `repoId`. A payload missing either
|
|
62
|
+
// does not participate in reconciliation and keeps the content-hash insert
|
|
63
|
+
// behaviour it was created under, rather than being defaulted to `'project'`:
|
|
64
|
+
// guessing would let an old client's `--global` file adopt a project row.
|
|
65
|
+
root: v.optional(GuideDiscoveryRootSchema),
|
|
66
|
+
format: GuideFileFormatSchema,
|
|
67
|
+
rawContent: BoundedRawContentSchema,
|
|
68
|
+
lastModified: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
69
|
+
content_hash: Sha256HexSchema,
|
|
70
|
+
// Only meaningful on `skill-md` payloads. `[]` asserts the skill has no
|
|
71
|
+
// member files (stale synced rows are removed server-side); omitting the
|
|
72
|
+
// field means "no member information" and leaves member rows untouched.
|
|
73
|
+
// No CLI caller omits it today — every sender reaches this schema through
|
|
74
|
+
// a directory scan that populates it — but the distinction is load-bearing
|
|
75
|
+
// on the wire and must not collapse: reading an absent `members` as an
|
|
76
|
+
// empty skill would hard-delete a client's member rows.
|
|
77
|
+
members: v.optional(v.pipe(v.array(RawSkillMemberFileSchema), v.maxLength(MAX_SKILL_MEMBER_FILES))),
|
|
78
|
+
/**
|
|
79
|
+
* The body-item version this machine last agreed with the server about for
|
|
80
|
+
* this `(scope, root, path)` — the machine-local baseline
|
|
81
|
+
* (`guide-versioned-identity-plan.md` → slice 2b-B, D10 in
|
|
82
|
+
* `context-bundle-authoring-plan.md`).
|
|
83
|
+
*
|
|
84
|
+
* It is the *client* half of the reconcile precondition, and it exists to
|
|
85
|
+
* answer a question the server cannot: whether the bytes on this disk were
|
|
86
|
+
* edited **from** the version the server currently holds, or from an older
|
|
87
|
+
* one. The server-only guard shipped in 2b-A can see that a dashboard edit
|
|
88
|
+
* exists, never that this machine has already seen it — so a guide the
|
|
89
|
+
* dashboard edited and the user then re-synced to disk forks forever.
|
|
90
|
+
*
|
|
91
|
+
* **Optional, and its absence is not an error.** A CLI predating the
|
|
92
|
+
* baseline store, a fresh machine, or a deleted `~/.mossbear/state/` sends
|
|
93
|
+
* none, and the payload falls back to the server-only guard exactly as it
|
|
94
|
+
* behaves today. Absence therefore degrades to "decline and fork", never to
|
|
95
|
+
* an overwrite; a *stale* value degrades to a reported conflict.
|
|
96
|
+
*/
|
|
97
|
+
expectedVersion: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
|
|
98
|
+
// Only alongside `members`: member paths present on disk but not imported
|
|
99
|
+
// this run. The server must NOT treat their absence from `members` as
|
|
100
|
+
// removal — a transiently unreadable or newly-oversized file would
|
|
101
|
+
// otherwise hard-delete its previously synced row.
|
|
102
|
+
skippedMemberPaths: v.optional(v.pipe(v.array(SkippedMemberPathSchema), v.maxLength(MAX_SKILL_SKIPPED_MEMBER_PATHS))),
|
|
103
|
+
}), v.check((payload) => payload.members === undefined || payload.format === 'skill-md', 'members are only supported on skill-md payloads'), v.check((payload) => payload.skippedMemberPaths === undefined || payload.members !== undefined, 'skippedMemberPaths requires members'),
|
|
104
|
+
// Case-insensitive uniqueness: the export round-trip re-creates these files
|
|
105
|
+
// on disk, where the default macOS/Windows filesystems fold case — two
|
|
106
|
+
// members differing only by case would silently overwrite each other.
|
|
107
|
+
v.check((payload) => payload.members === undefined ||
|
|
108
|
+
new Set(payload.members.map((member) => member.path.toLowerCase())).size ===
|
|
109
|
+
payload.members.length, 'member paths must be unique (case-insensitive)'));
|
|
110
|
+
/** Max number of rules accepted in a single `POST /api/rules/import` request. */
|
|
111
|
+
export const MAX_RULES_IMPORT_BATCH = 100;
|
|
112
|
+
// Envelope-only schema: caps request shape/size before the per-item
|
|
113
|
+
// parseRawGuideFilePayload loop validates each rule in detail, which is what
|
|
114
|
+
// preserves the import route's index-aware error reporting.
|
|
115
|
+
export const RulesImportRequestSchema = v.object({
|
|
116
|
+
rules: v.pipe(v.array(v.unknown()), v.maxLength(MAX_RULES_IMPORT_BATCH)),
|
|
117
|
+
/**
|
|
118
|
+
* Which checkout these files came from — the same opaque digest the hook and
|
|
119
|
+
* the rule manifest already carry (`packages/cli/src/repo-id.ts`,
|
|
120
|
+
* `RuleManifestSchema.repoId`). Envelope-level, not per-file: every file in
|
|
121
|
+
* one import comes from one repo, and the per-file payload stays lean (the
|
|
122
|
+
* "Import endpoint payload" resolved decision).
|
|
123
|
+
*
|
|
124
|
+
* It is what lets the server reconcile an edited file back onto the guide it
|
|
125
|
+
* already created instead of inserting a second one. `origin` alone cannot:
|
|
126
|
+
* it is `file:{format}:{path}` with no repo component, so two checkouts
|
|
127
|
+
* sharing `.agents/code-style.md` would collide.
|
|
128
|
+
*
|
|
129
|
+
* **Optional, and its absence is not an error.** A CLI predating this field
|
|
130
|
+
* sends none, and the server falls back to the content-hash dedupe it always
|
|
131
|
+
* used. Never send a repo id derived anywhere but `repoIdFromRoot` — the
|
|
132
|
+
* digest is keyed by a machine-local secret precisely so the server never
|
|
133
|
+
* learns a path.
|
|
134
|
+
*
|
|
135
|
+
* Shaped by the canonical `RepoIdSchema` (shared with run logs and manifests)
|
|
136
|
+
* rather than a looser local check: a row storing anything but
|
|
137
|
+
* a real digest could never match one, so a malformed identity has to be
|
|
138
|
+
* rejected at the boundary instead of persisted as a permanent orphan.
|
|
139
|
+
*/
|
|
140
|
+
repoId: v.optional(RepoIdSchema),
|
|
141
|
+
/**
|
|
142
|
+
* The repo's **portable** identity — `project.id` from the committed
|
|
143
|
+
* `<repo>/.mossbear/config.json` (`guide-write-side-identity` slice 1, shipped in
|
|
144
|
+
* #540). This is what makes `(scope, path)` reconciliation portable, and it is
|
|
145
|
+
* the field `unified-item-sync` slice 2 exists to put on the wire.
|
|
146
|
+
*
|
|
147
|
+
* **Why `repoId` is not enough, even though it is already here.**
|
|
148
|
+
* `repoIdFromRoot` is an HMAC keyed by a machine-local secret
|
|
149
|
+
* (`packages/cli/src/repo-id.ts`), so the same checkout on two machines — or
|
|
150
|
+
* one teammate's clone versus another's — produces two different digests. A
|
|
151
|
+
* guide reconciled on it therefore forks the moment anyone else edits the
|
|
152
|
+
* file, which is the one-way trip this item is closing. `projectId` is
|
|
153
|
+
* declared in a committed file, so every clone agrees on it.
|
|
154
|
+
*
|
|
155
|
+
* **Optional, and its absence is not an error.** A CLI predating this field
|
|
156
|
+
* sends none and the server falls back to `repoId` scoping, which is exactly
|
|
157
|
+
* the behaviour those clients already have. A repo that has never run
|
|
158
|
+
* `mossbear init` also has no declaration, and must keep importing.
|
|
159
|
+
*
|
|
160
|
+
* Deliberately looser than `RepoIdSchema`: a generated id is
|
|
161
|
+
* `proj_`+hex, but a *declared* one is whatever a human committed —
|
|
162
|
+
* `readRepoProjectId` accepts any non-empty trimmed string
|
|
163
|
+
* (`packages/cli/src/artifacts/repo-config.ts`), and rejecting those here would
|
|
164
|
+
* break a shipped contract. Constrained only as far as it must be to serve as
|
|
165
|
+
* a storage key: no whitespace, no path separators, no control characters,
|
|
166
|
+
* bounded length.
|
|
167
|
+
*/
|
|
168
|
+
projectId: v.optional(ProjectIdSchema),
|
|
169
|
+
/**
|
|
170
|
+
* The workspace this repo declares its project-scoped guidance belongs to —
|
|
171
|
+
* `workspace.id` from the committed `<repo>/.mossbear/config.json`
|
|
172
|
+
* (`workspace-declaration` slice 1).
|
|
173
|
+
*
|
|
174
|
+
* **What it changes: which of the caller's workspaces a project path resolves
|
|
175
|
+
* in.** Import identity is already scoped by workspace *membership* rather
|
|
176
|
+
* than authorship, so a caller in several workspaces has several candidate
|
|
177
|
+
* rows at one `(project, root, path)` and the resolver picked between them by
|
|
178
|
+
* row age. The declaration is the narrower lookup that removes the guess, and
|
|
179
|
+
* it is committed so every clone of the repo narrows the same way.
|
|
180
|
+
*
|
|
181
|
+
* **Membership stays the boundary; this only narrows inside it.** The
|
|
182
|
+
* declaration cannot widen what a caller may reach: a workspace they are not a
|
|
183
|
+
* member of is refused by name rather than resolved, and never quietly
|
|
184
|
+
* replaced by their personal one — falling back would recreate the fork the
|
|
185
|
+
* declaration exists to close.
|
|
186
|
+
*
|
|
187
|
+
* **Envelope-level, and never sent on a global batch.** It is the *repo's*
|
|
188
|
+
* declaration, so it travels with the same batch that carries `repoId` and
|
|
189
|
+
* `projectId`; a `root: 'global'` file belongs to no checkout and to no
|
|
190
|
+
* project, and by the same rule to no repo-declared workspace.
|
|
191
|
+
*
|
|
192
|
+
* **Optional, and its absence is not an error.** A CLI predating this field
|
|
193
|
+
* sends none, and a repo that has never declared one has none to send; both
|
|
194
|
+
* keep the resolution they have today.
|
|
195
|
+
*/
|
|
196
|
+
workspaceId: v.optional(WorkspaceIdSchema),
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* What the server did with one payload, reported per file so the CLI can update
|
|
200
|
+
* its machine-local baseline (`guide-versioned-identity-plan.md` → slice 2b-B).
|
|
201
|
+
*
|
|
202
|
+
* The distinction that matters is not "did something change" but **do disk and
|
|
203
|
+
* server now agree**: `imported`, `updated` and `skipped` all mean they do, and
|
|
204
|
+
* only those license recording a new baseline. `conflict` means the disk bytes
|
|
205
|
+
* did *not* land — recording the server's version for one would hand the next
|
|
206
|
+
* import a matching `expectedVersion` and turn a refused overwrite into an
|
|
207
|
+
* automatic one on the following run, which is the failure this whole precondition
|
|
208
|
+
* exists to prevent.
|
|
209
|
+
*/
|
|
210
|
+
export const GuideImportOutcomeSchema = v.picklist([
|
|
211
|
+
'imported',
|
|
212
|
+
'updated',
|
|
213
|
+
'skipped',
|
|
214
|
+
'conflict',
|
|
215
|
+
]);
|
|
216
|
+
/**
|
|
217
|
+
* Per-payload import outcome, addressed by the same `(root, path)` pair the
|
|
218
|
+
* server reconciles on so the CLI can key its baseline identically without
|
|
219
|
+
* re-deriving anything.
|
|
220
|
+
*
|
|
221
|
+
* `version` is the body item's version **as the server holds it after this
|
|
222
|
+
* request** — the value a later import should send as `expectedVersion` once
|
|
223
|
+
* disk and server agree. It is reported for a `conflict` too, deliberately: the
|
|
224
|
+
* conflict report needs it to offer explicit resolution, and reporting it is not
|
|
225
|
+
* the same as recording it.
|
|
226
|
+
*
|
|
227
|
+
* Entries are omitted for a payload the server could not address at all (no
|
|
228
|
+
* `root`, or a pre-R0 row): there is no identity to key a baseline on, and
|
|
229
|
+
* inventing one would let a later import claim a precondition it never observed.
|
|
230
|
+
*/
|
|
231
|
+
export const GuideImportResultSchema = v.object({
|
|
232
|
+
/** Canonical guide identity for review links; absent on older servers. */
|
|
233
|
+
guideId: v.optional(NonEmptyStringSchema),
|
|
234
|
+
root: GuideDiscoveryRootSchema,
|
|
235
|
+
path: SafeRelativePosixPathSchema,
|
|
236
|
+
outcome: GuideImportOutcomeSchema,
|
|
237
|
+
version: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
238
|
+
});
|
|
239
|
+
/** Max alias sets one import response reports as divergent. */
|
|
240
|
+
export const MAX_GUIDE_IMPORT_DIVERGENCES = 64;
|
|
241
|
+
/**
|
|
242
|
+
* An alias set the server found in one import but **did not** collapse, because
|
|
243
|
+
* the files do not hold the same rules
|
|
244
|
+
* (`alias-instruction-file-identity-plan.md` → second addendum,
|
|
245
|
+
* 2026-09-03).
|
|
246
|
+
*
|
|
247
|
+
* Reporting rather than refusing is the whole point. An identical
|
|
248
|
+
* `AGENTS.md`/`.cursorrules` pair becomes one guide; a divergent one imports as
|
|
249
|
+
* two guides exactly as it does today, and this names the paths so the user can
|
|
250
|
+
* see the drift the product would otherwise have kept silent. Nothing about the
|
|
251
|
+
* import fails, and nothing the user does today stops working.
|
|
252
|
+
*
|
|
253
|
+
* `paths` carries every path in the set this request saw, in the order the
|
|
254
|
+
* server ranks them — so the first is the one that would have kept the body had
|
|
255
|
+
* they matched.
|
|
256
|
+
*/
|
|
257
|
+
export const GuideImportDivergenceSchema = v.object({
|
|
258
|
+
root: GuideDiscoveryRootSchema,
|
|
259
|
+
paths: v.pipe(v.array(SafeRelativePosixPathSchema), v.minLength(2)),
|
|
260
|
+
});
|
|
261
|
+
/**
|
|
262
|
+
* An alias pair one import left as **two guides**, because a guide was already
|
|
263
|
+
* stored at the incoming file's alias partner path and the pair could not be
|
|
264
|
+
* collapsed onto it (`skill-alias-collapse-managed-file-plan.md` →
|
|
265
|
+
* *Reporting*).
|
|
266
|
+
*
|
|
267
|
+
* Distinct from {@link GuideImportDivergenceSchema}, which says the files
|
|
268
|
+
* differ. This one says only that the fork happened — the reasons are several
|
|
269
|
+
* (the bodies differ, the skill directories around them could not be proven to
|
|
270
|
+
* match, the partner path already answers to a second guide) and the import
|
|
271
|
+
* cannot always tell them apart, so it names the pair and leaves the reading to
|
|
272
|
+
* whoever wrote the files. Reported only when a guide was *created* at the
|
|
273
|
+
* incoming path, so a repo re-importing a pair that forked long ago stays
|
|
274
|
+
* quiet.
|
|
275
|
+
*
|
|
276
|
+
* `paths` is the incoming file first, then the partner already stored.
|
|
277
|
+
*/
|
|
278
|
+
export const GuideImportAliasForkSchema = v.object({
|
|
279
|
+
root: GuideDiscoveryRootSchema,
|
|
280
|
+
paths: v.pipe(v.array(SafeRelativePosixPathSchema), v.minLength(2)),
|
|
281
|
+
});
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// `mossbear unlink` — un-enrol a guide from the default bundle
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
/**
|
|
286
|
+
* One guide to stop delivering, addressed the way the **import** route already
|
|
287
|
+
* resolves an existing guide: `(root, path)` plus the envelope's checkout and
|
|
288
|
+
* project identity.
|
|
289
|
+
*
|
|
290
|
+
* **Deliberately not `origin`.** `file:{format}:{path}` is not unique — every
|
|
291
|
+
* repo has an `AGENTS.md`, so an origin-keyed request disables the matching
|
|
292
|
+
* guide in every repo in the workspace. That is the defect that sank the first
|
|
293
|
+
* implementation of this verb. `(root, path)` scoped by `repoId`/`projectId`
|
|
294
|
+
* is the key the import route reconciles on, so unlink addresses exactly the
|
|
295
|
+
* row link created and no other.
|
|
296
|
+
*/
|
|
297
|
+
export const RawGuideUnlinkSchema = v.object({
|
|
298
|
+
root: GuideDiscoveryRootSchema,
|
|
299
|
+
/**
|
|
300
|
+
* The canonical guide-path validator, not a fresh `v.string()`: it already
|
|
301
|
+
* rejects absolute paths, control characters and `..` traversal, and a second
|
|
302
|
+
* hand-rolled constraint here would be a place for the two to disagree.
|
|
303
|
+
*/
|
|
304
|
+
path: SafeRelativePosixPathSchema,
|
|
305
|
+
});
|
|
306
|
+
/** Max guides accepted in a single `POST /api/rules/unlink` request. */
|
|
307
|
+
export const MAX_RULE_UNLINK_BATCH = 500;
|
|
308
|
+
export const RuleUnlinkRequestSchema = v.object({
|
|
309
|
+
unlinks: v.pipe(v.array(RawGuideUnlinkSchema), v.maxLength(MAX_RULE_UNLINK_BATCH)),
|
|
310
|
+
/** Same envelope identity the import route carries, and for the same reason. */
|
|
311
|
+
repoId: v.optional(v.string()),
|
|
312
|
+
projectId: v.optional(v.string()),
|
|
313
|
+
});
|
|
314
|
+
/**
|
|
315
|
+
* `unlinked` counts guides removed from the default bundle; `skipped` counts
|
|
316
|
+
* requested paths that resolved to nothing, or were already out of it.
|
|
317
|
+
*
|
|
318
|
+
* `stillDelivered` names guides that remain in *other* bundles the caller can
|
|
319
|
+
* reach — including a teammate's, since a bundle shared into a workspace they
|
|
320
|
+
* belong to keeps arriving whoever owns it. Unlink is the exact inverse of what
|
|
321
|
+
* link does — it removes the default-bundle membership link created — so a
|
|
322
|
+
* guide someone deliberately added to a curated bundle stays there, and saying
|
|
323
|
+
* so is the difference between a true report and a reassuring one.
|
|
324
|
+
*
|
|
325
|
+
* `released` names the requested paths whose guide is now in **no** bundle the
|
|
326
|
+
* caller can reach, so nothing delivers it any more. It exists because the
|
|
327
|
+
* caller holds a fact the server does not: the local placement record that
|
|
328
|
+
* marks a path as managed by a bundle. A path taken out of every bundle and
|
|
329
|
+
* still recorded as bundle-managed is two answers to one question, and only the
|
|
330
|
+
* server can tell which paths genuinely stopped being delivered. Note this is
|
|
331
|
+
* not on its own enough to make a re-link restore delivery — the import route
|
|
332
|
+
* enrols only the guide rows its insert creates — so a caller acting on this
|
|
333
|
+
* should not report the path as re-adoptable.
|
|
334
|
+
*
|
|
335
|
+
* Optional with an empty default, so a client on this version still parses a
|
|
336
|
+
* response from a deployment that predates the field.
|
|
337
|
+
*/
|
|
338
|
+
export const RuleUnlinkResponseSchema = v.object({
|
|
339
|
+
unlinked: v.number(),
|
|
340
|
+
skipped: v.number(),
|
|
341
|
+
stillDelivered: v.array(v.string()),
|
|
342
|
+
released: v.optional(v.array(RawGuideUnlinkSchema), []),
|
|
343
|
+
});
|
|
344
|
+
export function parseRuleUnlinkRequest(data) {
|
|
345
|
+
return v.parse(RuleUnlinkRequestSchema, data);
|
|
346
|
+
}
|
|
347
|
+
export function parseRawGuideFilePayload(data) {
|
|
348
|
+
return v.parse(RawGuideFilePayloadSchema, data);
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=guideImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guideImport.js","sourceRoot":"","sources":["../src/guideImport.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EAAE,CAAC;CACxD,CAAC,CAAA;AAIF,MAAM,UAAU,sBAAsB,CAAC,IAAa;IAClD,OAAO,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAA;AAC/C,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,IAAa;IACpD,OAAO,CAAC,CAAC,KAAK,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guideImport.test.d.ts","sourceRoot":"","sources":["../src/guideImport.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
3
|
+
import * as imports from './guideImport.js';
|
|
4
|
+
import * as protocol from './index.js';
|
|
5
|
+
import * as schemas from './schemas.js';
|
|
6
|
+
import * as primitives from './wirePrimitives.js';
|
|
7
|
+
describe('guide import/unlink extraction', () => {
|
|
8
|
+
it('preserves aggregate exports and shared primitive identity', () => {
|
|
9
|
+
for (const [name, value] of Object.entries(imports)) {
|
|
10
|
+
expect(Reflect.get(schemas, name), name).toBe(value);
|
|
11
|
+
expect(Reflect.get(protocol, name), name).toBe(value);
|
|
12
|
+
}
|
|
13
|
+
expect(imports.RawGuideFilePayloadSchema.pipe[0].entries.path).toBe(primitives.SafeRelativePosixPathSchema);
|
|
14
|
+
expect(imports.RulesImportRequestSchema.entries.repoId.wrapped).toBe(primitives.RepoIdSchema);
|
|
15
|
+
expect(imports.RulesImportRequestSchema.entries.workspaceId.wrapped).toBe(primitives.WorkspaceIdSchema);
|
|
16
|
+
expect(schemas.GuideSnapshotSchema.entries.contentHash.wrapped.wrapped).toBe(primitives.Sha256HexSchema);
|
|
17
|
+
});
|
|
18
|
+
it('keeps consumer types and parser inference', () => {
|
|
19
|
+
expectTypeOf().toEqualTypeOf();
|
|
20
|
+
expectTypeOf().toEqualTypeOf();
|
|
21
|
+
expectTypeOf().toEqualTypeOf();
|
|
22
|
+
expectTypeOf().toEqualTypeOf();
|
|
23
|
+
expectTypeOf(imports.parseRawGuideFilePayload).returns.toEqualTypeOf();
|
|
24
|
+
expectTypeOf(imports.parseRuleUnlinkRequest).returns.toEqualTypeOf();
|
|
25
|
+
expectTypeOf().toEqualTypeOf();
|
|
26
|
+
});
|
|
27
|
+
it('leaves envelope validation separate from per-file validation', () => {
|
|
28
|
+
const invalid = { path: '../AGENTS.md' };
|
|
29
|
+
expect(v.parse(imports.RulesImportRequestSchema, { rules: [invalid] })).toEqual({
|
|
30
|
+
rules: [invalid],
|
|
31
|
+
});
|
|
32
|
+
expect(() => imports.parseRawGuideFilePayload(invalid)).toThrow(v.ValiError);
|
|
33
|
+
expect(v.safeParse(imports.RulesImportRequestSchema, { rules: [], repoId: 'bad' }).success).toBe(false);
|
|
34
|
+
// Unlink intentionally retains its older, looser envelope identity contract.
|
|
35
|
+
expect(imports.parseRuleUnlinkRequest({ unlinks: [], repoId: 'bad' })).toEqual({
|
|
36
|
+
unlinks: [],
|
|
37
|
+
repoId: 'bad',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it('retains unlink defaults and absent member information', () => {
|
|
41
|
+
expect(v.parse(imports.RuleUnlinkResponseSchema, {
|
|
42
|
+
unlinked: 0,
|
|
43
|
+
skipped: 1,
|
|
44
|
+
stillDelivered: [],
|
|
45
|
+
}).released).toEqual([]);
|
|
46
|
+
const payload = {
|
|
47
|
+
path: 'AGENTS.md',
|
|
48
|
+
format: 'agents-md',
|
|
49
|
+
rawContent: '',
|
|
50
|
+
lastModified: 0,
|
|
51
|
+
content_hash: 'A'.repeat(64),
|
|
52
|
+
};
|
|
53
|
+
expect(imports.parseRawGuideFilePayload(payload)).toEqual(payload);
|
|
54
|
+
expect(v.safeParse(imports.RawGuideFilePayloadSchema, { ...payload, members: [] })
|
|
55
|
+
.issues?.[0]?.message).toBe('members are only supported on skill-md payloads');
|
|
56
|
+
expect(v.safeParse(imports.RawGuideFilePayloadSchema, {
|
|
57
|
+
...payload,
|
|
58
|
+
skippedMemberPaths: ['file'],
|
|
59
|
+
}).issues?.[0]?.message).toBe('skippedMemberPaths requires members');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=guideImport.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guideImport.test.js","sourceRoot":"","sources":["../src/guideImport.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE3D,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AAIjD,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACpD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACpD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACvD,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CACjE,UAAU,CAAC,2BAA2B,CACvC,CAAA;QACD,MAAM,CAAC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M,CACJ,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,yBAAyB,EAAE;YAC7C,GAAG,OAAO;YACV,kBAAkB,EAAE,CAAC,MAAM,CAAC;SAC7B,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CACxB,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** Guide snapshot reads and observed rule-file delivery manifests. */
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
export declare const GuideSnapshotSchema: v.ObjectSchema<{
|
|
4
|
+
readonly id: v.StringSchema<undefined>;
|
|
5
|
+
readonly title: v.StringSchema<undefined>;
|
|
6
|
+
readonly content: v.StringSchema<undefined>;
|
|
7
|
+
readonly enabled: v.BooleanSchema<undefined>;
|
|
8
|
+
readonly updatedAt: v.StringSchema<undefined>;
|
|
9
|
+
readonly origin: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
10
|
+
readonly contentHash: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, undefined>;
|
|
11
|
+
readonly root: v.OptionalSchema<v.NullableSchema<v.PicklistSchema<["project", "global"], undefined>, undefined>, undefined>;
|
|
12
|
+
readonly path: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "path must use forward slashes">, v.CheckAction<string, "path must be relative">, v.CheckAction<string, "path must not contain control characters">, v.CheckAction<string, "path must not contain empty, \".\" or \"..\" segments">]>, undefined>, undefined>;
|
|
13
|
+
}, undefined>;
|
|
14
|
+
export declare const GuideBundleResponseSchema: v.ObjectSchema<{
|
|
15
|
+
readonly guides: v.ArraySchema<v.ObjectSchema<{
|
|
16
|
+
readonly id: v.StringSchema<undefined>;
|
|
17
|
+
readonly title: v.StringSchema<undefined>;
|
|
18
|
+
readonly content: v.StringSchema<undefined>;
|
|
19
|
+
readonly enabled: v.BooleanSchema<undefined>;
|
|
20
|
+
readonly updatedAt: v.StringSchema<undefined>;
|
|
21
|
+
readonly origin: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
22
|
+
readonly contentHash: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, undefined>;
|
|
23
|
+
readonly root: v.OptionalSchema<v.NullableSchema<v.PicklistSchema<["project", "global"], undefined>, undefined>, undefined>;
|
|
24
|
+
readonly path: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 512, undefined>, v.CheckAction<string, "path must use forward slashes">, v.CheckAction<string, "path must be relative">, v.CheckAction<string, "path must not contain control characters">, v.CheckAction<string, "path must not contain empty, \".\" or \"..\" segments">]>, undefined>, undefined>;
|
|
25
|
+
}, undefined>, undefined>;
|
|
26
|
+
readonly pulledAt: v.StringSchema<undefined>;
|
|
27
|
+
}, undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Max rule files one delivery manifest enumerates. Well above what a real repo
|
|
30
|
+
* carries (this one: ~20), and bounded because the manifest rides every
|
|
31
|
+
* action-carrying batch: an unbounded list would multiply across a chunked
|
|
32
|
+
* sync. Overflow sets `truncated` rather than being dropped silently.
|
|
33
|
+
*/
|
|
34
|
+
export declare const MAX_RULE_MANIFEST_FILES = 500;
|
|
35
|
+
/**
|
|
36
|
+
* A rule file observed on disk in the repo `mossbear report` ran from.
|
|
37
|
+
*
|
|
38
|
+
* `path` is relative to that repo root, in exactly the form `payloadPath`
|
|
39
|
+
* takes at import time (`packages/cli/src/guides/discover.ts`), so
|
|
40
|
+
* `file:{format}:{path}` reconstructs the `origin` the dashboard stored for
|
|
41
|
+
* the guide this file produced. That reconstruction is the whole join; nothing
|
|
42
|
+
* else about the file is needed and nothing else is sent.
|
|
43
|
+
*
|
|
44
|
+
* **Never any content.** `contentHash` is the same sha256 the import payload
|
|
45
|
+
* carries, present so a later slice can tell "delivered" from "delivered but
|
|
46
|
+
* edited since import" without shipping the bytes again.
|
|
47
|
+
*/
|
|
48
|
+
export declare const RuleManifestFileSchema: v.ObjectSchema<{
|
|
49
|
+
readonly path: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 512, undefined>]>;
|
|
50
|
+
readonly format: v.PicklistSchema<["agents-md", "agents-dir", "claude-md", "claude-rules", "cursorrules", "cursor-rules", "skill-md"], undefined>;
|
|
51
|
+
readonly contentHash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
52
|
+
}, undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Which rule files were actually on disk in the repo this sync ran from —
|
|
55
|
+
* observed delivery, replacing the assumption that every non-skill active
|
|
56
|
+
* guide reached the agent. Without it, an account with several repos, or a
|
|
57
|
+
* dashboard-authored guide never exported anywhere, is graded against
|
|
58
|
+
* instructions the agent never received.
|
|
59
|
+
*
|
|
60
|
+
* `repoId` is an opaque, machine-local digest — deliberately not a path, a
|
|
61
|
+
* remote URL, or a repo name. Its only job is to keep two checkouts on the
|
|
62
|
+
* same account distinguishable, which is the half of review finding 5 that
|
|
63
|
+
* repo-root-relative origins cannot express: two repos each holding
|
|
64
|
+
* `.claude/skills/review` produce byte-identical origins by construction. See
|
|
65
|
+
* `repoIdFromRoot` (`packages/cli/src/guides/manifest.ts`) for how it is
|
|
66
|
+
* derived and why that derivation is privacy-safe.
|
|
67
|
+
*/
|
|
68
|
+
export declare const RuleFileManifestSchema: v.ObjectSchema<{
|
|
69
|
+
readonly repoId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "repoId must be repo_ followed by 32 hex chars">]>;
|
|
70
|
+
readonly files: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
71
|
+
readonly path: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 512, undefined>]>;
|
|
72
|
+
readonly format: v.PicklistSchema<["agents-md", "agents-dir", "claude-md", "claude-rules", "cursorrules", "cursor-rules", "skill-md"], undefined>;
|
|
73
|
+
readonly contentHash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
74
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
75
|
+
path: string;
|
|
76
|
+
format: "agents-md" | "agents-dir" | "claude-md" | "claude-rules" | "cursorrules" | "cursor-rules" | "skill-md";
|
|
77
|
+
contentHash: string;
|
|
78
|
+
}[], 500, undefined>]>;
|
|
79
|
+
/**
|
|
80
|
+
* The repo held more rule files than the cap, so `files` is a prefix. Set
|
|
81
|
+
* rather than silently trimmed: a manifest read as complete would mark the
|
|
82
|
+
* omitted files' guides undelivered, which is the exact wrong-verdict
|
|
83
|
+
* failure this field exists to prevent.
|
|
84
|
+
*/
|
|
85
|
+
readonly truncated: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
86
|
+
}, undefined>;
|
|
87
|
+
export type GuideSnapshot = v.InferOutput<typeof GuideSnapshotSchema>;
|
|
88
|
+
export type GuideBundleResponse = v.InferOutput<typeof GuideBundleResponseSchema>;
|
|
89
|
+
export type RuleManifestFile = v.InferOutput<typeof RuleManifestFileSchema>;
|
|
90
|
+
export type RuleFileManifest = v.InferOutput<typeof RuleFileManifestSchema>;
|
|
91
|
+
export declare function parseGuideBundleResponse(data: unknown): {
|
|
92
|
+
guides: {
|
|
93
|
+
id: string;
|
|
94
|
+
title: string;
|
|
95
|
+
content: string;
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
updatedAt: string;
|
|
98
|
+
origin?: string | null | undefined;
|
|
99
|
+
contentHash?: string | null | undefined;
|
|
100
|
+
root?: "project" | "global" | null | undefined;
|
|
101
|
+
path?: string | null | undefined;
|
|
102
|
+
}[];
|
|
103
|
+
pulledAt: string;
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=guideSnapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guideSnapshot.d.ts","sourceRoot":"","sources":["../src/guideSnapshot.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAc5B,eAAO,MAAM,mBAAmB;;;;;;;;;;aAkC9B,CAAA;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;aAGpC,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,MAAM,CAAA;AAE1C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB;;;;aAIjC,CAAA;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;IAGjC;;;;;OAKG;;aAEH,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAA;AACrE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,yBAAyB,CAAC,CAAA;AACjF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE3E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO;;;;;;;;;;;;;EAErD"}
|