@mossbear/projections 0.1.0-alpha.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/bundle-mirror-path.d.ts +32 -0
- package/dist/bundle-mirror-path.d.ts.map +1 -0
- package/dist/bundle-mirror-path.js +52 -0
- package/dist/bundle-mirror-path.js.map +1 -0
- package/dist/bundle-mirror-path.test.d.ts +2 -0
- package/dist/bundle-mirror-path.test.d.ts.map +1 -0
- package/dist/bundle-mirror-path.test.js +46 -0
- package/dist/bundle-mirror-path.test.js.map +1 -0
- package/dist/detect-format.d.ts +15 -0
- package/dist/detect-format.d.ts.map +1 -0
- package/dist/detect-format.js +88 -0
- package/dist/detect-format.js.map +1 -0
- package/dist/detect-format.test.d.ts +2 -0
- package/dist/detect-format.test.d.ts.map +1 -0
- package/dist/detect-format.test.js +104 -0
- package/dist/detect-format.test.js.map +1 -0
- package/dist/eval-path.d.ts +89 -0
- package/dist/eval-path.d.ts.map +1 -0
- package/dist/eval-path.js +108 -0
- package/dist/eval-path.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/path-rules.d.ts +46 -0
- package/dist/path-rules.d.ts.map +1 -0
- package/dist/path-rules.js +66 -0
- package/dist/path-rules.js.map +1 -0
- package/dist/skill-member-path.d.ts +50 -0
- package/dist/skill-member-path.d.ts.map +1 -0
- package/dist/skill-member-path.js +75 -0
- package/dist/skill-member-path.js.map +1 -0
- package/dist/skill-member-path.test.d.ts +2 -0
- package/dist/skill-member-path.test.d.ts.map +1 -0
- package/dist/skill-member-path.test.js +0 -0
- package/dist/skill-member-path.test.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mossbear
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @mossbear/projections
|
|
2
|
+
|
|
3
|
+
Guide-file format detection for [Mossbear](https://app.mossbear.io) — `detectFormat()` for `AGENTS.md`, `.agents/`, `CLAUDE.md`, `.claude/rules/`, `.cursorrules`, and `.cursor/rules/*.mdc`. Used by the [`mossbear` CLI](https://www.npmjs.com/package/mossbear).
|
|
4
|
+
|
|
5
|
+
You normally don't install this directly; it ships as a dependency of `mossbear`.
|
|
6
|
+
|
|
7
|
+
Source: https://github.com/mossbear-io/mossbear (`packages/projections`)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a document's declared path lands in a repo that is **not** its home:
|
|
3
|
+
* mirrored under the bundle's own folder, `<bundleDir>/<declared path>`.
|
|
4
|
+
*
|
|
5
|
+
* A declared path is placement — where the document sits in its home repo's
|
|
6
|
+
* layout. Honoured literally everywhere, a bundle carrying `README.md` drops that
|
|
7
|
+
* README at the root of every subscribed repo lacking one, with nothing saying
|
|
8
|
+
* the file is foreign. Mirroring keeps the layout and moves the whole delivery
|
|
9
|
+
* inside a directory Mossbear owns outright, which is also what makes a
|
|
10
|
+
* recursive orphan sweep there sound.
|
|
11
|
+
*
|
|
12
|
+
* The same shape as `evalShadowPath` — a prefix plus the scope-relative path —
|
|
13
|
+
* because it is the same idea: a shadow tree that mirrors a path without landing
|
|
14
|
+
* on it. It has no inverse yet because nothing reads a mirrored path back into a
|
|
15
|
+
* declared one; add it beside its first caller.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* True when a declared path is already inside `.mossbear/` — Mossbear's own
|
|
19
|
+
* tree, which a document may land in literally anywhere, and which
|
|
20
|
+
* `bundleMirrorPath` therefore refuses to mirror. Exported so the caller choosing
|
|
21
|
+
* between the two asks the same question this module does.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isMossbearTreePath(path: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The mirrored path for a document declaring `declaredPath`, relative to the
|
|
26
|
+
* same root `bundleDir` is (the repo). `null` when the declared path could not
|
|
27
|
+
* have been declared in the first place (absolute, escaping, control
|
|
28
|
+
* characters, over-long, or already inside `.mossbear/`), when `bundleDir` is
|
|
29
|
+
* not a safe relative path, or when the two together pass the 512-char bound.
|
|
30
|
+
*/
|
|
31
|
+
export declare function bundleMirrorPath(bundleDir: string, declaredPath: string): string | null;
|
|
32
|
+
//# sourceMappingURL=bundle-mirror-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-mirror-path.d.ts","sourceRoot":"","sources":["../src/bundle-mirror-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYvF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a document's declared path lands in a repo that is **not** its home:
|
|
3
|
+
* mirrored under the bundle's own folder, `<bundleDir>/<declared path>`.
|
|
4
|
+
*
|
|
5
|
+
* A declared path is placement — where the document sits in its home repo's
|
|
6
|
+
* layout. Honoured literally everywhere, a bundle carrying `README.md` drops that
|
|
7
|
+
* README at the root of every subscribed repo lacking one, with nothing saying
|
|
8
|
+
* the file is foreign. Mirroring keeps the layout and moves the whole delivery
|
|
9
|
+
* inside a directory Mossbear owns outright, which is also what makes a
|
|
10
|
+
* recursive orphan sweep there sound.
|
|
11
|
+
*
|
|
12
|
+
* The same shape as `evalShadowPath` — a prefix plus the scope-relative path —
|
|
13
|
+
* because it is the same idea: a shadow tree that mirrors a path without landing
|
|
14
|
+
* on it. It has no inverse yet because nothing reads a mirrored path back into a
|
|
15
|
+
* declared one; add it beside its first caller.
|
|
16
|
+
*/
|
|
17
|
+
import { isSafeRelativePath, isUnderMossbearDir, toPosix } from './path-rules.js';
|
|
18
|
+
/**
|
|
19
|
+
* True when a declared path is already inside `.mossbear/` — Mossbear's own
|
|
20
|
+
* tree, which a document may land in literally anywhere, and which
|
|
21
|
+
* `bundleMirrorPath` therefore refuses to mirror. Exported so the caller choosing
|
|
22
|
+
* between the two asks the same question this module does.
|
|
23
|
+
*/
|
|
24
|
+
export function isMossbearTreePath(path) {
|
|
25
|
+
return isUnderMossbearDir(toPosix(path));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The mirrored path for a document declaring `declaredPath`, relative to the
|
|
29
|
+
* same root `bundleDir` is (the repo). `null` when the declared path could not
|
|
30
|
+
* have been declared in the first place (absolute, escaping, control
|
|
31
|
+
* characters, over-long, or already inside `.mossbear/`), when `bundleDir` is
|
|
32
|
+
* not a safe relative path, or when the two together pass the 512-char bound.
|
|
33
|
+
*/
|
|
34
|
+
export function bundleMirrorPath(bundleDir, declaredPath) {
|
|
35
|
+
const dir = trimTrailingSlashes(toPosix(bundleDir));
|
|
36
|
+
const normalized = toPosix(declaredPath);
|
|
37
|
+
if (!isSafeRelativePath(dir))
|
|
38
|
+
return null;
|
|
39
|
+
if (!isSafeRelativePath(normalized))
|
|
40
|
+
return null;
|
|
41
|
+
// A document declaring a place inside Mossbear's own state has no layout of
|
|
42
|
+
// its own to mirror, and mirroring it would nest one bundle's folder inside
|
|
43
|
+
// another's.
|
|
44
|
+
if (isUnderMossbearDir(normalized))
|
|
45
|
+
return null;
|
|
46
|
+
const mirrored = `${dir}/${normalized}`;
|
|
47
|
+
return isSafeRelativePath(mirrored) ? mirrored : null;
|
|
48
|
+
}
|
|
49
|
+
function trimTrailingSlashes(path) {
|
|
50
|
+
return path.replace(/\/+$/, '');
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=bundle-mirror-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-mirror-path.js","sourceRoot":"","sources":["../src/bundle-mirror-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEjF;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,YAAoB;IACtE,MAAM,GAAG,GAAG,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IACnD,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACxC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IACzC,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAA;IAChD,4EAA4E;IAC5E,4EAA4E;IAC5E,aAAa;IACb,IAAI,kBAAkB,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAA;IAE/C,MAAM,QAAQ,GAAG,GAAG,GAAG,IAAI,UAAU,EAAE,CAAA;IACvC,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;AACvD,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-mirror-path.test.d.ts","sourceRoot":"","sources":["../src/bundle-mirror-path.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { bundleMirrorPath, isMossbearTreePath } from './bundle-mirror-path.js';
|
|
3
|
+
const DIR = '.mossbear/context/team-docs';
|
|
4
|
+
describe('bundleMirrorPath', () => {
|
|
5
|
+
it('keeps a foreign document inside the bundle folder, layout intact', () => {
|
|
6
|
+
expect(bundleMirrorPath(DIR, 'README.md')).toBe(`${DIR}/README.md`);
|
|
7
|
+
expect(bundleMirrorPath(DIR, 'docs/architecture.md')).toBe(`${DIR}/docs/architecture.md`);
|
|
8
|
+
expect(bundleMirrorPath(`${DIR}/`, 'docs/a.md')).toBe(`${DIR}/docs/a.md`);
|
|
9
|
+
expect(bundleMirrorPath('.mossbear\\context\\team-docs', 'docs\\a.md')).toBe(`${DIR}/docs/a.md`);
|
|
10
|
+
});
|
|
11
|
+
it('refuses a declared path no repo could hold', () => {
|
|
12
|
+
for (const bad of [
|
|
13
|
+
'',
|
|
14
|
+
'/etc/passwd',
|
|
15
|
+
'C:/x.md',
|
|
16
|
+
'../escape.md',
|
|
17
|
+
'a/../b.md',
|
|
18
|
+
'a//b.md',
|
|
19
|
+
'a\u0000.md',
|
|
20
|
+
]) {
|
|
21
|
+
expect(bundleMirrorPath(DIR, bad)).toBeNull();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
it('refuses a declared path inside Mossbear state rather than nesting a bundle in a bundle', () => {
|
|
25
|
+
expect(bundleMirrorPath(DIR, '.mossbear/context/other/a.md')).toBeNull();
|
|
26
|
+
expect(bundleMirrorPath(DIR, '.Mossbear/config.json')).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
it('refuses when the mirror would pass the 512-char bound the declared path alone fits', () => {
|
|
29
|
+
const declared = `${'d/'.repeat(252)}x.md`;
|
|
30
|
+
expect(declared.length).toBeLessThanOrEqual(512);
|
|
31
|
+
expect(bundleMirrorPath(DIR, declared)).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
it('refuses an unsafe bundle folder', () => {
|
|
34
|
+
expect(bundleMirrorPath('../elsewhere', 'a.md')).toBeNull();
|
|
35
|
+
expect(bundleMirrorPath('/abs', 'a.md')).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('isMossbearTreePath', () => {
|
|
39
|
+
it('recognises Mossbear’s own tree whatever the case or separator', () => {
|
|
40
|
+
expect(isMossbearTreePath('.mossbear/context/a.md')).toBe(true);
|
|
41
|
+
expect(isMossbearTreePath('.Mossbear\\evals\\AGENTS.md')).toBe(true);
|
|
42
|
+
expect(isMossbearTreePath('docs/.mossbear/a.md')).toBe(false);
|
|
43
|
+
expect(isMossbearTreePath('README.md')).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=bundle-mirror-path.test.js.map
|
|
@@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C,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GuideFileFormat } from '@mossbear/protocol';
|
|
2
|
+
export declare function detectFormat(path: string): GuideFileFormat | null;
|
|
3
|
+
export declare function isSupportedGuidePath(path: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* True for a path inside a `skills/<name>/` tree that is NOT itself the
|
|
6
|
+
* SKILL.md — i.e. skill *member* content (scripts, references, assets).
|
|
7
|
+
* `detectFormat` deliberately returns `null` for these, so a consumer that
|
|
8
|
+
* resolves a member edit to its owning skill uses this to recognise them
|
|
9
|
+
* rather than dropping them as unknown. No caller in this repo today: the
|
|
10
|
+
* incremental re-sync that used it (`rules watch`) was deleted, and the full
|
|
11
|
+
* discovery scan groups members by walking the tree instead. Kept as part of
|
|
12
|
+
* this module's path-classification surface, alongside `isSupportedGuidePath`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSkillMemberPath(path: string): boolean;
|
|
15
|
+
//# sourceMappingURL=detect-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-format.d.ts","sourceRoot":"","sources":["../src/detect-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AA0BzD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA+DjE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,WAEhD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,WAG7C"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
function normalizeGuidePath(path) {
|
|
2
|
+
return path.replaceAll('\\', '/').replace(/\/+/g, '/').toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
function isUnderSkillsDir(normalizedPath) {
|
|
5
|
+
return (normalizedPath.startsWith('.claude/skills/') ||
|
|
6
|
+
normalizedPath.includes('/.claude/skills/') ||
|
|
7
|
+
normalizedPath.startsWith('.agents/skills/') ||
|
|
8
|
+
normalizedPath.includes('/.agents/skills/'));
|
|
9
|
+
}
|
|
10
|
+
function basenameOf(normalizedPath) {
|
|
11
|
+
return normalizedPath.slice(normalizedPath.lastIndexOf('/') + 1);
|
|
12
|
+
}
|
|
13
|
+
function isUnderCursorRulesDir(normalizedPath) {
|
|
14
|
+
return (normalizedPath.startsWith('.cursor/rules/') ||
|
|
15
|
+
normalizedPath.includes('/.cursor/rules/'));
|
|
16
|
+
}
|
|
17
|
+
export function detectFormat(path) {
|
|
18
|
+
const normalizedPath = normalizeGuidePath(path);
|
|
19
|
+
// Checked ahead of the generic `.agents/` rule below: a SKILL.md nested
|
|
20
|
+
// under a `skills/` directory is a distinct artifact (npx-skills / Claude
|
|
21
|
+
// Code skill installs), not a freeform `.agents/` guide entry. Every other
|
|
22
|
+
// file in a skills/ tree (scripts, references, assets) is skill *member*
|
|
23
|
+
// content — imported alongside its SKILL.md by discovery, never as a
|
|
24
|
+
// standalone guide — so the whole subtree is opaque to the rules below
|
|
25
|
+
// (previously `.agents/skills/<skill>/scripts/…` leaked through the
|
|
26
|
+
// `.agents/` catch-all as its own agents-dir guide).
|
|
27
|
+
if (isUnderSkillsDir(normalizedPath)) {
|
|
28
|
+
return normalizedPath.endsWith('/skill.md') ? 'skill-md' : null;
|
|
29
|
+
}
|
|
30
|
+
if (normalizedPath === 'agents.md' || normalizedPath.endsWith('/agents.md')) {
|
|
31
|
+
return 'agents-md';
|
|
32
|
+
}
|
|
33
|
+
if (normalizedPath === 'claude.md' || normalizedPath.endsWith('/claude.md')) {
|
|
34
|
+
return 'claude-md';
|
|
35
|
+
}
|
|
36
|
+
if (normalizedPath === '.cursorrules' || normalizedPath.endsWith('/.cursorrules')) {
|
|
37
|
+
return 'cursorrules';
|
|
38
|
+
}
|
|
39
|
+
// Dot-files inside a recognised location are tooling scaffolding, not
|
|
40
|
+
// guidance: `mossbear init` writes `.agents/.gitkeep` so git tracks the
|
|
41
|
+
// otherwise-empty directory (`commands/init.ts`), and editors and VCS leave
|
|
42
|
+
// `.DS_Store`/`.gitignore`/`.gitattributes` beside real guides. Importing
|
|
43
|
+
// them files a guide the user never wrote — an empty card on the guides
|
|
44
|
+
// screen, an extra head on the run summary's guide count, and a body-less
|
|
45
|
+
// guide handed to the grader.
|
|
46
|
+
//
|
|
47
|
+
// Ordering is load-bearing: this sits *below* the `.cursorrules` branch,
|
|
48
|
+
// the one dot-file that is a genuine guide and is matched by exact name. A
|
|
49
|
+
// future dot-named format must be matched above this line too. Same shape
|
|
50
|
+
// as the skills branch at the top — a recognised location whose contents
|
|
51
|
+
// still are not, individually, guides.
|
|
52
|
+
if (basenameOf(normalizedPath).startsWith('.'))
|
|
53
|
+
return null;
|
|
54
|
+
// Modern Cursor "Project Rules": a directory of `.mdc` files under
|
|
55
|
+
// `.cursor/rules/` (project or `~/.cursor/rules/` global), distinct from the
|
|
56
|
+
// legacy single-file `.cursorrules` above. Cursor only reads `.mdc` files
|
|
57
|
+
// here, so other files (README.md, assets) fall through to `null`. Nested
|
|
58
|
+
// rule directories (`.cursor/rules/frontend/*.mdc`) are matched too.
|
|
59
|
+
if (isUnderCursorRulesDir(normalizedPath) && normalizedPath.endsWith('.mdc')) {
|
|
60
|
+
return 'cursor-rules';
|
|
61
|
+
}
|
|
62
|
+
if (normalizedPath.startsWith('.agents/') || normalizedPath.includes('/.agents/')) {
|
|
63
|
+
return 'agents-dir';
|
|
64
|
+
}
|
|
65
|
+
if (normalizedPath.startsWith('.claude/rules/') ||
|
|
66
|
+
normalizedPath.includes('/.claude/rules/')) {
|
|
67
|
+
return 'claude-rules';
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
export function isSupportedGuidePath(path) {
|
|
72
|
+
return detectFormat(path) !== null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* True for a path inside a `skills/<name>/` tree that is NOT itself the
|
|
76
|
+
* SKILL.md — i.e. skill *member* content (scripts, references, assets).
|
|
77
|
+
* `detectFormat` deliberately returns `null` for these, so a consumer that
|
|
78
|
+
* resolves a member edit to its owning skill uses this to recognise them
|
|
79
|
+
* rather than dropping them as unknown. No caller in this repo today: the
|
|
80
|
+
* incremental re-sync that used it (`rules watch`) was deleted, and the full
|
|
81
|
+
* discovery scan groups members by walking the tree instead. Kept as part of
|
|
82
|
+
* this module's path-classification surface, alongside `isSupportedGuidePath`.
|
|
83
|
+
*/
|
|
84
|
+
export function isSkillMemberPath(path) {
|
|
85
|
+
const normalizedPath = normalizeGuidePath(path);
|
|
86
|
+
return isUnderSkillsDir(normalizedPath) && !normalizedPath.endsWith('/skill.md');
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=detect-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-format.js","sourceRoot":"","sources":["../src/detect-format.ts"],"names":[],"mappings":"AAEA,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;AACtE,CAAC;AAED,SAAS,gBAAgB,CAAC,cAAsB;IAC9C,OAAO,CACL,cAAc,CAAC,UAAU,CAAC,iBAAiB,CAAC;QAC5C,cAAc,CAAC,QAAQ,CAAC,kBAAkB,CAAC;QAC3C,cAAc,CAAC,UAAU,CAAC,iBAAiB,CAAC;QAC5C,cAAc,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAC5C,CAAA;AACH,CAAC;AAED,SAAS,UAAU,CAAC,cAAsB;IACxC,OAAO,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;AAClE,CAAC;AAED,SAAS,qBAAqB,CAAC,cAAsB;IACnD,OAAO,CACL,cAAc,CAAC,UAAU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I,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7E,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,IAAI,cAAc,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAClF,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,IACE,cAAc,CAAC,UAAU,CAAC,gBAAgB,CAAC;QAC3C,cAAc,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAC1C,CAAC;QACD,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;AACpC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,cAAc,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAA;IAC/C,OAAO,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;AAClF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-format.test.d.ts","sourceRoot":"","sources":["../src/detect-format.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { detectFormat, isSkillMemberPath, isSupportedGuidePath } from './detect-format.js';
|
|
3
|
+
describe('detectFormat', () => {
|
|
4
|
+
it('detects canonical single-file formats', () => {
|
|
5
|
+
expect(detectFormat('AGENTS.md')).toBe('agents-md');
|
|
6
|
+
expect(detectFormat('/repo/CLAUDE.md')).toBe('claude-md');
|
|
7
|
+
expect(detectFormat('.cursorrules')).toBe('cursorrules');
|
|
8
|
+
});
|
|
9
|
+
it('detects directory-backed formats by path only', () => {
|
|
10
|
+
expect(detectFormat('.agents/reviewer/SKILL.md')).toBe('agents-dir');
|
|
11
|
+
expect(detectFormat('/repo/.claude/rules/backend.md')).toBe('claude-rules');
|
|
12
|
+
});
|
|
13
|
+
it('detects a SKILL.md nested under a skills/ directory as skill-md', () => {
|
|
14
|
+
expect(detectFormat('.claude/skills/reviewer/SKILL.md')).toBe('skill-md');
|
|
15
|
+
expect(detectFormat('/repo/.claude/skills/reviewer/SKILL.md')).toBe('skill-md');
|
|
16
|
+
expect(detectFormat('.agents/skills/reviewer/SKILL.md')).toBe('skill-md');
|
|
17
|
+
expect(detectFormat('/repo/.agents/skills/reviewer/SKILL.md')).toBe('skill-md');
|
|
18
|
+
});
|
|
19
|
+
it('ignores non-SKILL.md files inside a skills/ directory', () => {
|
|
20
|
+
expect(detectFormat('.claude/skills/reviewer/script.py')).toBeNull();
|
|
21
|
+
expect(detectFormat('.claude/skills/reviewer/README.md')).toBeNull();
|
|
22
|
+
// The whole skills/ subtree is opaque: under .agents/skills/ member files
|
|
23
|
+
// must not leak through the generic .agents/ catch-all as agents-dir
|
|
24
|
+
// guides — they import with their skill, as members.
|
|
25
|
+
expect(detectFormat('.agents/skills/reviewer/scripts/lint.py')).toBeNull();
|
|
26
|
+
expect(detectFormat('.agents/skills/reviewer/references/api.md')).toBeNull();
|
|
27
|
+
// Even an AGENTS.md nested in a skill directory is skill member content.
|
|
28
|
+
expect(detectFormat('.claude/skills/reviewer/references/AGENTS.md')).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
it('ignores dot-files in every recognised guide location', () => {
|
|
31
|
+
// `mossbear init` writes .agents/.gitkeep so git tracks the directory; it is
|
|
32
|
+
// scaffolding, not guidance, and importing it produced an empty guide.
|
|
33
|
+
expect(detectFormat('.agents/.gitkeep')).toBeNull();
|
|
34
|
+
expect(detectFormat('/repo/.agents/.gitkeep')).toBeNull();
|
|
35
|
+
expect(detectFormat('C:\\repo\\.agents\\.gitkeep')).toBeNull();
|
|
36
|
+
expect(detectFormat('.agents/team/.DS_Store')).toBeNull();
|
|
37
|
+
expect(detectFormat('.claude/rules/.gitkeep')).toBeNull();
|
|
38
|
+
expect(detectFormat('.cursor/rules/.gitkeep')).toBeNull();
|
|
39
|
+
// Even a dot-file carrying a rules-directory extension stays out.
|
|
40
|
+
expect(detectFormat('.cursor/rules/.hidden.mdc')).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
it('still detects .cursorrules, the one dot-file that is a guide', () => {
|
|
43
|
+
// Guards the ordering: the dot-file rejection must sit below this branch.
|
|
44
|
+
expect(detectFormat('.cursorrules')).toBe('cursorrules');
|
|
45
|
+
expect(detectFormat('/repo/.cursorrules')).toBe('cursorrules');
|
|
46
|
+
expect(detectFormat('C:\\repo\\.cursorrules')).toBe('cursorrules');
|
|
47
|
+
expect(isSupportedGuidePath('.cursorrules')).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it('detects .mdc files under .cursor/rules/ as cursor-rules', () => {
|
|
50
|
+
expect(detectFormat('.cursor/rules/backend.mdc')).toBe('cursor-rules');
|
|
51
|
+
expect(detectFormat('/repo/.cursor/rules/backend.mdc')).toBe('cursor-rules');
|
|
52
|
+
// Nested rule directories are supported.
|
|
53
|
+
expect(detectFormat('.cursor/rules/frontend/api.mdc')).toBe('cursor-rules');
|
|
54
|
+
// Global (~/.cursor/rules/) paths resolve to absolute home paths.
|
|
55
|
+
expect(detectFormat('/home/user/.cursor/rules/style.mdc')).toBe('cursor-rules');
|
|
56
|
+
});
|
|
57
|
+
it('ignores non-.mdc files under .cursor/rules/ and the legacy single file', () => {
|
|
58
|
+
expect(detectFormat('.cursor/rules/README.md')).toBeNull();
|
|
59
|
+
expect(detectFormat('.cursor/rules/assets/logo.png')).toBeNull();
|
|
60
|
+
// The legacy single-file format stays distinct from the directory format.
|
|
61
|
+
expect(detectFormat('.cursorrules')).toBe('cursorrules');
|
|
62
|
+
});
|
|
63
|
+
it('normalizes windows-style paths', () => {
|
|
64
|
+
expect(detectFormat('C:\\repo\\AGENTS.md')).toBe('agents-md');
|
|
65
|
+
expect(detectFormat('C:\\repo\\CLAUDE.md')).toBe('claude-md');
|
|
66
|
+
expect(detectFormat('C:\\repo\\.agents\\reviewer\\SKILL.md')).toBe('agents-dir');
|
|
67
|
+
expect(detectFormat('C:\\repo\\.claude\\rules\\backend.md')).toBe('claude-rules');
|
|
68
|
+
expect(detectFormat('C:\\repo\\.claude\\skills\\reviewer\\SKILL.md')).toBe('skill-md');
|
|
69
|
+
expect(detectFormat('C:\\repo\\.cursor\\rules\\backend.mdc')).toBe('cursor-rules');
|
|
70
|
+
});
|
|
71
|
+
it('returns null for unsupported paths', () => {
|
|
72
|
+
expect(detectFormat('README.md')).toBeNull();
|
|
73
|
+
expect(detectFormat('.agents')).toBeNull();
|
|
74
|
+
expect(detectFormat('.claude/settings.json')).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('isSupportedGuidePath', () => {
|
|
78
|
+
it('tracks detectFormat support', () => {
|
|
79
|
+
expect(isSupportedGuidePath('AGENTS.md')).toBe(true);
|
|
80
|
+
expect(isSupportedGuidePath('docs/guide.md')).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('isSkillMemberPath', () => {
|
|
84
|
+
it('is true for member content inside a skills/ tree', () => {
|
|
85
|
+
expect(isSkillMemberPath('.claude/skills/reviewer/script.py')).toBe(true);
|
|
86
|
+
expect(isSkillMemberPath('.claude/skills/reviewer/references/api.md')).toBe(true);
|
|
87
|
+
expect(isSkillMemberPath('/repo/.claude/skills/reviewer/assets/logo.png')).toBe(true);
|
|
88
|
+
expect(isSkillMemberPath('.agents/skills/reviewer/scripts/lint.py')).toBe(true);
|
|
89
|
+
// Even a nested AGENTS.md is member content, matching detectFormat.
|
|
90
|
+
expect(isSkillMemberPath('.claude/skills/reviewer/references/AGENTS.md')).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
it('is false for the SKILL.md itself', () => {
|
|
93
|
+
expect(isSkillMemberPath('.claude/skills/reviewer/SKILL.md')).toBe(false);
|
|
94
|
+
expect(isSkillMemberPath('/repo/.agents/skills/reviewer/SKILL.md')).toBe(false);
|
|
95
|
+
expect(isSkillMemberPath('C:\\repo\\.claude\\skills\\reviewer\\SKILL.md')).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
it('is false for paths outside a skills/ tree', () => {
|
|
98
|
+
expect(isSkillMemberPath('AGENTS.md')).toBe(false);
|
|
99
|
+
expect(isSkillMemberPath('.claude/rules/backend.md')).toBe(false);
|
|
100
|
+
expect(isSkillMemberPath('.cursor/rules/backend.mdc')).toBe(false);
|
|
101
|
+
expect(isSkillMemberPath('docs/guide.md')).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=detect-format.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-format.test.js","sourceRoot":"","sources":["../src/detect-format.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE1F,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACnD,MAAM,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACzD,MAAM,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IAC1D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,YAAY,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CA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M,CAAC,iBAAiB,CAAC,+CAA+C,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxF,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClD,MAAM,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACjE,MAAM,CAAC,iBAAiB,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClE,MAAM,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a **plain guide's** evaluation criteria live on disk: the eval shadow
|
|
3
|
+
* tree at `<scopeRoot>/.mossbear/evals/<the guide's scope-relative path>`.
|
|
4
|
+
*
|
|
5
|
+
* One rule — *the eval file lives with its guide* — expressed two ways, because
|
|
6
|
+
* the two guide shapes have different structures:
|
|
7
|
+
*
|
|
8
|
+
* - a **skill** is a directory, so its criteria sit inside it as a positional
|
|
9
|
+
* `EVAL.md` (already shipped, server-side, as `skillMemberContentType`).
|
|
10
|
+
* Nothing here touches that half;
|
|
11
|
+
* - a **plain guide** is a bare file with nowhere to put a sibling that would
|
|
12
|
+
* not clutter — and land inside — a discovery root, so its criteria go in
|
|
13
|
+
* the shadow tree, which mirrors the guide's own path.
|
|
14
|
+
*
|
|
15
|
+
* Mirroring the path is what removes the mapping table: two guides cannot share
|
|
16
|
+
* a path, so their shadow entries cannot collide, and the scope root carries the
|
|
17
|
+
* rest — a `global` guide's criteria land in `~/.mossbear/evals/.claude/CLAUDE.md`
|
|
18
|
+
* by the same rule that puts a `project` guide's in the repo.
|
|
19
|
+
*
|
|
20
|
+
* **The shadow tree is never guidance.** `.mossbear/` is not a discovery root
|
|
21
|
+
* (`discover.ts`), so nothing under it is imported as a guide — that is the
|
|
22
|
+
* property `rules-discover.test.ts` and `rules-manifest.test.ts` pin down. But
|
|
23
|
+
* "not discovered" is not the same as "not classifiable", and `detectFormat` is
|
|
24
|
+
* path-only: hand it `.mossbear/evals/AGENTS.md` and it answers `agents-md`,
|
|
25
|
+
* because the path *ends* in `agents.md`. Any future call site that classifies a
|
|
26
|
+
* local file it did not get from discovery — the reconciler this item unblocks —
|
|
27
|
+
* must therefore ask `classifyLocalItemPath` rather than `detectFormat`, which
|
|
28
|
+
* is why the shadow-tree check lives inside it and cannot be forgotten.
|
|
29
|
+
*
|
|
30
|
+
* **Why this lives in `projections` rather than the CLI or the protocol.**
|
|
31
|
+
* The server needs it too: a guide pull has to tell each client where that
|
|
32
|
+
* guide's criteria belong, and deriving the path on each client instead would
|
|
33
|
+
* be the per-clone divergence `unified-item-sync` exists to remove. Of the
|
|
34
|
+
* three homes that could serve both sides, this is the cheapest — the rule is
|
|
35
|
+
* *about* format and path semantics, which is this package's subject, and it
|
|
36
|
+
* needs `detectFormat`, which is already here. Putting it in
|
|
37
|
+
* `@mossbear/protocol` would drag this package into the dependency graph of a
|
|
38
|
+
* published, deliberately valibot-only contract package; re-expressing the
|
|
39
|
+
* skill check without `detectFormat` would duplicate the rule this module was
|
|
40
|
+
* written to keep in one place (Planning Principle 14).
|
|
41
|
+
*/
|
|
42
|
+
import type { GuideFileFormat } from '@mossbear/protocol';
|
|
43
|
+
/** Scope-root-relative POSIX directory holding the eval shadow tree. */
|
|
44
|
+
export declare const EVAL_SHADOW_DIR = ".mossbear/evals";
|
|
45
|
+
/**
|
|
46
|
+
* The shadow-tree path for a **plain** guide, relative to the same scope root
|
|
47
|
+
* the guide's own path is relative to. `null` when the guide path could never
|
|
48
|
+
* have been discovered as a guide in the first place (absolute, escaping,
|
|
49
|
+
* control characters, over-long, or already inside `.mossbear/`) — and `null` for a
|
|
50
|
+
* skill, which keeps its criteria positionally.
|
|
51
|
+
*/
|
|
52
|
+
export declare function evalShadowPath(guidePath: string): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* The inverse: the guide whose criteria a shadow path holds, or `null` when the
|
|
55
|
+
* path is not in the shadow tree (or names the directory itself).
|
|
56
|
+
*
|
|
57
|
+
* A true inverse over the paths `evalShadowPath` accepts, and deliberately no
|
|
58
|
+
* wider: a remainder this function would recover but that function would never
|
|
59
|
+
* emit — `.mossbear/evals/.mossbear/evals/AGENTS.md`, `.mossbear/evals/.claude/skills/review/SKILL.md` —
|
|
60
|
+
* names no guide whose criteria belong here, so it is refused rather than
|
|
61
|
+
* reported as valid eval content. Without that, the shadow tree could hold an
|
|
62
|
+
* entry the derivation says is unreachable.
|
|
63
|
+
*/
|
|
64
|
+
export declare function guidePathFromEvalShadow(shadowPath: string): string | null;
|
|
65
|
+
/**
|
|
66
|
+
* What a scope-relative path on disk *is*, for a caller holding a path rather
|
|
67
|
+
* than a discovery result.
|
|
68
|
+
*
|
|
69
|
+
* `eval` is checked before anything else so no path under `.mossbear/` can come
|
|
70
|
+
* back as a guide — see this module's header for why `detectFormat` alone gets
|
|
71
|
+
* that wrong.
|
|
72
|
+
*/
|
|
73
|
+
export type LocalItemClassification =
|
|
74
|
+
/** Criteria for the guide at `guidePath`, held in the shadow tree. */
|
|
75
|
+
{
|
|
76
|
+
kind: 'eval';
|
|
77
|
+
guidePath: string;
|
|
78
|
+
}
|
|
79
|
+
/** A guide file, in the format `detectFormat` recognised. */
|
|
80
|
+
| {
|
|
81
|
+
kind: 'guide';
|
|
82
|
+
format: GuideFileFormat;
|
|
83
|
+
}
|
|
84
|
+
/** Neither: Mossbear's own state, a skill member, an unrelated file. */
|
|
85
|
+
| {
|
|
86
|
+
kind: 'other';
|
|
87
|
+
};
|
|
88
|
+
export declare function classifyLocalItemPath(path: string): LocalItemClassification;
|
|
89
|
+
//# sourceMappingURL=eval-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-path.d.ts","sourceRoot":"","sources":["../src/eval-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAWH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEzD,wEAAwE;AACxE,eAAO,MAAM,eAAe,oBAAoB,CAAA;AAIhD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYzE;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB;AACjC,sEAAsE;AACpE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE;AACrC,6DAA6D;GAC3D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE;AAC5C,wEAAwE;GACtE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAErB,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,CAU3E"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a **plain guide's** evaluation criteria live on disk: the eval shadow
|
|
3
|
+
* tree at `<scopeRoot>/.mossbear/evals/<the guide's scope-relative path>`.
|
|
4
|
+
*
|
|
5
|
+
* One rule — *the eval file lives with its guide* — expressed two ways, because
|
|
6
|
+
* the two guide shapes have different structures:
|
|
7
|
+
*
|
|
8
|
+
* - a **skill** is a directory, so its criteria sit inside it as a positional
|
|
9
|
+
* `EVAL.md` (already shipped, server-side, as `skillMemberContentType`).
|
|
10
|
+
* Nothing here touches that half;
|
|
11
|
+
* - a **plain guide** is a bare file with nowhere to put a sibling that would
|
|
12
|
+
* not clutter — and land inside — a discovery root, so its criteria go in
|
|
13
|
+
* the shadow tree, which mirrors the guide's own path.
|
|
14
|
+
*
|
|
15
|
+
* Mirroring the path is what removes the mapping table: two guides cannot share
|
|
16
|
+
* a path, so their shadow entries cannot collide, and the scope root carries the
|
|
17
|
+
* rest — a `global` guide's criteria land in `~/.mossbear/evals/.claude/CLAUDE.md`
|
|
18
|
+
* by the same rule that puts a `project` guide's in the repo.
|
|
19
|
+
*
|
|
20
|
+
* **The shadow tree is never guidance.** `.mossbear/` is not a discovery root
|
|
21
|
+
* (`discover.ts`), so nothing under it is imported as a guide — that is the
|
|
22
|
+
* property `rules-discover.test.ts` and `rules-manifest.test.ts` pin down. But
|
|
23
|
+
* "not discovered" is not the same as "not classifiable", and `detectFormat` is
|
|
24
|
+
* path-only: hand it `.mossbear/evals/AGENTS.md` and it answers `agents-md`,
|
|
25
|
+
* because the path *ends* in `agents.md`. Any future call site that classifies a
|
|
26
|
+
* local file it did not get from discovery — the reconciler this item unblocks —
|
|
27
|
+
* must therefore ask `classifyLocalItemPath` rather than `detectFormat`, which
|
|
28
|
+
* is why the shadow-tree check lives inside it and cannot be forgotten.
|
|
29
|
+
*
|
|
30
|
+
* **Why this lives in `projections` rather than the CLI or the protocol.**
|
|
31
|
+
* The server needs it too: a guide pull has to tell each client where that
|
|
32
|
+
* guide's criteria belong, and deriving the path on each client instead would
|
|
33
|
+
* be the per-clone divergence `unified-item-sync` exists to remove. Of the
|
|
34
|
+
* three homes that could serve both sides, this is the cheapest — the rule is
|
|
35
|
+
* *about* format and path semantics, which is this package's subject, and it
|
|
36
|
+
* needs `detectFormat`, which is already here. Putting it in
|
|
37
|
+
* `@mossbear/protocol` would drag this package into the dependency graph of a
|
|
38
|
+
* published, deliberately valibot-only contract package; re-expressing the
|
|
39
|
+
* skill check without `detectFormat` would duplicate the rule this module was
|
|
40
|
+
* written to keep in one place (Planning Principle 14).
|
|
41
|
+
*/
|
|
42
|
+
import { detectFormat } from './detect-format.js';
|
|
43
|
+
import { isSafeRelativePath, isSkillGuidePath, isUnderMossbearDir, segmentsOf, toPosix, } from './path-rules.js';
|
|
44
|
+
/** Scope-root-relative POSIX directory holding the eval shadow tree. */
|
|
45
|
+
export const EVAL_SHADOW_DIR = '.mossbear/evals';
|
|
46
|
+
const MOSSBEAR_DIR_SEGMENT = '.mossbear';
|
|
47
|
+
/**
|
|
48
|
+
* The shadow-tree path for a **plain** guide, relative to the same scope root
|
|
49
|
+
* the guide's own path is relative to. `null` when the guide path could never
|
|
50
|
+
* have been discovered as a guide in the first place (absolute, escaping,
|
|
51
|
+
* control characters, over-long, or already inside `.mossbear/`) — and `null` for a
|
|
52
|
+
* skill, which keeps its criteria positionally.
|
|
53
|
+
*/
|
|
54
|
+
export function evalShadowPath(guidePath) {
|
|
55
|
+
const normalized = toPosix(guidePath);
|
|
56
|
+
if (!isSafeRelativePath(normalized))
|
|
57
|
+
return null;
|
|
58
|
+
if (isUnderMossbearDir(normalized))
|
|
59
|
+
return null;
|
|
60
|
+
if (isSkillGuidePath(normalized))
|
|
61
|
+
return null;
|
|
62
|
+
const shadowPath = `${EVAL_SHADOW_DIR}/${normalized}`;
|
|
63
|
+
// The shadow path is itself carried in payloads and sidecars, so a guide path
|
|
64
|
+
// that is safe on its own but pushes the shadow path past the 512-char bound
|
|
65
|
+
// has no representable home — say so rather than emitting a path that fails
|
|
66
|
+
// validation one layer later.
|
|
67
|
+
return isSafeRelativePath(shadowPath) ? shadowPath : null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The inverse: the guide whose criteria a shadow path holds, or `null` when the
|
|
71
|
+
* path is not in the shadow tree (or names the directory itself).
|
|
72
|
+
*
|
|
73
|
+
* A true inverse over the paths `evalShadowPath` accepts, and deliberately no
|
|
74
|
+
* wider: a remainder this function would recover but that function would never
|
|
75
|
+
* emit — `.mossbear/evals/.mossbear/evals/AGENTS.md`, `.mossbear/evals/.claude/skills/review/SKILL.md` —
|
|
76
|
+
* names no guide whose criteria belong here, so it is refused rather than
|
|
77
|
+
* reported as valid eval content. Without that, the shadow tree could hold an
|
|
78
|
+
* entry the derivation says is unreachable.
|
|
79
|
+
*/
|
|
80
|
+
export function guidePathFromEvalShadow(shadowPath) {
|
|
81
|
+
const normalized = toPosix(shadowPath);
|
|
82
|
+
const segments = segmentsOf(normalized);
|
|
83
|
+
if (segments[0] !== MOSSBEAR_DIR_SEGMENT || segments[1] !== 'evals')
|
|
84
|
+
return null;
|
|
85
|
+
// Slice the original (not the lower-cased copy) so the guide path keeps the
|
|
86
|
+
// casing it was written with — `AGENTS.md` must not come back as `agents.md`.
|
|
87
|
+
const remainder = normalized.split('/').slice(2).join('/');
|
|
88
|
+
if (remainder.length === 0)
|
|
89
|
+
return null;
|
|
90
|
+
if (!isSafeRelativePath(remainder))
|
|
91
|
+
return null;
|
|
92
|
+
if (isUnderMossbearDir(remainder) || isSkillGuidePath(remainder))
|
|
93
|
+
return null;
|
|
94
|
+
return remainder;
|
|
95
|
+
}
|
|
96
|
+
export function classifyLocalItemPath(path) {
|
|
97
|
+
const guidePath = guidePathFromEvalShadow(path);
|
|
98
|
+
if (guidePath !== null)
|
|
99
|
+
return { kind: 'eval', guidePath };
|
|
100
|
+
// Everything else under `.mossbear/` is Mossbear's own state (`docs.json`, the repo
|
|
101
|
+
// config, pulled `context/`) — and an unusable shadow path (`.mossbear/evals/..`)
|
|
102
|
+
// lands here too. Never guidance either way.
|
|
103
|
+
if (isUnderMossbearDir(path))
|
|
104
|
+
return { kind: 'other' };
|
|
105
|
+
const format = detectFormat(toPosix(path));
|
|
106
|
+
return format === null ? { kind: 'other' } : { kind: 'guide', format };
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=eval-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-path.js","sourceRoot":"","sources":["../src/eval-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC1D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACvC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAC/C,IAAI,kBAAkB,CAAC,SAAS,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7E,OAAO,SAAS,CAAA;AAClB,CAAC;AAkBD,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,SAAS,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IAC/C,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;IAC1D,oFAAoF;IACpF,kFAAkF;IAClF,6CAA6C;IAC7C,IAAI,kBAAkB,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;IAEtD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1C,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AACxE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mossbear/projections
|
|
3
|
+
*
|
|
4
|
+
* Pure projection logic for the canonical .agents/ output, plus format
|
|
5
|
+
* detection and path helpers.
|
|
6
|
+
* This package must remain importable outside the CLI package.
|
|
7
|
+
*
|
|
8
|
+
* There is no AGENTS.md renderer here. `renderAgentsMd` and the `mossbear
|
|
9
|
+
* guides project` command that called it were deleted (`guides-project-removal`):
|
|
10
|
+
* AGENTS.md is written by the docs phase, from guides, and nothing produced
|
|
11
|
+
* the agent-config JSON this package's renderer took. (`mossbear init` was a
|
|
12
|
+
* second writer until it stopped scaffolding a starter template; the docs
|
|
13
|
+
* phase is the only one now.)
|
|
14
|
+
*/
|
|
15
|
+
export { bundleMirrorPath, isMossbearTreePath } from './bundle-mirror-path.js';
|
|
16
|
+
export { EVAL_SHADOW_DIR, classifyLocalItemPath, evalShadowPath, guidePathFromEvalShadow, } from './eval-path.js';
|
|
17
|
+
export { detectFormat, isSkillMemberPath, isSupportedGuidePath } from './detect-format.js';
|
|
18
|
+
export { skillMemberPath } from './skill-member-path.js';
|
|
19
|
+
export type { LocalItemClassification } from './eval-path.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,uBAAuB,GACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,YAAY,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mossbear/projections
|
|
3
|
+
*
|
|
4
|
+
* Pure projection logic for the canonical .agents/ output, plus format
|
|
5
|
+
* detection and path helpers.
|
|
6
|
+
* This package must remain importable outside the CLI package.
|
|
7
|
+
*
|
|
8
|
+
* There is no AGENTS.md renderer here. `renderAgentsMd` and the `mossbear
|
|
9
|
+
* guides project` command that called it were deleted (`guides-project-removal`):
|
|
10
|
+
* AGENTS.md is written by the docs phase, from guides, and nothing produced
|
|
11
|
+
* the agent-config JSON this package's renderer took. (`mossbear init` was a
|
|
12
|
+
* second writer until it stopped scaffolding a starter template; the docs
|
|
13
|
+
* phase is the only one now.)
|
|
14
|
+
*/
|
|
15
|
+
export { bundleMirrorPath, isMossbearTreePath } from './bundle-mirror-path.js';
|
|
16
|
+
export { EVAL_SHADOW_DIR, classifyLocalItemPath, evalShadowPath, guidePathFromEvalShadow, } from './eval-path.js';
|
|
17
|
+
export { detectFormat, isSkillMemberPath, isSupportedGuidePath } from './detect-format.js';
|
|
18
|
+
export { skillMemberPath } from './skill-member-path.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,uBAAuB,GACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope-relative path predicates that both attached-file derivations share.
|
|
3
|
+
*
|
|
4
|
+
* A guide's attached files land in two different places depending on the guide's
|
|
5
|
+
* shape — a plain guide's criteria go to the eval shadow tree (`eval-path.ts`), a
|
|
6
|
+
* skill's members go inside its own directory (`skill-member-path.ts`) — but both
|
|
7
|
+
* derivations answer the same safety questions first, and a second copy of those
|
|
8
|
+
* answers is a second thing to get wrong. They live here so the two derivations
|
|
9
|
+
* cannot drift on what counts as a safe path or as a skill.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toPosix(path: string): string;
|
|
12
|
+
export declare function isSafeRelativePath(path: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Split a scope-relative path into its lower-cased segments.
|
|
15
|
+
*
|
|
16
|
+
* Lower-cased because recognition and derivation pull in opposite directions:
|
|
17
|
+
* a shadow path is *written* as exactly `.mossbear/evals/…`, but on a
|
|
18
|
+
* case-insensitive filesystem `.Mossbear/Evals/AGENTS.md` names the same file, and
|
|
19
|
+
* the two ways of being wrong about it are not symmetric — classifying eval
|
|
20
|
+
* criteria as guidance hands a rubric to an agent as instructions, while
|
|
21
|
+
* classifying a stray capitalised path as eval content merely declines to treat
|
|
22
|
+
* it as a guide. Recognition therefore leans the safe way.
|
|
23
|
+
*/
|
|
24
|
+
export declare function segmentsOf(path: string): string[];
|
|
25
|
+
/** True when `path` is inside `.mossbear/`, whatever it holds. */
|
|
26
|
+
export declare function isUnderMossbearDir(path: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* True when a path is a skill's own `SKILL.md`.
|
|
29
|
+
*
|
|
30
|
+
* The rule is *the attached file lives with its guide*, and a skill's guide is a
|
|
31
|
+
* directory — so its criteria are the positional `EVAL.md` inside it and its
|
|
32
|
+
* members are the rest of that directory (`skillMemberContentType`,
|
|
33
|
+
* server-side). Shadowing a skill as well would put one skill's rubric in two
|
|
34
|
+
* places, split it out of the directory that makes a skill portable, and hand
|
|
35
|
+
* the next reconciler
|
|
36
|
+
* two rows to disagree over — two shapes of one fact, which is a dual-write
|
|
37
|
+
* window rather than a steady state, not something to build in on purpose.
|
|
38
|
+
* `detectFormat` is the same test discovery uses, so what counts as a
|
|
39
|
+
* skill here cannot drift from what counts as one there.
|
|
40
|
+
*
|
|
41
|
+
* This one predicate partitions the two derivations: `evalShadowPath` returns
|
|
42
|
+
* null exactly where this is true, and `skillMemberPath` returns null exactly
|
|
43
|
+
* where it is false.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isSkillGuidePath(path: string): boolean;
|
|
46
|
+
//# sourceMappingURL=path-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-rules.d.ts","sourceRoot":"","sources":["../src/path-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAeH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjD;AAED,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope-relative path predicates that both attached-file derivations share.
|
|
3
|
+
*
|
|
4
|
+
* A guide's attached files land in two different places depending on the guide's
|
|
5
|
+
* shape — a plain guide's criteria go to the eval shadow tree (`eval-path.ts`), a
|
|
6
|
+
* skill's members go inside its own directory (`skill-member-path.ts`) — but both
|
|
7
|
+
* derivations answer the same safety questions first, and a second copy of those
|
|
8
|
+
* answers is a second thing to get wrong. They live here so the two derivations
|
|
9
|
+
* cannot drift on what counts as a safe path or as a skill.
|
|
10
|
+
*/
|
|
11
|
+
import { SafeRelativePosixPathSchema } from '@mossbear/protocol';
|
|
12
|
+
import * as v from 'valibot';
|
|
13
|
+
import { detectFormat } from './detect-format.js';
|
|
14
|
+
/**
|
|
15
|
+
* The `.mossbear/` directory as a whole is Mossbear's own state — the sidecar, the
|
|
16
|
+
* repo config, pulled context, and the eval shadow tree. None of it is guidance,
|
|
17
|
+
* so a *guide* path that claims to live there is a caller error rather than a
|
|
18
|
+
* file to derive anything from.
|
|
19
|
+
*/
|
|
20
|
+
const MOSSBEAR_DIR_SEGMENT = '.mossbear';
|
|
21
|
+
export function toPosix(path) {
|
|
22
|
+
return path.replaceAll('\\', '/');
|
|
23
|
+
}
|
|
24
|
+
export function isSafeRelativePath(path) {
|
|
25
|
+
return v.safeParse(SafeRelativePosixPathSchema, path).success;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Split a scope-relative path into its lower-cased segments.
|
|
29
|
+
*
|
|
30
|
+
* Lower-cased because recognition and derivation pull in opposite directions:
|
|
31
|
+
* a shadow path is *written* as exactly `.mossbear/evals/…`, but on a
|
|
32
|
+
* case-insensitive filesystem `.Mossbear/Evals/AGENTS.md` names the same file, and
|
|
33
|
+
* the two ways of being wrong about it are not symmetric — classifying eval
|
|
34
|
+
* criteria as guidance hands a rubric to an agent as instructions, while
|
|
35
|
+
* classifying a stray capitalised path as eval content merely declines to treat
|
|
36
|
+
* it as a guide. Recognition therefore leans the safe way.
|
|
37
|
+
*/
|
|
38
|
+
export function segmentsOf(path) {
|
|
39
|
+
return toPosix(path).toLowerCase().split('/');
|
|
40
|
+
}
|
|
41
|
+
/** True when `path` is inside `.mossbear/`, whatever it holds. */
|
|
42
|
+
export function isUnderMossbearDir(path) {
|
|
43
|
+
return segmentsOf(path)[0] === MOSSBEAR_DIR_SEGMENT;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* True when a path is a skill's own `SKILL.md`.
|
|
47
|
+
*
|
|
48
|
+
* The rule is *the attached file lives with its guide*, and a skill's guide is a
|
|
49
|
+
* directory — so its criteria are the positional `EVAL.md` inside it and its
|
|
50
|
+
* members are the rest of that directory (`skillMemberContentType`,
|
|
51
|
+
* server-side). Shadowing a skill as well would put one skill's rubric in two
|
|
52
|
+
* places, split it out of the directory that makes a skill portable, and hand
|
|
53
|
+
* the next reconciler
|
|
54
|
+
* two rows to disagree over — two shapes of one fact, which is a dual-write
|
|
55
|
+
* window rather than a steady state, not something to build in on purpose.
|
|
56
|
+
* `detectFormat` is the same test discovery uses, so what counts as a
|
|
57
|
+
* skill here cannot drift from what counts as one there.
|
|
58
|
+
*
|
|
59
|
+
* This one predicate partitions the two derivations: `evalShadowPath` returns
|
|
60
|
+
* null exactly where this is true, and `skillMemberPath` returns null exactly
|
|
61
|
+
* where it is false.
|
|
62
|
+
*/
|
|
63
|
+
export function isSkillGuidePath(path) {
|
|
64
|
+
return detectFormat(path) === 'skill-md';
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=path-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-rules.js","sourceRoot":"","sources":["../src/path-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,WAAW,CAAA;AAExC,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,CAAC,CAAC,SAAS,CAAC,2BAA2B,EAAE,IAAI,CAAC,CAAC,OAAO,CAAA;AAC/D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,oBAAoB,CAAA;AACrD,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,UAAU,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a **skill's member files** live on disk: inside the skill's own
|
|
3
|
+
* directory, beside the `SKILL.md` that names it.
|
|
4
|
+
*
|
|
5
|
+
* This is the other half of the rule `eval-path.ts` states — *the attached file
|
|
6
|
+
* lives with its guide* — for the guide shape that is a directory rather than a
|
|
7
|
+
* bare file. A skill is `<dir>/SKILL.md` plus whatever `scripts/`,
|
|
8
|
+
* `references/` and `assets/` it carries, and those members are what make it
|
|
9
|
+
* runnable: a `SKILL.md` delivered without them is a skill that cannot do its
|
|
10
|
+
* job. `isSkillGuidePath` partitions the two derivations exactly —
|
|
11
|
+
* `evalShadowPath` returns null where it is true, this returns null where it is
|
|
12
|
+
* false — so no guide can ever get both, and none can get neither.
|
|
13
|
+
*
|
|
14
|
+
* **Why the server derives it rather than each client.** Identical to
|
|
15
|
+
* `evalShadowPath`'s reason, and it is the failure `skill-member-delivery` was
|
|
16
|
+
* filed for: members are `guide_files` rows attached to their guide by
|
|
17
|
+
* `guide_id` with no bundle membership of their own, so the only thing that
|
|
18
|
+
* knows where a member belongs is the guide's own path. Letting each
|
|
19
|
+
* subscribed clone re-derive that from a member name would be the per-clone
|
|
20
|
+
* divergence `unified-item-sync` exists to remove — and letting none of them
|
|
21
|
+
* derive it is what shipped, which is a skill delivered in pieces with the sync
|
|
22
|
+
* reporting success.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The scope-relative path a skill member lands at, or `null` when it has no
|
|
26
|
+
* representable home.
|
|
27
|
+
*
|
|
28
|
+
* `guidePath` is the skill's own `SKILL.md`, scope-relative; `memberPath` is the
|
|
29
|
+
* member's path *relative to the skill directory* — the form the importer stores
|
|
30
|
+
* in member metadata (`SkillMemberMetadata.path`). The result is relative to the
|
|
31
|
+
* same scope root the guide path is, so a `global` skill's members land under the
|
|
32
|
+
* home directory by the same rule that puts a `project` skill's under the
|
|
33
|
+
* checkout, with no second scope decision to keep in sync.
|
|
34
|
+
*
|
|
35
|
+
* Null, never a repaired path, in every rejecting case — the caller reports the
|
|
36
|
+
* member as unplaceable rather than writing it somewhere approximate:
|
|
37
|
+
*
|
|
38
|
+
* - the guide is not a skill (a plain guide has no directory to hold members),
|
|
39
|
+
* or its path is unsafe or inside `.mossbear/`;
|
|
40
|
+
* - the member path is absolute, traverses, carries control characters, or is
|
|
41
|
+
* over-long — `memberPath` is remote-supplied and is parsed, not trusted;
|
|
42
|
+
* - the joined result is unsafe or would land in `.mossbear/`, which is Mossbear's own
|
|
43
|
+
* state and is rewritten by sync.
|
|
44
|
+
*
|
|
45
|
+
* The result is re-checked rather than assumed safe from its two halves: length
|
|
46
|
+
* is the case that only exists after joining, where a legal guide path and a
|
|
47
|
+
* legal member path together exceed the bound the wire format enforces.
|
|
48
|
+
*/
|
|
49
|
+
export declare function skillMemberPath(guidePath: string, memberPath: string): string | null;
|
|
50
|
+
//# sourceMappingURL=skill-member-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-member-path.d.ts","sourceRoot":"","sources":["../src/skill-member-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AASH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoBpF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a **skill's member files** live on disk: inside the skill's own
|
|
3
|
+
* directory, beside the `SKILL.md` that names it.
|
|
4
|
+
*
|
|
5
|
+
* This is the other half of the rule `eval-path.ts` states — *the attached file
|
|
6
|
+
* lives with its guide* — for the guide shape that is a directory rather than a
|
|
7
|
+
* bare file. A skill is `<dir>/SKILL.md` plus whatever `scripts/`,
|
|
8
|
+
* `references/` and `assets/` it carries, and those members are what make it
|
|
9
|
+
* runnable: a `SKILL.md` delivered without them is a skill that cannot do its
|
|
10
|
+
* job. `isSkillGuidePath` partitions the two derivations exactly —
|
|
11
|
+
* `evalShadowPath` returns null where it is true, this returns null where it is
|
|
12
|
+
* false — so no guide can ever get both, and none can get neither.
|
|
13
|
+
*
|
|
14
|
+
* **Why the server derives it rather than each client.** Identical to
|
|
15
|
+
* `evalShadowPath`'s reason, and it is the failure `skill-member-delivery` was
|
|
16
|
+
* filed for: members are `guide_files` rows attached to their guide by
|
|
17
|
+
* `guide_id` with no bundle membership of their own, so the only thing that
|
|
18
|
+
* knows where a member belongs is the guide's own path. Letting each
|
|
19
|
+
* subscribed clone re-derive that from a member name would be the per-clone
|
|
20
|
+
* divergence `unified-item-sync` exists to remove — and letting none of them
|
|
21
|
+
* derive it is what shipped, which is a skill delivered in pieces with the sync
|
|
22
|
+
* reporting success.
|
|
23
|
+
*/
|
|
24
|
+
import { isSafeRelativePath, isSkillGuidePath, isUnderMossbearDir, toPosix, } from './path-rules.js';
|
|
25
|
+
/**
|
|
26
|
+
* The scope-relative path a skill member lands at, or `null` when it has no
|
|
27
|
+
* representable home.
|
|
28
|
+
*
|
|
29
|
+
* `guidePath` is the skill's own `SKILL.md`, scope-relative; `memberPath` is the
|
|
30
|
+
* member's path *relative to the skill directory* — the form the importer stores
|
|
31
|
+
* in member metadata (`SkillMemberMetadata.path`). The result is relative to the
|
|
32
|
+
* same scope root the guide path is, so a `global` skill's members land under the
|
|
33
|
+
* home directory by the same rule that puts a `project` skill's under the
|
|
34
|
+
* checkout, with no second scope decision to keep in sync.
|
|
35
|
+
*
|
|
36
|
+
* Null, never a repaired path, in every rejecting case — the caller reports the
|
|
37
|
+
* member as unplaceable rather than writing it somewhere approximate:
|
|
38
|
+
*
|
|
39
|
+
* - the guide is not a skill (a plain guide has no directory to hold members),
|
|
40
|
+
* or its path is unsafe or inside `.mossbear/`;
|
|
41
|
+
* - the member path is absolute, traverses, carries control characters, or is
|
|
42
|
+
* over-long — `memberPath` is remote-supplied and is parsed, not trusted;
|
|
43
|
+
* - the joined result is unsafe or would land in `.mossbear/`, which is Mossbear's own
|
|
44
|
+
* state and is rewritten by sync.
|
|
45
|
+
*
|
|
46
|
+
* The result is re-checked rather than assumed safe from its two halves: length
|
|
47
|
+
* is the case that only exists after joining, where a legal guide path and a
|
|
48
|
+
* legal member path together exceed the bound the wire format enforces.
|
|
49
|
+
*/
|
|
50
|
+
export function skillMemberPath(guidePath, memberPath) {
|
|
51
|
+
const guide = toPosix(guidePath);
|
|
52
|
+
if (!isSafeRelativePath(guide))
|
|
53
|
+
return null;
|
|
54
|
+
if (isUnderMossbearDir(guide))
|
|
55
|
+
return null;
|
|
56
|
+
if (!isSkillGuidePath(guide))
|
|
57
|
+
return null;
|
|
58
|
+
const member = toPosix(memberPath);
|
|
59
|
+
if (!isSafeRelativePath(member))
|
|
60
|
+
return null;
|
|
61
|
+
// A `skill-md` path always sits under a `skills/` directory and ends in
|
|
62
|
+
// `/skill.md` (`detect-format.ts`), so it always has a parent — there is no
|
|
63
|
+
// root-level skill and therefore no empty-directory case to handle.
|
|
64
|
+
const separatorIndex = guide.lastIndexOf('/');
|
|
65
|
+
if (separatorIndex === -1)
|
|
66
|
+
return null;
|
|
67
|
+
const skillDir = guide.slice(0, separatorIndex);
|
|
68
|
+
const joined = `${skillDir}/${member}`;
|
|
69
|
+
if (!isSafeRelativePath(joined))
|
|
70
|
+
return null;
|
|
71
|
+
if (isUnderMossbearDir(joined))
|
|
72
|
+
return null;
|
|
73
|
+
return joined;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=skill-member-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-member-path.js","sourceRoot":"","sources":["../src/skill-member-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,OAAO,GACR,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB,EAAE,UAAkB;IACnE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;IAChC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3C,IAAI,kBAAkB,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAC1C,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAEzC,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAClC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAE5C,wEAAwE;IACxE,4EAA4E;IAC5E,oEAAoE;IACpE,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC7C,IAAI,cAAc,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IACtC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAA;IAE/C,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAA;IACtC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAC5C,IAAI,kBAAkB,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3C,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-member-path.test.d.ts","sourceRoot":"","sources":["../src/skill-member-path.test.ts"],"names":[],"mappings":""}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-member-path.test.js","sourceRoot":"","sources":["../src/skill-member-path.test.ts"],"names":[],"mappings":"AAAA,OAAO,EA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BAAkB,CAAC,CAAC,CAAC,IAAI,CACnF,uCAAuC,CACxC,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mossbear/projections",
|
|
3
|
+
"version": "0.1.0-alpha.100",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Guide file format detection for Mossbear — AGENTS.md, .agents/, CLAUDE.md, .claude/rules/, .cursorrules.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"!dist/.tsbuildinfo",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://mossbear.io",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://mossbear.io/docs/"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"provenance": false
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc --project tsconfig.json",
|
|
32
|
+
"dev": "tsc --project tsconfig.json --watch",
|
|
33
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
34
|
+
"lint": "oxlint",
|
|
35
|
+
"lint:fix": "oxfmt && oxlint --fix",
|
|
36
|
+
"format": "oxfmt",
|
|
37
|
+
"format:check": "oxfmt --check",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@mossbear/protocol": "0.1.0-alpha.100",
|
|
42
|
+
"valibot": "^1.4.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "5.9.3"
|
|
46
|
+
}
|
|
47
|
+
}
|