11import * as NodeServices from "@effect/platform-node/NodeServices" ;
22import { it , describe , expect } from "@effect/vitest" ;
33import {
4+ ProjectId ,
45 ProviderDriverKind ,
56 ProviderInstanceId ,
67 SkillGetResult ,
78 SkillListResult ,
9+ SkillRequestError ,
10+ type Project ,
811 type SkillAgentAccess ,
912 type SkillSummary ,
1013} from "@t3tools/contracts" ;
@@ -13,9 +16,11 @@ import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
1316import * as Effect from "effect/Effect" ;
1417import * as FileSystem from "effect/FileSystem" ;
1518import * as Layer from "effect/Layer" ;
19+ import * as Option from "effect/Option" ;
1620import * as Path from "effect/Path" ;
1721import * as Schema from "effect/Schema" ;
1822
23+ import * as ProjectService from "../project/ProjectService.ts" ;
1924import * as Settings from "../serverSettings.ts" ;
2025import * as SkillCatalog from "./SkillCatalog.ts" ;
2126
@@ -84,30 +89,63 @@ const ALL_AGENTS_ENABLED = Object.fromEntries(
8489 ] ) ,
8590) ;
8691
87- /** The catalog as it sees a machine whose home is `home`, with these server settings. */
92+ const makeProject = ( workspaceRoot : string ) : Project => ( {
93+ id : ProjectId . make ( "project-skill-catalog" ) ,
94+ title : "App" ,
95+ workspaceRoot,
96+ repositoryIdentity : null ,
97+ faviconPath : null ,
98+ projectIcon : null ,
99+ defaultModelSelection : null ,
100+ defaultThreadEnvMode : null ,
101+ autoPull : false ,
102+ scripts : [ ] ,
103+ createdAt : "2026-01-01T00:00:00.000Z" ,
104+ updatedAt : "2026-01-01T00:00:00.000Z" ,
105+ deletedAt : null ,
106+ } ) ;
107+
108+ /**
109+ * The catalog as it sees a machine whose home is `home`, with these server settings. Only the
110+ * `registered` folders are projects; by default that is the machine's `repos/app`.
111+ */
88112const withCatalog = < A , E , R > (
89113 home : string ,
90114 use : ( catalog : SkillCatalog . SkillCatalog [ "Service" ] ) => Effect . Effect < A , E , R > ,
91115 options : {
92116 readonly settings ?: Parameters < typeof Settings . layerTest > [ 0 ] ;
93117 readonly env ?: NodeJS . ProcessEnv ;
118+ readonly registered ?: readonly string [ ] ;
94119 } = { } ,
95120) =>
96121 Effect . gen ( function * ( ) {
97- return yield * use ( yield * SkillCatalog . SkillCatalog ) ;
98- } ) . pipe (
99- Effect . provide (
100- SkillCatalog . layer . pipe (
101- Layer . provide (
102- Settings . layerTest ( {
103- ...options . settings ,
104- providerInstances : { ...ALL_AGENTS_ENABLED , ...options . settings ?. providerInstances } ,
105- } ) ,
122+ const path = yield * Path . Path ;
123+ const registered = options . registered ?? [ path . join ( home , "repos/app" ) ] ;
124+ const projects = Layer . mock ( ProjectService . ProjectService ) ( {
125+ getByWorkspaceRoot : ( root ) =>
126+ Effect . succeed ( registered . includes ( root ) ? Option . some ( makeProject ( root ) ) : Option . none ( ) ) ,
127+ } ) ;
128+ return yield * Effect . gen ( function * ( ) {
129+ return yield * use ( yield * SkillCatalog . SkillCatalog ) ;
130+ } ) . pipe (
131+ Effect . provide (
132+ SkillCatalog . layer . pipe (
133+ Layer . provide (
134+ Layer . mergeAll (
135+ projects ,
136+ Settings . layerTest ( {
137+ ...options . settings ,
138+ providerInstances : {
139+ ...ALL_AGENTS_ENABLED ,
140+ ...options . settings ?. providerInstances ,
141+ } ,
142+ } ) ,
143+ ) ,
144+ ) ,
106145 ) ,
107146 ) ,
108- ) ,
109- Effect . provideService ( HostProcessEnvironment , { HOME : home , ...options . env } ) ,
110- ) ;
147+ ) ;
148+ } ) . pipe ( Effect . provideService ( HostProcessEnvironment , { HOME : home , ...options . env } ) ) ;
111149
112150const byKey = ( skills : readonly SkillSummary [ ] ) =>
113151 new Map ( skills . map ( ( skill ) => [ `${ skill . scope } :${ skill . name } ` , skill ] ) ) ;
@@ -635,6 +673,52 @@ it.layer(NodeServices.layer, { excludeTestServices: true })("SkillCatalog", (it)
635673 ) ;
636674 } ) ;
637675
676+ describe ( "project folders" , ( ) => {
677+ it . effect . skipIf ( ! symlinksSupported ) (
678+ "reads a project's skill folders only when the folder is a registered project" ,
679+ ( ) =>
680+ Effect . gen ( function * ( ) {
681+ const { home, project } = yield * makeMachine ;
682+ const refused = new SkillRequestError ( { reason : "projectNotRegistered" } ) ;
683+ const get = ( cwd : string ) => ( {
684+ cwd,
685+ scope : "project" as const ,
686+ name : "verify" ,
687+ home : ".agents/skills/verify" ,
688+ } ) ;
689+
690+ // A folder that holds skills but isn't a project (the home, a project's subfolder, a
691+ // relative path, a path that isn't there) is refused for the list and for one skill.
692+ for ( const cwd of [ home , `${ project } /.agents` , "repos/app" , `${ home } /missing` ] ) {
693+ const registered = [ project ] ;
694+ expect (
695+ yield * withCatalog ( home , ( catalog ) => catalog . list ( { cwd } ) . pipe ( Effect . flip ) , {
696+ registered,
697+ } ) ,
698+ ) . toEqual ( refused ) ;
699+ expect (
700+ yield * withCatalog ( home , ( catalog ) => catalog . get ( get ( cwd ) ) . pipe ( Effect . flip ) , {
701+ registered,
702+ } ) ,
703+ ) . toEqual ( refused ) ;
704+ }
705+
706+ // The registered project, and the Global folders without any `cwd`, are read as before.
707+ const listed = yield * withCatalog ( home , ( catalog ) => catalog . list ( { cwd : project } ) ) ;
708+ expect ( listed . skills . some ( ( skill ) => skill . scope === "project" ) ) . toBe ( true ) ;
709+ const global = yield * withCatalog ( home , ( catalog ) => catalog . list ( { } ) , {
710+ registered : [ ] ,
711+ } ) ;
712+ expect ( global . skills . map ( ( skill ) => skill . scope ) ) . toEqual (
713+ global . skills . map ( ( ) => "global" ) ,
714+ ) ;
715+ expect ( global . skills . length ) . toBeGreaterThan ( 0 ) ;
716+ const detail = yield * withCatalog ( home , ( catalog ) => catalog . get ( get ( project ) ) ) ;
717+ expect ( detail . home ) . toBe ( `${ project } /.agents/skills/verify` ) ;
718+ } ) ,
719+ ) ;
720+ } ) ;
721+
638722 describe ( "get" , ( ) => {
639723 it . effect . skipIf ( ! symlinksSupported ) (
640724 "returns the full SKILL.md, the file list and which files can run" ,
0 commit comments